From ffe0c9ccc1d8ac5064f1de603df856c18a24d2c6 Mon Sep 17 00:00:00 2001 From: Tobias Schottdorf Date: Thu, 30 May 2019 11:31:52 +0200 Subject: [PATCH] hack: remove self-vendoring --- vendor/github.com/coreos/etcd/LICENSE | 202 - vendor/github.com/coreos/etcd/NOTICE | 5 - vendor/github.com/coreos/etcd/alarm/alarms.go | 152 - .../coreos/etcd/auth/authpb/auth.pb.go | 807 - vendor/github.com/coreos/etcd/auth/doc.go | 16 - vendor/github.com/coreos/etcd/auth/jwt.go | 139 - vendor/github.com/coreos/etcd/auth/nop.go | 35 - .../coreos/etcd/auth/range_perm_cache.go | 133 - .../coreos/etcd/auth/simple_token.go | 223 - vendor/github.com/coreos/etcd/auth/store.go | 1136 - .../coreos/etcd/client/auth_role.go | 236 - .../coreos/etcd/client/auth_user.go | 319 - .../coreos/etcd/client/cancelreq.go | 18 - .../github.com/coreos/etcd/client/client.go | 710 - .../coreos/etcd/client/cluster_error.go | 37 - vendor/github.com/coreos/etcd/client/curl.go | 70 - .../github.com/coreos/etcd/client/discover.go | 40 - vendor/github.com/coreos/etcd/client/doc.go | 73 - vendor/github.com/coreos/etcd/client/json.go | 72 - vendor/github.com/coreos/etcd/client/keys.go | 680 - .../github.com/coreos/etcd/client/members.go | 303 - vendor/github.com/coreos/etcd/client/util.go | 53 - .../github.com/coreos/etcd/clientv3/auth.go | 233 - .../github.com/coreos/etcd/clientv3/client.go | 578 - .../coreos/etcd/clientv3/cluster.go | 114 - .../coreos/etcd/clientv3/compact_op.go | 51 - .../coreos/etcd/clientv3/compare.go | 140 - .../coreos/etcd/clientv3/concurrency/doc.go | 17 - .../etcd/clientv3/concurrency/election.go | 245 - .../coreos/etcd/clientv3/concurrency/key.go | 65 - .../coreos/etcd/clientv3/concurrency/mutex.go | 117 - .../etcd/clientv3/concurrency/session.go | 141 - .../coreos/etcd/clientv3/concurrency/stm.go | 387 - .../github.com/coreos/etcd/clientv3/config.go | 75 - vendor/github.com/coreos/etcd/clientv3/doc.go | 97 - .../coreos/etcd/clientv3/health_balancer.go | 609 - vendor/github.com/coreos/etcd/clientv3/kv.go | 177 - .../github.com/coreos/etcd/clientv3/lease.go | 588 - .../coreos/etcd/clientv3/leasing/cache.go | 306 - .../coreos/etcd/clientv3/leasing/doc.go | 46 - .../coreos/etcd/clientv3/leasing/kv.go | 479 - .../coreos/etcd/clientv3/leasing/txn.go | 223 - .../coreos/etcd/clientv3/leasing/util.go | 108 - .../github.com/coreos/etcd/clientv3/logger.go | 135 - .../coreos/etcd/clientv3/maintenance.go | 226 - .../coreos/etcd/clientv3/mirror/syncer.go | 111 - .../coreos/etcd/clientv3/namespace/doc.go | 43 - .../coreos/etcd/clientv3/namespace/kv.go | 206 - .../coreos/etcd/clientv3/namespace/lease.go | 57 - .../coreos/etcd/clientv3/namespace/util.go | 42 - .../coreos/etcd/clientv3/namespace/watch.go | 83 - .../coreos/etcd/clientv3/naming/doc.go | 56 - .../coreos/etcd/clientv3/naming/grpc.go | 131 - vendor/github.com/coreos/etcd/clientv3/op.go | 513 - .../coreos/etcd/clientv3/options.go | 49 - .../coreos/etcd/clientv3/ordering/doc.go | 42 - .../coreos/etcd/clientv3/ordering/kv.go | 149 - .../coreos/etcd/clientv3/ordering/util.go | 49 - .../coreos/etcd/clientv3/ready_wait.go | 30 - .../github.com/coreos/etcd/clientv3/retry.go | 496 - .../github.com/coreos/etcd/clientv3/sort.go | 37 - vendor/github.com/coreos/etcd/clientv3/txn.go | 151 - .../github.com/coreos/etcd/clientv3/watch.go | 828 - .../coreos/etcd/compactor/compactor.go | 66 - .../github.com/coreos/etcd/compactor/doc.go | 16 - .../coreos/etcd/compactor/periodic.go | 191 - .../coreos/etcd/compactor/revision.go | 115 - .../coreos/etcd/discovery/discovery.go | 363 - vendor/github.com/coreos/etcd/embed/config.go | 699 - vendor/github.com/coreos/etcd/embed/doc.go | 45 - vendor/github.com/coreos/etcd/embed/etcd.go | 582 - vendor/github.com/coreos/etcd/embed/serve.go | 285 - vendor/github.com/coreos/etcd/embed/util.go | 30 - vendor/github.com/coreos/etcd/error/error.go | 163 - .../etcdctl/ctlv2/command/auth_commands.go | 90 - .../etcdctl/ctlv2/command/backup_command.go | 256 - .../etcdctl/ctlv2/command/cluster_health.go | 139 - .../coreos/etcd/etcdctl/ctlv2/command/doc.go | 16 - .../etcd/etcdctl/ctlv2/command/error.go | 52 - .../ctlv2/command/exec_watch_command.go | 129 - .../etcd/etcdctl/ctlv2/command/format.go | 60 - .../etcd/etcdctl/ctlv2/command/get_command.go | 66 - .../etcd/etcdctl/ctlv2/command/ls_command.go | 90 - .../etcdctl/ctlv2/command/member_commands.go | 207 - .../etcd/etcdctl/ctlv2/command/mk_command.go | 76 - .../etcdctl/ctlv2/command/mkdir_command.go | 59 - .../etcd/etcdctl/ctlv2/command/rm_command.go | 63 - .../etcdctl/ctlv2/command/rmdir_command.go | 54 - .../etcdctl/ctlv2/command/role_commands.go | 255 - .../etcd/etcdctl/ctlv2/command/set_command.go | 73 - .../etcdctl/ctlv2/command/set_dir_command.go | 36 - .../etcdctl/ctlv2/command/update_command.go | 63 - .../ctlv2/command/update_dir_command.go | 57 - .../etcdctl/ctlv2/command/user_commands.go | 225 - .../coreos/etcd/etcdctl/ctlv2/command/util.go | 337 - .../etcdctl/ctlv2/command/watch_command.go | 86 - .../etcdctl/ctlv3/command/alarm_command.go | 81 - .../etcdctl/ctlv3/command/auth_command.go | 97 - .../etcd/etcdctl/ctlv3/command/check.go | 218 - .../ctlv3/command/compaction_command.go | 62 - .../etcdctl/ctlv3/command/defrag_command.go | 89 - .../etcd/etcdctl/ctlv3/command/del_command.go | 94 - .../coreos/etcd/etcdctl/ctlv3/command/doc.go | 16 - .../etcdctl/ctlv3/command/elect_command.go | 137 - .../etcd/etcdctl/ctlv3/command/ep_command.go | 241 - .../etcd/etcdctl/ctlv3/command/error.go | 42 - .../etcd/etcdctl/ctlv3/command/get_command.go | 163 - .../etcd/etcdctl/ctlv3/command/global.go | 412 - .../etcdctl/ctlv3/command/lease_command.go | 207 - .../etcdctl/ctlv3/command/lock_command.go | 113 - .../ctlv3/command/make_mirror_command.go | 177 - .../etcdctl/ctlv3/command/member_command.go | 217 - .../etcdctl/ctlv3/command/migrate_command.go | 402 - .../ctlv3/command/move_leader_command.go | 82 - .../etcd/etcdctl/ctlv3/command/printer.go | 211 - .../etcdctl/ctlv3/command/printer_fields.go | 213 - .../etcdctl/ctlv3/command/printer_json.go | 42 - .../etcdctl/ctlv3/command/printer_protobuf.go | 64 - .../etcdctl/ctlv3/command/printer_simple.go | 271 - .../etcdctl/ctlv3/command/printer_table.go | 66 - .../etcd/etcdctl/ctlv3/command/put_command.go | 118 - .../etcdctl/ctlv3/command/role_command.go | 244 - .../etcdctl/ctlv3/command/snapshot_command.go | 475 - .../etcd/etcdctl/ctlv3/command/txn_command.go | 209 - .../etcdctl/ctlv3/command/user_command.go | 280 - .../coreos/etcd/etcdctl/ctlv3/command/util.go | 77 - .../etcdctl/ctlv3/command/version_command.go | 36 - .../etcdctl/ctlv3/command/watch_command.go | 347 - .../coreos/etcd/etcdserver/api/capability.go | 87 - .../coreos/etcd/etcdserver/api/cluster.go | 38 - .../coreos/etcd/etcdserver/api/doc.go | 16 - .../etcd/etcdserver/api/etcdhttp/base.go | 158 - .../etcd/etcdserver/api/etcdhttp/doc.go | 16 - .../etcd/etcdserver/api/etcdhttp/metrics.go | 123 - .../etcd/etcdserver/api/etcdhttp/peer.go | 73 - .../etcd/etcdserver/api/v2http/capability.go | 40 - .../etcd/etcdserver/api/v2http/client.go | 719 - .../etcd/etcdserver/api/v2http/client_auth.go | 543 - .../coreos/etcd/etcdserver/api/v2http/doc.go | 16 - .../coreos/etcd/etcdserver/api/v2http/http.go | 74 - .../etcdserver/api/v2http/httptypes/errors.go | 56 - .../etcdserver/api/v2http/httptypes/member.go | 69 - .../etcd/etcdserver/api/v2http/metrics.go | 96 - .../etcd/etcdserver/api/v2v3/cluster.go | 31 - .../coreos/etcd/etcdserver/api/v2v3/doc.go | 16 - .../coreos/etcd/etcdserver/api/v2v3/server.go | 117 - .../coreos/etcd/etcdserver/api/v2v3/store.go | 620 - .../etcd/etcdserver/api/v2v3/watcher.go | 140 - .../etcd/etcdserver/api/v3client/doc.go | 45 - .../etcd/etcdserver/api/v3client/v3client.go | 66 - .../etcd/etcdserver/api/v3election/doc.go | 16 - .../etcdserver/api/v3election/election.go | 134 - .../v3electionpb/gw/v3election.pb.gw.go | 313 - .../v3election/v3electionpb/v3election.pb.go | 2079 -- .../coreos/etcd/etcdserver/api/v3lock/doc.go | 16 - .../coreos/etcd/etcdserver/api/v3lock/lock.go | 56 - .../api/v3lock/v3lockpb/gw/v3lock.pb.gw.go | 167 - .../api/v3lock/v3lockpb/v3lock.pb.go | 959 - .../coreos/etcd/etcdserver/api/v3rpc/auth.go | 158 - .../coreos/etcd/etcdserver/api/v3rpc/codec.go | 34 - .../coreos/etcd/etcdserver/api/v3rpc/grpc.go | 76 - .../etcd/etcdserver/api/v3rpc/header.go | 49 - .../etcd/etcdserver/api/v3rpc/interceptor.go | 263 - .../coreos/etcd/etcdserver/api/v3rpc/key.go | 277 - .../coreos/etcd/etcdserver/api/v3rpc/lease.go | 148 - .../etcd/etcdserver/api/v3rpc/maintenance.go | 229 - .../etcd/etcdserver/api/v3rpc/member.go | 101 - .../etcd/etcdserver/api/v3rpc/metrics.go | 38 - .../coreos/etcd/etcdserver/api/v3rpc/quota.go | 90 - .../etcd/etcdserver/api/v3rpc/rpctypes/doc.go | 16 - .../etcdserver/api/v3rpc/rpctypes/error.go | 215 - .../etcd/etcdserver/api/v3rpc/rpctypes/md.go | 20 - .../coreos/etcd/etcdserver/api/v3rpc/util.go | 117 - .../coreos/etcd/etcdserver/api/v3rpc/watch.go | 447 - .../coreos/etcd/etcdserver/apply.go | 972 - .../coreos/etcd/etcdserver/apply_auth.go | 245 - .../coreos/etcd/etcdserver/apply_v2.go | 140 - .../coreos/etcd/etcdserver/auth/auth.go | 648 - .../etcd/etcdserver/auth/auth_requests.go | 166 - .../coreos/etcd/etcdserver/backend.go | 81 - .../coreos/etcd/etcdserver/cluster_util.go | 258 - .../coreos/etcd/etcdserver/config.go | 282 - .../etcd/etcdserver/consistent_index.go | 33 - .../coreos/etcd/etcdserver/corrupt.go | 262 - .../github.com/coreos/etcd/etcdserver/doc.go | 16 - .../coreos/etcd/etcdserver/errors.go | 48 - .../etcdserver/etcdserverpb/etcdserver.pb.go | 1035 - .../etcdserver/etcdserverpb/gw/rpc.pb.gw.go | 2134 -- .../etcdserverpb/raft_internal.pb.go | 2077 -- .../etcdserverpb/raft_internal_stringer.go | 183 - .../etcd/etcdserver/etcdserverpb/rpc.pb.go | 18665 ---------------- .../etcd/etcdserver/membership/cluster.go | 512 - .../coreos/etcd/etcdserver/membership/doc.go | 16 - .../etcd/etcdserver/membership/errors.go | 33 - .../etcd/etcdserver/membership/member.go | 124 - .../etcd/etcdserver/membership/store.go | 193 - .../coreos/etcd/etcdserver/metrics.go | 177 - .../coreos/etcd/etcdserver/quota.go | 124 - .../github.com/coreos/etcd/etcdserver/raft.go | 608 - .../coreos/etcd/etcdserver/server.go | 1745 -- .../coreos/etcd/etcdserver/snapshot_merge.go | 73 - .../coreos/etcd/etcdserver/stats/leader.go | 128 - .../coreos/etcd/etcdserver/stats/queue.go | 110 - .../coreos/etcd/etcdserver/stats/server.go | 142 - .../coreos/etcd/etcdserver/stats/stats.go | 32 - .../coreos/etcd/etcdserver/storage.go | 98 - .../github.com/coreos/etcd/etcdserver/util.go | 155 - .../coreos/etcd/etcdserver/v2_server.go | 165 - .../coreos/etcd/etcdserver/v3_server.go | 720 - .../etcd/functional/rpcpb/etcd_config.go | 99 - .../coreos/etcd/functional/rpcpb/member.go | 361 - .../coreos/etcd/functional/rpcpb/rpc.pb.go | 5112 ----- vendor/github.com/coreos/etcd/lease/doc.go | 16 - .../coreos/etcd/lease/leasehttp/doc.go | 16 - .../coreos/etcd/lease/leasehttp/http.go | 247 - .../coreos/etcd/lease/leasepb/lease.pb.go | 591 - vendor/github.com/coreos/etcd/lease/lessor.go | 680 - .../coreos/etcd/mvcc/backend/backend.go | 464 - .../coreos/etcd/mvcc/backend/batch_tx.go | 254 - .../etcd/mvcc/backend/config_default.go | 23 - .../coreos/etcd/mvcc/backend/config_linux.go | 34 - .../etcd/mvcc/backend/config_windows.go | 26 - .../coreos/etcd/mvcc/backend/doc.go | 16 - .../coreos/etcd/mvcc/backend/metrics.go | 59 - .../coreos/etcd/mvcc/backend/read_tx.go | 120 - .../coreos/etcd/mvcc/backend/tx_buffer.go | 181 - vendor/github.com/coreos/etcd/mvcc/doc.go | 16 - vendor/github.com/coreos/etcd/mvcc/index.go | 251 - .../github.com/coreos/etcd/mvcc/key_index.go | 356 - vendor/github.com/coreos/etcd/mvcc/kv.go | 149 - vendor/github.com/coreos/etcd/mvcc/kv_view.go | 53 - vendor/github.com/coreos/etcd/mvcc/kvstore.go | 510 - .../coreos/etcd/mvcc/kvstore_compaction.go | 69 - .../coreos/etcd/mvcc/kvstore_txn.go | 253 - vendor/github.com/coreos/etcd/mvcc/metrics.go | 239 - .../coreos/etcd/mvcc/metrics_txn.go | 59 - .../coreos/etcd/mvcc/mvccpb/kv.pb.go | 718 - .../github.com/coreos/etcd/mvcc/revision.go | 67 - vendor/github.com/coreos/etcd/mvcc/util.go | 56 - .../coreos/etcd/mvcc/watchable_store.go | 534 - .../coreos/etcd/mvcc/watchable_store_txn.go | 53 - vendor/github.com/coreos/etcd/mvcc/watcher.go | 180 - .../coreos/etcd/mvcc/watcher_group.go | 292 - vendor/github.com/coreos/etcd/pkg/adt/doc.go | 16 - .../coreos/etcd/pkg/adt/interval_tree.go | 599 - .../coreos/etcd/pkg/contention/contention.go | 69 - .../coreos/etcd/pkg/contention/doc.go | 16 - .../github.com/coreos/etcd/pkg/cors/cors.go | 90 - .../github.com/coreos/etcd/pkg/cpuutil/doc.go | 16 - .../coreos/etcd/pkg/cpuutil/endian.go | 36 - vendor/github.com/coreos/etcd/pkg/crc/crc.go | 43 - .../coreos/etcd/pkg/debugutil/doc.go | 16 - .../coreos/etcd/pkg/debugutil/pprof.go | 47 - .../coreos/etcd/pkg/fileutil/dir_unix.go | 22 - .../coreos/etcd/pkg/fileutil/dir_windows.go | 46 - .../coreos/etcd/pkg/fileutil/fileutil.go | 122 - .../coreos/etcd/pkg/fileutil/lock.go | 26 - .../coreos/etcd/pkg/fileutil/lock_flock.go | 49 - .../coreos/etcd/pkg/fileutil/lock_linux.go | 97 - .../coreos/etcd/pkg/fileutil/lock_plan9.go | 45 - .../coreos/etcd/pkg/fileutil/lock_solaris.go | 62 - .../coreos/etcd/pkg/fileutil/lock_unix.go | 29 - .../coreos/etcd/pkg/fileutil/lock_windows.go | 125 - .../coreos/etcd/pkg/fileutil/preallocate.go | 54 - .../etcd/pkg/fileutil/preallocate_darwin.go | 65 - .../etcd/pkg/fileutil/preallocate_unix.go | 49 - .../pkg/fileutil/preallocate_unsupported.go | 25 - .../coreos/etcd/pkg/fileutil/purge.go | 78 - .../coreos/etcd/pkg/fileutil/sync.go | 29 - .../coreos/etcd/pkg/fileutil/sync_darwin.go | 40 - .../coreos/etcd/pkg/fileutil/sync_linux.go | 34 - .../github.com/coreos/etcd/pkg/flags/flag.go | 166 - .../coreos/etcd/pkg/flags/strings.go | 85 - .../github.com/coreos/etcd/pkg/flags/urls.go | 52 - .../coreos/etcd/pkg/httputil/httputil.go | 22 - .../github.com/coreos/etcd/pkg/idutil/id.go | 78 - .../coreos/etcd/pkg/ioutil/pagewriter.go | 106 - .../coreos/etcd/pkg/ioutil/readcloser.go | 66 - .../coreos/etcd/pkg/ioutil/reader.go | 40 - .../github.com/coreos/etcd/pkg/ioutil/util.go | 43 - .../coreos/etcd/pkg/logutil/merge_logger.go | 195 - .../coreos/etcd/pkg/netutil/isolate_linux.go | 82 - .../coreos/etcd/pkg/netutil/isolate_stub.go | 25 - .../coreos/etcd/pkg/netutil/netutil.go | 187 - .../coreos/etcd/pkg/netutil/routes.go | 33 - .../coreos/etcd/pkg/netutil/routes_linux.go | 250 - .../coreos/etcd/pkg/osutil/interrupt_unix.go | 80 - .../etcd/pkg/osutil/interrupt_windows.go | 32 - .../coreos/etcd/pkg/osutil/osutil.go | 45 - .../coreos/etcd/pkg/osutil/signal.go | 21 - .../coreos/etcd/pkg/osutil/signal_linux.go | 30 - .../coreos/etcd/pkg/pathutil/path.go | 31 - .../coreos/etcd/pkg/pbutil/pbutil.go | 60 - .../github.com/coreos/etcd/pkg/proxy/doc.go | 16 - .../coreos/etcd/pkg/proxy/server.go | 949 - .../github.com/coreos/etcd/pkg/report/doc.go | 16 - .../coreos/etcd/pkg/report/report.go | 278 - .../coreos/etcd/pkg/report/timeseries.go | 160 - .../coreos/etcd/pkg/report/weighted.go | 101 - .../coreos/etcd/pkg/runtime/fds_linux.go | 37 - .../coreos/etcd/pkg/runtime/fds_other.go | 30 - .../coreos/etcd/pkg/schedule/doc.go | 16 - .../coreos/etcd/pkg/schedule/schedule.go | 165 - vendor/github.com/coreos/etcd/pkg/srv/srv.go | 141 - .../coreos/etcd/pkg/stringutil/stringutil.go | 55 - .../coreos/etcd/pkg/testutil/assert.go | 62 - .../coreos/etcd/pkg/testutil/leak.go | 139 - .../etcd/pkg/testutil/pauseable_handler.go | 57 - .../coreos/etcd/pkg/testutil/recorder.go | 132 - .../coreos/etcd/pkg/testutil/testutil.go | 84 - .../coreos/etcd/pkg/tlsutil/cipher_suites.go | 51 - .../github.com/coreos/etcd/pkg/tlsutil/doc.go | 16 - .../coreos/etcd/pkg/tlsutil/tlsutil.go | 72 - .../coreos/etcd/pkg/transport/doc.go | 17 - .../etcd/pkg/transport/keepalive_listener.go | 94 - .../coreos/etcd/pkg/transport/limit_listen.go | 80 - .../coreos/etcd/pkg/transport/listener.go | 289 - .../coreos/etcd/pkg/transport/listener_tls.go | 272 - .../coreos/etcd/pkg/transport/timeout_conn.go | 44 - .../etcd/pkg/transport/timeout_dialer.go | 36 - .../etcd/pkg/transport/timeout_listener.go | 57 - .../etcd/pkg/transport/timeout_transport.go | 51 - .../coreos/etcd/pkg/transport/tls.go | 49 - .../coreos/etcd/pkg/transport/transport.go | 71 - .../etcd/pkg/transport/unix_listener.go | 40 - .../github.com/coreos/etcd/pkg/types/doc.go | 17 - vendor/github.com/coreos/etcd/pkg/types/id.go | 41 - .../github.com/coreos/etcd/pkg/types/set.go | 178 - .../github.com/coreos/etcd/pkg/types/slice.go | 22 - .../github.com/coreos/etcd/pkg/types/urls.go | 82 - .../coreos/etcd/pkg/types/urlsmap.go | 107 - .../github.com/coreos/etcd/pkg/wait/wait.go | 91 - .../coreos/etcd/pkg/wait/wait_time.go | 66 - .../grpcproxy/adapter/auth_client_adapter.go | 93 - .../proxy/grpcproxy/adapter/chan_stream.go | 165 - .../adapter/cluster_client_adapter.go | 45 - .../etcd/proxy/grpcproxy/adapter/doc.go | 17 - .../adapter/election_client_adapter.go | 80 - .../grpcproxy/adapter/kv_client_adapter.go | 49 - .../grpcproxy/adapter/lease_client_adapter.go | 82 - .../grpcproxy/adapter/lock_client_adapter.go | 37 - .../adapter/maintenance_client_adapter.go | 88 - .../grpcproxy/adapter/watch_client_adapter.go | 66 - .../coreos/etcd/proxy/grpcproxy/auth.go | 110 - .../etcd/proxy/grpcproxy/cache/store.go | 171 - .../coreos/etcd/proxy/grpcproxy/cluster.go | 177 - .../coreos/etcd/proxy/grpcproxy/doc.go | 16 - .../coreos/etcd/proxy/grpcproxy/election.go | 65 - .../coreos/etcd/proxy/grpcproxy/health.go | 41 - .../coreos/etcd/proxy/grpcproxy/kv.go | 232 - .../coreos/etcd/proxy/grpcproxy/leader.go | 115 - .../coreos/etcd/proxy/grpcproxy/lease.go | 382 - .../coreos/etcd/proxy/grpcproxy/lock.go | 38 - .../coreos/etcd/proxy/grpcproxy/logger.go | 19 - .../etcd/proxy/grpcproxy/maintenance.go | 90 - .../coreos/etcd/proxy/grpcproxy/metrics.go | 114 - .../coreos/etcd/proxy/grpcproxy/register.go | 94 - .../coreos/etcd/proxy/grpcproxy/util.go | 73 - .../coreos/etcd/proxy/grpcproxy/watch.go | 298 - .../etcd/proxy/grpcproxy/watch_broadcast.go | 152 - .../etcd/proxy/grpcproxy/watch_broadcasts.go | 135 - .../etcd/proxy/grpcproxy/watch_ranges.go | 69 - .../coreos/etcd/proxy/grpcproxy/watcher.go | 129 - .../coreos/etcd/proxy/httpproxy/director.go | 158 - .../coreos/etcd/proxy/httpproxy/doc.go | 18 - .../coreos/etcd/proxy/httpproxy/metrics.go | 88 - .../coreos/etcd/proxy/httpproxy/proxy.go | 116 - .../coreos/etcd/proxy/httpproxy/reverse.go | 208 - .../coreos/etcd/proxy/tcpproxy/doc.go | 16 - .../coreos/etcd/proxy/tcpproxy/userspace.go | 226 - vendor/github.com/coreos/etcd/raft/doc.go | 300 - vendor/github.com/coreos/etcd/raft/log.go | 358 - .../coreos/etcd/raft/log_unstable.go | 159 - vendor/github.com/coreos/etcd/raft/logger.go | 126 - vendor/github.com/coreos/etcd/raft/node.go | 539 - .../github.com/coreos/etcd/raft/progress.go | 284 - vendor/github.com/coreos/etcd/raft/raft.go | 1406 -- .../coreos/etcd/raft/raftpb/raft.pb.go | 2004 -- vendor/github.com/coreos/etcd/raft/rawnode.go | 266 - .../github.com/coreos/etcd/raft/read_only.go | 118 - vendor/github.com/coreos/etcd/raft/status.go | 88 - vendor/github.com/coreos/etcd/raft/storage.go | 271 - vendor/github.com/coreos/etcd/raft/util.go | 129 - .../github.com/coreos/etcd/rafthttp/coder.go | 27 - vendor/github.com/coreos/etcd/rafthttp/doc.go | 16 - .../github.com/coreos/etcd/rafthttp/http.go | 366 - .../coreos/etcd/rafthttp/metrics.go | 143 - .../coreos/etcd/rafthttp/msg_codec.go | 68 - .../coreos/etcd/rafthttp/msgappv2_codec.go | 248 - .../github.com/coreos/etcd/rafthttp/peer.go | 313 - .../coreos/etcd/rafthttp/peer_status.go | 77 - .../coreos/etcd/rafthttp/pipeline.go | 160 - .../coreos/etcd/rafthttp/probing_status.go | 76 - .../github.com/coreos/etcd/rafthttp/remote.go | 70 - .../coreos/etcd/rafthttp/snapshot_sender.go | 164 - .../github.com/coreos/etcd/rafthttp/stream.go | 533 - .../coreos/etcd/rafthttp/transport.go | 438 - .../coreos/etcd/rafthttp/urlpick.go | 57 - .../github.com/coreos/etcd/rafthttp/util.go | 186 - vendor/github.com/coreos/etcd/snap/db.go | 83 - vendor/github.com/coreos/etcd/snap/message.go | 64 - vendor/github.com/coreos/etcd/snap/metrics.go | 65 - .../coreos/etcd/snap/snappb/snap.pb.go | 336 - .../coreos/etcd/snap/snapshotter.go | 204 - vendor/github.com/coreos/etcd/snapshot/doc.go | 16 - .../github.com/coreos/etcd/snapshot/util.go | 35 - .../coreos/etcd/snapshot/v3_snapshot.go | 485 - vendor/github.com/coreos/etcd/store/doc.go | 16 - vendor/github.com/coreos/etcd/store/event.go | 71 - .../coreos/etcd/store/event_history.go | 129 - .../coreos/etcd/store/event_queue.go | 34 - .../github.com/coreos/etcd/store/metrics.go | 132 - vendor/github.com/coreos/etcd/store/node.go | 395 - .../coreos/etcd/store/node_extern.go | 116 - vendor/github.com/coreos/etcd/store/stats.go | 145 - vendor/github.com/coreos/etcd/store/store.go | 791 - .../coreos/etcd/store/ttl_key_heap.go | 99 - .../github.com/coreos/etcd/store/watcher.go | 95 - .../coreos/etcd/store/watcher_hub.go | 200 - .../github.com/coreos/etcd/version/version.go | 56 - vendor/github.com/coreos/etcd/wal/decoder.go | 188 - vendor/github.com/coreos/etcd/wal/doc.go | 75 - vendor/github.com/coreos/etcd/wal/encoder.go | 120 - .../coreos/etcd/wal/file_pipeline.go | 97 - vendor/github.com/coreos/etcd/wal/metrics.go | 31 - vendor/github.com/coreos/etcd/wal/repair.go | 99 - vendor/github.com/coreos/etcd/wal/util.go | 107 - vendor/github.com/coreos/etcd/wal/wal.go | 772 - .../coreos/etcd/wal/walpb/record.go | 29 - .../coreos/etcd/wal/walpb/record.pb.go | 504 - vendor/go.etcd.io/etcd/LICENSE | 202 - vendor/go.etcd.io/etcd/NOTICE | 5 - vendor/go.etcd.io/etcd/auth/authpb/auth.pb.go | 807 - vendor/go.etcd.io/etcd/auth/doc.go | 16 - vendor/go.etcd.io/etcd/auth/jwt.go | 139 - vendor/go.etcd.io/etcd/auth/nop.go | 35 - .../go.etcd.io/etcd/auth/range_perm_cache.go | 133 - vendor/go.etcd.io/etcd/auth/simple_token.go | 223 - vendor/go.etcd.io/etcd/auth/store.go | 1136 - vendor/go.etcd.io/etcd/client/auth_role.go | 236 - vendor/go.etcd.io/etcd/client/auth_user.go | 319 - vendor/go.etcd.io/etcd/client/cancelreq.go | 18 - vendor/go.etcd.io/etcd/client/client.go | 710 - .../go.etcd.io/etcd/client/cluster_error.go | 37 - vendor/go.etcd.io/etcd/client/curl.go | 70 - vendor/go.etcd.io/etcd/client/discover.go | 40 - vendor/go.etcd.io/etcd/client/doc.go | 73 - vendor/go.etcd.io/etcd/client/json.go | 72 - vendor/go.etcd.io/etcd/client/keys.go | 680 - vendor/go.etcd.io/etcd/client/members.go | 303 - vendor/go.etcd.io/etcd/client/util.go | 53 - vendor/go.etcd.io/etcd/clientv3/auth.go | 233 - vendor/go.etcd.io/etcd/clientv3/client.go | 578 - .../etcd/clientv3/clientv3util/util.go | 33 - vendor/go.etcd.io/etcd/clientv3/cluster.go | 114 - vendor/go.etcd.io/etcd/clientv3/compact_op.go | 51 - vendor/go.etcd.io/etcd/clientv3/compare.go | 140 - .../etcd/clientv3/concurrency/doc.go | 17 - .../etcd/clientv3/concurrency/election.go | 245 - .../etcd/clientv3/concurrency/key.go | 65 - .../etcd/clientv3/concurrency/mutex.go | 117 - .../etcd/clientv3/concurrency/session.go | 141 - .../etcd/clientv3/concurrency/stm.go | 387 - vendor/go.etcd.io/etcd/clientv3/config.go | 75 - vendor/go.etcd.io/etcd/clientv3/doc.go | 97 - .../etcd/clientv3/health_balancer.go | 609 - vendor/go.etcd.io/etcd/clientv3/kv.go | 177 - vendor/go.etcd.io/etcd/clientv3/lease.go | 588 - .../go.etcd.io/etcd/clientv3/leasing/cache.go | 306 - .../go.etcd.io/etcd/clientv3/leasing/doc.go | 46 - vendor/go.etcd.io/etcd/clientv3/leasing/kv.go | 479 - .../go.etcd.io/etcd/clientv3/leasing/txn.go | 223 - .../go.etcd.io/etcd/clientv3/leasing/util.go | 108 - vendor/go.etcd.io/etcd/clientv3/logger.go | 135 - .../go.etcd.io/etcd/clientv3/maintenance.go | 226 - .../go.etcd.io/etcd/clientv3/mirror/syncer.go | 111 - .../go.etcd.io/etcd/clientv3/namespace/doc.go | 43 - .../go.etcd.io/etcd/clientv3/namespace/kv.go | 206 - .../etcd/clientv3/namespace/lease.go | 57 - .../etcd/clientv3/namespace/util.go | 42 - .../etcd/clientv3/namespace/watch.go | 83 - vendor/go.etcd.io/etcd/clientv3/naming/doc.go | 56 - .../go.etcd.io/etcd/clientv3/naming/grpc.go | 131 - vendor/go.etcd.io/etcd/clientv3/op.go | 513 - vendor/go.etcd.io/etcd/clientv3/options.go | 49 - .../go.etcd.io/etcd/clientv3/ordering/doc.go | 42 - .../go.etcd.io/etcd/clientv3/ordering/kv.go | 149 - .../go.etcd.io/etcd/clientv3/ordering/util.go | 49 - vendor/go.etcd.io/etcd/clientv3/ready_wait.go | 30 - vendor/go.etcd.io/etcd/clientv3/retry.go | 496 - vendor/go.etcd.io/etcd/clientv3/sort.go | 37 - vendor/go.etcd.io/etcd/clientv3/txn.go | 151 - vendor/go.etcd.io/etcd/clientv3/watch.go | 828 - .../etcd/contrib/recipes/barrier.go | 66 - .../go.etcd.io/etcd/contrib/recipes/client.go | 55 - vendor/go.etcd.io/etcd/contrib/recipes/doc.go | 17 - .../etcd/contrib/recipes/double_barrier.go | 138 - vendor/go.etcd.io/etcd/contrib/recipes/key.go | 163 - .../etcd/contrib/recipes/priority_queue.go | 80 - .../go.etcd.io/etcd/contrib/recipes/queue.go | 77 - .../etcd/contrib/recipes/rwmutex.go | 89 - .../go.etcd.io/etcd/contrib/recipes/watch.go | 54 - vendor/go.etcd.io/etcd/embed/config.go | 699 - vendor/go.etcd.io/etcd/embed/doc.go | 45 - vendor/go.etcd.io/etcd/embed/etcd.go | 582 - vendor/go.etcd.io/etcd/embed/serve.go | 285 - vendor/go.etcd.io/etcd/embed/util.go | 30 - .../etcdctl/ctlv2/command/auth_commands.go | 90 - .../etcdctl/ctlv2/command/backup_command.go | 256 - .../etcdctl/ctlv2/command/cluster_health.go | 139 - .../etcd/etcdctl/ctlv2/command/doc.go | 16 - .../etcd/etcdctl/ctlv2/command/error.go | 52 - .../ctlv2/command/exec_watch_command.go | 129 - .../etcd/etcdctl/ctlv2/command/format.go | 60 - .../etcd/etcdctl/ctlv2/command/get_command.go | 66 - .../etcd/etcdctl/ctlv2/command/ls_command.go | 90 - .../etcdctl/ctlv2/command/member_commands.go | 207 - .../etcd/etcdctl/ctlv2/command/mk_command.go | 76 - .../etcdctl/ctlv2/command/mkdir_command.go | 59 - .../etcd/etcdctl/ctlv2/command/rm_command.go | 63 - .../etcdctl/ctlv2/command/rmdir_command.go | 54 - .../etcdctl/ctlv2/command/role_commands.go | 255 - .../etcd/etcdctl/ctlv2/command/set_command.go | 73 - .../etcdctl/ctlv2/command/set_dir_command.go | 36 - .../etcdctl/ctlv2/command/update_command.go | 63 - .../ctlv2/command/update_dir_command.go | 57 - .../etcdctl/ctlv2/command/user_commands.go | 225 - .../etcd/etcdctl/ctlv2/command/util.go | 337 - .../etcdctl/ctlv2/command/watch_command.go | 86 - vendor/go.etcd.io/etcd/etcdctl/ctlv2/ctl.go | 87 - .../go.etcd.io/etcd/etcdctl/ctlv2/ctl_cov.go | 28 - .../etcd/etcdctl/ctlv2/ctl_nocov.go | 27 - .../etcdctl/ctlv3/command/alarm_command.go | 81 - .../etcdctl/ctlv3/command/auth_command.go | 97 - .../etcd/etcdctl/ctlv3/command/check.go | 218 - .../ctlv3/command/compaction_command.go | 62 - .../etcdctl/ctlv3/command/defrag_command.go | 89 - .../etcd/etcdctl/ctlv3/command/del_command.go | 94 - .../etcd/etcdctl/ctlv3/command/doc.go | 16 - .../etcdctl/ctlv3/command/elect_command.go | 137 - .../etcd/etcdctl/ctlv3/command/ep_command.go | 241 - .../etcd/etcdctl/ctlv3/command/error.go | 42 - .../etcd/etcdctl/ctlv3/command/get_command.go | 163 - .../etcd/etcdctl/ctlv3/command/global.go | 412 - .../etcdctl/ctlv3/command/lease_command.go | 207 - .../etcdctl/ctlv3/command/lock_command.go | 113 - .../ctlv3/command/make_mirror_command.go | 177 - .../etcdctl/ctlv3/command/member_command.go | 217 - .../etcdctl/ctlv3/command/migrate_command.go | 402 - .../ctlv3/command/move_leader_command.go | 82 - .../etcd/etcdctl/ctlv3/command/printer.go | 211 - .../etcdctl/ctlv3/command/printer_fields.go | 213 - .../etcdctl/ctlv3/command/printer_json.go | 42 - .../etcdctl/ctlv3/command/printer_protobuf.go | 64 - .../etcdctl/ctlv3/command/printer_simple.go | 271 - .../etcdctl/ctlv3/command/printer_table.go | 66 - .../etcd/etcdctl/ctlv3/command/put_command.go | 118 - .../etcdctl/ctlv3/command/role_command.go | 244 - .../etcdctl/ctlv3/command/snapshot_command.go | 475 - .../etcd/etcdctl/ctlv3/command/txn_command.go | 209 - .../etcdctl/ctlv3/command/user_command.go | 280 - .../etcd/etcdctl/ctlv3/command/util.go | 77 - .../etcdctl/ctlv3/command/version_command.go | 36 - .../etcdctl/ctlv3/command/watch_command.go | 347 - vendor/go.etcd.io/etcd/etcdctl/ctlv3/ctl.go | 97 - .../go.etcd.io/etcd/etcdctl/ctlv3/ctl_cov.go | 34 - .../etcd/etcdctl/ctlv3/ctl_nocov.go | 28 - vendor/go.etcd.io/etcd/etcdctl/ctlv3/help.go | 174 - vendor/go.etcd.io/etcd/etcdmain/config.go | 346 - vendor/go.etcd.io/etcd/etcdmain/doc.go | 16 - vendor/go.etcd.io/etcd/etcdmain/etcd.go | 399 - vendor/go.etcd.io/etcd/etcdmain/gateway.go | 135 - vendor/go.etcd.io/etcd/etcdmain/grpc_proxy.go | 436 - vendor/go.etcd.io/etcd/etcdmain/help.go | 203 - vendor/go.etcd.io/etcd/etcdmain/main.go | 60 - vendor/go.etcd.io/etcd/etcdmain/util.go | 65 - .../etcd/etcdserver/api/capability.go | 87 - .../go.etcd.io/etcd/etcdserver/api/cluster.go | 38 - vendor/go.etcd.io/etcd/etcdserver/api/doc.go | 16 - .../etcd/etcdserver/api/etcdhttp/base.go | 158 - .../etcd/etcdserver/api/etcdhttp/doc.go | 16 - .../etcd/etcdserver/api/etcdhttp/metrics.go | 123 - .../etcd/etcdserver/api/etcdhttp/peer.go | 73 - .../etcd/etcdserver/api/v2http/capability.go | 40 - .../etcd/etcdserver/api/v2http/client.go | 719 - .../etcd/etcdserver/api/v2http/client_auth.go | 543 - .../etcd/etcdserver/api/v2http/doc.go | 16 - .../etcd/etcdserver/api/v2http/http.go | 74 - .../etcdserver/api/v2http/httptypes/errors.go | 56 - .../etcdserver/api/v2http/httptypes/member.go | 69 - .../etcd/etcdserver/api/v2http/metrics.go | 96 - .../etcd/etcdserver/api/v2v3/cluster.go | 31 - .../etcd/etcdserver/api/v2v3/doc.go | 16 - .../etcd/etcdserver/api/v2v3/server.go | 117 - .../etcd/etcdserver/api/v2v3/store.go | 620 - .../etcd/etcdserver/api/v2v3/watcher.go | 140 - .../etcd/etcdserver/api/v3client/doc.go | 45 - .../etcd/etcdserver/api/v3client/v3client.go | 66 - .../etcd/etcdserver/api/v3election/doc.go | 16 - .../etcdserver/api/v3election/election.go | 134 - .../v3electionpb/gw/v3election.pb.gw.go | 313 - .../v3election/v3electionpb/v3election.pb.go | 2079 -- .../etcd/etcdserver/api/v3lock/doc.go | 16 - .../etcd/etcdserver/api/v3lock/lock.go | 56 - .../api/v3lock/v3lockpb/gw/v3lock.pb.gw.go | 167 - .../api/v3lock/v3lockpb/v3lock.pb.go | 959 - .../etcd/etcdserver/api/v3rpc/auth.go | 158 - .../etcd/etcdserver/api/v3rpc/codec.go | 34 - .../etcd/etcdserver/api/v3rpc/grpc.go | 76 - .../etcd/etcdserver/api/v3rpc/header.go | 49 - .../etcd/etcdserver/api/v3rpc/interceptor.go | 263 - .../etcd/etcdserver/api/v3rpc/key.go | 277 - .../etcd/etcdserver/api/v3rpc/lease.go | 148 - .../etcd/etcdserver/api/v3rpc/maintenance.go | 229 - .../etcd/etcdserver/api/v3rpc/member.go | 101 - .../etcd/etcdserver/api/v3rpc/metrics.go | 38 - .../etcd/etcdserver/api/v3rpc/quota.go | 90 - .../etcd/etcdserver/api/v3rpc/rpctypes/doc.go | 16 - .../etcdserver/api/v3rpc/rpctypes/error.go | 215 - .../etcd/etcdserver/api/v3rpc/rpctypes/md.go | 20 - .../etcd/etcdserver/api/v3rpc/util.go | 117 - .../etcd/etcdserver/api/v3rpc/watch.go | 447 - vendor/go.etcd.io/etcd/etcdserver/apply.go | 972 - .../go.etcd.io/etcd/etcdserver/apply_auth.go | 245 - vendor/go.etcd.io/etcd/etcdserver/apply_v2.go | 140 - vendor/go.etcd.io/etcd/etcdserver/backend.go | 81 - .../etcd/etcdserver/cluster_util.go | 258 - vendor/go.etcd.io/etcd/etcdserver/config.go | 282 - .../etcd/etcdserver/consistent_index.go | 33 - vendor/go.etcd.io/etcd/etcdserver/corrupt.go | 262 - vendor/go.etcd.io/etcd/etcdserver/doc.go | 16 - vendor/go.etcd.io/etcd/etcdserver/errors.go | 48 - .../etcdserver/etcdserverpb/etcdserver.pb.go | 1035 - .../etcdserver/etcdserverpb/gw/rpc.pb.gw.go | 2134 -- .../etcdserverpb/raft_internal.pb.go | 2077 -- .../etcdserverpb/raft_internal_stringer.go | 183 - .../etcd/etcdserver/etcdserverpb/rpc.pb.go | 18665 ---------------- vendor/go.etcd.io/etcd/etcdserver/metrics.go | 177 - vendor/go.etcd.io/etcd/etcdserver/quota.go | 124 - vendor/go.etcd.io/etcd/etcdserver/raft.go | 608 - vendor/go.etcd.io/etcd/etcdserver/server.go | 1745 -- .../etcd/etcdserver/snapshot_merge.go | 73 - vendor/go.etcd.io/etcd/etcdserver/storage.go | 98 - vendor/go.etcd.io/etcd/etcdserver/util.go | 155 - .../go.etcd.io/etcd/etcdserver/v2_server.go | 165 - .../go.etcd.io/etcd/etcdserver/v3_server.go | 720 - .../go.etcd.io/etcd/functional/agent/doc.go | 16 - .../etcd/functional/agent/handler.go | 698 - .../etcd/functional/agent/server.go | 166 - .../go.etcd.io/etcd/functional/agent/utils.go | 110 - .../etcd/functional/rpcpb/etcd_config.go | 99 - .../etcd/functional/rpcpb/member.go | 361 - .../etcd/functional/rpcpb/rpc.pb.go | 5112 ----- .../functional/runner/election_command.go | 144 - .../etcd/functional/runner/error.go | 42 - .../etcd/functional/runner/global.go | 114 - .../go.etcd.io/etcd/functional/runner/help.go | 175 - .../runner/lease_renewer_command.go | 91 - .../functional/runner/lock_racer_command.go | 94 - .../go.etcd.io/etcd/functional/runner/root.go | 70 - .../etcd/functional/runner/watch_command.go | 210 - .../go.etcd.io/etcd/functional/tester/case.go | 327 - .../etcd/functional/tester/case_delay.go | 41 - .../etcd/functional/tester/case_external.go | 55 - .../etcd/functional/tester/case_failpoints.go | 181 - .../tester/case_network_blackhole.go | 104 - .../functional/tester/case_network_delay.go | 156 - .../etcd/functional/tester/case_no_fail.go | 99 - .../functional/tester/case_sigquit_remove.go | 229 - .../tester/case_sigquit_remove_quorum.go | 275 - .../etcd/functional/tester/case_sigterm.go | 92 - .../etcd/functional/tester/checker.go | 28 - .../etcd/functional/tester/checker_kv_hash.go | 89 - .../functional/tester/checker_lease_expire.go | 238 - .../functional/tester/checker_no_check.go | 24 - .../etcd/functional/tester/checker_runner.go | 48 - .../etcd/functional/tester/cluster.go | 761 - .../functional/tester/cluster_read_config.go | 358 - .../etcd/functional/tester/cluster_run.go | 373 - .../etcd/functional/tester/cluster_shuffle.go | 64 - .../go.etcd.io/etcd/functional/tester/doc.go | 16 - .../etcd/functional/tester/metrics_report.go | 83 - .../etcd/functional/tester/stresser.go | 156 - .../functional/tester/stresser_composite.go | 82 - .../etcd/functional/tester/stresser_key.go | 344 - .../etcd/functional/tester/stresser_lease.go | 487 - .../etcd/functional/tester/stresser_runner.go | 120 - .../etcd/functional/tester/utils.go | 79 - vendor/go.etcd.io/etcd/integration/bridge.go | 228 - vendor/go.etcd.io/etcd/integration/cluster.go | 1105 - .../etcd/integration/cluster_direct.go | 41 - .../etcd/integration/cluster_proxy.go | 115 - vendor/go.etcd.io/etcd/integration/doc.go | 25 - vendor/go.etcd.io/etcd/lease/doc.go | 16 - vendor/go.etcd.io/etcd/lease/leasehttp/doc.go | 16 - .../go.etcd.io/etcd/lease/leasehttp/http.go | 247 - .../go.etcd.io/etcd/lease/leasepb/lease.pb.go | 591 - vendor/go.etcd.io/etcd/lease/lessor.go | 680 - .../go.etcd.io/etcd/mvcc/backend/backend.go | 464 - .../go.etcd.io/etcd/mvcc/backend/batch_tx.go | 254 - .../etcd/mvcc/backend/config_default.go | 23 - .../etcd/mvcc/backend/config_linux.go | 34 - .../etcd/mvcc/backend/config_windows.go | 26 - vendor/go.etcd.io/etcd/mvcc/backend/doc.go | 16 - .../go.etcd.io/etcd/mvcc/backend/metrics.go | 59 - .../go.etcd.io/etcd/mvcc/backend/read_tx.go | 120 - .../go.etcd.io/etcd/mvcc/backend/tx_buffer.go | 181 - vendor/go.etcd.io/etcd/mvcc/doc.go | 16 - vendor/go.etcd.io/etcd/mvcc/index.go | 251 - vendor/go.etcd.io/etcd/mvcc/key_index.go | 356 - vendor/go.etcd.io/etcd/mvcc/kv.go | 149 - vendor/go.etcd.io/etcd/mvcc/kv_view.go | 53 - vendor/go.etcd.io/etcd/mvcc/kvstore.go | 510 - .../etcd/mvcc/kvstore_compaction.go | 69 - vendor/go.etcd.io/etcd/mvcc/kvstore_txn.go | 253 - vendor/go.etcd.io/etcd/mvcc/metrics.go | 239 - vendor/go.etcd.io/etcd/mvcc/metrics_txn.go | 59 - vendor/go.etcd.io/etcd/mvcc/mvccpb/kv.pb.go | 718 - vendor/go.etcd.io/etcd/mvcc/revision.go | 67 - vendor/go.etcd.io/etcd/mvcc/util.go | 56 - .../go.etcd.io/etcd/mvcc/watchable_store.go | 534 - .../etcd/mvcc/watchable_store_txn.go | 53 - vendor/go.etcd.io/etcd/mvcc/watcher.go | 180 - vendor/go.etcd.io/etcd/mvcc/watcher_group.go | 292 - vendor/go.etcd.io/etcd/pkg/adt/doc.go | 16 - .../go.etcd.io/etcd/pkg/adt/interval_tree.go | 599 - .../etcd/pkg/contention/contention.go | 69 - vendor/go.etcd.io/etcd/pkg/contention/doc.go | 16 - vendor/go.etcd.io/etcd/pkg/cpuutil/doc.go | 16 - vendor/go.etcd.io/etcd/pkg/cpuutil/endian.go | 36 - vendor/go.etcd.io/etcd/pkg/crc/crc.go | 43 - vendor/go.etcd.io/etcd/pkg/debugutil/doc.go | 16 - vendor/go.etcd.io/etcd/pkg/debugutil/pprof.go | 47 - vendor/go.etcd.io/etcd/pkg/expect/expect.go | 169 - .../go.etcd.io/etcd/pkg/fileutil/dir_unix.go | 22 - .../etcd/pkg/fileutil/dir_windows.go | 46 - .../go.etcd.io/etcd/pkg/fileutil/fileutil.go | 122 - vendor/go.etcd.io/etcd/pkg/fileutil/lock.go | 26 - .../etcd/pkg/fileutil/lock_flock.go | 49 - .../etcd/pkg/fileutil/lock_linux.go | 97 - .../etcd/pkg/fileutil/lock_plan9.go | 45 - .../etcd/pkg/fileutil/lock_solaris.go | 62 - .../go.etcd.io/etcd/pkg/fileutil/lock_unix.go | 29 - .../etcd/pkg/fileutil/lock_windows.go | 125 - .../etcd/pkg/fileutil/preallocate.go | 54 - .../etcd/pkg/fileutil/preallocate_darwin.go | 65 - .../etcd/pkg/fileutil/preallocate_unix.go | 49 - .../pkg/fileutil/preallocate_unsupported.go | 25 - vendor/go.etcd.io/etcd/pkg/fileutil/purge.go | 78 - vendor/go.etcd.io/etcd/pkg/fileutil/sync.go | 29 - .../etcd/pkg/fileutil/sync_darwin.go | 40 - .../etcd/pkg/fileutil/sync_linux.go | 34 - vendor/go.etcd.io/etcd/pkg/flags/flag.go | 166 - vendor/go.etcd.io/etcd/pkg/flags/strings.go | 85 - vendor/go.etcd.io/etcd/pkg/flags/urls.go | 52 - .../go.etcd.io/etcd/pkg/httputil/httputil.go | 22 - vendor/go.etcd.io/etcd/pkg/idutil/id.go | 78 - .../go.etcd.io/etcd/pkg/ioutil/pagewriter.go | 106 - .../go.etcd.io/etcd/pkg/ioutil/readcloser.go | 66 - vendor/go.etcd.io/etcd/pkg/ioutil/reader.go | 40 - vendor/go.etcd.io/etcd/pkg/ioutil/util.go | 43 - .../etcd/pkg/logutil/merge_logger.go | 195 - .../etcd/pkg/mock/mockstorage/doc.go | 16 - .../pkg/mock/mockstorage/storage_recorder.go | 48 - .../go.etcd.io/etcd/pkg/mock/mockstore/doc.go | 16 - .../etcd/pkg/mock/mockstore/store_recorder.go | 157 - .../go.etcd.io/etcd/pkg/mock/mockwait/doc.go | 16 - .../etcd/pkg/mock/mockwait/wait_recorder.go | 47 - .../etcd/pkg/netutil/isolate_linux.go | 82 - .../etcd/pkg/netutil/isolate_stub.go | 25 - vendor/go.etcd.io/etcd/pkg/netutil/netutil.go | 187 - vendor/go.etcd.io/etcd/pkg/netutil/routes.go | 33 - .../etcd/pkg/netutil/routes_linux.go | 250 - .../etcd/pkg/osutil/interrupt_unix.go | 80 - .../etcd/pkg/osutil/interrupt_windows.go | 32 - vendor/go.etcd.io/etcd/pkg/osutil/osutil.go | 45 - vendor/go.etcd.io/etcd/pkg/osutil/signal.go | 21 - .../etcd/pkg/osutil/signal_linux.go | 30 - vendor/go.etcd.io/etcd/pkg/pathutil/path.go | 31 - vendor/go.etcd.io/etcd/pkg/pbutil/pbutil.go | 60 - vendor/go.etcd.io/etcd/pkg/proxy/doc.go | 16 - vendor/go.etcd.io/etcd/pkg/proxy/server.go | 949 - vendor/go.etcd.io/etcd/pkg/report/doc.go | 16 - vendor/go.etcd.io/etcd/pkg/report/report.go | 278 - .../go.etcd.io/etcd/pkg/report/timeseries.go | 160 - vendor/go.etcd.io/etcd/pkg/report/weighted.go | 101 - .../go.etcd.io/etcd/pkg/runtime/fds_linux.go | 37 - .../go.etcd.io/etcd/pkg/runtime/fds_other.go | 30 - vendor/go.etcd.io/etcd/pkg/schedule/doc.go | 16 - .../go.etcd.io/etcd/pkg/schedule/schedule.go | 165 - vendor/go.etcd.io/etcd/pkg/srv/srv.go | 141 - .../etcd/pkg/stringutil/stringutil.go | 55 - vendor/go.etcd.io/etcd/pkg/testutil/assert.go | 62 - vendor/go.etcd.io/etcd/pkg/testutil/leak.go | 139 - .../etcd/pkg/testutil/pauseable_handler.go | 57 - .../go.etcd.io/etcd/pkg/testutil/recorder.go | 132 - .../go.etcd.io/etcd/pkg/testutil/testutil.go | 84 - .../etcd/pkg/tlsutil/cipher_suites.go | 51 - vendor/go.etcd.io/etcd/pkg/tlsutil/doc.go | 16 - vendor/go.etcd.io/etcd/pkg/tlsutil/tlsutil.go | 72 - vendor/go.etcd.io/etcd/pkg/transport/doc.go | 17 - .../etcd/pkg/transport/keepalive_listener.go | 94 - .../etcd/pkg/transport/limit_listen.go | 80 - .../go.etcd.io/etcd/pkg/transport/listener.go | 289 - .../etcd/pkg/transport/listener_tls.go | 272 - .../etcd/pkg/transport/timeout_conn.go | 44 - .../etcd/pkg/transport/timeout_dialer.go | 36 - .../etcd/pkg/transport/timeout_listener.go | 57 - .../etcd/pkg/transport/timeout_transport.go | 51 - vendor/go.etcd.io/etcd/pkg/transport/tls.go | 49 - .../etcd/pkg/transport/transport.go | 71 - .../etcd/pkg/transport/unix_listener.go | 40 - vendor/go.etcd.io/etcd/pkg/types/doc.go | 17 - vendor/go.etcd.io/etcd/pkg/types/id.go | 41 - vendor/go.etcd.io/etcd/pkg/types/set.go | 178 - vendor/go.etcd.io/etcd/pkg/types/slice.go | 22 - vendor/go.etcd.io/etcd/pkg/types/urls.go | 82 - vendor/go.etcd.io/etcd/pkg/types/urlsmap.go | 107 - vendor/go.etcd.io/etcd/pkg/wait/wait.go | 91 - vendor/go.etcd.io/etcd/pkg/wait/wait_time.go | 66 - .../grpcproxy/adapter/auth_client_adapter.go | 93 - .../proxy/grpcproxy/adapter/chan_stream.go | 165 - .../adapter/cluster_client_adapter.go | 45 - .../etcd/proxy/grpcproxy/adapter/doc.go | 17 - .../adapter/election_client_adapter.go | 80 - .../grpcproxy/adapter/kv_client_adapter.go | 49 - .../grpcproxy/adapter/lease_client_adapter.go | 82 - .../grpcproxy/adapter/lock_client_adapter.go | 37 - .../adapter/maintenance_client_adapter.go | 88 - .../grpcproxy/adapter/watch_client_adapter.go | 66 - .../go.etcd.io/etcd/proxy/grpcproxy/auth.go | 110 - .../etcd/proxy/grpcproxy/cache/store.go | 171 - .../etcd/proxy/grpcproxy/cluster.go | 177 - vendor/go.etcd.io/etcd/proxy/grpcproxy/doc.go | 16 - .../etcd/proxy/grpcproxy/election.go | 65 - .../go.etcd.io/etcd/proxy/grpcproxy/health.go | 41 - vendor/go.etcd.io/etcd/proxy/grpcproxy/kv.go | 232 - .../go.etcd.io/etcd/proxy/grpcproxy/leader.go | 115 - .../go.etcd.io/etcd/proxy/grpcproxy/lease.go | 382 - .../go.etcd.io/etcd/proxy/grpcproxy/lock.go | 38 - .../go.etcd.io/etcd/proxy/grpcproxy/logger.go | 19 - .../etcd/proxy/grpcproxy/maintenance.go | 90 - .../etcd/proxy/grpcproxy/metrics.go | 114 - .../etcd/proxy/grpcproxy/register.go | 94 - .../go.etcd.io/etcd/proxy/grpcproxy/util.go | 73 - .../go.etcd.io/etcd/proxy/grpcproxy/watch.go | 298 - .../etcd/proxy/grpcproxy/watch_broadcast.go | 152 - .../etcd/proxy/grpcproxy/watch_broadcasts.go | 135 - .../etcd/proxy/grpcproxy/watch_ranges.go | 69 - .../etcd/proxy/grpcproxy/watcher.go | 129 - .../etcd/proxy/httpproxy/director.go | 158 - vendor/go.etcd.io/etcd/proxy/httpproxy/doc.go | 18 - .../etcd/proxy/httpproxy/metrics.go | 88 - .../go.etcd.io/etcd/proxy/httpproxy/proxy.go | 116 - .../etcd/proxy/httpproxy/reverse.go | 208 - vendor/go.etcd.io/etcd/proxy/tcpproxy/doc.go | 16 - .../etcd/proxy/tcpproxy/userspace.go | 226 - vendor/go.etcd.io/etcd/raft/doc.go | 300 - vendor/go.etcd.io/etcd/raft/log.go | 358 - vendor/go.etcd.io/etcd/raft/log_unstable.go | 159 - vendor/go.etcd.io/etcd/raft/logger.go | 126 - vendor/go.etcd.io/etcd/raft/node.go | 539 - vendor/go.etcd.io/etcd/raft/progress.go | 284 - vendor/go.etcd.io/etcd/raft/raft.go | 1406 -- vendor/go.etcd.io/etcd/raft/raftpb/raft.pb.go | 2004 -- vendor/go.etcd.io/etcd/raft/rawnode.go | 266 - vendor/go.etcd.io/etcd/raft/read_only.go | 118 - vendor/go.etcd.io/etcd/raft/status.go | 88 - vendor/go.etcd.io/etcd/raft/storage.go | 271 - vendor/go.etcd.io/etcd/raft/util.go | 129 - vendor/go.etcd.io/etcd/version/version.go | 56 - vendor/go.etcd.io/etcd/wal/decoder.go | 188 - vendor/go.etcd.io/etcd/wal/doc.go | 75 - vendor/go.etcd.io/etcd/wal/encoder.go | 120 - vendor/go.etcd.io/etcd/wal/file_pipeline.go | 97 - vendor/go.etcd.io/etcd/wal/metrics.go | 31 - vendor/go.etcd.io/etcd/wal/repair.go | 99 - vendor/go.etcd.io/etcd/wal/util.go | 107 - vendor/go.etcd.io/etcd/wal/wal.go | 772 - vendor/go.etcd.io/etcd/wal/walpb/record.go | 29 - vendor/go.etcd.io/etcd/wal/walpb/record.pb.go | 504 - 881 files changed, 211162 deletions(-) delete mode 100644 vendor/github.com/coreos/etcd/LICENSE delete mode 100644 vendor/github.com/coreos/etcd/NOTICE delete mode 100644 vendor/github.com/coreos/etcd/alarm/alarms.go delete mode 100644 vendor/github.com/coreos/etcd/auth/authpb/auth.pb.go delete mode 100644 vendor/github.com/coreos/etcd/auth/doc.go delete mode 100644 vendor/github.com/coreos/etcd/auth/jwt.go delete mode 100644 vendor/github.com/coreos/etcd/auth/nop.go delete mode 100644 vendor/github.com/coreos/etcd/auth/range_perm_cache.go delete mode 100644 vendor/github.com/coreos/etcd/auth/simple_token.go delete mode 100644 vendor/github.com/coreos/etcd/auth/store.go delete mode 100644 vendor/github.com/coreos/etcd/client/auth_role.go delete mode 100644 vendor/github.com/coreos/etcd/client/auth_user.go delete mode 100644 vendor/github.com/coreos/etcd/client/cancelreq.go delete mode 100644 vendor/github.com/coreos/etcd/client/client.go delete mode 100644 vendor/github.com/coreos/etcd/client/cluster_error.go delete mode 100644 vendor/github.com/coreos/etcd/client/curl.go delete mode 100644 vendor/github.com/coreos/etcd/client/discover.go delete mode 100644 vendor/github.com/coreos/etcd/client/doc.go delete mode 100644 vendor/github.com/coreos/etcd/client/json.go delete mode 100644 vendor/github.com/coreos/etcd/client/keys.go delete mode 100644 vendor/github.com/coreos/etcd/client/members.go delete mode 100644 vendor/github.com/coreos/etcd/client/util.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/auth.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/client.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/cluster.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/compact_op.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/compare.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/concurrency/doc.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/concurrency/election.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/concurrency/key.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/concurrency/mutex.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/concurrency/session.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/concurrency/stm.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/config.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/doc.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/health_balancer.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/kv.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/lease.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/leasing/cache.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/leasing/doc.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/leasing/kv.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/leasing/txn.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/leasing/util.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/logger.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/maintenance.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/mirror/syncer.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/namespace/doc.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/namespace/kv.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/namespace/lease.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/namespace/util.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/namespace/watch.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/naming/doc.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/naming/grpc.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/op.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/options.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/ordering/doc.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/ordering/kv.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/ordering/util.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/ready_wait.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/retry.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/sort.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/txn.go delete mode 100644 vendor/github.com/coreos/etcd/clientv3/watch.go delete mode 100644 vendor/github.com/coreos/etcd/compactor/compactor.go delete mode 100644 vendor/github.com/coreos/etcd/compactor/doc.go delete mode 100644 vendor/github.com/coreos/etcd/compactor/periodic.go delete mode 100644 vendor/github.com/coreos/etcd/compactor/revision.go delete mode 100644 vendor/github.com/coreos/etcd/discovery/discovery.go delete mode 100644 vendor/github.com/coreos/etcd/embed/config.go delete mode 100644 vendor/github.com/coreos/etcd/embed/doc.go delete mode 100644 vendor/github.com/coreos/etcd/embed/etcd.go delete mode 100644 vendor/github.com/coreos/etcd/embed/serve.go delete mode 100644 vendor/github.com/coreos/etcd/embed/util.go delete mode 100644 vendor/github.com/coreos/etcd/error/error.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/auth_commands.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/backup_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/cluster_health.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/doc.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/error.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/exec_watch_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/format.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/get_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/ls_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/member_commands.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/mk_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/mkdir_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/rm_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/rmdir_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/role_commands.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/set_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/set_dir_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/update_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/update_dir_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/user_commands.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/util.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/watch_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/alarm_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/auth_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/check.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/compaction_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/defrag_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/del_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/doc.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/elect_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/ep_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/error.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/get_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/global.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/lease_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/lock_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/make_mirror_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/member_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/migrate_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/move_leader_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_fields.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_json.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_protobuf.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_simple.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_table.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/put_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/role_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/snapshot_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/txn_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/user_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/util.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/version_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/watch_command.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/capability.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/cluster.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/doc.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/etcdhttp/base.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/etcdhttp/doc.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/etcdhttp/metrics.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/etcdhttp/peer.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v2http/capability.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v2http/client.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v2http/client_auth.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v2http/doc.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v2http/http.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v2http/httptypes/errors.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v2http/httptypes/member.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v2http/metrics.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v2v3/cluster.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v2v3/doc.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v2v3/server.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v2v3/store.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v2v3/watcher.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3client/doc.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3client/v3client.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3election/doc.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3election/election.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb/gw/v3election.pb.gw.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb/v3election.pb.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3lock/doc.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3lock/lock.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb/gw/v3lock.pb.gw.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb/v3lock.pb.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/auth.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/codec.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/grpc.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/header.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/interceptor.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/key.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/lease.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/maintenance.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/member.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/metrics.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/quota.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes/doc.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes/error.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes/md.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/util.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/watch.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/apply.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/apply_auth.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/apply_v2.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/auth/auth.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/auth/auth_requests.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/backend.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/cluster_util.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/config.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/consistent_index.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/corrupt.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/doc.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/errors.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/etcdserver.pb.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/gw/rpc.pb.gw.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/raft_internal.pb.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/raft_internal_stringer.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/rpc.pb.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/membership/cluster.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/membership/doc.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/membership/errors.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/membership/member.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/membership/store.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/metrics.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/quota.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/raft.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/server.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/snapshot_merge.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/stats/leader.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/stats/queue.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/stats/server.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/stats/stats.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/storage.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/util.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/v2_server.go delete mode 100644 vendor/github.com/coreos/etcd/etcdserver/v3_server.go delete mode 100644 vendor/github.com/coreos/etcd/functional/rpcpb/etcd_config.go delete mode 100644 vendor/github.com/coreos/etcd/functional/rpcpb/member.go delete mode 100644 vendor/github.com/coreos/etcd/functional/rpcpb/rpc.pb.go delete mode 100644 vendor/github.com/coreos/etcd/lease/doc.go delete mode 100644 vendor/github.com/coreos/etcd/lease/leasehttp/doc.go delete mode 100644 vendor/github.com/coreos/etcd/lease/leasehttp/http.go delete mode 100644 vendor/github.com/coreos/etcd/lease/leasepb/lease.pb.go delete mode 100644 vendor/github.com/coreos/etcd/lease/lessor.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/backend/backend.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/backend/batch_tx.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/backend/config_default.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/backend/config_linux.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/backend/config_windows.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/backend/doc.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/backend/metrics.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/backend/read_tx.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/backend/tx_buffer.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/doc.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/index.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/key_index.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/kv.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/kv_view.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/kvstore.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/kvstore_compaction.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/kvstore_txn.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/metrics.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/metrics_txn.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/mvccpb/kv.pb.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/revision.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/util.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/watchable_store.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/watchable_store_txn.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/watcher.go delete mode 100644 vendor/github.com/coreos/etcd/mvcc/watcher_group.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/adt/doc.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/adt/interval_tree.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/contention/contention.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/contention/doc.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/cors/cors.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/cpuutil/doc.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/cpuutil/endian.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/crc/crc.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/debugutil/doc.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/debugutil/pprof.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/fileutil/dir_unix.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/fileutil/dir_windows.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/fileutil/fileutil.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/fileutil/lock.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/fileutil/lock_flock.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/fileutil/lock_linux.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/fileutil/lock_plan9.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/fileutil/lock_solaris.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/fileutil/lock_unix.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/fileutil/lock_windows.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/fileutil/preallocate.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/fileutil/preallocate_darwin.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/fileutil/preallocate_unix.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/fileutil/preallocate_unsupported.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/fileutil/purge.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/fileutil/sync.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/fileutil/sync_darwin.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/fileutil/sync_linux.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/flags/flag.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/flags/strings.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/flags/urls.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/httputil/httputil.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/idutil/id.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/ioutil/pagewriter.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/ioutil/readcloser.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/ioutil/reader.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/ioutil/util.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/logutil/merge_logger.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/netutil/isolate_linux.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/netutil/isolate_stub.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/netutil/netutil.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/netutil/routes.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/netutil/routes_linux.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/osutil/interrupt_unix.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/osutil/interrupt_windows.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/osutil/osutil.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/osutil/signal.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/osutil/signal_linux.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/pathutil/path.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/pbutil/pbutil.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/proxy/doc.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/proxy/server.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/report/doc.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/report/report.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/report/timeseries.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/report/weighted.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/runtime/fds_linux.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/runtime/fds_other.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/schedule/doc.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/schedule/schedule.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/srv/srv.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/stringutil/stringutil.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/testutil/assert.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/testutil/leak.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/testutil/pauseable_handler.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/testutil/recorder.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/testutil/testutil.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/tlsutil/cipher_suites.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/tlsutil/doc.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/tlsutil/tlsutil.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/transport/doc.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/transport/keepalive_listener.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/transport/limit_listen.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/transport/listener.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/transport/listener_tls.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/transport/timeout_conn.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/transport/timeout_dialer.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/transport/timeout_listener.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/transport/timeout_transport.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/transport/tls.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/transport/transport.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/transport/unix_listener.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/types/doc.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/types/id.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/types/set.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/types/slice.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/types/urls.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/types/urlsmap.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/wait/wait.go delete mode 100644 vendor/github.com/coreos/etcd/pkg/wait/wait_time.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/auth_client_adapter.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/chan_stream.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/cluster_client_adapter.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/doc.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/election_client_adapter.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/kv_client_adapter.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/lease_client_adapter.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/lock_client_adapter.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/maintenance_client_adapter.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/watch_client_adapter.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/auth.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/cache/store.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/cluster.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/doc.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/election.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/health.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/kv.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/leader.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/lease.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/lock.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/logger.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/maintenance.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/metrics.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/register.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/util.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/watch.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/watch_broadcast.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/watch_broadcasts.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/watch_ranges.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/grpcproxy/watcher.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/httpproxy/director.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/httpproxy/doc.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/httpproxy/metrics.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/httpproxy/proxy.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/httpproxy/reverse.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/tcpproxy/doc.go delete mode 100644 vendor/github.com/coreos/etcd/proxy/tcpproxy/userspace.go delete mode 100644 vendor/github.com/coreos/etcd/raft/doc.go delete mode 100644 vendor/github.com/coreos/etcd/raft/log.go delete mode 100644 vendor/github.com/coreos/etcd/raft/log_unstable.go delete mode 100644 vendor/github.com/coreos/etcd/raft/logger.go delete mode 100644 vendor/github.com/coreos/etcd/raft/node.go delete mode 100644 vendor/github.com/coreos/etcd/raft/progress.go delete mode 100644 vendor/github.com/coreos/etcd/raft/raft.go delete mode 100644 vendor/github.com/coreos/etcd/raft/raftpb/raft.pb.go delete mode 100644 vendor/github.com/coreos/etcd/raft/rawnode.go delete mode 100644 vendor/github.com/coreos/etcd/raft/read_only.go delete mode 100644 vendor/github.com/coreos/etcd/raft/status.go delete mode 100644 vendor/github.com/coreos/etcd/raft/storage.go delete mode 100644 vendor/github.com/coreos/etcd/raft/util.go delete mode 100644 vendor/github.com/coreos/etcd/rafthttp/coder.go delete mode 100644 vendor/github.com/coreos/etcd/rafthttp/doc.go delete mode 100644 vendor/github.com/coreos/etcd/rafthttp/http.go delete mode 100644 vendor/github.com/coreos/etcd/rafthttp/metrics.go delete mode 100644 vendor/github.com/coreos/etcd/rafthttp/msg_codec.go delete mode 100644 vendor/github.com/coreos/etcd/rafthttp/msgappv2_codec.go delete mode 100644 vendor/github.com/coreos/etcd/rafthttp/peer.go delete mode 100644 vendor/github.com/coreos/etcd/rafthttp/peer_status.go delete mode 100644 vendor/github.com/coreos/etcd/rafthttp/pipeline.go delete mode 100644 vendor/github.com/coreos/etcd/rafthttp/probing_status.go delete mode 100644 vendor/github.com/coreos/etcd/rafthttp/remote.go delete mode 100644 vendor/github.com/coreos/etcd/rafthttp/snapshot_sender.go delete mode 100644 vendor/github.com/coreos/etcd/rafthttp/stream.go delete mode 100644 vendor/github.com/coreos/etcd/rafthttp/transport.go delete mode 100644 vendor/github.com/coreos/etcd/rafthttp/urlpick.go delete mode 100644 vendor/github.com/coreos/etcd/rafthttp/util.go delete mode 100644 vendor/github.com/coreos/etcd/snap/db.go delete mode 100644 vendor/github.com/coreos/etcd/snap/message.go delete mode 100644 vendor/github.com/coreos/etcd/snap/metrics.go delete mode 100644 vendor/github.com/coreos/etcd/snap/snappb/snap.pb.go delete mode 100644 vendor/github.com/coreos/etcd/snap/snapshotter.go delete mode 100644 vendor/github.com/coreos/etcd/snapshot/doc.go delete mode 100644 vendor/github.com/coreos/etcd/snapshot/util.go delete mode 100644 vendor/github.com/coreos/etcd/snapshot/v3_snapshot.go delete mode 100644 vendor/github.com/coreos/etcd/store/doc.go delete mode 100644 vendor/github.com/coreos/etcd/store/event.go delete mode 100644 vendor/github.com/coreos/etcd/store/event_history.go delete mode 100644 vendor/github.com/coreos/etcd/store/event_queue.go delete mode 100644 vendor/github.com/coreos/etcd/store/metrics.go delete mode 100644 vendor/github.com/coreos/etcd/store/node.go delete mode 100644 vendor/github.com/coreos/etcd/store/node_extern.go delete mode 100644 vendor/github.com/coreos/etcd/store/stats.go delete mode 100644 vendor/github.com/coreos/etcd/store/store.go delete mode 100644 vendor/github.com/coreos/etcd/store/ttl_key_heap.go delete mode 100644 vendor/github.com/coreos/etcd/store/watcher.go delete mode 100644 vendor/github.com/coreos/etcd/store/watcher_hub.go delete mode 100644 vendor/github.com/coreos/etcd/version/version.go delete mode 100644 vendor/github.com/coreos/etcd/wal/decoder.go delete mode 100644 vendor/github.com/coreos/etcd/wal/doc.go delete mode 100644 vendor/github.com/coreos/etcd/wal/encoder.go delete mode 100644 vendor/github.com/coreos/etcd/wal/file_pipeline.go delete mode 100644 vendor/github.com/coreos/etcd/wal/metrics.go delete mode 100644 vendor/github.com/coreos/etcd/wal/repair.go delete mode 100644 vendor/github.com/coreos/etcd/wal/util.go delete mode 100644 vendor/github.com/coreos/etcd/wal/wal.go delete mode 100644 vendor/github.com/coreos/etcd/wal/walpb/record.go delete mode 100644 vendor/github.com/coreos/etcd/wal/walpb/record.pb.go delete mode 100644 vendor/go.etcd.io/etcd/LICENSE delete mode 100644 vendor/go.etcd.io/etcd/NOTICE delete mode 100644 vendor/go.etcd.io/etcd/auth/authpb/auth.pb.go delete mode 100644 vendor/go.etcd.io/etcd/auth/doc.go delete mode 100644 vendor/go.etcd.io/etcd/auth/jwt.go delete mode 100644 vendor/go.etcd.io/etcd/auth/nop.go delete mode 100644 vendor/go.etcd.io/etcd/auth/range_perm_cache.go delete mode 100644 vendor/go.etcd.io/etcd/auth/simple_token.go delete mode 100644 vendor/go.etcd.io/etcd/auth/store.go delete mode 100644 vendor/go.etcd.io/etcd/client/auth_role.go delete mode 100644 vendor/go.etcd.io/etcd/client/auth_user.go delete mode 100644 vendor/go.etcd.io/etcd/client/cancelreq.go delete mode 100644 vendor/go.etcd.io/etcd/client/client.go delete mode 100644 vendor/go.etcd.io/etcd/client/cluster_error.go delete mode 100644 vendor/go.etcd.io/etcd/client/curl.go delete mode 100644 vendor/go.etcd.io/etcd/client/discover.go delete mode 100644 vendor/go.etcd.io/etcd/client/doc.go delete mode 100644 vendor/go.etcd.io/etcd/client/json.go delete mode 100644 vendor/go.etcd.io/etcd/client/keys.go delete mode 100644 vendor/go.etcd.io/etcd/client/members.go delete mode 100644 vendor/go.etcd.io/etcd/client/util.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/auth.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/client.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/clientv3util/util.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/cluster.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/compact_op.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/compare.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/concurrency/doc.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/concurrency/election.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/concurrency/key.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/concurrency/mutex.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/concurrency/session.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/concurrency/stm.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/config.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/doc.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/health_balancer.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/kv.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/lease.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/leasing/cache.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/leasing/doc.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/leasing/kv.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/leasing/txn.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/leasing/util.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/logger.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/maintenance.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/mirror/syncer.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/namespace/doc.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/namespace/kv.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/namespace/lease.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/namespace/util.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/namespace/watch.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/naming/doc.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/naming/grpc.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/op.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/options.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/ordering/doc.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/ordering/kv.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/ordering/util.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/ready_wait.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/retry.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/sort.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/txn.go delete mode 100644 vendor/go.etcd.io/etcd/clientv3/watch.go delete mode 100644 vendor/go.etcd.io/etcd/contrib/recipes/barrier.go delete mode 100644 vendor/go.etcd.io/etcd/contrib/recipes/client.go delete mode 100644 vendor/go.etcd.io/etcd/contrib/recipes/doc.go delete mode 100644 vendor/go.etcd.io/etcd/contrib/recipes/double_barrier.go delete mode 100644 vendor/go.etcd.io/etcd/contrib/recipes/key.go delete mode 100644 vendor/go.etcd.io/etcd/contrib/recipes/priority_queue.go delete mode 100644 vendor/go.etcd.io/etcd/contrib/recipes/queue.go delete mode 100644 vendor/go.etcd.io/etcd/contrib/recipes/rwmutex.go delete mode 100644 vendor/go.etcd.io/etcd/contrib/recipes/watch.go delete mode 100644 vendor/go.etcd.io/etcd/embed/config.go delete mode 100644 vendor/go.etcd.io/etcd/embed/doc.go delete mode 100644 vendor/go.etcd.io/etcd/embed/etcd.go delete mode 100644 vendor/go.etcd.io/etcd/embed/serve.go delete mode 100644 vendor/go.etcd.io/etcd/embed/util.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/auth_commands.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/backup_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/cluster_health.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/doc.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/error.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/exec_watch_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/format.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/get_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/ls_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/member_commands.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/mk_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/mkdir_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/rm_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/rmdir_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/role_commands.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/set_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/set_dir_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/update_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/update_dir_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/user_commands.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/util.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/watch_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/ctl.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/ctl_cov.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv2/ctl_nocov.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/alarm_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/auth_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/check.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/compaction_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/defrag_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/del_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/doc.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/elect_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/ep_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/error.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/get_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/global.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/lease_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/lock_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/make_mirror_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/member_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/migrate_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/move_leader_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_fields.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_json.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_protobuf.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_simple.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_table.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/put_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/role_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/snapshot_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/txn_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/user_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/util.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/version_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/watch_command.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/ctl.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/ctl_cov.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/ctl_nocov.go delete mode 100644 vendor/go.etcd.io/etcd/etcdctl/ctlv3/help.go delete mode 100644 vendor/go.etcd.io/etcd/etcdmain/config.go delete mode 100644 vendor/go.etcd.io/etcd/etcdmain/doc.go delete mode 100644 vendor/go.etcd.io/etcd/etcdmain/etcd.go delete mode 100644 vendor/go.etcd.io/etcd/etcdmain/gateway.go delete mode 100644 vendor/go.etcd.io/etcd/etcdmain/grpc_proxy.go delete mode 100644 vendor/go.etcd.io/etcd/etcdmain/help.go delete mode 100644 vendor/go.etcd.io/etcd/etcdmain/main.go delete mode 100644 vendor/go.etcd.io/etcd/etcdmain/util.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/capability.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/cluster.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/doc.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/etcdhttp/base.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/etcdhttp/doc.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/etcdhttp/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/etcdhttp/peer.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v2http/capability.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v2http/client.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v2http/client_auth.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v2http/doc.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v2http/http.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v2http/httptypes/errors.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v2http/httptypes/member.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v2http/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v2v3/cluster.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v2v3/doc.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v2v3/server.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v2v3/store.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v2v3/watcher.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3client/doc.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3client/v3client.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3election/doc.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3election/election.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3election/v3electionpb/gw/v3election.pb.gw.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3election/v3electionpb/v3election.pb.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3lock/doc.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3lock/lock.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3lock/v3lockpb/gw/v3lock.pb.gw.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3lock/v3lockpb/v3lock.pb.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/auth.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/codec.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/grpc.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/header.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/interceptor.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/key.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/lease.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/maintenance.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/member.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/quota.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes/doc.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes/error.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes/md.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/util.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/watch.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/apply.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/apply_auth.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/apply_v2.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/backend.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/cluster_util.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/config.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/consistent_index.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/corrupt.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/doc.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/errors.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/etcdserver.pb.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/gw/rpc.pb.gw.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/raft_internal.pb.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/raft_internal_stringer.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/rpc.pb.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/quota.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/raft.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/server.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/snapshot_merge.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/storage.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/util.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/v2_server.go delete mode 100644 vendor/go.etcd.io/etcd/etcdserver/v3_server.go delete mode 100644 vendor/go.etcd.io/etcd/functional/agent/doc.go delete mode 100644 vendor/go.etcd.io/etcd/functional/agent/handler.go delete mode 100644 vendor/go.etcd.io/etcd/functional/agent/server.go delete mode 100644 vendor/go.etcd.io/etcd/functional/agent/utils.go delete mode 100644 vendor/go.etcd.io/etcd/functional/rpcpb/etcd_config.go delete mode 100644 vendor/go.etcd.io/etcd/functional/rpcpb/member.go delete mode 100644 vendor/go.etcd.io/etcd/functional/rpcpb/rpc.pb.go delete mode 100644 vendor/go.etcd.io/etcd/functional/runner/election_command.go delete mode 100644 vendor/go.etcd.io/etcd/functional/runner/error.go delete mode 100644 vendor/go.etcd.io/etcd/functional/runner/global.go delete mode 100644 vendor/go.etcd.io/etcd/functional/runner/help.go delete mode 100644 vendor/go.etcd.io/etcd/functional/runner/lease_renewer_command.go delete mode 100644 vendor/go.etcd.io/etcd/functional/runner/lock_racer_command.go delete mode 100644 vendor/go.etcd.io/etcd/functional/runner/root.go delete mode 100644 vendor/go.etcd.io/etcd/functional/runner/watch_command.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/case.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/case_delay.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/case_external.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/case_failpoints.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/case_network_blackhole.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/case_network_delay.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/case_no_fail.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/case_sigquit_remove.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/case_sigquit_remove_quorum.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/case_sigterm.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/checker.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/checker_kv_hash.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/checker_lease_expire.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/checker_no_check.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/checker_runner.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/cluster.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/cluster_read_config.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/cluster_run.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/cluster_shuffle.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/doc.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/metrics_report.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/stresser.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/stresser_composite.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/stresser_key.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/stresser_lease.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/stresser_runner.go delete mode 100644 vendor/go.etcd.io/etcd/functional/tester/utils.go delete mode 100644 vendor/go.etcd.io/etcd/integration/bridge.go delete mode 100644 vendor/go.etcd.io/etcd/integration/cluster.go delete mode 100644 vendor/go.etcd.io/etcd/integration/cluster_direct.go delete mode 100644 vendor/go.etcd.io/etcd/integration/cluster_proxy.go delete mode 100644 vendor/go.etcd.io/etcd/integration/doc.go delete mode 100644 vendor/go.etcd.io/etcd/lease/doc.go delete mode 100644 vendor/go.etcd.io/etcd/lease/leasehttp/doc.go delete mode 100644 vendor/go.etcd.io/etcd/lease/leasehttp/http.go delete mode 100644 vendor/go.etcd.io/etcd/lease/leasepb/lease.pb.go delete mode 100644 vendor/go.etcd.io/etcd/lease/lessor.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/backend/backend.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/backend/batch_tx.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/backend/config_default.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/backend/config_linux.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/backend/config_windows.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/backend/doc.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/backend/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/backend/read_tx.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/backend/tx_buffer.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/doc.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/index.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/key_index.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/kv.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/kv_view.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/kvstore.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/kvstore_compaction.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/kvstore_txn.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/metrics_txn.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/mvccpb/kv.pb.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/revision.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/util.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/watchable_store.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/watchable_store_txn.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/watcher.go delete mode 100644 vendor/go.etcd.io/etcd/mvcc/watcher_group.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/adt/doc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/adt/interval_tree.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/contention/contention.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/contention/doc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/cpuutil/doc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/cpuutil/endian.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/crc/crc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/debugutil/doc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/debugutil/pprof.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/expect/expect.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/fileutil/dir_unix.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/fileutil/dir_windows.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/fileutil/fileutil.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/fileutil/lock.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/fileutil/lock_flock.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/fileutil/lock_linux.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/fileutil/lock_plan9.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/fileutil/lock_solaris.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/fileutil/lock_unix.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/fileutil/lock_windows.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/fileutil/preallocate.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/fileutil/preallocate_darwin.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/fileutil/preallocate_unix.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/fileutil/preallocate_unsupported.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/fileutil/purge.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/fileutil/sync.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/fileutil/sync_darwin.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/fileutil/sync_linux.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/flags/flag.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/flags/strings.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/flags/urls.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/httputil/httputil.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/idutil/id.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/ioutil/pagewriter.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/ioutil/readcloser.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/ioutil/reader.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/ioutil/util.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/logutil/merge_logger.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/mock/mockstorage/doc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/mock/mockstorage/storage_recorder.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/mock/mockstore/doc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/mock/mockstore/store_recorder.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/mock/mockwait/doc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/mock/mockwait/wait_recorder.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/netutil/isolate_linux.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/netutil/isolate_stub.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/netutil/netutil.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/netutil/routes.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/netutil/routes_linux.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/osutil/interrupt_unix.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/osutil/interrupt_windows.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/osutil/osutil.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/osutil/signal.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/osutil/signal_linux.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/pathutil/path.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/pbutil/pbutil.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/proxy/doc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/proxy/server.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/report/doc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/report/report.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/report/timeseries.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/report/weighted.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/runtime/fds_linux.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/runtime/fds_other.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/schedule/doc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/schedule/schedule.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/srv/srv.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/stringutil/stringutil.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/testutil/assert.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/testutil/leak.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/testutil/pauseable_handler.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/testutil/recorder.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/testutil/testutil.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/tlsutil/cipher_suites.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/tlsutil/doc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/tlsutil/tlsutil.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/transport/doc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/transport/keepalive_listener.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/transport/limit_listen.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/transport/listener.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/transport/listener_tls.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/transport/timeout_conn.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/transport/timeout_dialer.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/transport/timeout_listener.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/transport/timeout_transport.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/transport/tls.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/transport/transport.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/transport/unix_listener.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/types/doc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/types/id.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/types/set.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/types/slice.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/types/urls.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/types/urlsmap.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/wait/wait.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/wait/wait_time.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/auth_client_adapter.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/chan_stream.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/cluster_client_adapter.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/doc.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/election_client_adapter.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/kv_client_adapter.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/lease_client_adapter.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/lock_client_adapter.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/maintenance_client_adapter.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/watch_client_adapter.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/auth.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/cache/store.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/cluster.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/doc.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/election.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/health.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/kv.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/leader.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/lease.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/lock.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/logger.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/maintenance.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/register.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/util.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/watch.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/watch_broadcast.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/watch_broadcasts.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/watch_ranges.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/grpcproxy/watcher.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/httpproxy/director.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/httpproxy/doc.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/httpproxy/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/httpproxy/proxy.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/httpproxy/reverse.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/tcpproxy/doc.go delete mode 100644 vendor/go.etcd.io/etcd/proxy/tcpproxy/userspace.go delete mode 100644 vendor/go.etcd.io/etcd/raft/doc.go delete mode 100644 vendor/go.etcd.io/etcd/raft/log.go delete mode 100644 vendor/go.etcd.io/etcd/raft/log_unstable.go delete mode 100644 vendor/go.etcd.io/etcd/raft/logger.go delete mode 100644 vendor/go.etcd.io/etcd/raft/node.go delete mode 100644 vendor/go.etcd.io/etcd/raft/progress.go delete mode 100644 vendor/go.etcd.io/etcd/raft/raft.go delete mode 100644 vendor/go.etcd.io/etcd/raft/raftpb/raft.pb.go delete mode 100644 vendor/go.etcd.io/etcd/raft/rawnode.go delete mode 100644 vendor/go.etcd.io/etcd/raft/read_only.go delete mode 100644 vendor/go.etcd.io/etcd/raft/status.go delete mode 100644 vendor/go.etcd.io/etcd/raft/storage.go delete mode 100644 vendor/go.etcd.io/etcd/raft/util.go delete mode 100644 vendor/go.etcd.io/etcd/version/version.go delete mode 100644 vendor/go.etcd.io/etcd/wal/decoder.go delete mode 100644 vendor/go.etcd.io/etcd/wal/doc.go delete mode 100644 vendor/go.etcd.io/etcd/wal/encoder.go delete mode 100644 vendor/go.etcd.io/etcd/wal/file_pipeline.go delete mode 100644 vendor/go.etcd.io/etcd/wal/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/wal/repair.go delete mode 100644 vendor/go.etcd.io/etcd/wal/util.go delete mode 100644 vendor/go.etcd.io/etcd/wal/wal.go delete mode 100644 vendor/go.etcd.io/etcd/wal/walpb/record.go delete mode 100644 vendor/go.etcd.io/etcd/wal/walpb/record.pb.go diff --git a/vendor/github.com/coreos/etcd/LICENSE b/vendor/github.com/coreos/etcd/LICENSE deleted file mode 100644 index d64569567334..000000000000 --- a/vendor/github.com/coreos/etcd/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/github.com/coreos/etcd/NOTICE b/vendor/github.com/coreos/etcd/NOTICE deleted file mode 100644 index b39ddfa5cbde..000000000000 --- a/vendor/github.com/coreos/etcd/NOTICE +++ /dev/null @@ -1,5 +0,0 @@ -CoreOS Project -Copyright 2014 CoreOS, Inc - -This product includes software developed at CoreOS, Inc. -(http://www.coreos.com/). diff --git a/vendor/github.com/coreos/etcd/alarm/alarms.go b/vendor/github.com/coreos/etcd/alarm/alarms.go deleted file mode 100644 index 4f0ebe93f3bf..000000000000 --- a/vendor/github.com/coreos/etcd/alarm/alarms.go +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package alarm manages health status alarms in etcd. -package alarm - -import ( - "sync" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/pkg/capnslog" -) - -var ( - alarmBucketName = []byte("alarm") - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "alarm") -) - -type BackendGetter interface { - Backend() backend.Backend -} - -type alarmSet map[types.ID]*pb.AlarmMember - -// AlarmStore persists alarms to the backend. -type AlarmStore struct { - mu sync.Mutex - types map[pb.AlarmType]alarmSet - - bg BackendGetter -} - -func NewAlarmStore(bg BackendGetter) (*AlarmStore, error) { - ret := &AlarmStore{types: make(map[pb.AlarmType]alarmSet), bg: bg} - err := ret.restore() - return ret, err -} - -func (a *AlarmStore) Activate(id types.ID, at pb.AlarmType) *pb.AlarmMember { - a.mu.Lock() - defer a.mu.Unlock() - - newAlarm := &pb.AlarmMember{MemberID: uint64(id), Alarm: at} - if m := a.addToMap(newAlarm); m != newAlarm { - return m - } - - v, err := newAlarm.Marshal() - if err != nil { - plog.Panicf("failed to marshal alarm member") - } - - b := a.bg.Backend() - b.BatchTx().Lock() - b.BatchTx().UnsafePut(alarmBucketName, v, nil) - b.BatchTx().Unlock() - - return newAlarm -} - -func (a *AlarmStore) Deactivate(id types.ID, at pb.AlarmType) *pb.AlarmMember { - a.mu.Lock() - defer a.mu.Unlock() - - t := a.types[at] - if t == nil { - t = make(alarmSet) - a.types[at] = t - } - m := t[id] - if m == nil { - return nil - } - - delete(t, id) - - v, err := m.Marshal() - if err != nil { - plog.Panicf("failed to marshal alarm member") - } - - b := a.bg.Backend() - b.BatchTx().Lock() - b.BatchTx().UnsafeDelete(alarmBucketName, v) - b.BatchTx().Unlock() - - return m -} - -func (a *AlarmStore) Get(at pb.AlarmType) (ret []*pb.AlarmMember) { - a.mu.Lock() - defer a.mu.Unlock() - if at == pb.AlarmType_NONE { - for _, t := range a.types { - for _, m := range t { - ret = append(ret, m) - } - } - return ret - } - for _, m := range a.types[at] { - ret = append(ret, m) - } - return ret -} - -func (a *AlarmStore) restore() error { - b := a.bg.Backend() - tx := b.BatchTx() - - tx.Lock() - tx.UnsafeCreateBucket(alarmBucketName) - err := tx.UnsafeForEach(alarmBucketName, func(k, v []byte) error { - var m pb.AlarmMember - if err := m.Unmarshal(k); err != nil { - return err - } - a.addToMap(&m) - return nil - }) - tx.Unlock() - - b.ForceCommit() - return err -} - -func (a *AlarmStore) addToMap(newAlarm *pb.AlarmMember) *pb.AlarmMember { - t := a.types[newAlarm.Alarm] - if t == nil { - t = make(alarmSet) - a.types[newAlarm.Alarm] = t - } - m := t[types.ID(newAlarm.MemberID)] - if m != nil { - return m - } - t[types.ID(newAlarm.MemberID)] = newAlarm - return newAlarm -} diff --git a/vendor/github.com/coreos/etcd/auth/authpb/auth.pb.go b/vendor/github.com/coreos/etcd/auth/authpb/auth.pb.go deleted file mode 100644 index 1a940c39b26e..000000000000 --- a/vendor/github.com/coreos/etcd/auth/authpb/auth.pb.go +++ /dev/null @@ -1,807 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: auth.proto - -/* - Package authpb is a generated protocol buffer package. - - It is generated from these files: - auth.proto - - It has these top-level messages: - User - Permission - Role -*/ -package authpb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type Permission_Type int32 - -const ( - READ Permission_Type = 0 - WRITE Permission_Type = 1 - READWRITE Permission_Type = 2 -) - -var Permission_Type_name = map[int32]string{ - 0: "READ", - 1: "WRITE", - 2: "READWRITE", -} -var Permission_Type_value = map[string]int32{ - "READ": 0, - "WRITE": 1, - "READWRITE": 2, -} - -func (x Permission_Type) String() string { - return proto.EnumName(Permission_Type_name, int32(x)) -} -func (Permission_Type) EnumDescriptor() ([]byte, []int) { return fileDescriptorAuth, []int{1, 0} } - -// User is a single entry in the bucket authUsers -type User struct { - Name []byte `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Password []byte `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` - Roles []string `protobuf:"bytes,3,rep,name=roles" json:"roles,omitempty"` -} - -func (m *User) Reset() { *m = User{} } -func (m *User) String() string { return proto.CompactTextString(m) } -func (*User) ProtoMessage() {} -func (*User) Descriptor() ([]byte, []int) { return fileDescriptorAuth, []int{0} } - -// Permission is a single entity -type Permission struct { - PermType Permission_Type `protobuf:"varint,1,opt,name=permType,proto3,enum=authpb.Permission_Type" json:"permType,omitempty"` - Key []byte `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` - RangeEnd []byte `protobuf:"bytes,3,opt,name=range_end,json=rangeEnd,proto3" json:"range_end,omitempty"` -} - -func (m *Permission) Reset() { *m = Permission{} } -func (m *Permission) String() string { return proto.CompactTextString(m) } -func (*Permission) ProtoMessage() {} -func (*Permission) Descriptor() ([]byte, []int) { return fileDescriptorAuth, []int{1} } - -// Role is a single entry in the bucket authRoles -type Role struct { - Name []byte `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - KeyPermission []*Permission `protobuf:"bytes,2,rep,name=keyPermission" json:"keyPermission,omitempty"` -} - -func (m *Role) Reset() { *m = Role{} } -func (m *Role) String() string { return proto.CompactTextString(m) } -func (*Role) ProtoMessage() {} -func (*Role) Descriptor() ([]byte, []int) { return fileDescriptorAuth, []int{2} } - -func init() { - proto.RegisterType((*User)(nil), "authpb.User") - proto.RegisterType((*Permission)(nil), "authpb.Permission") - proto.RegisterType((*Role)(nil), "authpb.Role") - proto.RegisterEnum("authpb.Permission_Type", Permission_Type_name, Permission_Type_value) -} -func (m *User) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *User) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintAuth(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.Password) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintAuth(dAtA, i, uint64(len(m.Password))) - i += copy(dAtA[i:], m.Password) - } - if len(m.Roles) > 0 { - for _, s := range m.Roles { - dAtA[i] = 0x1a - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - return i, nil -} - -func (m *Permission) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Permission) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.PermType != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintAuth(dAtA, i, uint64(m.PermType)) - } - if len(m.Key) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintAuth(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - if len(m.RangeEnd) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintAuth(dAtA, i, uint64(len(m.RangeEnd))) - i += copy(dAtA[i:], m.RangeEnd) - } - return i, nil -} - -func (m *Role) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Role) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintAuth(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.KeyPermission) > 0 { - for _, msg := range m.KeyPermission { - dAtA[i] = 0x12 - i++ - i = encodeVarintAuth(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func encodeVarintAuth(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *User) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovAuth(uint64(l)) - } - l = len(m.Password) - if l > 0 { - n += 1 + l + sovAuth(uint64(l)) - } - if len(m.Roles) > 0 { - for _, s := range m.Roles { - l = len(s) - n += 1 + l + sovAuth(uint64(l)) - } - } - return n -} - -func (m *Permission) Size() (n int) { - var l int - _ = l - if m.PermType != 0 { - n += 1 + sovAuth(uint64(m.PermType)) - } - l = len(m.Key) - if l > 0 { - n += 1 + l + sovAuth(uint64(l)) - } - l = len(m.RangeEnd) - if l > 0 { - n += 1 + l + sovAuth(uint64(l)) - } - return n -} - -func (m *Role) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovAuth(uint64(l)) - } - if len(m.KeyPermission) > 0 { - for _, e := range m.KeyPermission { - l = e.Size() - n += 1 + l + sovAuth(uint64(l)) - } - } - return n -} - -func sovAuth(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozAuth(x uint64) (n int) { - return sovAuth(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *User) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: User: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: User: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthAuth - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = append(m.Name[:0], dAtA[iNdEx:postIndex]...) - if m.Name == nil { - m.Name = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Password", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthAuth - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Password = append(m.Password[:0], dAtA[iNdEx:postIndex]...) - if m.Password == nil { - m.Password = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Roles", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthAuth - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Roles = append(m.Roles, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipAuth(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthAuth - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Permission) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Permission: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Permission: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PermType", wireType) - } - m.PermType = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.PermType |= (Permission_Type(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthAuth - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RangeEnd", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthAuth - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RangeEnd = append(m.RangeEnd[:0], dAtA[iNdEx:postIndex]...) - if m.RangeEnd == nil { - m.RangeEnd = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipAuth(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthAuth - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Role) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Role: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Role: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthAuth - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = append(m.Name[:0], dAtA[iNdEx:postIndex]...) - if m.Name == nil { - m.Name = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field KeyPermission", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthAuth - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.KeyPermission = append(m.KeyPermission, &Permission{}) - if err := m.KeyPermission[len(m.KeyPermission)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipAuth(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthAuth - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipAuth(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowAuth - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowAuth - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowAuth - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthAuth - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowAuth - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipAuth(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthAuth = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowAuth = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("auth.proto", fileDescriptorAuth) } - -var fileDescriptorAuth = []byte{ - // 288 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0xc1, 0x4a, 0xc3, 0x30, - 0x1c, 0xc6, 0x9b, 0xb6, 0x1b, 0xed, 0x5f, 0x27, 0x25, 0x0c, 0x0c, 0x13, 0x42, 0xe9, 0xa9, 0x78, - 0xa8, 0xb0, 0x5d, 0xbc, 0x2a, 0xf6, 0x20, 0x78, 0x90, 0x50, 0xf1, 0x28, 0x1d, 0x0d, 0x75, 0x6c, - 0x6d, 0x4a, 0x32, 0x91, 0xbe, 0x89, 0x07, 0x1f, 0x68, 0xc7, 0x3d, 0x82, 0xab, 0x2f, 0x22, 0x4d, - 0x64, 0x43, 0xdc, 0xed, 0xfb, 0xbe, 0xff, 0x97, 0xe4, 0x97, 0x3f, 0x40, 0xfe, 0xb6, 0x7e, 0x4d, - 0x1a, 0x29, 0xd6, 0x02, 0x0f, 0x7b, 0xdd, 0xcc, 0x27, 0xe3, 0x52, 0x94, 0x42, 0x47, 0x57, 0xbd, - 0x32, 0xd3, 0xe8, 0x01, 0xdc, 0x27, 0xc5, 0x25, 0xc6, 0xe0, 0xd6, 0x79, 0xc5, 0x09, 0x0a, 0x51, - 0x7c, 0xca, 0xb4, 0xc6, 0x13, 0xf0, 0x9a, 0x5c, 0xa9, 0x77, 0x21, 0x0b, 0x62, 0xeb, 0x7c, 0xef, - 0xf1, 0x18, 0x06, 0x52, 0xac, 0xb8, 0x22, 0x4e, 0xe8, 0xc4, 0x3e, 0x33, 0x26, 0xfa, 0x44, 0x00, - 0x8f, 0x5c, 0x56, 0x0b, 0xa5, 0x16, 0xa2, 0xc6, 0x33, 0xf0, 0x1a, 0x2e, 0xab, 0xac, 0x6d, 0xcc, - 0xc5, 0x67, 0xd3, 0xf3, 0xc4, 0xd0, 0x24, 0x87, 0x56, 0xd2, 0x8f, 0xd9, 0xbe, 0x88, 0x03, 0x70, - 0x96, 0xbc, 0xfd, 0x7d, 0xb0, 0x97, 0xf8, 0x02, 0x7c, 0x99, 0xd7, 0x25, 0x7f, 0xe1, 0x75, 0x41, - 0x1c, 0x03, 0xa2, 0x83, 0xb4, 0x2e, 0xa2, 0x4b, 0x70, 0xf5, 0x31, 0x0f, 0x5c, 0x96, 0xde, 0xdc, - 0x05, 0x16, 0xf6, 0x61, 0xf0, 0xcc, 0xee, 0xb3, 0x34, 0x40, 0x78, 0x04, 0x7e, 0x1f, 0x1a, 0x6b, - 0x47, 0x19, 0xb8, 0x4c, 0xac, 0xf8, 0xd1, 0xcf, 0x5e, 0xc3, 0x68, 0xc9, 0xdb, 0x03, 0x16, 0xb1, - 0x43, 0x27, 0x3e, 0x99, 0xe2, 0xff, 0xc0, 0xec, 0x6f, 0xf1, 0x96, 0x6c, 0x76, 0xd4, 0xda, 0xee, - 0xa8, 0xb5, 0xe9, 0x28, 0xda, 0x76, 0x14, 0x7d, 0x75, 0x14, 0x7d, 0x7c, 0x53, 0x6b, 0x3e, 0xd4, - 0x3b, 0x9e, 0xfd, 0x04, 0x00, 0x00, 0xff, 0xff, 0xcc, 0x76, 0x8d, 0x4f, 0x8f, 0x01, 0x00, 0x00, -} diff --git a/vendor/github.com/coreos/etcd/auth/doc.go b/vendor/github.com/coreos/etcd/auth/doc.go deleted file mode 100644 index 72741a107745..000000000000 --- a/vendor/github.com/coreos/etcd/auth/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package auth provides client role authentication for accessing keys in etcd. -package auth diff --git a/vendor/github.com/coreos/etcd/auth/jwt.go b/vendor/github.com/coreos/etcd/auth/jwt.go deleted file mode 100644 index 99b2d6b5c714..000000000000 --- a/vendor/github.com/coreos/etcd/auth/jwt.go +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth - -import ( - "context" - "crypto/rsa" - "io/ioutil" - - jwt "github.com/dgrijalva/jwt-go" -) - -type tokenJWT struct { - signMethod string - signKey *rsa.PrivateKey - verifyKey *rsa.PublicKey -} - -func (t *tokenJWT) enable() {} -func (t *tokenJWT) disable() {} -func (t *tokenJWT) invalidateUser(string) {} -func (t *tokenJWT) genTokenPrefix() (string, error) { return "", nil } - -func (t *tokenJWT) info(ctx context.Context, token string, rev uint64) (*AuthInfo, bool) { - // rev isn't used in JWT, it is only used in simple token - var ( - username string - revision uint64 - ) - - parsed, err := jwt.Parse(token, func(token *jwt.Token) (interface{}, error) { - return t.verifyKey, nil - }) - - switch err.(type) { - case nil: - if !parsed.Valid { - plog.Warningf("invalid jwt token: %s", token) - return nil, false - } - - claims := parsed.Claims.(jwt.MapClaims) - - username = claims["username"].(string) - revision = uint64(claims["revision"].(float64)) - default: - plog.Warningf("failed to parse jwt token: %s", err) - return nil, false - } - - return &AuthInfo{Username: username, Revision: revision}, true -} - -func (t *tokenJWT) assign(ctx context.Context, username string, revision uint64) (string, error) { - // Future work: let a jwt token include permission information would be useful for - // permission checking in proxy side. - tk := jwt.NewWithClaims(jwt.GetSigningMethod(t.signMethod), - jwt.MapClaims{ - "username": username, - "revision": revision, - }) - - token, err := tk.SignedString(t.signKey) - if err != nil { - plog.Debugf("failed to sign jwt token: %s", err) - return "", err - } - - plog.Debugf("jwt token: %s", token) - - return token, err -} - -func prepareOpts(opts map[string]string) (jwtSignMethod, jwtPubKeyPath, jwtPrivKeyPath string, err error) { - for k, v := range opts { - switch k { - case "sign-method": - jwtSignMethod = v - case "pub-key": - jwtPubKeyPath = v - case "priv-key": - jwtPrivKeyPath = v - default: - plog.Errorf("unknown token specific option: %s", k) - return "", "", "", ErrInvalidAuthOpts - } - } - if len(jwtSignMethod) == 0 { - return "", "", "", ErrInvalidAuthOpts - } - return jwtSignMethod, jwtPubKeyPath, jwtPrivKeyPath, nil -} - -func newTokenProviderJWT(opts map[string]string) (*tokenJWT, error) { - jwtSignMethod, jwtPubKeyPath, jwtPrivKeyPath, err := prepareOpts(opts) - if err != nil { - return nil, ErrInvalidAuthOpts - } - - t := &tokenJWT{} - - t.signMethod = jwtSignMethod - - verifyBytes, err := ioutil.ReadFile(jwtPubKeyPath) - if err != nil { - plog.Errorf("failed to read public key (%s) for jwt: %s", jwtPubKeyPath, err) - return nil, err - } - t.verifyKey, err = jwt.ParseRSAPublicKeyFromPEM(verifyBytes) - if err != nil { - plog.Errorf("failed to parse public key (%s): %s", jwtPubKeyPath, err) - return nil, err - } - - signBytes, err := ioutil.ReadFile(jwtPrivKeyPath) - if err != nil { - plog.Errorf("failed to read private key (%s) for jwt: %s", jwtPrivKeyPath, err) - return nil, err - } - t.signKey, err = jwt.ParseRSAPrivateKeyFromPEM(signBytes) - if err != nil { - plog.Errorf("failed to parse private key (%s): %s", jwtPrivKeyPath, err) - return nil, err - } - - return t, nil -} diff --git a/vendor/github.com/coreos/etcd/auth/nop.go b/vendor/github.com/coreos/etcd/auth/nop.go deleted file mode 100644 index d4378747bd8b..000000000000 --- a/vendor/github.com/coreos/etcd/auth/nop.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth - -import ( - "context" -) - -type tokenNop struct{} - -func (t *tokenNop) enable() {} -func (t *tokenNop) disable() {} -func (t *tokenNop) invalidateUser(string) {} -func (t *tokenNop) genTokenPrefix() (string, error) { return "", nil } -func (t *tokenNop) info(ctx context.Context, token string, rev uint64) (*AuthInfo, bool) { - return nil, false -} -func (t *tokenNop) assign(ctx context.Context, username string, revision uint64) (string, error) { - return "", ErrAuthFailed -} -func newTokenProviderNop() (*tokenNop, error) { - return &tokenNop{}, nil -} diff --git a/vendor/github.com/coreos/etcd/auth/range_perm_cache.go b/vendor/github.com/coreos/etcd/auth/range_perm_cache.go deleted file mode 100644 index 691b65ba38e7..000000000000 --- a/vendor/github.com/coreos/etcd/auth/range_perm_cache.go +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth - -import ( - "github.com/coreos/etcd/auth/authpb" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/pkg/adt" -) - -func getMergedPerms(tx backend.BatchTx, userName string) *unifiedRangePermissions { - user := getUser(tx, userName) - if user == nil { - plog.Errorf("invalid user name %s", userName) - return nil - } - - readPerms := &adt.IntervalTree{} - writePerms := &adt.IntervalTree{} - - for _, roleName := range user.Roles { - role := getRole(tx, roleName) - if role == nil { - continue - } - - for _, perm := range role.KeyPermission { - var ivl adt.Interval - var rangeEnd []byte - - if len(perm.RangeEnd) != 1 || perm.RangeEnd[0] != 0 { - rangeEnd = perm.RangeEnd - } - - if len(perm.RangeEnd) != 0 { - ivl = adt.NewBytesAffineInterval(perm.Key, rangeEnd) - } else { - ivl = adt.NewBytesAffinePoint(perm.Key) - } - - switch perm.PermType { - case authpb.READWRITE: - readPerms.Insert(ivl, struct{}{}) - writePerms.Insert(ivl, struct{}{}) - - case authpb.READ: - readPerms.Insert(ivl, struct{}{}) - - case authpb.WRITE: - writePerms.Insert(ivl, struct{}{}) - } - } - } - - return &unifiedRangePermissions{ - readPerms: readPerms, - writePerms: writePerms, - } -} - -func checkKeyInterval(cachedPerms *unifiedRangePermissions, key, rangeEnd []byte, permtyp authpb.Permission_Type) bool { - if len(rangeEnd) == 1 && rangeEnd[0] == 0 { - rangeEnd = nil - } - - ivl := adt.NewBytesAffineInterval(key, rangeEnd) - switch permtyp { - case authpb.READ: - return cachedPerms.readPerms.Contains(ivl) - case authpb.WRITE: - return cachedPerms.writePerms.Contains(ivl) - default: - plog.Panicf("unknown auth type: %v", permtyp) - } - return false -} - -func checkKeyPoint(cachedPerms *unifiedRangePermissions, key []byte, permtyp authpb.Permission_Type) bool { - pt := adt.NewBytesAffinePoint(key) - switch permtyp { - case authpb.READ: - return cachedPerms.readPerms.Intersects(pt) - case authpb.WRITE: - return cachedPerms.writePerms.Intersects(pt) - default: - plog.Panicf("unknown auth type: %v", permtyp) - } - return false -} - -func (as *authStore) isRangeOpPermitted(tx backend.BatchTx, userName string, key, rangeEnd []byte, permtyp authpb.Permission_Type) bool { - // assumption: tx is Lock()ed - _, ok := as.rangePermCache[userName] - if !ok { - perms := getMergedPerms(tx, userName) - if perms == nil { - plog.Errorf("failed to create a unified permission of user %s", userName) - return false - } - as.rangePermCache[userName] = perms - } - - if len(rangeEnd) == 0 { - return checkKeyPoint(as.rangePermCache[userName], key, permtyp) - } - - return checkKeyInterval(as.rangePermCache[userName], key, rangeEnd, permtyp) -} - -func (as *authStore) clearCachedPerm() { - as.rangePermCache = make(map[string]*unifiedRangePermissions) -} - -func (as *authStore) invalidateCachedPerm(userName string) { - delete(as.rangePermCache, userName) -} - -type unifiedRangePermissions struct { - readPerms *adt.IntervalTree - writePerms *adt.IntervalTree -} diff --git a/vendor/github.com/coreos/etcd/auth/simple_token.go b/vendor/github.com/coreos/etcd/auth/simple_token.go deleted file mode 100644 index ac55ad7f13fc..000000000000 --- a/vendor/github.com/coreos/etcd/auth/simple_token.go +++ /dev/null @@ -1,223 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth - -// CAUTION: This randum number based token mechanism is only for testing purpose. -// JWT based mechanism will be added in the near future. - -import ( - "context" - "crypto/rand" - "fmt" - "math/big" - "strconv" - "strings" - "sync" - "time" -) - -const ( - letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" - defaultSimpleTokenLength = 16 -) - -// var for testing purposes -var ( - simpleTokenTTL = 5 * time.Minute - simpleTokenTTLResolution = 1 * time.Second -) - -type simpleTokenTTLKeeper struct { - tokens map[string]time.Time - donec chan struct{} - stopc chan struct{} - deleteTokenFunc func(string) - mu *sync.Mutex -} - -func (tm *simpleTokenTTLKeeper) stop() { - select { - case tm.stopc <- struct{}{}: - case <-tm.donec: - } - <-tm.donec -} - -func (tm *simpleTokenTTLKeeper) addSimpleToken(token string) { - tm.tokens[token] = time.Now().Add(simpleTokenTTL) -} - -func (tm *simpleTokenTTLKeeper) resetSimpleToken(token string) { - if _, ok := tm.tokens[token]; ok { - tm.tokens[token] = time.Now().Add(simpleTokenTTL) - } -} - -func (tm *simpleTokenTTLKeeper) deleteSimpleToken(token string) { - delete(tm.tokens, token) -} - -func (tm *simpleTokenTTLKeeper) run() { - tokenTicker := time.NewTicker(simpleTokenTTLResolution) - defer func() { - tokenTicker.Stop() - close(tm.donec) - }() - for { - select { - case <-tokenTicker.C: - nowtime := time.Now() - tm.mu.Lock() - for t, tokenendtime := range tm.tokens { - if nowtime.After(tokenendtime) { - tm.deleteTokenFunc(t) - delete(tm.tokens, t) - } - } - tm.mu.Unlock() - case <-tm.stopc: - return - } - } -} - -type tokenSimple struct { - indexWaiter func(uint64) <-chan struct{} - simpleTokenKeeper *simpleTokenTTLKeeper - simpleTokensMu sync.Mutex - simpleTokens map[string]string // token -> username -} - -func (t *tokenSimple) genTokenPrefix() (string, error) { - ret := make([]byte, defaultSimpleTokenLength) - - for i := 0; i < defaultSimpleTokenLength; i++ { - bInt, err := rand.Int(rand.Reader, big.NewInt(int64(len(letters)))) - if err != nil { - return "", err - } - - ret[i] = letters[bInt.Int64()] - } - - return string(ret), nil -} - -func (t *tokenSimple) assignSimpleTokenToUser(username, token string) { - t.simpleTokensMu.Lock() - defer t.simpleTokensMu.Unlock() - if t.simpleTokenKeeper == nil { - return - } - - _, ok := t.simpleTokens[token] - if ok { - plog.Panicf("token %s is alredy used", token) - } - - t.simpleTokens[token] = username - t.simpleTokenKeeper.addSimpleToken(token) -} - -func (t *tokenSimple) invalidateUser(username string) { - if t.simpleTokenKeeper == nil { - return - } - t.simpleTokensMu.Lock() - for token, name := range t.simpleTokens { - if strings.Compare(name, username) == 0 { - delete(t.simpleTokens, token) - t.simpleTokenKeeper.deleteSimpleToken(token) - } - } - t.simpleTokensMu.Unlock() -} - -func (t *tokenSimple) enable() { - delf := func(tk string) { - if username, ok := t.simpleTokens[tk]; ok { - plog.Infof("deleting token %s for user %s", tk, username) - delete(t.simpleTokens, tk) - } - } - t.simpleTokenKeeper = &simpleTokenTTLKeeper{ - tokens: make(map[string]time.Time), - donec: make(chan struct{}), - stopc: make(chan struct{}), - deleteTokenFunc: delf, - mu: &t.simpleTokensMu, - } - go t.simpleTokenKeeper.run() -} - -func (t *tokenSimple) disable() { - t.simpleTokensMu.Lock() - tk := t.simpleTokenKeeper - t.simpleTokenKeeper = nil - t.simpleTokens = make(map[string]string) // invalidate all tokens - t.simpleTokensMu.Unlock() - if tk != nil { - tk.stop() - } -} - -func (t *tokenSimple) info(ctx context.Context, token string, revision uint64) (*AuthInfo, bool) { - if !t.isValidSimpleToken(ctx, token) { - return nil, false - } - t.simpleTokensMu.Lock() - username, ok := t.simpleTokens[token] - if ok && t.simpleTokenKeeper != nil { - t.simpleTokenKeeper.resetSimpleToken(token) - } - t.simpleTokensMu.Unlock() - return &AuthInfo{Username: username, Revision: revision}, ok -} - -func (t *tokenSimple) assign(ctx context.Context, username string, rev uint64) (string, error) { - // rev isn't used in simple token, it is only used in JWT - index := ctx.Value(AuthenticateParamIndex{}).(uint64) - simpleTokenPrefix := ctx.Value(AuthenticateParamSimpleTokenPrefix{}).(string) - token := fmt.Sprintf("%s.%d", simpleTokenPrefix, index) - t.assignSimpleTokenToUser(username, token) - - return token, nil -} - -func (t *tokenSimple) isValidSimpleToken(ctx context.Context, token string) bool { - splitted := strings.Split(token, ".") - if len(splitted) != 2 { - return false - } - index, err := strconv.Atoi(splitted[1]) - if err != nil { - return false - } - - select { - case <-t.indexWaiter(uint64(index)): - return true - case <-ctx.Done(): - } - - return false -} - -func newTokenProviderSimple(indexWaiter func(uint64) <-chan struct{}) *tokenSimple { - return &tokenSimple{ - simpleTokens: make(map[string]string), - indexWaiter: indexWaiter, - } -} diff --git a/vendor/github.com/coreos/etcd/auth/store.go b/vendor/github.com/coreos/etcd/auth/store.go deleted file mode 100644 index d676cb5553bb..000000000000 --- a/vendor/github.com/coreos/etcd/auth/store.go +++ /dev/null @@ -1,1136 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth - -import ( - "bytes" - "context" - "encoding/binary" - "errors" - "sort" - "strings" - "sync" - "sync/atomic" - - "github.com/coreos/etcd/auth/authpb" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc/backend" - - "github.com/coreos/pkg/capnslog" - "golang.org/x/crypto/bcrypt" - "google.golang.org/grpc/credentials" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/peer" -) - -var ( - enableFlagKey = []byte("authEnabled") - authEnabled = []byte{1} - authDisabled = []byte{0} - - revisionKey = []byte("authRevision") - - authBucketName = []byte("auth") - authUsersBucketName = []byte("authUsers") - authRolesBucketName = []byte("authRoles") - - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "auth") - - ErrRootUserNotExist = errors.New("auth: root user does not exist") - ErrRootRoleNotExist = errors.New("auth: root user does not have root role") - ErrUserAlreadyExist = errors.New("auth: user already exists") - ErrUserEmpty = errors.New("auth: user name is empty") - ErrUserNotFound = errors.New("auth: user not found") - ErrRoleAlreadyExist = errors.New("auth: role already exists") - ErrRoleNotFound = errors.New("auth: role not found") - ErrAuthFailed = errors.New("auth: authentication failed, invalid user ID or password") - ErrPermissionDenied = errors.New("auth: permission denied") - ErrRoleNotGranted = errors.New("auth: role is not granted to the user") - ErrPermissionNotGranted = errors.New("auth: permission is not granted to the role") - ErrAuthNotEnabled = errors.New("auth: authentication is not enabled") - ErrAuthOldRevision = errors.New("auth: revision in header is old") - ErrInvalidAuthToken = errors.New("auth: invalid auth token") - ErrInvalidAuthOpts = errors.New("auth: invalid auth options") - ErrInvalidAuthMgmt = errors.New("auth: invalid auth management") - - // BcryptCost is the algorithm cost / strength for hashing auth passwords - BcryptCost = bcrypt.DefaultCost -) - -const ( - rootUser = "root" - rootRole = "root" - - tokenTypeSimple = "simple" - tokenTypeJWT = "jwt" - - revBytesLen = 8 -) - -type AuthInfo struct { - Username string - Revision uint64 -} - -// AuthenticateParamIndex is used for a key of context in the parameters of Authenticate() -type AuthenticateParamIndex struct{} - -// AuthenticateParamSimpleTokenPrefix is used for a key of context in the parameters of Authenticate() -type AuthenticateParamSimpleTokenPrefix struct{} - -type AuthStore interface { - // AuthEnable turns on the authentication feature - AuthEnable() error - - // AuthDisable turns off the authentication feature - AuthDisable() - - // Authenticate does authentication based on given user name and password - Authenticate(ctx context.Context, username, password string) (*pb.AuthenticateResponse, error) - - // Recover recovers the state of auth store from the given backend - Recover(b backend.Backend) - - // UserAdd adds a new user - UserAdd(r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) - - // UserDelete deletes a user - UserDelete(r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) - - // UserChangePassword changes a password of a user - UserChangePassword(r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) - - // UserGrantRole grants a role to the user - UserGrantRole(r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) - - // UserGet gets the detailed information of a users - UserGet(r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) - - // UserRevokeRole revokes a role of a user - UserRevokeRole(r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) - - // RoleAdd adds a new role - RoleAdd(r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) - - // RoleGrantPermission grants a permission to a role - RoleGrantPermission(r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) - - // RoleGet gets the detailed information of a role - RoleGet(r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) - - // RoleRevokePermission gets the detailed information of a role - RoleRevokePermission(r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) - - // RoleDelete gets the detailed information of a role - RoleDelete(r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) - - // UserList gets a list of all users - UserList(r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) - - // RoleList gets a list of all roles - RoleList(r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) - - // IsPutPermitted checks put permission of the user - IsPutPermitted(authInfo *AuthInfo, key []byte) error - - // IsRangePermitted checks range permission of the user - IsRangePermitted(authInfo *AuthInfo, key, rangeEnd []byte) error - - // IsDeleteRangePermitted checks delete-range permission of the user - IsDeleteRangePermitted(authInfo *AuthInfo, key, rangeEnd []byte) error - - // IsAdminPermitted checks admin permission of the user - IsAdminPermitted(authInfo *AuthInfo) error - - // GenTokenPrefix produces a random string in a case of simple token - // in a case of JWT, it produces an empty string - GenTokenPrefix() (string, error) - - // Revision gets current revision of authStore - Revision() uint64 - - // CheckPassword checks a given pair of username and password is correct - CheckPassword(username, password string) (uint64, error) - - // Close does cleanup of AuthStore - Close() error - - // AuthInfoFromCtx gets AuthInfo from gRPC's context - AuthInfoFromCtx(ctx context.Context) (*AuthInfo, error) - - // AuthInfoFromTLS gets AuthInfo from TLS info of gRPC's context - AuthInfoFromTLS(ctx context.Context) *AuthInfo - - // WithRoot generates and installs a token that can be used as a root credential - WithRoot(ctx context.Context) context.Context - - // HasRole checks that user has role - HasRole(user, role string) bool -} - -type TokenProvider interface { - info(ctx context.Context, token string, revision uint64) (*AuthInfo, bool) - assign(ctx context.Context, username string, revision uint64) (string, error) - enable() - disable() - - invalidateUser(string) - genTokenPrefix() (string, error) -} - -type authStore struct { - // atomic operations; need 64-bit align, or 32-bit tests will crash - revision uint64 - - be backend.Backend - enabled bool - enabledMu sync.RWMutex - - rangePermCache map[string]*unifiedRangePermissions // username -> unifiedRangePermissions - - tokenProvider TokenProvider -} - -func (as *authStore) AuthEnable() error { - as.enabledMu.Lock() - defer as.enabledMu.Unlock() - if as.enabled { - plog.Noticef("Authentication already enabled") - return nil - } - b := as.be - tx := b.BatchTx() - tx.Lock() - defer func() { - tx.Unlock() - b.ForceCommit() - }() - - u := getUser(tx, rootUser) - if u == nil { - return ErrRootUserNotExist - } - - if !hasRootRole(u) { - return ErrRootRoleNotExist - } - - tx.UnsafePut(authBucketName, enableFlagKey, authEnabled) - - as.enabled = true - as.tokenProvider.enable() - - as.rangePermCache = make(map[string]*unifiedRangePermissions) - - as.setRevision(getRevision(tx)) - - plog.Noticef("Authentication enabled") - - return nil -} - -func (as *authStore) AuthDisable() { - as.enabledMu.Lock() - defer as.enabledMu.Unlock() - if !as.enabled { - return - } - b := as.be - tx := b.BatchTx() - tx.Lock() - tx.UnsafePut(authBucketName, enableFlagKey, authDisabled) - as.commitRevision(tx) - tx.Unlock() - b.ForceCommit() - - as.enabled = false - as.tokenProvider.disable() - - plog.Noticef("Authentication disabled") -} - -func (as *authStore) Close() error { - as.enabledMu.Lock() - defer as.enabledMu.Unlock() - if !as.enabled { - return nil - } - as.tokenProvider.disable() - return nil -} - -func (as *authStore) Authenticate(ctx context.Context, username, password string) (*pb.AuthenticateResponse, error) { - if !as.isAuthEnabled() { - return nil, ErrAuthNotEnabled - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(tx, username) - if user == nil { - return nil, ErrAuthFailed - } - - // Password checking is already performed in the API layer, so we don't need to check for now. - // Staleness of password can be detected with OCC in the API layer, too. - - token, err := as.tokenProvider.assign(ctx, username, as.Revision()) - if err != nil { - return nil, err - } - - plog.Debugf("authorized %s, token is %s", username, token) - return &pb.AuthenticateResponse{Token: token}, nil -} - -func (as *authStore) CheckPassword(username, password string) (uint64, error) { - if !as.isAuthEnabled() { - return 0, ErrAuthNotEnabled - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(tx, username) - if user == nil { - return 0, ErrAuthFailed - } - - if bcrypt.CompareHashAndPassword(user.Password, []byte(password)) != nil { - plog.Noticef("authentication failed, invalid password for user %s", username) - return 0, ErrAuthFailed - } - - return getRevision(tx), nil -} - -func (as *authStore) Recover(be backend.Backend) { - enabled := false - as.be = be - tx := be.BatchTx() - tx.Lock() - _, vs := tx.UnsafeRange(authBucketName, enableFlagKey, nil, 0) - if len(vs) == 1 { - if bytes.Equal(vs[0], authEnabled) { - enabled = true - } - } - - as.setRevision(getRevision(tx)) - - tx.Unlock() - - as.enabledMu.Lock() - as.enabled = enabled - as.enabledMu.Unlock() -} - -func (as *authStore) UserAdd(r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) { - if len(r.Name) == 0 { - return nil, ErrUserEmpty - } - - hashed, err := bcrypt.GenerateFromPassword([]byte(r.Password), BcryptCost) - if err != nil { - plog.Errorf("failed to hash password: %s", err) - return nil, err - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(tx, r.Name) - if user != nil { - return nil, ErrUserAlreadyExist - } - - newUser := &authpb.User{ - Name: []byte(r.Name), - Password: hashed, - } - - putUser(tx, newUser) - - as.commitRevision(tx) - - plog.Noticef("added a new user: %s", r.Name) - - return &pb.AuthUserAddResponse{}, nil -} - -func (as *authStore) UserDelete(r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) { - if as.enabled && strings.Compare(r.Name, rootUser) == 0 { - plog.Errorf("the user root must not be deleted") - return nil, ErrInvalidAuthMgmt - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(tx, r.Name) - if user == nil { - return nil, ErrUserNotFound - } - - delUser(tx, r.Name) - - as.commitRevision(tx) - - as.invalidateCachedPerm(r.Name) - as.tokenProvider.invalidateUser(r.Name) - - plog.Noticef("deleted a user: %s", r.Name) - - return &pb.AuthUserDeleteResponse{}, nil -} - -func (as *authStore) UserChangePassword(r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) { - // TODO(mitake): measure the cost of bcrypt.GenerateFromPassword() - // If the cost is too high, we should move the encryption to outside of the raft - hashed, err := bcrypt.GenerateFromPassword([]byte(r.Password), BcryptCost) - if err != nil { - plog.Errorf("failed to hash password: %s", err) - return nil, err - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(tx, r.Name) - if user == nil { - return nil, ErrUserNotFound - } - - updatedUser := &authpb.User{ - Name: []byte(r.Name), - Roles: user.Roles, - Password: hashed, - } - - putUser(tx, updatedUser) - - as.commitRevision(tx) - - as.invalidateCachedPerm(r.Name) - as.tokenProvider.invalidateUser(r.Name) - - plog.Noticef("changed a password of a user: %s", r.Name) - - return &pb.AuthUserChangePasswordResponse{}, nil -} - -func (as *authStore) UserGrantRole(r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(tx, r.User) - if user == nil { - return nil, ErrUserNotFound - } - - if r.Role != rootRole { - role := getRole(tx, r.Role) - if role == nil { - return nil, ErrRoleNotFound - } - } - - idx := sort.SearchStrings(user.Roles, r.Role) - if idx < len(user.Roles) && strings.Compare(user.Roles[idx], r.Role) == 0 { - plog.Warningf("user %s is already granted role %s", r.User, r.Role) - return &pb.AuthUserGrantRoleResponse{}, nil - } - - user.Roles = append(user.Roles, r.Role) - sort.Strings(user.Roles) - - putUser(tx, user) - - as.invalidateCachedPerm(r.User) - - as.commitRevision(tx) - - plog.Noticef("granted role %s to user %s", r.Role, r.User) - return &pb.AuthUserGrantRoleResponse{}, nil -} - -func (as *authStore) UserGet(r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - user := getUser(tx, r.Name) - tx.Unlock() - - if user == nil { - return nil, ErrUserNotFound - } - - var resp pb.AuthUserGetResponse - resp.Roles = append(resp.Roles, user.Roles...) - return &resp, nil -} - -func (as *authStore) UserList(r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - users := getAllUsers(tx) - tx.Unlock() - - resp := &pb.AuthUserListResponse{Users: make([]string, len(users))} - for i := range users { - resp.Users[i] = string(users[i].Name) - } - return resp, nil -} - -func (as *authStore) UserRevokeRole(r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) { - if as.enabled && strings.Compare(r.Name, rootUser) == 0 && strings.Compare(r.Role, rootRole) == 0 { - plog.Errorf("the role root must not be revoked from the user root") - return nil, ErrInvalidAuthMgmt - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(tx, r.Name) - if user == nil { - return nil, ErrUserNotFound - } - - updatedUser := &authpb.User{ - Name: user.Name, - Password: user.Password, - } - - for _, role := range user.Roles { - if strings.Compare(role, r.Role) != 0 { - updatedUser.Roles = append(updatedUser.Roles, role) - } - } - - if len(updatedUser.Roles) == len(user.Roles) { - return nil, ErrRoleNotGranted - } - - putUser(tx, updatedUser) - - as.invalidateCachedPerm(r.Name) - - as.commitRevision(tx) - - plog.Noticef("revoked role %s from user %s", r.Role, r.Name) - return &pb.AuthUserRevokeRoleResponse{}, nil -} - -func (as *authStore) RoleGet(r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - var resp pb.AuthRoleGetResponse - - role := getRole(tx, r.Role) - if role == nil { - return nil, ErrRoleNotFound - } - resp.Perm = append(resp.Perm, role.KeyPermission...) - return &resp, nil -} - -func (as *authStore) RoleList(r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - roles := getAllRoles(tx) - tx.Unlock() - - resp := &pb.AuthRoleListResponse{Roles: make([]string, len(roles))} - for i := range roles { - resp.Roles[i] = string(roles[i].Name) - } - return resp, nil -} - -func (as *authStore) RoleRevokePermission(r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - role := getRole(tx, r.Role) - if role == nil { - return nil, ErrRoleNotFound - } - - updatedRole := &authpb.Role{ - Name: role.Name, - } - - for _, perm := range role.KeyPermission { - if !bytes.Equal(perm.Key, []byte(r.Key)) || !bytes.Equal(perm.RangeEnd, []byte(r.RangeEnd)) { - updatedRole.KeyPermission = append(updatedRole.KeyPermission, perm) - } - } - - if len(role.KeyPermission) == len(updatedRole.KeyPermission) { - return nil, ErrPermissionNotGranted - } - - putRole(tx, updatedRole) - - // TODO(mitake): currently single role update invalidates every cache - // It should be optimized. - as.clearCachedPerm() - - as.commitRevision(tx) - - plog.Noticef("revoked key %s from role %s", r.Key, r.Role) - return &pb.AuthRoleRevokePermissionResponse{}, nil -} - -func (as *authStore) RoleDelete(r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) { - if as.enabled && strings.Compare(r.Role, rootRole) == 0 { - plog.Errorf("the role root must not be deleted") - return nil, ErrInvalidAuthMgmt - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - role := getRole(tx, r.Role) - if role == nil { - return nil, ErrRoleNotFound - } - - delRole(tx, r.Role) - - users := getAllUsers(tx) - for _, user := range users { - updatedUser := &authpb.User{ - Name: user.Name, - Password: user.Password, - } - - for _, role := range user.Roles { - if strings.Compare(role, r.Role) != 0 { - updatedUser.Roles = append(updatedUser.Roles, role) - } - } - - if len(updatedUser.Roles) == len(user.Roles) { - continue - } - - putUser(tx, updatedUser) - - as.invalidateCachedPerm(string(user.Name)) - } - - as.commitRevision(tx) - - plog.Noticef("deleted role %s", r.Role) - return &pb.AuthRoleDeleteResponse{}, nil -} - -func (as *authStore) RoleAdd(r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - role := getRole(tx, r.Name) - if role != nil { - return nil, ErrRoleAlreadyExist - } - - newRole := &authpb.Role{ - Name: []byte(r.Name), - } - - putRole(tx, newRole) - - as.commitRevision(tx) - - plog.Noticef("Role %s is created", r.Name) - - return &pb.AuthRoleAddResponse{}, nil -} - -func (as *authStore) authInfoFromToken(ctx context.Context, token string) (*AuthInfo, bool) { - return as.tokenProvider.info(ctx, token, as.Revision()) -} - -type permSlice []*authpb.Permission - -func (perms permSlice) Len() int { - return len(perms) -} - -func (perms permSlice) Less(i, j int) bool { - return bytes.Compare(perms[i].Key, perms[j].Key) < 0 -} - -func (perms permSlice) Swap(i, j int) { - perms[i], perms[j] = perms[j], perms[i] -} - -func (as *authStore) RoleGrantPermission(r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - role := getRole(tx, r.Name) - if role == nil { - return nil, ErrRoleNotFound - } - - idx := sort.Search(len(role.KeyPermission), func(i int) bool { - return bytes.Compare(role.KeyPermission[i].Key, []byte(r.Perm.Key)) >= 0 - }) - - if idx < len(role.KeyPermission) && bytes.Equal(role.KeyPermission[idx].Key, r.Perm.Key) && bytes.Equal(role.KeyPermission[idx].RangeEnd, r.Perm.RangeEnd) { - // update existing permission - role.KeyPermission[idx].PermType = r.Perm.PermType - } else { - // append new permission to the role - newPerm := &authpb.Permission{ - Key: []byte(r.Perm.Key), - RangeEnd: []byte(r.Perm.RangeEnd), - PermType: r.Perm.PermType, - } - - role.KeyPermission = append(role.KeyPermission, newPerm) - sort.Sort(permSlice(role.KeyPermission)) - } - - putRole(tx, role) - - // TODO(mitake): currently single role update invalidates every cache - // It should be optimized. - as.clearCachedPerm() - - as.commitRevision(tx) - - plog.Noticef("role %s's permission of key %s is updated as %s", r.Name, r.Perm.Key, authpb.Permission_Type_name[int32(r.Perm.PermType)]) - - return &pb.AuthRoleGrantPermissionResponse{}, nil -} - -func (as *authStore) isOpPermitted(userName string, revision uint64, key, rangeEnd []byte, permTyp authpb.Permission_Type) error { - // TODO(mitake): this function would be costly so we need a caching mechanism - if !as.isAuthEnabled() { - return nil - } - - // only gets rev == 0 when passed AuthInfo{}; no user given - if revision == 0 { - return ErrUserEmpty - } - - if revision < as.Revision() { - return ErrAuthOldRevision - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(tx, userName) - if user == nil { - plog.Errorf("invalid user name %s for permission checking", userName) - return ErrPermissionDenied - } - - // root role should have permission on all ranges - if hasRootRole(user) { - return nil - } - - if as.isRangeOpPermitted(tx, userName, key, rangeEnd, permTyp) { - return nil - } - - return ErrPermissionDenied -} - -func (as *authStore) IsPutPermitted(authInfo *AuthInfo, key []byte) error { - return as.isOpPermitted(authInfo.Username, authInfo.Revision, key, nil, authpb.WRITE) -} - -func (as *authStore) IsRangePermitted(authInfo *AuthInfo, key, rangeEnd []byte) error { - return as.isOpPermitted(authInfo.Username, authInfo.Revision, key, rangeEnd, authpb.READ) -} - -func (as *authStore) IsDeleteRangePermitted(authInfo *AuthInfo, key, rangeEnd []byte) error { - return as.isOpPermitted(authInfo.Username, authInfo.Revision, key, rangeEnd, authpb.WRITE) -} - -func (as *authStore) IsAdminPermitted(authInfo *AuthInfo) error { - if !as.isAuthEnabled() { - return nil - } - if authInfo == nil { - return ErrUserEmpty - } - - tx := as.be.BatchTx() - tx.Lock() - u := getUser(tx, authInfo.Username) - tx.Unlock() - - if u == nil { - return ErrUserNotFound - } - - if !hasRootRole(u) { - return ErrPermissionDenied - } - - return nil -} - -func getUser(tx backend.BatchTx, username string) *authpb.User { - _, vs := tx.UnsafeRange(authUsersBucketName, []byte(username), nil, 0) - if len(vs) == 0 { - return nil - } - - user := &authpb.User{} - err := user.Unmarshal(vs[0]) - if err != nil { - plog.Panicf("failed to unmarshal user struct (name: %s): %s", username, err) - } - return user -} - -func getAllUsers(tx backend.BatchTx) []*authpb.User { - _, vs := tx.UnsafeRange(authUsersBucketName, []byte{0}, []byte{0xff}, -1) - if len(vs) == 0 { - return nil - } - - users := make([]*authpb.User, len(vs)) - for i := range vs { - user := &authpb.User{} - err := user.Unmarshal(vs[i]) - if err != nil { - plog.Panicf("failed to unmarshal user struct: %s", err) - } - users[i] = user - } - return users -} - -func putUser(tx backend.BatchTx, user *authpb.User) { - b, err := user.Marshal() - if err != nil { - plog.Panicf("failed to marshal user struct (name: %s): %s", user.Name, err) - } - tx.UnsafePut(authUsersBucketName, user.Name, b) -} - -func delUser(tx backend.BatchTx, username string) { - tx.UnsafeDelete(authUsersBucketName, []byte(username)) -} - -func getRole(tx backend.BatchTx, rolename string) *authpb.Role { - _, vs := tx.UnsafeRange(authRolesBucketName, []byte(rolename), nil, 0) - if len(vs) == 0 { - return nil - } - - role := &authpb.Role{} - err := role.Unmarshal(vs[0]) - if err != nil { - plog.Panicf("failed to unmarshal role struct (name: %s): %s", rolename, err) - } - return role -} - -func getAllRoles(tx backend.BatchTx) []*authpb.Role { - _, vs := tx.UnsafeRange(authRolesBucketName, []byte{0}, []byte{0xff}, -1) - if len(vs) == 0 { - return nil - } - - roles := make([]*authpb.Role, len(vs)) - for i := range vs { - role := &authpb.Role{} - err := role.Unmarshal(vs[i]) - if err != nil { - plog.Panicf("failed to unmarshal role struct: %s", err) - } - roles[i] = role - } - return roles -} - -func putRole(tx backend.BatchTx, role *authpb.Role) { - b, err := role.Marshal() - if err != nil { - plog.Panicf("failed to marshal role struct (name: %s): %s", role.Name, err) - } - - tx.UnsafePut(authRolesBucketName, []byte(role.Name), b) -} - -func delRole(tx backend.BatchTx, rolename string) { - tx.UnsafeDelete(authRolesBucketName, []byte(rolename)) -} - -func (as *authStore) isAuthEnabled() bool { - as.enabledMu.RLock() - defer as.enabledMu.RUnlock() - return as.enabled -} - -func NewAuthStore(be backend.Backend, tp TokenProvider) *authStore { - tx := be.BatchTx() - tx.Lock() - - tx.UnsafeCreateBucket(authBucketName) - tx.UnsafeCreateBucket(authUsersBucketName) - tx.UnsafeCreateBucket(authRolesBucketName) - - enabled := false - _, vs := tx.UnsafeRange(authBucketName, enableFlagKey, nil, 0) - if len(vs) == 1 { - if bytes.Equal(vs[0], authEnabled) { - enabled = true - } - } - - as := &authStore{ - be: be, - revision: getRevision(tx), - enabled: enabled, - rangePermCache: make(map[string]*unifiedRangePermissions), - tokenProvider: tp, - } - - if enabled { - as.tokenProvider.enable() - } - - if as.Revision() == 0 { - as.commitRevision(tx) - } - - tx.Unlock() - be.ForceCommit() - - return as -} - -func hasRootRole(u *authpb.User) bool { - // u.Roles is sorted in UserGrantRole(), so we can use binary search. - idx := sort.SearchStrings(u.Roles, rootRole) - return idx != len(u.Roles) && u.Roles[idx] == rootRole -} - -func (as *authStore) commitRevision(tx backend.BatchTx) { - atomic.AddUint64(&as.revision, 1) - revBytes := make([]byte, revBytesLen) - binary.BigEndian.PutUint64(revBytes, as.Revision()) - tx.UnsafePut(authBucketName, revisionKey, revBytes) -} - -func getRevision(tx backend.BatchTx) uint64 { - _, vs := tx.UnsafeRange(authBucketName, []byte(revisionKey), nil, 0) - if len(vs) != 1 { - // this can happen in the initialization phase - return 0 - } - - return binary.BigEndian.Uint64(vs[0]) -} - -func (as *authStore) setRevision(rev uint64) { - atomic.StoreUint64(&as.revision, rev) -} - -func (as *authStore) Revision() uint64 { - return atomic.LoadUint64(&as.revision) -} - -func (as *authStore) AuthInfoFromTLS(ctx context.Context) *AuthInfo { - peer, ok := peer.FromContext(ctx) - if !ok || peer == nil || peer.AuthInfo == nil { - return nil - } - - tlsInfo := peer.AuthInfo.(credentials.TLSInfo) - for _, chains := range tlsInfo.State.VerifiedChains { - for _, chain := range chains { - cn := chain.Subject.CommonName - plog.Debugf("found common name %s", cn) - - ai := &AuthInfo{ - Username: cn, - Revision: as.Revision(), - } - md, ok := metadata.FromIncomingContext(ctx) - if !ok { - return nil - } - - // gRPC-gateway proxy request to etcd server includes Grpcgateway-Accept - // header. The proxy uses etcd client server certificate. If the certificate - // has a CommonName we should never use this for authentication. - if gw := md["grpcgateway-accept"]; len(gw) > 0 { - plog.Warningf("ignoring common name in gRPC-gateway proxy request %s", ai.Username) - return nil - } - return ai - } - } - - return nil -} - -func (as *authStore) AuthInfoFromCtx(ctx context.Context) (*AuthInfo, error) { - md, ok := metadata.FromIncomingContext(ctx) - if !ok { - return nil, nil - } - - //TODO(mitake|hexfusion) review unifying key names - ts, ok := md["token"] - if !ok { - ts, ok = md["authorization"] - } - if !ok { - return nil, nil - } - - token := ts[0] - authInfo, uok := as.authInfoFromToken(ctx, token) - if !uok { - plog.Warningf("invalid auth token: %s", token) - return nil, ErrInvalidAuthToken - } - - return authInfo, nil -} - -func (as *authStore) GenTokenPrefix() (string, error) { - return as.tokenProvider.genTokenPrefix() -} - -func decomposeOpts(optstr string) (string, map[string]string, error) { - opts := strings.Split(optstr, ",") - tokenType := opts[0] - - typeSpecificOpts := make(map[string]string) - for i := 1; i < len(opts); i++ { - pair := strings.Split(opts[i], "=") - - if len(pair) != 2 { - plog.Errorf("invalid token specific option: %s", optstr) - return "", nil, ErrInvalidAuthOpts - } - - if _, ok := typeSpecificOpts[pair[0]]; ok { - plog.Errorf("invalid token specific option, duplicated parameters (%s): %s", pair[0], optstr) - return "", nil, ErrInvalidAuthOpts - } - - typeSpecificOpts[pair[0]] = pair[1] - } - - return tokenType, typeSpecificOpts, nil - -} - -func NewTokenProvider(tokenOpts string, indexWaiter func(uint64) <-chan struct{}) (TokenProvider, error) { - tokenType, typeSpecificOpts, err := decomposeOpts(tokenOpts) - if err != nil { - return nil, ErrInvalidAuthOpts - } - - switch tokenType { - case tokenTypeSimple: - plog.Warningf("simple token is not cryptographically signed") - return newTokenProviderSimple(indexWaiter), nil - - case tokenTypeJWT: - return newTokenProviderJWT(typeSpecificOpts) - - case "": - return newTokenProviderNop() - default: - plog.Errorf("unknown token type: %s", tokenType) - return nil, ErrInvalidAuthOpts - } -} - -func (as *authStore) WithRoot(ctx context.Context) context.Context { - if !as.isAuthEnabled() { - return ctx - } - - var ctxForAssign context.Context - if ts, ok := as.tokenProvider.(*tokenSimple); ok && ts != nil { - ctx1 := context.WithValue(ctx, AuthenticateParamIndex{}, uint64(0)) - prefix, err := ts.genTokenPrefix() - if err != nil { - plog.Errorf("failed to generate prefix of internally used token") - return ctx - } - ctxForAssign = context.WithValue(ctx1, AuthenticateParamSimpleTokenPrefix{}, prefix) - } else { - ctxForAssign = ctx - } - - token, err := as.tokenProvider.assign(ctxForAssign, "root", as.Revision()) - if err != nil { - // this must not happen - plog.Errorf("failed to assign token for lease revoking: %s", err) - return ctx - } - - mdMap := map[string]string{ - "token": token, - } - tokenMD := metadata.New(mdMap) - - // use "mdIncomingKey{}" since it's called from local etcdserver - return metadata.NewIncomingContext(ctx, tokenMD) -} - -func (as *authStore) HasRole(user, role string) bool { - tx := as.be.BatchTx() - tx.Lock() - u := getUser(tx, user) - tx.Unlock() - - if u == nil { - plog.Warningf("tried to check user %s has role %s, but user %s doesn't exist", user, role, user) - return false - } - - for _, r := range u.Roles { - if role == r { - return true - } - } - - return false -} diff --git a/vendor/github.com/coreos/etcd/client/auth_role.go b/vendor/github.com/coreos/etcd/client/auth_role.go deleted file mode 100644 index b6ba7e150dc6..000000000000 --- a/vendor/github.com/coreos/etcd/client/auth_role.go +++ /dev/null @@ -1,236 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "bytes" - "context" - "encoding/json" - "net/http" - "net/url" -) - -type Role struct { - Role string `json:"role"` - Permissions Permissions `json:"permissions"` - Grant *Permissions `json:"grant,omitempty"` - Revoke *Permissions `json:"revoke,omitempty"` -} - -type Permissions struct { - KV rwPermission `json:"kv"` -} - -type rwPermission struct { - Read []string `json:"read"` - Write []string `json:"write"` -} - -type PermissionType int - -const ( - ReadPermission PermissionType = iota - WritePermission - ReadWritePermission -) - -// NewAuthRoleAPI constructs a new AuthRoleAPI that uses HTTP to -// interact with etcd's role creation and modification features. -func NewAuthRoleAPI(c Client) AuthRoleAPI { - return &httpAuthRoleAPI{ - client: c, - } -} - -type AuthRoleAPI interface { - // AddRole adds a role. - AddRole(ctx context.Context, role string) error - - // RemoveRole removes a role. - RemoveRole(ctx context.Context, role string) error - - // GetRole retrieves role details. - GetRole(ctx context.Context, role string) (*Role, error) - - // GrantRoleKV grants a role some permission prefixes for the KV store. - GrantRoleKV(ctx context.Context, role string, prefixes []string, permType PermissionType) (*Role, error) - - // RevokeRoleKV revokes some permission prefixes for a role on the KV store. - RevokeRoleKV(ctx context.Context, role string, prefixes []string, permType PermissionType) (*Role, error) - - // ListRoles lists roles. - ListRoles(ctx context.Context) ([]string, error) -} - -type httpAuthRoleAPI struct { - client httpClient -} - -type authRoleAPIAction struct { - verb string - name string - role *Role -} - -type authRoleAPIList struct{} - -func (list *authRoleAPIList) HTTPRequest(ep url.URL) *http.Request { - u := v2AuthURL(ep, "roles", "") - req, _ := http.NewRequest("GET", u.String(), nil) - req.Header.Set("Content-Type", "application/json") - return req -} - -func (l *authRoleAPIAction) HTTPRequest(ep url.URL) *http.Request { - u := v2AuthURL(ep, "roles", l.name) - if l.role == nil { - req, _ := http.NewRequest(l.verb, u.String(), nil) - return req - } - b, err := json.Marshal(l.role) - if err != nil { - panic(err) - } - body := bytes.NewReader(b) - req, _ := http.NewRequest(l.verb, u.String(), body) - req.Header.Set("Content-Type", "application/json") - return req -} - -func (r *httpAuthRoleAPI) ListRoles(ctx context.Context) ([]string, error) { - resp, body, err := r.client.Do(ctx, &authRoleAPIList{}) - if err != nil { - return nil, err - } - if err = assertStatusCode(resp.StatusCode, http.StatusOK); err != nil { - return nil, err - } - var roleList struct { - Roles []Role `json:"roles"` - } - if err = json.Unmarshal(body, &roleList); err != nil { - return nil, err - } - ret := make([]string, 0, len(roleList.Roles)) - for _, r := range roleList.Roles { - ret = append(ret, r.Role) - } - return ret, nil -} - -func (r *httpAuthRoleAPI) AddRole(ctx context.Context, rolename string) error { - role := &Role{ - Role: rolename, - } - return r.addRemoveRole(ctx, &authRoleAPIAction{ - verb: "PUT", - name: rolename, - role: role, - }) -} - -func (r *httpAuthRoleAPI) RemoveRole(ctx context.Context, rolename string) error { - return r.addRemoveRole(ctx, &authRoleAPIAction{ - verb: "DELETE", - name: rolename, - }) -} - -func (r *httpAuthRoleAPI) addRemoveRole(ctx context.Context, req *authRoleAPIAction) error { - resp, body, err := r.client.Do(ctx, req) - if err != nil { - return err - } - if err := assertStatusCode(resp.StatusCode, http.StatusOK, http.StatusCreated); err != nil { - var sec authError - err := json.Unmarshal(body, &sec) - if err != nil { - return err - } - return sec - } - return nil -} - -func (r *httpAuthRoleAPI) GetRole(ctx context.Context, rolename string) (*Role, error) { - return r.modRole(ctx, &authRoleAPIAction{ - verb: "GET", - name: rolename, - }) -} - -func buildRWPermission(prefixes []string, permType PermissionType) rwPermission { - var out rwPermission - switch permType { - case ReadPermission: - out.Read = prefixes - case WritePermission: - out.Write = prefixes - case ReadWritePermission: - out.Read = prefixes - out.Write = prefixes - } - return out -} - -func (r *httpAuthRoleAPI) GrantRoleKV(ctx context.Context, rolename string, prefixes []string, permType PermissionType) (*Role, error) { - rwp := buildRWPermission(prefixes, permType) - role := &Role{ - Role: rolename, - Grant: &Permissions{ - KV: rwp, - }, - } - return r.modRole(ctx, &authRoleAPIAction{ - verb: "PUT", - name: rolename, - role: role, - }) -} - -func (r *httpAuthRoleAPI) RevokeRoleKV(ctx context.Context, rolename string, prefixes []string, permType PermissionType) (*Role, error) { - rwp := buildRWPermission(prefixes, permType) - role := &Role{ - Role: rolename, - Revoke: &Permissions{ - KV: rwp, - }, - } - return r.modRole(ctx, &authRoleAPIAction{ - verb: "PUT", - name: rolename, - role: role, - }) -} - -func (r *httpAuthRoleAPI) modRole(ctx context.Context, req *authRoleAPIAction) (*Role, error) { - resp, body, err := r.client.Do(ctx, req) - if err != nil { - return nil, err - } - if err = assertStatusCode(resp.StatusCode, http.StatusOK); err != nil { - var sec authError - err = json.Unmarshal(body, &sec) - if err != nil { - return nil, err - } - return nil, sec - } - var role Role - if err = json.Unmarshal(body, &role); err != nil { - return nil, err - } - return &role, nil -} diff --git a/vendor/github.com/coreos/etcd/client/auth_user.go b/vendor/github.com/coreos/etcd/client/auth_user.go deleted file mode 100644 index 8e7e2efe8333..000000000000 --- a/vendor/github.com/coreos/etcd/client/auth_user.go +++ /dev/null @@ -1,319 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "bytes" - "context" - "encoding/json" - "net/http" - "net/url" - "path" -) - -var ( - defaultV2AuthPrefix = "/v2/auth" -) - -type User struct { - User string `json:"user"` - Password string `json:"password,omitempty"` - Roles []string `json:"roles"` - Grant []string `json:"grant,omitempty"` - Revoke []string `json:"revoke,omitempty"` -} - -// userListEntry is the user representation given by the server for ListUsers -type userListEntry struct { - User string `json:"user"` - Roles []Role `json:"roles"` -} - -type UserRoles struct { - User string `json:"user"` - Roles []Role `json:"roles"` -} - -func v2AuthURL(ep url.URL, action string, name string) *url.URL { - if name != "" { - ep.Path = path.Join(ep.Path, defaultV2AuthPrefix, action, name) - return &ep - } - ep.Path = path.Join(ep.Path, defaultV2AuthPrefix, action) - return &ep -} - -// NewAuthAPI constructs a new AuthAPI that uses HTTP to -// interact with etcd's general auth features. -func NewAuthAPI(c Client) AuthAPI { - return &httpAuthAPI{ - client: c, - } -} - -type AuthAPI interface { - // Enable auth. - Enable(ctx context.Context) error - - // Disable auth. - Disable(ctx context.Context) error -} - -type httpAuthAPI struct { - client httpClient -} - -func (s *httpAuthAPI) Enable(ctx context.Context) error { - return s.enableDisable(ctx, &authAPIAction{"PUT"}) -} - -func (s *httpAuthAPI) Disable(ctx context.Context) error { - return s.enableDisable(ctx, &authAPIAction{"DELETE"}) -} - -func (s *httpAuthAPI) enableDisable(ctx context.Context, req httpAction) error { - resp, body, err := s.client.Do(ctx, req) - if err != nil { - return err - } - if err = assertStatusCode(resp.StatusCode, http.StatusOK, http.StatusCreated); err != nil { - var sec authError - err = json.Unmarshal(body, &sec) - if err != nil { - return err - } - return sec - } - return nil -} - -type authAPIAction struct { - verb string -} - -func (l *authAPIAction) HTTPRequest(ep url.URL) *http.Request { - u := v2AuthURL(ep, "enable", "") - req, _ := http.NewRequest(l.verb, u.String(), nil) - return req -} - -type authError struct { - Message string `json:"message"` - Code int `json:"-"` -} - -func (e authError) Error() string { - return e.Message -} - -// NewAuthUserAPI constructs a new AuthUserAPI that uses HTTP to -// interact with etcd's user creation and modification features. -func NewAuthUserAPI(c Client) AuthUserAPI { - return &httpAuthUserAPI{ - client: c, - } -} - -type AuthUserAPI interface { - // AddUser adds a user. - AddUser(ctx context.Context, username string, password string) error - - // RemoveUser removes a user. - RemoveUser(ctx context.Context, username string) error - - // GetUser retrieves user details. - GetUser(ctx context.Context, username string) (*User, error) - - // GrantUser grants a user some permission roles. - GrantUser(ctx context.Context, username string, roles []string) (*User, error) - - // RevokeUser revokes some permission roles from a user. - RevokeUser(ctx context.Context, username string, roles []string) (*User, error) - - // ChangePassword changes the user's password. - ChangePassword(ctx context.Context, username string, password string) (*User, error) - - // ListUsers lists the users. - ListUsers(ctx context.Context) ([]string, error) -} - -type httpAuthUserAPI struct { - client httpClient -} - -type authUserAPIAction struct { - verb string - username string - user *User -} - -type authUserAPIList struct{} - -func (list *authUserAPIList) HTTPRequest(ep url.URL) *http.Request { - u := v2AuthURL(ep, "users", "") - req, _ := http.NewRequest("GET", u.String(), nil) - req.Header.Set("Content-Type", "application/json") - return req -} - -func (l *authUserAPIAction) HTTPRequest(ep url.URL) *http.Request { - u := v2AuthURL(ep, "users", l.username) - if l.user == nil { - req, _ := http.NewRequest(l.verb, u.String(), nil) - return req - } - b, err := json.Marshal(l.user) - if err != nil { - panic(err) - } - body := bytes.NewReader(b) - req, _ := http.NewRequest(l.verb, u.String(), body) - req.Header.Set("Content-Type", "application/json") - return req -} - -func (u *httpAuthUserAPI) ListUsers(ctx context.Context) ([]string, error) { - resp, body, err := u.client.Do(ctx, &authUserAPIList{}) - if err != nil { - return nil, err - } - if err = assertStatusCode(resp.StatusCode, http.StatusOK); err != nil { - var sec authError - err = json.Unmarshal(body, &sec) - if err != nil { - return nil, err - } - return nil, sec - } - - var userList struct { - Users []userListEntry `json:"users"` - } - - if err = json.Unmarshal(body, &userList); err != nil { - return nil, err - } - - ret := make([]string, 0, len(userList.Users)) - for _, u := range userList.Users { - ret = append(ret, u.User) - } - return ret, nil -} - -func (u *httpAuthUserAPI) AddUser(ctx context.Context, username string, password string) error { - user := &User{ - User: username, - Password: password, - } - return u.addRemoveUser(ctx, &authUserAPIAction{ - verb: "PUT", - username: username, - user: user, - }) -} - -func (u *httpAuthUserAPI) RemoveUser(ctx context.Context, username string) error { - return u.addRemoveUser(ctx, &authUserAPIAction{ - verb: "DELETE", - username: username, - }) -} - -func (u *httpAuthUserAPI) addRemoveUser(ctx context.Context, req *authUserAPIAction) error { - resp, body, err := u.client.Do(ctx, req) - if err != nil { - return err - } - if err = assertStatusCode(resp.StatusCode, http.StatusOK, http.StatusCreated); err != nil { - var sec authError - err = json.Unmarshal(body, &sec) - if err != nil { - return err - } - return sec - } - return nil -} - -func (u *httpAuthUserAPI) GetUser(ctx context.Context, username string) (*User, error) { - return u.modUser(ctx, &authUserAPIAction{ - verb: "GET", - username: username, - }) -} - -func (u *httpAuthUserAPI) GrantUser(ctx context.Context, username string, roles []string) (*User, error) { - user := &User{ - User: username, - Grant: roles, - } - return u.modUser(ctx, &authUserAPIAction{ - verb: "PUT", - username: username, - user: user, - }) -} - -func (u *httpAuthUserAPI) RevokeUser(ctx context.Context, username string, roles []string) (*User, error) { - user := &User{ - User: username, - Revoke: roles, - } - return u.modUser(ctx, &authUserAPIAction{ - verb: "PUT", - username: username, - user: user, - }) -} - -func (u *httpAuthUserAPI) ChangePassword(ctx context.Context, username string, password string) (*User, error) { - user := &User{ - User: username, - Password: password, - } - return u.modUser(ctx, &authUserAPIAction{ - verb: "PUT", - username: username, - user: user, - }) -} - -func (u *httpAuthUserAPI) modUser(ctx context.Context, req *authUserAPIAction) (*User, error) { - resp, body, err := u.client.Do(ctx, req) - if err != nil { - return nil, err - } - if err = assertStatusCode(resp.StatusCode, http.StatusOK); err != nil { - var sec authError - err = json.Unmarshal(body, &sec) - if err != nil { - return nil, err - } - return nil, sec - } - var user User - if err = json.Unmarshal(body, &user); err != nil { - var userR UserRoles - if urerr := json.Unmarshal(body, &userR); urerr != nil { - return nil, err - } - user.User = userR.User - for _, r := range userR.Roles { - user.Roles = append(user.Roles, r.Role) - } - } - return &user, nil -} diff --git a/vendor/github.com/coreos/etcd/client/cancelreq.go b/vendor/github.com/coreos/etcd/client/cancelreq.go deleted file mode 100644 index 76d1f040198b..000000000000 --- a/vendor/github.com/coreos/etcd/client/cancelreq.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// borrowed from golang/net/context/ctxhttp/cancelreq.go - -package client - -import "net/http" - -func requestCanceler(tr CancelableTransport, req *http.Request) func() { - ch := make(chan struct{}) - req.Cancel = ch - - return func() { - close(ch) - } -} diff --git a/vendor/github.com/coreos/etcd/client/client.go b/vendor/github.com/coreos/etcd/client/client.go deleted file mode 100644 index e6874505666b..000000000000 --- a/vendor/github.com/coreos/etcd/client/client.go +++ /dev/null @@ -1,710 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "math/rand" - "net" - "net/http" - "net/url" - "sort" - "strconv" - "sync" - "time" - - "github.com/coreos/etcd/version" -) - -var ( - ErrNoEndpoints = errors.New("client: no endpoints available") - ErrTooManyRedirects = errors.New("client: too many redirects") - ErrClusterUnavailable = errors.New("client: etcd cluster is unavailable or misconfigured") - ErrNoLeaderEndpoint = errors.New("client: no leader endpoint available") - errTooManyRedirectChecks = errors.New("client: too many redirect checks") - - // oneShotCtxValue is set on a context using WithValue(&oneShotValue) so - // that Do() will not retry a request - oneShotCtxValue interface{} -) - -var DefaultRequestTimeout = 5 * time.Second - -var DefaultTransport CancelableTransport = &http.Transport{ - Proxy: http.ProxyFromEnvironment, - Dial: (&net.Dialer{ - Timeout: 30 * time.Second, - KeepAlive: 30 * time.Second, - }).Dial, - TLSHandshakeTimeout: 10 * time.Second, -} - -type EndpointSelectionMode int - -const ( - // EndpointSelectionRandom is the default value of the 'SelectionMode'. - // As the name implies, the client object will pick a node from the members - // of the cluster in a random fashion. If the cluster has three members, A, B, - // and C, the client picks any node from its three members as its request - // destination. - EndpointSelectionRandom EndpointSelectionMode = iota - - // If 'SelectionMode' is set to 'EndpointSelectionPrioritizeLeader', - // requests are sent directly to the cluster leader. This reduces - // forwarding roundtrips compared to making requests to etcd followers - // who then forward them to the cluster leader. In the event of a leader - // failure, however, clients configured this way cannot prioritize among - // the remaining etcd followers. Therefore, when a client sets 'SelectionMode' - // to 'EndpointSelectionPrioritizeLeader', it must use 'client.AutoSync()' to - // maintain its knowledge of current cluster state. - // - // This mode should be used with Client.AutoSync(). - EndpointSelectionPrioritizeLeader -) - -type Config struct { - // Endpoints defines a set of URLs (schemes, hosts and ports only) - // that can be used to communicate with a logical etcd cluster. For - // example, a three-node cluster could be provided like so: - // - // Endpoints: []string{ - // "http://node1.example.com:2379", - // "http://node2.example.com:2379", - // "http://node3.example.com:2379", - // } - // - // If multiple endpoints are provided, the Client will attempt to - // use them all in the event that one or more of them are unusable. - // - // If Client.Sync is ever called, the Client may cache an alternate - // set of endpoints to continue operation. - Endpoints []string - - // Transport is used by the Client to drive HTTP requests. If not - // provided, DefaultTransport will be used. - Transport CancelableTransport - - // CheckRedirect specifies the policy for handling HTTP redirects. - // If CheckRedirect is not nil, the Client calls it before - // following an HTTP redirect. The sole argument is the number of - // requests that have already been made. If CheckRedirect returns - // an error, Client.Do will not make any further requests and return - // the error back it to the caller. - // - // If CheckRedirect is nil, the Client uses its default policy, - // which is to stop after 10 consecutive requests. - CheckRedirect CheckRedirectFunc - - // Username specifies the user credential to add as an authorization header - Username string - - // Password is the password for the specified user to add as an authorization header - // to the request. - Password string - - // HeaderTimeoutPerRequest specifies the time limit to wait for response - // header in a single request made by the Client. The timeout includes - // connection time, any redirects, and header wait time. - // - // For non-watch GET request, server returns the response body immediately. - // For PUT/POST/DELETE request, server will attempt to commit request - // before responding, which is expected to take `100ms + 2 * RTT`. - // For watch request, server returns the header immediately to notify Client - // watch start. But if server is behind some kind of proxy, the response - // header may be cached at proxy, and Client cannot rely on this behavior. - // - // Especially, wait request will ignore this timeout. - // - // One API call may send multiple requests to different etcd servers until it - // succeeds. Use context of the API to specify the overall timeout. - // - // A HeaderTimeoutPerRequest of zero means no timeout. - HeaderTimeoutPerRequest time.Duration - - // SelectionMode is an EndpointSelectionMode enum that specifies the - // policy for choosing the etcd cluster node to which requests are sent. - SelectionMode EndpointSelectionMode -} - -func (cfg *Config) transport() CancelableTransport { - if cfg.Transport == nil { - return DefaultTransport - } - return cfg.Transport -} - -func (cfg *Config) checkRedirect() CheckRedirectFunc { - if cfg.CheckRedirect == nil { - return DefaultCheckRedirect - } - return cfg.CheckRedirect -} - -// CancelableTransport mimics net/http.Transport, but requires that -// the object also support request cancellation. -type CancelableTransport interface { - http.RoundTripper - CancelRequest(req *http.Request) -} - -type CheckRedirectFunc func(via int) error - -// DefaultCheckRedirect follows up to 10 redirects, but no more. -var DefaultCheckRedirect CheckRedirectFunc = func(via int) error { - if via > 10 { - return ErrTooManyRedirects - } - return nil -} - -type Client interface { - // Sync updates the internal cache of the etcd cluster's membership. - Sync(context.Context) error - - // AutoSync periodically calls Sync() every given interval. - // The recommended sync interval is 10 seconds to 1 minute, which does - // not bring too much overhead to server and makes client catch up the - // cluster change in time. - // - // The example to use it: - // - // for { - // err := client.AutoSync(ctx, 10*time.Second) - // if err == context.DeadlineExceeded || err == context.Canceled { - // break - // } - // log.Print(err) - // } - AutoSync(context.Context, time.Duration) error - - // Endpoints returns a copy of the current set of API endpoints used - // by Client to resolve HTTP requests. If Sync has ever been called, - // this may differ from the initial Endpoints provided in the Config. - Endpoints() []string - - // SetEndpoints sets the set of API endpoints used by Client to resolve - // HTTP requests. If the given endpoints are not valid, an error will be - // returned - SetEndpoints(eps []string) error - - // GetVersion retrieves the current etcd server and cluster version - GetVersion(ctx context.Context) (*version.Versions, error) - - httpClient -} - -func New(cfg Config) (Client, error) { - c := &httpClusterClient{ - clientFactory: newHTTPClientFactory(cfg.transport(), cfg.checkRedirect(), cfg.HeaderTimeoutPerRequest), - rand: rand.New(rand.NewSource(int64(time.Now().Nanosecond()))), - selectionMode: cfg.SelectionMode, - } - if cfg.Username != "" { - c.credentials = &credentials{ - username: cfg.Username, - password: cfg.Password, - } - } - if err := c.SetEndpoints(cfg.Endpoints); err != nil { - return nil, err - } - return c, nil -} - -type httpClient interface { - Do(context.Context, httpAction) (*http.Response, []byte, error) -} - -func newHTTPClientFactory(tr CancelableTransport, cr CheckRedirectFunc, headerTimeout time.Duration) httpClientFactory { - return func(ep url.URL) httpClient { - return &redirectFollowingHTTPClient{ - checkRedirect: cr, - client: &simpleHTTPClient{ - transport: tr, - endpoint: ep, - headerTimeout: headerTimeout, - }, - } - } -} - -type credentials struct { - username string - password string -} - -type httpClientFactory func(url.URL) httpClient - -type httpAction interface { - HTTPRequest(url.URL) *http.Request -} - -type httpClusterClient struct { - clientFactory httpClientFactory - endpoints []url.URL - pinned int - credentials *credentials - sync.RWMutex - rand *rand.Rand - selectionMode EndpointSelectionMode -} - -func (c *httpClusterClient) getLeaderEndpoint(ctx context.Context, eps []url.URL) (string, error) { - ceps := make([]url.URL, len(eps)) - copy(ceps, eps) - - // To perform a lookup on the new endpoint list without using the current - // client, we'll copy it - clientCopy := &httpClusterClient{ - clientFactory: c.clientFactory, - credentials: c.credentials, - rand: c.rand, - - pinned: 0, - endpoints: ceps, - } - - mAPI := NewMembersAPI(clientCopy) - leader, err := mAPI.Leader(ctx) - if err != nil { - return "", err - } - if len(leader.ClientURLs) == 0 { - return "", ErrNoLeaderEndpoint - } - - return leader.ClientURLs[0], nil // TODO: how to handle multiple client URLs? -} - -func (c *httpClusterClient) parseEndpoints(eps []string) ([]url.URL, error) { - if len(eps) == 0 { - return []url.URL{}, ErrNoEndpoints - } - - neps := make([]url.URL, len(eps)) - for i, ep := range eps { - u, err := url.Parse(ep) - if err != nil { - return []url.URL{}, err - } - neps[i] = *u - } - return neps, nil -} - -func (c *httpClusterClient) SetEndpoints(eps []string) error { - neps, err := c.parseEndpoints(eps) - if err != nil { - return err - } - - c.Lock() - defer c.Unlock() - - c.endpoints = shuffleEndpoints(c.rand, neps) - // We're not doing anything for PrioritizeLeader here. This is - // due to not having a context meaning we can't call getLeaderEndpoint - // However, if you're using PrioritizeLeader, you've already been told - // to regularly call sync, where we do have a ctx, and can figure the - // leader. PrioritizeLeader is also quite a loose guarantee, so deal - // with it - c.pinned = 0 - - return nil -} - -func (c *httpClusterClient) Do(ctx context.Context, act httpAction) (*http.Response, []byte, error) { - action := act - c.RLock() - leps := len(c.endpoints) - eps := make([]url.URL, leps) - n := copy(eps, c.endpoints) - pinned := c.pinned - - if c.credentials != nil { - action = &authedAction{ - act: act, - credentials: *c.credentials, - } - } - c.RUnlock() - - if leps == 0 { - return nil, nil, ErrNoEndpoints - } - - if leps != n { - return nil, nil, errors.New("unable to pick endpoint: copy failed") - } - - var resp *http.Response - var body []byte - var err error - cerr := &ClusterError{} - isOneShot := ctx.Value(&oneShotCtxValue) != nil - - for i := pinned; i < leps+pinned; i++ { - k := i % leps - hc := c.clientFactory(eps[k]) - resp, body, err = hc.Do(ctx, action) - if err != nil { - cerr.Errors = append(cerr.Errors, err) - if err == ctx.Err() { - return nil, nil, ctx.Err() - } - if err == context.Canceled || err == context.DeadlineExceeded { - return nil, nil, err - } - } else if resp.StatusCode/100 == 5 { - switch resp.StatusCode { - case http.StatusInternalServerError, http.StatusServiceUnavailable: - // TODO: make sure this is a no leader response - cerr.Errors = append(cerr.Errors, fmt.Errorf("client: etcd member %s has no leader", eps[k].String())) - default: - cerr.Errors = append(cerr.Errors, fmt.Errorf("client: etcd member %s returns server error [%s]", eps[k].String(), http.StatusText(resp.StatusCode))) - } - err = cerr.Errors[0] - } - if err != nil { - if !isOneShot { - continue - } - c.Lock() - c.pinned = (k + 1) % leps - c.Unlock() - return nil, nil, err - } - if k != pinned { - c.Lock() - c.pinned = k - c.Unlock() - } - return resp, body, nil - } - - return nil, nil, cerr -} - -func (c *httpClusterClient) Endpoints() []string { - c.RLock() - defer c.RUnlock() - - eps := make([]string, len(c.endpoints)) - for i, ep := range c.endpoints { - eps[i] = ep.String() - } - - return eps -} - -func (c *httpClusterClient) Sync(ctx context.Context) error { - mAPI := NewMembersAPI(c) - ms, err := mAPI.List(ctx) - if err != nil { - return err - } - - var eps []string - for _, m := range ms { - eps = append(eps, m.ClientURLs...) - } - - neps, err := c.parseEndpoints(eps) - if err != nil { - return err - } - - npin := 0 - - switch c.selectionMode { - case EndpointSelectionRandom: - c.RLock() - eq := endpointsEqual(c.endpoints, neps) - c.RUnlock() - - if eq { - return nil - } - // When items in the endpoint list changes, we choose a new pin - neps = shuffleEndpoints(c.rand, neps) - case EndpointSelectionPrioritizeLeader: - nle, err := c.getLeaderEndpoint(ctx, neps) - if err != nil { - return ErrNoLeaderEndpoint - } - - for i, n := range neps { - if n.String() == nle { - npin = i - break - } - } - default: - return fmt.Errorf("invalid endpoint selection mode: %d", c.selectionMode) - } - - c.Lock() - defer c.Unlock() - c.endpoints = neps - c.pinned = npin - - return nil -} - -func (c *httpClusterClient) AutoSync(ctx context.Context, interval time.Duration) error { - ticker := time.NewTicker(interval) - defer ticker.Stop() - for { - err := c.Sync(ctx) - if err != nil { - return err - } - select { - case <-ctx.Done(): - return ctx.Err() - case <-ticker.C: - } - } -} - -func (c *httpClusterClient) GetVersion(ctx context.Context) (*version.Versions, error) { - act := &getAction{Prefix: "/version"} - - resp, body, err := c.Do(ctx, act) - if err != nil { - return nil, err - } - - switch resp.StatusCode { - case http.StatusOK: - if len(body) == 0 { - return nil, ErrEmptyBody - } - var vresp version.Versions - if err := json.Unmarshal(body, &vresp); err != nil { - return nil, ErrInvalidJSON - } - return &vresp, nil - default: - var etcdErr Error - if err := json.Unmarshal(body, &etcdErr); err != nil { - return nil, ErrInvalidJSON - } - return nil, etcdErr - } -} - -type roundTripResponse struct { - resp *http.Response - err error -} - -type simpleHTTPClient struct { - transport CancelableTransport - endpoint url.URL - headerTimeout time.Duration -} - -func (c *simpleHTTPClient) Do(ctx context.Context, act httpAction) (*http.Response, []byte, error) { - req := act.HTTPRequest(c.endpoint) - - if err := printcURL(req); err != nil { - return nil, nil, err - } - - isWait := false - if req != nil && req.URL != nil { - ws := req.URL.Query().Get("wait") - if len(ws) != 0 { - var err error - isWait, err = strconv.ParseBool(ws) - if err != nil { - return nil, nil, fmt.Errorf("wrong wait value %s (%v for %+v)", ws, err, req) - } - } - } - - var hctx context.Context - var hcancel context.CancelFunc - if !isWait && c.headerTimeout > 0 { - hctx, hcancel = context.WithTimeout(ctx, c.headerTimeout) - } else { - hctx, hcancel = context.WithCancel(ctx) - } - defer hcancel() - - reqcancel := requestCanceler(c.transport, req) - - rtchan := make(chan roundTripResponse, 1) - go func() { - resp, err := c.transport.RoundTrip(req) - rtchan <- roundTripResponse{resp: resp, err: err} - close(rtchan) - }() - - var resp *http.Response - var err error - - select { - case rtresp := <-rtchan: - resp, err = rtresp.resp, rtresp.err - case <-hctx.Done(): - // cancel and wait for request to actually exit before continuing - reqcancel() - rtresp := <-rtchan - resp = rtresp.resp - switch { - case ctx.Err() != nil: - err = ctx.Err() - case hctx.Err() != nil: - err = fmt.Errorf("client: endpoint %s exceeded header timeout", c.endpoint.String()) - default: - panic("failed to get error from context") - } - } - - // always check for resp nil-ness to deal with possible - // race conditions between channels above - defer func() { - if resp != nil { - resp.Body.Close() - } - }() - - if err != nil { - return nil, nil, err - } - - var body []byte - done := make(chan struct{}) - go func() { - body, err = ioutil.ReadAll(resp.Body) - done <- struct{}{} - }() - - select { - case <-ctx.Done(): - resp.Body.Close() - <-done - return nil, nil, ctx.Err() - case <-done: - } - - return resp, body, err -} - -type authedAction struct { - act httpAction - credentials credentials -} - -func (a *authedAction) HTTPRequest(url url.URL) *http.Request { - r := a.act.HTTPRequest(url) - r.SetBasicAuth(a.credentials.username, a.credentials.password) - return r -} - -type redirectFollowingHTTPClient struct { - client httpClient - checkRedirect CheckRedirectFunc -} - -func (r *redirectFollowingHTTPClient) Do(ctx context.Context, act httpAction) (*http.Response, []byte, error) { - next := act - for i := 0; i < 100; i++ { - if i > 0 { - if err := r.checkRedirect(i); err != nil { - return nil, nil, err - } - } - resp, body, err := r.client.Do(ctx, next) - if err != nil { - return nil, nil, err - } - if resp.StatusCode/100 == 3 { - hdr := resp.Header.Get("Location") - if hdr == "" { - return nil, nil, fmt.Errorf("Location header not set") - } - loc, err := url.Parse(hdr) - if err != nil { - return nil, nil, fmt.Errorf("Location header not valid URL: %s", hdr) - } - next = &redirectedHTTPAction{ - action: act, - location: *loc, - } - continue - } - return resp, body, nil - } - - return nil, nil, errTooManyRedirectChecks -} - -type redirectedHTTPAction struct { - action httpAction - location url.URL -} - -func (r *redirectedHTTPAction) HTTPRequest(ep url.URL) *http.Request { - orig := r.action.HTTPRequest(ep) - orig.URL = &r.location - return orig -} - -func shuffleEndpoints(r *rand.Rand, eps []url.URL) []url.URL { - // copied from Go 1.9<= rand.Rand.Perm - n := len(eps) - p := make([]int, n) - for i := 0; i < n; i++ { - j := r.Intn(i + 1) - p[i] = p[j] - p[j] = i - } - neps := make([]url.URL, n) - for i, k := range p { - neps[i] = eps[k] - } - return neps -} - -func endpointsEqual(left, right []url.URL) bool { - if len(left) != len(right) { - return false - } - - sLeft := make([]string, len(left)) - sRight := make([]string, len(right)) - for i, l := range left { - sLeft[i] = l.String() - } - for i, r := range right { - sRight[i] = r.String() - } - - sort.Strings(sLeft) - sort.Strings(sRight) - for i := range sLeft { - if sLeft[i] != sRight[i] { - return false - } - } - return true -} diff --git a/vendor/github.com/coreos/etcd/client/cluster_error.go b/vendor/github.com/coreos/etcd/client/cluster_error.go deleted file mode 100644 index 34618cdbd9e6..000000000000 --- a/vendor/github.com/coreos/etcd/client/cluster_error.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import "fmt" - -type ClusterError struct { - Errors []error -} - -func (ce *ClusterError) Error() string { - s := ErrClusterUnavailable.Error() - for i, e := range ce.Errors { - s += fmt.Sprintf("; error #%d: %s\n", i, e) - } - return s -} - -func (ce *ClusterError) Detail() string { - s := "" - for i, e := range ce.Errors { - s += fmt.Sprintf("error #%d: %s\n", i, e) - } - return s -} diff --git a/vendor/github.com/coreos/etcd/client/curl.go b/vendor/github.com/coreos/etcd/client/curl.go deleted file mode 100644 index c8bc9fba20ec..000000000000 --- a/vendor/github.com/coreos/etcd/client/curl.go +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "os" -) - -var ( - cURLDebug = false -) - -func EnablecURLDebug() { - cURLDebug = true -} - -func DisablecURLDebug() { - cURLDebug = false -} - -// printcURL prints the cURL equivalent request to stderr. -// It returns an error if the body of the request cannot -// be read. -// The caller MUST cancel the request if there is an error. -func printcURL(req *http.Request) error { - if !cURLDebug { - return nil - } - var ( - command string - b []byte - err error - ) - - if req.URL != nil { - command = fmt.Sprintf("curl -X %s %s", req.Method, req.URL.String()) - } - - if req.Body != nil { - b, err = ioutil.ReadAll(req.Body) - if err != nil { - return err - } - command += fmt.Sprintf(" -d %q", string(b)) - } - - fmt.Fprintf(os.Stderr, "cURL Command: %s\n", command) - - // reset body - body := bytes.NewBuffer(b) - req.Body = ioutil.NopCloser(body) - - return nil -} diff --git a/vendor/github.com/coreos/etcd/client/discover.go b/vendor/github.com/coreos/etcd/client/discover.go deleted file mode 100644 index 442e35fe543b..000000000000 --- a/vendor/github.com/coreos/etcd/client/discover.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "github.com/coreos/etcd/pkg/srv" -) - -// Discoverer is an interface that wraps the Discover method. -type Discoverer interface { - // Discover looks up the etcd servers for the domain. - Discover(domain string) ([]string, error) -} - -type srvDiscover struct{} - -// NewSRVDiscover constructs a new Discoverer that uses the stdlib to lookup SRV records. -func NewSRVDiscover() Discoverer { - return &srvDiscover{} -} - -func (d *srvDiscover) Discover(domain string) ([]string, error) { - srvs, err := srv.GetClient("etcd-client", domain) - if err != nil { - return nil, err - } - return srvs.Endpoints, nil -} diff --git a/vendor/github.com/coreos/etcd/client/doc.go b/vendor/github.com/coreos/etcd/client/doc.go deleted file mode 100644 index ad4eca4e1635..000000000000 --- a/vendor/github.com/coreos/etcd/client/doc.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package client provides bindings for the etcd APIs. - -Create a Config and exchange it for a Client: - - import ( - "net/http" - "context" - - "github.com/coreos/etcd/client" - ) - - cfg := client.Config{ - Endpoints: []string{"http://127.0.0.1:2379"}, - Transport: DefaultTransport, - } - - c, err := client.New(cfg) - if err != nil { - // handle error - } - -Clients are safe for concurrent use by multiple goroutines. - -Create a KeysAPI using the Client, then use it to interact with etcd: - - kAPI := client.NewKeysAPI(c) - - // create a new key /foo with the value "bar" - _, err = kAPI.Create(context.Background(), "/foo", "bar") - if err != nil { - // handle error - } - - // delete the newly created key only if the value is still "bar" - _, err = kAPI.Delete(context.Background(), "/foo", &DeleteOptions{PrevValue: "bar"}) - if err != nil { - // handle error - } - -Use a custom context to set timeouts on your operations: - - import "time" - - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - - // set a new key, ignoring its previous state - _, err := kAPI.Set(ctx, "/ping", "pong", nil) - if err != nil { - if err == context.DeadlineExceeded { - // request took longer than 5s - } else { - // handle error - } - } - -*/ -package client diff --git a/vendor/github.com/coreos/etcd/client/json.go b/vendor/github.com/coreos/etcd/client/json.go deleted file mode 100644 index 97cdbcd7cfa5..000000000000 --- a/vendor/github.com/coreos/etcd/client/json.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2019 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "github.com/json-iterator/go" - "github.com/modern-go/reflect2" - "strconv" - "unsafe" -) - -type customNumberExtension struct { - jsoniter.DummyExtension -} - -func (cne *customNumberExtension) CreateDecoder(typ reflect2.Type) jsoniter.ValDecoder { - if typ.String() == "interface {}" { - return customNumberDecoder{} - } - return nil -} - -type customNumberDecoder struct { -} - -func (customNumberDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { - switch iter.WhatIsNext() { - case jsoniter.NumberValue: - var number jsoniter.Number - iter.ReadVal(&number) - i64, err := strconv.ParseInt(string(number), 10, 64) - if err == nil { - *(*interface{})(ptr) = i64 - return - } - f64, err := strconv.ParseFloat(string(number), 64) - if err == nil { - *(*interface{})(ptr) = f64 - return - } - iter.ReportError("DecodeNumber", err.Error()) - default: - *(*interface{})(ptr) = iter.Read() - } -} - -// caseSensitiveJsonIterator returns a jsoniterator API that's configured to be -// case-sensitive when unmarshalling, and otherwise compatible with -// the encoding/json standard library. -func caseSensitiveJsonIterator() jsoniter.API { - config := jsoniter.Config{ - EscapeHTML: true, - SortMapKeys: true, - ValidateJsonRawMessage: true, - CaseSensitive: true, - }.Froze() - // Force jsoniter to decode number to interface{} via int64/float64, if possible. - config.RegisterExtension(&customNumberExtension{}) - return config -} diff --git a/vendor/github.com/coreos/etcd/client/keys.go b/vendor/github.com/coreos/etcd/client/keys.go deleted file mode 100644 index f8f2c7b186c2..000000000000 --- a/vendor/github.com/coreos/etcd/client/keys.go +++ /dev/null @@ -1,680 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "net/url" - "strconv" - "strings" - "time" - - "github.com/coreos/etcd/pkg/pathutil" -) - -const ( - ErrorCodeKeyNotFound = 100 - ErrorCodeTestFailed = 101 - ErrorCodeNotFile = 102 - ErrorCodeNotDir = 104 - ErrorCodeNodeExist = 105 - ErrorCodeRootROnly = 107 - ErrorCodeDirNotEmpty = 108 - ErrorCodeUnauthorized = 110 - - ErrorCodePrevValueRequired = 201 - ErrorCodeTTLNaN = 202 - ErrorCodeIndexNaN = 203 - ErrorCodeInvalidField = 209 - ErrorCodeInvalidForm = 210 - - ErrorCodeRaftInternal = 300 - ErrorCodeLeaderElect = 301 - - ErrorCodeWatcherCleared = 400 - ErrorCodeEventIndexCleared = 401 -) - -type Error struct { - Code int `json:"errorCode"` - Message string `json:"message"` - Cause string `json:"cause"` - Index uint64 `json:"index"` -} - -func (e Error) Error() string { - return fmt.Sprintf("%v: %v (%v) [%v]", e.Code, e.Message, e.Cause, e.Index) -} - -var ( - ErrInvalidJSON = errors.New("client: response is invalid json. The endpoint is probably not valid etcd cluster endpoint.") - ErrEmptyBody = errors.New("client: response body is empty") -) - -// PrevExistType is used to define an existence condition when setting -// or deleting Nodes. -type PrevExistType string - -const ( - PrevIgnore = PrevExistType("") - PrevExist = PrevExistType("true") - PrevNoExist = PrevExistType("false") -) - -var ( - defaultV2KeysPrefix = "/v2/keys" -) - -// NewKeysAPI builds a KeysAPI that interacts with etcd's key-value -// API over HTTP. -func NewKeysAPI(c Client) KeysAPI { - return NewKeysAPIWithPrefix(c, defaultV2KeysPrefix) -} - -// NewKeysAPIWithPrefix acts like NewKeysAPI, but allows the caller -// to provide a custom base URL path. This should only be used in -// very rare cases. -func NewKeysAPIWithPrefix(c Client, p string) KeysAPI { - return &httpKeysAPI{ - client: c, - prefix: p, - } -} - -type KeysAPI interface { - // Get retrieves a set of Nodes from etcd - Get(ctx context.Context, key string, opts *GetOptions) (*Response, error) - - // Set assigns a new value to a Node identified by a given key. The caller - // may define a set of conditions in the SetOptions. If SetOptions.Dir=true - // then value is ignored. - Set(ctx context.Context, key, value string, opts *SetOptions) (*Response, error) - - // Delete removes a Node identified by the given key, optionally destroying - // all of its children as well. The caller may define a set of required - // conditions in an DeleteOptions object. - Delete(ctx context.Context, key string, opts *DeleteOptions) (*Response, error) - - // Create is an alias for Set w/ PrevExist=false - Create(ctx context.Context, key, value string) (*Response, error) - - // CreateInOrder is used to atomically create in-order keys within the given directory. - CreateInOrder(ctx context.Context, dir, value string, opts *CreateInOrderOptions) (*Response, error) - - // Update is an alias for Set w/ PrevExist=true - Update(ctx context.Context, key, value string) (*Response, error) - - // Watcher builds a new Watcher targeted at a specific Node identified - // by the given key. The Watcher may be configured at creation time - // through a WatcherOptions object. The returned Watcher is designed - // to emit events that happen to a Node, and optionally to its children. - Watcher(key string, opts *WatcherOptions) Watcher -} - -type WatcherOptions struct { - // AfterIndex defines the index after-which the Watcher should - // start emitting events. For example, if a value of 5 is - // provided, the first event will have an index >= 6. - // - // Setting AfterIndex to 0 (default) means that the Watcher - // should start watching for events starting at the current - // index, whatever that may be. - AfterIndex uint64 - - // Recursive specifies whether or not the Watcher should emit - // events that occur in children of the given keyspace. If set - // to false (default), events will be limited to those that - // occur for the exact key. - Recursive bool -} - -type CreateInOrderOptions struct { - // TTL defines a period of time after-which the Node should - // expire and no longer exist. Values <= 0 are ignored. Given - // that the zero-value is ignored, TTL cannot be used to set - // a TTL of 0. - TTL time.Duration -} - -type SetOptions struct { - // PrevValue specifies what the current value of the Node must - // be in order for the Set operation to succeed. - // - // Leaving this field empty means that the caller wishes to - // ignore the current value of the Node. This cannot be used - // to compare the Node's current value to an empty string. - // - // PrevValue is ignored if Dir=true - PrevValue string - - // PrevIndex indicates what the current ModifiedIndex of the - // Node must be in order for the Set operation to succeed. - // - // If PrevIndex is set to 0 (default), no comparison is made. - PrevIndex uint64 - - // PrevExist specifies whether the Node must currently exist - // (PrevExist) or not (PrevNoExist). If the caller does not - // care about existence, set PrevExist to PrevIgnore, or simply - // leave it unset. - PrevExist PrevExistType - - // TTL defines a period of time after-which the Node should - // expire and no longer exist. Values <= 0 are ignored. Given - // that the zero-value is ignored, TTL cannot be used to set - // a TTL of 0. - TTL time.Duration - - // Refresh set to true means a TTL value can be updated - // without firing a watch or changing the node value. A - // value must not be provided when refreshing a key. - Refresh bool - - // Dir specifies whether or not this Node should be created as a directory. - Dir bool - - // NoValueOnSuccess specifies whether the response contains the current value of the Node. - // If set, the response will only contain the current value when the request fails. - NoValueOnSuccess bool -} - -type GetOptions struct { - // Recursive defines whether or not all children of the Node - // should be returned. - Recursive bool - - // Sort instructs the server whether or not to sort the Nodes. - // If true, the Nodes are sorted alphabetically by key in - // ascending order (A to z). If false (default), the Nodes will - // not be sorted and the ordering used should not be considered - // predictable. - Sort bool - - // Quorum specifies whether it gets the latest committed value that - // has been applied in quorum of members, which ensures external - // consistency (or linearizability). - Quorum bool -} - -type DeleteOptions struct { - // PrevValue specifies what the current value of the Node must - // be in order for the Delete operation to succeed. - // - // Leaving this field empty means that the caller wishes to - // ignore the current value of the Node. This cannot be used - // to compare the Node's current value to an empty string. - PrevValue string - - // PrevIndex indicates what the current ModifiedIndex of the - // Node must be in order for the Delete operation to succeed. - // - // If PrevIndex is set to 0 (default), no comparison is made. - PrevIndex uint64 - - // Recursive defines whether or not all children of the Node - // should be deleted. If set to true, all children of the Node - // identified by the given key will be deleted. If left unset - // or explicitly set to false, only a single Node will be - // deleted. - Recursive bool - - // Dir specifies whether or not this Node should be removed as a directory. - Dir bool -} - -type Watcher interface { - // Next blocks until an etcd event occurs, then returns a Response - // representing that event. The behavior of Next depends on the - // WatcherOptions used to construct the Watcher. Next is designed to - // be called repeatedly, each time blocking until a subsequent event - // is available. - // - // If the provided context is cancelled, Next will return a non-nil - // error. Any other failures encountered while waiting for the next - // event (connection issues, deserialization failures, etc) will - // also result in a non-nil error. - Next(context.Context) (*Response, error) -} - -type Response struct { - // Action is the name of the operation that occurred. Possible values - // include get, set, delete, update, create, compareAndSwap, - // compareAndDelete and expire. - Action string `json:"action"` - - // Node represents the state of the relevant etcd Node. - Node *Node `json:"node"` - - // PrevNode represents the previous state of the Node. PrevNode is non-nil - // only if the Node existed before the action occurred and the action - // caused a change to the Node. - PrevNode *Node `json:"prevNode"` - - // Index holds the cluster-level index at the time the Response was generated. - // This index is not tied to the Node(s) contained in this Response. - Index uint64 `json:"-"` - - // ClusterID holds the cluster-level ID reported by the server. This - // should be different for different etcd clusters. - ClusterID string `json:"-"` -} - -type Node struct { - // Key represents the unique location of this Node (e.g. "/foo/bar"). - Key string `json:"key"` - - // Dir reports whether node describes a directory. - Dir bool `json:"dir,omitempty"` - - // Value is the current data stored on this Node. If this Node - // is a directory, Value will be empty. - Value string `json:"value"` - - // Nodes holds the children of this Node, only if this Node is a directory. - // This slice of will be arbitrarily deep (children, grandchildren, great- - // grandchildren, etc.) if a recursive Get or Watch request were made. - Nodes Nodes `json:"nodes"` - - // CreatedIndex is the etcd index at-which this Node was created. - CreatedIndex uint64 `json:"createdIndex"` - - // ModifiedIndex is the etcd index at-which this Node was last modified. - ModifiedIndex uint64 `json:"modifiedIndex"` - - // Expiration is the server side expiration time of the key. - Expiration *time.Time `json:"expiration,omitempty"` - - // TTL is the time to live of the key in second. - TTL int64 `json:"ttl,omitempty"` -} - -func (n *Node) String() string { - return fmt.Sprintf("{Key: %s, CreatedIndex: %d, ModifiedIndex: %d, TTL: %d}", n.Key, n.CreatedIndex, n.ModifiedIndex, n.TTL) -} - -// TTLDuration returns the Node's TTL as a time.Duration object -func (n *Node) TTLDuration() time.Duration { - return time.Duration(n.TTL) * time.Second -} - -type Nodes []*Node - -// interfaces for sorting - -func (ns Nodes) Len() int { return len(ns) } -func (ns Nodes) Less(i, j int) bool { return ns[i].Key < ns[j].Key } -func (ns Nodes) Swap(i, j int) { ns[i], ns[j] = ns[j], ns[i] } - -type httpKeysAPI struct { - client httpClient - prefix string -} - -func (k *httpKeysAPI) Set(ctx context.Context, key, val string, opts *SetOptions) (*Response, error) { - act := &setAction{ - Prefix: k.prefix, - Key: key, - Value: val, - } - - if opts != nil { - act.PrevValue = opts.PrevValue - act.PrevIndex = opts.PrevIndex - act.PrevExist = opts.PrevExist - act.TTL = opts.TTL - act.Refresh = opts.Refresh - act.Dir = opts.Dir - act.NoValueOnSuccess = opts.NoValueOnSuccess - } - - doCtx := ctx - if act.PrevExist == PrevNoExist { - doCtx = context.WithValue(doCtx, &oneShotCtxValue, &oneShotCtxValue) - } - resp, body, err := k.client.Do(doCtx, act) - if err != nil { - return nil, err - } - - return unmarshalHTTPResponse(resp.StatusCode, resp.Header, body) -} - -func (k *httpKeysAPI) Create(ctx context.Context, key, val string) (*Response, error) { - return k.Set(ctx, key, val, &SetOptions{PrevExist: PrevNoExist}) -} - -func (k *httpKeysAPI) CreateInOrder(ctx context.Context, dir, val string, opts *CreateInOrderOptions) (*Response, error) { - act := &createInOrderAction{ - Prefix: k.prefix, - Dir: dir, - Value: val, - } - - if opts != nil { - act.TTL = opts.TTL - } - - resp, body, err := k.client.Do(ctx, act) - if err != nil { - return nil, err - } - - return unmarshalHTTPResponse(resp.StatusCode, resp.Header, body) -} - -func (k *httpKeysAPI) Update(ctx context.Context, key, val string) (*Response, error) { - return k.Set(ctx, key, val, &SetOptions{PrevExist: PrevExist}) -} - -func (k *httpKeysAPI) Delete(ctx context.Context, key string, opts *DeleteOptions) (*Response, error) { - act := &deleteAction{ - Prefix: k.prefix, - Key: key, - } - - if opts != nil { - act.PrevValue = opts.PrevValue - act.PrevIndex = opts.PrevIndex - act.Dir = opts.Dir - act.Recursive = opts.Recursive - } - - doCtx := context.WithValue(ctx, &oneShotCtxValue, &oneShotCtxValue) - resp, body, err := k.client.Do(doCtx, act) - if err != nil { - return nil, err - } - - return unmarshalHTTPResponse(resp.StatusCode, resp.Header, body) -} - -func (k *httpKeysAPI) Get(ctx context.Context, key string, opts *GetOptions) (*Response, error) { - act := &getAction{ - Prefix: k.prefix, - Key: key, - } - - if opts != nil { - act.Recursive = opts.Recursive - act.Sorted = opts.Sort - act.Quorum = opts.Quorum - } - - resp, body, err := k.client.Do(ctx, act) - if err != nil { - return nil, err - } - - return unmarshalHTTPResponse(resp.StatusCode, resp.Header, body) -} - -func (k *httpKeysAPI) Watcher(key string, opts *WatcherOptions) Watcher { - act := waitAction{ - Prefix: k.prefix, - Key: key, - } - - if opts != nil { - act.Recursive = opts.Recursive - if opts.AfterIndex > 0 { - act.WaitIndex = opts.AfterIndex + 1 - } - } - - return &httpWatcher{ - client: k.client, - nextWait: act, - } -} - -type httpWatcher struct { - client httpClient - nextWait waitAction -} - -func (hw *httpWatcher) Next(ctx context.Context) (*Response, error) { - for { - httpresp, body, err := hw.client.Do(ctx, &hw.nextWait) - if err != nil { - return nil, err - } - - resp, err := unmarshalHTTPResponse(httpresp.StatusCode, httpresp.Header, body) - if err != nil { - if err == ErrEmptyBody { - continue - } - return nil, err - } - - hw.nextWait.WaitIndex = resp.Node.ModifiedIndex + 1 - return resp, nil - } -} - -// v2KeysURL forms a URL representing the location of a key. -// The endpoint argument represents the base URL of an etcd -// server. The prefix is the path needed to route from the -// provided endpoint's path to the root of the keys API -// (typically "/v2/keys"). -func v2KeysURL(ep url.URL, prefix, key string) *url.URL { - // We concatenate all parts together manually. We cannot use - // path.Join because it does not reserve trailing slash. - // We call CanonicalURLPath to further cleanup the path. - if prefix != "" && prefix[0] != '/' { - prefix = "/" + prefix - } - if key != "" && key[0] != '/' { - key = "/" + key - } - ep.Path = pathutil.CanonicalURLPath(ep.Path + prefix + key) - return &ep -} - -type getAction struct { - Prefix string - Key string - Recursive bool - Sorted bool - Quorum bool -} - -func (g *getAction) HTTPRequest(ep url.URL) *http.Request { - u := v2KeysURL(ep, g.Prefix, g.Key) - - params := u.Query() - params.Set("recursive", strconv.FormatBool(g.Recursive)) - params.Set("sorted", strconv.FormatBool(g.Sorted)) - params.Set("quorum", strconv.FormatBool(g.Quorum)) - u.RawQuery = params.Encode() - - req, _ := http.NewRequest("GET", u.String(), nil) - return req -} - -type waitAction struct { - Prefix string - Key string - WaitIndex uint64 - Recursive bool -} - -func (w *waitAction) HTTPRequest(ep url.URL) *http.Request { - u := v2KeysURL(ep, w.Prefix, w.Key) - - params := u.Query() - params.Set("wait", "true") - params.Set("waitIndex", strconv.FormatUint(w.WaitIndex, 10)) - params.Set("recursive", strconv.FormatBool(w.Recursive)) - u.RawQuery = params.Encode() - - req, _ := http.NewRequest("GET", u.String(), nil) - return req -} - -type setAction struct { - Prefix string - Key string - Value string - PrevValue string - PrevIndex uint64 - PrevExist PrevExistType - TTL time.Duration - Refresh bool - Dir bool - NoValueOnSuccess bool -} - -func (a *setAction) HTTPRequest(ep url.URL) *http.Request { - u := v2KeysURL(ep, a.Prefix, a.Key) - - params := u.Query() - form := url.Values{} - - // we're either creating a directory or setting a key - if a.Dir { - params.Set("dir", strconv.FormatBool(a.Dir)) - } else { - // These options are only valid for setting a key - if a.PrevValue != "" { - params.Set("prevValue", a.PrevValue) - } - form.Add("value", a.Value) - } - - // Options which apply to both setting a key and creating a dir - if a.PrevIndex != 0 { - params.Set("prevIndex", strconv.FormatUint(a.PrevIndex, 10)) - } - if a.PrevExist != PrevIgnore { - params.Set("prevExist", string(a.PrevExist)) - } - if a.TTL > 0 { - form.Add("ttl", strconv.FormatUint(uint64(a.TTL.Seconds()), 10)) - } - - if a.Refresh { - form.Add("refresh", "true") - } - if a.NoValueOnSuccess { - params.Set("noValueOnSuccess", strconv.FormatBool(a.NoValueOnSuccess)) - } - - u.RawQuery = params.Encode() - body := strings.NewReader(form.Encode()) - - req, _ := http.NewRequest("PUT", u.String(), body) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - - return req -} - -type deleteAction struct { - Prefix string - Key string - PrevValue string - PrevIndex uint64 - Dir bool - Recursive bool -} - -func (a *deleteAction) HTTPRequest(ep url.URL) *http.Request { - u := v2KeysURL(ep, a.Prefix, a.Key) - - params := u.Query() - if a.PrevValue != "" { - params.Set("prevValue", a.PrevValue) - } - if a.PrevIndex != 0 { - params.Set("prevIndex", strconv.FormatUint(a.PrevIndex, 10)) - } - if a.Dir { - params.Set("dir", "true") - } - if a.Recursive { - params.Set("recursive", "true") - } - u.RawQuery = params.Encode() - - req, _ := http.NewRequest("DELETE", u.String(), nil) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - - return req -} - -type createInOrderAction struct { - Prefix string - Dir string - Value string - TTL time.Duration -} - -func (a *createInOrderAction) HTTPRequest(ep url.URL) *http.Request { - u := v2KeysURL(ep, a.Prefix, a.Dir) - - form := url.Values{} - form.Add("value", a.Value) - if a.TTL > 0 { - form.Add("ttl", strconv.FormatUint(uint64(a.TTL.Seconds()), 10)) - } - body := strings.NewReader(form.Encode()) - - req, _ := http.NewRequest("POST", u.String(), body) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - return req -} - -func unmarshalHTTPResponse(code int, header http.Header, body []byte) (res *Response, err error) { - switch code { - case http.StatusOK, http.StatusCreated: - if len(body) == 0 { - return nil, ErrEmptyBody - } - res, err = unmarshalSuccessfulKeysResponse(header, body) - default: - err = unmarshalFailedKeysResponse(body) - } - return res, err -} - -var jsonIterator = caseSensitiveJsonIterator() - -func unmarshalSuccessfulKeysResponse(header http.Header, body []byte) (*Response, error) { - var res Response - err := jsonIterator.Unmarshal(body, &res) - if err != nil { - return nil, ErrInvalidJSON - } - if header.Get("X-Etcd-Index") != "" { - res.Index, err = strconv.ParseUint(header.Get("X-Etcd-Index"), 10, 64) - if err != nil { - return nil, err - } - } - res.ClusterID = header.Get("X-Etcd-Cluster-ID") - return &res, nil -} - -func unmarshalFailedKeysResponse(body []byte) error { - var etcdErr Error - if err := json.Unmarshal(body, &etcdErr); err != nil { - return ErrInvalidJSON - } - return etcdErr -} diff --git a/vendor/github.com/coreos/etcd/client/members.go b/vendor/github.com/coreos/etcd/client/members.go deleted file mode 100644 index aafa3d1b8706..000000000000 --- a/vendor/github.com/coreos/etcd/client/members.go +++ /dev/null @@ -1,303 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "bytes" - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - "path" - - "github.com/coreos/etcd/pkg/types" -) - -var ( - defaultV2MembersPrefix = "/v2/members" - defaultLeaderSuffix = "/leader" -) - -type Member struct { - // ID is the unique identifier of this Member. - ID string `json:"id"` - - // Name is a human-readable, non-unique identifier of this Member. - Name string `json:"name"` - - // PeerURLs represents the HTTP(S) endpoints this Member uses to - // participate in etcd's consensus protocol. - PeerURLs []string `json:"peerURLs"` - - // ClientURLs represents the HTTP(S) endpoints on which this Member - // serves its client-facing APIs. - ClientURLs []string `json:"clientURLs"` -} - -type memberCollection []Member - -func (c *memberCollection) UnmarshalJSON(data []byte) error { - d := struct { - Members []Member - }{} - - if err := json.Unmarshal(data, &d); err != nil { - return err - } - - if d.Members == nil { - *c = make([]Member, 0) - return nil - } - - *c = d.Members - return nil -} - -type memberCreateOrUpdateRequest struct { - PeerURLs types.URLs -} - -func (m *memberCreateOrUpdateRequest) MarshalJSON() ([]byte, error) { - s := struct { - PeerURLs []string `json:"peerURLs"` - }{ - PeerURLs: make([]string, len(m.PeerURLs)), - } - - for i, u := range m.PeerURLs { - s.PeerURLs[i] = u.String() - } - - return json.Marshal(&s) -} - -// NewMembersAPI constructs a new MembersAPI that uses HTTP to -// interact with etcd's membership API. -func NewMembersAPI(c Client) MembersAPI { - return &httpMembersAPI{ - client: c, - } -} - -type MembersAPI interface { - // List enumerates the current cluster membership. - List(ctx context.Context) ([]Member, error) - - // Add instructs etcd to accept a new Member into the cluster. - Add(ctx context.Context, peerURL string) (*Member, error) - - // Remove demotes an existing Member out of the cluster. - Remove(ctx context.Context, mID string) error - - // Update instructs etcd to update an existing Member in the cluster. - Update(ctx context.Context, mID string, peerURLs []string) error - - // Leader gets current leader of the cluster - Leader(ctx context.Context) (*Member, error) -} - -type httpMembersAPI struct { - client httpClient -} - -func (m *httpMembersAPI) List(ctx context.Context) ([]Member, error) { - req := &membersAPIActionList{} - resp, body, err := m.client.Do(ctx, req) - if err != nil { - return nil, err - } - - if err := assertStatusCode(resp.StatusCode, http.StatusOK); err != nil { - return nil, err - } - - var mCollection memberCollection - if err := json.Unmarshal(body, &mCollection); err != nil { - return nil, err - } - - return []Member(mCollection), nil -} - -func (m *httpMembersAPI) Add(ctx context.Context, peerURL string) (*Member, error) { - urls, err := types.NewURLs([]string{peerURL}) - if err != nil { - return nil, err - } - - req := &membersAPIActionAdd{peerURLs: urls} - resp, body, err := m.client.Do(ctx, req) - if err != nil { - return nil, err - } - - if err := assertStatusCode(resp.StatusCode, http.StatusCreated, http.StatusConflict); err != nil { - return nil, err - } - - if resp.StatusCode != http.StatusCreated { - var merr membersError - if err := json.Unmarshal(body, &merr); err != nil { - return nil, err - } - return nil, merr - } - - var memb Member - if err := json.Unmarshal(body, &memb); err != nil { - return nil, err - } - - return &memb, nil -} - -func (m *httpMembersAPI) Update(ctx context.Context, memberID string, peerURLs []string) error { - urls, err := types.NewURLs(peerURLs) - if err != nil { - return err - } - - req := &membersAPIActionUpdate{peerURLs: urls, memberID: memberID} - resp, body, err := m.client.Do(ctx, req) - if err != nil { - return err - } - - if err := assertStatusCode(resp.StatusCode, http.StatusNoContent, http.StatusNotFound, http.StatusConflict); err != nil { - return err - } - - if resp.StatusCode != http.StatusNoContent { - var merr membersError - if err := json.Unmarshal(body, &merr); err != nil { - return err - } - return merr - } - - return nil -} - -func (m *httpMembersAPI) Remove(ctx context.Context, memberID string) error { - req := &membersAPIActionRemove{memberID: memberID} - resp, _, err := m.client.Do(ctx, req) - if err != nil { - return err - } - - return assertStatusCode(resp.StatusCode, http.StatusNoContent, http.StatusGone) -} - -func (m *httpMembersAPI) Leader(ctx context.Context) (*Member, error) { - req := &membersAPIActionLeader{} - resp, body, err := m.client.Do(ctx, req) - if err != nil { - return nil, err - } - - if err := assertStatusCode(resp.StatusCode, http.StatusOK); err != nil { - return nil, err - } - - var leader Member - if err := json.Unmarshal(body, &leader); err != nil { - return nil, err - } - - return &leader, nil -} - -type membersAPIActionList struct{} - -func (l *membersAPIActionList) HTTPRequest(ep url.URL) *http.Request { - u := v2MembersURL(ep) - req, _ := http.NewRequest("GET", u.String(), nil) - return req -} - -type membersAPIActionRemove struct { - memberID string -} - -func (d *membersAPIActionRemove) HTTPRequest(ep url.URL) *http.Request { - u := v2MembersURL(ep) - u.Path = path.Join(u.Path, d.memberID) - req, _ := http.NewRequest("DELETE", u.String(), nil) - return req -} - -type membersAPIActionAdd struct { - peerURLs types.URLs -} - -func (a *membersAPIActionAdd) HTTPRequest(ep url.URL) *http.Request { - u := v2MembersURL(ep) - m := memberCreateOrUpdateRequest{PeerURLs: a.peerURLs} - b, _ := json.Marshal(&m) - req, _ := http.NewRequest("POST", u.String(), bytes.NewReader(b)) - req.Header.Set("Content-Type", "application/json") - return req -} - -type membersAPIActionUpdate struct { - memberID string - peerURLs types.URLs -} - -func (a *membersAPIActionUpdate) HTTPRequest(ep url.URL) *http.Request { - u := v2MembersURL(ep) - m := memberCreateOrUpdateRequest{PeerURLs: a.peerURLs} - u.Path = path.Join(u.Path, a.memberID) - b, _ := json.Marshal(&m) - req, _ := http.NewRequest("PUT", u.String(), bytes.NewReader(b)) - req.Header.Set("Content-Type", "application/json") - return req -} - -func assertStatusCode(got int, want ...int) (err error) { - for _, w := range want { - if w == got { - return nil - } - } - return fmt.Errorf("unexpected status code %d", got) -} - -type membersAPIActionLeader struct{} - -func (l *membersAPIActionLeader) HTTPRequest(ep url.URL) *http.Request { - u := v2MembersURL(ep) - u.Path = path.Join(u.Path, defaultLeaderSuffix) - req, _ := http.NewRequest("GET", u.String(), nil) - return req -} - -// v2MembersURL add the necessary path to the provided endpoint -// to route requests to the default v2 members API. -func v2MembersURL(ep url.URL) *url.URL { - ep.Path = path.Join(ep.Path, defaultV2MembersPrefix) - return &ep -} - -type membersError struct { - Message string `json:"message"` - Code int `json:"-"` -} - -func (e membersError) Error() string { - return e.Message -} diff --git a/vendor/github.com/coreos/etcd/client/util.go b/vendor/github.com/coreos/etcd/client/util.go deleted file mode 100644 index 15a8babff4d4..000000000000 --- a/vendor/github.com/coreos/etcd/client/util.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "regexp" -) - -var ( - roleNotFoundRegExp *regexp.Regexp - userNotFoundRegExp *regexp.Regexp -) - -func init() { - roleNotFoundRegExp = regexp.MustCompile("auth: Role .* does not exist.") - userNotFoundRegExp = regexp.MustCompile("auth: User .* does not exist.") -} - -// IsKeyNotFound returns true if the error code is ErrorCodeKeyNotFound. -func IsKeyNotFound(err error) bool { - if cErr, ok := err.(Error); ok { - return cErr.Code == ErrorCodeKeyNotFound - } - return false -} - -// IsRoleNotFound returns true if the error means role not found of v2 API. -func IsRoleNotFound(err error) bool { - if ae, ok := err.(authError); ok { - return roleNotFoundRegExp.MatchString(ae.Message) - } - return false -} - -// IsUserNotFound returns true if the error means user not found of v2 API. -func IsUserNotFound(err error) bool { - if ae, ok := err.(authError); ok { - return userNotFoundRegExp.MatchString(ae.Message) - } - return false -} diff --git a/vendor/github.com/coreos/etcd/clientv3/auth.go b/vendor/github.com/coreos/etcd/clientv3/auth.go deleted file mode 100644 index 7545bb6ca1ca..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/auth.go +++ /dev/null @@ -1,233 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - "fmt" - "strings" - - "github.com/coreos/etcd/auth/authpb" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" -) - -type ( - AuthEnableResponse pb.AuthEnableResponse - AuthDisableResponse pb.AuthDisableResponse - AuthenticateResponse pb.AuthenticateResponse - AuthUserAddResponse pb.AuthUserAddResponse - AuthUserDeleteResponse pb.AuthUserDeleteResponse - AuthUserChangePasswordResponse pb.AuthUserChangePasswordResponse - AuthUserGrantRoleResponse pb.AuthUserGrantRoleResponse - AuthUserGetResponse pb.AuthUserGetResponse - AuthUserRevokeRoleResponse pb.AuthUserRevokeRoleResponse - AuthRoleAddResponse pb.AuthRoleAddResponse - AuthRoleGrantPermissionResponse pb.AuthRoleGrantPermissionResponse - AuthRoleGetResponse pb.AuthRoleGetResponse - AuthRoleRevokePermissionResponse pb.AuthRoleRevokePermissionResponse - AuthRoleDeleteResponse pb.AuthRoleDeleteResponse - AuthUserListResponse pb.AuthUserListResponse - AuthRoleListResponse pb.AuthRoleListResponse - - PermissionType authpb.Permission_Type - Permission authpb.Permission -) - -const ( - PermRead = authpb.READ - PermWrite = authpb.WRITE - PermReadWrite = authpb.READWRITE -) - -type Auth interface { - // AuthEnable enables auth of an etcd cluster. - AuthEnable(ctx context.Context) (*AuthEnableResponse, error) - - // AuthDisable disables auth of an etcd cluster. - AuthDisable(ctx context.Context) (*AuthDisableResponse, error) - - // UserAdd adds a new user to an etcd cluster. - UserAdd(ctx context.Context, name string, password string) (*AuthUserAddResponse, error) - - // UserDelete deletes a user from an etcd cluster. - UserDelete(ctx context.Context, name string) (*AuthUserDeleteResponse, error) - - // UserChangePassword changes a password of a user. - UserChangePassword(ctx context.Context, name string, password string) (*AuthUserChangePasswordResponse, error) - - // UserGrantRole grants a role to a user. - UserGrantRole(ctx context.Context, user string, role string) (*AuthUserGrantRoleResponse, error) - - // UserGet gets a detailed information of a user. - UserGet(ctx context.Context, name string) (*AuthUserGetResponse, error) - - // UserList gets a list of all users. - UserList(ctx context.Context) (*AuthUserListResponse, error) - - // UserRevokeRole revokes a role of a user. - UserRevokeRole(ctx context.Context, name string, role string) (*AuthUserRevokeRoleResponse, error) - - // RoleAdd adds a new role to an etcd cluster. - RoleAdd(ctx context.Context, name string) (*AuthRoleAddResponse, error) - - // RoleGrantPermission grants a permission to a role. - RoleGrantPermission(ctx context.Context, name string, key, rangeEnd string, permType PermissionType) (*AuthRoleGrantPermissionResponse, error) - - // RoleGet gets a detailed information of a role. - RoleGet(ctx context.Context, role string) (*AuthRoleGetResponse, error) - - // RoleList gets a list of all roles. - RoleList(ctx context.Context) (*AuthRoleListResponse, error) - - // RoleRevokePermission revokes a permission from a role. - RoleRevokePermission(ctx context.Context, role string, key, rangeEnd string) (*AuthRoleRevokePermissionResponse, error) - - // RoleDelete deletes a role. - RoleDelete(ctx context.Context, role string) (*AuthRoleDeleteResponse, error) -} - -type auth struct { - remote pb.AuthClient - callOpts []grpc.CallOption -} - -func NewAuth(c *Client) Auth { - api := &auth{remote: RetryAuthClient(c)} - if c != nil { - api.callOpts = c.callOpts - } - return api -} - -func (auth *auth) AuthEnable(ctx context.Context) (*AuthEnableResponse, error) { - resp, err := auth.remote.AuthEnable(ctx, &pb.AuthEnableRequest{}, auth.callOpts...) - return (*AuthEnableResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) AuthDisable(ctx context.Context) (*AuthDisableResponse, error) { - resp, err := auth.remote.AuthDisable(ctx, &pb.AuthDisableRequest{}, auth.callOpts...) - return (*AuthDisableResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) UserAdd(ctx context.Context, name string, password string) (*AuthUserAddResponse, error) { - resp, err := auth.remote.UserAdd(ctx, &pb.AuthUserAddRequest{Name: name, Password: password}, auth.callOpts...) - return (*AuthUserAddResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) UserDelete(ctx context.Context, name string) (*AuthUserDeleteResponse, error) { - resp, err := auth.remote.UserDelete(ctx, &pb.AuthUserDeleteRequest{Name: name}, auth.callOpts...) - return (*AuthUserDeleteResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) UserChangePassword(ctx context.Context, name string, password string) (*AuthUserChangePasswordResponse, error) { - resp, err := auth.remote.UserChangePassword(ctx, &pb.AuthUserChangePasswordRequest{Name: name, Password: password}, auth.callOpts...) - return (*AuthUserChangePasswordResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) UserGrantRole(ctx context.Context, user string, role string) (*AuthUserGrantRoleResponse, error) { - resp, err := auth.remote.UserGrantRole(ctx, &pb.AuthUserGrantRoleRequest{User: user, Role: role}, auth.callOpts...) - return (*AuthUserGrantRoleResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) UserGet(ctx context.Context, name string) (*AuthUserGetResponse, error) { - resp, err := auth.remote.UserGet(ctx, &pb.AuthUserGetRequest{Name: name}, auth.callOpts...) - return (*AuthUserGetResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) UserList(ctx context.Context) (*AuthUserListResponse, error) { - resp, err := auth.remote.UserList(ctx, &pb.AuthUserListRequest{}, auth.callOpts...) - return (*AuthUserListResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) UserRevokeRole(ctx context.Context, name string, role string) (*AuthUserRevokeRoleResponse, error) { - resp, err := auth.remote.UserRevokeRole(ctx, &pb.AuthUserRevokeRoleRequest{Name: name, Role: role}, auth.callOpts...) - return (*AuthUserRevokeRoleResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) RoleAdd(ctx context.Context, name string) (*AuthRoleAddResponse, error) { - resp, err := auth.remote.RoleAdd(ctx, &pb.AuthRoleAddRequest{Name: name}, auth.callOpts...) - return (*AuthRoleAddResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) RoleGrantPermission(ctx context.Context, name string, key, rangeEnd string, permType PermissionType) (*AuthRoleGrantPermissionResponse, error) { - perm := &authpb.Permission{ - Key: []byte(key), - RangeEnd: []byte(rangeEnd), - PermType: authpb.Permission_Type(permType), - } - resp, err := auth.remote.RoleGrantPermission(ctx, &pb.AuthRoleGrantPermissionRequest{Name: name, Perm: perm}, auth.callOpts...) - return (*AuthRoleGrantPermissionResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) RoleGet(ctx context.Context, role string) (*AuthRoleGetResponse, error) { - resp, err := auth.remote.RoleGet(ctx, &pb.AuthRoleGetRequest{Role: role}, auth.callOpts...) - return (*AuthRoleGetResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) RoleList(ctx context.Context) (*AuthRoleListResponse, error) { - resp, err := auth.remote.RoleList(ctx, &pb.AuthRoleListRequest{}, auth.callOpts...) - return (*AuthRoleListResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) RoleRevokePermission(ctx context.Context, role string, key, rangeEnd string) (*AuthRoleRevokePermissionResponse, error) { - resp, err := auth.remote.RoleRevokePermission(ctx, &pb.AuthRoleRevokePermissionRequest{Role: role, Key: key, RangeEnd: rangeEnd}, auth.callOpts...) - return (*AuthRoleRevokePermissionResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) RoleDelete(ctx context.Context, role string) (*AuthRoleDeleteResponse, error) { - resp, err := auth.remote.RoleDelete(ctx, &pb.AuthRoleDeleteRequest{Role: role}, auth.callOpts...) - return (*AuthRoleDeleteResponse)(resp), toErr(ctx, err) -} - -func StrToPermissionType(s string) (PermissionType, error) { - val, ok := authpb.Permission_Type_value[strings.ToUpper(s)] - if ok { - return PermissionType(val), nil - } - return PermissionType(-1), fmt.Errorf("invalid permission type: %s", s) -} - -type authenticator struct { - conn *grpc.ClientConn // conn in-use - remote pb.AuthClient - callOpts []grpc.CallOption -} - -func (auth *authenticator) authenticate(ctx context.Context, name string, password string) (*AuthenticateResponse, error) { - resp, err := auth.remote.Authenticate(ctx, &pb.AuthenticateRequest{Name: name, Password: password}, auth.callOpts...) - return (*AuthenticateResponse)(resp), toErr(ctx, err) -} - -func (auth *authenticator) close() { - auth.conn.Close() -} - -func newAuthenticator(endpoint string, opts []grpc.DialOption, c *Client) (*authenticator, error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return nil, err - } - - api := &authenticator{ - conn: conn, - remote: pb.NewAuthClient(conn), - } - if c != nil { - api.callOpts = c.callOpts - } - return api, nil -} diff --git a/vendor/github.com/coreos/etcd/clientv3/client.go b/vendor/github.com/coreos/etcd/clientv3/client.go deleted file mode 100644 index 78db5d4bfaf1..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/client.go +++ /dev/null @@ -1,578 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - "crypto/tls" - "errors" - "fmt" - "net" - "net/url" - "strconv" - "strings" - "sync" - "time" - - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/credentials" - "google.golang.org/grpc/keepalive" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" -) - -var ( - ErrNoAvailableEndpoints = errors.New("etcdclient: no available endpoints") - ErrOldCluster = errors.New("etcdclient: old cluster version") -) - -// Client provides and manages an etcd v3 client session. -type Client struct { - Cluster - KV - Lease - Watcher - Auth - Maintenance - - conn *grpc.ClientConn - dialerrc chan error - - cfg Config - creds *credentials.TransportCredentials - balancer *healthBalancer - mu *sync.RWMutex - - ctx context.Context - cancel context.CancelFunc - - // Username is a user name for authentication. - Username string - // Password is a password for authentication. - Password string - // tokenCred is an instance of WithPerRPCCredentials()'s argument - tokenCred *authTokenCredential - - callOpts []grpc.CallOption -} - -// New creates a new etcdv3 client from a given configuration. -func New(cfg Config) (*Client, error) { - if len(cfg.Endpoints) == 0 { - return nil, ErrNoAvailableEndpoints - } - - return newClient(&cfg) -} - -// NewCtxClient creates a client with a context but no underlying grpc -// connection. This is useful for embedded cases that override the -// service interface implementations and do not need connection management. -func NewCtxClient(ctx context.Context) *Client { - cctx, cancel := context.WithCancel(ctx) - return &Client{ctx: cctx, cancel: cancel} -} - -// NewFromURL creates a new etcdv3 client from a URL. -func NewFromURL(url string) (*Client, error) { - return New(Config{Endpoints: []string{url}}) -} - -// Close shuts down the client's etcd connections. -func (c *Client) Close() error { - c.cancel() - c.Watcher.Close() - c.Lease.Close() - if c.conn != nil { - return toErr(c.ctx, c.conn.Close()) - } - return c.ctx.Err() -} - -// Ctx is a context for "out of band" messages (e.g., for sending -// "clean up" message when another context is canceled). It is -// canceled on client Close(). -func (c *Client) Ctx() context.Context { return c.ctx } - -// Endpoints lists the registered endpoints for the client. -func (c *Client) Endpoints() []string { - c.mu.RLock() - defer c.mu.RUnlock() - // copy the slice; protect original endpoints from being changed - eps := make([]string, len(c.cfg.Endpoints)) - copy(eps, c.cfg.Endpoints) - return eps -} - -// SetEndpoints updates client's endpoints. -func (c *Client) SetEndpoints(eps ...string) { - c.mu.Lock() - c.cfg.Endpoints = eps - c.mu.Unlock() - c.balancer.updateAddrs(eps...) - - // updating notifyCh can trigger new connections, - // need update addrs if all connections are down - // or addrs does not include pinAddr. - c.balancer.mu.RLock() - update := !hasAddr(c.balancer.addrs, c.balancer.pinAddr) - c.balancer.mu.RUnlock() - if update { - select { - case c.balancer.updateAddrsC <- notifyNext: - case <-c.balancer.stopc: - } - } -} - -// Sync synchronizes client's endpoints with the known endpoints from the etcd membership. -func (c *Client) Sync(ctx context.Context) error { - mresp, err := c.MemberList(ctx) - if err != nil { - return err - } - var eps []string - for _, m := range mresp.Members { - eps = append(eps, m.ClientURLs...) - } - c.SetEndpoints(eps...) - return nil -} - -func (c *Client) autoSync() { - if c.cfg.AutoSyncInterval == time.Duration(0) { - return - } - - for { - select { - case <-c.ctx.Done(): - return - case <-time.After(c.cfg.AutoSyncInterval): - ctx, cancel := context.WithTimeout(c.ctx, 5*time.Second) - err := c.Sync(ctx) - cancel() - if err != nil && err != c.ctx.Err() { - logger.Println("Auto sync endpoints failed:", err) - } - } - } -} - -type authTokenCredential struct { - token string - tokenMu *sync.RWMutex -} - -func (cred authTokenCredential) RequireTransportSecurity() bool { - return false -} - -func (cred authTokenCredential) GetRequestMetadata(ctx context.Context, s ...string) (map[string]string, error) { - cred.tokenMu.RLock() - defer cred.tokenMu.RUnlock() - return map[string]string{ - "token": cred.token, - }, nil -} - -func parseEndpoint(endpoint string) (proto string, host string, scheme string) { - proto = "tcp" - host = endpoint - url, uerr := url.Parse(endpoint) - if uerr != nil || !strings.Contains(endpoint, "://") { - return proto, host, scheme - } - scheme = url.Scheme - - // strip scheme:// prefix since grpc dials by host - host = url.Host - switch url.Scheme { - case "http", "https": - case "unix", "unixs": - proto = "unix" - host = url.Host + url.Path - default: - proto, host = "", "" - } - return proto, host, scheme -} - -func (c *Client) processCreds(scheme string) (creds *credentials.TransportCredentials) { - creds = c.creds - switch scheme { - case "unix": - case "http": - creds = nil - case "https", "unixs": - if creds != nil { - break - } - tlsconfig := &tls.Config{} - emptyCreds := credentials.NewTLS(tlsconfig) - creds = &emptyCreds - default: - creds = nil - } - return creds -} - -// dialSetupOpts gives the dial opts prior to any authentication -func (c *Client) dialSetupOpts(endpoint string, dopts ...grpc.DialOption) (opts []grpc.DialOption) { - if c.cfg.DialTimeout > 0 { - opts = []grpc.DialOption{grpc.WithTimeout(c.cfg.DialTimeout)} - } - if c.cfg.DialKeepAliveTime > 0 { - params := keepalive.ClientParameters{ - Time: c.cfg.DialKeepAliveTime, - Timeout: c.cfg.DialKeepAliveTimeout, - } - opts = append(opts, grpc.WithKeepaliveParams(params)) - } - opts = append(opts, dopts...) - - f := func(host string, t time.Duration) (net.Conn, error) { - proto, host, _ := parseEndpoint(c.balancer.endpoint(host)) - if host == "" && endpoint != "" { - // dialing an endpoint not in the balancer; use - // endpoint passed into dial - proto, host, _ = parseEndpoint(endpoint) - } - if proto == "" { - return nil, fmt.Errorf("unknown scheme for %q", host) - } - select { - case <-c.ctx.Done(): - return nil, c.ctx.Err() - default: - } - dialer := &net.Dialer{Timeout: t} - conn, err := dialer.DialContext(c.ctx, proto, host) - if err != nil { - select { - case c.dialerrc <- err: - default: - } - } - return conn, err - } - opts = append(opts, grpc.WithDialer(f)) - - creds := c.creds - if _, _, scheme := parseEndpoint(endpoint); len(scheme) != 0 { - creds = c.processCreds(scheme) - } - if creds != nil { - opts = append(opts, grpc.WithTransportCredentials(*creds)) - } else { - opts = append(opts, grpc.WithInsecure()) - } - - return opts -} - -// Dial connects to a single endpoint using the client's config. -func (c *Client) Dial(endpoint string) (*grpc.ClientConn, error) { - return c.dial(endpoint) -} - -func (c *Client) getToken(ctx context.Context) error { - var err error // return last error in a case of fail - var auth *authenticator - - for i := 0; i < len(c.cfg.Endpoints); i++ { - endpoint := c.cfg.Endpoints[i] - host := getHost(endpoint) - // use dial options without dopts to avoid reusing the client balancer - auth, err = newAuthenticator(host, c.dialSetupOpts(endpoint), c) - if err != nil { - continue - } - defer auth.close() - - var resp *AuthenticateResponse - resp, err = auth.authenticate(ctx, c.Username, c.Password) - if err != nil { - continue - } - - c.tokenCred.tokenMu.Lock() - c.tokenCred.token = resp.Token - c.tokenCred.tokenMu.Unlock() - - return nil - } - - return err -} - -func (c *Client) dial(endpoint string, dopts ...grpc.DialOption) (*grpc.ClientConn, error) { - opts := c.dialSetupOpts(endpoint, dopts...) - host := getHost(endpoint) - if c.Username != "" && c.Password != "" { - c.tokenCred = &authTokenCredential{ - tokenMu: &sync.RWMutex{}, - } - - ctx := c.ctx - if c.cfg.DialTimeout > 0 { - cctx, cancel := context.WithTimeout(ctx, c.cfg.DialTimeout) - defer cancel() - ctx = cctx - } - - err := c.getToken(ctx) - if err != nil { - if toErr(ctx, err) != rpctypes.ErrAuthNotEnabled { - if err == ctx.Err() && ctx.Err() != c.ctx.Err() { - err = context.DeadlineExceeded - } - return nil, err - } - } else { - opts = append(opts, grpc.WithPerRPCCredentials(c.tokenCred)) - } - } - - opts = append(opts, c.cfg.DialOptions...) - - conn, err := grpc.DialContext(c.ctx, host, opts...) - if err != nil { - return nil, err - } - return conn, nil -} - -// WithRequireLeader requires client requests to only succeed -// when the cluster has a leader. -func WithRequireLeader(ctx context.Context) context.Context { - md := metadata.Pairs(rpctypes.MetadataRequireLeaderKey, rpctypes.MetadataHasLeader) - return metadata.NewOutgoingContext(ctx, md) -} - -func newClient(cfg *Config) (*Client, error) { - if cfg == nil { - cfg = &Config{} - } - var creds *credentials.TransportCredentials - if cfg.TLS != nil { - c := credentials.NewTLS(cfg.TLS) - creds = &c - } - - // use a temporary skeleton client to bootstrap first connection - baseCtx := context.TODO() - if cfg.Context != nil { - baseCtx = cfg.Context - } - - ctx, cancel := context.WithCancel(baseCtx) - client := &Client{ - conn: nil, - dialerrc: make(chan error, 1), - cfg: *cfg, - creds: creds, - ctx: ctx, - cancel: cancel, - mu: new(sync.RWMutex), - callOpts: defaultCallOpts, - } - if cfg.Username != "" && cfg.Password != "" { - client.Username = cfg.Username - client.Password = cfg.Password - } - if cfg.MaxCallSendMsgSize > 0 || cfg.MaxCallRecvMsgSize > 0 { - if cfg.MaxCallRecvMsgSize > 0 && cfg.MaxCallSendMsgSize > cfg.MaxCallRecvMsgSize { - return nil, fmt.Errorf("gRPC message recv limit (%d bytes) must be greater than send limit (%d bytes)", cfg.MaxCallRecvMsgSize, cfg.MaxCallSendMsgSize) - } - callOpts := []grpc.CallOption{ - defaultFailFast, - defaultMaxCallSendMsgSize, - defaultMaxCallRecvMsgSize, - } - if cfg.MaxCallSendMsgSize > 0 { - callOpts[1] = grpc.MaxCallSendMsgSize(cfg.MaxCallSendMsgSize) - } - if cfg.MaxCallRecvMsgSize > 0 { - callOpts[2] = grpc.MaxCallRecvMsgSize(cfg.MaxCallRecvMsgSize) - } - client.callOpts = callOpts - } - - client.balancer = newHealthBalancer(cfg.Endpoints, cfg.DialTimeout, func(ep string) (bool, error) { - return grpcHealthCheck(client, ep) - }) - - // use Endpoints[0] so that for https:// without any tls config given, then - // grpc will assume the certificate server name is the endpoint host. - conn, err := client.dial(cfg.Endpoints[0], grpc.WithBalancer(client.balancer)) - if err != nil { - client.cancel() - client.balancer.Close() - return nil, err - } - client.conn = conn - - // wait for a connection - if cfg.DialTimeout > 0 { - hasConn := false - waitc := time.After(cfg.DialTimeout) - select { - case <-client.balancer.ready(): - hasConn = true - case <-ctx.Done(): - case <-waitc: - } - if !hasConn { - err := context.DeadlineExceeded - select { - case err = <-client.dialerrc: - default: - } - client.cancel() - client.balancer.Close() - conn.Close() - return nil, err - } - } - - client.Cluster = NewCluster(client) - client.KV = NewKV(client) - client.Lease = NewLease(client) - client.Watcher = NewWatcher(client) - client.Auth = NewAuth(client) - client.Maintenance = NewMaintenance(client) - - if cfg.RejectOldCluster { - if err := client.checkVersion(); err != nil { - client.Close() - return nil, err - } - } - - go client.autoSync() - return client, nil -} - -func (c *Client) checkVersion() (err error) { - var wg sync.WaitGroup - errc := make(chan error, len(c.cfg.Endpoints)) - ctx, cancel := context.WithCancel(c.ctx) - if c.cfg.DialTimeout > 0 { - ctx, cancel = context.WithTimeout(ctx, c.cfg.DialTimeout) - } - wg.Add(len(c.cfg.Endpoints)) - for _, ep := range c.cfg.Endpoints { - // if cluster is current, any endpoint gives a recent version - go func(e string) { - defer wg.Done() - resp, rerr := c.Status(ctx, e) - if rerr != nil { - errc <- rerr - return - } - vs := strings.Split(resp.Version, ".") - maj, min := 0, 0 - if len(vs) >= 2 { - maj, _ = strconv.Atoi(vs[0]) - min, rerr = strconv.Atoi(vs[1]) - } - if maj < 3 || (maj == 3 && min < 2) { - rerr = ErrOldCluster - } - errc <- rerr - }(ep) - } - // wait for success - for i := 0; i < len(c.cfg.Endpoints); i++ { - if err = <-errc; err == nil { - break - } - } - cancel() - wg.Wait() - return err -} - -// ActiveConnection returns the current in-use connection -func (c *Client) ActiveConnection() *grpc.ClientConn { return c.conn } - -// isHaltErr returns true if the given error and context indicate no forward -// progress can be made, even after reconnecting. -func isHaltErr(ctx context.Context, err error) bool { - if ctx != nil && ctx.Err() != nil { - return true - } - if err == nil { - return false - } - ev, _ := status.FromError(err) - // Unavailable codes mean the system will be right back. - // (e.g., can't connect, lost leader) - // Treat Internal codes as if something failed, leaving the - // system in an inconsistent state, but retrying could make progress. - // (e.g., failed in middle of send, corrupted frame) - // TODO: are permanent Internal errors possible from grpc? - return ev.Code() != codes.Unavailable && ev.Code() != codes.Internal -} - -// isUnavailableErr returns true if the given error is an unavailable error -func isUnavailableErr(ctx context.Context, err error) bool { - if ctx != nil && ctx.Err() != nil { - return false - } - if err == nil { - return false - } - ev, _ := status.FromError(err) - // Unavailable codes mean the system will be right back. - // (e.g., can't connect, lost leader) - return ev.Code() == codes.Unavailable -} - -func toErr(ctx context.Context, err error) error { - if err == nil { - return nil - } - err = rpctypes.Error(err) - if _, ok := err.(rpctypes.EtcdError); ok { - return err - } - ev, _ := status.FromError(err) - code := ev.Code() - switch code { - case codes.DeadlineExceeded: - fallthrough - case codes.Canceled: - if ctx.Err() != nil { - err = ctx.Err() - } - case codes.Unavailable: - case codes.FailedPrecondition: - err = grpc.ErrClientConnClosing - } - return err -} - -func canceledByCaller(stopCtx context.Context, err error) bool { - if stopCtx.Err() == nil || err == nil { - return false - } - - return err == context.Canceled || err == context.DeadlineExceeded -} diff --git a/vendor/github.com/coreos/etcd/clientv3/cluster.go b/vendor/github.com/coreos/etcd/clientv3/cluster.go deleted file mode 100644 index 785672be8ca2..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/cluster.go +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/pkg/types" - - "google.golang.org/grpc" -) - -type ( - Member pb.Member - MemberListResponse pb.MemberListResponse - MemberAddResponse pb.MemberAddResponse - MemberRemoveResponse pb.MemberRemoveResponse - MemberUpdateResponse pb.MemberUpdateResponse -) - -type Cluster interface { - // MemberList lists the current cluster membership. - MemberList(ctx context.Context) (*MemberListResponse, error) - - // MemberAdd adds a new member into the cluster. - MemberAdd(ctx context.Context, peerAddrs []string) (*MemberAddResponse, error) - - // MemberRemove removes an existing member from the cluster. - MemberRemove(ctx context.Context, id uint64) (*MemberRemoveResponse, error) - - // MemberUpdate updates the peer addresses of the member. - MemberUpdate(ctx context.Context, id uint64, peerAddrs []string) (*MemberUpdateResponse, error) -} - -type cluster struct { - remote pb.ClusterClient - callOpts []grpc.CallOption -} - -func NewCluster(c *Client) Cluster { - api := &cluster{remote: RetryClusterClient(c)} - if c != nil { - api.callOpts = c.callOpts - } - return api -} - -func NewClusterFromClusterClient(remote pb.ClusterClient, c *Client) Cluster { - api := &cluster{remote: remote} - if c != nil { - api.callOpts = c.callOpts - } - return api -} - -func (c *cluster) MemberAdd(ctx context.Context, peerAddrs []string) (*MemberAddResponse, error) { - // fail-fast before panic in rafthttp - if _, err := types.NewURLs(peerAddrs); err != nil { - return nil, err - } - - r := &pb.MemberAddRequest{PeerURLs: peerAddrs} - resp, err := c.remote.MemberAdd(ctx, r, c.callOpts...) - if err != nil { - return nil, toErr(ctx, err) - } - return (*MemberAddResponse)(resp), nil -} - -func (c *cluster) MemberRemove(ctx context.Context, id uint64) (*MemberRemoveResponse, error) { - r := &pb.MemberRemoveRequest{ID: id} - resp, err := c.remote.MemberRemove(ctx, r, c.callOpts...) - if err != nil { - return nil, toErr(ctx, err) - } - return (*MemberRemoveResponse)(resp), nil -} - -func (c *cluster) MemberUpdate(ctx context.Context, id uint64, peerAddrs []string) (*MemberUpdateResponse, error) { - // fail-fast before panic in rafthttp - if _, err := types.NewURLs(peerAddrs); err != nil { - return nil, err - } - - // it is safe to retry on update. - r := &pb.MemberUpdateRequest{ID: id, PeerURLs: peerAddrs} - resp, err := c.remote.MemberUpdate(ctx, r, c.callOpts...) - if err == nil { - return (*MemberUpdateResponse)(resp), nil - } - return nil, toErr(ctx, err) -} - -func (c *cluster) MemberList(ctx context.Context) (*MemberListResponse, error) { - // it is safe to retry on list. - resp, err := c.remote.MemberList(ctx, &pb.MemberListRequest{}, c.callOpts...) - if err == nil { - return (*MemberListResponse)(resp), nil - } - return nil, toErr(ctx, err) -} diff --git a/vendor/github.com/coreos/etcd/clientv3/compact_op.go b/vendor/github.com/coreos/etcd/clientv3/compact_op.go deleted file mode 100644 index 41e80c1da5d4..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/compact_op.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -// CompactOp represents a compact operation. -type CompactOp struct { - revision int64 - physical bool -} - -// CompactOption configures compact operation. -type CompactOption func(*CompactOp) - -func (op *CompactOp) applyCompactOpts(opts []CompactOption) { - for _, opt := range opts { - opt(op) - } -} - -// OpCompact wraps slice CompactOption to create a CompactOp. -func OpCompact(rev int64, opts ...CompactOption) CompactOp { - ret := CompactOp{revision: rev} - ret.applyCompactOpts(opts) - return ret -} - -func (op CompactOp) toRequest() *pb.CompactionRequest { - return &pb.CompactionRequest{Revision: op.revision, Physical: op.physical} -} - -// WithCompactPhysical makes Compact wait until all compacted entries are -// removed from the etcd server's storage. -func WithCompactPhysical() CompactOption { - return func(op *CompactOp) { op.physical = true } -} diff --git a/vendor/github.com/coreos/etcd/clientv3/compare.go b/vendor/github.com/coreos/etcd/clientv3/compare.go deleted file mode 100644 index b5f0a255279c..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/compare.go +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -type CompareTarget int -type CompareResult int - -const ( - CompareVersion CompareTarget = iota - CompareCreated - CompareModified - CompareValue -) - -type Cmp pb.Compare - -func Compare(cmp Cmp, result string, v interface{}) Cmp { - var r pb.Compare_CompareResult - - switch result { - case "=": - r = pb.Compare_EQUAL - case "!=": - r = pb.Compare_NOT_EQUAL - case ">": - r = pb.Compare_GREATER - case "<": - r = pb.Compare_LESS - default: - panic("Unknown result op") - } - - cmp.Result = r - switch cmp.Target { - case pb.Compare_VALUE: - val, ok := v.(string) - if !ok { - panic("bad compare value") - } - cmp.TargetUnion = &pb.Compare_Value{Value: []byte(val)} - case pb.Compare_VERSION: - cmp.TargetUnion = &pb.Compare_Version{Version: mustInt64(v)} - case pb.Compare_CREATE: - cmp.TargetUnion = &pb.Compare_CreateRevision{CreateRevision: mustInt64(v)} - case pb.Compare_MOD: - cmp.TargetUnion = &pb.Compare_ModRevision{ModRevision: mustInt64(v)} - case pb.Compare_LEASE: - cmp.TargetUnion = &pb.Compare_Lease{Lease: mustInt64orLeaseID(v)} - default: - panic("Unknown compare type") - } - return cmp -} - -func Value(key string) Cmp { - return Cmp{Key: []byte(key), Target: pb.Compare_VALUE} -} - -func Version(key string) Cmp { - return Cmp{Key: []byte(key), Target: pb.Compare_VERSION} -} - -func CreateRevision(key string) Cmp { - return Cmp{Key: []byte(key), Target: pb.Compare_CREATE} -} - -func ModRevision(key string) Cmp { - return Cmp{Key: []byte(key), Target: pb.Compare_MOD} -} - -// LeaseValue compares a key's LeaseID to a value of your choosing. The empty -// LeaseID is 0, otherwise known as `NoLease`. -func LeaseValue(key string) Cmp { - return Cmp{Key: []byte(key), Target: pb.Compare_LEASE} -} - -// KeyBytes returns the byte slice holding with the comparison key. -func (cmp *Cmp) KeyBytes() []byte { return cmp.Key } - -// WithKeyBytes sets the byte slice for the comparison key. -func (cmp *Cmp) WithKeyBytes(key []byte) { cmp.Key = key } - -// ValueBytes returns the byte slice holding the comparison value, if any. -func (cmp *Cmp) ValueBytes() []byte { - if tu, ok := cmp.TargetUnion.(*pb.Compare_Value); ok { - return tu.Value - } - return nil -} - -// WithValueBytes sets the byte slice for the comparison's value. -func (cmp *Cmp) WithValueBytes(v []byte) { cmp.TargetUnion.(*pb.Compare_Value).Value = v } - -// WithRange sets the comparison to scan the range [key, end). -func (cmp Cmp) WithRange(end string) Cmp { - cmp.RangeEnd = []byte(end) - return cmp -} - -// WithPrefix sets the comparison to scan all keys prefixed by the key. -func (cmp Cmp) WithPrefix() Cmp { - cmp.RangeEnd = getPrefix(cmp.Key) - return cmp -} - -// mustInt64 panics if val isn't an int or int64. It returns an int64 otherwise. -func mustInt64(val interface{}) int64 { - if v, ok := val.(int64); ok { - return v - } - if v, ok := val.(int); ok { - return int64(v) - } - panic("bad value") -} - -// mustInt64orLeaseID panics if val isn't a LeaseID, int or int64. It returns an -// int64 otherwise. -func mustInt64orLeaseID(val interface{}) int64 { - if v, ok := val.(LeaseID); ok { - return int64(v) - } - return mustInt64(val) -} diff --git a/vendor/github.com/coreos/etcd/clientv3/concurrency/doc.go b/vendor/github.com/coreos/etcd/clientv3/concurrency/doc.go deleted file mode 100644 index dcdbf511d1b1..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/concurrency/doc.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package concurrency implements concurrency operations on top of -// etcd such as distributed locks, barriers, and elections. -package concurrency diff --git a/vendor/github.com/coreos/etcd/clientv3/concurrency/election.go b/vendor/github.com/coreos/etcd/clientv3/concurrency/election.go deleted file mode 100644 index e18a0ed4ad92..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/concurrency/election.go +++ /dev/null @@ -1,245 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package concurrency - -import ( - "context" - "errors" - "fmt" - - v3 "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -var ( - ErrElectionNotLeader = errors.New("election: not leader") - ErrElectionNoLeader = errors.New("election: no leader") -) - -type Election struct { - session *Session - - keyPrefix string - - leaderKey string - leaderRev int64 - leaderSession *Session - hdr *pb.ResponseHeader -} - -// NewElection returns a new election on a given key prefix. -func NewElection(s *Session, pfx string) *Election { - return &Election{session: s, keyPrefix: pfx + "/"} -} - -// ResumeElection initializes an election with a known leader. -func ResumeElection(s *Session, pfx string, leaderKey string, leaderRev int64) *Election { - return &Election{ - session: s, - leaderKey: leaderKey, - leaderRev: leaderRev, - leaderSession: s, - } -} - -// Campaign puts a value as eligible for the election. It blocks until -// it is elected, an error occurs, or the context is cancelled. -func (e *Election) Campaign(ctx context.Context, val string) error { - s := e.session - client := e.session.Client() - - k := fmt.Sprintf("%s%x", e.keyPrefix, s.Lease()) - txn := client.Txn(ctx).If(v3.Compare(v3.CreateRevision(k), "=", 0)) - txn = txn.Then(v3.OpPut(k, val, v3.WithLease(s.Lease()))) - txn = txn.Else(v3.OpGet(k)) - resp, err := txn.Commit() - if err != nil { - return err - } - e.leaderKey, e.leaderRev, e.leaderSession = k, resp.Header.Revision, s - if !resp.Succeeded { - kv := resp.Responses[0].GetResponseRange().Kvs[0] - e.leaderRev = kv.CreateRevision - if string(kv.Value) != val { - if err = e.Proclaim(ctx, val); err != nil { - e.Resign(ctx) - return err - } - } - } - - _, err = waitDeletes(ctx, client, e.keyPrefix, e.leaderRev-1) - if err != nil { - // clean up in case of context cancel - select { - case <-ctx.Done(): - e.Resign(client.Ctx()) - default: - e.leaderSession = nil - } - return err - } - e.hdr = resp.Header - - return nil -} - -// Proclaim lets the leader announce a new value without another election. -func (e *Election) Proclaim(ctx context.Context, val string) error { - if e.leaderSession == nil { - return ErrElectionNotLeader - } - client := e.session.Client() - cmp := v3.Compare(v3.CreateRevision(e.leaderKey), "=", e.leaderRev) - txn := client.Txn(ctx).If(cmp) - txn = txn.Then(v3.OpPut(e.leaderKey, val, v3.WithLease(e.leaderSession.Lease()))) - tresp, terr := txn.Commit() - if terr != nil { - return terr - } - if !tresp.Succeeded { - e.leaderKey = "" - return ErrElectionNotLeader - } - - e.hdr = tresp.Header - return nil -} - -// Resign lets a leader start a new election. -func (e *Election) Resign(ctx context.Context) (err error) { - if e.leaderSession == nil { - return nil - } - client := e.session.Client() - cmp := v3.Compare(v3.CreateRevision(e.leaderKey), "=", e.leaderRev) - resp, err := client.Txn(ctx).If(cmp).Then(v3.OpDelete(e.leaderKey)).Commit() - if err == nil { - e.hdr = resp.Header - } - e.leaderKey = "" - e.leaderSession = nil - return err -} - -// Leader returns the leader value for the current election. -func (e *Election) Leader(ctx context.Context) (*v3.GetResponse, error) { - client := e.session.Client() - resp, err := client.Get(ctx, e.keyPrefix, v3.WithFirstCreate()...) - if err != nil { - return nil, err - } else if len(resp.Kvs) == 0 { - // no leader currently elected - return nil, ErrElectionNoLeader - } - return resp, nil -} - -// Observe returns a channel that reliably observes ordered leader proposals -// as GetResponse values on every current elected leader key. It will not -// necessarily fetch all historical leader updates, but will always post the -// most recent leader value. -// -// The channel closes when the context is canceled or the underlying watcher -// is otherwise disrupted. -func (e *Election) Observe(ctx context.Context) <-chan v3.GetResponse { - retc := make(chan v3.GetResponse) - go e.observe(ctx, retc) - return retc -} - -func (e *Election) observe(ctx context.Context, ch chan<- v3.GetResponse) { - client := e.session.Client() - - defer close(ch) - for { - resp, err := client.Get(ctx, e.keyPrefix, v3.WithFirstCreate()...) - if err != nil { - return - } - - var kv *mvccpb.KeyValue - var hdr *pb.ResponseHeader - - if len(resp.Kvs) == 0 { - cctx, cancel := context.WithCancel(ctx) - // wait for first key put on prefix - opts := []v3.OpOption{v3.WithRev(resp.Header.Revision), v3.WithPrefix()} - wch := client.Watch(cctx, e.keyPrefix, opts...) - for kv == nil { - wr, ok := <-wch - if !ok || wr.Err() != nil { - cancel() - return - } - // only accept puts; a delete will make observe() spin - for _, ev := range wr.Events { - if ev.Type == mvccpb.PUT { - hdr, kv = &wr.Header, ev.Kv - // may have multiple revs; hdr.rev = the last rev - // set to kv's rev in case batch has multiple Puts - hdr.Revision = kv.ModRevision - break - } - } - } - cancel() - } else { - hdr, kv = resp.Header, resp.Kvs[0] - } - - select { - case ch <- v3.GetResponse{Header: hdr, Kvs: []*mvccpb.KeyValue{kv}}: - case <-ctx.Done(): - return - } - - cctx, cancel := context.WithCancel(ctx) - wch := client.Watch(cctx, string(kv.Key), v3.WithRev(hdr.Revision+1)) - keyDeleted := false - for !keyDeleted { - wr, ok := <-wch - if !ok { - cancel() - return - } - for _, ev := range wr.Events { - if ev.Type == mvccpb.DELETE { - keyDeleted = true - break - } - resp.Header = &wr.Header - resp.Kvs = []*mvccpb.KeyValue{ev.Kv} - select { - case ch <- *resp: - case <-cctx.Done(): - cancel() - return - } - } - } - cancel() - } -} - -// Key returns the leader key if elected, empty string otherwise. -func (e *Election) Key() string { return e.leaderKey } - -// Rev returns the leader key's creation revision, if elected. -func (e *Election) Rev() int64 { return e.leaderRev } - -// Header is the response header from the last successful election proposal. -func (e *Election) Header() *pb.ResponseHeader { return e.hdr } diff --git a/vendor/github.com/coreos/etcd/clientv3/concurrency/key.go b/vendor/github.com/coreos/etcd/clientv3/concurrency/key.go deleted file mode 100644 index 4b6e399bd4e1..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/concurrency/key.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package concurrency - -import ( - "context" - "fmt" - - v3 "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -func waitDelete(ctx context.Context, client *v3.Client, key string, rev int64) error { - cctx, cancel := context.WithCancel(ctx) - defer cancel() - - var wr v3.WatchResponse - wch := client.Watch(cctx, key, v3.WithRev(rev)) - for wr = range wch { - for _, ev := range wr.Events { - if ev.Type == mvccpb.DELETE { - return nil - } - } - } - if err := wr.Err(); err != nil { - return err - } - if err := ctx.Err(); err != nil { - return err - } - return fmt.Errorf("lost watcher waiting for delete") -} - -// waitDeletes efficiently waits until all keys matching the prefix and no greater -// than the create revision. -func waitDeletes(ctx context.Context, client *v3.Client, pfx string, maxCreateRev int64) (*pb.ResponseHeader, error) { - getOpts := append(v3.WithLastCreate(), v3.WithMaxCreateRev(maxCreateRev)) - for { - resp, err := client.Get(ctx, pfx, getOpts...) - if err != nil { - return nil, err - } - if len(resp.Kvs) == 0 { - return resp.Header, nil - } - lastKey := string(resp.Kvs[0].Key) - if err = waitDelete(ctx, client, lastKey, resp.Header.Revision); err != nil { - return nil, err - } - } -} diff --git a/vendor/github.com/coreos/etcd/clientv3/concurrency/mutex.go b/vendor/github.com/coreos/etcd/clientv3/concurrency/mutex.go deleted file mode 100644 index 77b3582cde52..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/concurrency/mutex.go +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package concurrency - -import ( - "context" - "fmt" - "sync" - - v3 "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -// Mutex implements the sync Locker interface with etcd -type Mutex struct { - s *Session - - pfx string - myKey string - myRev int64 - hdr *pb.ResponseHeader -} - -func NewMutex(s *Session, pfx string) *Mutex { - return &Mutex{s, pfx + "/", "", -1, nil} -} - -// Lock locks the mutex with a cancelable context. If the context is canceled -// while trying to acquire the lock, the mutex tries to clean its stale lock entry. -func (m *Mutex) Lock(ctx context.Context) error { - s := m.s - client := m.s.Client() - - m.myKey = fmt.Sprintf("%s%x", m.pfx, s.Lease()) - cmp := v3.Compare(v3.CreateRevision(m.myKey), "=", 0) - // put self in lock waiters via myKey; oldest waiter holds lock - put := v3.OpPut(m.myKey, "", v3.WithLease(s.Lease())) - // reuse key in case this session already holds the lock - get := v3.OpGet(m.myKey) - // fetch current holder to complete uncontended path with only one RPC - getOwner := v3.OpGet(m.pfx, v3.WithFirstCreate()...) - resp, err := client.Txn(ctx).If(cmp).Then(put, getOwner).Else(get, getOwner).Commit() - if err != nil { - return err - } - m.myRev = resp.Header.Revision - if !resp.Succeeded { - m.myRev = resp.Responses[0].GetResponseRange().Kvs[0].CreateRevision - } - // if no key on prefix / the minimum rev is key, already hold the lock - ownerKey := resp.Responses[1].GetResponseRange().Kvs - if len(ownerKey) == 0 || ownerKey[0].CreateRevision == m.myRev { - m.hdr = resp.Header - return nil - } - - // wait for deletion revisions prior to myKey - hdr, werr := waitDeletes(ctx, client, m.pfx, m.myRev-1) - // release lock key if wait failed - if werr != nil { - m.Unlock(client.Ctx()) - } else { - m.hdr = hdr - } - return werr -} - -func (m *Mutex) Unlock(ctx context.Context) error { - client := m.s.Client() - if _, err := client.Delete(ctx, m.myKey); err != nil { - return err - } - m.myKey = "\x00" - m.myRev = -1 - return nil -} - -func (m *Mutex) IsOwner() v3.Cmp { - return v3.Compare(v3.CreateRevision(m.myKey), "=", m.myRev) -} - -func (m *Mutex) Key() string { return m.myKey } - -// Header is the response header received from etcd on acquiring the lock. -func (m *Mutex) Header() *pb.ResponseHeader { return m.hdr } - -type lockerMutex struct{ *Mutex } - -func (lm *lockerMutex) Lock() { - client := lm.s.Client() - if err := lm.Mutex.Lock(client.Ctx()); err != nil { - panic(err) - } -} -func (lm *lockerMutex) Unlock() { - client := lm.s.Client() - if err := lm.Mutex.Unlock(client.Ctx()); err != nil { - panic(err) - } -} - -// NewLocker creates a sync.Locker backed by an etcd mutex. -func NewLocker(s *Session, pfx string) sync.Locker { - return &lockerMutex{NewMutex(s, pfx)} -} diff --git a/vendor/github.com/coreos/etcd/clientv3/concurrency/session.go b/vendor/github.com/coreos/etcd/clientv3/concurrency/session.go deleted file mode 100644 index c399d64a61db..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/concurrency/session.go +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package concurrency - -import ( - "context" - "time" - - v3 "github.com/coreos/etcd/clientv3" -) - -const defaultSessionTTL = 60 - -// Session represents a lease kept alive for the lifetime of a client. -// Fault-tolerant applications may use sessions to reason about liveness. -type Session struct { - client *v3.Client - opts *sessionOptions - id v3.LeaseID - - cancel context.CancelFunc - donec <-chan struct{} -} - -// NewSession gets the leased session for a client. -func NewSession(client *v3.Client, opts ...SessionOption) (*Session, error) { - ops := &sessionOptions{ttl: defaultSessionTTL, ctx: client.Ctx()} - for _, opt := range opts { - opt(ops) - } - - id := ops.leaseID - if id == v3.NoLease { - resp, err := client.Grant(ops.ctx, int64(ops.ttl)) - if err != nil { - return nil, err - } - id = v3.LeaseID(resp.ID) - } - - ctx, cancel := context.WithCancel(ops.ctx) - keepAlive, err := client.KeepAlive(ctx, id) - if err != nil || keepAlive == nil { - cancel() - return nil, err - } - - donec := make(chan struct{}) - s := &Session{client: client, opts: ops, id: id, cancel: cancel, donec: donec} - - // keep the lease alive until client error or cancelled context - go func() { - defer close(donec) - for range keepAlive { - // eat messages until keep alive channel closes - } - }() - - return s, nil -} - -// Client is the etcd client that is attached to the session. -func (s *Session) Client() *v3.Client { - return s.client -} - -// Lease is the lease ID for keys bound to the session. -func (s *Session) Lease() v3.LeaseID { return s.id } - -// Done returns a channel that closes when the lease is orphaned, expires, or -// is otherwise no longer being refreshed. -func (s *Session) Done() <-chan struct{} { return s.donec } - -// Orphan ends the refresh for the session lease. This is useful -// in case the state of the client connection is indeterminate (revoke -// would fail) or when transferring lease ownership. -func (s *Session) Orphan() { - s.cancel() - <-s.donec -} - -// Close orphans the session and revokes the session lease. -func (s *Session) Close() error { - s.Orphan() - // if revoke takes longer than the ttl, lease is expired anyway - ctx, cancel := context.WithTimeout(s.opts.ctx, time.Duration(s.opts.ttl)*time.Second) - _, err := s.client.Revoke(ctx, s.id) - cancel() - return err -} - -type sessionOptions struct { - ttl int - leaseID v3.LeaseID - ctx context.Context -} - -// SessionOption configures Session. -type SessionOption func(*sessionOptions) - -// WithTTL configures the session's TTL in seconds. -// If TTL is <= 0, the default 60 seconds TTL will be used. -func WithTTL(ttl int) SessionOption { - return func(so *sessionOptions) { - if ttl > 0 { - so.ttl = ttl - } - } -} - -// WithLease specifies the existing leaseID to be used for the session. -// This is useful in process restart scenario, for example, to reclaim -// leadership from an election prior to restart. -func WithLease(leaseID v3.LeaseID) SessionOption { - return func(so *sessionOptions) { - so.leaseID = leaseID - } -} - -// WithContext assigns a context to the session instead of defaulting to -// using the client context. This is useful for canceling NewSession and -// Close operations immediately without having to close the client. If the -// context is canceled before Close() completes, the session's lease will be -// abandoned and left to expire instead of being revoked. -func WithContext(ctx context.Context) SessionOption { - return func(so *sessionOptions) { - so.ctx = ctx - } -} diff --git a/vendor/github.com/coreos/etcd/clientv3/concurrency/stm.go b/vendor/github.com/coreos/etcd/clientv3/concurrency/stm.go deleted file mode 100644 index d11023ebe361..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/concurrency/stm.go +++ /dev/null @@ -1,387 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package concurrency - -import ( - "context" - "math" - - v3 "github.com/coreos/etcd/clientv3" -) - -// STM is an interface for software transactional memory. -type STM interface { - // Get returns the value for a key and inserts the key in the txn's read set. - // If Get fails, it aborts the transaction with an error, never returning. - Get(key ...string) string - // Put adds a value for a key to the write set. - Put(key, val string, opts ...v3.OpOption) - // Rev returns the revision of a key in the read set. - Rev(key string) int64 - // Del deletes a key. - Del(key string) - - // commit attempts to apply the txn's changes to the server. - commit() *v3.TxnResponse - reset() -} - -// Isolation is an enumeration of transactional isolation levels which -// describes how transactions should interfere and conflict. -type Isolation int - -const ( - // SerializableSnapshot provides serializable isolation and also checks - // for write conflicts. - SerializableSnapshot Isolation = iota - // Serializable reads within the same transaction attempt return data - // from the at the revision of the first read. - Serializable - // RepeatableReads reads within the same transaction attempt always - // return the same data. - RepeatableReads - // ReadCommitted reads keys from any committed revision. - ReadCommitted -) - -// stmError safely passes STM errors through panic to the STM error channel. -type stmError struct{ err error } - -type stmOptions struct { - iso Isolation - ctx context.Context - prefetch []string -} - -type stmOption func(*stmOptions) - -// WithIsolation specifies the transaction isolation level. -func WithIsolation(lvl Isolation) stmOption { - return func(so *stmOptions) { so.iso = lvl } -} - -// WithAbortContext specifies the context for permanently aborting the transaction. -func WithAbortContext(ctx context.Context) stmOption { - return func(so *stmOptions) { so.ctx = ctx } -} - -// WithPrefetch is a hint to prefetch a list of keys before trying to apply. -// If an STM transaction will unconditionally fetch a set of keys, prefetching -// those keys will save the round-trip cost from requesting each key one by one -// with Get(). -func WithPrefetch(keys ...string) stmOption { - return func(so *stmOptions) { so.prefetch = append(so.prefetch, keys...) } -} - -// NewSTM initiates a new STM instance, using serializable snapshot isolation by default. -func NewSTM(c *v3.Client, apply func(STM) error, so ...stmOption) (*v3.TxnResponse, error) { - opts := &stmOptions{ctx: c.Ctx()} - for _, f := range so { - f(opts) - } - if len(opts.prefetch) != 0 { - f := apply - apply = func(s STM) error { - s.Get(opts.prefetch...) - return f(s) - } - } - return runSTM(mkSTM(c, opts), apply) -} - -func mkSTM(c *v3.Client, opts *stmOptions) STM { - switch opts.iso { - case SerializableSnapshot: - s := &stmSerializable{ - stm: stm{client: c, ctx: opts.ctx}, - prefetch: make(map[string]*v3.GetResponse), - } - s.conflicts = func() []v3.Cmp { - return append(s.rset.cmps(), s.wset.cmps(s.rset.first()+1)...) - } - return s - case Serializable: - s := &stmSerializable{ - stm: stm{client: c, ctx: opts.ctx}, - prefetch: make(map[string]*v3.GetResponse), - } - s.conflicts = func() []v3.Cmp { return s.rset.cmps() } - return s - case RepeatableReads: - s := &stm{client: c, ctx: opts.ctx, getOpts: []v3.OpOption{v3.WithSerializable()}} - s.conflicts = func() []v3.Cmp { return s.rset.cmps() } - return s - case ReadCommitted: - s := &stm{client: c, ctx: opts.ctx, getOpts: []v3.OpOption{v3.WithSerializable()}} - s.conflicts = func() []v3.Cmp { return nil } - return s - default: - panic("unsupported stm") - } -} - -type stmResponse struct { - resp *v3.TxnResponse - err error -} - -func runSTM(s STM, apply func(STM) error) (*v3.TxnResponse, error) { - outc := make(chan stmResponse, 1) - go func() { - defer func() { - if r := recover(); r != nil { - e, ok := r.(stmError) - if !ok { - // client apply panicked - panic(r) - } - outc <- stmResponse{nil, e.err} - } - }() - var out stmResponse - for { - s.reset() - if out.err = apply(s); out.err != nil { - break - } - if out.resp = s.commit(); out.resp != nil { - break - } - } - outc <- out - }() - r := <-outc - return r.resp, r.err -} - -// stm implements repeatable-read software transactional memory over etcd -type stm struct { - client *v3.Client - ctx context.Context - // rset holds read key values and revisions - rset readSet - // wset holds overwritten keys and their values - wset writeSet - // getOpts are the opts used for gets - getOpts []v3.OpOption - // conflicts computes the current conflicts on the txn - conflicts func() []v3.Cmp -} - -type stmPut struct { - val string - op v3.Op -} - -type readSet map[string]*v3.GetResponse - -func (rs readSet) add(keys []string, txnresp *v3.TxnResponse) { - for i, resp := range txnresp.Responses { - rs[keys[i]] = (*v3.GetResponse)(resp.GetResponseRange()) - } -} - -// first returns the store revision from the first fetch -func (rs readSet) first() int64 { - ret := int64(math.MaxInt64 - 1) - for _, resp := range rs { - if rev := resp.Header.Revision; rev < ret { - ret = rev - } - } - return ret -} - -// cmps guards the txn from updates to read set -func (rs readSet) cmps() []v3.Cmp { - cmps := make([]v3.Cmp, 0, len(rs)) - for k, rk := range rs { - cmps = append(cmps, isKeyCurrent(k, rk)) - } - return cmps -} - -type writeSet map[string]stmPut - -func (ws writeSet) get(keys ...string) *stmPut { - for _, key := range keys { - if wv, ok := ws[key]; ok { - return &wv - } - } - return nil -} - -// cmps returns a cmp list testing no writes have happened past rev -func (ws writeSet) cmps(rev int64) []v3.Cmp { - cmps := make([]v3.Cmp, 0, len(ws)) - for key := range ws { - cmps = append(cmps, v3.Compare(v3.ModRevision(key), "<", rev)) - } - return cmps -} - -// puts is the list of ops for all pending writes -func (ws writeSet) puts() []v3.Op { - puts := make([]v3.Op, 0, len(ws)) - for _, v := range ws { - puts = append(puts, v.op) - } - return puts -} - -func (s *stm) Get(keys ...string) string { - if wv := s.wset.get(keys...); wv != nil { - return wv.val - } - return respToValue(s.fetch(keys...)) -} - -func (s *stm) Put(key, val string, opts ...v3.OpOption) { - s.wset[key] = stmPut{val, v3.OpPut(key, val, opts...)} -} - -func (s *stm) Del(key string) { s.wset[key] = stmPut{"", v3.OpDelete(key)} } - -func (s *stm) Rev(key string) int64 { - if resp := s.fetch(key); resp != nil && len(resp.Kvs) != 0 { - return resp.Kvs[0].ModRevision - } - return 0 -} - -func (s *stm) commit() *v3.TxnResponse { - txnresp, err := s.client.Txn(s.ctx).If(s.conflicts()...).Then(s.wset.puts()...).Commit() - if err != nil { - panic(stmError{err}) - } - if txnresp.Succeeded { - return txnresp - } - return nil -} - -func (s *stm) fetch(keys ...string) *v3.GetResponse { - if len(keys) == 0 { - return nil - } - ops := make([]v3.Op, len(keys)) - for i, key := range keys { - if resp, ok := s.rset[key]; ok { - return resp - } - ops[i] = v3.OpGet(key, s.getOpts...) - } - txnresp, err := s.client.Txn(s.ctx).Then(ops...).Commit() - if err != nil { - panic(stmError{err}) - } - s.rset.add(keys, txnresp) - return (*v3.GetResponse)(txnresp.Responses[0].GetResponseRange()) -} - -func (s *stm) reset() { - s.rset = make(map[string]*v3.GetResponse) - s.wset = make(map[string]stmPut) -} - -type stmSerializable struct { - stm - prefetch map[string]*v3.GetResponse -} - -func (s *stmSerializable) Get(keys ...string) string { - if wv := s.wset.get(keys...); wv != nil { - return wv.val - } - firstRead := len(s.rset) == 0 - for _, key := range keys { - if resp, ok := s.prefetch[key]; ok { - delete(s.prefetch, key) - s.rset[key] = resp - } - } - resp := s.stm.fetch(keys...) - if firstRead { - // txn's base revision is defined by the first read - s.getOpts = []v3.OpOption{ - v3.WithRev(resp.Header.Revision), - v3.WithSerializable(), - } - } - return respToValue(resp) -} - -func (s *stmSerializable) Rev(key string) int64 { - s.Get(key) - return s.stm.Rev(key) -} - -func (s *stmSerializable) gets() ([]string, []v3.Op) { - keys := make([]string, 0, len(s.rset)) - ops := make([]v3.Op, 0, len(s.rset)) - for k := range s.rset { - keys = append(keys, k) - ops = append(ops, v3.OpGet(k)) - } - return keys, ops -} - -func (s *stmSerializable) commit() *v3.TxnResponse { - keys, getops := s.gets() - txn := s.client.Txn(s.ctx).If(s.conflicts()...).Then(s.wset.puts()...) - // use Else to prefetch keys in case of conflict to save a round trip - txnresp, err := txn.Else(getops...).Commit() - if err != nil { - panic(stmError{err}) - } - if txnresp.Succeeded { - return txnresp - } - // load prefetch with Else data - s.rset.add(keys, txnresp) - s.prefetch = s.rset - s.getOpts = nil - return nil -} - -func isKeyCurrent(k string, r *v3.GetResponse) v3.Cmp { - if len(r.Kvs) != 0 { - return v3.Compare(v3.ModRevision(k), "=", r.Kvs[0].ModRevision) - } - return v3.Compare(v3.ModRevision(k), "=", 0) -} - -func respToValue(resp *v3.GetResponse) string { - if resp == nil || len(resp.Kvs) == 0 { - return "" - } - return string(resp.Kvs[0].Value) -} - -// NewSTMRepeatable is deprecated. -func NewSTMRepeatable(ctx context.Context, c *v3.Client, apply func(STM) error) (*v3.TxnResponse, error) { - return NewSTM(c, apply, WithAbortContext(ctx), WithIsolation(RepeatableReads)) -} - -// NewSTMSerializable is deprecated. -func NewSTMSerializable(ctx context.Context, c *v3.Client, apply func(STM) error) (*v3.TxnResponse, error) { - return NewSTM(c, apply, WithAbortContext(ctx), WithIsolation(Serializable)) -} - -// NewSTMReadCommitted is deprecated. -func NewSTMReadCommitted(ctx context.Context, c *v3.Client, apply func(STM) error) (*v3.TxnResponse, error) { - return NewSTM(c, apply, WithAbortContext(ctx), WithIsolation(ReadCommitted)) -} diff --git a/vendor/github.com/coreos/etcd/clientv3/config.go b/vendor/github.com/coreos/etcd/clientv3/config.go deleted file mode 100644 index 79d6e2a984f3..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/config.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - "crypto/tls" - "time" - - "google.golang.org/grpc" -) - -type Config struct { - // Endpoints is a list of URLs. - Endpoints []string `json:"endpoints"` - - // AutoSyncInterval is the interval to update endpoints with its latest members. - // 0 disables auto-sync. By default auto-sync is disabled. - AutoSyncInterval time.Duration `json:"auto-sync-interval"` - - // DialTimeout is the timeout for failing to establish a connection. - DialTimeout time.Duration `json:"dial-timeout"` - - // DialKeepAliveTime is the time after which client pings the server to see if - // transport is alive. - DialKeepAliveTime time.Duration `json:"dial-keep-alive-time"` - - // DialKeepAliveTimeout is the time that the client waits for a response for the - // keep-alive probe. If the response is not received in this time, the connection is closed. - DialKeepAliveTimeout time.Duration `json:"dial-keep-alive-timeout"` - - // MaxCallSendMsgSize is the client-side request send limit in bytes. - // If 0, it defaults to 2.0 MiB (2 * 1024 * 1024). - // Make sure that "MaxCallSendMsgSize" < server-side default send/recv limit. - // ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes"). - MaxCallSendMsgSize int - - // MaxCallRecvMsgSize is the client-side response receive limit. - // If 0, it defaults to "math.MaxInt32", because range response can - // easily exceed request send limits. - // Make sure that "MaxCallRecvMsgSize" >= server-side default send/recv limit. - // ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes"). - MaxCallRecvMsgSize int - - // TLS holds the client secure credentials, if any. - TLS *tls.Config - - // Username is a user name for authentication. - Username string `json:"username"` - - // Password is a password for authentication. - Password string `json:"password"` - - // RejectOldCluster when set will refuse to create a client against an outdated cluster. - RejectOldCluster bool `json:"reject-old-cluster"` - - // DialOptions is a list of dial options for the grpc client (e.g., for interceptors). - DialOptions []grpc.DialOption - - // Context is the default client context; it can be used to cancel grpc dial out and - // other operations that do not have an explicit context. - Context context.Context -} diff --git a/vendor/github.com/coreos/etcd/clientv3/doc.go b/vendor/github.com/coreos/etcd/clientv3/doc.go deleted file mode 100644 index 717fbe435ea5..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/doc.go +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package clientv3 implements the official Go etcd client for v3. -// -// Create client using `clientv3.New`: -// -// // expect dial time-out on ipv4 blackhole -// _, err := clientv3.New(clientv3.Config{ -// Endpoints: []string{"http://254.0.0.1:12345"}, -// DialTimeout: 2 * time.Second -// }) -// -// // etcd clientv3 >= v3.2.10, grpc/grpc-go >= v1.7.3 -// if err == context.DeadlineExceeded { -// // handle errors -// } -// -// // etcd clientv3 <= v3.2.9, grpc/grpc-go <= v1.2.1 -// if err == grpc.ErrClientConnTimeout { -// // handle errors -// } -// -// cli, err := clientv3.New(clientv3.Config{ -// Endpoints: []string{"localhost:2379", "localhost:22379", "localhost:32379"}, -// DialTimeout: 5 * time.Second, -// }) -// if err != nil { -// // handle error! -// } -// defer cli.Close() -// -// Make sure to close the client after using it. If the client is not closed, the -// connection will have leaky goroutines. -// -// To specify a client request timeout, wrap the context with context.WithTimeout: -// -// ctx, cancel := context.WithTimeout(context.Background(), timeout) -// resp, err := kvc.Put(ctx, "sample_key", "sample_value") -// cancel() -// if err != nil { -// // handle error! -// } -// // use the response -// -// The Client has internal state (watchers and leases), so Clients should be reused instead of created as needed. -// Clients are safe for concurrent use by multiple goroutines. -// -// etcd client returns 3 types of errors: -// -// 1. context error: canceled or deadline exceeded. -// 2. gRPC status error: e.g. when clock drifts in server-side before client's context deadline exceeded. -// 3. gRPC error: see https://github.com/coreos/etcd/blob/master/etcdserver/api/v3rpc/rpctypes/error.go -// -// Here is the example code to handle client errors: -// -// resp, err := kvc.Put(ctx, "", "") -// if err != nil { -// if err == context.Canceled { -// // ctx is canceled by another routine -// } else if err == context.DeadlineExceeded { -// // ctx is attached with a deadline and it exceeded -// } else if ev, ok := status.FromError(err); ok { -// code := ev.Code() -// if code == codes.DeadlineExceeded { -// // server-side context might have timed-out first (due to clock skew) -// // while original client-side context is not timed-out yet -// } -// } else if verr, ok := err.(*v3rpc.ErrEmptyKey); ok { -// // process (verr.Errors) -// } else { -// // bad cluster endpoints, which are not etcd servers -// } -// } -// -// go func() { cli.Close() }() -// _, err := kvc.Get(ctx, "a") -// if err != nil { -// if err == context.Canceled { -// // grpc balancer calls 'Get' with an inflight client.Close -// } else if err == grpc.ErrClientConnClosing { -// // grpc balancer calls 'Get' after client.Close. -// } -// } -// -package clientv3 diff --git a/vendor/github.com/coreos/etcd/clientv3/health_balancer.go b/vendor/github.com/coreos/etcd/clientv3/health_balancer.go deleted file mode 100644 index 5918cba84823..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/health_balancer.go +++ /dev/null @@ -1,609 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - "errors" - "net/url" - "strings" - "sync" - "time" - - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - healthpb "google.golang.org/grpc/health/grpc_health_v1" - "google.golang.org/grpc/status" -) - -const ( - minHealthRetryDuration = 3 * time.Second - unknownService = "unknown service grpc.health.v1.Health" -) - -// ErrNoAddrAvilable is returned by Get() when the balancer does not have -// any active connection to endpoints at the time. -// This error is returned only when opts.BlockingWait is true. -var ErrNoAddrAvilable = status.Error(codes.Unavailable, "there is no address available") - -type healthCheckFunc func(ep string) (bool, error) - -type notifyMsg int - -const ( - notifyReset notifyMsg = iota - notifyNext -) - -// healthBalancer does the bare minimum to expose multiple eps -// to the grpc reconnection code path -type healthBalancer struct { - // addrs are the client's endpoint addresses for grpc - addrs []grpc.Address - - // eps holds the raw endpoints from the client - eps []string - - // notifyCh notifies grpc of the set of addresses for connecting - notifyCh chan []grpc.Address - - // readyc closes once the first connection is up - readyc chan struct{} - readyOnce sync.Once - - // healthCheck checks an endpoint's health. - healthCheck healthCheckFunc - healthCheckTimeout time.Duration - - unhealthyMu sync.RWMutex - unhealthyHostPorts map[string]time.Time - - // mu protects all fields below. - mu sync.RWMutex - - // upc closes when pinAddr transitions from empty to non-empty or the balancer closes. - upc chan struct{} - - // downc closes when grpc calls down() on pinAddr - downc chan struct{} - - // stopc is closed to signal updateNotifyLoop should stop. - stopc chan struct{} - stopOnce sync.Once - wg sync.WaitGroup - - // donec closes when all goroutines are exited - donec chan struct{} - - // updateAddrsC notifies updateNotifyLoop to update addrs. - updateAddrsC chan notifyMsg - - // grpc issues TLS cert checks using the string passed into dial so - // that string must be the host. To recover the full scheme://host URL, - // have a map from hosts to the original endpoint. - hostPort2ep map[string]string - - // pinAddr is the currently pinned address; set to the empty string on - // initialization and shutdown. - pinAddr string - - closed bool -} - -func newHealthBalancer(eps []string, timeout time.Duration, hc healthCheckFunc) *healthBalancer { - notifyCh := make(chan []grpc.Address) - addrs := eps2addrs(eps) - hb := &healthBalancer{ - addrs: addrs, - eps: eps, - notifyCh: notifyCh, - readyc: make(chan struct{}), - healthCheck: hc, - unhealthyHostPorts: make(map[string]time.Time), - upc: make(chan struct{}), - stopc: make(chan struct{}), - downc: make(chan struct{}), - donec: make(chan struct{}), - updateAddrsC: make(chan notifyMsg), - hostPort2ep: getHostPort2ep(eps), - } - if timeout < minHealthRetryDuration { - timeout = minHealthRetryDuration - } - hb.healthCheckTimeout = timeout - - close(hb.downc) - go hb.updateNotifyLoop() - hb.wg.Add(1) - go func() { - defer hb.wg.Done() - hb.updateUnhealthy() - }() - return hb -} - -func (b *healthBalancer) Start(target string, config grpc.BalancerConfig) error { return nil } - -func (b *healthBalancer) ConnectNotify() <-chan struct{} { - b.mu.Lock() - defer b.mu.Unlock() - return b.upc -} - -func (b *healthBalancer) ready() <-chan struct{} { return b.readyc } - -func (b *healthBalancer) endpoint(hostPort string) string { - b.mu.RLock() - defer b.mu.RUnlock() - return b.hostPort2ep[hostPort] -} - -func (b *healthBalancer) pinned() string { - b.mu.RLock() - defer b.mu.RUnlock() - return b.pinAddr -} - -func (b *healthBalancer) hostPortError(hostPort string, err error) { - if b.endpoint(hostPort) == "" { - logger.Lvl(4).Infof("clientv3/balancer: %q is stale (skip marking as unhealthy on %q)", hostPort, err.Error()) - return - } - - b.unhealthyMu.Lock() - b.unhealthyHostPorts[hostPort] = time.Now() - b.unhealthyMu.Unlock() - logger.Lvl(4).Infof("clientv3/balancer: %q is marked unhealthy (%q)", hostPort, err.Error()) -} - -func (b *healthBalancer) removeUnhealthy(hostPort, msg string) { - if b.endpoint(hostPort) == "" { - logger.Lvl(4).Infof("clientv3/balancer: %q was not in unhealthy (%q)", hostPort, msg) - return - } - - b.unhealthyMu.Lock() - delete(b.unhealthyHostPorts, hostPort) - b.unhealthyMu.Unlock() - logger.Lvl(4).Infof("clientv3/balancer: %q is removed from unhealthy (%q)", hostPort, msg) -} - -func (b *healthBalancer) countUnhealthy() (count int) { - b.unhealthyMu.RLock() - count = len(b.unhealthyHostPorts) - b.unhealthyMu.RUnlock() - return count -} - -func (b *healthBalancer) isUnhealthy(hostPort string) (unhealthy bool) { - b.unhealthyMu.RLock() - _, unhealthy = b.unhealthyHostPorts[hostPort] - b.unhealthyMu.RUnlock() - return unhealthy -} - -func (b *healthBalancer) cleanupUnhealthy() { - b.unhealthyMu.Lock() - for k, v := range b.unhealthyHostPorts { - if time.Since(v) > b.healthCheckTimeout { - delete(b.unhealthyHostPorts, k) - logger.Lvl(4).Infof("clientv3/balancer: removed %q from unhealthy after %v", k, b.healthCheckTimeout) - } - } - b.unhealthyMu.Unlock() -} - -func (b *healthBalancer) liveAddrs() ([]grpc.Address, map[string]struct{}) { - unhealthyCnt := b.countUnhealthy() - - b.mu.RLock() - defer b.mu.RUnlock() - - hbAddrs := b.addrs - if len(b.addrs) == 1 || unhealthyCnt == 0 || unhealthyCnt == len(b.addrs) { - liveHostPorts := make(map[string]struct{}, len(b.hostPort2ep)) - for k := range b.hostPort2ep { - liveHostPorts[k] = struct{}{} - } - return hbAddrs, liveHostPorts - } - - addrs := make([]grpc.Address, 0, len(b.addrs)-unhealthyCnt) - liveHostPorts := make(map[string]struct{}, len(addrs)) - for _, addr := range b.addrs { - if !b.isUnhealthy(addr.Addr) { - addrs = append(addrs, addr) - liveHostPorts[addr.Addr] = struct{}{} - } - } - return addrs, liveHostPorts -} - -func (b *healthBalancer) updateUnhealthy() { - for { - select { - case <-time.After(b.healthCheckTimeout): - b.cleanupUnhealthy() - pinned := b.pinned() - if pinned == "" || b.isUnhealthy(pinned) { - select { - case b.updateAddrsC <- notifyNext: - case <-b.stopc: - return - } - } - case <-b.stopc: - return - } - } -} - -func (b *healthBalancer) updateAddrs(eps ...string) { - np := getHostPort2ep(eps) - - b.mu.Lock() - defer b.mu.Unlock() - - match := len(np) == len(b.hostPort2ep) - if match { - for k, v := range np { - if b.hostPort2ep[k] != v { - match = false - break - } - } - } - if match { - // same endpoints, so no need to update address - return - } - - b.hostPort2ep = np - b.addrs, b.eps = eps2addrs(eps), eps - - b.unhealthyMu.Lock() - b.unhealthyHostPorts = make(map[string]time.Time) - b.unhealthyMu.Unlock() -} - -func (b *healthBalancer) next() { - b.mu.RLock() - downc := b.downc - b.mu.RUnlock() - select { - case b.updateAddrsC <- notifyNext: - case <-b.stopc: - } - // wait until disconnect so new RPCs are not issued on old connection - select { - case <-downc: - case <-b.stopc: - } -} - -func (b *healthBalancer) updateNotifyLoop() { - defer close(b.donec) - - for { - b.mu.RLock() - upc, downc, addr := b.upc, b.downc, b.pinAddr - b.mu.RUnlock() - // downc or upc should be closed - select { - case <-downc: - downc = nil - default: - } - select { - case <-upc: - upc = nil - default: - } - switch { - case downc == nil && upc == nil: - // stale - select { - case <-b.stopc: - return - default: - } - case downc == nil: - b.notifyAddrs(notifyReset) - select { - case <-upc: - case msg := <-b.updateAddrsC: - b.notifyAddrs(msg) - case <-b.stopc: - return - } - case upc == nil: - select { - // close connections that are not the pinned address - case b.notifyCh <- []grpc.Address{{Addr: addr}}: - case <-downc: - case <-b.stopc: - return - } - select { - case <-downc: - b.notifyAddrs(notifyReset) - case msg := <-b.updateAddrsC: - b.notifyAddrs(msg) - case <-b.stopc: - return - } - } - } -} - -func (b *healthBalancer) notifyAddrs(msg notifyMsg) { - if msg == notifyNext { - select { - case b.notifyCh <- []grpc.Address{}: - case <-b.stopc: - return - } - } - b.mu.RLock() - pinAddr := b.pinAddr - downc := b.downc - b.mu.RUnlock() - addrs, hostPorts := b.liveAddrs() - - var waitDown bool - if pinAddr != "" { - _, ok := hostPorts[pinAddr] - waitDown = !ok - } - - select { - case b.notifyCh <- addrs: - if waitDown { - select { - case <-downc: - case <-b.stopc: - } - } - case <-b.stopc: - } -} - -func (b *healthBalancer) Up(addr grpc.Address) func(error) { - if !b.mayPin(addr) { - return func(err error) {} - } - - b.mu.Lock() - defer b.mu.Unlock() - - // gRPC might call Up after it called Close. We add this check - // to "fix" it up at application layer. Otherwise, will panic - // if b.upc is already closed. - if b.closed { - return func(err error) {} - } - - // gRPC might call Up on a stale address. - // Prevent updating pinAddr with a stale address. - if !hasAddr(b.addrs, addr.Addr) { - return func(err error) {} - } - - if b.pinAddr != "" { - logger.Lvl(4).Infof("clientv3/balancer: %q is up but not pinned (already pinned %q)", addr.Addr, b.pinAddr) - return func(err error) {} - } - - // notify waiting Get()s and pin first connected address - close(b.upc) - b.downc = make(chan struct{}) - b.pinAddr = addr.Addr - logger.Lvl(4).Infof("clientv3/balancer: pin %q", addr.Addr) - - // notify client that a connection is up - b.readyOnce.Do(func() { close(b.readyc) }) - - return func(err error) { - // If connected to a black hole endpoint or a killed server, the gRPC ping - // timeout will induce a network I/O error, and retrying until success; - // finding healthy endpoint on retry could take several timeouts and redials. - // To avoid wasting retries, gray-list unhealthy endpoints. - b.hostPortError(addr.Addr, err) - - b.mu.Lock() - b.upc = make(chan struct{}) - close(b.downc) - b.pinAddr = "" - b.mu.Unlock() - logger.Lvl(4).Infof("clientv3/balancer: unpin %q (%q)", addr.Addr, err.Error()) - } -} - -func (b *healthBalancer) mayPin(addr grpc.Address) bool { - if b.endpoint(addr.Addr) == "" { // stale host:port - return false - } - - b.unhealthyMu.RLock() - unhealthyCnt := len(b.unhealthyHostPorts) - failedTime, bad := b.unhealthyHostPorts[addr.Addr] - b.unhealthyMu.RUnlock() - - b.mu.RLock() - skip := len(b.addrs) == 1 || unhealthyCnt == 0 || len(b.addrs) == unhealthyCnt - b.mu.RUnlock() - if skip || !bad { - return true - } - - // prevent isolated member's endpoint from being infinitely retried, as follows: - // 1. keepalive pings detects GoAway with http2.ErrCodeEnhanceYourCalm - // 2. balancer 'Up' unpins with grpc: failed with network I/O error - // 3. grpc-healthcheck still SERVING, thus retry to pin - // instead, return before grpc-healthcheck if failed within healthcheck timeout - if elapsed := time.Since(failedTime); elapsed < b.healthCheckTimeout { - logger.Lvl(4).Infof("clientv3/balancer: %q is up but not pinned (failed %v ago, require minimum %v after failure)", addr.Addr, elapsed, b.healthCheckTimeout) - return false - } - - if ok, _ := b.healthCheck(addr.Addr); ok { - b.removeUnhealthy(addr.Addr, "health check success") - return true - } - - b.hostPortError(addr.Addr, errors.New("health check failed")) - return false -} - -func (b *healthBalancer) Get(ctx context.Context, opts grpc.BalancerGetOptions) (grpc.Address, func(), error) { - var ( - addr string - closed bool - ) - - // If opts.BlockingWait is false (for fail-fast RPCs), it should return - // an address it has notified via Notify immediately instead of blocking. - if !opts.BlockingWait { - b.mu.RLock() - closed = b.closed - addr = b.pinAddr - b.mu.RUnlock() - if closed { - return grpc.Address{Addr: ""}, nil, grpc.ErrClientConnClosing - } - if addr == "" { - return grpc.Address{Addr: ""}, nil, ErrNoAddrAvilable - } - return grpc.Address{Addr: addr}, func() {}, nil - } - - for { - b.mu.RLock() - ch := b.upc - b.mu.RUnlock() - select { - case <-ch: - case <-b.donec: - return grpc.Address{Addr: ""}, nil, grpc.ErrClientConnClosing - case <-ctx.Done(): - return grpc.Address{Addr: ""}, nil, ctx.Err() - } - b.mu.RLock() - closed = b.closed - addr = b.pinAddr - b.mu.RUnlock() - // Close() which sets b.closed = true can be called before Get(), Get() must exit if balancer is closed. - if closed { - return grpc.Address{Addr: ""}, nil, grpc.ErrClientConnClosing - } - if addr != "" { - break - } - } - return grpc.Address{Addr: addr}, func() {}, nil -} - -func (b *healthBalancer) Notify() <-chan []grpc.Address { return b.notifyCh } - -func (b *healthBalancer) Close() error { - b.mu.Lock() - // In case gRPC calls close twice. TODO: remove the checking - // when we are sure that gRPC wont call close twice. - if b.closed { - b.mu.Unlock() - <-b.donec - return nil - } - b.closed = true - b.stopOnce.Do(func() { close(b.stopc) }) - b.pinAddr = "" - - // In the case of following scenario: - // 1. upc is not closed; no pinned address - // 2. client issues an RPC, calling invoke(), which calls Get(), enters for loop, blocks - // 3. client.conn.Close() calls balancer.Close(); closed = true - // 4. for loop in Get() never exits since ctx is the context passed in by the client and may not be canceled - // we must close upc so Get() exits from blocking on upc - select { - case <-b.upc: - default: - // terminate all waiting Get()s - close(b.upc) - } - - b.mu.Unlock() - b.wg.Wait() - - // wait for updateNotifyLoop to finish - <-b.donec - close(b.notifyCh) - - return nil -} - -func grpcHealthCheck(client *Client, ep string) (bool, error) { - conn, err := client.dial(ep) - if err != nil { - return false, err - } - defer conn.Close() - cli := healthpb.NewHealthClient(conn) - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - resp, err := cli.Check(ctx, &healthpb.HealthCheckRequest{}) - cancel() - if err != nil { - if s, ok := status.FromError(err); ok && s.Code() == codes.Unavailable { - if s.Message() == unknownService { // etcd < v3.3.0 - return true, nil - } - } - return false, err - } - return resp.Status == healthpb.HealthCheckResponse_SERVING, nil -} - -func hasAddr(addrs []grpc.Address, targetAddr string) bool { - for _, addr := range addrs { - if targetAddr == addr.Addr { - return true - } - } - return false -} - -func getHost(ep string) string { - url, uerr := url.Parse(ep) - if uerr != nil || !strings.Contains(ep, "://") { - return ep - } - return url.Host -} - -func eps2addrs(eps []string) []grpc.Address { - addrs := make([]grpc.Address, len(eps)) - for i := range eps { - addrs[i].Addr = getHost(eps[i]) - } - return addrs -} - -func getHostPort2ep(eps []string) map[string]string { - hm := make(map[string]string, len(eps)) - for i := range eps { - _, host, _ := parseEndpoint(eps[i]) - hm[host] = eps[i] - } - return hm -} diff --git a/vendor/github.com/coreos/etcd/clientv3/kv.go b/vendor/github.com/coreos/etcd/clientv3/kv.go deleted file mode 100644 index 5a7469bd4c91..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/kv.go +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" -) - -type ( - CompactResponse pb.CompactionResponse - PutResponse pb.PutResponse - GetResponse pb.RangeResponse - DeleteResponse pb.DeleteRangeResponse - TxnResponse pb.TxnResponse -) - -type KV interface { - // Put puts a key-value pair into etcd. - // Note that key,value can be plain bytes array and string is - // an immutable representation of that bytes array. - // To get a string of bytes, do string([]byte{0x10, 0x20}). - Put(ctx context.Context, key, val string, opts ...OpOption) (*PutResponse, error) - - // Get retrieves keys. - // By default, Get will return the value for "key", if any. - // When passed WithRange(end), Get will return the keys in the range [key, end). - // When passed WithFromKey(), Get returns keys greater than or equal to key. - // When passed WithRev(rev) with rev > 0, Get retrieves keys at the given revision; - // if the required revision is compacted, the request will fail with ErrCompacted . - // When passed WithLimit(limit), the number of returned keys is bounded by limit. - // When passed WithSort(), the keys will be sorted. - Get(ctx context.Context, key string, opts ...OpOption) (*GetResponse, error) - - // Delete deletes a key, or optionally using WithRange(end), [key, end). - Delete(ctx context.Context, key string, opts ...OpOption) (*DeleteResponse, error) - - // Compact compacts etcd KV history before the given rev. - Compact(ctx context.Context, rev int64, opts ...CompactOption) (*CompactResponse, error) - - // Do applies a single Op on KV without a transaction. - // Do is useful when creating arbitrary operations to be issued at a - // later time; the user can range over the operations, calling Do to - // execute them. Get/Put/Delete, on the other hand, are best suited - // for when the operation should be issued at the time of declaration. - Do(ctx context.Context, op Op) (OpResponse, error) - - // Txn creates a transaction. - Txn(ctx context.Context) Txn -} - -type OpResponse struct { - put *PutResponse - get *GetResponse - del *DeleteResponse - txn *TxnResponse -} - -func (op OpResponse) Put() *PutResponse { return op.put } -func (op OpResponse) Get() *GetResponse { return op.get } -func (op OpResponse) Del() *DeleteResponse { return op.del } -func (op OpResponse) Txn() *TxnResponse { return op.txn } - -func (resp *PutResponse) OpResponse() OpResponse { - return OpResponse{put: resp} -} -func (resp *GetResponse) OpResponse() OpResponse { - return OpResponse{get: resp} -} -func (resp *DeleteResponse) OpResponse() OpResponse { - return OpResponse{del: resp} -} -func (resp *TxnResponse) OpResponse() OpResponse { - return OpResponse{txn: resp} -} - -type kv struct { - remote pb.KVClient - callOpts []grpc.CallOption -} - -func NewKV(c *Client) KV { - api := &kv{remote: RetryKVClient(c)} - if c != nil { - api.callOpts = c.callOpts - } - return api -} - -func NewKVFromKVClient(remote pb.KVClient, c *Client) KV { - api := &kv{remote: remote} - if c != nil { - api.callOpts = c.callOpts - } - return api -} - -func (kv *kv) Put(ctx context.Context, key, val string, opts ...OpOption) (*PutResponse, error) { - r, err := kv.Do(ctx, OpPut(key, val, opts...)) - return r.put, toErr(ctx, err) -} - -func (kv *kv) Get(ctx context.Context, key string, opts ...OpOption) (*GetResponse, error) { - r, err := kv.Do(ctx, OpGet(key, opts...)) - return r.get, toErr(ctx, err) -} - -func (kv *kv) Delete(ctx context.Context, key string, opts ...OpOption) (*DeleteResponse, error) { - r, err := kv.Do(ctx, OpDelete(key, opts...)) - return r.del, toErr(ctx, err) -} - -func (kv *kv) Compact(ctx context.Context, rev int64, opts ...CompactOption) (*CompactResponse, error) { - resp, err := kv.remote.Compact(ctx, OpCompact(rev, opts...).toRequest(), kv.callOpts...) - if err != nil { - return nil, toErr(ctx, err) - } - return (*CompactResponse)(resp), err -} - -func (kv *kv) Txn(ctx context.Context) Txn { - return &txn{ - kv: kv, - ctx: ctx, - callOpts: kv.callOpts, - } -} - -func (kv *kv) Do(ctx context.Context, op Op) (OpResponse, error) { - var err error - switch op.t { - case tRange: - var resp *pb.RangeResponse - resp, err = kv.remote.Range(ctx, op.toRangeRequest(), kv.callOpts...) - if err == nil { - return OpResponse{get: (*GetResponse)(resp)}, nil - } - case tPut: - var resp *pb.PutResponse - r := &pb.PutRequest{Key: op.key, Value: op.val, Lease: int64(op.leaseID), PrevKv: op.prevKV, IgnoreValue: op.ignoreValue, IgnoreLease: op.ignoreLease} - resp, err = kv.remote.Put(ctx, r, kv.callOpts...) - if err == nil { - return OpResponse{put: (*PutResponse)(resp)}, nil - } - case tDeleteRange: - var resp *pb.DeleteRangeResponse - r := &pb.DeleteRangeRequest{Key: op.key, RangeEnd: op.end, PrevKv: op.prevKV} - resp, err = kv.remote.DeleteRange(ctx, r, kv.callOpts...) - if err == nil { - return OpResponse{del: (*DeleteResponse)(resp)}, nil - } - case tTxn: - var resp *pb.TxnResponse - resp, err = kv.remote.Txn(ctx, op.toTxnRequest(), kv.callOpts...) - if err == nil { - return OpResponse{txn: (*TxnResponse)(resp)}, nil - } - default: - panic("Unknown op") - } - return OpResponse{}, toErr(ctx, err) -} diff --git a/vendor/github.com/coreos/etcd/clientv3/lease.go b/vendor/github.com/coreos/etcd/clientv3/lease.go deleted file mode 100644 index 3729cf37be04..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/lease.go +++ /dev/null @@ -1,588 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - "sync" - "time" - - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" - "google.golang.org/grpc/metadata" -) - -type ( - LeaseRevokeResponse pb.LeaseRevokeResponse - LeaseID int64 -) - -// LeaseGrantResponse wraps the protobuf message LeaseGrantResponse. -type LeaseGrantResponse struct { - *pb.ResponseHeader - ID LeaseID - TTL int64 - Error string -} - -// LeaseKeepAliveResponse wraps the protobuf message LeaseKeepAliveResponse. -type LeaseKeepAliveResponse struct { - *pb.ResponseHeader - ID LeaseID - TTL int64 -} - -// LeaseTimeToLiveResponse wraps the protobuf message LeaseTimeToLiveResponse. -type LeaseTimeToLiveResponse struct { - *pb.ResponseHeader - ID LeaseID `json:"id"` - - // TTL is the remaining TTL in seconds for the lease; the lease will expire in under TTL+1 seconds. Expired lease will return -1. - TTL int64 `json:"ttl"` - - // GrantedTTL is the initial granted time in seconds upon lease creation/renewal. - GrantedTTL int64 `json:"granted-ttl"` - - // Keys is the list of keys attached to this lease. - Keys [][]byte `json:"keys"` -} - -// LeaseStatus represents a lease status. -type LeaseStatus struct { - ID LeaseID `json:"id"` - // TODO: TTL int64 -} - -// LeaseLeasesResponse wraps the protobuf message LeaseLeasesResponse. -type LeaseLeasesResponse struct { - *pb.ResponseHeader - Leases []LeaseStatus `json:"leases"` -} - -const ( - // defaultTTL is the assumed lease TTL used for the first keepalive - // deadline before the actual TTL is known to the client. - defaultTTL = 5 * time.Second - // NoLease is a lease ID for the absence of a lease. - NoLease LeaseID = 0 - - // retryConnWait is how long to wait before retrying request due to an error - retryConnWait = 500 * time.Millisecond -) - -// LeaseResponseChSize is the size of buffer to store unsent lease responses. -// WARNING: DO NOT UPDATE. -// Only for testing purposes. -var LeaseResponseChSize = 16 - -// ErrKeepAliveHalted is returned if client keep alive loop halts with an unexpected error. -// -// This usually means that automatic lease renewal via KeepAlive is broken, but KeepAliveOnce will still work as expected. -type ErrKeepAliveHalted struct { - Reason error -} - -func (e ErrKeepAliveHalted) Error() string { - s := "etcdclient: leases keep alive halted" - if e.Reason != nil { - s += ": " + e.Reason.Error() - } - return s -} - -type Lease interface { - // Grant creates a new lease. - Grant(ctx context.Context, ttl int64) (*LeaseGrantResponse, error) - - // Revoke revokes the given lease. - Revoke(ctx context.Context, id LeaseID) (*LeaseRevokeResponse, error) - - // TimeToLive retrieves the lease information of the given lease ID. - TimeToLive(ctx context.Context, id LeaseID, opts ...LeaseOption) (*LeaseTimeToLiveResponse, error) - - // Leases retrieves all leases. - Leases(ctx context.Context) (*LeaseLeasesResponse, error) - - // KeepAlive keeps the given lease alive forever. If the keepalive response - // posted to the channel is not consumed immediately, the lease client will - // continue sending keep alive requests to the etcd server at least every - // second until latest response is consumed. - // - // The returned "LeaseKeepAliveResponse" channel closes if underlying keep - // alive stream is interrupted in some way the client cannot handle itself; - // given context "ctx" is canceled or timed out. "LeaseKeepAliveResponse" - // from this closed channel is nil. - // - // If client keep alive loop halts with an unexpected error (e.g. "etcdserver: - // no leader") or canceled by the caller (e.g. context.Canceled), the error - // is returned. Otherwise, it retries. - // - // TODO(v4.0): post errors to last keep alive message before closing - // (see https://github.com/coreos/etcd/pull/7866) - KeepAlive(ctx context.Context, id LeaseID) (<-chan *LeaseKeepAliveResponse, error) - - // KeepAliveOnce renews the lease once. The response corresponds to the - // first message from calling KeepAlive. If the response has a recoverable - // error, KeepAliveOnce will retry the RPC with a new keep alive message. - // - // In most of the cases, Keepalive should be used instead of KeepAliveOnce. - KeepAliveOnce(ctx context.Context, id LeaseID) (*LeaseKeepAliveResponse, error) - - // Close releases all resources Lease keeps for efficient communication - // with the etcd server. - Close() error -} - -type lessor struct { - mu sync.Mutex // guards all fields - - // donec is closed and loopErr is set when recvKeepAliveLoop stops - donec chan struct{} - loopErr error - - remote pb.LeaseClient - - stream pb.Lease_LeaseKeepAliveClient - streamCancel context.CancelFunc - - stopCtx context.Context - stopCancel context.CancelFunc - - keepAlives map[LeaseID]*keepAlive - - // firstKeepAliveTimeout is the timeout for the first keepalive request - // before the actual TTL is known to the lease client - firstKeepAliveTimeout time.Duration - - // firstKeepAliveOnce ensures stream starts after first KeepAlive call. - firstKeepAliveOnce sync.Once - - callOpts []grpc.CallOption -} - -// keepAlive multiplexes a keepalive for a lease over multiple channels -type keepAlive struct { - chs []chan<- *LeaseKeepAliveResponse - ctxs []context.Context - // deadline is the time the keep alive channels close if no response - deadline time.Time - // nextKeepAlive is when to send the next keep alive message - nextKeepAlive time.Time - // donec is closed on lease revoke, expiration, or cancel. - donec chan struct{} -} - -func NewLease(c *Client) Lease { - return NewLeaseFromLeaseClient(RetryLeaseClient(c), c, c.cfg.DialTimeout+time.Second) -} - -func NewLeaseFromLeaseClient(remote pb.LeaseClient, c *Client, keepAliveTimeout time.Duration) Lease { - l := &lessor{ - donec: make(chan struct{}), - keepAlives: make(map[LeaseID]*keepAlive), - remote: remote, - firstKeepAliveTimeout: keepAliveTimeout, - } - if l.firstKeepAliveTimeout == time.Second { - l.firstKeepAliveTimeout = defaultTTL - } - if c != nil { - l.callOpts = c.callOpts - } - reqLeaderCtx := WithRequireLeader(context.Background()) - l.stopCtx, l.stopCancel = context.WithCancel(reqLeaderCtx) - return l -} - -func (l *lessor) Grant(ctx context.Context, ttl int64) (*LeaseGrantResponse, error) { - r := &pb.LeaseGrantRequest{TTL: ttl} - resp, err := l.remote.LeaseGrant(ctx, r, l.callOpts...) - if err == nil { - gresp := &LeaseGrantResponse{ - ResponseHeader: resp.GetHeader(), - ID: LeaseID(resp.ID), - TTL: resp.TTL, - Error: resp.Error, - } - return gresp, nil - } - return nil, toErr(ctx, err) -} - -func (l *lessor) Revoke(ctx context.Context, id LeaseID) (*LeaseRevokeResponse, error) { - r := &pb.LeaseRevokeRequest{ID: int64(id)} - resp, err := l.remote.LeaseRevoke(ctx, r, l.callOpts...) - if err == nil { - return (*LeaseRevokeResponse)(resp), nil - } - return nil, toErr(ctx, err) -} - -func (l *lessor) TimeToLive(ctx context.Context, id LeaseID, opts ...LeaseOption) (*LeaseTimeToLiveResponse, error) { - r := toLeaseTimeToLiveRequest(id, opts...) - resp, err := l.remote.LeaseTimeToLive(ctx, r, l.callOpts...) - if err == nil { - gresp := &LeaseTimeToLiveResponse{ - ResponseHeader: resp.GetHeader(), - ID: LeaseID(resp.ID), - TTL: resp.TTL, - GrantedTTL: resp.GrantedTTL, - Keys: resp.Keys, - } - return gresp, nil - } - return nil, toErr(ctx, err) -} - -func (l *lessor) Leases(ctx context.Context) (*LeaseLeasesResponse, error) { - resp, err := l.remote.LeaseLeases(ctx, &pb.LeaseLeasesRequest{}, l.callOpts...) - if err == nil { - leases := make([]LeaseStatus, len(resp.Leases)) - for i := range resp.Leases { - leases[i] = LeaseStatus{ID: LeaseID(resp.Leases[i].ID)} - } - return &LeaseLeasesResponse{ResponseHeader: resp.GetHeader(), Leases: leases}, nil - } - return nil, toErr(ctx, err) -} - -func (l *lessor) KeepAlive(ctx context.Context, id LeaseID) (<-chan *LeaseKeepAliveResponse, error) { - ch := make(chan *LeaseKeepAliveResponse, LeaseResponseChSize) - - l.mu.Lock() - // ensure that recvKeepAliveLoop is still running - select { - case <-l.donec: - err := l.loopErr - l.mu.Unlock() - close(ch) - return ch, ErrKeepAliveHalted{Reason: err} - default: - } - ka, ok := l.keepAlives[id] - if !ok { - // create fresh keep alive - ka = &keepAlive{ - chs: []chan<- *LeaseKeepAliveResponse{ch}, - ctxs: []context.Context{ctx}, - deadline: time.Now().Add(l.firstKeepAliveTimeout), - nextKeepAlive: time.Now(), - donec: make(chan struct{}), - } - l.keepAlives[id] = ka - } else { - // add channel and context to existing keep alive - ka.ctxs = append(ka.ctxs, ctx) - ka.chs = append(ka.chs, ch) - } - l.mu.Unlock() - - go l.keepAliveCtxCloser(id, ctx, ka.donec) - l.firstKeepAliveOnce.Do(func() { - go l.recvKeepAliveLoop() - go l.deadlineLoop() - }) - - return ch, nil -} - -func (l *lessor) KeepAliveOnce(ctx context.Context, id LeaseID) (*LeaseKeepAliveResponse, error) { - for { - resp, err := l.keepAliveOnce(ctx, id) - if err == nil { - if resp.TTL <= 0 { - err = rpctypes.ErrLeaseNotFound - } - return resp, err - } - if isHaltErr(ctx, err) { - return nil, toErr(ctx, err) - } - } -} - -func (l *lessor) Close() error { - l.stopCancel() - // close for synchronous teardown if stream goroutines never launched - l.firstKeepAliveOnce.Do(func() { close(l.donec) }) - <-l.donec - return nil -} - -func (l *lessor) keepAliveCtxCloser(id LeaseID, ctx context.Context, donec <-chan struct{}) { - select { - case <-donec: - return - case <-l.donec: - return - case <-ctx.Done(): - } - - l.mu.Lock() - defer l.mu.Unlock() - - ka, ok := l.keepAlives[id] - if !ok { - return - } - - // close channel and remove context if still associated with keep alive - for i, c := range ka.ctxs { - if c == ctx { - close(ka.chs[i]) - ka.ctxs = append(ka.ctxs[:i], ka.ctxs[i+1:]...) - ka.chs = append(ka.chs[:i], ka.chs[i+1:]...) - break - } - } - // remove if no one more listeners - if len(ka.chs) == 0 { - delete(l.keepAlives, id) - } -} - -// closeRequireLeader scans keepAlives for ctxs that have require leader -// and closes the associated channels. -func (l *lessor) closeRequireLeader() { - l.mu.Lock() - defer l.mu.Unlock() - for _, ka := range l.keepAlives { - reqIdxs := 0 - // find all required leader channels, close, mark as nil - for i, ctx := range ka.ctxs { - md, ok := metadata.FromOutgoingContext(ctx) - if !ok { - continue - } - ks := md[rpctypes.MetadataRequireLeaderKey] - if len(ks) < 1 || ks[0] != rpctypes.MetadataHasLeader { - continue - } - close(ka.chs[i]) - ka.chs[i] = nil - reqIdxs++ - } - if reqIdxs == 0 { - continue - } - // remove all channels that required a leader from keepalive - newChs := make([]chan<- *LeaseKeepAliveResponse, len(ka.chs)-reqIdxs) - newCtxs := make([]context.Context, len(newChs)) - newIdx := 0 - for i := range ka.chs { - if ka.chs[i] == nil { - continue - } - newChs[newIdx], newCtxs[newIdx] = ka.chs[i], ka.ctxs[newIdx] - newIdx++ - } - ka.chs, ka.ctxs = newChs, newCtxs - } -} - -func (l *lessor) keepAliveOnce(ctx context.Context, id LeaseID) (*LeaseKeepAliveResponse, error) { - cctx, cancel := context.WithCancel(ctx) - defer cancel() - - stream, err := l.remote.LeaseKeepAlive(cctx, l.callOpts...) - if err != nil { - return nil, toErr(ctx, err) - } - - err = stream.Send(&pb.LeaseKeepAliveRequest{ID: int64(id)}) - if err != nil { - return nil, toErr(ctx, err) - } - - resp, rerr := stream.Recv() - if rerr != nil { - return nil, toErr(ctx, rerr) - } - - karesp := &LeaseKeepAliveResponse{ - ResponseHeader: resp.GetHeader(), - ID: LeaseID(resp.ID), - TTL: resp.TTL, - } - return karesp, nil -} - -func (l *lessor) recvKeepAliveLoop() (gerr error) { - defer func() { - l.mu.Lock() - close(l.donec) - l.loopErr = gerr - for _, ka := range l.keepAlives { - ka.close() - } - l.keepAlives = make(map[LeaseID]*keepAlive) - l.mu.Unlock() - }() - - for { - stream, err := l.resetRecv() - if err != nil { - if canceledByCaller(l.stopCtx, err) { - return err - } - } else { - for { - resp, err := stream.Recv() - if err != nil { - if canceledByCaller(l.stopCtx, err) { - return err - } - - if toErr(l.stopCtx, err) == rpctypes.ErrNoLeader { - l.closeRequireLeader() - } - break - } - - l.recvKeepAlive(resp) - } - } - - select { - case <-time.After(retryConnWait): - continue - case <-l.stopCtx.Done(): - return l.stopCtx.Err() - } - } -} - -// resetRecv opens a new lease stream and starts sending keep alive requests. -func (l *lessor) resetRecv() (pb.Lease_LeaseKeepAliveClient, error) { - sctx, cancel := context.WithCancel(l.stopCtx) - stream, err := l.remote.LeaseKeepAlive(sctx, l.callOpts...) - if err != nil { - cancel() - return nil, err - } - - l.mu.Lock() - defer l.mu.Unlock() - if l.stream != nil && l.streamCancel != nil { - l.streamCancel() - } - - l.streamCancel = cancel - l.stream = stream - - go l.sendKeepAliveLoop(stream) - return stream, nil -} - -// recvKeepAlive updates a lease based on its LeaseKeepAliveResponse -func (l *lessor) recvKeepAlive(resp *pb.LeaseKeepAliveResponse) { - karesp := &LeaseKeepAliveResponse{ - ResponseHeader: resp.GetHeader(), - ID: LeaseID(resp.ID), - TTL: resp.TTL, - } - - l.mu.Lock() - defer l.mu.Unlock() - - ka, ok := l.keepAlives[karesp.ID] - if !ok { - return - } - - if karesp.TTL <= 0 { - // lease expired; close all keep alive channels - delete(l.keepAlives, karesp.ID) - ka.close() - return - } - - // send update to all channels - nextKeepAlive := time.Now().Add((time.Duration(karesp.TTL) * time.Second) / 3.0) - ka.deadline = time.Now().Add(time.Duration(karesp.TTL) * time.Second) - for _, ch := range ka.chs { - select { - case ch <- karesp: - default: - } - // still advance in order to rate-limit keep-alive sends - ka.nextKeepAlive = nextKeepAlive - } -} - -// deadlineLoop reaps any keep alive channels that have not received a response -// within the lease TTL -func (l *lessor) deadlineLoop() { - for { - select { - case <-time.After(time.Second): - case <-l.donec: - return - } - now := time.Now() - l.mu.Lock() - for id, ka := range l.keepAlives { - if ka.deadline.Before(now) { - // waited too long for response; lease may be expired - ka.close() - delete(l.keepAlives, id) - } - } - l.mu.Unlock() - } -} - -// sendKeepAliveLoop sends keep alive requests for the lifetime of the given stream. -func (l *lessor) sendKeepAliveLoop(stream pb.Lease_LeaseKeepAliveClient) { - for { - var tosend []LeaseID - - now := time.Now() - l.mu.Lock() - for id, ka := range l.keepAlives { - if ka.nextKeepAlive.Before(now) { - tosend = append(tosend, id) - } - } - l.mu.Unlock() - - for _, id := range tosend { - r := &pb.LeaseKeepAliveRequest{ID: int64(id)} - if err := stream.Send(r); err != nil { - // TODO do something with this error? - return - } - } - - select { - case <-time.After(500 * time.Millisecond): - case <-stream.Context().Done(): - return - case <-l.donec: - return - case <-l.stopCtx.Done(): - return - } - } -} - -func (ka *keepAlive) close() { - close(ka.donec) - for _, ch := range ka.chs { - close(ch) - } -} diff --git a/vendor/github.com/coreos/etcd/clientv3/leasing/cache.go b/vendor/github.com/coreos/etcd/clientv3/leasing/cache.go deleted file mode 100644 index 6903a785c789..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/leasing/cache.go +++ /dev/null @@ -1,306 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package leasing - -import ( - "context" - "strings" - "sync" - "time" - - v3 "github.com/coreos/etcd/clientv3" - v3pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -const revokeBackoff = 2 * time.Second - -type leaseCache struct { - mu sync.RWMutex - entries map[string]*leaseKey - revokes map[string]time.Time - header *v3pb.ResponseHeader -} - -type leaseKey struct { - response *v3.GetResponse - // rev is the leasing key revision. - rev int64 - waitc chan struct{} -} - -func (lc *leaseCache) Rev(key string) int64 { - lc.mu.RLock() - defer lc.mu.RUnlock() - if li := lc.entries[key]; li != nil { - return li.rev - } - return 0 -} - -func (lc *leaseCache) Lock(key string) (chan<- struct{}, int64) { - lc.mu.Lock() - defer lc.mu.Unlock() - if li := lc.entries[key]; li != nil { - li.waitc = make(chan struct{}) - return li.waitc, li.rev - } - return nil, 0 -} - -func (lc *leaseCache) LockRange(begin, end string) (ret []chan<- struct{}) { - lc.mu.Lock() - defer lc.mu.Unlock() - for k, li := range lc.entries { - if inRange(k, begin, end) { - li.waitc = make(chan struct{}) - ret = append(ret, li.waitc) - } - } - return ret -} - -func inRange(k, begin, end string) bool { - if strings.Compare(k, begin) < 0 { - return false - } - if end != "\x00" && strings.Compare(k, end) >= 0 { - return false - } - return true -} - -func (lc *leaseCache) LockWriteOps(ops []v3.Op) (ret []chan<- struct{}) { - for _, op := range ops { - if op.IsGet() { - continue - } - key := string(op.KeyBytes()) - if end := string(op.RangeBytes()); end == "" { - if wc, _ := lc.Lock(key); wc != nil { - ret = append(ret, wc) - } - } else { - for k := range lc.entries { - if !inRange(k, key, end) { - continue - } - if wc, _ := lc.Lock(k); wc != nil { - ret = append(ret, wc) - } - } - } - } - return ret -} - -func (lc *leaseCache) NotifyOps(ops []v3.Op) (wcs []<-chan struct{}) { - for _, op := range ops { - if op.IsGet() { - if _, wc := lc.notify(string(op.KeyBytes())); wc != nil { - wcs = append(wcs, wc) - } - } - } - return wcs -} - -func (lc *leaseCache) MayAcquire(key string) bool { - lc.mu.RLock() - lr, ok := lc.revokes[key] - lc.mu.RUnlock() - return !ok || time.Since(lr) > revokeBackoff -} - -func (lc *leaseCache) Add(key string, resp *v3.GetResponse, op v3.Op) *v3.GetResponse { - lk := &leaseKey{resp, resp.Header.Revision, closedCh} - lc.mu.Lock() - if lc.header == nil || lc.header.Revision < resp.Header.Revision { - lc.header = resp.Header - } - lc.entries[key] = lk - ret := lk.get(op) - lc.mu.Unlock() - return ret -} - -func (lc *leaseCache) Update(key, val []byte, respHeader *v3pb.ResponseHeader) { - li := lc.entries[string(key)] - if li == nil { - return - } - cacheResp := li.response - if len(cacheResp.Kvs) == 0 { - kv := &mvccpb.KeyValue{ - Key: key, - CreateRevision: respHeader.Revision, - } - cacheResp.Kvs = append(cacheResp.Kvs, kv) - cacheResp.Count = 1 - } - cacheResp.Kvs[0].Version++ - if cacheResp.Kvs[0].ModRevision < respHeader.Revision { - cacheResp.Header = respHeader - cacheResp.Kvs[0].ModRevision = respHeader.Revision - cacheResp.Kvs[0].Value = val - } -} - -func (lc *leaseCache) Delete(key string, hdr *v3pb.ResponseHeader) { - lc.mu.Lock() - defer lc.mu.Unlock() - lc.delete(key, hdr) -} - -func (lc *leaseCache) delete(key string, hdr *v3pb.ResponseHeader) { - if li := lc.entries[key]; li != nil && hdr.Revision >= li.response.Header.Revision { - li.response.Kvs = nil - li.response.Header = copyHeader(hdr) - } -} - -func (lc *leaseCache) Evict(key string) (rev int64) { - lc.mu.Lock() - defer lc.mu.Unlock() - if li := lc.entries[key]; li != nil { - rev = li.rev - delete(lc.entries, key) - lc.revokes[key] = time.Now() - } - return rev -} - -func (lc *leaseCache) EvictRange(key, end string) { - lc.mu.Lock() - defer lc.mu.Unlock() - for k := range lc.entries { - if inRange(k, key, end) { - delete(lc.entries, key) - lc.revokes[key] = time.Now() - } - } -} - -func isBadOp(op v3.Op) bool { return op.Rev() > 0 || len(op.RangeBytes()) > 0 } - -func (lc *leaseCache) Get(ctx context.Context, op v3.Op) (*v3.GetResponse, bool) { - if isBadOp(op) { - return nil, false - } - key := string(op.KeyBytes()) - li, wc := lc.notify(key) - if li == nil { - return nil, true - } - select { - case <-wc: - case <-ctx.Done(): - return nil, true - } - lc.mu.RLock() - lk := *li - ret := lk.get(op) - lc.mu.RUnlock() - return ret, true -} - -func (lk *leaseKey) get(op v3.Op) *v3.GetResponse { - ret := *lk.response - ret.Header = copyHeader(ret.Header) - empty := len(ret.Kvs) == 0 || op.IsCountOnly() - empty = empty || (op.MinModRev() > ret.Kvs[0].ModRevision) - empty = empty || (op.MaxModRev() != 0 && op.MaxModRev() < ret.Kvs[0].ModRevision) - empty = empty || (op.MinCreateRev() > ret.Kvs[0].CreateRevision) - empty = empty || (op.MaxCreateRev() != 0 && op.MaxCreateRev() < ret.Kvs[0].CreateRevision) - if empty { - ret.Kvs = nil - } else { - kv := *ret.Kvs[0] - kv.Key = make([]byte, len(kv.Key)) - copy(kv.Key, ret.Kvs[0].Key) - if !op.IsKeysOnly() { - kv.Value = make([]byte, len(kv.Value)) - copy(kv.Value, ret.Kvs[0].Value) - } - ret.Kvs = []*mvccpb.KeyValue{&kv} - } - return &ret -} - -func (lc *leaseCache) notify(key string) (*leaseKey, <-chan struct{}) { - lc.mu.RLock() - defer lc.mu.RUnlock() - if li := lc.entries[key]; li != nil { - return li, li.waitc - } - return nil, nil -} - -func (lc *leaseCache) clearOldRevokes(ctx context.Context) { - for { - select { - case <-ctx.Done(): - return - case <-time.After(time.Second): - lc.mu.Lock() - for k, lr := range lc.revokes { - if time.Now().Sub(lr.Add(revokeBackoff)) > 0 { - delete(lc.revokes, k) - } - } - lc.mu.Unlock() - } - } -} - -func (lc *leaseCache) evalCmp(cmps []v3.Cmp) (cmpVal bool, ok bool) { - for _, cmp := range cmps { - if len(cmp.RangeEnd) > 0 { - return false, false - } - lk := lc.entries[string(cmp.Key)] - if lk == nil { - return false, false - } - if !evalCmp(lk.response, cmp) { - return false, true - } - } - return true, true -} - -func (lc *leaseCache) evalOps(ops []v3.Op) ([]*v3pb.ResponseOp, bool) { - resps := make([]*v3pb.ResponseOp, len(ops)) - for i, op := range ops { - if !op.IsGet() || isBadOp(op) { - // TODO: support read-only Txn - return nil, false - } - lk := lc.entries[string(op.KeyBytes())] - if lk == nil { - return nil, false - } - resp := lk.get(op) - if resp == nil { - return nil, false - } - resps[i] = &v3pb.ResponseOp{ - Response: &v3pb.ResponseOp_ResponseRange{ - (*v3pb.RangeResponse)(resp), - }, - } - } - return resps, true -} diff --git a/vendor/github.com/coreos/etcd/clientv3/leasing/doc.go b/vendor/github.com/coreos/etcd/clientv3/leasing/doc.go deleted file mode 100644 index fc97fc882689..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/leasing/doc.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package leasing serves linearizable reads from a local cache by acquiring -// exclusive write access to keys through a client-side leasing protocol. This -// leasing layer can either directly wrap the etcd client or it can be exposed -// through the etcd grpc proxy server, granting multiple clients write access. -// -// First, create a leasing KV from a clientv3.Client 'cli': -// -// lkv, err := leasing.NewKV(cli, "leasing-prefix") -// if err != nil { -// // handle error -// } -// -// A range request for a key "abc" tries to acquire a leasing key so it can cache the range's -// key locally. On the server, the leasing key is stored to "leasing-prefix/abc": -// -// resp, err := lkv.Get(context.TODO(), "abc") -// -// Future linearized read requests using 'lkv' will be served locally for the lease's lifetime: -// -// resp, err = lkv.Get(context.TODO(), "abc") -// -// If another leasing client writes to a leased key, then the owner relinquishes its exclusive -// access, permitting the writer to modify the key: -// -// lkv2, err := leasing.NewKV(cli, "leasing-prefix") -// if err != nil { -// // handle error -// } -// lkv2.Put(context.TODO(), "abc", "456") -// resp, err = lkv.Get("abc") -// -package leasing diff --git a/vendor/github.com/coreos/etcd/clientv3/leasing/kv.go b/vendor/github.com/coreos/etcd/clientv3/leasing/kv.go deleted file mode 100644 index 5a5e2312b726..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/leasing/kv.go +++ /dev/null @@ -1,479 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package leasing - -import ( - "context" - "strings" - "sync" - "time" - - v3 "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/concurrency" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc/mvccpb" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -type leasingKV struct { - cl *v3.Client - kv v3.KV - pfx string - leases leaseCache - - ctx context.Context - cancel context.CancelFunc - wg sync.WaitGroup - - sessionOpts []concurrency.SessionOption - session *concurrency.Session - sessionc chan struct{} -} - -var closedCh chan struct{} - -func init() { - closedCh = make(chan struct{}) - close(closedCh) -} - -// NewKV wraps a KV instance so that all requests are wired through a leasing protocol. -func NewKV(cl *v3.Client, pfx string, opts ...concurrency.SessionOption) (v3.KV, func(), error) { - cctx, cancel := context.WithCancel(cl.Ctx()) - lkv := &leasingKV{ - cl: cl, - kv: cl.KV, - pfx: pfx, - leases: leaseCache{revokes: make(map[string]time.Time)}, - ctx: cctx, - cancel: cancel, - sessionOpts: opts, - sessionc: make(chan struct{}), - } - lkv.wg.Add(2) - go func() { - defer lkv.wg.Done() - lkv.monitorSession() - }() - go func() { - defer lkv.wg.Done() - lkv.leases.clearOldRevokes(cctx) - }() - return lkv, lkv.Close, lkv.waitSession(cctx) -} - -func (lkv *leasingKV) Close() { - lkv.cancel() - lkv.wg.Wait() -} - -func (lkv *leasingKV) Get(ctx context.Context, key string, opts ...v3.OpOption) (*v3.GetResponse, error) { - return lkv.get(ctx, v3.OpGet(key, opts...)) -} - -func (lkv *leasingKV) Put(ctx context.Context, key, val string, opts ...v3.OpOption) (*v3.PutResponse, error) { - return lkv.put(ctx, v3.OpPut(key, val, opts...)) -} - -func (lkv *leasingKV) Delete(ctx context.Context, key string, opts ...v3.OpOption) (*v3.DeleteResponse, error) { - return lkv.delete(ctx, v3.OpDelete(key, opts...)) -} - -func (lkv *leasingKV) Do(ctx context.Context, op v3.Op) (v3.OpResponse, error) { - switch { - case op.IsGet(): - resp, err := lkv.get(ctx, op) - return resp.OpResponse(), err - case op.IsPut(): - resp, err := lkv.put(ctx, op) - return resp.OpResponse(), err - case op.IsDelete(): - resp, err := lkv.delete(ctx, op) - return resp.OpResponse(), err - case op.IsTxn(): - cmps, thenOps, elseOps := op.Txn() - resp, err := lkv.Txn(ctx).If(cmps...).Then(thenOps...).Else(elseOps...).Commit() - return resp.OpResponse(), err - } - return v3.OpResponse{}, nil -} - -func (lkv *leasingKV) Compact(ctx context.Context, rev int64, opts ...v3.CompactOption) (*v3.CompactResponse, error) { - return lkv.kv.Compact(ctx, rev, opts...) -} - -func (lkv *leasingKV) Txn(ctx context.Context) v3.Txn { - return &txnLeasing{Txn: lkv.kv.Txn(ctx), lkv: lkv, ctx: ctx} -} - -func (lkv *leasingKV) monitorSession() { - for lkv.ctx.Err() == nil { - if lkv.session != nil { - select { - case <-lkv.session.Done(): - case <-lkv.ctx.Done(): - return - } - } - lkv.leases.mu.Lock() - select { - case <-lkv.sessionc: - lkv.sessionc = make(chan struct{}) - default: - } - lkv.leases.entries = make(map[string]*leaseKey) - lkv.leases.mu.Unlock() - - s, err := concurrency.NewSession(lkv.cl, lkv.sessionOpts...) - if err != nil { - continue - } - - lkv.leases.mu.Lock() - lkv.session = s - close(lkv.sessionc) - lkv.leases.mu.Unlock() - } -} - -func (lkv *leasingKV) monitorLease(ctx context.Context, key string, rev int64) { - cctx, cancel := context.WithCancel(lkv.ctx) - defer cancel() - for cctx.Err() == nil { - if rev == 0 { - resp, err := lkv.kv.Get(ctx, lkv.pfx+key) - if err != nil { - continue - } - rev = resp.Header.Revision - if len(resp.Kvs) == 0 || string(resp.Kvs[0].Value) == "REVOKE" { - lkv.rescind(cctx, key, rev) - return - } - } - wch := lkv.cl.Watch(cctx, lkv.pfx+key, v3.WithRev(rev+1)) - for resp := range wch { - for _, ev := range resp.Events { - if string(ev.Kv.Value) != "REVOKE" { - continue - } - if v3.LeaseID(ev.Kv.Lease) == lkv.leaseID() { - lkv.rescind(cctx, key, ev.Kv.ModRevision) - } - return - } - } - rev = 0 - } -} - -// rescind releases a lease from this client. -func (lkv *leasingKV) rescind(ctx context.Context, key string, rev int64) { - if lkv.leases.Evict(key) > rev { - return - } - cmp := v3.Compare(v3.CreateRevision(lkv.pfx+key), "<", rev) - op := v3.OpDelete(lkv.pfx + key) - for ctx.Err() == nil { - if _, err := lkv.kv.Txn(ctx).If(cmp).Then(op).Commit(); err == nil { - return - } - } -} - -func (lkv *leasingKV) waitRescind(ctx context.Context, key string, rev int64) error { - cctx, cancel := context.WithCancel(ctx) - defer cancel() - wch := lkv.cl.Watch(cctx, lkv.pfx+key, v3.WithRev(rev+1)) - for resp := range wch { - for _, ev := range resp.Events { - if ev.Type == v3.EventTypeDelete { - return ctx.Err() - } - } - } - return ctx.Err() -} - -func (lkv *leasingKV) tryModifyOp(ctx context.Context, op v3.Op) (*v3.TxnResponse, chan<- struct{}, error) { - key := string(op.KeyBytes()) - wc, rev := lkv.leases.Lock(key) - cmp := v3.Compare(v3.CreateRevision(lkv.pfx+key), "<", rev+1) - resp, err := lkv.kv.Txn(ctx).If(cmp).Then(op).Commit() - switch { - case err != nil: - lkv.leases.Evict(key) - fallthrough - case !resp.Succeeded: - if wc != nil { - close(wc) - } - return nil, nil, err - } - return resp, wc, nil -} - -func (lkv *leasingKV) put(ctx context.Context, op v3.Op) (pr *v3.PutResponse, err error) { - if err := lkv.waitSession(ctx); err != nil { - return nil, err - } - for ctx.Err() == nil { - resp, wc, err := lkv.tryModifyOp(ctx, op) - if err != nil || wc == nil { - resp, err = lkv.revoke(ctx, string(op.KeyBytes()), op) - } - if err != nil { - return nil, err - } - if resp.Succeeded { - lkv.leases.mu.Lock() - lkv.leases.Update(op.KeyBytes(), op.ValueBytes(), resp.Header) - lkv.leases.mu.Unlock() - pr = (*v3.PutResponse)(resp.Responses[0].GetResponsePut()) - pr.Header = resp.Header - } - if wc != nil { - close(wc) - } - if resp.Succeeded { - return pr, nil - } - } - return nil, ctx.Err() -} - -func (lkv *leasingKV) acquire(ctx context.Context, key string, op v3.Op) (*v3.TxnResponse, error) { - for ctx.Err() == nil { - if err := lkv.waitSession(ctx); err != nil { - return nil, err - } - lcmp := v3.Cmp{Key: []byte(key), Target: pb.Compare_LEASE} - resp, err := lkv.kv.Txn(ctx).If( - v3.Compare(v3.CreateRevision(lkv.pfx+key), "=", 0), - v3.Compare(lcmp, "=", 0)). - Then( - op, - v3.OpPut(lkv.pfx+key, "", v3.WithLease(lkv.leaseID()))). - Else( - op, - v3.OpGet(lkv.pfx+key), - ).Commit() - if err == nil { - if !resp.Succeeded { - kvs := resp.Responses[1].GetResponseRange().Kvs - // if txn failed since already owner, lease is acquired - resp.Succeeded = len(kvs) > 0 && v3.LeaseID(kvs[0].Lease) == lkv.leaseID() - } - return resp, nil - } - // retry if transient error - if _, ok := err.(rpctypes.EtcdError); ok { - return nil, err - } - if ev, _ := status.FromError(err); ev.Code() != codes.Unavailable { - return nil, err - } - } - return nil, ctx.Err() -} - -func (lkv *leasingKV) get(ctx context.Context, op v3.Op) (*v3.GetResponse, error) { - do := func() (*v3.GetResponse, error) { - r, err := lkv.kv.Do(ctx, op) - return r.Get(), err - } - if !lkv.readySession() { - return do() - } - - if resp, ok := lkv.leases.Get(ctx, op); resp != nil { - return resp, nil - } else if !ok || op.IsSerializable() { - // must be handled by server or can skip linearization - return do() - } - - key := string(op.KeyBytes()) - if !lkv.leases.MayAcquire(key) { - resp, err := lkv.kv.Do(ctx, op) - return resp.Get(), err - } - - resp, err := lkv.acquire(ctx, key, v3.OpGet(key)) - if err != nil { - return nil, err - } - getResp := (*v3.GetResponse)(resp.Responses[0].GetResponseRange()) - getResp.Header = resp.Header - if resp.Succeeded { - getResp = lkv.leases.Add(key, getResp, op) - lkv.wg.Add(1) - go func() { - defer lkv.wg.Done() - lkv.monitorLease(ctx, key, resp.Header.Revision) - }() - } - return getResp, nil -} - -func (lkv *leasingKV) deleteRangeRPC(ctx context.Context, maxLeaseRev int64, key, end string) (*v3.DeleteResponse, error) { - lkey, lend := lkv.pfx+key, lkv.pfx+end - resp, err := lkv.kv.Txn(ctx).If( - v3.Compare(v3.CreateRevision(lkey).WithRange(lend), "<", maxLeaseRev+1), - ).Then( - v3.OpGet(key, v3.WithRange(end), v3.WithKeysOnly()), - v3.OpDelete(key, v3.WithRange(end)), - ).Commit() - if err != nil { - lkv.leases.EvictRange(key, end) - return nil, err - } - if !resp.Succeeded { - return nil, nil - } - for _, kv := range resp.Responses[0].GetResponseRange().Kvs { - lkv.leases.Delete(string(kv.Key), resp.Header) - } - delResp := (*v3.DeleteResponse)(resp.Responses[1].GetResponseDeleteRange()) - delResp.Header = resp.Header - return delResp, nil -} - -func (lkv *leasingKV) deleteRange(ctx context.Context, op v3.Op) (*v3.DeleteResponse, error) { - key, end := string(op.KeyBytes()), string(op.RangeBytes()) - for ctx.Err() == nil { - maxLeaseRev, err := lkv.revokeRange(ctx, key, end) - if err != nil { - return nil, err - } - wcs := lkv.leases.LockRange(key, end) - delResp, err := lkv.deleteRangeRPC(ctx, maxLeaseRev, key, end) - closeAll(wcs) - if err != nil || delResp != nil { - return delResp, err - } - } - return nil, ctx.Err() -} - -func (lkv *leasingKV) delete(ctx context.Context, op v3.Op) (dr *v3.DeleteResponse, err error) { - if err := lkv.waitSession(ctx); err != nil { - return nil, err - } - if len(op.RangeBytes()) > 0 { - return lkv.deleteRange(ctx, op) - } - key := string(op.KeyBytes()) - for ctx.Err() == nil { - resp, wc, err := lkv.tryModifyOp(ctx, op) - if err != nil || wc == nil { - resp, err = lkv.revoke(ctx, key, op) - } - if err != nil { - // don't know if delete was processed - lkv.leases.Evict(key) - return nil, err - } - if resp.Succeeded { - dr = (*v3.DeleteResponse)(resp.Responses[0].GetResponseDeleteRange()) - dr.Header = resp.Header - lkv.leases.Delete(key, dr.Header) - } - if wc != nil { - close(wc) - } - if resp.Succeeded { - return dr, nil - } - } - return nil, ctx.Err() -} - -func (lkv *leasingKV) revoke(ctx context.Context, key string, op v3.Op) (*v3.TxnResponse, error) { - rev := lkv.leases.Rev(key) - txn := lkv.kv.Txn(ctx).If(v3.Compare(v3.CreateRevision(lkv.pfx+key), "<", rev+1)).Then(op) - resp, err := txn.Else(v3.OpPut(lkv.pfx+key, "REVOKE", v3.WithIgnoreLease())).Commit() - if err != nil || resp.Succeeded { - return resp, err - } - return resp, lkv.waitRescind(ctx, key, resp.Header.Revision) -} - -func (lkv *leasingKV) revokeRange(ctx context.Context, begin, end string) (int64, error) { - lkey, lend := lkv.pfx+begin, "" - if len(end) > 0 { - lend = lkv.pfx + end - } - leaseKeys, err := lkv.kv.Get(ctx, lkey, v3.WithRange(lend)) - if err != nil { - return 0, err - } - return lkv.revokeLeaseKvs(ctx, leaseKeys.Kvs) -} - -func (lkv *leasingKV) revokeLeaseKvs(ctx context.Context, kvs []*mvccpb.KeyValue) (int64, error) { - maxLeaseRev := int64(0) - for _, kv := range kvs { - if rev := kv.CreateRevision; rev > maxLeaseRev { - maxLeaseRev = rev - } - if v3.LeaseID(kv.Lease) == lkv.leaseID() { - // don't revoke own keys - continue - } - key := strings.TrimPrefix(string(kv.Key), lkv.pfx) - if _, err := lkv.revoke(ctx, key, v3.OpGet(key)); err != nil { - return 0, err - } - } - return maxLeaseRev, nil -} - -func (lkv *leasingKV) waitSession(ctx context.Context) error { - lkv.leases.mu.RLock() - sessionc := lkv.sessionc - lkv.leases.mu.RUnlock() - select { - case <-sessionc: - return nil - case <-lkv.ctx.Done(): - return lkv.ctx.Err() - case <-ctx.Done(): - return ctx.Err() - } -} - -func (lkv *leasingKV) readySession() bool { - lkv.leases.mu.RLock() - defer lkv.leases.mu.RUnlock() - if lkv.session == nil { - return false - } - select { - case <-lkv.session.Done(): - default: - return true - } - return false -} - -func (lkv *leasingKV) leaseID() v3.LeaseID { - lkv.leases.mu.RLock() - defer lkv.leases.mu.RUnlock() - return lkv.session.Lease() -} diff --git a/vendor/github.com/coreos/etcd/clientv3/leasing/txn.go b/vendor/github.com/coreos/etcd/clientv3/leasing/txn.go deleted file mode 100644 index da5b83a8abb9..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/leasing/txn.go +++ /dev/null @@ -1,223 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package leasing - -import ( - "context" - "strings" - - v3 "github.com/coreos/etcd/clientv3" - v3pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -type txnLeasing struct { - v3.Txn - lkv *leasingKV - ctx context.Context - cs []v3.Cmp - opst []v3.Op - opse []v3.Op -} - -func (txn *txnLeasing) If(cs ...v3.Cmp) v3.Txn { - txn.cs = append(txn.cs, cs...) - txn.Txn = txn.Txn.If(cs...) - return txn -} - -func (txn *txnLeasing) Then(ops ...v3.Op) v3.Txn { - txn.opst = append(txn.opst, ops...) - txn.Txn = txn.Txn.Then(ops...) - return txn -} - -func (txn *txnLeasing) Else(ops ...v3.Op) v3.Txn { - txn.opse = append(txn.opse, ops...) - txn.Txn = txn.Txn.Else(ops...) - return txn -} - -func (txn *txnLeasing) Commit() (*v3.TxnResponse, error) { - if resp, err := txn.eval(); resp != nil || err != nil { - return resp, err - } - return txn.serverTxn() -} - -func (txn *txnLeasing) eval() (*v3.TxnResponse, error) { - // TODO: wait on keys in comparisons - thenOps, elseOps := gatherOps(txn.opst), gatherOps(txn.opse) - ops := make([]v3.Op, 0, len(thenOps)+len(elseOps)) - ops = append(ops, thenOps...) - ops = append(ops, elseOps...) - - for _, ch := range txn.lkv.leases.NotifyOps(ops) { - select { - case <-ch: - case <-txn.ctx.Done(): - return nil, txn.ctx.Err() - } - } - - txn.lkv.leases.mu.RLock() - defer txn.lkv.leases.mu.RUnlock() - succeeded, ok := txn.lkv.leases.evalCmp(txn.cs) - if !ok || txn.lkv.leases.header == nil { - return nil, nil - } - if ops = txn.opst; !succeeded { - ops = txn.opse - } - - resps, ok := txn.lkv.leases.evalOps(ops) - if !ok { - return nil, nil - } - return &v3.TxnResponse{copyHeader(txn.lkv.leases.header), succeeded, resps}, nil -} - -// fallback computes the ops to fetch all possible conflicting -// leasing keys for a list of ops. -func (txn *txnLeasing) fallback(ops []v3.Op) (fbOps []v3.Op) { - for _, op := range ops { - if op.IsGet() { - continue - } - lkey, lend := txn.lkv.pfx+string(op.KeyBytes()), "" - if len(op.RangeBytes()) > 0 { - lend = txn.lkv.pfx + string(op.RangeBytes()) - } - fbOps = append(fbOps, v3.OpGet(lkey, v3.WithRange(lend))) - } - return fbOps -} - -func (txn *txnLeasing) guardKeys(ops []v3.Op) (cmps []v3.Cmp) { - seen := make(map[string]bool) - for _, op := range ops { - key := string(op.KeyBytes()) - if op.IsGet() || len(op.RangeBytes()) != 0 || seen[key] { - continue - } - rev := txn.lkv.leases.Rev(key) - cmps = append(cmps, v3.Compare(v3.CreateRevision(txn.lkv.pfx+key), "<", rev+1)) - seen[key] = true - } - return cmps -} - -func (txn *txnLeasing) guardRanges(ops []v3.Op) (cmps []v3.Cmp, err error) { - for _, op := range ops { - if op.IsGet() || len(op.RangeBytes()) == 0 { - continue - } - - key, end := string(op.KeyBytes()), string(op.RangeBytes()) - maxRevLK, err := txn.lkv.revokeRange(txn.ctx, key, end) - if err != nil { - return nil, err - } - - opts := append(v3.WithLastRev(), v3.WithRange(end)) - getResp, err := txn.lkv.kv.Get(txn.ctx, key, opts...) - if err != nil { - return nil, err - } - maxModRev := int64(0) - if len(getResp.Kvs) > 0 { - maxModRev = getResp.Kvs[0].ModRevision - } - - noKeyUpdate := v3.Compare(v3.ModRevision(key).WithRange(end), "<", maxModRev+1) - noLeaseUpdate := v3.Compare( - v3.CreateRevision(txn.lkv.pfx+key).WithRange(txn.lkv.pfx+end), - "<", - maxRevLK+1) - cmps = append(cmps, noKeyUpdate, noLeaseUpdate) - } - return cmps, nil -} - -func (txn *txnLeasing) guard(ops []v3.Op) ([]v3.Cmp, error) { - cmps := txn.guardKeys(ops) - rangeCmps, err := txn.guardRanges(ops) - return append(cmps, rangeCmps...), err -} - -func (txn *txnLeasing) commitToCache(txnResp *v3pb.TxnResponse, userTxn v3.Op) { - ops := gatherResponseOps(txnResp.Responses, []v3.Op{userTxn}) - txn.lkv.leases.mu.Lock() - for _, op := range ops { - key := string(op.KeyBytes()) - if op.IsDelete() && len(op.RangeBytes()) > 0 { - end := string(op.RangeBytes()) - for k := range txn.lkv.leases.entries { - if inRange(k, key, end) { - txn.lkv.leases.delete(k, txnResp.Header) - } - } - } else if op.IsDelete() { - txn.lkv.leases.delete(key, txnResp.Header) - } - if op.IsPut() { - txn.lkv.leases.Update(op.KeyBytes(), op.ValueBytes(), txnResp.Header) - } - } - txn.lkv.leases.mu.Unlock() -} - -func (txn *txnLeasing) revokeFallback(fbResps []*v3pb.ResponseOp) error { - for _, resp := range fbResps { - _, err := txn.lkv.revokeLeaseKvs(txn.ctx, resp.GetResponseRange().Kvs) - if err != nil { - return err - } - } - return nil -} - -func (txn *txnLeasing) serverTxn() (*v3.TxnResponse, error) { - if err := txn.lkv.waitSession(txn.ctx); err != nil { - return nil, err - } - - userOps := gatherOps(append(txn.opst, txn.opse...)) - userTxn := v3.OpTxn(txn.cs, txn.opst, txn.opse) - fbOps := txn.fallback(userOps) - - defer closeAll(txn.lkv.leases.LockWriteOps(userOps)) - for { - cmps, err := txn.guard(userOps) - if err != nil { - return nil, err - } - resp, err := txn.lkv.kv.Txn(txn.ctx).If(cmps...).Then(userTxn).Else(fbOps...).Commit() - if err != nil { - for _, cmp := range cmps { - txn.lkv.leases.Evict(strings.TrimPrefix(string(cmp.Key), txn.lkv.pfx)) - } - return nil, err - } - if resp.Succeeded { - txn.commitToCache((*v3pb.TxnResponse)(resp), userTxn) - userResp := resp.Responses[0].GetResponseTxn() - userResp.Header = resp.Header - return (*v3.TxnResponse)(userResp), nil - } - if err := txn.revokeFallback(resp.Responses); err != nil { - return nil, err - } - } -} diff --git a/vendor/github.com/coreos/etcd/clientv3/leasing/util.go b/vendor/github.com/coreos/etcd/clientv3/leasing/util.go deleted file mode 100644 index 61f6e8c33fc0..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/leasing/util.go +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package leasing - -import ( - "bytes" - - v3 "github.com/coreos/etcd/clientv3" - v3pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -func compareInt64(a, b int64) int { - switch { - case a < b: - return -1 - case a > b: - return 1 - default: - return 0 - } -} - -func evalCmp(resp *v3.GetResponse, tcmp v3.Cmp) bool { - var result int - if len(resp.Kvs) != 0 { - kv := resp.Kvs[0] - switch tcmp.Target { - case v3pb.Compare_VALUE: - if tv, _ := tcmp.TargetUnion.(*v3pb.Compare_Value); tv != nil { - result = bytes.Compare(kv.Value, tv.Value) - } - case v3pb.Compare_CREATE: - if tv, _ := tcmp.TargetUnion.(*v3pb.Compare_CreateRevision); tv != nil { - result = compareInt64(kv.CreateRevision, tv.CreateRevision) - } - case v3pb.Compare_MOD: - if tv, _ := tcmp.TargetUnion.(*v3pb.Compare_ModRevision); tv != nil { - result = compareInt64(kv.ModRevision, tv.ModRevision) - } - case v3pb.Compare_VERSION: - if tv, _ := tcmp.TargetUnion.(*v3pb.Compare_Version); tv != nil { - result = compareInt64(kv.Version, tv.Version) - } - } - } - switch tcmp.Result { - case v3pb.Compare_EQUAL: - return result == 0 - case v3pb.Compare_NOT_EQUAL: - return result != 0 - case v3pb.Compare_GREATER: - return result > 0 - case v3pb.Compare_LESS: - return result < 0 - } - return true -} - -func gatherOps(ops []v3.Op) (ret []v3.Op) { - for _, op := range ops { - if !op.IsTxn() { - ret = append(ret, op) - continue - } - _, thenOps, elseOps := op.Txn() - ret = append(ret, gatherOps(append(thenOps, elseOps...))...) - } - return ret -} - -func gatherResponseOps(resp []*v3pb.ResponseOp, ops []v3.Op) (ret []v3.Op) { - for i, op := range ops { - if !op.IsTxn() { - ret = append(ret, op) - continue - } - _, thenOps, elseOps := op.Txn() - if txnResp := resp[i].GetResponseTxn(); txnResp.Succeeded { - ret = append(ret, gatherResponseOps(txnResp.Responses, thenOps)...) - } else { - ret = append(ret, gatherResponseOps(txnResp.Responses, elseOps)...) - } - } - return ret -} - -func copyHeader(hdr *v3pb.ResponseHeader) *v3pb.ResponseHeader { - h := *hdr - return &h -} - -func closeAll(chs []chan<- struct{}) { - for _, ch := range chs { - close(ch) - } -} diff --git a/vendor/github.com/coreos/etcd/clientv3/logger.go b/vendor/github.com/coreos/etcd/clientv3/logger.go deleted file mode 100644 index 782e313137a6..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/logger.go +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "io/ioutil" - "sync" - - "google.golang.org/grpc/grpclog" -) - -// Logger is the logger used by client library. -// It implements grpclog.LoggerV2 interface. -type Logger interface { - grpclog.LoggerV2 - - // Lvl returns logger if logger's verbosity level >= "lvl". - // Otherwise, logger that discards all logs. - Lvl(lvl int) Logger - - // to satisfy capnslog - - Print(args ...interface{}) - Printf(format string, args ...interface{}) - Println(args ...interface{}) -} - -var ( - loggerMu sync.RWMutex - logger Logger -) - -type settableLogger struct { - l grpclog.LoggerV2 - mu sync.RWMutex -} - -func init() { - // disable client side logs by default - logger = &settableLogger{} - SetLogger(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, ioutil.Discard)) -} - -// SetLogger sets client-side Logger. -func SetLogger(l grpclog.LoggerV2) { - loggerMu.Lock() - logger = NewLogger(l) - // override grpclog so that any changes happen with locking - grpclog.SetLoggerV2(logger) - loggerMu.Unlock() -} - -// GetLogger returns the current logger. -func GetLogger() Logger { - loggerMu.RLock() - l := logger - loggerMu.RUnlock() - return l -} - -// NewLogger returns a new Logger with grpclog.LoggerV2. -func NewLogger(gl grpclog.LoggerV2) Logger { - return &settableLogger{l: gl} -} - -func (s *settableLogger) get() grpclog.LoggerV2 { - s.mu.RLock() - l := s.l - s.mu.RUnlock() - return l -} - -// implement the grpclog.LoggerV2 interface - -func (s *settableLogger) Info(args ...interface{}) { s.get().Info(args...) } -func (s *settableLogger) Infof(format string, args ...interface{}) { s.get().Infof(format, args...) } -func (s *settableLogger) Infoln(args ...interface{}) { s.get().Infoln(args...) } -func (s *settableLogger) Warning(args ...interface{}) { s.get().Warning(args...) } -func (s *settableLogger) Warningf(format string, args ...interface{}) { - s.get().Warningf(format, args...) -} -func (s *settableLogger) Warningln(args ...interface{}) { s.get().Warningln(args...) } -func (s *settableLogger) Error(args ...interface{}) { s.get().Error(args...) } -func (s *settableLogger) Errorf(format string, args ...interface{}) { - s.get().Errorf(format, args...) -} -func (s *settableLogger) Errorln(args ...interface{}) { s.get().Errorln(args...) } -func (s *settableLogger) Fatal(args ...interface{}) { s.get().Fatal(args...) } -func (s *settableLogger) Fatalf(format string, args ...interface{}) { s.get().Fatalf(format, args...) } -func (s *settableLogger) Fatalln(args ...interface{}) { s.get().Fatalln(args...) } -func (s *settableLogger) Print(args ...interface{}) { s.get().Info(args...) } -func (s *settableLogger) Printf(format string, args ...interface{}) { s.get().Infof(format, args...) } -func (s *settableLogger) Println(args ...interface{}) { s.get().Infoln(args...) } -func (s *settableLogger) V(l int) bool { return s.get().V(l) } -func (s *settableLogger) Lvl(lvl int) Logger { - s.mu.RLock() - l := s.l - s.mu.RUnlock() - if l.V(lvl) { - return s - } - return &noLogger{} -} - -type noLogger struct{} - -func (*noLogger) Info(args ...interface{}) {} -func (*noLogger) Infof(format string, args ...interface{}) {} -func (*noLogger) Infoln(args ...interface{}) {} -func (*noLogger) Warning(args ...interface{}) {} -func (*noLogger) Warningf(format string, args ...interface{}) {} -func (*noLogger) Warningln(args ...interface{}) {} -func (*noLogger) Error(args ...interface{}) {} -func (*noLogger) Errorf(format string, args ...interface{}) {} -func (*noLogger) Errorln(args ...interface{}) {} -func (*noLogger) Fatal(args ...interface{}) {} -func (*noLogger) Fatalf(format string, args ...interface{}) {} -func (*noLogger) Fatalln(args ...interface{}) {} -func (*noLogger) Print(args ...interface{}) {} -func (*noLogger) Printf(format string, args ...interface{}) {} -func (*noLogger) Println(args ...interface{}) {} -func (*noLogger) V(l int) bool { return false } -func (ng *noLogger) Lvl(lvl int) Logger { return ng } diff --git a/vendor/github.com/coreos/etcd/clientv3/maintenance.go b/vendor/github.com/coreos/etcd/clientv3/maintenance.go deleted file mode 100644 index f60cfbe47193..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/maintenance.go +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - "io" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" -) - -type ( - DefragmentResponse pb.DefragmentResponse - AlarmResponse pb.AlarmResponse - AlarmMember pb.AlarmMember - StatusResponse pb.StatusResponse - HashKVResponse pb.HashKVResponse - MoveLeaderResponse pb.MoveLeaderResponse -) - -type Maintenance interface { - // AlarmList gets all active alarms. - AlarmList(ctx context.Context) (*AlarmResponse, error) - - // AlarmDisarm disarms a given alarm. - AlarmDisarm(ctx context.Context, m *AlarmMember) (*AlarmResponse, error) - - // Defragment releases wasted space from internal fragmentation on a given etcd member. - // Defragment is only needed when deleting a large number of keys and want to reclaim - // the resources. - // Defragment is an expensive operation. User should avoid defragmenting multiple members - // at the same time. - // To defragment multiple members in the cluster, user need to call defragment multiple - // times with different endpoints. - Defragment(ctx context.Context, endpoint string) (*DefragmentResponse, error) - - // Status gets the status of the endpoint. - Status(ctx context.Context, endpoint string) (*StatusResponse, error) - - // HashKV returns a hash of the KV state at the time of the RPC. - // If revision is zero, the hash is computed on all keys. If the revision - // is non-zero, the hash is computed on all keys at or below the given revision. - HashKV(ctx context.Context, endpoint string, rev int64) (*HashKVResponse, error) - - // Snapshot provides a reader for a point-in-time snapshot of etcd. - Snapshot(ctx context.Context) (io.ReadCloser, error) - - // MoveLeader requests current leader to transfer its leadership to the transferee. - // Request must be made to the leader. - MoveLeader(ctx context.Context, transfereeID uint64) (*MoveLeaderResponse, error) -} - -type maintenance struct { - dial func(endpoint string) (pb.MaintenanceClient, func(), error) - remote pb.MaintenanceClient - callOpts []grpc.CallOption -} - -func NewMaintenance(c *Client) Maintenance { - api := &maintenance{ - dial: func(endpoint string) (pb.MaintenanceClient, func(), error) { - conn, err := c.dial(endpoint) - if err != nil { - return nil, nil, err - } - cancel := func() { conn.Close() } - return RetryMaintenanceClient(c, conn), cancel, nil - }, - remote: RetryMaintenanceClient(c, c.conn), - } - if c != nil { - api.callOpts = c.callOpts - } - return api -} - -func NewMaintenanceFromMaintenanceClient(remote pb.MaintenanceClient, c *Client) Maintenance { - api := &maintenance{ - dial: func(string) (pb.MaintenanceClient, func(), error) { - return remote, func() {}, nil - }, - remote: remote, - } - if c != nil { - api.callOpts = c.callOpts - } - return api -} - -func (m *maintenance) AlarmList(ctx context.Context) (*AlarmResponse, error) { - req := &pb.AlarmRequest{ - Action: pb.AlarmRequest_GET, - MemberID: 0, // all - Alarm: pb.AlarmType_NONE, // all - } - resp, err := m.remote.Alarm(ctx, req, m.callOpts...) - if err == nil { - return (*AlarmResponse)(resp), nil - } - return nil, toErr(ctx, err) -} - -func (m *maintenance) AlarmDisarm(ctx context.Context, am *AlarmMember) (*AlarmResponse, error) { - req := &pb.AlarmRequest{ - Action: pb.AlarmRequest_DEACTIVATE, - MemberID: am.MemberID, - Alarm: am.Alarm, - } - - if req.MemberID == 0 && req.Alarm == pb.AlarmType_NONE { - ar, err := m.AlarmList(ctx) - if err != nil { - return nil, toErr(ctx, err) - } - ret := AlarmResponse{} - for _, am := range ar.Alarms { - dresp, derr := m.AlarmDisarm(ctx, (*AlarmMember)(am)) - if derr != nil { - return nil, toErr(ctx, derr) - } - ret.Alarms = append(ret.Alarms, dresp.Alarms...) - } - return &ret, nil - } - - resp, err := m.remote.Alarm(ctx, req, m.callOpts...) - if err == nil { - return (*AlarmResponse)(resp), nil - } - return nil, toErr(ctx, err) -} - -func (m *maintenance) Defragment(ctx context.Context, endpoint string) (*DefragmentResponse, error) { - remote, cancel, err := m.dial(endpoint) - if err != nil { - return nil, toErr(ctx, err) - } - defer cancel() - resp, err := remote.Defragment(ctx, &pb.DefragmentRequest{}, m.callOpts...) - if err != nil { - return nil, toErr(ctx, err) - } - return (*DefragmentResponse)(resp), nil -} - -func (m *maintenance) Status(ctx context.Context, endpoint string) (*StatusResponse, error) { - remote, cancel, err := m.dial(endpoint) - if err != nil { - return nil, toErr(ctx, err) - } - defer cancel() - resp, err := remote.Status(ctx, &pb.StatusRequest{}, m.callOpts...) - if err != nil { - return nil, toErr(ctx, err) - } - return (*StatusResponse)(resp), nil -} - -func (m *maintenance) HashKV(ctx context.Context, endpoint string, rev int64) (*HashKVResponse, error) { - remote, cancel, err := m.dial(endpoint) - if err != nil { - return nil, toErr(ctx, err) - } - defer cancel() - resp, err := remote.HashKV(ctx, &pb.HashKVRequest{Revision: rev}, m.callOpts...) - if err != nil { - return nil, toErr(ctx, err) - } - return (*HashKVResponse)(resp), nil -} - -func (m *maintenance) Snapshot(ctx context.Context) (io.ReadCloser, error) { - ss, err := m.remote.Snapshot(ctx, &pb.SnapshotRequest{}, m.callOpts...) - if err != nil { - return nil, toErr(ctx, err) - } - - pr, pw := io.Pipe() - go func() { - for { - resp, err := ss.Recv() - if err != nil { - pw.CloseWithError(err) - return - } - if resp == nil && err == nil { - break - } - if _, werr := pw.Write(resp.Blob); werr != nil { - pw.CloseWithError(werr) - return - } - } - pw.Close() - }() - return &snapshotReadCloser{ctx: ctx, ReadCloser: pr}, nil -} - -type snapshotReadCloser struct { - ctx context.Context - io.ReadCloser -} - -func (rc *snapshotReadCloser) Read(p []byte) (n int, err error) { - n, err = rc.ReadCloser.Read(p) - return n, toErr(rc.ctx, err) -} - -func (m *maintenance) MoveLeader(ctx context.Context, transfereeID uint64) (*MoveLeaderResponse, error) { - resp, err := m.remote.MoveLeader(ctx, &pb.MoveLeaderRequest{TargetID: transfereeID}, m.callOpts...) - return (*MoveLeaderResponse)(resp), toErr(ctx, err) -} diff --git a/vendor/github.com/coreos/etcd/clientv3/mirror/syncer.go b/vendor/github.com/coreos/etcd/clientv3/mirror/syncer.go deleted file mode 100644 index b820933227cb..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/mirror/syncer.go +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package mirror implements etcd mirroring operations. -package mirror - -import ( - "context" - - "github.com/coreos/etcd/clientv3" -) - -const ( - batchLimit = 1000 -) - -// Syncer syncs with the key-value state of an etcd cluster. -type Syncer interface { - // SyncBase syncs the base state of the key-value state. - // The key-value state are sent through the returned chan. - SyncBase(ctx context.Context) (<-chan clientv3.GetResponse, chan error) - // SyncUpdates syncs the updates of the key-value state. - // The update events are sent through the returned chan. - SyncUpdates(ctx context.Context) clientv3.WatchChan -} - -// NewSyncer creates a Syncer. -func NewSyncer(c *clientv3.Client, prefix string, rev int64) Syncer { - return &syncer{c: c, prefix: prefix, rev: rev} -} - -type syncer struct { - c *clientv3.Client - rev int64 - prefix string -} - -func (s *syncer) SyncBase(ctx context.Context) (<-chan clientv3.GetResponse, chan error) { - respchan := make(chan clientv3.GetResponse, 1024) - errchan := make(chan error, 1) - - // if rev is not specified, we will choose the most recent revision. - if s.rev == 0 { - resp, err := s.c.Get(ctx, "foo") - if err != nil { - errchan <- err - close(respchan) - close(errchan) - return respchan, errchan - } - s.rev = resp.Header.Revision - } - - go func() { - defer close(respchan) - defer close(errchan) - - var key string - - opts := []clientv3.OpOption{clientv3.WithLimit(batchLimit), clientv3.WithRev(s.rev)} - - if len(s.prefix) == 0 { - // If len(s.prefix) == 0, we will sync the entire key-value space. - // We then range from the smallest key (0x00) to the end. - opts = append(opts, clientv3.WithFromKey()) - key = "\x00" - } else { - // If len(s.prefix) != 0, we will sync key-value space with given prefix. - // We then range from the prefix to the next prefix if exists. Or we will - // range from the prefix to the end if the next prefix does not exists. - opts = append(opts, clientv3.WithRange(clientv3.GetPrefixRangeEnd(s.prefix))) - key = s.prefix - } - - for { - resp, err := s.c.Get(ctx, key, opts...) - if err != nil { - errchan <- err - return - } - - respchan <- (clientv3.GetResponse)(*resp) - - if !resp.More { - return - } - // move to next key - key = string(append(resp.Kvs[len(resp.Kvs)-1].Key, 0)) - } - }() - - return respchan, errchan -} - -func (s *syncer) SyncUpdates(ctx context.Context) clientv3.WatchChan { - if s.rev == 0 { - panic("unexpected revision = 0. Calling SyncUpdates before SyncBase finishes?") - } - return s.c.Watch(ctx, s.prefix, clientv3.WithPrefix(), clientv3.WithRev(s.rev+1)) -} diff --git a/vendor/github.com/coreos/etcd/clientv3/namespace/doc.go b/vendor/github.com/coreos/etcd/clientv3/namespace/doc.go deleted file mode 100644 index 3f883320fcca..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/namespace/doc.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package namespace is a clientv3 wrapper that translates all keys to begin -// with a given prefix. -// -// First, create a client: -// -// cli, err := clientv3.New(clientv3.Config{Endpoints: []string{"localhost:2379"}}) -// if err != nil { -// // handle error! -// } -// -// Next, override the client interfaces: -// -// unprefixedKV := cli.KV -// cli.KV = namespace.NewKV(cli.KV, "my-prefix/") -// cli.Watcher = namespace.NewWatcher(cli.Watcher, "my-prefix/") -// cli.Lease = namespace.NewLease(cli.Lease, "my-prefix/") -// -// Now calls using 'cli' will namespace / prefix all keys with "my-prefix/": -// -// cli.Put(context.TODO(), "abc", "123") -// resp, _ := unprefixedKV.Get(context.TODO(), "my-prefix/abc") -// fmt.Printf("%s\n", resp.Kvs[0].Value) -// // Output: 123 -// unprefixedKV.Put(context.TODO(), "my-prefix/abc", "456") -// resp, _ = cli.Get("abc") -// fmt.Printf("%s\n", resp.Kvs[0].Value) -// // Output: 456 -// -package namespace diff --git a/vendor/github.com/coreos/etcd/clientv3/namespace/kv.go b/vendor/github.com/coreos/etcd/clientv3/namespace/kv.go deleted file mode 100644 index 13dd83a24550..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/namespace/kv.go +++ /dev/null @@ -1,206 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package namespace - -import ( - "context" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -type kvPrefix struct { - clientv3.KV - pfx string -} - -// NewKV wraps a KV instance so that all requests -// are prefixed with a given string. -func NewKV(kv clientv3.KV, prefix string) clientv3.KV { - return &kvPrefix{kv, prefix} -} - -func (kv *kvPrefix) Put(ctx context.Context, key, val string, opts ...clientv3.OpOption) (*clientv3.PutResponse, error) { - if len(key) == 0 { - return nil, rpctypes.ErrEmptyKey - } - op := kv.prefixOp(clientv3.OpPut(key, val, opts...)) - r, err := kv.KV.Do(ctx, op) - if err != nil { - return nil, err - } - put := r.Put() - kv.unprefixPutResponse(put) - return put, nil -} - -func (kv *kvPrefix) Get(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error) { - if len(key) == 0 { - return nil, rpctypes.ErrEmptyKey - } - r, err := kv.KV.Do(ctx, kv.prefixOp(clientv3.OpGet(key, opts...))) - if err != nil { - return nil, err - } - get := r.Get() - kv.unprefixGetResponse(get) - return get, nil -} - -func (kv *kvPrefix) Delete(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.DeleteResponse, error) { - if len(key) == 0 { - return nil, rpctypes.ErrEmptyKey - } - r, err := kv.KV.Do(ctx, kv.prefixOp(clientv3.OpDelete(key, opts...))) - if err != nil { - return nil, err - } - del := r.Del() - kv.unprefixDeleteResponse(del) - return del, nil -} - -func (kv *kvPrefix) Do(ctx context.Context, op clientv3.Op) (clientv3.OpResponse, error) { - if len(op.KeyBytes()) == 0 && !op.IsTxn() { - return clientv3.OpResponse{}, rpctypes.ErrEmptyKey - } - r, err := kv.KV.Do(ctx, kv.prefixOp(op)) - if err != nil { - return r, err - } - switch { - case r.Get() != nil: - kv.unprefixGetResponse(r.Get()) - case r.Put() != nil: - kv.unprefixPutResponse(r.Put()) - case r.Del() != nil: - kv.unprefixDeleteResponse(r.Del()) - case r.Txn() != nil: - kv.unprefixTxnResponse(r.Txn()) - } - return r, nil -} - -type txnPrefix struct { - clientv3.Txn - kv *kvPrefix -} - -func (kv *kvPrefix) Txn(ctx context.Context) clientv3.Txn { - return &txnPrefix{kv.KV.Txn(ctx), kv} -} - -func (txn *txnPrefix) If(cs ...clientv3.Cmp) clientv3.Txn { - txn.Txn = txn.Txn.If(txn.kv.prefixCmps(cs)...) - return txn -} - -func (txn *txnPrefix) Then(ops ...clientv3.Op) clientv3.Txn { - txn.Txn = txn.Txn.Then(txn.kv.prefixOps(ops)...) - return txn -} - -func (txn *txnPrefix) Else(ops ...clientv3.Op) clientv3.Txn { - txn.Txn = txn.Txn.Else(txn.kv.prefixOps(ops)...) - return txn -} - -func (txn *txnPrefix) Commit() (*clientv3.TxnResponse, error) { - resp, err := txn.Txn.Commit() - if err != nil { - return nil, err - } - txn.kv.unprefixTxnResponse(resp) - return resp, nil -} - -func (kv *kvPrefix) prefixOp(op clientv3.Op) clientv3.Op { - if !op.IsTxn() { - begin, end := kv.prefixInterval(op.KeyBytes(), op.RangeBytes()) - op.WithKeyBytes(begin) - op.WithRangeBytes(end) - return op - } - cmps, thenOps, elseOps := op.Txn() - return clientv3.OpTxn(kv.prefixCmps(cmps), kv.prefixOps(thenOps), kv.prefixOps(elseOps)) -} - -func (kv *kvPrefix) unprefixGetResponse(resp *clientv3.GetResponse) { - for i := range resp.Kvs { - resp.Kvs[i].Key = resp.Kvs[i].Key[len(kv.pfx):] - } -} - -func (kv *kvPrefix) unprefixPutResponse(resp *clientv3.PutResponse) { - if resp.PrevKv != nil { - resp.PrevKv.Key = resp.PrevKv.Key[len(kv.pfx):] - } -} - -func (kv *kvPrefix) unprefixDeleteResponse(resp *clientv3.DeleteResponse) { - for i := range resp.PrevKvs { - resp.PrevKvs[i].Key = resp.PrevKvs[i].Key[len(kv.pfx):] - } -} - -func (kv *kvPrefix) unprefixTxnResponse(resp *clientv3.TxnResponse) { - for _, r := range resp.Responses { - switch tv := r.Response.(type) { - case *pb.ResponseOp_ResponseRange: - if tv.ResponseRange != nil { - kv.unprefixGetResponse((*clientv3.GetResponse)(tv.ResponseRange)) - } - case *pb.ResponseOp_ResponsePut: - if tv.ResponsePut != nil { - kv.unprefixPutResponse((*clientv3.PutResponse)(tv.ResponsePut)) - } - case *pb.ResponseOp_ResponseDeleteRange: - if tv.ResponseDeleteRange != nil { - kv.unprefixDeleteResponse((*clientv3.DeleteResponse)(tv.ResponseDeleteRange)) - } - case *pb.ResponseOp_ResponseTxn: - if tv.ResponseTxn != nil { - kv.unprefixTxnResponse((*clientv3.TxnResponse)(tv.ResponseTxn)) - } - default: - } - } -} - -func (kv *kvPrefix) prefixInterval(key, end []byte) (pfxKey []byte, pfxEnd []byte) { - return prefixInterval(kv.pfx, key, end) -} - -func (kv *kvPrefix) prefixCmps(cs []clientv3.Cmp) []clientv3.Cmp { - newCmps := make([]clientv3.Cmp, len(cs)) - for i := range cs { - newCmps[i] = cs[i] - pfxKey, endKey := kv.prefixInterval(cs[i].KeyBytes(), cs[i].RangeEnd) - newCmps[i].WithKeyBytes(pfxKey) - if len(cs[i].RangeEnd) != 0 { - newCmps[i].RangeEnd = endKey - } - } - return newCmps -} - -func (kv *kvPrefix) prefixOps(ops []clientv3.Op) []clientv3.Op { - newOps := make([]clientv3.Op, len(ops)) - for i := range ops { - newOps[i] = kv.prefixOp(ops[i]) - } - return newOps -} diff --git a/vendor/github.com/coreos/etcd/clientv3/namespace/lease.go b/vendor/github.com/coreos/etcd/clientv3/namespace/lease.go deleted file mode 100644 index f092106cbf25..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/namespace/lease.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package namespace - -import ( - "bytes" - "context" - - "github.com/coreos/etcd/clientv3" -) - -type leasePrefix struct { - clientv3.Lease - pfx []byte -} - -// NewLease wraps a Lease interface to filter for only keys with a prefix -// and remove that prefix when fetching attached keys through TimeToLive. -func NewLease(l clientv3.Lease, prefix string) clientv3.Lease { - return &leasePrefix{l, []byte(prefix)} -} - -func (l *leasePrefix) TimeToLive(ctx context.Context, id clientv3.LeaseID, opts ...clientv3.LeaseOption) (*clientv3.LeaseTimeToLiveResponse, error) { - resp, err := l.Lease.TimeToLive(ctx, id, opts...) - if err != nil { - return nil, err - } - if len(resp.Keys) > 0 { - var outKeys [][]byte - for i := range resp.Keys { - if len(resp.Keys[i]) < len(l.pfx) { - // too short - continue - } - if !bytes.Equal(resp.Keys[i][:len(l.pfx)], l.pfx) { - // doesn't match prefix - continue - } - // strip prefix - outKeys = append(outKeys, resp.Keys[i][len(l.pfx):]) - } - resp.Keys = outKeys - } - return resp, nil -} diff --git a/vendor/github.com/coreos/etcd/clientv3/namespace/util.go b/vendor/github.com/coreos/etcd/clientv3/namespace/util.go deleted file mode 100644 index ecf04046c32d..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/namespace/util.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package namespace - -func prefixInterval(pfx string, key, end []byte) (pfxKey []byte, pfxEnd []byte) { - pfxKey = make([]byte, len(pfx)+len(key)) - copy(pfxKey[copy(pfxKey, pfx):], key) - - if len(end) == 1 && end[0] == 0 { - // the edge of the keyspace - pfxEnd = make([]byte, len(pfx)) - copy(pfxEnd, pfx) - ok := false - for i := len(pfxEnd) - 1; i >= 0; i-- { - if pfxEnd[i]++; pfxEnd[i] != 0 { - ok = true - break - } - } - if !ok { - // 0xff..ff => 0x00 - pfxEnd = []byte{0} - } - } else if len(end) >= 1 { - pfxEnd = make([]byte, len(pfx)+len(end)) - copy(pfxEnd[copy(pfxEnd, pfx):], end) - } - - return pfxKey, pfxEnd -} diff --git a/vendor/github.com/coreos/etcd/clientv3/namespace/watch.go b/vendor/github.com/coreos/etcd/clientv3/namespace/watch.go deleted file mode 100644 index 5a9596df5d8f..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/namespace/watch.go +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package namespace - -import ( - "context" - "sync" - - "github.com/coreos/etcd/clientv3" -) - -type watcherPrefix struct { - clientv3.Watcher - pfx string - - wg sync.WaitGroup - stopc chan struct{} - stopOnce sync.Once -} - -// NewWatcher wraps a Watcher instance so that all Watch requests -// are prefixed with a given string and all Watch responses have -// the prefix removed. -func NewWatcher(w clientv3.Watcher, prefix string) clientv3.Watcher { - return &watcherPrefix{Watcher: w, pfx: prefix, stopc: make(chan struct{})} -} - -func (w *watcherPrefix) Watch(ctx context.Context, key string, opts ...clientv3.OpOption) clientv3.WatchChan { - // since OpOption is opaque, determine range for prefixing through an OpGet - op := clientv3.OpGet(key, opts...) - end := op.RangeBytes() - pfxBegin, pfxEnd := prefixInterval(w.pfx, []byte(key), end) - if pfxEnd != nil { - opts = append(opts, clientv3.WithRange(string(pfxEnd))) - } - - wch := w.Watcher.Watch(ctx, string(pfxBegin), opts...) - - // translate watch events from prefixed to unprefixed - pfxWch := make(chan clientv3.WatchResponse) - w.wg.Add(1) - go func() { - defer func() { - close(pfxWch) - w.wg.Done() - }() - for wr := range wch { - for i := range wr.Events { - wr.Events[i].Kv.Key = wr.Events[i].Kv.Key[len(w.pfx):] - if wr.Events[i].PrevKv != nil { - wr.Events[i].PrevKv.Key = wr.Events[i].Kv.Key - } - } - select { - case pfxWch <- wr: - case <-ctx.Done(): - return - case <-w.stopc: - return - } - } - }() - return pfxWch -} - -func (w *watcherPrefix) Close() error { - err := w.Watcher.Close() - w.stopOnce.Do(func() { close(w.stopc) }) - w.wg.Wait() - return err -} diff --git a/vendor/github.com/coreos/etcd/clientv3/naming/doc.go b/vendor/github.com/coreos/etcd/clientv3/naming/doc.go deleted file mode 100644 index 71608cc738bc..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/naming/doc.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package naming provides an etcd-backed gRPC resolver for discovering gRPC services. -// -// To use, first import the packages: -// -// import ( -// "github.com/coreos/etcd/clientv3" -// etcdnaming "github.com/coreos/etcd/clientv3/naming" -// -// "google.golang.org/grpc" -// "google.golang.org/grpc/naming" -// ) -// -// First, register new endpoint addresses for a service: -// -// func etcdAdd(c *clientv3.Client, service, addr string) error { -// r := &etcdnaming.GRPCResolver{Client: c} -// return r.Update(c.Ctx(), service, naming.Update{Op: naming.Add, Addr: addr}) -// } -// -// Dial an RPC service using the etcd gRPC resolver and a gRPC Balancer: -// -// func etcdDial(c *clientv3.Client, service string) (*grpc.ClientConn, error) { -// r := &etcdnaming.GRPCResolver{Client: c} -// b := grpc.RoundRobin(r) -// return grpc.Dial(service, grpc.WithBalancer(b)) -// } -// -// Optionally, force delete an endpoint: -// -// func etcdDelete(c *clientv3, service, addr string) error { -// r := &etcdnaming.GRPCResolver{Client: c} -// return r.Update(c.Ctx(), "my-service", naming.Update{Op: naming.Delete, Addr: "1.2.3.4"}) -// } -// -// Or register an expiring endpoint with a lease: -// -// func etcdLeaseAdd(c *clientv3.Client, lid clientv3.LeaseID, service, addr string) error { -// r := &etcdnaming.GRPCResolver{Client: c} -// return r.Update(c.Ctx(), service, naming.Update{Op: naming.Add, Addr: addr}, clientv3.WithLease(lid)) -// } -// -package naming diff --git a/vendor/github.com/coreos/etcd/clientv3/naming/grpc.go b/vendor/github.com/coreos/etcd/clientv3/naming/grpc.go deleted file mode 100644 index 3c0e8e664bd3..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/naming/grpc.go +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package naming - -import ( - "context" - "encoding/json" - "fmt" - - etcd "github.com/coreos/etcd/clientv3" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc/naming" - "google.golang.org/grpc/status" -) - -var ErrWatcherClosed = fmt.Errorf("naming: watch closed") - -// GRPCResolver creates a grpc.Watcher for a target to track its resolution changes. -type GRPCResolver struct { - // Client is an initialized etcd client. - Client *etcd.Client -} - -func (gr *GRPCResolver) Update(ctx context.Context, target string, nm naming.Update, opts ...etcd.OpOption) (err error) { - switch nm.Op { - case naming.Add: - var v []byte - if v, err = json.Marshal(nm); err != nil { - return status.Error(codes.InvalidArgument, err.Error()) - } - _, err = gr.Client.KV.Put(ctx, target+"/"+nm.Addr, string(v), opts...) - case naming.Delete: - _, err = gr.Client.Delete(ctx, target+"/"+nm.Addr, opts...) - default: - return status.Error(codes.InvalidArgument, "naming: bad naming op") - } - return err -} - -func (gr *GRPCResolver) Resolve(target string) (naming.Watcher, error) { - ctx, cancel := context.WithCancel(context.Background()) - w := &gRPCWatcher{c: gr.Client, target: target + "/", ctx: ctx, cancel: cancel} - return w, nil -} - -type gRPCWatcher struct { - c *etcd.Client - target string - ctx context.Context - cancel context.CancelFunc - wch etcd.WatchChan - err error -} - -// Next gets the next set of updates from the etcd resolver. -// Calls to Next should be serialized; concurrent calls are not safe since -// there is no way to reconcile the update ordering. -func (gw *gRPCWatcher) Next() ([]*naming.Update, error) { - if gw.wch == nil { - // first Next() returns all addresses - return gw.firstNext() - } - if gw.err != nil { - return nil, gw.err - } - - // process new events on target/* - wr, ok := <-gw.wch - if !ok { - gw.err = status.Error(codes.Unavailable, ErrWatcherClosed.Error()) - return nil, gw.err - } - if gw.err = wr.Err(); gw.err != nil { - return nil, gw.err - } - - updates := make([]*naming.Update, 0, len(wr.Events)) - for _, e := range wr.Events { - var jupdate naming.Update - var err error - switch e.Type { - case etcd.EventTypePut: - err = json.Unmarshal(e.Kv.Value, &jupdate) - jupdate.Op = naming.Add - case etcd.EventTypeDelete: - err = json.Unmarshal(e.PrevKv.Value, &jupdate) - jupdate.Op = naming.Delete - } - if err == nil { - updates = append(updates, &jupdate) - } - } - return updates, nil -} - -func (gw *gRPCWatcher) firstNext() ([]*naming.Update, error) { - // Use serialized request so resolution still works if the target etcd - // server is partitioned away from the quorum. - resp, err := gw.c.Get(gw.ctx, gw.target, etcd.WithPrefix(), etcd.WithSerializable()) - if gw.err = err; err != nil { - return nil, err - } - - updates := make([]*naming.Update, 0, len(resp.Kvs)) - for _, kv := range resp.Kvs { - var jupdate naming.Update - if err := json.Unmarshal(kv.Value, &jupdate); err != nil { - continue - } - updates = append(updates, &jupdate) - } - - opts := []etcd.OpOption{etcd.WithRev(resp.Header.Revision + 1), etcd.WithPrefix(), etcd.WithPrevKV()} - gw.wch = gw.c.Watch(gw.ctx, gw.target, opts...) - return updates, nil -} - -func (gw *gRPCWatcher) Close() { gw.cancel() } diff --git a/vendor/github.com/coreos/etcd/clientv3/op.go b/vendor/github.com/coreos/etcd/clientv3/op.go deleted file mode 100644 index c6ec5bf5200c..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/op.go +++ /dev/null @@ -1,513 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - -type opType int - -const ( - // A default Op has opType 0, which is invalid. - tRange opType = iota + 1 - tPut - tDeleteRange - tTxn -) - -var ( - noPrefixEnd = []byte{0} -) - -// Op represents an Operation that kv can execute. -type Op struct { - t opType - key []byte - end []byte - - // for range - limit int64 - sort *SortOption - serializable bool - keysOnly bool - countOnly bool - minModRev int64 - maxModRev int64 - minCreateRev int64 - maxCreateRev int64 - - // for range, watch - rev int64 - - // for watch, put, delete - prevKV bool - - // for put - ignoreValue bool - ignoreLease bool - - // progressNotify is for progress updates. - progressNotify bool - // createdNotify is for created event - createdNotify bool - // filters for watchers - filterPut bool - filterDelete bool - - // for put - val []byte - leaseID LeaseID - - // txn - cmps []Cmp - thenOps []Op - elseOps []Op -} - -// accessors / mutators - -func (op Op) IsTxn() bool { return op.t == tTxn } -func (op Op) Txn() ([]Cmp, []Op, []Op) { return op.cmps, op.thenOps, op.elseOps } - -// KeyBytes returns the byte slice holding the Op's key. -func (op Op) KeyBytes() []byte { return op.key } - -// WithKeyBytes sets the byte slice for the Op's key. -func (op *Op) WithKeyBytes(key []byte) { op.key = key } - -// RangeBytes returns the byte slice holding with the Op's range end, if any. -func (op Op) RangeBytes() []byte { return op.end } - -// Rev returns the requested revision, if any. -func (op Op) Rev() int64 { return op.rev } - -// IsPut returns true iff the operation is a Put. -func (op Op) IsPut() bool { return op.t == tPut } - -// IsGet returns true iff the operation is a Get. -func (op Op) IsGet() bool { return op.t == tRange } - -// IsDelete returns true iff the operation is a Delete. -func (op Op) IsDelete() bool { return op.t == tDeleteRange } - -// IsSerializable returns true if the serializable field is true. -func (op Op) IsSerializable() bool { return op.serializable == true } - -// IsKeysOnly returns whether keysOnly is set. -func (op Op) IsKeysOnly() bool { return op.keysOnly == true } - -// IsCountOnly returns whether countOnly is set. -func (op Op) IsCountOnly() bool { return op.countOnly == true } - -// MinModRev returns the operation's minimum modify revision. -func (op Op) MinModRev() int64 { return op.minModRev } - -// MaxModRev returns the operation's maximum modify revision. -func (op Op) MaxModRev() int64 { return op.maxModRev } - -// MinCreateRev returns the operation's minimum create revision. -func (op Op) MinCreateRev() int64 { return op.minCreateRev } - -// MaxCreateRev returns the operation's maximum create revision. -func (op Op) MaxCreateRev() int64 { return op.maxCreateRev } - -// WithRangeBytes sets the byte slice for the Op's range end. -func (op *Op) WithRangeBytes(end []byte) { op.end = end } - -// ValueBytes returns the byte slice holding the Op's value, if any. -func (op Op) ValueBytes() []byte { return op.val } - -// WithValueBytes sets the byte slice for the Op's value. -func (op *Op) WithValueBytes(v []byte) { op.val = v } - -func (op Op) toRangeRequest() *pb.RangeRequest { - if op.t != tRange { - panic("op.t != tRange") - } - r := &pb.RangeRequest{ - Key: op.key, - RangeEnd: op.end, - Limit: op.limit, - Revision: op.rev, - Serializable: op.serializable, - KeysOnly: op.keysOnly, - CountOnly: op.countOnly, - MinModRevision: op.minModRev, - MaxModRevision: op.maxModRev, - MinCreateRevision: op.minCreateRev, - MaxCreateRevision: op.maxCreateRev, - } - if op.sort != nil { - r.SortOrder = pb.RangeRequest_SortOrder(op.sort.Order) - r.SortTarget = pb.RangeRequest_SortTarget(op.sort.Target) - } - return r -} - -func (op Op) toTxnRequest() *pb.TxnRequest { - thenOps := make([]*pb.RequestOp, len(op.thenOps)) - for i, tOp := range op.thenOps { - thenOps[i] = tOp.toRequestOp() - } - elseOps := make([]*pb.RequestOp, len(op.elseOps)) - for i, eOp := range op.elseOps { - elseOps[i] = eOp.toRequestOp() - } - cmps := make([]*pb.Compare, len(op.cmps)) - for i := range op.cmps { - cmps[i] = (*pb.Compare)(&op.cmps[i]) - } - return &pb.TxnRequest{Compare: cmps, Success: thenOps, Failure: elseOps} -} - -func (op Op) toRequestOp() *pb.RequestOp { - switch op.t { - case tRange: - return &pb.RequestOp{Request: &pb.RequestOp_RequestRange{RequestRange: op.toRangeRequest()}} - case tPut: - r := &pb.PutRequest{Key: op.key, Value: op.val, Lease: int64(op.leaseID), PrevKv: op.prevKV, IgnoreValue: op.ignoreValue, IgnoreLease: op.ignoreLease} - return &pb.RequestOp{Request: &pb.RequestOp_RequestPut{RequestPut: r}} - case tDeleteRange: - r := &pb.DeleteRangeRequest{Key: op.key, RangeEnd: op.end, PrevKv: op.prevKV} - return &pb.RequestOp{Request: &pb.RequestOp_RequestDeleteRange{RequestDeleteRange: r}} - case tTxn: - return &pb.RequestOp{Request: &pb.RequestOp_RequestTxn{RequestTxn: op.toTxnRequest()}} - default: - panic("Unknown Op") - } -} - -func (op Op) isWrite() bool { - if op.t == tTxn { - for _, tOp := range op.thenOps { - if tOp.isWrite() { - return true - } - } - for _, tOp := range op.elseOps { - if tOp.isWrite() { - return true - } - } - return false - } - return op.t != tRange -} - -func OpGet(key string, opts ...OpOption) Op { - ret := Op{t: tRange, key: []byte(key)} - ret.applyOpts(opts) - return ret -} - -func OpDelete(key string, opts ...OpOption) Op { - ret := Op{t: tDeleteRange, key: []byte(key)} - ret.applyOpts(opts) - switch { - case ret.leaseID != 0: - panic("unexpected lease in delete") - case ret.limit != 0: - panic("unexpected limit in delete") - case ret.rev != 0: - panic("unexpected revision in delete") - case ret.sort != nil: - panic("unexpected sort in delete") - case ret.serializable: - panic("unexpected serializable in delete") - case ret.countOnly: - panic("unexpected countOnly in delete") - case ret.minModRev != 0, ret.maxModRev != 0: - panic("unexpected mod revision filter in delete") - case ret.minCreateRev != 0, ret.maxCreateRev != 0: - panic("unexpected create revision filter in delete") - case ret.filterDelete, ret.filterPut: - panic("unexpected filter in delete") - case ret.createdNotify: - panic("unexpected createdNotify in delete") - } - return ret -} - -func OpPut(key, val string, opts ...OpOption) Op { - ret := Op{t: tPut, key: []byte(key), val: []byte(val)} - ret.applyOpts(opts) - switch { - case ret.end != nil: - panic("unexpected range in put") - case ret.limit != 0: - panic("unexpected limit in put") - case ret.rev != 0: - panic("unexpected revision in put") - case ret.sort != nil: - panic("unexpected sort in put") - case ret.serializable: - panic("unexpected serializable in put") - case ret.countOnly: - panic("unexpected countOnly in put") - case ret.minModRev != 0, ret.maxModRev != 0: - panic("unexpected mod revision filter in put") - case ret.minCreateRev != 0, ret.maxCreateRev != 0: - panic("unexpected create revision filter in put") - case ret.filterDelete, ret.filterPut: - panic("unexpected filter in put") - case ret.createdNotify: - panic("unexpected createdNotify in put") - } - return ret -} - -func OpTxn(cmps []Cmp, thenOps []Op, elseOps []Op) Op { - return Op{t: tTxn, cmps: cmps, thenOps: thenOps, elseOps: elseOps} -} - -func opWatch(key string, opts ...OpOption) Op { - ret := Op{t: tRange, key: []byte(key)} - ret.applyOpts(opts) - switch { - case ret.leaseID != 0: - panic("unexpected lease in watch") - case ret.limit != 0: - panic("unexpected limit in watch") - case ret.sort != nil: - panic("unexpected sort in watch") - case ret.serializable: - panic("unexpected serializable in watch") - case ret.countOnly: - panic("unexpected countOnly in watch") - case ret.minModRev != 0, ret.maxModRev != 0: - panic("unexpected mod revision filter in watch") - case ret.minCreateRev != 0, ret.maxCreateRev != 0: - panic("unexpected create revision filter in watch") - } - return ret -} - -func (op *Op) applyOpts(opts []OpOption) { - for _, opt := range opts { - opt(op) - } -} - -// OpOption configures Operations like Get, Put, Delete. -type OpOption func(*Op) - -// WithLease attaches a lease ID to a key in 'Put' request. -func WithLease(leaseID LeaseID) OpOption { - return func(op *Op) { op.leaseID = leaseID } -} - -// WithLimit limits the number of results to return from 'Get' request. -// If WithLimit is given a 0 limit, it is treated as no limit. -func WithLimit(n int64) OpOption { return func(op *Op) { op.limit = n } } - -// WithRev specifies the store revision for 'Get' request. -// Or the start revision of 'Watch' request. -func WithRev(rev int64) OpOption { return func(op *Op) { op.rev = rev } } - -// WithSort specifies the ordering in 'Get' request. It requires -// 'WithRange' and/or 'WithPrefix' to be specified too. -// 'target' specifies the target to sort by: key, version, revisions, value. -// 'order' can be either 'SortNone', 'SortAscend', 'SortDescend'. -func WithSort(target SortTarget, order SortOrder) OpOption { - return func(op *Op) { - if target == SortByKey && order == SortAscend { - // If order != SortNone, server fetches the entire key-space, - // and then applies the sort and limit, if provided. - // Since by default the server returns results sorted by keys - // in lexicographically ascending order, the client should ignore - // SortOrder if the target is SortByKey. - order = SortNone - } - op.sort = &SortOption{target, order} - } -} - -// GetPrefixRangeEnd gets the range end of the prefix. -// 'Get(foo, WithPrefix())' is equal to 'Get(foo, WithRange(GetPrefixRangeEnd(foo))'. -func GetPrefixRangeEnd(prefix string) string { - return string(getPrefix([]byte(prefix))) -} - -func getPrefix(key []byte) []byte { - end := make([]byte, len(key)) - copy(end, key) - for i := len(end) - 1; i >= 0; i-- { - if end[i] < 0xff { - end[i] = end[i] + 1 - end = end[:i+1] - return end - } - } - // next prefix does not exist (e.g., 0xffff); - // default to WithFromKey policy - return noPrefixEnd -} - -// WithPrefix enables 'Get', 'Delete', or 'Watch' requests to operate -// on the keys with matching prefix. For example, 'Get(foo, WithPrefix())' -// can return 'foo1', 'foo2', and so on. -func WithPrefix() OpOption { - return func(op *Op) { - if len(op.key) == 0 { - op.key, op.end = []byte{0}, []byte{0} - return - } - op.end = getPrefix(op.key) - } -} - -// WithRange specifies the range of 'Get', 'Delete', 'Watch' requests. -// For example, 'Get' requests with 'WithRange(end)' returns -// the keys in the range [key, end). -// endKey must be lexicographically greater than start key. -func WithRange(endKey string) OpOption { - return func(op *Op) { op.end = []byte(endKey) } -} - -// WithFromKey specifies the range of 'Get', 'Delete', 'Watch' requests -// to be equal or greater than the key in the argument. -func WithFromKey() OpOption { return WithRange("\x00") } - -// WithSerializable makes 'Get' request serializable. By default, -// it's linearizable. Serializable requests are better for lower latency -// requirement. -func WithSerializable() OpOption { - return func(op *Op) { op.serializable = true } -} - -// WithKeysOnly makes the 'Get' request return only the keys and the corresponding -// values will be omitted. -func WithKeysOnly() OpOption { - return func(op *Op) { op.keysOnly = true } -} - -// WithCountOnly makes the 'Get' request return only the count of keys. -func WithCountOnly() OpOption { - return func(op *Op) { op.countOnly = true } -} - -// WithMinModRev filters out keys for Get with modification revisions less than the given revision. -func WithMinModRev(rev int64) OpOption { return func(op *Op) { op.minModRev = rev } } - -// WithMaxModRev filters out keys for Get with modification revisions greater than the given revision. -func WithMaxModRev(rev int64) OpOption { return func(op *Op) { op.maxModRev = rev } } - -// WithMinCreateRev filters out keys for Get with creation revisions less than the given revision. -func WithMinCreateRev(rev int64) OpOption { return func(op *Op) { op.minCreateRev = rev } } - -// WithMaxCreateRev filters out keys for Get with creation revisions greater than the given revision. -func WithMaxCreateRev(rev int64) OpOption { return func(op *Op) { op.maxCreateRev = rev } } - -// WithFirstCreate gets the key with the oldest creation revision in the request range. -func WithFirstCreate() []OpOption { return withTop(SortByCreateRevision, SortAscend) } - -// WithLastCreate gets the key with the latest creation revision in the request range. -func WithLastCreate() []OpOption { return withTop(SortByCreateRevision, SortDescend) } - -// WithFirstKey gets the lexically first key in the request range. -func WithFirstKey() []OpOption { return withTop(SortByKey, SortAscend) } - -// WithLastKey gets the lexically last key in the request range. -func WithLastKey() []OpOption { return withTop(SortByKey, SortDescend) } - -// WithFirstRev gets the key with the oldest modification revision in the request range. -func WithFirstRev() []OpOption { return withTop(SortByModRevision, SortAscend) } - -// WithLastRev gets the key with the latest modification revision in the request range. -func WithLastRev() []OpOption { return withTop(SortByModRevision, SortDescend) } - -// withTop gets the first key over the get's prefix given a sort order -func withTop(target SortTarget, order SortOrder) []OpOption { - return []OpOption{WithPrefix(), WithSort(target, order), WithLimit(1)} -} - -// WithProgressNotify makes watch server send periodic progress updates -// every 10 minutes when there is no incoming events. -// Progress updates have zero events in WatchResponse. -func WithProgressNotify() OpOption { - return func(op *Op) { - op.progressNotify = true - } -} - -// WithCreatedNotify makes watch server sends the created event. -func WithCreatedNotify() OpOption { - return func(op *Op) { - op.createdNotify = true - } -} - -// WithFilterPut discards PUT events from the watcher. -func WithFilterPut() OpOption { - return func(op *Op) { op.filterPut = true } -} - -// WithFilterDelete discards DELETE events from the watcher. -func WithFilterDelete() OpOption { - return func(op *Op) { op.filterDelete = true } -} - -// WithPrevKV gets the previous key-value pair before the event happens. If the previous KV is already compacted, -// nothing will be returned. -func WithPrevKV() OpOption { - return func(op *Op) { - op.prevKV = true - } -} - -// WithIgnoreValue updates the key using its current value. -// This option can not be combined with non-empty values. -// Returns an error if the key does not exist. -func WithIgnoreValue() OpOption { - return func(op *Op) { - op.ignoreValue = true - } -} - -// WithIgnoreLease updates the key using its current lease. -// This option can not be combined with WithLease. -// Returns an error if the key does not exist. -func WithIgnoreLease() OpOption { - return func(op *Op) { - op.ignoreLease = true - } -} - -// LeaseOp represents an Operation that lease can execute. -type LeaseOp struct { - id LeaseID - - // for TimeToLive - attachedKeys bool -} - -// LeaseOption configures lease operations. -type LeaseOption func(*LeaseOp) - -func (op *LeaseOp) applyOpts(opts []LeaseOption) { - for _, opt := range opts { - opt(op) - } -} - -// WithAttachedKeys makes TimeToLive list the keys attached to the given lease ID. -func WithAttachedKeys() LeaseOption { - return func(op *LeaseOp) { op.attachedKeys = true } -} - -func toLeaseTimeToLiveRequest(id LeaseID, opts ...LeaseOption) *pb.LeaseTimeToLiveRequest { - ret := &LeaseOp{id: id} - ret.applyOpts(opts) - return &pb.LeaseTimeToLiveRequest{ID: int64(id), Keys: ret.attachedKeys} -} diff --git a/vendor/github.com/coreos/etcd/clientv3/options.go b/vendor/github.com/coreos/etcd/clientv3/options.go deleted file mode 100644 index fa25811f3b04..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/options.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "math" - - "google.golang.org/grpc" -) - -var ( - // Disable gRPC internal retrial logic - // TODO: enable when gRPC retry is stable (FailFast=false) - // Reference: - // - https://github.com/grpc/grpc-go/issues/1532 - // - https://github.com/grpc/proposal/blob/master/A6-client-retries.md - defaultFailFast = grpc.FailFast(true) - - // client-side request send limit, gRPC default is math.MaxInt32 - // Make sure that "client-side send limit < server-side default send/recv limit" - // Same value as "embed.DefaultMaxRequestBytes" plus gRPC overhead bytes - defaultMaxCallSendMsgSize = grpc.MaxCallSendMsgSize(2 * 1024 * 1024) - - // client-side response receive limit, gRPC default is 4MB - // Make sure that "client-side receive limit >= server-side default send/recv limit" - // because range response can easily exceed request send limits - // Default to math.MaxInt32; writes exceeding server-side send limit fails anyway - defaultMaxCallRecvMsgSize = grpc.MaxCallRecvMsgSize(math.MaxInt32) -) - -// defaultCallOpts defines a list of default "gRPC.CallOption". -// Some options are exposed to "clientv3.Config". -// Defaults will be overridden by the settings in "clientv3.Config". -var defaultCallOpts = []grpc.CallOption{defaultFailFast, defaultMaxCallSendMsgSize, defaultMaxCallRecvMsgSize} - -// MaxLeaseTTL is the maximum lease TTL value -const MaxLeaseTTL = 9000000000 diff --git a/vendor/github.com/coreos/etcd/clientv3/ordering/doc.go b/vendor/github.com/coreos/etcd/clientv3/ordering/doc.go deleted file mode 100644 index 856f33058011..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/ordering/doc.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package ordering is a clientv3 wrapper that caches response header revisions -// to detect ordering violations from stale responses. Users may define a -// policy on how to handle the ordering violation, but typically the client -// should connect to another endpoint and reissue the request. -// -// The most common situation where an ordering violation happens is a client -// reconnects to a partitioned member and issues a serializable read. Since the -// partitioned member is likely behind the last member, it may return a Get -// response based on a store revision older than the store revision used to -// service a prior Get on the former endpoint. -// -// First, create a client: -// -// cli, err := clientv3.New(clientv3.Config{Endpoints: []string{"localhost:2379"}}) -// if err != nil { -// // handle error! -// } -// -// Next, override the client interface with the ordering wrapper: -// -// vf := func(op clientv3.Op, resp clientv3.OpResponse, prevRev int64) error { -// return fmt.Errorf("ordering: issued %+v, got %+v, expected rev=%v", op, resp, prevRev) -// } -// cli.KV = ordering.NewKV(cli.KV, vf) -// -// Now calls using 'cli' will reject order violations with an error. -// -package ordering diff --git a/vendor/github.com/coreos/etcd/clientv3/ordering/kv.go b/vendor/github.com/coreos/etcd/clientv3/ordering/kv.go deleted file mode 100644 index dc9926ec6c2b..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/ordering/kv.go +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ordering - -import ( - "context" - "sync" - - "github.com/coreos/etcd/clientv3" -) - -// kvOrdering ensures that serialized requests do not return -// get with revisions less than the previous -// returned revision. -type kvOrdering struct { - clientv3.KV - orderViolationFunc OrderViolationFunc - prevRev int64 - revMu sync.RWMutex -} - -func NewKV(kv clientv3.KV, orderViolationFunc OrderViolationFunc) *kvOrdering { - return &kvOrdering{kv, orderViolationFunc, 0, sync.RWMutex{}} -} - -func (kv *kvOrdering) getPrevRev() int64 { - kv.revMu.RLock() - defer kv.revMu.RUnlock() - return kv.prevRev -} - -func (kv *kvOrdering) setPrevRev(currRev int64) { - kv.revMu.Lock() - defer kv.revMu.Unlock() - if currRev > kv.prevRev { - kv.prevRev = currRev - } -} - -func (kv *kvOrdering) Get(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error) { - // prevRev is stored in a local variable in order to record the prevRev - // at the beginning of the Get operation, because concurrent - // access to kvOrdering could change the prevRev field in the - // middle of the Get operation. - prevRev := kv.getPrevRev() - op := clientv3.OpGet(key, opts...) - for { - r, err := kv.KV.Do(ctx, op) - if err != nil { - return nil, err - } - resp := r.Get() - if resp.Header.Revision == prevRev { - return resp, nil - } else if resp.Header.Revision > prevRev { - kv.setPrevRev(resp.Header.Revision) - return resp, nil - } - err = kv.orderViolationFunc(op, r, prevRev) - if err != nil { - return nil, err - } - } -} - -func (kv *kvOrdering) Txn(ctx context.Context) clientv3.Txn { - return &txnOrdering{ - kv.KV.Txn(ctx), - kv, - ctx, - sync.Mutex{}, - []clientv3.Cmp{}, - []clientv3.Op{}, - []clientv3.Op{}, - } -} - -// txnOrdering ensures that serialized requests do not return -// txn responses with revisions less than the previous -// returned revision. -type txnOrdering struct { - clientv3.Txn - *kvOrdering - ctx context.Context - mu sync.Mutex - cmps []clientv3.Cmp - thenOps []clientv3.Op - elseOps []clientv3.Op -} - -func (txn *txnOrdering) If(cs ...clientv3.Cmp) clientv3.Txn { - txn.mu.Lock() - defer txn.mu.Unlock() - txn.cmps = cs - txn.Txn.If(cs...) - return txn -} - -func (txn *txnOrdering) Then(ops ...clientv3.Op) clientv3.Txn { - txn.mu.Lock() - defer txn.mu.Unlock() - txn.thenOps = ops - txn.Txn.Then(ops...) - return txn -} - -func (txn *txnOrdering) Else(ops ...clientv3.Op) clientv3.Txn { - txn.mu.Lock() - defer txn.mu.Unlock() - txn.elseOps = ops - txn.Txn.Else(ops...) - return txn -} - -func (txn *txnOrdering) Commit() (*clientv3.TxnResponse, error) { - // prevRev is stored in a local variable in order to record the prevRev - // at the beginning of the Commit operation, because concurrent - // access to txnOrdering could change the prevRev field in the - // middle of the Commit operation. - prevRev := txn.getPrevRev() - opTxn := clientv3.OpTxn(txn.cmps, txn.thenOps, txn.elseOps) - for { - opResp, err := txn.KV.Do(txn.ctx, opTxn) - if err != nil { - return nil, err - } - txnResp := opResp.Txn() - if txnResp.Header.Revision >= prevRev { - txn.setPrevRev(txnResp.Header.Revision) - return txnResp, nil - } - err = txn.orderViolationFunc(opTxn, opResp, prevRev) - if err != nil { - return nil, err - } - } -} diff --git a/vendor/github.com/coreos/etcd/clientv3/ordering/util.go b/vendor/github.com/coreos/etcd/clientv3/ordering/util.go deleted file mode 100644 index 190a5919a525..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/ordering/util.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ordering - -import ( - "errors" - "sync" - "time" - - "github.com/coreos/etcd/clientv3" -) - -type OrderViolationFunc func(op clientv3.Op, resp clientv3.OpResponse, prevRev int64) error - -var ErrNoGreaterRev = errors.New("etcdclient: no cluster members have a revision higher than the previously received revision") - -func NewOrderViolationSwitchEndpointClosure(c clientv3.Client) OrderViolationFunc { - var mu sync.Mutex - violationCount := 0 - return func(op clientv3.Op, resp clientv3.OpResponse, prevRev int64) error { - if violationCount > len(c.Endpoints()) { - return ErrNoGreaterRev - } - mu.Lock() - defer mu.Unlock() - eps := c.Endpoints() - // force client to connect to given endpoint by limiting to a single endpoint - c.SetEndpoints(eps[violationCount%len(eps)]) - // give enough time for operation - time.Sleep(1 * time.Second) - // set available endpoints back to all endpoints in to ensure - // the client has access to all the endpoints. - c.SetEndpoints(eps...) - violationCount++ - return nil - } -} diff --git a/vendor/github.com/coreos/etcd/clientv3/ready_wait.go b/vendor/github.com/coreos/etcd/clientv3/ready_wait.go deleted file mode 100644 index c6ef585b5b41..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/ready_wait.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import "context" - -// TODO: remove this when "FailFast=false" is fixed. -// See https://github.com/grpc/grpc-go/issues/1532. -func readyWait(rpcCtx, clientCtx context.Context, ready <-chan struct{}) error { - select { - case <-ready: - return nil - case <-rpcCtx.Done(): - return rpcCtx.Err() - case <-clientCtx.Done(): - return clientCtx.Err() - } -} diff --git a/vendor/github.com/coreos/etcd/clientv3/retry.go b/vendor/github.com/coreos/etcd/clientv3/retry.go deleted file mode 100644 index 7f89ba641a44..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/retry.go +++ /dev/null @@ -1,496 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -type retryPolicy uint8 - -const ( - repeatable retryPolicy = iota - nonRepeatable -) - -type rpcFunc func(ctx context.Context) error -type retryRPCFunc func(context.Context, rpcFunc, retryPolicy) error -type retryStopErrFunc func(error) bool - -// immutable requests (e.g. Get) should be retried unless it's -// an obvious server-side error (e.g. rpctypes.ErrRequestTooLarge). -// -// "isRepeatableStopError" returns "true" when an immutable request -// is interrupted by server-side or gRPC-side error and its status -// code is not transient (!= codes.Unavailable). -// -// Returning "true" means retry should stop, since client cannot -// handle itself even with retries. -func isRepeatableStopError(err error) bool { - eErr := rpctypes.Error(err) - // always stop retry on etcd errors - if serverErr, ok := eErr.(rpctypes.EtcdError); ok && serverErr.Code() != codes.Unavailable { - return true - } - // only retry if unavailable - ev, _ := status.FromError(err) - return ev.Code() != codes.Unavailable -} - -// mutable requests (e.g. Put, Delete, Txn) should only be retried -// when the status code is codes.Unavailable when initial connection -// has not been established (no pinned endpoint). -// -// "isNonRepeatableStopError" returns "true" when a mutable request -// is interrupted by non-transient error that client cannot handle itself, -// or transient error while the connection has already been established -// (pinned endpoint exists). -// -// Returning "true" means retry should stop, otherwise it violates -// write-at-most-once semantics. -func isNonRepeatableStopError(err error) bool { - ev, _ := status.FromError(err) - if ev.Code() != codes.Unavailable { - return true - } - desc := rpctypes.ErrorDesc(err) - return desc != "there is no address available" && desc != "there is no connection available" -} - -func (c *Client) newRetryWrapper() retryRPCFunc { - return func(rpcCtx context.Context, f rpcFunc, rp retryPolicy) error { - var isStop retryStopErrFunc - switch rp { - case repeatable: - isStop = isRepeatableStopError - case nonRepeatable: - isStop = isNonRepeatableStopError - } - for { - if err := readyWait(rpcCtx, c.ctx, c.balancer.ConnectNotify()); err != nil { - return err - } - pinned := c.balancer.pinned() - err := f(rpcCtx) - if err == nil { - return nil - } - logger.Lvl(4).Infof("clientv3/retry: error %q on pinned endpoint %q", err.Error(), pinned) - - if s, ok := status.FromError(err); ok && (s.Code() == codes.Unavailable || s.Code() == codes.DeadlineExceeded || s.Code() == codes.Internal) { - // mark this before endpoint switch is triggered - c.balancer.hostPortError(pinned, err) - c.balancer.next() - logger.Lvl(4).Infof("clientv3/retry: switching from %q due to error %q", pinned, err.Error()) - } - - if isStop(err) { - return err - } - } - } -} - -func (c *Client) newAuthRetryWrapper(retryf retryRPCFunc) retryRPCFunc { - return func(rpcCtx context.Context, f rpcFunc, rp retryPolicy) error { - for { - pinned := c.balancer.pinned() - err := retryf(rpcCtx, f, rp) - if err == nil { - return nil - } - logger.Lvl(4).Infof("clientv3/auth-retry: error %q on pinned endpoint %q", err.Error(), pinned) - // always stop retry on etcd errors other than invalid auth token - if rpctypes.Error(err) == rpctypes.ErrInvalidAuthToken { - gterr := c.getToken(rpcCtx) - if gterr != nil { - logger.Lvl(4).Infof("clientv3/auth-retry: cannot retry due to error %q(%q) on pinned endpoint %q", err.Error(), gterr.Error(), pinned) - return err // return the original error for simplicity - } - continue - } - return err - } - } -} - -type retryKVClient struct { - kc pb.KVClient - retryf retryRPCFunc -} - -// RetryKVClient implements a KVClient. -func RetryKVClient(c *Client) pb.KVClient { - return &retryKVClient{ - kc: pb.NewKVClient(c.conn), - retryf: c.newAuthRetryWrapper(c.newRetryWrapper()), - } -} -func (rkv *retryKVClient) Range(ctx context.Context, in *pb.RangeRequest, opts ...grpc.CallOption) (resp *pb.RangeResponse, err error) { - err = rkv.retryf(ctx, func(rctx context.Context) error { - resp, err = rkv.kc.Range(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rkv *retryKVClient) Put(ctx context.Context, in *pb.PutRequest, opts ...grpc.CallOption) (resp *pb.PutResponse, err error) { - err = rkv.retryf(ctx, func(rctx context.Context) error { - resp, err = rkv.kc.Put(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rkv *retryKVClient) DeleteRange(ctx context.Context, in *pb.DeleteRangeRequest, opts ...grpc.CallOption) (resp *pb.DeleteRangeResponse, err error) { - err = rkv.retryf(ctx, func(rctx context.Context) error { - resp, err = rkv.kc.DeleteRange(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rkv *retryKVClient) Txn(ctx context.Context, in *pb.TxnRequest, opts ...grpc.CallOption) (resp *pb.TxnResponse, err error) { - // TODO: "repeatable" for read-only txn - err = rkv.retryf(ctx, func(rctx context.Context) error { - resp, err = rkv.kc.Txn(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rkv *retryKVClient) Compact(ctx context.Context, in *pb.CompactionRequest, opts ...grpc.CallOption) (resp *pb.CompactionResponse, err error) { - err = rkv.retryf(ctx, func(rctx context.Context) error { - resp, err = rkv.kc.Compact(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -type retryLeaseClient struct { - lc pb.LeaseClient - retryf retryRPCFunc -} - -// RetryLeaseClient implements a LeaseClient. -func RetryLeaseClient(c *Client) pb.LeaseClient { - return &retryLeaseClient{ - lc: pb.NewLeaseClient(c.conn), - retryf: c.newAuthRetryWrapper(c.newRetryWrapper()), - } -} - -func (rlc *retryLeaseClient) LeaseTimeToLive(ctx context.Context, in *pb.LeaseTimeToLiveRequest, opts ...grpc.CallOption) (resp *pb.LeaseTimeToLiveResponse, err error) { - err = rlc.retryf(ctx, func(rctx context.Context) error { - resp, err = rlc.lc.LeaseTimeToLive(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rlc *retryLeaseClient) LeaseLeases(ctx context.Context, in *pb.LeaseLeasesRequest, opts ...grpc.CallOption) (resp *pb.LeaseLeasesResponse, err error) { - err = rlc.retryf(ctx, func(rctx context.Context) error { - resp, err = rlc.lc.LeaseLeases(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rlc *retryLeaseClient) LeaseGrant(ctx context.Context, in *pb.LeaseGrantRequest, opts ...grpc.CallOption) (resp *pb.LeaseGrantResponse, err error) { - err = rlc.retryf(ctx, func(rctx context.Context) error { - resp, err = rlc.lc.LeaseGrant(rctx, in, opts...) - return err - }, repeatable) - return resp, err - -} - -func (rlc *retryLeaseClient) LeaseRevoke(ctx context.Context, in *pb.LeaseRevokeRequest, opts ...grpc.CallOption) (resp *pb.LeaseRevokeResponse, err error) { - err = rlc.retryf(ctx, func(rctx context.Context) error { - resp, err = rlc.lc.LeaseRevoke(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rlc *retryLeaseClient) LeaseKeepAlive(ctx context.Context, opts ...grpc.CallOption) (stream pb.Lease_LeaseKeepAliveClient, err error) { - err = rlc.retryf(ctx, func(rctx context.Context) error { - stream, err = rlc.lc.LeaseKeepAlive(rctx, opts...) - return err - }, repeatable) - return stream, err -} - -type retryClusterClient struct { - cc pb.ClusterClient - retryf retryRPCFunc -} - -// RetryClusterClient implements a ClusterClient. -func RetryClusterClient(c *Client) pb.ClusterClient { - return &retryClusterClient{ - cc: pb.NewClusterClient(c.conn), - retryf: c.newRetryWrapper(), - } -} - -func (rcc *retryClusterClient) MemberList(ctx context.Context, in *pb.MemberListRequest, opts ...grpc.CallOption) (resp *pb.MemberListResponse, err error) { - err = rcc.retryf(ctx, func(rctx context.Context) error { - resp, err = rcc.cc.MemberList(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rcc *retryClusterClient) MemberAdd(ctx context.Context, in *pb.MemberAddRequest, opts ...grpc.CallOption) (resp *pb.MemberAddResponse, err error) { - err = rcc.retryf(ctx, func(rctx context.Context) error { - resp, err = rcc.cc.MemberAdd(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rcc *retryClusterClient) MemberRemove(ctx context.Context, in *pb.MemberRemoveRequest, opts ...grpc.CallOption) (resp *pb.MemberRemoveResponse, err error) { - err = rcc.retryf(ctx, func(rctx context.Context) error { - resp, err = rcc.cc.MemberRemove(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rcc *retryClusterClient) MemberUpdate(ctx context.Context, in *pb.MemberUpdateRequest, opts ...grpc.CallOption) (resp *pb.MemberUpdateResponse, err error) { - err = rcc.retryf(ctx, func(rctx context.Context) error { - resp, err = rcc.cc.MemberUpdate(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -type retryMaintenanceClient struct { - mc pb.MaintenanceClient - retryf retryRPCFunc -} - -// RetryMaintenanceClient implements a Maintenance. -func RetryMaintenanceClient(c *Client, conn *grpc.ClientConn) pb.MaintenanceClient { - return &retryMaintenanceClient{ - mc: pb.NewMaintenanceClient(conn), - retryf: c.newRetryWrapper(), - } -} - -func (rmc *retryMaintenanceClient) Alarm(ctx context.Context, in *pb.AlarmRequest, opts ...grpc.CallOption) (resp *pb.AlarmResponse, err error) { - err = rmc.retryf(ctx, func(rctx context.Context) error { - resp, err = rmc.mc.Alarm(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rmc *retryMaintenanceClient) Status(ctx context.Context, in *pb.StatusRequest, opts ...grpc.CallOption) (resp *pb.StatusResponse, err error) { - err = rmc.retryf(ctx, func(rctx context.Context) error { - resp, err = rmc.mc.Status(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rmc *retryMaintenanceClient) Hash(ctx context.Context, in *pb.HashRequest, opts ...grpc.CallOption) (resp *pb.HashResponse, err error) { - err = rmc.retryf(ctx, func(rctx context.Context) error { - resp, err = rmc.mc.Hash(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rmc *retryMaintenanceClient) HashKV(ctx context.Context, in *pb.HashKVRequest, opts ...grpc.CallOption) (resp *pb.HashKVResponse, err error) { - err = rmc.retryf(ctx, func(rctx context.Context) error { - resp, err = rmc.mc.HashKV(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rmc *retryMaintenanceClient) Snapshot(ctx context.Context, in *pb.SnapshotRequest, opts ...grpc.CallOption) (stream pb.Maintenance_SnapshotClient, err error) { - err = rmc.retryf(ctx, func(rctx context.Context) error { - stream, err = rmc.mc.Snapshot(rctx, in, opts...) - return err - }, repeatable) - return stream, err -} - -func (rmc *retryMaintenanceClient) MoveLeader(ctx context.Context, in *pb.MoveLeaderRequest, opts ...grpc.CallOption) (resp *pb.MoveLeaderResponse, err error) { - err = rmc.retryf(ctx, func(rctx context.Context) error { - resp, err = rmc.mc.MoveLeader(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rmc *retryMaintenanceClient) Defragment(ctx context.Context, in *pb.DefragmentRequest, opts ...grpc.CallOption) (resp *pb.DefragmentResponse, err error) { - err = rmc.retryf(ctx, func(rctx context.Context) error { - resp, err = rmc.mc.Defragment(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -type retryAuthClient struct { - ac pb.AuthClient - retryf retryRPCFunc -} - -// RetryAuthClient implements a AuthClient. -func RetryAuthClient(c *Client) pb.AuthClient { - return &retryAuthClient{ - ac: pb.NewAuthClient(c.conn), - retryf: c.newRetryWrapper(), - } -} - -func (rac *retryAuthClient) UserList(ctx context.Context, in *pb.AuthUserListRequest, opts ...grpc.CallOption) (resp *pb.AuthUserListResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.UserList(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rac *retryAuthClient) UserGet(ctx context.Context, in *pb.AuthUserGetRequest, opts ...grpc.CallOption) (resp *pb.AuthUserGetResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.UserGet(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rac *retryAuthClient) RoleGet(ctx context.Context, in *pb.AuthRoleGetRequest, opts ...grpc.CallOption) (resp *pb.AuthRoleGetResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.RoleGet(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rac *retryAuthClient) RoleList(ctx context.Context, in *pb.AuthRoleListRequest, opts ...grpc.CallOption) (resp *pb.AuthRoleListResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.RoleList(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rac *retryAuthClient) AuthEnable(ctx context.Context, in *pb.AuthEnableRequest, opts ...grpc.CallOption) (resp *pb.AuthEnableResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.AuthEnable(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) AuthDisable(ctx context.Context, in *pb.AuthDisableRequest, opts ...grpc.CallOption) (resp *pb.AuthDisableResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.AuthDisable(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) UserAdd(ctx context.Context, in *pb.AuthUserAddRequest, opts ...grpc.CallOption) (resp *pb.AuthUserAddResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.UserAdd(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) UserDelete(ctx context.Context, in *pb.AuthUserDeleteRequest, opts ...grpc.CallOption) (resp *pb.AuthUserDeleteResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.UserDelete(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) UserChangePassword(ctx context.Context, in *pb.AuthUserChangePasswordRequest, opts ...grpc.CallOption) (resp *pb.AuthUserChangePasswordResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.UserChangePassword(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) UserGrantRole(ctx context.Context, in *pb.AuthUserGrantRoleRequest, opts ...grpc.CallOption) (resp *pb.AuthUserGrantRoleResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.UserGrantRole(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) UserRevokeRole(ctx context.Context, in *pb.AuthUserRevokeRoleRequest, opts ...grpc.CallOption) (resp *pb.AuthUserRevokeRoleResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.UserRevokeRole(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) RoleAdd(ctx context.Context, in *pb.AuthRoleAddRequest, opts ...grpc.CallOption) (resp *pb.AuthRoleAddResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.RoleAdd(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) RoleDelete(ctx context.Context, in *pb.AuthRoleDeleteRequest, opts ...grpc.CallOption) (resp *pb.AuthRoleDeleteResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.RoleDelete(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) RoleGrantPermission(ctx context.Context, in *pb.AuthRoleGrantPermissionRequest, opts ...grpc.CallOption) (resp *pb.AuthRoleGrantPermissionResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.RoleGrantPermission(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) RoleRevokePermission(ctx context.Context, in *pb.AuthRoleRevokePermissionRequest, opts ...grpc.CallOption) (resp *pb.AuthRoleRevokePermissionResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.RoleRevokePermission(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) Authenticate(ctx context.Context, in *pb.AuthenticateRequest, opts ...grpc.CallOption) (resp *pb.AuthenticateResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.Authenticate(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} diff --git a/vendor/github.com/coreos/etcd/clientv3/sort.go b/vendor/github.com/coreos/etcd/clientv3/sort.go deleted file mode 100644 index 2bb9d9a13b78..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/sort.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -type SortTarget int -type SortOrder int - -const ( - SortNone SortOrder = iota - SortAscend - SortDescend -) - -const ( - SortByKey SortTarget = iota - SortByVersion - SortByCreateRevision - SortByModRevision - SortByValue -) - -type SortOption struct { - Target SortTarget - Order SortOrder -} diff --git a/vendor/github.com/coreos/etcd/clientv3/txn.go b/vendor/github.com/coreos/etcd/clientv3/txn.go deleted file mode 100644 index c3c2d2485693..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/txn.go +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - "sync" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" -) - -// Txn is the interface that wraps mini-transactions. -// -// Txn(context.TODO()).If( -// Compare(Value(k1), ">", v1), -// Compare(Version(k1), "=", 2) -// ).Then( -// OpPut(k2,v2), OpPut(k3,v3) -// ).Else( -// OpPut(k4,v4), OpPut(k5,v5) -// ).Commit() -// -type Txn interface { - // If takes a list of comparison. If all comparisons passed in succeed, - // the operations passed into Then() will be executed. Or the operations - // passed into Else() will be executed. - If(cs ...Cmp) Txn - - // Then takes a list of operations. The Ops list will be executed, if the - // comparisons passed in If() succeed. - Then(ops ...Op) Txn - - // Else takes a list of operations. The Ops list will be executed, if the - // comparisons passed in If() fail. - Else(ops ...Op) Txn - - // Commit tries to commit the transaction. - Commit() (*TxnResponse, error) -} - -type txn struct { - kv *kv - ctx context.Context - - mu sync.Mutex - cif bool - cthen bool - celse bool - - isWrite bool - - cmps []*pb.Compare - - sus []*pb.RequestOp - fas []*pb.RequestOp - - callOpts []grpc.CallOption -} - -func (txn *txn) If(cs ...Cmp) Txn { - txn.mu.Lock() - defer txn.mu.Unlock() - - if txn.cif { - panic("cannot call If twice!") - } - - if txn.cthen { - panic("cannot call If after Then!") - } - - if txn.celse { - panic("cannot call If after Else!") - } - - txn.cif = true - - for i := range cs { - txn.cmps = append(txn.cmps, (*pb.Compare)(&cs[i])) - } - - return txn -} - -func (txn *txn) Then(ops ...Op) Txn { - txn.mu.Lock() - defer txn.mu.Unlock() - - if txn.cthen { - panic("cannot call Then twice!") - } - if txn.celse { - panic("cannot call Then after Else!") - } - - txn.cthen = true - - for _, op := range ops { - txn.isWrite = txn.isWrite || op.isWrite() - txn.sus = append(txn.sus, op.toRequestOp()) - } - - return txn -} - -func (txn *txn) Else(ops ...Op) Txn { - txn.mu.Lock() - defer txn.mu.Unlock() - - if txn.celse { - panic("cannot call Else twice!") - } - - txn.celse = true - - for _, op := range ops { - txn.isWrite = txn.isWrite || op.isWrite() - txn.fas = append(txn.fas, op.toRequestOp()) - } - - return txn -} - -func (txn *txn) Commit() (*TxnResponse, error) { - txn.mu.Lock() - defer txn.mu.Unlock() - - r := &pb.TxnRequest{Compare: txn.cmps, Success: txn.sus, Failure: txn.fas} - - var resp *pb.TxnResponse - var err error - resp, err = txn.kv.remote.Txn(txn.ctx, r, txn.callOpts...) - if err != nil { - return nil, toErr(txn.ctx, err) - } - return (*TxnResponse)(resp), nil -} diff --git a/vendor/github.com/coreos/etcd/clientv3/watch.go b/vendor/github.com/coreos/etcd/clientv3/watch.go deleted file mode 100644 index d7633850e7c9..000000000000 --- a/vendor/github.com/coreos/etcd/clientv3/watch.go +++ /dev/null @@ -1,828 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - "fmt" - "sync" - "time" - - v3rpc "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - mvccpb "github.com/coreos/etcd/mvcc/mvccpb" - - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" -) - -const ( - EventTypeDelete = mvccpb.DELETE - EventTypePut = mvccpb.PUT - - closeSendErrTimeout = 250 * time.Millisecond -) - -type Event mvccpb.Event - -type WatchChan <-chan WatchResponse - -type Watcher interface { - // Watch watches on a key or prefix. The watched events will be returned - // through the returned channel. If revisions waiting to be sent over the - // watch are compacted, then the watch will be canceled by the server, the - // client will post a compacted error watch response, and the channel will close. - Watch(ctx context.Context, key string, opts ...OpOption) WatchChan - - // Close closes the watcher and cancels all watch requests. - Close() error -} - -type WatchResponse struct { - Header pb.ResponseHeader - Events []*Event - - // CompactRevision is the minimum revision the watcher may receive. - CompactRevision int64 - - // Canceled is used to indicate watch failure. - // If the watch failed and the stream was about to close, before the channel is closed, - // the channel sends a final response that has Canceled set to true with a non-nil Err(). - Canceled bool - - // Created is used to indicate the creation of the watcher. - Created bool - - closeErr error - - // cancelReason is a reason of canceling watch - cancelReason string -} - -// IsCreate returns true if the event tells that the key is newly created. -func (e *Event) IsCreate() bool { - return e.Type == EventTypePut && e.Kv.CreateRevision == e.Kv.ModRevision -} - -// IsModify returns true if the event tells that a new value is put on existing key. -func (e *Event) IsModify() bool { - return e.Type == EventTypePut && e.Kv.CreateRevision != e.Kv.ModRevision -} - -// Err is the error value if this WatchResponse holds an error. -func (wr *WatchResponse) Err() error { - switch { - case wr.closeErr != nil: - return v3rpc.Error(wr.closeErr) - case wr.CompactRevision != 0: - return v3rpc.ErrCompacted - case wr.Canceled: - if len(wr.cancelReason) != 0 { - return v3rpc.Error(status.Error(codes.FailedPrecondition, wr.cancelReason)) - } - return v3rpc.ErrFutureRev - } - return nil -} - -// IsProgressNotify returns true if the WatchResponse is progress notification. -func (wr *WatchResponse) IsProgressNotify() bool { - return len(wr.Events) == 0 && !wr.Canceled && !wr.Created && wr.CompactRevision == 0 && wr.Header.Revision != 0 -} - -// watcher implements the Watcher interface -type watcher struct { - remote pb.WatchClient - callOpts []grpc.CallOption - - // mu protects the grpc streams map - mu sync.RWMutex - - // streams holds all the active grpc streams keyed by ctx value. - streams map[string]*watchGrpcStream -} - -// watchGrpcStream tracks all watch resources attached to a single grpc stream. -type watchGrpcStream struct { - owner *watcher - remote pb.WatchClient - callOpts []grpc.CallOption - - // ctx controls internal remote.Watch requests - ctx context.Context - // ctxKey is the key used when looking up this stream's context - ctxKey string - cancel context.CancelFunc - - // substreams holds all active watchers on this grpc stream - substreams map[int64]*watcherStream - // resuming holds all resuming watchers on this grpc stream - resuming []*watcherStream - - // reqc sends a watch request from Watch() to the main goroutine - reqc chan *watchRequest - // respc receives data from the watch client - respc chan *pb.WatchResponse - // donec closes to broadcast shutdown - donec chan struct{} - // errc transmits errors from grpc Recv to the watch stream reconnect logic - errc chan error - // closingc gets the watcherStream of closing watchers - closingc chan *watcherStream - // wg is Done when all substream goroutines have exited - wg sync.WaitGroup - - // resumec closes to signal that all substreams should begin resuming - resumec chan struct{} - // closeErr is the error that closed the watch stream - closeErr error -} - -// watchRequest is issued by the subscriber to start a new watcher -type watchRequest struct { - ctx context.Context - key string - end string - rev int64 - // send created notification event if this field is true - createdNotify bool - // progressNotify is for progress updates - progressNotify bool - // filters is the list of events to filter out - filters []pb.WatchCreateRequest_FilterType - // get the previous key-value pair before the event happens - prevKV bool - // retc receives a chan WatchResponse once the watcher is established - retc chan chan WatchResponse -} - -// watcherStream represents a registered watcher -type watcherStream struct { - // initReq is the request that initiated this request - initReq watchRequest - - // outc publishes watch responses to subscriber - outc chan WatchResponse - // recvc buffers watch responses before publishing - recvc chan *WatchResponse - // donec closes when the watcherStream goroutine stops. - donec chan struct{} - // closing is set to true when stream should be scheduled to shutdown. - closing bool - // id is the registered watch id on the grpc stream - id int64 - - // buf holds all events received from etcd but not yet consumed by the client - buf []*WatchResponse -} - -func NewWatcher(c *Client) Watcher { - return NewWatchFromWatchClient(pb.NewWatchClient(c.conn), c) -} - -func NewWatchFromWatchClient(wc pb.WatchClient, c *Client) Watcher { - w := &watcher{ - remote: wc, - streams: make(map[string]*watchGrpcStream), - } - if c != nil { - w.callOpts = c.callOpts - } - return w -} - -// never closes -var valCtxCh = make(chan struct{}) -var zeroTime = time.Unix(0, 0) - -// ctx with only the values; never Done -type valCtx struct{ context.Context } - -func (vc *valCtx) Deadline() (time.Time, bool) { return zeroTime, false } -func (vc *valCtx) Done() <-chan struct{} { return valCtxCh } -func (vc *valCtx) Err() error { return nil } - -func (w *watcher) newWatcherGrpcStream(inctx context.Context) *watchGrpcStream { - ctx, cancel := context.WithCancel(&valCtx{inctx}) - wgs := &watchGrpcStream{ - owner: w, - remote: w.remote, - callOpts: w.callOpts, - ctx: ctx, - ctxKey: streamKeyFromCtx(inctx), - cancel: cancel, - substreams: make(map[int64]*watcherStream), - respc: make(chan *pb.WatchResponse), - reqc: make(chan *watchRequest), - donec: make(chan struct{}), - errc: make(chan error, 1), - closingc: make(chan *watcherStream), - resumec: make(chan struct{}), - } - go wgs.run() - return wgs -} - -// Watch posts a watch request to run() and waits for a new watcher channel -func (w *watcher) Watch(ctx context.Context, key string, opts ...OpOption) WatchChan { - ow := opWatch(key, opts...) - - var filters []pb.WatchCreateRequest_FilterType - if ow.filterPut { - filters = append(filters, pb.WatchCreateRequest_NOPUT) - } - if ow.filterDelete { - filters = append(filters, pb.WatchCreateRequest_NODELETE) - } - - wr := &watchRequest{ - ctx: ctx, - createdNotify: ow.createdNotify, - key: string(ow.key), - end: string(ow.end), - rev: ow.rev, - progressNotify: ow.progressNotify, - filters: filters, - prevKV: ow.prevKV, - retc: make(chan chan WatchResponse, 1), - } - - ok := false - ctxKey := streamKeyFromCtx(ctx) - - // find or allocate appropriate grpc watch stream - w.mu.Lock() - if w.streams == nil { - // closed - w.mu.Unlock() - ch := make(chan WatchResponse) - close(ch) - return ch - } - wgs := w.streams[ctxKey] - if wgs == nil { - wgs = w.newWatcherGrpcStream(ctx) - w.streams[ctxKey] = wgs - } - donec := wgs.donec - reqc := wgs.reqc - w.mu.Unlock() - - // couldn't create channel; return closed channel - closeCh := make(chan WatchResponse, 1) - - // submit request - select { - case reqc <- wr: - ok = true - case <-wr.ctx.Done(): - case <-donec: - if wgs.closeErr != nil { - closeCh <- WatchResponse{closeErr: wgs.closeErr} - break - } - // retry; may have dropped stream from no ctxs - return w.Watch(ctx, key, opts...) - } - - // receive channel - if ok { - select { - case ret := <-wr.retc: - return ret - case <-ctx.Done(): - case <-donec: - if wgs.closeErr != nil { - closeCh <- WatchResponse{closeErr: wgs.closeErr} - break - } - // retry; may have dropped stream from no ctxs - return w.Watch(ctx, key, opts...) - } - } - - close(closeCh) - return closeCh -} - -func (w *watcher) Close() (err error) { - w.mu.Lock() - streams := w.streams - w.streams = nil - w.mu.Unlock() - for _, wgs := range streams { - if werr := wgs.close(); werr != nil { - err = werr - } - } - return err -} - -func (w *watchGrpcStream) close() (err error) { - w.cancel() - <-w.donec - select { - case err = <-w.errc: - default: - } - return toErr(w.ctx, err) -} - -func (w *watcher) closeStream(wgs *watchGrpcStream) { - w.mu.Lock() - close(wgs.donec) - wgs.cancel() - if w.streams != nil { - delete(w.streams, wgs.ctxKey) - } - w.mu.Unlock() -} - -func (w *watchGrpcStream) addSubstream(resp *pb.WatchResponse, ws *watcherStream) { - if resp.WatchId == -1 { - // failed; no channel - close(ws.recvc) - return - } - ws.id = resp.WatchId - w.substreams[ws.id] = ws -} - -func (w *watchGrpcStream) sendCloseSubstream(ws *watcherStream, resp *WatchResponse) { - select { - case ws.outc <- *resp: - case <-ws.initReq.ctx.Done(): - case <-time.After(closeSendErrTimeout): - } - close(ws.outc) -} - -func (w *watchGrpcStream) closeSubstream(ws *watcherStream) { - // send channel response in case stream was never established - select { - case ws.initReq.retc <- ws.outc: - default: - } - // close subscriber's channel - if closeErr := w.closeErr; closeErr != nil && ws.initReq.ctx.Err() == nil { - go w.sendCloseSubstream(ws, &WatchResponse{closeErr: w.closeErr}) - } else if ws.outc != nil { - close(ws.outc) - } - if ws.id != -1 { - delete(w.substreams, ws.id) - return - } - for i := range w.resuming { - if w.resuming[i] == ws { - w.resuming[i] = nil - return - } - } -} - -// run is the root of the goroutines for managing a watcher client -func (w *watchGrpcStream) run() { - var wc pb.Watch_WatchClient - var closeErr error - - // substreams marked to close but goroutine still running; needed for - // avoiding double-closing recvc on grpc stream teardown - closing := make(map[*watcherStream]struct{}) - - defer func() { - w.closeErr = closeErr - // shutdown substreams and resuming substreams - for _, ws := range w.substreams { - if _, ok := closing[ws]; !ok { - close(ws.recvc) - closing[ws] = struct{}{} - } - } - for _, ws := range w.resuming { - if _, ok := closing[ws]; ws != nil && !ok { - close(ws.recvc) - closing[ws] = struct{}{} - } - } - w.joinSubstreams() - for range closing { - w.closeSubstream(<-w.closingc) - } - w.wg.Wait() - w.owner.closeStream(w) - }() - - // start a stream with the etcd grpc server - if wc, closeErr = w.newWatchClient(); closeErr != nil { - return - } - - cancelSet := make(map[int64]struct{}) - - for { - select { - // Watch() requested - case wreq := <-w.reqc: - outc := make(chan WatchResponse, 1) - ws := &watcherStream{ - initReq: *wreq, - id: -1, - outc: outc, - // unbuffered so resumes won't cause repeat events - recvc: make(chan *WatchResponse), - } - - ws.donec = make(chan struct{}) - w.wg.Add(1) - go w.serveSubstream(ws, w.resumec) - - // queue up for watcher creation/resume - w.resuming = append(w.resuming, ws) - if len(w.resuming) == 1 { - // head of resume queue, can register a new watcher - wc.Send(ws.initReq.toPB()) - } - // New events from the watch client - case pbresp := <-w.respc: - switch { - case pbresp.Created: - // response to head of queue creation - if ws := w.resuming[0]; ws != nil { - w.addSubstream(pbresp, ws) - w.dispatchEvent(pbresp) - w.resuming[0] = nil - } - if ws := w.nextResume(); ws != nil { - wc.Send(ws.initReq.toPB()) - } - case pbresp.Canceled && pbresp.CompactRevision == 0: - delete(cancelSet, pbresp.WatchId) - if ws, ok := w.substreams[pbresp.WatchId]; ok { - // signal to stream goroutine to update closingc - close(ws.recvc) - closing[ws] = struct{}{} - } - default: - // dispatch to appropriate watch stream - if ok := w.dispatchEvent(pbresp); ok { - break - } - // watch response on unexpected watch id; cancel id - if _, ok := cancelSet[pbresp.WatchId]; ok { - break - } - cancelSet[pbresp.WatchId] = struct{}{} - cr := &pb.WatchRequest_CancelRequest{ - CancelRequest: &pb.WatchCancelRequest{ - WatchId: pbresp.WatchId, - }, - } - req := &pb.WatchRequest{RequestUnion: cr} - wc.Send(req) - } - // watch client failed on Recv; spawn another if possible - case err := <-w.errc: - if isHaltErr(w.ctx, err) || toErr(w.ctx, err) == v3rpc.ErrNoLeader { - closeErr = err - return - } - if wc, closeErr = w.newWatchClient(); closeErr != nil { - return - } - if ws := w.nextResume(); ws != nil { - wc.Send(ws.initReq.toPB()) - } - cancelSet = make(map[int64]struct{}) - case <-w.ctx.Done(): - return - case ws := <-w.closingc: - w.closeSubstream(ws) - delete(closing, ws) - if len(w.substreams)+len(w.resuming) == 0 { - // no more watchers on this stream, shutdown - return - } - } - } -} - -// nextResume chooses the next resuming to register with the grpc stream. Abandoned -// streams are marked as nil in the queue since the head must wait for its inflight registration. -func (w *watchGrpcStream) nextResume() *watcherStream { - for len(w.resuming) != 0 { - if w.resuming[0] != nil { - return w.resuming[0] - } - w.resuming = w.resuming[1:len(w.resuming)] - } - return nil -} - -// dispatchEvent sends a WatchResponse to the appropriate watcher stream -func (w *watchGrpcStream) dispatchEvent(pbresp *pb.WatchResponse) bool { - events := make([]*Event, len(pbresp.Events)) - for i, ev := range pbresp.Events { - events[i] = (*Event)(ev) - } - wr := &WatchResponse{ - Header: *pbresp.Header, - Events: events, - CompactRevision: pbresp.CompactRevision, - Created: pbresp.Created, - Canceled: pbresp.Canceled, - cancelReason: pbresp.CancelReason, - } - ws, ok := w.substreams[pbresp.WatchId] - if !ok { - return false - } - select { - case ws.recvc <- wr: - case <-ws.donec: - return false - } - return true -} - -// serveWatchClient forwards messages from the grpc stream to run() -func (w *watchGrpcStream) serveWatchClient(wc pb.Watch_WatchClient) { - for { - resp, err := wc.Recv() - if err != nil { - select { - case w.errc <- err: - case <-w.donec: - } - return - } - select { - case w.respc <- resp: - case <-w.donec: - return - } - } -} - -// serveSubstream forwards watch responses from run() to the subscriber -func (w *watchGrpcStream) serveSubstream(ws *watcherStream, resumec chan struct{}) { - if ws.closing { - panic("created substream goroutine but substream is closing") - } - - // nextRev is the minimum expected next revision - nextRev := ws.initReq.rev - resuming := false - defer func() { - if !resuming { - ws.closing = true - } - close(ws.donec) - if !resuming { - w.closingc <- ws - } - w.wg.Done() - }() - - emptyWr := &WatchResponse{} - for { - curWr := emptyWr - outc := ws.outc - - if len(ws.buf) > 0 { - curWr = ws.buf[0] - } else { - outc = nil - } - select { - case outc <- *curWr: - if ws.buf[0].Err() != nil { - return - } - ws.buf[0] = nil - ws.buf = ws.buf[1:] - case wr, ok := <-ws.recvc: - if !ok { - // shutdown from closeSubstream - return - } - - if wr.Created { - if ws.initReq.retc != nil { - ws.initReq.retc <- ws.outc - // to prevent next write from taking the slot in buffered channel - // and posting duplicate create events - ws.initReq.retc = nil - - // send first creation event only if requested - if ws.initReq.createdNotify { - ws.outc <- *wr - } - // once the watch channel is returned, a current revision - // watch must resume at the store revision. This is necessary - // for the following case to work as expected: - // wch := m1.Watch("a") - // m2.Put("a", "b") - // <-wch - // If the revision is only bound on the first observed event, - // if wch is disconnected before the Put is issued, then reconnects - // after it is committed, it'll miss the Put. - if ws.initReq.rev == 0 { - nextRev = wr.Header.Revision - } - } - } else { - // current progress of watch; <= store revision - nextRev = wr.Header.Revision - } - - if len(wr.Events) > 0 { - nextRev = wr.Events[len(wr.Events)-1].Kv.ModRevision + 1 - } - ws.initReq.rev = nextRev - - // created event is already sent above, - // watcher should not post duplicate events - if wr.Created { - continue - } - - // TODO pause channel if buffer gets too large - ws.buf = append(ws.buf, wr) - case <-w.ctx.Done(): - return - case <-ws.initReq.ctx.Done(): - return - case <-resumec: - resuming = true - return - } - } - // lazily send cancel message if events on missing id -} - -func (w *watchGrpcStream) newWatchClient() (pb.Watch_WatchClient, error) { - // mark all substreams as resuming - close(w.resumec) - w.resumec = make(chan struct{}) - w.joinSubstreams() - for _, ws := range w.substreams { - ws.id = -1 - w.resuming = append(w.resuming, ws) - } - // strip out nils, if any - var resuming []*watcherStream - for _, ws := range w.resuming { - if ws != nil { - resuming = append(resuming, ws) - } - } - w.resuming = resuming - w.substreams = make(map[int64]*watcherStream) - - // connect to grpc stream while accepting watcher cancelation - stopc := make(chan struct{}) - donec := w.waitCancelSubstreams(stopc) - wc, err := w.openWatchClient() - close(stopc) - <-donec - - // serve all non-closing streams, even if there's a client error - // so that the teardown path can shutdown the streams as expected. - for _, ws := range w.resuming { - if ws.closing { - continue - } - ws.donec = make(chan struct{}) - w.wg.Add(1) - go w.serveSubstream(ws, w.resumec) - } - - if err != nil { - return nil, v3rpc.Error(err) - } - - // receive data from new grpc stream - go w.serveWatchClient(wc) - return wc, nil -} - -func (w *watchGrpcStream) waitCancelSubstreams(stopc <-chan struct{}) <-chan struct{} { - var wg sync.WaitGroup - wg.Add(len(w.resuming)) - donec := make(chan struct{}) - for i := range w.resuming { - go func(ws *watcherStream) { - defer wg.Done() - if ws.closing { - if ws.initReq.ctx.Err() != nil && ws.outc != nil { - close(ws.outc) - ws.outc = nil - } - return - } - select { - case <-ws.initReq.ctx.Done(): - // closed ws will be removed from resuming - ws.closing = true - close(ws.outc) - ws.outc = nil - w.wg.Add(1) - go func() { - defer w.wg.Done() - w.closingc <- ws - }() - case <-stopc: - } - }(w.resuming[i]) - } - go func() { - defer close(donec) - wg.Wait() - }() - return donec -} - -// joinSubstreams waits for all substream goroutines to complete. -func (w *watchGrpcStream) joinSubstreams() { - for _, ws := range w.substreams { - <-ws.donec - } - for _, ws := range w.resuming { - if ws != nil { - <-ws.donec - } - } -} - -var maxBackoff = 100 * time.Millisecond - -// openWatchClient retries opening a watch client until success or halt. -// manually retry in case "ws==nil && err==nil" -// TODO: remove FailFast=false -func (w *watchGrpcStream) openWatchClient() (ws pb.Watch_WatchClient, err error) { - backoff := time.Millisecond - for { - select { - case <-w.ctx.Done(): - if err == nil { - return nil, w.ctx.Err() - } - return nil, err - default: - } - if ws, err = w.remote.Watch(w.ctx, w.callOpts...); ws != nil && err == nil { - break - } - if isHaltErr(w.ctx, err) { - return nil, v3rpc.Error(err) - } - if isUnavailableErr(w.ctx, err) { - // retry, but backoff - if backoff < maxBackoff { - // 25% backoff factor - backoff = backoff + backoff/4 - if backoff > maxBackoff { - backoff = maxBackoff - } - } - time.Sleep(backoff) - } - } - return ws, nil -} - -// toPB converts an internal watch request structure to its protobuf WatchRequest structure. -func (wr *watchRequest) toPB() *pb.WatchRequest { - req := &pb.WatchCreateRequest{ - StartRevision: wr.rev, - Key: []byte(wr.key), - RangeEnd: []byte(wr.end), - ProgressNotify: wr.progressNotify, - Filters: wr.filters, - PrevKv: wr.prevKV, - } - cr := &pb.WatchRequest_CreateRequest{CreateRequest: req} - return &pb.WatchRequest{RequestUnion: cr} -} - -func streamKeyFromCtx(ctx context.Context) string { - if md, ok := metadata.FromOutgoingContext(ctx); ok { - return fmt.Sprintf("%+v", md) - } - return "" -} diff --git a/vendor/github.com/coreos/etcd/compactor/compactor.go b/vendor/github.com/coreos/etcd/compactor/compactor.go deleted file mode 100644 index 8100b69385ad..000000000000 --- a/vendor/github.com/coreos/etcd/compactor/compactor.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package compactor - -import ( - "context" - "fmt" - "time" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "github.com/coreos/pkg/capnslog" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "compactor") -) - -const ( - ModePeriodic = "periodic" - ModeRevision = "revision" -) - -// Compactor purges old log from the storage periodically. -type Compactor interface { - // Run starts the main loop of the compactor in background. - // Use Stop() to halt the loop and release the resource. - Run() - // Stop halts the main loop of the compactor. - Stop() - // Pause temporally suspend the compactor not to run compaction. Resume() to unpose. - Pause() - // Resume restarts the compactor suspended by Pause(). - Resume() -} - -type Compactable interface { - Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error) -} - -type RevGetter interface { - Rev() int64 -} - -func New(mode string, retention time.Duration, rg RevGetter, c Compactable) (Compactor, error) { - switch mode { - case ModePeriodic: - return NewPeriodic(retention, rg, c), nil - case ModeRevision: - return NewRevision(int64(retention), rg, c), nil - default: - return nil, fmt.Errorf("unsupported compaction mode %s", mode) - } -} diff --git a/vendor/github.com/coreos/etcd/compactor/doc.go b/vendor/github.com/coreos/etcd/compactor/doc.go deleted file mode 100644 index cb158340e493..000000000000 --- a/vendor/github.com/coreos/etcd/compactor/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package compactor implements automated policies for compacting etcd's mvcc storage. -package compactor diff --git a/vendor/github.com/coreos/etcd/compactor/periodic.go b/vendor/github.com/coreos/etcd/compactor/periodic.go deleted file mode 100644 index 9d9164e9c5c6..000000000000 --- a/vendor/github.com/coreos/etcd/compactor/periodic.go +++ /dev/null @@ -1,191 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package compactor - -import ( - "context" - "sync" - "time" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc" - - "github.com/jonboulle/clockwork" -) - -// Periodic compacts the log by purging revisions older than -// the configured retention time. -type Periodic struct { - clock clockwork.Clock - period time.Duration - - rg RevGetter - c Compactable - - revs []int64 - ctx context.Context - cancel context.CancelFunc - - // mu protects paused - mu sync.RWMutex - paused bool -} - -// NewPeriodic creates a new instance of Periodic compactor that purges -// the log older than h Duration. -func NewPeriodic(h time.Duration, rg RevGetter, c Compactable) *Periodic { - return newPeriodic(clockwork.NewRealClock(), h, rg, c) -} - -func newPeriodic(clock clockwork.Clock, h time.Duration, rg RevGetter, c Compactable) *Periodic { - t := &Periodic{ - clock: clock, - period: h, - rg: rg, - c: c, - revs: make([]int64, 0), - } - t.ctx, t.cancel = context.WithCancel(context.Background()) - return t -} - -/* -Compaction period 1-hour: - 1. compute compaction period, which is 1-hour - 2. record revisions for every 1/10 of 1-hour (6-minute) - 3. keep recording revisions with no compaction for first 1-hour - 4. do compact with revs[0] - - success? contiue on for-loop and move sliding window; revs = revs[1:] - - failure? update revs, and retry after 1/10 of 1-hour (6-minute) - -Compaction period 24-hour: - 1. compute compaction period, which is 1-hour - 2. record revisions for every 1/10 of 1-hour (6-minute) - 3. keep recording revisions with no compaction for first 24-hour - 4. do compact with revs[0] - - success? contiue on for-loop and move sliding window; revs = revs[1:] - - failure? update revs, and retry after 1/10 of 1-hour (6-minute) - -Compaction period 59-min: - 1. compute compaction period, which is 59-min - 2. record revisions for every 1/10 of 59-min (5.9-min) - 3. keep recording revisions with no compaction for first 59-min - 4. do compact with revs[0] - - success? contiue on for-loop and move sliding window; revs = revs[1:] - - failure? update revs, and retry after 1/10 of 59-min (5.9-min) - -Compaction period 5-sec: - 1. compute compaction period, which is 5-sec - 2. record revisions for every 1/10 of 5-sec (0.5-sec) - 3. keep recording revisions with no compaction for first 5-sec - 4. do compact with revs[0] - - success? contiue on for-loop and move sliding window; revs = revs[1:] - - failure? update revs, and retry after 1/10 of 5-sec (0.5-sec) -*/ - -// Run runs periodic compactor. -func (t *Periodic) Run() { - compactInterval := t.getCompactInterval() - retryInterval := t.getRetryInterval() - retentions := t.getRetentions() - - go func() { - lastSuccess := t.clock.Now() - baseInterval := t.period - for { - t.revs = append(t.revs, t.rg.Rev()) - if len(t.revs) > retentions { - t.revs = t.revs[1:] // t.revs[0] is always the rev at t.period ago - } - - select { - case <-t.ctx.Done(): - return - case <-t.clock.After(retryInterval): - t.mu.Lock() - p := t.paused - t.mu.Unlock() - if p { - continue - } - } - - if t.clock.Now().Sub(lastSuccess) < baseInterval { - continue - } - - // wait up to initial given period - if baseInterval == t.period { - baseInterval = compactInterval - } - rev := t.revs[0] - - plog.Noticef("Starting auto-compaction at revision %d (retention: %v)", rev, t.period) - _, err := t.c.Compact(t.ctx, &pb.CompactionRequest{Revision: rev}) - if err == nil || err == mvcc.ErrCompacted { - lastSuccess = t.clock.Now() - plog.Noticef("Finished auto-compaction at revision %d", rev) - } else { - plog.Noticef("Failed auto-compaction at revision %d (%v)", rev, err) - plog.Noticef("Retry after %v", retryInterval) - } - } - }() -} - -// if given compaction period x is <1-hour, compact every x duration. -// (e.g. --auto-compaction-mode 'periodic' --auto-compaction-retention='10m', then compact every 10-minute) -// if given compaction period x is >1-hour, compact every hour. -// (e.g. --auto-compaction-mode 'periodic' --auto-compaction-retention='2h', then compact every 1-hour) -func (t *Periodic) getCompactInterval() time.Duration { - itv := t.period - if itv > time.Hour { - itv = time.Hour - } - return itv -} - -func (t *Periodic) getRetentions() int { - return int(t.period/t.getRetryInterval()) + 1 -} - -const retryDivisor = 10 - -func (t *Periodic) getRetryInterval() time.Duration { - itv := t.period - if itv > time.Hour { - itv = time.Hour - } - return itv / retryDivisor -} - -// Stop stops periodic compactor. -func (t *Periodic) Stop() { - t.cancel() -} - -// Pause pauses periodic compactor. -func (t *Periodic) Pause() { - t.mu.Lock() - defer t.mu.Unlock() - t.paused = true -} - -// Resume resumes periodic compactor. -func (t *Periodic) Resume() { - t.mu.Lock() - defer t.mu.Unlock() - t.paused = false -} diff --git a/vendor/github.com/coreos/etcd/compactor/revision.go b/vendor/github.com/coreos/etcd/compactor/revision.go deleted file mode 100644 index 927e41c97faf..000000000000 --- a/vendor/github.com/coreos/etcd/compactor/revision.go +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package compactor - -import ( - "context" - "sync" - "time" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc" - - "github.com/jonboulle/clockwork" -) - -// Revision compacts the log by purging revisions older than -// the configured reivison number. Compaction happens every 5 minutes. -type Revision struct { - clock clockwork.Clock - retention int64 - - rg RevGetter - c Compactable - - ctx context.Context - cancel context.CancelFunc - - mu sync.Mutex - paused bool -} - -// NewRevision creates a new instance of Revisonal compactor that purges -// the log older than retention revisions from the current revision. -func NewRevision(retention int64, rg RevGetter, c Compactable) *Revision { - return newRevision(clockwork.NewRealClock(), retention, rg, c) -} - -func newRevision(clock clockwork.Clock, retention int64, rg RevGetter, c Compactable) *Revision { - t := &Revision{ - clock: clock, - retention: retention, - rg: rg, - c: c, - } - t.ctx, t.cancel = context.WithCancel(context.Background()) - return t -} - -const revInterval = 5 * time.Minute - -// Run runs revision-based compactor. -func (t *Revision) Run() { - prev := int64(0) - go func() { - for { - select { - case <-t.ctx.Done(): - return - case <-t.clock.After(revInterval): - t.mu.Lock() - p := t.paused - t.mu.Unlock() - if p { - continue - } - } - - rev := t.rg.Rev() - t.retention - if rev <= 0 || rev == prev { - continue - } - - plog.Noticef("Starting auto-compaction at revision %d (retention: %d revisions)", rev, t.retention) - _, err := t.c.Compact(t.ctx, &pb.CompactionRequest{Revision: rev}) - if err == nil || err == mvcc.ErrCompacted { - prev = rev - plog.Noticef("Finished auto-compaction at revision %d", rev) - } else { - plog.Noticef("Failed auto-compaction at revision %d (%v)", rev, err) - plog.Noticef("Retry after %v", revInterval) - } - } - }() -} - -// Stop stops revision-based compactor. -func (t *Revision) Stop() { - t.cancel() -} - -// Pause pauses revision-based compactor. -func (t *Revision) Pause() { - t.mu.Lock() - defer t.mu.Unlock() - t.paused = true -} - -// Resume resumes revision-based compactor. -func (t *Revision) Resume() { - t.mu.Lock() - defer t.mu.Unlock() - t.paused = false -} diff --git a/vendor/github.com/coreos/etcd/discovery/discovery.go b/vendor/github.com/coreos/etcd/discovery/discovery.go deleted file mode 100644 index 7d1fa0d058df..000000000000 --- a/vendor/github.com/coreos/etcd/discovery/discovery.go +++ /dev/null @@ -1,363 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package discovery provides an implementation of the cluster discovery that -// is used by etcd. -package discovery - -import ( - "context" - "errors" - "fmt" - "math" - "net/http" - "net/url" - "path" - "sort" - "strconv" - "strings" - "time" - - "github.com/coreos/etcd/client" - "github.com/coreos/etcd/pkg/transport" - "github.com/coreos/etcd/pkg/types" - - "github.com/coreos/pkg/capnslog" - "github.com/jonboulle/clockwork" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "discovery") - - ErrInvalidURL = errors.New("discovery: invalid URL") - ErrBadSizeKey = errors.New("discovery: size key is bad") - ErrSizeNotFound = errors.New("discovery: size key not found") - ErrTokenNotFound = errors.New("discovery: token not found") - ErrDuplicateID = errors.New("discovery: found duplicate id") - ErrDuplicateName = errors.New("discovery: found duplicate name") - ErrFullCluster = errors.New("discovery: cluster is full") - ErrTooManyRetries = errors.New("discovery: too many retries") - ErrBadDiscoveryEndpoint = errors.New("discovery: bad discovery endpoint") -) - -var ( - // Number of retries discovery will attempt before giving up and erroring out. - nRetries = uint(math.MaxUint32) - maxExpoentialRetries = uint(8) -) - -// JoinCluster will connect to the discovery service at the given url, and -// register the server represented by the given id and config to the cluster -func JoinCluster(durl, dproxyurl string, id types.ID, config string) (string, error) { - d, err := newDiscovery(durl, dproxyurl, id) - if err != nil { - return "", err - } - return d.joinCluster(config) -} - -// GetCluster will connect to the discovery service at the given url and -// retrieve a string describing the cluster -func GetCluster(durl, dproxyurl string) (string, error) { - d, err := newDiscovery(durl, dproxyurl, 0) - if err != nil { - return "", err - } - return d.getCluster() -} - -type discovery struct { - cluster string - id types.ID - c client.KeysAPI - retries uint - url *url.URL - - clock clockwork.Clock -} - -// newProxyFunc builds a proxy function from the given string, which should -// represent a URL that can be used as a proxy. It performs basic -// sanitization of the URL and returns any error encountered. -func newProxyFunc(proxy string) (func(*http.Request) (*url.URL, error), error) { - if proxy == "" { - return nil, nil - } - // Do a small amount of URL sanitization to help the user - // Derived from net/http.ProxyFromEnvironment - proxyURL, err := url.Parse(proxy) - if err != nil || !strings.HasPrefix(proxyURL.Scheme, "http") { - // proxy was bogus. Try prepending "http://" to it and - // see if that parses correctly. If not, we ignore the - // error and complain about the original one - var err2 error - proxyURL, err2 = url.Parse("http://" + proxy) - if err2 == nil { - err = nil - } - } - if err != nil { - return nil, fmt.Errorf("invalid proxy address %q: %v", proxy, err) - } - - plog.Infof("using proxy %q", proxyURL.String()) - return http.ProxyURL(proxyURL), nil -} - -func newDiscovery(durl, dproxyurl string, id types.ID) (*discovery, error) { - u, err := url.Parse(durl) - if err != nil { - return nil, err - } - token := u.Path - u.Path = "" - pf, err := newProxyFunc(dproxyurl) - if err != nil { - return nil, err - } - - // TODO: add ResponseHeaderTimeout back when watch on discovery service writes header early - tr, err := transport.NewTransport(transport.TLSInfo{}, 30*time.Second) - if err != nil { - return nil, err - } - tr.Proxy = pf - cfg := client.Config{ - Transport: tr, - Endpoints: []string{u.String()}, - } - c, err := client.New(cfg) - if err != nil { - return nil, err - } - dc := client.NewKeysAPIWithPrefix(c, "") - return &discovery{ - cluster: token, - c: dc, - id: id, - url: u, - clock: clockwork.NewRealClock(), - }, nil -} - -func (d *discovery) joinCluster(config string) (string, error) { - // fast path: if the cluster is full, return the error - // do not need to register to the cluster in this case. - if _, _, _, err := d.checkCluster(); err != nil { - return "", err - } - - if err := d.createSelf(config); err != nil { - // Fails, even on a timeout, if createSelf times out. - // TODO(barakmich): Retrying the same node might want to succeed here - // (ie, createSelf should be idempotent for discovery). - return "", err - } - - nodes, size, index, err := d.checkCluster() - if err != nil { - return "", err - } - - all, err := d.waitNodes(nodes, size, index) - if err != nil { - return "", err - } - - return nodesToCluster(all, size) -} - -func (d *discovery) getCluster() (string, error) { - nodes, size, index, err := d.checkCluster() - if err != nil { - if err == ErrFullCluster { - return nodesToCluster(nodes, size) - } - return "", err - } - - all, err := d.waitNodes(nodes, size, index) - if err != nil { - return "", err - } - return nodesToCluster(all, size) -} - -func (d *discovery) createSelf(contents string) error { - ctx, cancel := context.WithTimeout(context.Background(), client.DefaultRequestTimeout) - resp, err := d.c.Create(ctx, d.selfKey(), contents) - cancel() - if err != nil { - if eerr, ok := err.(client.Error); ok && eerr.Code == client.ErrorCodeNodeExist { - return ErrDuplicateID - } - return err - } - - // ensure self appears on the server we connected to - w := d.c.Watcher(d.selfKey(), &client.WatcherOptions{AfterIndex: resp.Node.CreatedIndex - 1}) - _, err = w.Next(context.Background()) - return err -} - -func (d *discovery) checkCluster() ([]*client.Node, int, uint64, error) { - configKey := path.Join("/", d.cluster, "_config") - ctx, cancel := context.WithTimeout(context.Background(), client.DefaultRequestTimeout) - // find cluster size - resp, err := d.c.Get(ctx, path.Join(configKey, "size"), nil) - cancel() - if err != nil { - if eerr, ok := err.(*client.Error); ok && eerr.Code == client.ErrorCodeKeyNotFound { - return nil, 0, 0, ErrSizeNotFound - } - if err == client.ErrInvalidJSON { - return nil, 0, 0, ErrBadDiscoveryEndpoint - } - if ce, ok := err.(*client.ClusterError); ok { - plog.Error(ce.Detail()) - return d.checkClusterRetry() - } - return nil, 0, 0, err - } - size, err := strconv.Atoi(resp.Node.Value) - if err != nil { - return nil, 0, 0, ErrBadSizeKey - } - - ctx, cancel = context.WithTimeout(context.Background(), client.DefaultRequestTimeout) - resp, err = d.c.Get(ctx, d.cluster, nil) - cancel() - if err != nil { - if ce, ok := err.(*client.ClusterError); ok { - plog.Error(ce.Detail()) - return d.checkClusterRetry() - } - return nil, 0, 0, err - } - var nodes []*client.Node - // append non-config keys to nodes - for _, n := range resp.Node.Nodes { - if !(path.Base(n.Key) == path.Base(configKey)) { - nodes = append(nodes, n) - } - } - - snodes := sortableNodes{nodes} - sort.Sort(snodes) - - // find self position - for i := range nodes { - if path.Base(nodes[i].Key) == path.Base(d.selfKey()) { - break - } - if i >= size-1 { - return nodes[:size], size, resp.Index, ErrFullCluster - } - } - return nodes, size, resp.Index, nil -} - -func (d *discovery) logAndBackoffForRetry(step string) { - d.retries++ - // logAndBackoffForRetry stops exponential backoff when the retries are more than maxExpoentialRetries and is set to a constant backoff afterward. - retries := d.retries - if retries > maxExpoentialRetries { - retries = maxExpoentialRetries - } - retryTimeInSecond := time.Duration(0x1< size { - nodes = nodes[:size] - } - // watch from the next index - w := d.c.Watcher(d.cluster, &client.WatcherOptions{AfterIndex: index, Recursive: true}) - all := make([]*client.Node, len(nodes)) - copy(all, nodes) - for _, n := range all { - if path.Base(n.Key) == path.Base(d.selfKey()) { - plog.Noticef("found self %s in the cluster", path.Base(d.selfKey())) - } else { - plog.Noticef("found peer %s in the cluster", path.Base(n.Key)) - } - } - - // wait for others - for len(all) < size { - plog.Noticef("found %d peer(s), waiting for %d more", len(all), size-len(all)) - resp, err := w.Next(context.Background()) - if err != nil { - if ce, ok := err.(*client.ClusterError); ok { - plog.Error(ce.Detail()) - return d.waitNodesRetry() - } - return nil, err - } - plog.Noticef("found peer %s in the cluster", path.Base(resp.Node.Key)) - all = append(all, resp.Node) - } - plog.Noticef("found %d needed peer(s)", len(all)) - return all, nil -} - -func (d *discovery) selfKey() string { - return path.Join("/", d.cluster, d.id.String()) -} - -func nodesToCluster(ns []*client.Node, size int) (string, error) { - s := make([]string, len(ns)) - for i, n := range ns { - s[i] = n.Value - } - us := strings.Join(s, ",") - m, err := types.NewURLsMap(us) - if err != nil { - return us, ErrInvalidURL - } - if m.Len() != size { - return us, ErrDuplicateName - } - return us, nil -} - -type sortableNodes struct{ Nodes []*client.Node } - -func (ns sortableNodes) Len() int { return len(ns.Nodes) } -func (ns sortableNodes) Less(i, j int) bool { - return ns.Nodes[i].CreatedIndex < ns.Nodes[j].CreatedIndex -} -func (ns sortableNodes) Swap(i, j int) { ns.Nodes[i], ns.Nodes[j] = ns.Nodes[j], ns.Nodes[i] } diff --git a/vendor/github.com/coreos/etcd/embed/config.go b/vendor/github.com/coreos/etcd/embed/config.go deleted file mode 100644 index 835e051a7d62..000000000000 --- a/vendor/github.com/coreos/etcd/embed/config.go +++ /dev/null @@ -1,699 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package embed - -import ( - "crypto/tls" - "fmt" - "io/ioutil" - "net" - "net/http" - "net/url" - "os" - "path/filepath" - "strings" - "time" - - "github.com/coreos/etcd/compactor" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/pkg/cors" - "github.com/coreos/etcd/pkg/netutil" - "github.com/coreos/etcd/pkg/srv" - "github.com/coreos/etcd/pkg/tlsutil" - "github.com/coreos/etcd/pkg/transport" - "github.com/coreos/etcd/pkg/types" - - "github.com/coreos/pkg/capnslog" - "github.com/ghodss/yaml" - "google.golang.org/grpc" - "google.golang.org/grpc/grpclog" -) - -const ( - ClusterStateFlagNew = "new" - ClusterStateFlagExisting = "existing" - - DefaultName = "default" - DefaultMaxSnapshots = 5 - DefaultMaxWALs = 5 - DefaultMaxTxnOps = uint(128) - DefaultMaxRequestBytes = 1.5 * 1024 * 1024 - DefaultGRPCKeepAliveMinTime = 5 * time.Second - DefaultGRPCKeepAliveInterval = 2 * time.Hour - DefaultGRPCKeepAliveTimeout = 20 * time.Second - - DefaultListenPeerURLs = "http://localhost:2380" - DefaultListenClientURLs = "http://localhost:2379" - - DefaultLogOutput = "default" - - // DefaultStrictReconfigCheck is the default value for "--strict-reconfig-check" flag. - // It's enabled by default. - DefaultStrictReconfigCheck = true - // DefaultEnableV2 is the default value for "--enable-v2" flag. - // v2 is enabled by default. - // TODO: disable v2 when deprecated. - DefaultEnableV2 = true - - // maxElectionMs specifies the maximum value of election timeout. - // More details are listed in ../Documentation/tuning.md#time-parameters. - maxElectionMs = 50000 -) - -var ( - ErrConflictBootstrapFlags = fmt.Errorf("multiple discovery or bootstrap flags are set. " + - "Choose one of \"initial-cluster\", \"discovery\" or \"discovery-srv\"") - ErrUnsetAdvertiseClientURLsFlag = fmt.Errorf("--advertise-client-urls is required when --listen-client-urls is set explicitly") - - DefaultInitialAdvertisePeerURLs = "http://localhost:2380" - DefaultAdvertiseClientURLs = "http://localhost:2379" - - defaultHostname string - defaultHostStatus error -) - -func init() { - defaultHostname, defaultHostStatus = netutil.GetDefaultHost() -} - -// Config holds the arguments for configuring an etcd server. -type Config struct { - // member - - CorsInfo *cors.CORSInfo - LPUrls, LCUrls []url.URL - Dir string `json:"data-dir"` - WalDir string `json:"wal-dir"` - MaxSnapFiles uint `json:"max-snapshots"` - MaxWalFiles uint `json:"max-wals"` - Name string `json:"name"` - SnapCount uint64 `json:"snapshot-count"` - - // AutoCompactionMode is either 'periodic' or 'revision'. - AutoCompactionMode string `json:"auto-compaction-mode"` - // AutoCompactionRetention is either duration string with time unit - // (e.g. '5m' for 5-minute), or revision unit (e.g. '5000'). - // If no time unit is provided and compaction mode is 'periodic', - // the unit defaults to hour. For example, '5' translates into 5-hour. - AutoCompactionRetention string `json:"auto-compaction-retention"` - - // TickMs is the number of milliseconds between heartbeat ticks. - // TODO: decouple tickMs and heartbeat tick (current heartbeat tick = 1). - // make ticks a cluster wide configuration. - TickMs uint `json:"heartbeat-interval"` - ElectionMs uint `json:"election-timeout"` - - // InitialElectionTickAdvance is true, then local member fast-forwards - // election ticks to speed up "initial" leader election trigger. This - // benefits the case of larger election ticks. For instance, cross - // datacenter deployment may require longer election timeout of 10-second. - // If true, local node does not need wait up to 10-second. Instead, - // forwards its election ticks to 8-second, and have only 2-second left - // before leader election. - // - // Major assumptions are that: - // - cluster has no active leader thus advancing ticks enables faster - // leader election, or - // - cluster already has an established leader, and rejoining follower - // is likely to receive heartbeats from the leader after tick advance - // and before election timeout. - // - // However, when network from leader to rejoining follower is congested, - // and the follower does not receive leader heartbeat within left election - // ticks, disruptive election has to happen thus affecting cluster - // availabilities. - // - // Disabling this would slow down initial bootstrap process for cross - // datacenter deployments. Make your own tradeoffs by configuring - // --initial-election-tick-advance at the cost of slow initial bootstrap. - // - // If single-node, it advances ticks regardless. - // - // See https://github.com/coreos/etcd/issues/9333 for more detail. - InitialElectionTickAdvance bool `json:"initial-election-tick-advance"` - - QuotaBackendBytes int64 `json:"quota-backend-bytes"` - MaxTxnOps uint `json:"max-txn-ops"` - MaxRequestBytes uint `json:"max-request-bytes"` - - // gRPC server options - - // GRPCKeepAliveMinTime is the minimum interval that a client should - // wait before pinging server. When client pings "too fast", server - // sends goaway and closes the connection (errors: too_many_pings, - // http2.ErrCodeEnhanceYourCalm). When too slow, nothing happens. - // Server expects client pings only when there is any active streams - // (PermitWithoutStream is set false). - GRPCKeepAliveMinTime time.Duration `json:"grpc-keepalive-min-time"` - // GRPCKeepAliveInterval is the frequency of server-to-client ping - // to check if a connection is alive. Close a non-responsive connection - // after an additional duration of Timeout. 0 to disable. - GRPCKeepAliveInterval time.Duration `json:"grpc-keepalive-interval"` - // GRPCKeepAliveTimeout is the additional duration of wait - // before closing a non-responsive connection. 0 to disable. - GRPCKeepAliveTimeout time.Duration `json:"grpc-keepalive-timeout"` - - // clustering - - APUrls, ACUrls []url.URL - ClusterState string `json:"initial-cluster-state"` - DNSCluster string `json:"discovery-srv"` - Dproxy string `json:"discovery-proxy"` - Durl string `json:"discovery"` - InitialCluster string `json:"initial-cluster"` - InitialClusterToken string `json:"initial-cluster-token"` - StrictReconfigCheck bool `json:"strict-reconfig-check"` - EnableV2 bool `json:"enable-v2"` - - // security - - ClientTLSInfo transport.TLSInfo - ClientAutoTLS bool - PeerTLSInfo transport.TLSInfo - PeerAutoTLS bool - - // CipherSuites is a list of supported TLS cipher suites between - // client/server and peers. If empty, Go auto-populates the list. - // Note that cipher suites are prioritized in the given order. - CipherSuites []string `json:"cipher-suites"` - - // debug - - Debug bool `json:"debug"` - LogPkgLevels string `json:"log-package-levels"` - LogOutput string `json:"log-output"` - EnablePprof bool `json:"enable-pprof"` - Metrics string `json:"metrics"` - ListenMetricsUrls []url.URL - ListenMetricsUrlsJSON string `json:"listen-metrics-urls"` - - // ForceNewCluster starts a new cluster even if previously started; unsafe. - ForceNewCluster bool `json:"force-new-cluster"` - - // UserHandlers is for registering users handlers and only used for - // embedding etcd into other applications. - // The map key is the route path for the handler, and - // you must ensure it can't be conflicted with etcd's. - UserHandlers map[string]http.Handler `json:"-"` - // ServiceRegister is for registering users' gRPC services. A simple usage example: - // cfg := embed.NewConfig() - // cfg.ServerRegister = func(s *grpc.Server) { - // pb.RegisterFooServer(s, &fooServer{}) - // pb.RegisterBarServer(s, &barServer{}) - // } - // embed.StartEtcd(cfg) - ServiceRegister func(*grpc.Server) `json:"-"` - - // auth - - AuthToken string `json:"auth-token"` - - // Experimental flags - - ExperimentalInitialCorruptCheck bool `json:"experimental-initial-corrupt-check"` - ExperimentalCorruptCheckTime time.Duration `json:"experimental-corrupt-check-time"` - ExperimentalEnableV2V3 string `json:"experimental-enable-v2v3"` -} - -// configYAML holds the config suitable for yaml parsing -type configYAML struct { - Config - configJSON -} - -// configJSON has file options that are translated into Config options -type configJSON struct { - LPUrlsJSON string `json:"listen-peer-urls"` - LCUrlsJSON string `json:"listen-client-urls"` - CorsJSON string `json:"cors"` - APUrlsJSON string `json:"initial-advertise-peer-urls"` - ACUrlsJSON string `json:"advertise-client-urls"` - ClientSecurityJSON securityConfig `json:"client-transport-security"` - PeerSecurityJSON securityConfig `json:"peer-transport-security"` -} - -type securityConfig struct { - CAFile string `json:"ca-file"` - CertFile string `json:"cert-file"` - KeyFile string `json:"key-file"` - CertAuth bool `json:"client-cert-auth"` - TrustedCAFile string `json:"trusted-ca-file"` - AutoTLS bool `json:"auto-tls"` -} - -// NewConfig creates a new Config populated with default values. -func NewConfig() *Config { - lpurl, _ := url.Parse(DefaultListenPeerURLs) - apurl, _ := url.Parse(DefaultInitialAdvertisePeerURLs) - lcurl, _ := url.Parse(DefaultListenClientURLs) - acurl, _ := url.Parse(DefaultAdvertiseClientURLs) - cfg := &Config{ - CorsInfo: &cors.CORSInfo{}, - MaxSnapFiles: DefaultMaxSnapshots, - MaxWalFiles: DefaultMaxWALs, - Name: DefaultName, - SnapCount: etcdserver.DefaultSnapCount, - MaxTxnOps: DefaultMaxTxnOps, - MaxRequestBytes: DefaultMaxRequestBytes, - GRPCKeepAliveMinTime: DefaultGRPCKeepAliveMinTime, - GRPCKeepAliveInterval: DefaultGRPCKeepAliveInterval, - GRPCKeepAliveTimeout: DefaultGRPCKeepAliveTimeout, - TickMs: 100, - ElectionMs: 1000, - InitialElectionTickAdvance: true, - LPUrls: []url.URL{*lpurl}, - LCUrls: []url.URL{*lcurl}, - APUrls: []url.URL{*apurl}, - ACUrls: []url.URL{*acurl}, - ClusterState: ClusterStateFlagNew, - InitialClusterToken: "etcd-cluster", - StrictReconfigCheck: DefaultStrictReconfigCheck, - LogOutput: DefaultLogOutput, - Metrics: "basic", - EnableV2: DefaultEnableV2, - AuthToken: "simple", - } - cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name) - return cfg -} - -func logTLSHandshakeFailure(conn *tls.Conn, err error) { - state := conn.ConnectionState() - remoteAddr := conn.RemoteAddr().String() - serverName := state.ServerName - if len(state.PeerCertificates) > 0 { - cert := state.PeerCertificates[0] - ips, dns := cert.IPAddresses, cert.DNSNames - plog.Infof("rejected connection from %q (error %q, ServerName %q, IPAddresses %q, DNSNames %q)", remoteAddr, err.Error(), serverName, ips, dns) - } else { - plog.Infof("rejected connection from %q (error %q, ServerName %q)", remoteAddr, err.Error(), serverName) - } -} - -// SetupLogging initializes etcd logging. -// Must be called after flag parsing. -func (cfg *Config) SetupLogging() { - cfg.ClientTLSInfo.HandshakeFailure = logTLSHandshakeFailure - cfg.PeerTLSInfo.HandshakeFailure = logTLSHandshakeFailure - - capnslog.SetGlobalLogLevel(capnslog.INFO) - if cfg.Debug { - capnslog.SetGlobalLogLevel(capnslog.DEBUG) - grpc.EnableTracing = true - // enable info, warning, error - grpclog.SetLoggerV2(grpclog.NewLoggerV2(os.Stderr, os.Stderr, os.Stderr)) - } else { - // only discard info - grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, os.Stderr, os.Stderr)) - } - if cfg.LogPkgLevels != "" { - repoLog := capnslog.MustRepoLogger("github.com/coreos/etcd") - settings, err := repoLog.ParseLogLevelConfig(cfg.LogPkgLevels) - if err != nil { - plog.Warningf("couldn't parse log level string: %s, continuing with default levels", err.Error()) - return - } - repoLog.SetLogLevel(settings) - } - - // capnslog initially SetFormatter(NewDefaultFormatter(os.Stderr)) - // where NewDefaultFormatter returns NewJournaldFormatter when syscall.Getppid() == 1 - // specify 'stdout' or 'stderr' to skip journald logging even when running under systemd - switch cfg.LogOutput { - case "stdout": - capnslog.SetFormatter(capnslog.NewPrettyFormatter(os.Stdout, cfg.Debug)) - case "stderr": - capnslog.SetFormatter(capnslog.NewPrettyFormatter(os.Stderr, cfg.Debug)) - case DefaultLogOutput: - default: - plog.Panicf(`unknown log-output %q (only supports %q, "stdout", "stderr")`, cfg.LogOutput, DefaultLogOutput) - } -} - -func ConfigFromFile(path string) (*Config, error) { - cfg := &configYAML{Config: *NewConfig()} - if err := cfg.configFromFile(path); err != nil { - return nil, err - } - return &cfg.Config, nil -} - -func (cfg *configYAML) configFromFile(path string) error { - b, err := ioutil.ReadFile(path) - if err != nil { - return err - } - - defaultInitialCluster := cfg.InitialCluster - - err = yaml.Unmarshal(b, cfg) - if err != nil { - return err - } - - if cfg.LPUrlsJSON != "" { - u, err := types.NewURLs(strings.Split(cfg.LPUrlsJSON, ",")) - if err != nil { - plog.Fatalf("unexpected error setting up listen-peer-urls: %v", err) - } - cfg.LPUrls = []url.URL(u) - } - - if cfg.LCUrlsJSON != "" { - u, err := types.NewURLs(strings.Split(cfg.LCUrlsJSON, ",")) - if err != nil { - plog.Fatalf("unexpected error setting up listen-client-urls: %v", err) - } - cfg.LCUrls = []url.URL(u) - } - - if cfg.CorsJSON != "" { - if err := cfg.CorsInfo.Set(cfg.CorsJSON); err != nil { - plog.Panicf("unexpected error setting up cors: %v", err) - } - } - - if cfg.APUrlsJSON != "" { - u, err := types.NewURLs(strings.Split(cfg.APUrlsJSON, ",")) - if err != nil { - plog.Fatalf("unexpected error setting up initial-advertise-peer-urls: %v", err) - } - cfg.APUrls = []url.URL(u) - } - - if cfg.ACUrlsJSON != "" { - u, err := types.NewURLs(strings.Split(cfg.ACUrlsJSON, ",")) - if err != nil { - plog.Fatalf("unexpected error setting up advertise-peer-urls: %v", err) - } - cfg.ACUrls = []url.URL(u) - } - - if cfg.ListenMetricsUrlsJSON != "" { - u, err := types.NewURLs(strings.Split(cfg.ListenMetricsUrlsJSON, ",")) - if err != nil { - plog.Fatalf("unexpected error setting up listen-metrics-urls: %v", err) - } - cfg.ListenMetricsUrls = []url.URL(u) - } - - // If a discovery flag is set, clear default initial cluster set by InitialClusterFromName - if (cfg.Durl != "" || cfg.DNSCluster != "") && cfg.InitialCluster == defaultInitialCluster { - cfg.InitialCluster = "" - } - if cfg.ClusterState == "" { - cfg.ClusterState = ClusterStateFlagNew - } - - copySecurityDetails := func(tls *transport.TLSInfo, ysc *securityConfig) { - tls.CAFile = ysc.CAFile - tls.CertFile = ysc.CertFile - tls.KeyFile = ysc.KeyFile - tls.ClientCertAuth = ysc.CertAuth - tls.TrustedCAFile = ysc.TrustedCAFile - } - copySecurityDetails(&cfg.ClientTLSInfo, &cfg.ClientSecurityJSON) - copySecurityDetails(&cfg.PeerTLSInfo, &cfg.PeerSecurityJSON) - cfg.ClientAutoTLS = cfg.ClientSecurityJSON.AutoTLS - cfg.PeerAutoTLS = cfg.PeerSecurityJSON.AutoTLS - - return cfg.Validate() -} - -func updateCipherSuites(tls *transport.TLSInfo, ss []string) error { - if len(tls.CipherSuites) > 0 && len(ss) > 0 { - return fmt.Errorf("TLSInfo.CipherSuites is already specified (given %v)", ss) - } - if len(ss) > 0 { - cs := make([]uint16, len(ss)) - for i, s := range ss { - var ok bool - cs[i], ok = tlsutil.GetCipherSuite(s) - if !ok { - return fmt.Errorf("unexpected TLS cipher suite %q", s) - } - } - tls.CipherSuites = cs - } - return nil -} - -// Validate ensures that '*embed.Config' fields are properly configured. -func (cfg *Config) Validate() error { - if err := checkBindURLs(cfg.LPUrls); err != nil { - return err - } - if err := checkBindURLs(cfg.LCUrls); err != nil { - return err - } - if err := checkBindURLs(cfg.ListenMetricsUrls); err != nil { - return err - } - if err := checkHostURLs(cfg.APUrls); err != nil { - // TODO: return err in v3.4 - addrs := make([]string, len(cfg.APUrls)) - for i := range cfg.APUrls { - addrs[i] = cfg.APUrls[i].String() - } - plog.Warningf("advertise-peer-urls %q is deprecated (%v)", strings.Join(addrs, ","), err) - } - if err := checkHostURLs(cfg.ACUrls); err != nil { - // TODO: return err in v3.4 - addrs := make([]string, len(cfg.ACUrls)) - for i := range cfg.ACUrls { - addrs[i] = cfg.ACUrls[i].String() - } - plog.Warningf("advertise-client-urls %q is deprecated (%v)", strings.Join(addrs, ","), err) - } - - // Check if conflicting flags are passed. - nSet := 0 - for _, v := range []bool{cfg.Durl != "", cfg.InitialCluster != "", cfg.DNSCluster != ""} { - if v { - nSet++ - } - } - - if cfg.ClusterState != ClusterStateFlagNew && cfg.ClusterState != ClusterStateFlagExisting { - return fmt.Errorf("unexpected clusterState %q", cfg.ClusterState) - } - - if nSet > 1 { - return ErrConflictBootstrapFlags - } - - if cfg.TickMs <= 0 { - return fmt.Errorf("--heartbeat-interval must be >0 (set to %dms)", cfg.TickMs) - } - if cfg.ElectionMs <= 0 { - return fmt.Errorf("--election-timeout must be >0 (set to %dms)", cfg.ElectionMs) - } - if 5*cfg.TickMs > cfg.ElectionMs { - return fmt.Errorf("--election-timeout[%vms] should be at least as 5 times as --heartbeat-interval[%vms]", cfg.ElectionMs, cfg.TickMs) - } - if cfg.ElectionMs > maxElectionMs { - return fmt.Errorf("--election-timeout[%vms] is too long, and should be set less than %vms", cfg.ElectionMs, maxElectionMs) - } - - // check this last since proxying in etcdmain may make this OK - if cfg.LCUrls != nil && cfg.ACUrls == nil { - return ErrUnsetAdvertiseClientURLsFlag - } - - switch cfg.AutoCompactionMode { - case "": - case compactor.ModeRevision, compactor.ModePeriodic: - default: - return fmt.Errorf("unknown auto-compaction-mode %q", cfg.AutoCompactionMode) - } - - return nil -} - -// PeerURLsMapAndToken sets up an initial peer URLsMap and cluster token for bootstrap or discovery. -func (cfg *Config) PeerURLsMapAndToken(which string) (urlsmap types.URLsMap, token string, err error) { - token = cfg.InitialClusterToken - switch { - case cfg.Durl != "": - urlsmap = types.URLsMap{} - // If using discovery, generate a temporary cluster based on - // self's advertised peer URLs - urlsmap[cfg.Name] = cfg.APUrls - token = cfg.Durl - case cfg.DNSCluster != "": - clusterStrs, cerr := srv.GetCluster("etcd-server", cfg.Name, cfg.DNSCluster, cfg.APUrls) - if cerr != nil { - plog.Errorf("couldn't resolve during SRV discovery (%v)", cerr) - return nil, "", cerr - } - for _, s := range clusterStrs { - plog.Noticef("got bootstrap from DNS for etcd-server at %s", s) - } - clusterStr := strings.Join(clusterStrs, ",") - if strings.Contains(clusterStr, "https://") && cfg.PeerTLSInfo.CAFile == "" { - cfg.PeerTLSInfo.ServerName = cfg.DNSCluster - } - urlsmap, err = types.NewURLsMap(clusterStr) - // only etcd member must belong to the discovered cluster. - // proxy does not need to belong to the discovered cluster. - if which == "etcd" { - if _, ok := urlsmap[cfg.Name]; !ok { - return nil, "", fmt.Errorf("cannot find local etcd member %q in SRV records", cfg.Name) - } - } - default: - // We're statically configured, and cluster has appropriately been set. - urlsmap, err = types.NewURLsMap(cfg.InitialCluster) - } - return urlsmap, token, err -} - -func (cfg Config) InitialClusterFromName(name string) (ret string) { - if len(cfg.APUrls) == 0 { - return "" - } - n := name - if name == "" { - n = DefaultName - } - for i := range cfg.APUrls { - ret = ret + "," + n + "=" + cfg.APUrls[i].String() - } - return ret[1:] -} - -func (cfg Config) IsNewCluster() bool { return cfg.ClusterState == ClusterStateFlagNew } -func (cfg Config) ElectionTicks() int { return int(cfg.ElectionMs / cfg.TickMs) } - -func (cfg Config) defaultPeerHost() bool { - return len(cfg.APUrls) == 1 && cfg.APUrls[0].String() == DefaultInitialAdvertisePeerURLs -} - -func (cfg Config) defaultClientHost() bool { - return len(cfg.ACUrls) == 1 && cfg.ACUrls[0].String() == DefaultAdvertiseClientURLs -} - -func (cfg *Config) ClientSelfCert() (err error) { - if !cfg.ClientAutoTLS { - return nil - } - if !cfg.ClientTLSInfo.Empty() { - plog.Warningf("ignoring client auto TLS since certs given") - return nil - } - chosts := make([]string, len(cfg.LCUrls)) - for i, u := range cfg.LCUrls { - chosts[i] = u.Host - } - cfg.ClientTLSInfo, err = transport.SelfCert(filepath.Join(cfg.Dir, "fixtures", "client"), chosts) - if err != nil { - return err - } - return updateCipherSuites(&cfg.ClientTLSInfo, cfg.CipherSuites) -} - -func (cfg *Config) PeerSelfCert() (err error) { - if !cfg.PeerAutoTLS { - return nil - } - if !cfg.PeerTLSInfo.Empty() { - plog.Warningf("ignoring peer auto TLS since certs given") - return nil - } - phosts := make([]string, len(cfg.LPUrls)) - for i, u := range cfg.LPUrls { - phosts[i] = u.Host - } - cfg.PeerTLSInfo, err = transport.SelfCert(filepath.Join(cfg.Dir, "fixtures", "peer"), phosts) - if err != nil { - return err - } - return updateCipherSuites(&cfg.PeerTLSInfo, cfg.CipherSuites) -} - -// UpdateDefaultClusterFromName updates cluster advertise URLs with, if available, default host, -// if advertise URLs are default values(localhost:2379,2380) AND if listen URL is 0.0.0.0. -// e.g. advertise peer URL localhost:2380 or listen peer URL 0.0.0.0:2380 -// then the advertise peer host would be updated with machine's default host, -// while keeping the listen URL's port. -// User can work around this by explicitly setting URL with 127.0.0.1. -// It returns the default hostname, if used, and the error, if any, from getting the machine's default host. -// TODO: check whether fields are set instead of whether fields have default value -func (cfg *Config) UpdateDefaultClusterFromName(defaultInitialCluster string) (string, error) { - if defaultHostname == "" || defaultHostStatus != nil { - // update 'initial-cluster' when only the name is specified (e.g. 'etcd --name=abc') - if cfg.Name != DefaultName && cfg.InitialCluster == defaultInitialCluster { - cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name) - } - return "", defaultHostStatus - } - - used := false - pip, pport := cfg.LPUrls[0].Hostname(), cfg.LPUrls[0].Port() - if cfg.defaultPeerHost() && pip == "0.0.0.0" { - cfg.APUrls[0] = url.URL{Scheme: cfg.APUrls[0].Scheme, Host: fmt.Sprintf("%s:%s", defaultHostname, pport)} - used = true - } - // update 'initial-cluster' when only the name is specified (e.g. 'etcd --name=abc') - if cfg.Name != DefaultName && cfg.InitialCluster == defaultInitialCluster { - cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name) - } - - cip, cport := cfg.LCUrls[0].Hostname(), cfg.LCUrls[0].Port() - if cfg.defaultClientHost() && cip == "0.0.0.0" { - cfg.ACUrls[0] = url.URL{Scheme: cfg.ACUrls[0].Scheme, Host: fmt.Sprintf("%s:%s", defaultHostname, cport)} - used = true - } - dhost := defaultHostname - if !used { - dhost = "" - } - return dhost, defaultHostStatus -} - -// checkBindURLs returns an error if any URL uses a domain name. -func checkBindURLs(urls []url.URL) error { - for _, url := range urls { - if url.Scheme == "unix" || url.Scheme == "unixs" { - continue - } - host, _, err := net.SplitHostPort(url.Host) - if err != nil { - return err - } - if host == "localhost" { - // special case for local address - // TODO: support /etc/hosts ? - continue - } - if net.ParseIP(host) == nil { - return fmt.Errorf("expected IP in URL for binding (%s)", url.String()) - } - } - return nil -} - -func checkHostURLs(urls []url.URL) error { - for _, url := range urls { - host, _, err := net.SplitHostPort(url.Host) - if err != nil { - return err - } - if host == "" { - return fmt.Errorf("unexpected empty host (%s)", url.String()) - } - } - return nil -} diff --git a/vendor/github.com/coreos/etcd/embed/doc.go b/vendor/github.com/coreos/etcd/embed/doc.go deleted file mode 100644 index c555aa58ebac..000000000000 --- a/vendor/github.com/coreos/etcd/embed/doc.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package embed provides bindings for embedding an etcd server in a program. - -Launch an embedded etcd server using the configuration defaults: - - import ( - "log" - "time" - - "github.com/coreos/etcd/embed" - ) - - func main() { - cfg := embed.NewConfig() - cfg.Dir = "default.etcd" - e, err := embed.StartEtcd(cfg) - if err != nil { - log.Fatal(err) - } - defer e.Close() - select { - case <-e.Server.ReadyNotify(): - log.Printf("Server is ready!") - case <-time.After(60 * time.Second): - e.Server.Stop() // trigger a shutdown - log.Printf("Server took too long to start!") - } - log.Fatal(<-e.Err()) - } -*/ -package embed diff --git a/vendor/github.com/coreos/etcd/embed/etcd.go b/vendor/github.com/coreos/etcd/embed/etcd.go deleted file mode 100644 index bd848a7137e3..000000000000 --- a/vendor/github.com/coreos/etcd/embed/etcd.go +++ /dev/null @@ -1,582 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package embed - -import ( - "context" - "crypto/tls" - "fmt" - "io/ioutil" - defaultLog "log" - "net" - "net/http" - "net/url" - "strconv" - "sync" - "time" - - "github.com/coreos/etcd/compactor" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/etcdhttp" - "github.com/coreos/etcd/etcdserver/api/v2http" - "github.com/coreos/etcd/etcdserver/api/v2v3" - "github.com/coreos/etcd/etcdserver/api/v3client" - "github.com/coreos/etcd/etcdserver/api/v3rpc" - "github.com/coreos/etcd/pkg/cors" - "github.com/coreos/etcd/pkg/debugutil" - runtimeutil "github.com/coreos/etcd/pkg/runtime" - "github.com/coreos/etcd/pkg/transport" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/rafthttp" - - "github.com/coreos/pkg/capnslog" - grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" - "github.com/soheilhy/cmux" - "google.golang.org/grpc" - "google.golang.org/grpc/keepalive" -) - -var plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "embed") - -const ( - // internal fd usage includes disk usage and transport usage. - // To read/write snapshot, snap pkg needs 1. In normal case, wal pkg needs - // at most 2 to read/lock/write WALs. One case that it needs to 2 is to - // read all logs after some snapshot index, which locates at the end of - // the second last and the head of the last. For purging, it needs to read - // directory, so it needs 1. For fd monitor, it needs 1. - // For transport, rafthttp builds two long-polling connections and at most - // four temporary connections with each member. There are at most 9 members - // in a cluster, so it should reserve 96. - // For the safety, we set the total reserved number to 150. - reservedInternalFDNum = 150 -) - -// Etcd contains a running etcd server and its listeners. -type Etcd struct { - Peers []*peerListener - Clients []net.Listener - // a map of contexts for the servers that serves client requests. - sctxs map[string]*serveCtx - metricsListeners []net.Listener - - Server *etcdserver.EtcdServer - - cfg Config - stopc chan struct{} - errc chan error - - closeOnce sync.Once -} - -type peerListener struct { - net.Listener - serve func() error - close func(context.Context) error -} - -// StartEtcd launches the etcd server and HTTP handlers for client/server communication. -// The returned Etcd.Server is not guaranteed to have joined the cluster. Wait -// on the Etcd.Server.ReadyNotify() channel to know when it completes and is ready for use. -func StartEtcd(inCfg *Config) (e *Etcd, err error) { - if err = inCfg.Validate(); err != nil { - return nil, err - } - serving := false - e = &Etcd{cfg: *inCfg, stopc: make(chan struct{})} - cfg := &e.cfg - defer func() { - if e == nil || err == nil { - return - } - if !serving { - // errored before starting gRPC server for serveCtx.serversC - for _, sctx := range e.sctxs { - close(sctx.serversC) - } - } - e.Close() - e = nil - }() - - if e.Peers, err = startPeerListeners(cfg); err != nil { - return e, err - } - if e.sctxs, err = startClientListeners(cfg); err != nil { - return e, err - } - for _, sctx := range e.sctxs { - e.Clients = append(e.Clients, sctx.l) - } - - var ( - urlsmap types.URLsMap - token string - ) - - memberInitialized := true - if !isMemberInitialized(cfg) { - memberInitialized = false - urlsmap, token, err = cfg.PeerURLsMapAndToken("etcd") - if err != nil { - return e, fmt.Errorf("error setting up initial cluster: %v", err) - } - } - - // AutoCompactionRetention defaults to "0" if not set. - if len(cfg.AutoCompactionRetention) == 0 { - cfg.AutoCompactionRetention = "0" - } - autoCompactionRetention, err := parseCompactionRetention(cfg.AutoCompactionMode, cfg.AutoCompactionRetention) - if err != nil { - return e, err - } - - srvcfg := etcdserver.ServerConfig{ - Name: cfg.Name, - ClientURLs: cfg.ACUrls, - PeerURLs: cfg.APUrls, - DataDir: cfg.Dir, - DedicatedWALDir: cfg.WalDir, - SnapCount: cfg.SnapCount, - MaxSnapFiles: cfg.MaxSnapFiles, - MaxWALFiles: cfg.MaxWalFiles, - InitialPeerURLsMap: urlsmap, - InitialClusterToken: token, - DiscoveryURL: cfg.Durl, - DiscoveryProxy: cfg.Dproxy, - NewCluster: cfg.IsNewCluster(), - ForceNewCluster: cfg.ForceNewCluster, - PeerTLSInfo: cfg.PeerTLSInfo, - TickMs: cfg.TickMs, - ElectionTicks: cfg.ElectionTicks(), - InitialElectionTickAdvance: cfg.InitialElectionTickAdvance, - AutoCompactionRetention: autoCompactionRetention, - AutoCompactionMode: cfg.AutoCompactionMode, - QuotaBackendBytes: cfg.QuotaBackendBytes, - MaxTxnOps: cfg.MaxTxnOps, - MaxRequestBytes: cfg.MaxRequestBytes, - StrictReconfigCheck: cfg.StrictReconfigCheck, - ClientCertAuthEnabled: cfg.ClientTLSInfo.ClientCertAuth, - AuthToken: cfg.AuthToken, - InitialCorruptCheck: cfg.ExperimentalInitialCorruptCheck, - CorruptCheckTime: cfg.ExperimentalCorruptCheckTime, - Debug: cfg.Debug, - } - - if e.Server, err = etcdserver.NewServer(srvcfg); err != nil { - return e, err - } - - // buffer channel so goroutines on closed connections won't wait forever - e.errc = make(chan error, len(e.Peers)+len(e.Clients)+2*len(e.sctxs)) - - // newly started member ("memberInitialized==false") - // does not need corruption check - if memberInitialized { - if err = e.Server.CheckInitialHashKV(); err != nil { - // set "EtcdServer" to nil, so that it does not block on "EtcdServer.Close()" - // (nothing to close since rafthttp transports have not been started) - e.Server = nil - return e, err - } - } - e.Server.Start() - - if err = e.servePeers(); err != nil { - return e, err - } - if err = e.serveClients(); err != nil { - return e, err - } - if err = e.serveMetrics(); err != nil { - return e, err - } - - serving = true - return e, nil -} - -// Config returns the current configuration. -func (e *Etcd) Config() Config { - return e.cfg -} - -// Close gracefully shuts down all servers/listeners. -// Client requests will be terminated with request timeout. -// After timeout, enforce remaning requests be closed immediately. -func (e *Etcd) Close() { - e.closeOnce.Do(func() { close(e.stopc) }) - - // close client requests with request timeout - timeout := 2 * time.Second - if e.Server != nil { - timeout = e.Server.Cfg.ReqTimeout() - } - for _, sctx := range e.sctxs { - for ss := range sctx.serversC { - ctx, cancel := context.WithTimeout(context.Background(), timeout) - stopServers(ctx, ss) - cancel() - } - } - - for _, sctx := range e.sctxs { - sctx.cancel() - } - - for i := range e.Clients { - if e.Clients[i] != nil { - e.Clients[i].Close() - } - } - - for i := range e.metricsListeners { - e.metricsListeners[i].Close() - } - - // close rafthttp transports - if e.Server != nil { - e.Server.Stop() - } - - // close all idle connections in peer handler (wait up to 1-second) - for i := range e.Peers { - if e.Peers[i] != nil && e.Peers[i].close != nil { - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - e.Peers[i].close(ctx) - cancel() - } - } -} - -func stopServers(ctx context.Context, ss *servers) { - shutdownNow := func() { - // first, close the http.Server - ss.http.Shutdown(ctx) - // then close grpc.Server; cancels all active RPCs - ss.grpc.Stop() - } - - // do not grpc.Server.GracefulStop with TLS enabled etcd server - // See https://github.com/grpc/grpc-go/issues/1384#issuecomment-317124531 - // and https://github.com/coreos/etcd/issues/8916 - if ss.secure { - shutdownNow() - return - } - - ch := make(chan struct{}) - go func() { - defer close(ch) - // close listeners to stop accepting new connections, - // will block on any existing transports - ss.grpc.GracefulStop() - }() - - // wait until all pending RPCs are finished - select { - case <-ch: - case <-ctx.Done(): - // took too long, manually close open transports - // e.g. watch streams - shutdownNow() - - // concurrent GracefulStop should be interrupted - <-ch - } -} - -func (e *Etcd) Err() <-chan error { return e.errc } - -func startPeerListeners(cfg *Config) (peers []*peerListener, err error) { - if err = updateCipherSuites(&cfg.PeerTLSInfo, cfg.CipherSuites); err != nil { - return nil, err - } - if err = cfg.PeerSelfCert(); err != nil { - plog.Fatalf("could not get certs (%v)", err) - } - if !cfg.PeerTLSInfo.Empty() { - plog.Infof("peerTLS: %s", cfg.PeerTLSInfo) - } - - peers = make([]*peerListener, len(cfg.LPUrls)) - defer func() { - if err == nil { - return - } - for i := range peers { - if peers[i] != nil && peers[i].close != nil { - plog.Info("stopping listening for peers on ", cfg.LPUrls[i].String()) - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - peers[i].close(ctx) - cancel() - } - } - }() - - for i, u := range cfg.LPUrls { - if u.Scheme == "http" { - if !cfg.PeerTLSInfo.Empty() { - plog.Warningf("The scheme of peer url %s is HTTP while peer key/cert files are presented. Ignored peer key/cert files.", u.String()) - } - if cfg.PeerTLSInfo.ClientCertAuth { - plog.Warningf("The scheme of peer url %s is HTTP while client cert auth (--peer-client-cert-auth) is enabled. Ignored client cert auth for this url.", u.String()) - } - } - peers[i] = &peerListener{close: func(context.Context) error { return nil }} - peers[i].Listener, err = rafthttp.NewListener(u, &cfg.PeerTLSInfo) - if err != nil { - return nil, err - } - // once serve, overwrite with 'http.Server.Shutdown' - peers[i].close = func(context.Context) error { - return peers[i].Listener.Close() - } - plog.Info("listening for peers on ", u.String()) - } - return peers, nil -} - -// configure peer handlers after rafthttp.Transport started -func (e *Etcd) servePeers() (err error) { - ph := etcdhttp.NewPeerHandler(e.Server) - var peerTLScfg *tls.Config - if !e.cfg.PeerTLSInfo.Empty() { - if peerTLScfg, err = e.cfg.PeerTLSInfo.ServerConfig(); err != nil { - return err - } - } - - for _, p := range e.Peers { - gs := v3rpc.Server(e.Server, peerTLScfg) - m := cmux.New(p.Listener) - go gs.Serve(m.Match(cmux.HTTP2())) - srv := &http.Server{ - Handler: grpcHandlerFunc(gs, ph), - ReadTimeout: 5 * time.Minute, - ErrorLog: defaultLog.New(ioutil.Discard, "", 0), // do not log user error - } - go srv.Serve(m.Match(cmux.Any())) - p.serve = func() error { return m.Serve() } - p.close = func(ctx context.Context) error { - // gracefully shutdown http.Server - // close open listeners, idle connections - // until context cancel or time-out - stopServers(ctx, &servers{secure: peerTLScfg != nil, grpc: gs, http: srv}) - return nil - } - } - - // start peer servers in a goroutine - for _, pl := range e.Peers { - go func(l *peerListener) { - e.errHandler(l.serve()) - }(pl) - } - return nil -} - -func startClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err error) { - if err = updateCipherSuites(&cfg.ClientTLSInfo, cfg.CipherSuites); err != nil { - return nil, err - } - if err = cfg.ClientSelfCert(); err != nil { - plog.Fatalf("could not get certs (%v)", err) - } - if cfg.EnablePprof { - plog.Infof("pprof is enabled under %s", debugutil.HTTPPrefixPProf) - } - - sctxs = make(map[string]*serveCtx) - for _, u := range cfg.LCUrls { - sctx := newServeCtx() - - if u.Scheme == "http" || u.Scheme == "unix" { - if !cfg.ClientTLSInfo.Empty() { - plog.Warningf("The scheme of client url %s is HTTP while peer key/cert files are presented. Ignored key/cert files.", u.String()) - } - if cfg.ClientTLSInfo.ClientCertAuth { - plog.Warningf("The scheme of client url %s is HTTP while client cert auth (--client-cert-auth) is enabled. Ignored client cert auth for this url.", u.String()) - } - } - if (u.Scheme == "https" || u.Scheme == "unixs") && cfg.ClientTLSInfo.Empty() { - return nil, fmt.Errorf("TLS key/cert (--cert-file, --key-file) must be provided for client url %s with HTTPs scheme", u.String()) - } - - proto := "tcp" - addr := u.Host - if u.Scheme == "unix" || u.Scheme == "unixs" { - proto = "unix" - addr = u.Host + u.Path - } - - sctx.secure = u.Scheme == "https" || u.Scheme == "unixs" - sctx.insecure = !sctx.secure - if oldctx := sctxs[addr]; oldctx != nil { - oldctx.secure = oldctx.secure || sctx.secure - oldctx.insecure = oldctx.insecure || sctx.insecure - continue - } - - if sctx.l, err = net.Listen(proto, addr); err != nil { - return nil, err - } - // net.Listener will rewrite ipv4 0.0.0.0 to ipv6 [::], breaking - // hosts that disable ipv6. So, use the address given by the user. - sctx.addr = addr - - if fdLimit, fderr := runtimeutil.FDLimit(); fderr == nil { - if fdLimit <= reservedInternalFDNum { - plog.Fatalf("file descriptor limit[%d] of etcd process is too low, and should be set higher than %d to ensure internal usage", fdLimit, reservedInternalFDNum) - } - sctx.l = transport.LimitListener(sctx.l, int(fdLimit-reservedInternalFDNum)) - } - - if proto == "tcp" { - if sctx.l, err = transport.NewKeepAliveListener(sctx.l, "tcp", nil); err != nil { - return nil, err - } - } - - plog.Info("listening for client requests on ", u.Host) - defer func() { - if err != nil { - sctx.l.Close() - plog.Info("stopping listening for client requests on ", u.Host) - } - }() - for k := range cfg.UserHandlers { - sctx.userHandlers[k] = cfg.UserHandlers[k] - } - sctx.serviceRegister = cfg.ServiceRegister - if cfg.EnablePprof || cfg.Debug { - sctx.registerPprof() - } - if cfg.Debug { - sctx.registerTrace() - } - sctxs[addr] = sctx - } - return sctxs, nil -} - -func (e *Etcd) serveClients() (err error) { - if !e.cfg.ClientTLSInfo.Empty() { - plog.Infof("ClientTLS: %s", e.cfg.ClientTLSInfo) - } - - if e.cfg.CorsInfo.String() != "" { - plog.Infof("cors = %s", e.cfg.CorsInfo) - } - - // Start a client server goroutine for each listen address - var h http.Handler - if e.Config().EnableV2 { - if len(e.Config().ExperimentalEnableV2V3) > 0 { - srv := v2v3.NewServer(v3client.New(e.Server), e.cfg.ExperimentalEnableV2V3) - h = v2http.NewClientHandler(srv, e.Server.Cfg.ReqTimeout()) - } else { - h = v2http.NewClientHandler(e.Server, e.Server.Cfg.ReqTimeout()) - } - } else { - mux := http.NewServeMux() - etcdhttp.HandleBasic(mux, e.Server) - h = mux - } - h = http.Handler(&cors.CORSHandler{Handler: h, Info: e.cfg.CorsInfo}) - - gopts := []grpc.ServerOption{} - if e.cfg.GRPCKeepAliveMinTime > time.Duration(0) { - gopts = append(gopts, grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{ - MinTime: e.cfg.GRPCKeepAliveMinTime, - PermitWithoutStream: false, - })) - } - if e.cfg.GRPCKeepAliveInterval > time.Duration(0) && - e.cfg.GRPCKeepAliveTimeout > time.Duration(0) { - gopts = append(gopts, grpc.KeepaliveParams(keepalive.ServerParameters{ - Time: e.cfg.GRPCKeepAliveInterval, - Timeout: e.cfg.GRPCKeepAliveTimeout, - })) - } - - // start client servers in a goroutine - for _, sctx := range e.sctxs { - go func(s *serveCtx) { - e.errHandler(s.serve(e.Server, &e.cfg.ClientTLSInfo, h, e.errHandler, gopts...)) - }(sctx) - } - return nil -} - -func (e *Etcd) serveMetrics() (err error) { - if e.cfg.Metrics == "extensive" { - grpc_prometheus.EnableHandlingTimeHistogram() - } - - if len(e.cfg.ListenMetricsUrls) > 0 { - metricsMux := http.NewServeMux() - etcdhttp.HandleMetricsHealth(metricsMux, e.Server) - - for _, murl := range e.cfg.ListenMetricsUrls { - tlsInfo := &e.cfg.ClientTLSInfo - if murl.Scheme == "http" { - tlsInfo = nil - } - ml, err := transport.NewListener(murl.Host, murl.Scheme, tlsInfo) - if err != nil { - return err - } - e.metricsListeners = append(e.metricsListeners, ml) - go func(u url.URL, ln net.Listener) { - plog.Info("listening for metrics on ", u.String()) - e.errHandler(http.Serve(ln, metricsMux)) - }(murl, ml) - } - } - return nil -} - -func (e *Etcd) errHandler(err error) { - select { - case <-e.stopc: - return - default: - } - select { - case <-e.stopc: - case e.errc <- err: - } -} - -func parseCompactionRetention(mode, retention string) (ret time.Duration, err error) { - h, err := strconv.Atoi(retention) - if err == nil { - switch mode { - case compactor.ModeRevision: - ret = time.Duration(int64(h)) - case compactor.ModePeriodic: - ret = time.Duration(int64(h)) * time.Hour - } - } else { - // periodic compaction - ret, err = time.ParseDuration(retention) - if err != nil { - return 0, fmt.Errorf("error parsing CompactionRetention: %v", err) - } - } - return ret, nil -} diff --git a/vendor/github.com/coreos/etcd/embed/serve.go b/vendor/github.com/coreos/etcd/embed/serve.go deleted file mode 100644 index 62b8b57805b6..000000000000 --- a/vendor/github.com/coreos/etcd/embed/serve.go +++ /dev/null @@ -1,285 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package embed - -import ( - "context" - "io/ioutil" - defaultLog "log" - "net" - "net/http" - "strings" - - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/v3client" - "github.com/coreos/etcd/etcdserver/api/v3election" - "github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb" - v3electiongw "github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb/gw" - "github.com/coreos/etcd/etcdserver/api/v3lock" - "github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb" - v3lockgw "github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb/gw" - "github.com/coreos/etcd/etcdserver/api/v3rpc" - etcdservergw "github.com/coreos/etcd/etcdserver/etcdserverpb/gw" - "github.com/coreos/etcd/pkg/debugutil" - "github.com/coreos/etcd/pkg/transport" - - gw "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/soheilhy/cmux" - "github.com/tmc/grpc-websocket-proxy/wsproxy" - "golang.org/x/net/trace" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials" -) - -type serveCtx struct { - l net.Listener - addr string - secure bool - insecure bool - - ctx context.Context - cancel context.CancelFunc - - userHandlers map[string]http.Handler - serviceRegister func(*grpc.Server) - serversC chan *servers -} - -type servers struct { - secure bool - grpc *grpc.Server - http *http.Server -} - -func newServeCtx() *serveCtx { - ctx, cancel := context.WithCancel(context.Background()) - return &serveCtx{ctx: ctx, cancel: cancel, userHandlers: make(map[string]http.Handler), - serversC: make(chan *servers, 2), // in case sctx.insecure,sctx.secure true - } -} - -// serve accepts incoming connections on the listener l, -// creating a new service goroutine for each. The service goroutines -// read requests and then call handler to reply to them. -func (sctx *serveCtx) serve( - s *etcdserver.EtcdServer, - tlsinfo *transport.TLSInfo, - handler http.Handler, - errHandler func(error), - gopts ...grpc.ServerOption) (err error) { - logger := defaultLog.New(ioutil.Discard, "etcdhttp", 0) - <-s.ReadyNotify() - plog.Info("ready to serve client requests") - - m := cmux.New(sctx.l) - v3c := v3client.New(s) - servElection := v3election.NewElectionServer(v3c) - servLock := v3lock.NewLockServer(v3c) - - var gs *grpc.Server - defer func() { - if err != nil && gs != nil { - gs.Stop() - } - }() - - if sctx.insecure { - gs = v3rpc.Server(s, nil, gopts...) - v3electionpb.RegisterElectionServer(gs, servElection) - v3lockpb.RegisterLockServer(gs, servLock) - if sctx.serviceRegister != nil { - sctx.serviceRegister(gs) - } - grpcl := m.Match(cmux.HTTP2()) - go func() { errHandler(gs.Serve(grpcl)) }() - - var gwmux *gw.ServeMux - gwmux, err = sctx.registerGateway([]grpc.DialOption{grpc.WithInsecure()}) - if err != nil { - return err - } - - httpmux := sctx.createMux(gwmux, handler) - - srvhttp := &http.Server{ - Handler: wrapMux(httpmux), - ErrorLog: logger, // do not log user error - } - httpl := m.Match(cmux.HTTP1()) - go func() { errHandler(srvhttp.Serve(httpl)) }() - - sctx.serversC <- &servers{grpc: gs, http: srvhttp} - plog.Noticef("serving insecure client requests on %s, this is strongly discouraged!", sctx.l.Addr().String()) - } - - if sctx.secure { - tlscfg, tlsErr := tlsinfo.ServerConfig() - if tlsErr != nil { - return tlsErr - } - gs = v3rpc.Server(s, tlscfg, gopts...) - v3electionpb.RegisterElectionServer(gs, servElection) - v3lockpb.RegisterLockServer(gs, servLock) - if sctx.serviceRegister != nil { - sctx.serviceRegister(gs) - } - handler = grpcHandlerFunc(gs, handler) - - dtls := tlscfg.Clone() - // trust local server - dtls.InsecureSkipVerify = true - creds := credentials.NewTLS(dtls) - opts := []grpc.DialOption{grpc.WithTransportCredentials(creds)} - var gwmux *gw.ServeMux - gwmux, err = sctx.registerGateway(opts) - if err != nil { - return err - } - - var tlsl net.Listener - tlsl, err = transport.NewTLSListener(m.Match(cmux.Any()), tlsinfo) - if err != nil { - return err - } - // TODO: add debug flag; enable logging when debug flag is set - httpmux := sctx.createMux(gwmux, handler) - - srv := &http.Server{ - Handler: wrapMux(httpmux), - TLSConfig: tlscfg, - ErrorLog: logger, // do not log user error - } - go func() { errHandler(srv.Serve(tlsl)) }() - - sctx.serversC <- &servers{secure: true, grpc: gs, http: srv} - plog.Infof("serving client requests on %s", sctx.l.Addr().String()) - } - - close(sctx.serversC) - return m.Serve() -} - -// grpcHandlerFunc returns an http.Handler that delegates to grpcServer on incoming gRPC -// connections or otherHandler otherwise. Given in gRPC docs. -func grpcHandlerFunc(grpcServer *grpc.Server, otherHandler http.Handler) http.Handler { - if otherHandler == nil { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - grpcServer.ServeHTTP(w, r) - }) - } - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") { - grpcServer.ServeHTTP(w, r) - } else { - otherHandler.ServeHTTP(w, r) - } - }) -} - -type registerHandlerFunc func(context.Context, *gw.ServeMux, *grpc.ClientConn) error - -func (sctx *serveCtx) registerGateway(opts []grpc.DialOption) (*gw.ServeMux, error) { - ctx := sctx.ctx - conn, err := grpc.DialContext(ctx, sctx.addr, opts...) - if err != nil { - return nil, err - } - gwmux := gw.NewServeMux() - - handlers := []registerHandlerFunc{ - etcdservergw.RegisterKVHandler, - etcdservergw.RegisterWatchHandler, - etcdservergw.RegisterLeaseHandler, - etcdservergw.RegisterClusterHandler, - etcdservergw.RegisterMaintenanceHandler, - etcdservergw.RegisterAuthHandler, - v3lockgw.RegisterLockHandler, - v3electiongw.RegisterElectionHandler, - } - for _, h := range handlers { - if err := h(ctx, gwmux, conn); err != nil { - return nil, err - } - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - plog.Warningf("failed to close conn to %s: %v", sctx.l.Addr().String(), cerr) - } - }() - - return gwmux, nil -} - -func (sctx *serveCtx) createMux(gwmux *gw.ServeMux, handler http.Handler) *http.ServeMux { - httpmux := http.NewServeMux() - for path, h := range sctx.userHandlers { - httpmux.Handle(path, h) - } - - httpmux.Handle( - "/v3beta/", - wsproxy.WebsocketProxy( - gwmux, - wsproxy.WithRequestMutator( - // Default to the POST method for streams - func(incoming *http.Request, outgoing *http.Request) *http.Request { - outgoing.Method = "POST" - return outgoing - }, - ), - ), - ) - if handler != nil { - httpmux.Handle("/", handler) - } - return httpmux -} - -// wraps HTTP multiplexer to mute requests to /v3alpha -// TODO: deprecate this in 3.4 release -func wrapMux(mux *http.ServeMux) http.Handler { return &v3alphaMutator{mux: mux} } - -type v3alphaMutator struct { - mux *http.ServeMux -} - -func (m *v3alphaMutator) ServeHTTP(rw http.ResponseWriter, req *http.Request) { - if req != nil && req.URL != nil && strings.HasPrefix(req.URL.Path, "/v3alpha/") { - req.URL.Path = strings.Replace(req.URL.Path, "/v3alpha/", "/v3beta/", 1) - } - m.mux.ServeHTTP(rw, req) -} - -func (sctx *serveCtx) registerUserHandler(s string, h http.Handler) { - if sctx.userHandlers[s] != nil { - plog.Warningf("path %s already registered by user handler", s) - return - } - sctx.userHandlers[s] = h -} - -func (sctx *serveCtx) registerPprof() { - for p, h := range debugutil.PProfHandlers() { - sctx.registerUserHandler(p, h) - } -} - -func (sctx *serveCtx) registerTrace() { - reqf := func(w http.ResponseWriter, r *http.Request) { trace.Render(w, r, true) } - sctx.registerUserHandler("/debug/requests", http.HandlerFunc(reqf)) - evf := func(w http.ResponseWriter, r *http.Request) { trace.RenderEvents(w, r, true) } - sctx.registerUserHandler("/debug/events", http.HandlerFunc(evf)) -} diff --git a/vendor/github.com/coreos/etcd/embed/util.go b/vendor/github.com/coreos/etcd/embed/util.go deleted file mode 100644 index 168e031389d7..000000000000 --- a/vendor/github.com/coreos/etcd/embed/util.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package embed - -import ( - "path/filepath" - - "github.com/coreos/etcd/wal" -) - -func isMemberInitialized(cfg *Config) bool { - waldir := cfg.WalDir - if waldir == "" { - waldir = filepath.Join(cfg.Dir, "member", "wal") - } - - return wal.Exist(waldir) -} diff --git a/vendor/github.com/coreos/etcd/error/error.go b/vendor/github.com/coreos/etcd/error/error.go deleted file mode 100644 index b541a628b87f..000000000000 --- a/vendor/github.com/coreos/etcd/error/error.go +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package error describes errors in etcd project. When any change happens, -// Documentation/v2/errorcode.md needs to be updated correspondingly. -package error - -import ( - "encoding/json" - "fmt" - "net/http" -) - -var errors = map[int]string{ - // command related errors - EcodeKeyNotFound: "Key not found", - EcodeTestFailed: "Compare failed", //test and set - EcodeNotFile: "Not a file", - ecodeNoMorePeer: "Reached the max number of peers in the cluster", - EcodeNotDir: "Not a directory", - EcodeNodeExist: "Key already exists", // create - ecodeKeyIsPreserved: "The prefix of given key is a keyword in etcd", - EcodeRootROnly: "Root is read only", - EcodeDirNotEmpty: "Directory not empty", - ecodeExistingPeerAddr: "Peer address has existed", - EcodeUnauthorized: "The request requires user authentication", - - // Post form related errors - ecodeValueRequired: "Value is Required in POST form", - EcodePrevValueRequired: "PrevValue is Required in POST form", - EcodeTTLNaN: "The given TTL in POST form is not a number", - EcodeIndexNaN: "The given index in POST form is not a number", - ecodeValueOrTTLRequired: "Value or TTL is required in POST form", - ecodeTimeoutNaN: "The given timeout in POST form is not a number", - ecodeNameRequired: "Name is required in POST form", - ecodeIndexOrValueRequired: "Index or value is required", - ecodeIndexValueMutex: "Index and value cannot both be specified", - EcodeInvalidField: "Invalid field", - EcodeInvalidForm: "Invalid POST form", - EcodeRefreshValue: "Value provided on refresh", - EcodeRefreshTTLRequired: "A TTL must be provided on refresh", - - // raft related errors - EcodeRaftInternal: "Raft Internal Error", - EcodeLeaderElect: "During Leader Election", - - // etcd related errors - EcodeWatcherCleared: "watcher is cleared due to etcd recovery", - EcodeEventIndexCleared: "The event in requested index is outdated and cleared", - ecodeStandbyInternal: "Standby Internal Error", - ecodeInvalidActiveSize: "Invalid active size", - ecodeInvalidRemoveDelay: "Standby remove delay", - - // client related errors - ecodeClientInternal: "Client Internal Error", -} - -var errorStatus = map[int]int{ - EcodeKeyNotFound: http.StatusNotFound, - EcodeNotFile: http.StatusForbidden, - EcodeDirNotEmpty: http.StatusForbidden, - EcodeUnauthorized: http.StatusUnauthorized, - EcodeTestFailed: http.StatusPreconditionFailed, - EcodeNodeExist: http.StatusPreconditionFailed, - EcodeRaftInternal: http.StatusInternalServerError, - EcodeLeaderElect: http.StatusInternalServerError, -} - -const ( - EcodeKeyNotFound = 100 - EcodeTestFailed = 101 - EcodeNotFile = 102 - ecodeNoMorePeer = 103 - EcodeNotDir = 104 - EcodeNodeExist = 105 - ecodeKeyIsPreserved = 106 - EcodeRootROnly = 107 - EcodeDirNotEmpty = 108 - ecodeExistingPeerAddr = 109 - EcodeUnauthorized = 110 - - ecodeValueRequired = 200 - EcodePrevValueRequired = 201 - EcodeTTLNaN = 202 - EcodeIndexNaN = 203 - ecodeValueOrTTLRequired = 204 - ecodeTimeoutNaN = 205 - ecodeNameRequired = 206 - ecodeIndexOrValueRequired = 207 - ecodeIndexValueMutex = 208 - EcodeInvalidField = 209 - EcodeInvalidForm = 210 - EcodeRefreshValue = 211 - EcodeRefreshTTLRequired = 212 - - EcodeRaftInternal = 300 - EcodeLeaderElect = 301 - - EcodeWatcherCleared = 400 - EcodeEventIndexCleared = 401 - ecodeStandbyInternal = 402 - ecodeInvalidActiveSize = 403 - ecodeInvalidRemoveDelay = 404 - - ecodeClientInternal = 500 -) - -type Error struct { - ErrorCode int `json:"errorCode"` - Message string `json:"message"` - Cause string `json:"cause,omitempty"` - Index uint64 `json:"index"` -} - -func NewRequestError(errorCode int, cause string) *Error { - return NewError(errorCode, cause, 0) -} - -func NewError(errorCode int, cause string, index uint64) *Error { - return &Error{ - ErrorCode: errorCode, - Message: errors[errorCode], - Cause: cause, - Index: index, - } -} - -// Error is for the error interface -func (e Error) Error() string { - return e.Message + " (" + e.Cause + ")" -} - -func (e Error) toJsonString() string { - b, _ := json.Marshal(e) - return string(b) -} - -func (e Error) StatusCode() int { - status, ok := errorStatus[e.ErrorCode] - if !ok { - status = http.StatusBadRequest - } - return status -} - -func (e Error) WriteTo(w http.ResponseWriter) error { - w.Header().Add("X-Etcd-Index", fmt.Sprint(e.Index)) - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(e.StatusCode()) - _, err := w.Write([]byte(e.toJsonString() + "\n")) - return err -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/auth_commands.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/auth_commands.go deleted file mode 100644 index 96a17738fc9e..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/auth_commands.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "os" - "strings" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -func NewAuthCommands() cli.Command { - return cli.Command{ - Name: "auth", - Usage: "overall auth controls", - Subcommands: []cli.Command{ - { - Name: "enable", - Usage: "enable auth access controls", - ArgsUsage: " ", - Action: actionAuthEnable, - }, - { - Name: "disable", - Usage: "disable auth access controls", - ArgsUsage: " ", - Action: actionAuthDisable, - }, - }, - } -} - -func actionAuthEnable(c *cli.Context) error { - authEnableDisable(c, true) - return nil -} - -func actionAuthDisable(c *cli.Context) error { - authEnableDisable(c, false) - return nil -} - -func mustNewAuthAPI(c *cli.Context) client.AuthAPI { - hc := mustNewClient(c) - - if c.GlobalBool("debug") { - fmt.Fprintf(os.Stderr, "Cluster-Endpoints: %s\n", strings.Join(hc.Endpoints(), ", ")) - } - - return client.NewAuthAPI(hc) -} - -func authEnableDisable(c *cli.Context, enable bool) { - if len(c.Args()) != 0 { - fmt.Fprintln(os.Stderr, "No arguments accepted") - os.Exit(1) - } - s := mustNewAuthAPI(c) - ctx, cancel := contextWithTotalTimeout(c) - var err error - if enable { - err = s.Enable(ctx) - } else { - err = s.Disable(ctx) - } - cancel() - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - if enable { - fmt.Println("Authentication Enabled") - } else { - fmt.Println("Authentication Disabled") - } -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/backup_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/backup_command.go deleted file mode 100644 index 82e61d8ab291..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/backup_command.go +++ /dev/null @@ -1,256 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "encoding/binary" - "log" - "os" - "path" - "path/filepath" - "regexp" - "time" - - "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/pkg/fileutil" - "github.com/coreos/etcd/pkg/idutil" - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/snap" - "github.com/coreos/etcd/wal" - "github.com/coreos/etcd/wal/walpb" - - bolt "github.com/coreos/bbolt" - "github.com/urfave/cli" -) - -func NewBackupCommand() cli.Command { - return cli.Command{ - Name: "backup", - Usage: "backup an etcd directory", - ArgsUsage: " ", - Flags: []cli.Flag{ - cli.StringFlag{Name: "data-dir", Value: "", Usage: "Path to the etcd data dir"}, - cli.StringFlag{Name: "wal-dir", Value: "", Usage: "Path to the etcd wal dir"}, - cli.StringFlag{Name: "backup-dir", Value: "", Usage: "Path to the backup dir"}, - cli.StringFlag{Name: "backup-wal-dir", Value: "", Usage: "Path to the backup wal dir"}, - cli.BoolFlag{Name: "with-v3", Usage: "Backup v3 backend data"}, - }, - Action: handleBackup, - } -} - -// handleBackup handles a request that intends to do a backup. -func handleBackup(c *cli.Context) error { - var srcWAL string - var destWAL string - - withV3 := c.Bool("with-v3") - srcSnap := filepath.Join(c.String("data-dir"), "member", "snap") - destSnap := filepath.Join(c.String("backup-dir"), "member", "snap") - - if c.String("wal-dir") != "" { - srcWAL = c.String("wal-dir") - } else { - srcWAL = filepath.Join(c.String("data-dir"), "member", "wal") - } - - if c.String("backup-wal-dir") != "" { - destWAL = c.String("backup-wal-dir") - } else { - destWAL = filepath.Join(c.String("backup-dir"), "member", "wal") - } - - if err := fileutil.CreateDirAll(destSnap); err != nil { - log.Fatalf("failed creating backup snapshot dir %v: %v", destSnap, err) - } - - walsnap := saveSnap(destSnap, srcSnap) - metadata, state, ents := loadWAL(srcWAL, walsnap, withV3) - saveDB(filepath.Join(destSnap, "db"), filepath.Join(srcSnap, "db"), state.Commit, withV3) - - idgen := idutil.NewGenerator(0, time.Now()) - metadata.NodeID = idgen.Next() - metadata.ClusterID = idgen.Next() - - neww, err := wal.Create(destWAL, pbutil.MustMarshal(&metadata)) - if err != nil { - log.Fatal(err) - } - defer neww.Close() - if err := neww.Save(state, ents); err != nil { - log.Fatal(err) - } - if err := neww.SaveSnapshot(walsnap); err != nil { - log.Fatal(err) - } - - return nil -} - -func saveSnap(destSnap, srcSnap string) (walsnap walpb.Snapshot) { - ss := snap.New(srcSnap) - snapshot, err := ss.Load() - if err != nil && err != snap.ErrNoSnapshot { - log.Fatal(err) - } - if snapshot != nil { - walsnap.Index, walsnap.Term = snapshot.Metadata.Index, snapshot.Metadata.Term - newss := snap.New(destSnap) - if err = newss.SaveSnap(*snapshot); err != nil { - log.Fatal(err) - } - } - return walsnap -} - -func loadWAL(srcWAL string, walsnap walpb.Snapshot, v3 bool) (etcdserverpb.Metadata, raftpb.HardState, []raftpb.Entry) { - w, err := wal.OpenForRead(srcWAL, walsnap) - if err != nil { - log.Fatal(err) - } - defer w.Close() - wmetadata, state, ents, err := w.ReadAll() - switch err { - case nil: - case wal.ErrSnapshotNotFound: - log.Printf("Failed to find the match snapshot record %+v in wal %v.", walsnap, srcWAL) - log.Printf("etcdctl will add it back. Start auto fixing...") - default: - log.Fatal(err) - } - - re := path.Join(membership.StoreMembersPrefix, "[[:xdigit:]]{1,16}", "attributes") - memberAttrRE := regexp.MustCompile(re) - - removed := uint64(0) - i := 0 - remove := func() { - ents = append(ents[:i], ents[i+1:]...) - removed++ - i-- - } - for i = 0; i < len(ents); i++ { - ents[i].Index -= removed - if ents[i].Type == raftpb.EntryConfChange { - log.Println("ignoring EntryConfChange raft entry") - remove() - continue - } - - var raftReq etcdserverpb.InternalRaftRequest - var v2Req *etcdserverpb.Request - if pbutil.MaybeUnmarshal(&raftReq, ents[i].Data) { - v2Req = raftReq.V2 - } else { - v2Req = &etcdserverpb.Request{} - pbutil.MustUnmarshal(v2Req, ents[i].Data) - } - - if v2Req != nil && v2Req.Method == "PUT" && memberAttrRE.MatchString(v2Req.Path) { - log.Println("ignoring member attribute update on", v2Req.Path) - remove() - continue - } - - if v2Req != nil { - continue - } - - if v3 || raftReq.Header == nil { - continue - } - log.Println("ignoring v3 raft entry") - remove() - } - state.Commit -= removed - var metadata etcdserverpb.Metadata - pbutil.MustUnmarshal(&metadata, wmetadata) - return metadata, state, ents -} - -// saveDB copies the v3 backend and strips cluster information. -func saveDB(destDB, srcDB string, idx uint64, v3 bool) { - // open src db to safely copy db state - if v3 { - var src *bolt.DB - ch := make(chan *bolt.DB, 1) - go func() { - src, err := bolt.Open(srcDB, 0444, &bolt.Options{ReadOnly: true}) - if err != nil { - log.Fatal(err) - } - ch <- src - }() - select { - case src = <-ch: - case <-time.After(time.Second): - log.Println("waiting to acquire lock on", srcDB) - src = <-ch - } - defer src.Close() - - tx, err := src.Begin(false) - if err != nil { - log.Fatal(err) - } - - // copy srcDB to destDB - dest, err := os.Create(destDB) - if err != nil { - log.Fatal(err) - } - if _, err := tx.WriteTo(dest); err != nil { - log.Fatal(err) - } - dest.Close() - if err := tx.Rollback(); err != nil { - log.Fatal(err) - } - } - - db, err := bolt.Open(destDB, 0644, &bolt.Options{}) - if err != nil { - log.Fatal(err) - } - tx, err := db.Begin(true) - if err != nil { - log.Fatal(err) - } - - // remove membership information; should be clobbered by --force-new-cluster - for _, bucket := range []string{"members", "members_removed", "cluster"} { - tx.DeleteBucket([]byte(bucket)) - } - - // update consistent index to match hard state - if !v3 { - idxBytes := make([]byte, 8) - binary.BigEndian.PutUint64(idxBytes, idx) - b, err := tx.CreateBucketIfNotExists([]byte("meta")) - if err != nil { - log.Fatal(err) - } - b.Put([]byte("consistent_index"), idxBytes) - } - - if err := tx.Commit(); err != nil { - log.Fatal(err) - } - if err := db.Close(); err != nil { - log.Fatal(err) - } -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/cluster_health.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/cluster_health.go deleted file mode 100644 index ec0bb241de41..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/cluster_health.go +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "os" - "os/signal" - "time" - - "github.com/coreos/etcd/client" - - "github.com/urfave/cli" -) - -func NewClusterHealthCommand() cli.Command { - return cli.Command{ - Name: "cluster-health", - Usage: "check the health of the etcd cluster", - ArgsUsage: " ", - Flags: []cli.Flag{ - cli.BoolFlag{Name: "forever, f", Usage: "forever check the health every 10 second until CTRL+C"}, - }, - Action: handleClusterHealth, - } -} - -func handleClusterHealth(c *cli.Context) error { - forever := c.Bool("forever") - if forever { - sigch := make(chan os.Signal, 1) - signal.Notify(sigch, os.Interrupt) - - go func() { - <-sigch - os.Exit(0) - }() - } - - tr, err := getTransport(c) - if err != nil { - handleError(c, ExitServerError, err) - } - - hc := http.Client{ - Transport: tr, - } - - cln := mustNewClientNoSync(c) - mi := client.NewMembersAPI(cln) - ms, err := mi.List(context.TODO()) - if err != nil { - fmt.Println("cluster may be unhealthy: failed to list members") - handleError(c, ExitServerError, err) - } - - for { - healthyMembers := 0 - for _, m := range ms { - if len(m.ClientURLs) == 0 { - fmt.Printf("member %s is unreachable: no available published client urls\n", m.ID) - continue - } - - checked := false - for _, url := range m.ClientURLs { - resp, err := hc.Get(url + "/health") - if err != nil { - fmt.Printf("failed to check the health of member %s on %s: %v\n", m.ID, url, err) - continue - } - - result := struct{ Health string }{} - nresult := struct{ Health bool }{} - bytes, err := ioutil.ReadAll(resp.Body) - if err != nil { - fmt.Printf("failed to check the health of member %s on %s: %v\n", m.ID, url, err) - continue - } - resp.Body.Close() - - err = json.Unmarshal(bytes, &result) - if err != nil { - err = json.Unmarshal(bytes, &nresult) - } - if err != nil { - fmt.Printf("failed to check the health of member %s on %s: %v\n", m.ID, url, err) - continue - } - - checked = true - if result.Health == "true" || nresult.Health { - fmt.Printf("member %s is healthy: got healthy result from %s\n", m.ID, url) - healthyMembers++ - } else { - fmt.Printf("member %s is unhealthy: got unhealthy result from %s\n", m.ID, url) - } - break - } - if !checked { - fmt.Printf("member %s is unreachable: %v are all unreachable\n", m.ID, m.ClientURLs) - } - } - switch healthyMembers { - case len(ms): - fmt.Println("cluster is healthy") - case 0: - fmt.Println("cluster is unavailable") - default: - fmt.Println("cluster is degraded") - } - - if !forever { - if healthyMembers == len(ms) { - os.Exit(ExitSuccess) - } - os.Exit(ExitClusterNotHealthy) - } - - fmt.Printf("\nnext check after 10 second...\n\n") - time.Sleep(10 * time.Second) - } -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/doc.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/doc.go deleted file mode 100644 index cedf3f762f62..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package command is a set of libraries for etcdctl commands. -package command diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/error.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/error.go deleted file mode 100644 index e673fa39cf1d..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/error.go +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "encoding/json" - "fmt" - "os" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -const ( - ExitSuccess = iota - ExitBadArgs - ExitBadConnection - ExitBadAuth - ExitServerError - ExitClusterNotHealthy -) - -func handleError(c *cli.Context, code int, err error) { - if c.GlobalString("output") == "json" { - if err, ok := err.(*client.Error); ok { - b, err := json.Marshal(err) - if err != nil { - panic(err) - } - fmt.Fprintln(os.Stderr, string(b)) - os.Exit(code) - } - } - - fmt.Fprintln(os.Stderr, "Error: ", err) - if cerr, ok := err.(*client.ClusterError); ok { - fmt.Fprintln(os.Stderr, cerr.Detail()) - } - os.Exit(code) -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/exec_watch_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/exec_watch_command.go deleted file mode 100644 index cc3478cc32f1..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/exec_watch_command.go +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "errors" - "fmt" - "os" - "os/exec" - "os/signal" - - "github.com/coreos/etcd/client" - - "github.com/urfave/cli" -) - -// NewExecWatchCommand returns the CLI command for "exec-watch". -func NewExecWatchCommand() cli.Command { - return cli.Command{ - Name: "exec-watch", - Usage: "watch a key for changes and exec an executable", - ArgsUsage: " [args...]", - Flags: []cli.Flag{ - cli.IntFlag{Name: "after-index", Value: 0, Usage: "watch after the given index"}, - cli.BoolFlag{Name: "recursive, r", Usage: "watch all values for key and child keys"}, - }, - Action: func(c *cli.Context) error { - execWatchCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// execWatchCommandFunc executes the "exec-watch" command. -func execWatchCommandFunc(c *cli.Context, ki client.KeysAPI) { - args := c.Args() - argslen := len(args) - - if argslen < 2 { - handleError(c, ExitBadArgs, errors.New("key and command to exec required")) - } - - var ( - key string - cmdArgs []string - ) - - foundSep := false - for i := range args { - if args[i] == "--" && i != 0 { - foundSep = true - break - } - } - - if foundSep { - key = args[0] - cmdArgs = args[2:] - } else { - // If no flag is parsed, the order of key and cmdArgs will be switched and - // args will not contain `--`. - key = args[argslen-1] - cmdArgs = args[:argslen-1] - } - - index := 0 - if c.Int("after-index") != 0 { - index = c.Int("after-index") - } - - recursive := c.Bool("recursive") - - sigch := make(chan os.Signal, 1) - signal.Notify(sigch, os.Interrupt) - - go func() { - <-sigch - os.Exit(0) - }() - - w := ki.Watcher(key, &client.WatcherOptions{AfterIndex: uint64(index), Recursive: recursive}) - - for { - resp, err := w.Next(context.TODO()) - if err != nil { - handleError(c, ExitServerError, err) - } - if resp.Node.Dir { - fmt.Fprintf(os.Stderr, "Ignored dir %s change\n", resp.Node.Key) - continue - } - - cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...) - cmd.Env = environResponse(resp, os.Environ()) - - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - - go func() { - err := cmd.Start() - if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) - os.Exit(1) - } - cmd.Wait() - }() - } -} - -func environResponse(resp *client.Response, env []string) []string { - env = append(env, "ETCD_WATCH_ACTION="+resp.Action) - env = append(env, "ETCD_WATCH_MODIFIED_INDEX="+fmt.Sprintf("%d", resp.Node.ModifiedIndex)) - env = append(env, "ETCD_WATCH_KEY="+resp.Node.Key) - env = append(env, "ETCD_WATCH_VALUE="+resp.Node.Value) - return env -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/format.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/format.go deleted file mode 100644 index 4a5d4a6a4404..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/format.go +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "encoding/json" - "fmt" - "os" - - "github.com/coreos/etcd/client" -) - -// printResponseKey only supports to print key correctly. -func printResponseKey(resp *client.Response, format string) { - // Format the result. - switch format { - case "simple": - if resp.Action != "delete" { - fmt.Println(resp.Node.Value) - } else { - fmt.Println("PrevNode.Value:", resp.PrevNode.Value) - } - case "extended": - // Extended prints in a rfc2822 style format - fmt.Println("Key:", resp.Node.Key) - fmt.Println("Created-Index:", resp.Node.CreatedIndex) - fmt.Println("Modified-Index:", resp.Node.ModifiedIndex) - - if resp.PrevNode != nil { - fmt.Println("PrevNode.Value:", resp.PrevNode.Value) - } - - fmt.Println("TTL:", resp.Node.TTL) - fmt.Println("Index:", resp.Index) - if resp.Action != "delete" { - fmt.Println("") - fmt.Println(resp.Node.Value) - } - case "json": - b, err := json.Marshal(resp) - if err != nil { - panic(err) - } - fmt.Println(string(b)) - default: - fmt.Fprintln(os.Stderr, "Unsupported output format:", format) - } -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/get_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/get_command.go deleted file mode 100644 index 7f1fc4db1a26..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/get_command.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "errors" - "fmt" - "os" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -// NewGetCommand returns the CLI command for "get". -func NewGetCommand() cli.Command { - return cli.Command{ - Name: "get", - Usage: "retrieve the value of a key", - ArgsUsage: "", - Flags: []cli.Flag{ - cli.BoolFlag{Name: "sort", Usage: "returns result in sorted order"}, - cli.BoolFlag{Name: "quorum, q", Usage: "require quorum for get request"}, - }, - Action: func(c *cli.Context) error { - getCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// getCommandFunc executes the "get" command. -func getCommandFunc(c *cli.Context, ki client.KeysAPI) { - if len(c.Args()) == 0 { - handleError(c, ExitBadArgs, errors.New("key required")) - } - - key := c.Args()[0] - sorted := c.Bool("sort") - quorum := c.Bool("quorum") - - ctx, cancel := contextWithTotalTimeout(c) - resp, err := ki.Get(ctx, key, &client.GetOptions{Sort: sorted, Quorum: quorum}) - cancel() - if err != nil { - handleError(c, ExitServerError, err) - } - - if resp.Node.Dir { - fmt.Fprintln(os.Stderr, fmt.Sprintf("%s: is a directory", resp.Node.Key)) - os.Exit(1) - } - - printResponseKey(resp, c.GlobalString("output")) -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/ls_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/ls_command.go deleted file mode 100644 index b2e94fb938e6..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/ls_command.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -func NewLsCommand() cli.Command { - return cli.Command{ - Name: "ls", - Usage: "retrieve a directory", - ArgsUsage: "[key]", - Flags: []cli.Flag{ - cli.BoolFlag{Name: "sort", Usage: "returns result in sorted order"}, - cli.BoolFlag{Name: "recursive, r", Usage: "returns all key names recursively for the given path"}, - cli.BoolFlag{Name: "p", Usage: "append slash (/) to directories"}, - cli.BoolFlag{Name: "quorum, q", Usage: "require quorum for get request"}, - }, - Action: func(c *cli.Context) error { - lsCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// lsCommandFunc executes the "ls" command. -func lsCommandFunc(c *cli.Context, ki client.KeysAPI) { - key := "/" - if len(c.Args()) != 0 { - key = c.Args()[0] - } - - sort := c.Bool("sort") - recursive := c.Bool("recursive") - quorum := c.Bool("quorum") - - ctx, cancel := contextWithTotalTimeout(c) - resp, err := ki.Get(ctx, key, &client.GetOptions{Sort: sort, Recursive: recursive, Quorum: quorum}) - cancel() - if err != nil { - handleError(c, ExitServerError, err) - } - - printLs(c, resp) -} - -// printLs writes a response out in a manner similar to the `ls` command in unix. -// Non-empty directories list their contents and files list their name. -func printLs(c *cli.Context, resp *client.Response) { - if c.GlobalString("output") == "simple" { - if !resp.Node.Dir { - fmt.Println(resp.Node.Key) - } - for _, node := range resp.Node.Nodes { - rPrint(c, node) - } - } else { - // user wants JSON or extended output - printResponseKey(resp, c.GlobalString("output")) - } -} - -// rPrint recursively prints out the nodes in the node structure. -func rPrint(c *cli.Context, n *client.Node) { - if n.Dir && c.Bool("p") { - fmt.Println(fmt.Sprintf("%v/", n.Key)) - } else { - fmt.Println(n.Key) - } - - for _, node := range n.Nodes { - rPrint(c, node) - } -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/member_commands.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/member_commands.go deleted file mode 100644 index 84747873b635..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/member_commands.go +++ /dev/null @@ -1,207 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "os" - "strings" - - "github.com/urfave/cli" -) - -func NewMemberCommand() cli.Command { - return cli.Command{ - Name: "member", - Usage: "member add, remove and list subcommands", - Subcommands: []cli.Command{ - { - Name: "list", - Usage: "enumerate existing cluster members", - ArgsUsage: " ", - Action: actionMemberList, - }, - { - Name: "add", - Usage: "add a new member to the etcd cluster", - ArgsUsage: " ", - Action: actionMemberAdd, - }, - { - Name: "remove", - Usage: "remove an existing member from the etcd cluster", - ArgsUsage: "", - Action: actionMemberRemove, - }, - { - Name: "update", - Usage: "update an existing member in the etcd cluster", - ArgsUsage: " ", - Action: actionMemberUpdate, - }, - }, - } -} - -func actionMemberList(c *cli.Context) error { - if len(c.Args()) != 0 { - fmt.Fprintln(os.Stderr, "No arguments accepted") - os.Exit(1) - } - mAPI := mustNewMembersAPI(c) - ctx, cancel := contextWithTotalTimeout(c) - defer cancel() - - members, err := mAPI.List(ctx) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - leader, err := mAPI.Leader(ctx) - if err != nil { - fmt.Fprintln(os.Stderr, "Failed to get leader: ", err) - os.Exit(1) - } - - for _, m := range members { - isLeader := false - if m.ID == leader.ID { - isLeader = true - } - if len(m.Name) == 0 { - fmt.Printf("%s[unstarted]: peerURLs=%s\n", m.ID, strings.Join(m.PeerURLs, ",")) - } else { - fmt.Printf("%s: name=%s peerURLs=%s clientURLs=%s isLeader=%v\n", m.ID, m.Name, strings.Join(m.PeerURLs, ","), strings.Join(m.ClientURLs, ","), isLeader) - } - } - - return nil -} - -func actionMemberAdd(c *cli.Context) error { - args := c.Args() - if len(args) != 2 { - fmt.Fprintln(os.Stderr, "Provide a name and a single member peerURL") - os.Exit(1) - } - - mAPI := mustNewMembersAPI(c) - - url := args[1] - ctx, cancel := contextWithTotalTimeout(c) - defer cancel() - - m, err := mAPI.Add(ctx, url) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - newID := m.ID - newName := args[0] - fmt.Printf("Added member named %s with ID %s to cluster\n", newName, newID) - - members, err := mAPI.List(ctx) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - conf := []string{} - for _, memb := range members { - for _, u := range memb.PeerURLs { - n := memb.Name - if memb.ID == newID { - n = newName - } - conf = append(conf, fmt.Sprintf("%s=%s", n, u)) - } - } - - fmt.Print("\n") - fmt.Printf("ETCD_NAME=%q\n", newName) - fmt.Printf("ETCD_INITIAL_CLUSTER=%q\n", strings.Join(conf, ",")) - fmt.Printf("ETCD_INITIAL_CLUSTER_STATE=\"existing\"\n") - return nil -} - -func actionMemberRemove(c *cli.Context) error { - args := c.Args() - if len(args) != 1 { - fmt.Fprintln(os.Stderr, "Provide a single member ID") - os.Exit(1) - } - removalID := args[0] - - mAPI := mustNewMembersAPI(c) - - ctx, cancel := contextWithTotalTimeout(c) - defer cancel() - // Get the list of members. - members, err := mAPI.List(ctx) - if err != nil { - fmt.Fprintln(os.Stderr, "Error while verifying ID against known members:", err.Error()) - os.Exit(1) - } - // Sanity check the input. - foundID := false - for _, m := range members { - if m.ID == removalID { - foundID = true - } - if m.Name == removalID { - // Note that, so long as it's not ambiguous, we *could* do the right thing by name here. - fmt.Fprintf(os.Stderr, "Found a member named %s; if this is correct, please use its ID, eg:\n\tetcdctl member remove %s\n", m.Name, m.ID) - fmt.Fprintf(os.Stderr, "For more details, read the documentation at https://github.com/coreos/etcd/blob/master/Documentation/runtime-configuration.md#remove-a-member\n\n") - } - } - if !foundID { - fmt.Fprintf(os.Stderr, "Couldn't find a member in the cluster with an ID of %s.\n", removalID) - os.Exit(1) - } - - // Actually attempt to remove the member. - err = mAPI.Remove(ctx, removalID) - if err != nil { - fmt.Fprintf(os.Stderr, "Received an error trying to remove member %s: %s", removalID, err.Error()) - os.Exit(1) - } - - fmt.Printf("Removed member %s from cluster\n", removalID) - return nil -} - -func actionMemberUpdate(c *cli.Context) error { - args := c.Args() - if len(args) != 2 { - fmt.Fprintln(os.Stderr, "Provide an ID and a list of comma separated peerURL (0xabcd http://example.com,http://example1.com)") - os.Exit(1) - } - - mAPI := mustNewMembersAPI(c) - - mid := args[0] - urls := args[1] - ctx, cancel := contextWithTotalTimeout(c) - err := mAPI.Update(ctx, mid, strings.Split(urls, ",")) - cancel() - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - fmt.Printf("Updated member with ID %s in cluster\n", mid) - return nil -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/mk_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/mk_command.go deleted file mode 100644 index f62415350e11..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/mk_command.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "errors" - "os" - "time" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -// NewMakeCommand returns the CLI command for "mk". -func NewMakeCommand() cli.Command { - return cli.Command{ - Name: "mk", - Usage: "make a new key with a given value", - ArgsUsage: " ", - Flags: []cli.Flag{ - cli.BoolFlag{Name: "in-order", Usage: "create in-order key under directory "}, - cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live in seconds"}, - }, - Action: func(c *cli.Context) error { - mkCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// mkCommandFunc executes the "mk" command. -func mkCommandFunc(c *cli.Context, ki client.KeysAPI) { - if len(c.Args()) == 0 { - handleError(c, ExitBadArgs, errors.New("key required")) - } - key := c.Args()[0] - value, err := argOrStdin(c.Args(), os.Stdin, 1) - if err != nil { - handleError(c, ExitBadArgs, errors.New("value required")) - } - - ttl := c.Int("ttl") - inorder := c.Bool("in-order") - - var resp *client.Response - ctx, cancel := contextWithTotalTimeout(c) - if !inorder { - // Since PrevNoExist means that the Node must not exist previously, - // this Set method always creates a new key. Therefore, mk command - // succeeds only if the key did not previously exist, and the command - // prevents one from overwriting values accidentally. - resp, err = ki.Set(ctx, key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevNoExist}) - } else { - // If in-order flag is specified then create an inorder key under - // the directory identified by the key argument. - resp, err = ki.CreateInOrder(ctx, key, value, &client.CreateInOrderOptions{TTL: time.Duration(ttl) * time.Second}) - } - cancel() - if err != nil { - handleError(c, ExitServerError, err) - } - - printResponseKey(resp, c.GlobalString("output")) -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/mkdir_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/mkdir_command.go deleted file mode 100644 index 1d17b7b91031..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/mkdir_command.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "errors" - "time" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -// NewMakeDirCommand returns the CLI command for "mkdir". -func NewMakeDirCommand() cli.Command { - return cli.Command{ - Name: "mkdir", - Usage: "make a new directory", - ArgsUsage: "", - Flags: []cli.Flag{ - cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live in seconds"}, - }, - Action: func(c *cli.Context) error { - mkdirCommandFunc(c, mustNewKeyAPI(c), client.PrevNoExist) - return nil - }, - } -} - -// mkdirCommandFunc executes the "mkdir" command. -func mkdirCommandFunc(c *cli.Context, ki client.KeysAPI, prevExist client.PrevExistType) { - if len(c.Args()) == 0 { - handleError(c, ExitBadArgs, errors.New("key required")) - } - - key := c.Args()[0] - ttl := c.Int("ttl") - - ctx, cancel := contextWithTotalTimeout(c) - resp, err := ki.Set(ctx, key, "", &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: prevExist}) - cancel() - if err != nil { - handleError(c, ExitServerError, err) - } - if c.GlobalString("output") != "simple" { - printResponseKey(resp, c.GlobalString("output")) - } -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/rm_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/rm_command.go deleted file mode 100644 index c6f173be776a..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/rm_command.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "errors" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -// NewRemoveCommand returns the CLI command for "rm". -func NewRemoveCommand() cli.Command { - return cli.Command{ - Name: "rm", - Usage: "remove a key or a directory", - ArgsUsage: "", - Flags: []cli.Flag{ - cli.BoolFlag{Name: "dir", Usage: "removes the key if it is an empty directory or a key-value pair"}, - cli.BoolFlag{Name: "recursive, r", Usage: "removes the key and all child keys(if it is a directory)"}, - cli.StringFlag{Name: "with-value", Value: "", Usage: "previous value"}, - cli.IntFlag{Name: "with-index", Value: 0, Usage: "previous index"}, - }, - Action: func(c *cli.Context) error { - rmCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// rmCommandFunc executes the "rm" command. -func rmCommandFunc(c *cli.Context, ki client.KeysAPI) { - if len(c.Args()) == 0 { - handleError(c, ExitBadArgs, errors.New("key required")) - } - key := c.Args()[0] - recursive := c.Bool("recursive") - dir := c.Bool("dir") - prevValue := c.String("with-value") - prevIndex := c.Int("with-index") - - ctx, cancel := contextWithTotalTimeout(c) - resp, err := ki.Delete(ctx, key, &client.DeleteOptions{PrevIndex: uint64(prevIndex), PrevValue: prevValue, Dir: dir, Recursive: recursive}) - cancel() - if err != nil { - handleError(c, ExitServerError, err) - } - if !resp.Node.Dir || c.GlobalString("output") != "simple" { - printResponseKey(resp, c.GlobalString("output")) - } -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/rmdir_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/rmdir_command.go deleted file mode 100644 index cb3089548f07..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/rmdir_command.go +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "errors" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -// NewRemoveDirCommand returns the CLI command for "rmdir". -func NewRemoveDirCommand() cli.Command { - return cli.Command{ - Name: "rmdir", - Usage: "removes the key if it is an empty directory or a key-value pair", - ArgsUsage: "", - Action: func(c *cli.Context) error { - rmdirCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// rmdirCommandFunc executes the "rmdir" command. -func rmdirCommandFunc(c *cli.Context, ki client.KeysAPI) { - if len(c.Args()) == 0 { - handleError(c, ExitBadArgs, errors.New("key required")) - } - key := c.Args()[0] - - ctx, cancel := contextWithTotalTimeout(c) - resp, err := ki.Delete(ctx, key, &client.DeleteOptions{Dir: true}) - cancel() - if err != nil { - handleError(c, ExitServerError, err) - } - - if !resp.Node.Dir || c.GlobalString("output") != "simple" { - printResponseKey(resp, c.GlobalString("output")) - } -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/role_commands.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/role_commands.go deleted file mode 100644 index 838b040623e1..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/role_commands.go +++ /dev/null @@ -1,255 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "os" - "reflect" - "strings" - - "github.com/coreos/etcd/client" - "github.com/coreos/etcd/pkg/pathutil" - "github.com/urfave/cli" -) - -func NewRoleCommands() cli.Command { - return cli.Command{ - Name: "role", - Usage: "role add, grant and revoke subcommands", - Subcommands: []cli.Command{ - { - Name: "add", - Usage: "add a new role for the etcd cluster", - ArgsUsage: " ", - Action: actionRoleAdd, - }, - { - Name: "get", - Usage: "get details for a role", - ArgsUsage: "", - Action: actionRoleGet, - }, - { - Name: "list", - Usage: "list all roles", - ArgsUsage: " ", - Action: actionRoleList, - }, - { - Name: "remove", - Usage: "remove a role from the etcd cluster", - ArgsUsage: "", - Action: actionRoleRemove, - }, - { - Name: "grant", - Usage: "grant path matches to an etcd role", - ArgsUsage: "", - Flags: []cli.Flag{ - cli.StringFlag{Name: "path", Value: "", Usage: "Path granted for the role to access"}, - cli.BoolFlag{Name: "read", Usage: "Grant read-only access"}, - cli.BoolFlag{Name: "write", Usage: "Grant write-only access"}, - cli.BoolFlag{Name: "readwrite, rw", Usage: "Grant read-write access"}, - }, - Action: actionRoleGrant, - }, - { - Name: "revoke", - Usage: "revoke path matches for an etcd role", - ArgsUsage: "", - Flags: []cli.Flag{ - cli.StringFlag{Name: "path", Value: "", Usage: "Path revoked for the role to access"}, - cli.BoolFlag{Name: "read", Usage: "Revoke read access"}, - cli.BoolFlag{Name: "write", Usage: "Revoke write access"}, - cli.BoolFlag{Name: "readwrite, rw", Usage: "Revoke read-write access"}, - }, - Action: actionRoleRevoke, - }, - }, - } -} - -func mustNewAuthRoleAPI(c *cli.Context) client.AuthRoleAPI { - hc := mustNewClient(c) - - if c.GlobalBool("debug") { - fmt.Fprintf(os.Stderr, "Cluster-Endpoints: %s\n", strings.Join(hc.Endpoints(), ", ")) - } - - return client.NewAuthRoleAPI(hc) -} - -func actionRoleList(c *cli.Context) error { - if len(c.Args()) != 0 { - fmt.Fprintln(os.Stderr, "No arguments accepted") - os.Exit(1) - } - r := mustNewAuthRoleAPI(c) - ctx, cancel := contextWithTotalTimeout(c) - roles, err := r.ListRoles(ctx) - cancel() - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - for _, role := range roles { - fmt.Printf("%s\n", role) - } - - return nil -} - -func actionRoleAdd(c *cli.Context) error { - api, role := mustRoleAPIAndName(c) - ctx, cancel := contextWithTotalTimeout(c) - defer cancel() - currentRole, _ := api.GetRole(ctx, role) - if currentRole != nil { - fmt.Fprintf(os.Stderr, "Role %s already exists\n", role) - os.Exit(1) - } - - err := api.AddRole(ctx, role) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - fmt.Printf("Role %s created\n", role) - return nil -} - -func actionRoleRemove(c *cli.Context) error { - api, role := mustRoleAPIAndName(c) - ctx, cancel := contextWithTotalTimeout(c) - err := api.RemoveRole(ctx, role) - cancel() - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - fmt.Printf("Role %s removed\n", role) - return nil -} - -func actionRoleGrant(c *cli.Context) error { - roleGrantRevoke(c, true) - return nil -} - -func actionRoleRevoke(c *cli.Context) error { - roleGrantRevoke(c, false) - return nil -} - -func roleGrantRevoke(c *cli.Context, grant bool) { - path := c.String("path") - if path == "" { - fmt.Fprintln(os.Stderr, "No path specified; please use `--path`") - os.Exit(1) - } - if pathutil.CanonicalURLPath(path) != path { - fmt.Fprintf(os.Stderr, "Not canonical path; please use `--path=%s`\n", pathutil.CanonicalURLPath(path)) - os.Exit(1) - } - - read := c.Bool("read") - write := c.Bool("write") - rw := c.Bool("readwrite") - permcount := 0 - for _, v := range []bool{read, write, rw} { - if v { - permcount++ - } - } - if permcount != 1 { - fmt.Fprintln(os.Stderr, "Please specify exactly one of --read, --write or --readwrite") - os.Exit(1) - } - var permType client.PermissionType - switch { - case read: - permType = client.ReadPermission - case write: - permType = client.WritePermission - case rw: - permType = client.ReadWritePermission - } - - api, role := mustRoleAPIAndName(c) - ctx, cancel := contextWithTotalTimeout(c) - defer cancel() - currentRole, err := api.GetRole(ctx, role) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - var newRole *client.Role - if grant { - newRole, err = api.GrantRoleKV(ctx, role, []string{path}, permType) - } else { - newRole, err = api.RevokeRoleKV(ctx, role, []string{path}, permType) - } - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - if reflect.DeepEqual(newRole, currentRole) { - if grant { - fmt.Printf("Role unchanged; already granted") - } else { - fmt.Printf("Role unchanged; already revoked") - } - } - - fmt.Printf("Role %s updated\n", role) -} - -func actionRoleGet(c *cli.Context) error { - api, rolename := mustRoleAPIAndName(c) - - ctx, cancel := contextWithTotalTimeout(c) - role, err := api.GetRole(ctx, rolename) - cancel() - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - fmt.Printf("Role: %s\n", role.Role) - fmt.Printf("KV Read:\n") - for _, v := range role.Permissions.KV.Read { - fmt.Printf("\t%s\n", v) - } - fmt.Printf("KV Write:\n") - for _, v := range role.Permissions.KV.Write { - fmt.Printf("\t%s\n", v) - } - return nil -} - -func mustRoleAPIAndName(c *cli.Context) (client.AuthRoleAPI, string) { - args := c.Args() - if len(args) != 1 { - fmt.Fprintln(os.Stderr, "Please provide a role name") - os.Exit(1) - } - - name := args[0] - api := mustNewAuthRoleAPI(c) - return api, name -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/set_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/set_command.go deleted file mode 100644 index f7bb6bd537d4..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/set_command.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "errors" - "os" - "time" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -// NewSetCommand returns the CLI command for "set". -func NewSetCommand() cli.Command { - return cli.Command{ - Name: "set", - Usage: "set the value of a key", - ArgsUsage: " ", - Description: `Set sets the value of a key. - - When begins with '-', is interpreted as a flag. - Insert '--' for workaround: - - $ set -- `, - Flags: []cli.Flag{ - cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live in seconds"}, - cli.StringFlag{Name: "swap-with-value", Value: "", Usage: "previous value"}, - cli.IntFlag{Name: "swap-with-index", Value: 0, Usage: "previous index"}, - }, - Action: func(c *cli.Context) error { - setCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// setCommandFunc executes the "set" command. -func setCommandFunc(c *cli.Context, ki client.KeysAPI) { - if len(c.Args()) == 0 { - handleError(c, ExitBadArgs, errors.New("key required")) - } - key := c.Args()[0] - value, err := argOrStdin(c.Args(), os.Stdin, 1) - if err != nil { - handleError(c, ExitBadArgs, errors.New("value required")) - } - - ttl := c.Int("ttl") - prevValue := c.String("swap-with-value") - prevIndex := c.Int("swap-with-index") - - ctx, cancel := contextWithTotalTimeout(c) - resp, err := ki.Set(ctx, key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevIndex: uint64(prevIndex), PrevValue: prevValue}) - cancel() - if err != nil { - handleError(c, ExitServerError, err) - } - - printResponseKey(resp, c.GlobalString("output")) -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/set_dir_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/set_dir_command.go deleted file mode 100644 index aba66b089381..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/set_dir_command.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -// NewSetDirCommand returns the CLI command for "setDir". -func NewSetDirCommand() cli.Command { - return cli.Command{ - Name: "setdir", - Usage: "create a new directory or update an existing directory TTL", - ArgsUsage: "", - Flags: []cli.Flag{ - cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live in seconds"}, - }, - Action: func(c *cli.Context) error { - mkdirCommandFunc(c, mustNewKeyAPI(c), client.PrevIgnore) - return nil - }, - } -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/update_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/update_command.go deleted file mode 100644 index ed4224892de3..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/update_command.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "errors" - "os" - "time" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -// NewUpdateCommand returns the CLI command for "update". -func NewUpdateCommand() cli.Command { - return cli.Command{ - Name: "update", - Usage: "update an existing key with a given value", - ArgsUsage: " ", - Flags: []cli.Flag{ - cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live in seconds"}, - }, - Action: func(c *cli.Context) error { - updateCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// updateCommandFunc executes the "update" command. -func updateCommandFunc(c *cli.Context, ki client.KeysAPI) { - if len(c.Args()) == 0 { - handleError(c, ExitBadArgs, errors.New("key required")) - } - key := c.Args()[0] - value, err := argOrStdin(c.Args(), os.Stdin, 1) - if err != nil { - handleError(c, ExitBadArgs, errors.New("value required")) - } - - ttl := c.Int("ttl") - - ctx, cancel := contextWithTotalTimeout(c) - resp, err := ki.Set(ctx, key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevExist}) - cancel() - if err != nil { - handleError(c, ExitServerError, err) - } - - printResponseKey(resp, c.GlobalString("output")) -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/update_dir_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/update_dir_command.go deleted file mode 100644 index 72411dfba1dc..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/update_dir_command.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "errors" - "time" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -// NewUpdateDirCommand returns the CLI command for "updatedir". -func NewUpdateDirCommand() cli.Command { - return cli.Command{ - Name: "updatedir", - Usage: "update an existing directory", - ArgsUsage: " ", - Flags: []cli.Flag{ - cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live in seconds"}, - }, - Action: func(c *cli.Context) error { - updatedirCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// updatedirCommandFunc executes the "updatedir" command. -func updatedirCommandFunc(c *cli.Context, ki client.KeysAPI) { - if len(c.Args()) == 0 { - handleError(c, ExitBadArgs, errors.New("key required")) - } - key := c.Args()[0] - ttl := c.Int("ttl") - ctx, cancel := contextWithTotalTimeout(c) - resp, err := ki.Set(ctx, key, "", &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: client.PrevExist}) - cancel() - if err != nil { - handleError(c, ExitServerError, err) - } - if c.GlobalString("output") != "simple" { - printResponseKey(resp, c.GlobalString("output")) - } -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/user_commands.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/user_commands.go deleted file mode 100644 index c0fb900b247a..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/user_commands.go +++ /dev/null @@ -1,225 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "os" - "strings" - - "github.com/bgentry/speakeasy" - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -func NewUserCommands() cli.Command { - return cli.Command{ - Name: "user", - Usage: "user add, grant and revoke subcommands", - Subcommands: []cli.Command{ - { - Name: "add", - Usage: "add a new user for the etcd cluster", - ArgsUsage: "", - Action: actionUserAdd, - }, - { - Name: "get", - Usage: "get details for a user", - ArgsUsage: "", - Action: actionUserGet, - }, - { - Name: "list", - Usage: "list all current users", - ArgsUsage: "", - Action: actionUserList, - }, - { - Name: "remove", - Usage: "remove a user for the etcd cluster", - ArgsUsage: "", - Action: actionUserRemove, - }, - { - Name: "grant", - Usage: "grant roles to an etcd user", - ArgsUsage: "", - Flags: []cli.Flag{cli.StringSliceFlag{Name: "roles", Value: new(cli.StringSlice), Usage: "List of roles to grant or revoke"}}, - Action: actionUserGrant, - }, - { - Name: "revoke", - Usage: "revoke roles for an etcd user", - ArgsUsage: "", - Flags: []cli.Flag{cli.StringSliceFlag{Name: "roles", Value: new(cli.StringSlice), Usage: "List of roles to grant or revoke"}}, - Action: actionUserRevoke, - }, - { - Name: "passwd", - Usage: "change password for a user", - ArgsUsage: "", - Action: actionUserPasswd, - }, - }, - } -} - -func mustNewAuthUserAPI(c *cli.Context) client.AuthUserAPI { - hc := mustNewClient(c) - - if c.GlobalBool("debug") { - fmt.Fprintf(os.Stderr, "Cluster-Endpoints: %s\n", strings.Join(hc.Endpoints(), ", ")) - } - - return client.NewAuthUserAPI(hc) -} - -func actionUserList(c *cli.Context) error { - if len(c.Args()) != 0 { - fmt.Fprintln(os.Stderr, "No arguments accepted") - os.Exit(1) - } - u := mustNewAuthUserAPI(c) - ctx, cancel := contextWithTotalTimeout(c) - users, err := u.ListUsers(ctx) - cancel() - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - for _, user := range users { - fmt.Printf("%s\n", user) - } - return nil -} - -func actionUserAdd(c *cli.Context) error { - api, userarg := mustUserAPIAndName(c) - ctx, cancel := contextWithTotalTimeout(c) - defer cancel() - user, _, _ := getUsernamePassword("", userarg+":") - - _, pass, err := getUsernamePassword("New password: ", userarg) - if err != nil { - fmt.Fprintln(os.Stderr, "Error reading password:", err) - os.Exit(1) - } - err = api.AddUser(ctx, user, pass) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - fmt.Printf("User %s created\n", user) - return nil -} - -func actionUserRemove(c *cli.Context) error { - api, user := mustUserAPIAndName(c) - ctx, cancel := contextWithTotalTimeout(c) - err := api.RemoveUser(ctx, user) - cancel() - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - fmt.Printf("User %s removed\n", user) - return nil -} - -func actionUserPasswd(c *cli.Context) error { - api, user := mustUserAPIAndName(c) - ctx, cancel := contextWithTotalTimeout(c) - defer cancel() - pass, err := speakeasy.Ask("New password: ") - if err != nil { - fmt.Fprintln(os.Stderr, "Error reading password:", err) - os.Exit(1) - } - - _, err = api.ChangePassword(ctx, user, pass) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - fmt.Printf("Password updated\n") - return nil -} - -func actionUserGrant(c *cli.Context) error { - userGrantRevoke(c, true) - return nil -} - -func actionUserRevoke(c *cli.Context) error { - userGrantRevoke(c, false) - return nil -} - -func userGrantRevoke(c *cli.Context, grant bool) { - roles := c.StringSlice("roles") - if len(roles) == 0 { - fmt.Fprintln(os.Stderr, "No roles specified; please use `--roles`") - os.Exit(1) - } - - ctx, cancel := contextWithTotalTimeout(c) - defer cancel() - - api, user := mustUserAPIAndName(c) - var err error - if grant { - _, err = api.GrantUser(ctx, user, roles) - } else { - _, err = api.RevokeUser(ctx, user, roles) - } - - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - fmt.Printf("User %s updated\n", user) -} - -func actionUserGet(c *cli.Context) error { - api, username := mustUserAPIAndName(c) - ctx, cancel := contextWithTotalTimeout(c) - user, err := api.GetUser(ctx, username) - cancel() - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - fmt.Printf("User: %s\n", user.User) - fmt.Printf("Roles: %s\n", strings.Join(user.Roles, " ")) - return nil -} - -func mustUserAPIAndName(c *cli.Context) (client.AuthUserAPI, string) { - args := c.Args() - if len(args) != 1 { - fmt.Fprintln(os.Stderr, "Please provide a username") - os.Exit(1) - } - - api := mustNewAuthUserAPI(c) - username := args[0] - return api, username -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/util.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/util.go deleted file mode 100644 index 4f3d2df69666..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/util.go +++ /dev/null @@ -1,337 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "errors" - "fmt" - "io" - "io/ioutil" - "net" - "net/http" - "net/url" - "os" - "strings" - "syscall" - "time" - - "github.com/coreos/etcd/client" - "github.com/coreos/etcd/pkg/transport" - - "github.com/bgentry/speakeasy" - "github.com/urfave/cli" -) - -var ( - ErrNoAvailSrc = errors.New("no available argument and stdin") - - // the maximum amount of time a dial will wait for a connection to setup. - // 30s is long enough for most of the network conditions. - defaultDialTimeout = 30 * time.Second -) - -func argOrStdin(args []string, stdin io.Reader, i int) (string, error) { - if i < len(args) { - return args[i], nil - } - bytes, err := ioutil.ReadAll(stdin) - if string(bytes) == "" || err != nil { - return "", ErrNoAvailSrc - } - return string(bytes), nil -} - -func getPeersFlagValue(c *cli.Context) []string { - peerstr := c.GlobalString("endpoints") - - if peerstr == "" { - peerstr = os.Getenv("ETCDCTL_ENDPOINTS") - } - - if peerstr == "" { - peerstr = c.GlobalString("endpoint") - } - - if peerstr == "" { - peerstr = os.Getenv("ETCDCTL_ENDPOINT") - } - - if peerstr == "" { - peerstr = c.GlobalString("peers") - } - - if peerstr == "" { - peerstr = os.Getenv("ETCDCTL_PEERS") - } - - // If we still don't have peers, use a default - if peerstr == "" { - peerstr = "http://127.0.0.1:2379,http://127.0.0.1:4001" - } - - return strings.Split(peerstr, ",") -} - -func getDomainDiscoveryFlagValue(c *cli.Context) ([]string, error) { - domainstr, insecure := getDiscoveryDomain(c) - - // If we still don't have domain discovery, return nothing - if domainstr == "" { - return []string{}, nil - } - - discoverer := client.NewSRVDiscover() - eps, err := discoverer.Discover(domainstr) - if err != nil { - return nil, err - } - if insecure { - return eps, err - } - // strip insecure connections - ret := []string{} - for _, ep := range eps { - if strings.HasPrefix(ep, "http://") { - fmt.Fprintf(os.Stderr, "ignoring discovered insecure endpoint %q\n", ep) - continue - } - ret = append(ret, ep) - } - return ret, err -} - -func getDiscoveryDomain(c *cli.Context) (domainstr string, insecure bool) { - domainstr = c.GlobalString("discovery-srv") - // Use an environment variable if nothing was supplied on the - // command line - if domainstr == "" { - domainstr = os.Getenv("ETCDCTL_DISCOVERY_SRV") - } - insecure = c.GlobalBool("insecure-discovery") || (os.Getenv("ETCDCTL_INSECURE_DISCOVERY") != "") - return domainstr, insecure -} - -func getEndpoints(c *cli.Context) ([]string, error) { - eps, err := getDomainDiscoveryFlagValue(c) - if err != nil { - return nil, err - } - - // If domain discovery returns no endpoints, check peer flag - if len(eps) == 0 { - eps = getPeersFlagValue(c) - } - - for i, ep := range eps { - u, err := url.Parse(ep) - if err != nil { - return nil, err - } - - if u.Scheme == "" { - u.Scheme = "http" - } - - eps[i] = u.String() - } - - return eps, nil -} - -func getTransport(c *cli.Context) (*http.Transport, error) { - cafile := c.GlobalString("ca-file") - certfile := c.GlobalString("cert-file") - keyfile := c.GlobalString("key-file") - - // Use an environment variable if nothing was supplied on the - // command line - if cafile == "" { - cafile = os.Getenv("ETCDCTL_CA_FILE") - } - if certfile == "" { - certfile = os.Getenv("ETCDCTL_CERT_FILE") - } - if keyfile == "" { - keyfile = os.Getenv("ETCDCTL_KEY_FILE") - } - - discoveryDomain, insecure := getDiscoveryDomain(c) - if insecure { - discoveryDomain = "" - } - tls := transport.TLSInfo{ - CAFile: cafile, - CertFile: certfile, - KeyFile: keyfile, - ServerName: discoveryDomain, - } - - dialTimeout := defaultDialTimeout - totalTimeout := c.GlobalDuration("total-timeout") - if totalTimeout != 0 && totalTimeout < dialTimeout { - dialTimeout = totalTimeout - } - return transport.NewTransport(tls, dialTimeout) -} - -func getUsernamePasswordFromFlag(usernameFlag string) (username string, password string, err error) { - return getUsernamePassword("Password: ", usernameFlag) -} - -func getUsernamePassword(prompt, usernameFlag string) (username string, password string, err error) { - colon := strings.Index(usernameFlag, ":") - if colon == -1 { - username = usernameFlag - // Prompt for the password. - password, err = speakeasy.Ask(prompt) - if err != nil { - return "", "", err - } - } else { - username = usernameFlag[:colon] - password = usernameFlag[colon+1:] - } - return username, password, nil -} - -func mustNewKeyAPI(c *cli.Context) client.KeysAPI { - return client.NewKeysAPI(mustNewClient(c)) -} - -func mustNewMembersAPI(c *cli.Context) client.MembersAPI { - return client.NewMembersAPI(mustNewClient(c)) -} - -func mustNewClient(c *cli.Context) client.Client { - hc, err := newClient(c) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - debug := c.GlobalBool("debug") - if debug { - client.EnablecURLDebug() - } - - if !c.GlobalBool("no-sync") { - if debug { - fmt.Fprintf(os.Stderr, "start to sync cluster using endpoints(%s)\n", strings.Join(hc.Endpoints(), ",")) - } - ctx, cancel := contextWithTotalTimeout(c) - err := hc.Sync(ctx) - cancel() - if err != nil { - if err == client.ErrNoEndpoints { - fmt.Fprintf(os.Stderr, "etcd cluster has no published client endpoints.\n") - fmt.Fprintf(os.Stderr, "Try '--no-sync' if you want to access non-published client endpoints(%s).\n", strings.Join(hc.Endpoints(), ",")) - handleError(c, ExitServerError, err) - } - if isConnectionError(err) { - handleError(c, ExitBadConnection, err) - } - } - if debug { - fmt.Fprintf(os.Stderr, "got endpoints(%s) after sync\n", strings.Join(hc.Endpoints(), ",")) - } - } - - if debug { - fmt.Fprintf(os.Stderr, "Cluster-Endpoints: %s\n", strings.Join(hc.Endpoints(), ", ")) - } - - return hc -} - -func isConnectionError(err error) bool { - switch t := err.(type) { - case *client.ClusterError: - for _, cerr := range t.Errors { - if !isConnectionError(cerr) { - return false - } - } - return true - case *net.OpError: - if t.Op == "dial" || t.Op == "read" { - return true - } - return isConnectionError(t.Err) - case net.Error: - if t.Timeout() { - return true - } - case syscall.Errno: - if t == syscall.ECONNREFUSED { - return true - } - } - return false -} - -func mustNewClientNoSync(c *cli.Context) client.Client { - hc, err := newClient(c) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - if c.GlobalBool("debug") { - fmt.Fprintf(os.Stderr, "Cluster-Endpoints: %s\n", strings.Join(hc.Endpoints(), ", ")) - client.EnablecURLDebug() - } - - return hc -} - -func newClient(c *cli.Context) (client.Client, error) { - eps, err := getEndpoints(c) - if err != nil { - return nil, err - } - - tr, err := getTransport(c) - if err != nil { - return nil, err - } - - cfg := client.Config{ - Transport: tr, - Endpoints: eps, - HeaderTimeoutPerRequest: c.GlobalDuration("timeout"), - } - - uFlag := c.GlobalString("username") - - if uFlag == "" { - uFlag = os.Getenv("ETCDCTL_USERNAME") - } - - if uFlag != "" { - username, password, err := getUsernamePasswordFromFlag(uFlag) - if err != nil { - return nil, err - } - cfg.Username = username - cfg.Password = password - } - - return client.New(cfg) -} - -func contextWithTotalTimeout(c *cli.Context) (context.Context, context.CancelFunc) { - return context.WithTimeout(context.Background(), c.GlobalDuration("total-timeout")) -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/watch_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/watch_command.go deleted file mode 100644 index eac63b04078a..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv2/command/watch_command.go +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "errors" - "fmt" - "os" - "os/signal" - - "github.com/coreos/etcd/client" - - "github.com/urfave/cli" -) - -// NewWatchCommand returns the CLI command for "watch". -func NewWatchCommand() cli.Command { - return cli.Command{ - Name: "watch", - Usage: "watch a key for changes", - ArgsUsage: "", - Flags: []cli.Flag{ - cli.BoolFlag{Name: "forever, f", Usage: "forever watch a key until CTRL+C"}, - cli.IntFlag{Name: "after-index", Value: 0, Usage: "watch after the given index"}, - cli.BoolFlag{Name: "recursive, r", Usage: "returns all values for key and child keys"}, - }, - Action: func(c *cli.Context) error { - watchCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// watchCommandFunc executes the "watch" command. -func watchCommandFunc(c *cli.Context, ki client.KeysAPI) { - if len(c.Args()) == 0 { - handleError(c, ExitBadArgs, errors.New("key required")) - } - key := c.Args()[0] - recursive := c.Bool("recursive") - forever := c.Bool("forever") - index := c.Int("after-index") - - stop := false - w := ki.Watcher(key, &client.WatcherOptions{AfterIndex: uint64(index), Recursive: recursive}) - - sigch := make(chan os.Signal, 1) - signal.Notify(sigch, os.Interrupt) - - go func() { - <-sigch - os.Exit(0) - }() - - for !stop { - resp, err := w.Next(context.TODO()) - if err != nil { - handleError(c, ExitServerError, err) - } - if resp.Node.Dir { - continue - } - if recursive { - fmt.Printf("[%s] %s\n", resp.Action, resp.Node.Key) - } - - printResponseKey(resp, c.GlobalString("output")) - - if !forever { - stop = true - } - } -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/alarm_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/alarm_command.go deleted file mode 100644 index 2befbc2aa064..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/alarm_command.go +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - - v3 "github.com/coreos/etcd/clientv3" - "github.com/spf13/cobra" -) - -// NewAlarmCommand returns the cobra command for "alarm". -func NewAlarmCommand() *cobra.Command { - ac := &cobra.Command{ - Use: "alarm ", - Short: "Alarm related commands", - } - - ac.AddCommand(NewAlarmDisarmCommand()) - ac.AddCommand(NewAlarmListCommand()) - - return ac -} - -func NewAlarmDisarmCommand() *cobra.Command { - cmd := cobra.Command{ - Use: "disarm", - Short: "Disarms all alarms", - Run: alarmDisarmCommandFunc, - } - return &cmd -} - -// alarmDisarmCommandFunc executes the "alarm disarm" command. -func alarmDisarmCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("alarm disarm command accepts no arguments")) - } - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).AlarmDisarm(ctx, &v3.AlarmMember{}) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - display.Alarm(*resp) -} - -func NewAlarmListCommand() *cobra.Command { - cmd := cobra.Command{ - Use: "list", - Short: "Lists all alarms", - Run: alarmListCommandFunc, - } - return &cmd -} - -// alarmListCommandFunc executes the "alarm list" command. -func alarmListCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("alarm list command accepts no arguments")) - } - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).AlarmList(ctx) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - display.Alarm(*resp) -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/auth_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/auth_command.go deleted file mode 100644 index f9a909049728..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/auth_command.go +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - "github.com/spf13/cobra" -) - -// NewAuthCommand returns the cobra command for "auth". -func NewAuthCommand() *cobra.Command { - ac := &cobra.Command{ - Use: "auth ", - Short: "Enable or disable authentication", - } - - ac.AddCommand(newAuthEnableCommand()) - ac.AddCommand(newAuthDisableCommand()) - - return ac -} - -func newAuthEnableCommand() *cobra.Command { - return &cobra.Command{ - Use: "enable", - Short: "Enables authentication", - Run: authEnableCommandFunc, - } -} - -// authEnableCommandFunc executes the "auth enable" command. -func authEnableCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("auth enable command does not accept any arguments.")) - } - - ctx, cancel := commandCtx(cmd) - cli := mustClientFromCmd(cmd) - var err error - for err == nil { - if _, err = cli.AuthEnable(ctx); err == nil { - break - } - if err == rpctypes.ErrRootRoleNotExist { - if _, err = cli.RoleAdd(ctx, "root"); err != nil { - break - } - if _, err = cli.UserGrantRole(ctx, "root", "root"); err != nil { - break - } - } - } - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - - fmt.Println("Authentication Enabled") -} - -func newAuthDisableCommand() *cobra.Command { - return &cobra.Command{ - Use: "disable", - Short: "Disables authentication", - Run: authDisableCommandFunc, - } -} - -// authDisableCommandFunc executes the "auth disable" command. -func authDisableCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("auth disable command does not accept any arguments.")) - } - - ctx, cancel := commandCtx(cmd) - _, err := mustClientFromCmd(cmd).Auth.AuthDisable(ctx) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - - fmt.Println("Authentication Disabled") -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/check.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/check.go deleted file mode 100644 index 2ad568217a07..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/check.go +++ /dev/null @@ -1,218 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "encoding/binary" - "fmt" - "math" - "math/rand" - "os" - "sync" - "time" - - v3 "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/pkg/report" - - "github.com/spf13/cobra" - "golang.org/x/time/rate" - "gopkg.in/cheggaaa/pb.v1" -) - -var ( - checkPerfLoad string - checkPerfPrefix string -) - -type checkPerfCfg struct { - limit int - clients int - duration int -} - -var checkPerfCfgMap = map[string]checkPerfCfg{ - // TODO: support read limit - "s": { - limit: 150, - clients: 50, - duration: 60, - }, - "m": { - limit: 1000, - clients: 200, - duration: 60, - }, - "l": { - limit: 8000, - clients: 500, - duration: 60, - }, - "xl": { - limit: 15000, - clients: 1000, - duration: 60, - }, -} - -// NewCheckCommand returns the cobra command for "check". -func NewCheckCommand() *cobra.Command { - cc := &cobra.Command{ - Use: "check ", - Short: "commands for checking properties of the etcd cluster", - } - - cc.AddCommand(NewCheckPerfCommand()) - - return cc -} - -// NewCheckPerfCommand returns the cobra command for "check perf". -func NewCheckPerfCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "perf [options]", - Short: "Check the performance of the etcd cluster", - Run: newCheckPerfCommand, - } - - // TODO: support customized configuration - cmd.Flags().StringVar(&checkPerfLoad, "load", "s", "The performance check's workload model. Accepted workloads: s(small), m(medium), l(large), xl(xLarge)") - cmd.Flags().StringVar(&checkPerfPrefix, "prefix", "/etcdctl-check-perf/", "The prefix for writing the performance check's keys.") - - return cmd -} - -// newCheckPerfCommand executes the "check perf" command. -func newCheckPerfCommand(cmd *cobra.Command, args []string) { - var checkPerfAlias = map[string]string{ - "s": "s", "small": "s", - "m": "m", "medium": "m", - "l": "l", "large": "l", - "xl": "xl", "xLarge": "xl", - } - - model, ok := checkPerfAlias[checkPerfLoad] - if !ok { - ExitWithError(ExitBadFeature, fmt.Errorf("unknown load option %v", checkPerfLoad)) - } - cfg := checkPerfCfgMap[model] - - requests := make(chan v3.Op, cfg.clients) - limit := rate.NewLimiter(rate.Limit(cfg.limit), 1) - - cc := clientConfigFromCmd(cmd) - clients := make([]*v3.Client, cfg.clients) - for i := 0; i < cfg.clients; i++ { - clients[i] = cc.mustClient() - } - - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(cfg.duration)*time.Second) - resp, err := clients[0].Get(ctx, checkPerfPrefix, v3.WithPrefix(), v3.WithLimit(1)) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - if len(resp.Kvs) > 0 { - ExitWithError(ExitInvalidInput, fmt.Errorf("prefix %q has keys. Delete with etcdctl del --prefix %s first.", checkPerfPrefix, checkPerfPrefix)) - } - - ksize, vsize := 256, 1024 - k, v := make([]byte, ksize), string(make([]byte, vsize)) - - bar := pb.New(cfg.duration) - bar.Format("Bom !") - bar.Start() - - r := report.NewReport("%4.4f") - var wg sync.WaitGroup - - wg.Add(len(clients)) - for i := range clients { - go func(c *v3.Client) { - defer wg.Done() - for op := range requests { - st := time.Now() - _, derr := c.Do(context.Background(), op) - r.Results() <- report.Result{Err: derr, Start: st, End: time.Now()} - } - }(clients[i]) - } - - go func() { - cctx, ccancel := context.WithTimeout(context.Background(), time.Duration(cfg.duration)*time.Second) - defer ccancel() - for limit.Wait(cctx) == nil { - binary.PutVarint(k, int64(rand.Int63n(math.MaxInt64))) - requests <- v3.OpPut(checkPerfPrefix+string(k), v) - } - close(requests) - }() - - go func() { - for i := 0; i < cfg.duration; i++ { - time.Sleep(time.Second) - bar.Add(1) - } - bar.Finish() - }() - - sc := r.Stats() - wg.Wait() - close(r.Results()) - - s := <-sc - - ctx, cancel = context.WithTimeout(context.Background(), 30*time.Second) - _, err = clients[0].Delete(ctx, checkPerfPrefix, v3.WithPrefix()) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - - ok = true - if len(s.ErrorDist) != 0 { - fmt.Println("FAIL: too many errors") - for k, v := range s.ErrorDist { - fmt.Printf("FAIL: ERROR(%v) -> %d\n", k, v) - } - ok = false - } - - if s.RPS/float64(cfg.limit) <= 0.9 { - fmt.Printf("FAIL: Throughput too low: %d writes/s\n", int(s.RPS)+1) - ok = false - } else { - fmt.Printf("PASS: Throughput is %d writes/s\n", int(s.RPS)+1) - } - if s.Slowest > 0.5 { // slowest request > 500ms - fmt.Printf("Slowest request took too long: %fs\n", s.Slowest) - ok = false - } else { - fmt.Printf("PASS: Slowest request took %fs\n", s.Slowest) - } - if s.Stddev > 0.1 { // stddev > 100ms - fmt.Printf("Stddev too high: %fs\n", s.Stddev) - ok = false - } else { - fmt.Printf("PASS: Stddev is %fs\n", s.Stddev) - } - - if ok { - fmt.Println("PASS") - } else { - fmt.Println("FAIL") - os.Exit(ExitError) - } -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/compaction_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/compaction_command.go deleted file mode 100644 index 59e8990fb70a..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/compaction_command.go +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "strconv" - - "github.com/coreos/etcd/clientv3" - "github.com/spf13/cobra" -) - -var compactPhysical bool - -// NewCompactionCommand returns the cobra command for "compaction". -func NewCompactionCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "compaction [options] ", - Short: "Compacts the event history in etcd", - Run: compactionCommandFunc, - } - cmd.Flags().BoolVar(&compactPhysical, "physical", false, "'true' to wait for compaction to physically remove all old revisions") - return cmd -} - -// compactionCommandFunc executes the "compaction" command. -func compactionCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("compaction command needs 1 argument.")) - } - - rev, err := strconv.ParseInt(args[0], 10, 64) - if err != nil { - ExitWithError(ExitError, err) - } - - var opts []clientv3.CompactOption - if compactPhysical { - opts = append(opts, clientv3.WithCompactPhysical()) - } - - c := mustClientFromCmd(cmd) - ctx, cancel := commandCtx(cmd) - _, cerr := c.Compact(ctx, rev, opts...) - cancel() - if cerr != nil { - ExitWithError(ExitError, cerr) - } - fmt.Println("compacted revision", rev) -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/defrag_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/defrag_command.go deleted file mode 100644 index a7e6f76f3cad..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/defrag_command.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "os" - "path/filepath" - "time" - - "github.com/coreos/etcd/mvcc/backend" - "github.com/spf13/cobra" -) - -var ( - defragDataDir string -) - -// NewDefragCommand returns the cobra command for "Defrag". -func NewDefragCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "defrag", - Short: "Defragments the storage of the etcd members with given endpoints", - Run: defragCommandFunc, - } - cmd.Flags().StringVar(&defragDataDir, "data-dir", "", "Optional. If present, defragments a data directory not in use by etcd.") - return cmd -} - -func defragCommandFunc(cmd *cobra.Command, args []string) { - if len(defragDataDir) > 0 { - err := defragData(defragDataDir) - if err != nil { - fmt.Fprintf(os.Stderr, "Failed to defragment etcd data[%s] (%v)\n", defragDataDir, err) - os.Exit(ExitError) - } - return - } - - failures := 0 - c := mustClientFromCmd(cmd) - for _, ep := range c.Endpoints() { - ctx, cancel := commandCtx(cmd) - _, err := c.Defragment(ctx, ep) - cancel() - if err != nil { - fmt.Fprintf(os.Stderr, "Failed to defragment etcd member[%s] (%v)\n", ep, err) - failures++ - } else { - fmt.Printf("Finished defragmenting etcd member[%s]\n", ep) - } - } - - if failures != 0 { - os.Exit(ExitError) - } -} - -func defragData(dataDir string) error { - var be backend.Backend - - bch := make(chan struct{}) - dbDir := filepath.Join(dataDir, "member", "snap", "db") - go func() { - defer close(bch) - be = backend.NewDefaultBackend(dbDir) - - }() - select { - case <-bch: - case <-time.After(time.Second): - fmt.Fprintf(os.Stderr, "waiting for etcd to close and release its lock on %q. "+ - "To defrag a running etcd instance, omit --data-dir.\n", dbDir) - <-bch - } - return be.Defrag() -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/del_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/del_command.go deleted file mode 100644 index bb0663024aa3..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/del_command.go +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - - "github.com/coreos/etcd/clientv3" - "github.com/spf13/cobra" -) - -var ( - delPrefix bool - delPrevKV bool - delFromKey bool -) - -// NewDelCommand returns the cobra command for "del". -func NewDelCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "del [options] [range_end]", - Short: "Removes the specified key or range of keys [key, range_end)", - Run: delCommandFunc, - } - - cmd.Flags().BoolVar(&delPrefix, "prefix", false, "delete keys with matching prefix") - cmd.Flags().BoolVar(&delPrevKV, "prev-kv", false, "return deleted key-value pairs") - cmd.Flags().BoolVar(&delFromKey, "from-key", false, "delete keys that are greater than or equal to the given key using byte compare") - return cmd -} - -// delCommandFunc executes the "del" command. -func delCommandFunc(cmd *cobra.Command, args []string) { - key, opts := getDelOp(cmd, args) - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).Delete(ctx, key, opts...) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - display.Del(*resp) -} - -func getDelOp(cmd *cobra.Command, args []string) (string, []clientv3.OpOption) { - if len(args) == 0 || len(args) > 2 { - ExitWithError(ExitBadArgs, fmt.Errorf("del command needs one argument as key and an optional argument as range_end.")) - } - - if delPrefix && delFromKey { - ExitWithError(ExitBadArgs, fmt.Errorf("`--prefix` and `--from-key` cannot be set at the same time, choose one.")) - } - - opts := []clientv3.OpOption{} - key := args[0] - if len(args) > 1 { - if delPrefix || delFromKey { - ExitWithError(ExitBadArgs, fmt.Errorf("too many arguments, only accept one argument when `--prefix` or `--from-key` is set.")) - } - opts = append(opts, clientv3.WithRange(args[1])) - } - - if delPrefix { - if len(key) == 0 { - key = "\x00" - opts = append(opts, clientv3.WithFromKey()) - } else { - opts = append(opts, clientv3.WithPrefix()) - } - } - if delPrevKV { - opts = append(opts, clientv3.WithPrevKV()) - } - - if delFromKey { - if len(key) == 0 { - key = "\x00" - } - opts = append(opts, clientv3.WithFromKey()) - } - - return key, opts -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/doc.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/doc.go deleted file mode 100644 index 2e5636c29daa..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package command is a set of libraries for etcd v3 commands. -package command diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/elect_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/elect_command.go deleted file mode 100644 index ace4f1197b82..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/elect_command.go +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "errors" - "os" - "os/signal" - "syscall" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/concurrency" - - "github.com/spf13/cobra" -) - -var ( - electListen bool -) - -// NewElectCommand returns the cobra command for "elect". -func NewElectCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "elect [proposal]", - Short: "Observes and participates in leader election", - Run: electCommandFunc, - } - cmd.Flags().BoolVarP(&electListen, "listen", "l", false, "observation mode") - return cmd -} - -func electCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 && len(args) != 2 { - ExitWithError(ExitBadArgs, errors.New("elect takes one election name argument and an optional proposal argument.")) - } - c := mustClientFromCmd(cmd) - - var err error - if len(args) == 1 { - if !electListen { - ExitWithError(ExitBadArgs, errors.New("no proposal argument but -l not set")) - } - err = observe(c, args[0]) - } else { - if electListen { - ExitWithError(ExitBadArgs, errors.New("proposal given but -l is set")) - } - err = campaign(c, args[0], args[1]) - } - if err != nil { - ExitWithError(ExitError, err) - } -} - -func observe(c *clientv3.Client, election string) error { - s, err := concurrency.NewSession(c) - if err != nil { - return err - } - e := concurrency.NewElection(s, election) - ctx, cancel := context.WithCancel(context.TODO()) - - donec := make(chan struct{}) - sigc := make(chan os.Signal, 1) - signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM) - go func() { - <-sigc - cancel() - }() - - go func() { - for resp := range e.Observe(ctx) { - display.Get(resp) - } - close(donec) - }() - - <-donec - - select { - case <-ctx.Done(): - default: - return errors.New("elect: observer lost") - } - - return nil -} - -func campaign(c *clientv3.Client, election string, prop string) error { - s, err := concurrency.NewSession(c) - if err != nil { - return err - } - e := concurrency.NewElection(s, election) - ctx, cancel := context.WithCancel(context.TODO()) - - donec := make(chan struct{}) - sigc := make(chan os.Signal, 1) - signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM) - go func() { - <-sigc - cancel() - close(donec) - }() - - if err = e.Campaign(ctx, prop); err != nil { - return err - } - - // print key since elected - resp, err := c.Get(ctx, e.Key()) - if err != nil { - return err - } - display.Get(*resp) - - select { - case <-donec: - case <-s.Done(): - return errors.New("elect: session expired") - } - - return e.Resign(context.TODO()) -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/ep_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/ep_command.go deleted file mode 100644 index 88f0199fec12..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/ep_command.go +++ /dev/null @@ -1,241 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "os" - "sync" - "time" - - v3 "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - "github.com/coreos/etcd/pkg/flags" - - "github.com/spf13/cobra" -) - -var epClusterEndpoints bool -var epHashKVRev int64 - -// NewEndpointCommand returns the cobra command for "endpoint". -func NewEndpointCommand() *cobra.Command { - ec := &cobra.Command{ - Use: "endpoint ", - Short: "Endpoint related commands", - } - - ec.PersistentFlags().BoolVar(&epClusterEndpoints, "cluster", false, "use all endpoints from the cluster member list") - ec.AddCommand(newEpHealthCommand()) - ec.AddCommand(newEpStatusCommand()) - ec.AddCommand(newEpHashKVCommand()) - - return ec -} - -func newEpHealthCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "health", - Short: "Checks the healthiness of endpoints specified in `--endpoints` flag", - Run: epHealthCommandFunc, - } - - return cmd -} - -func newEpStatusCommand() *cobra.Command { - return &cobra.Command{ - Use: "status", - Short: "Prints out the status of endpoints specified in `--endpoints` flag", - Long: `When --write-out is set to simple, this command prints out comma-separated status lists for each endpoint. -The items in the lists are endpoint, ID, version, db size, is leader, raft term, raft index. -`, - Run: epStatusCommandFunc, - } -} - -func newEpHashKVCommand() *cobra.Command { - hc := &cobra.Command{ - Use: "hashkv", - Short: "Prints the KV history hash for each endpoint in --endpoints", - Run: epHashKVCommandFunc, - } - hc.PersistentFlags().Int64Var(&epHashKVRev, "rev", 0, "maximum revision to hash (default: all revisions)") - return hc -} - -// epHealthCommandFunc executes the "endpoint-health" command. -func epHealthCommandFunc(cmd *cobra.Command, args []string) { - flags.SetPflagsFromEnv("ETCDCTL", cmd.InheritedFlags()) - - sec := secureCfgFromCmd(cmd) - dt := dialTimeoutFromCmd(cmd) - ka := keepAliveTimeFromCmd(cmd) - kat := keepAliveTimeoutFromCmd(cmd) - auth := authCfgFromCmd(cmd) - cfgs := []*v3.Config{} - for _, ep := range endpointsFromCluster(cmd) { - cfg, err := newClientCfg([]string{ep}, dt, ka, kat, sec, auth) - if err != nil { - ExitWithError(ExitBadArgs, err) - } - cfgs = append(cfgs, cfg) - } - - var wg sync.WaitGroup - errc := make(chan error, len(cfgs)) - for _, cfg := range cfgs { - wg.Add(1) - go func(cfg *v3.Config) { - defer wg.Done() - ep := cfg.Endpoints[0] - cli, err := v3.New(*cfg) - if err != nil { - errc <- fmt.Errorf("%s is unhealthy: failed to connect: %v", ep, err) - return - } - st := time.Now() - // get a random key. As long as we can get the response without an error, the - // endpoint is health. - ctx, cancel := commandCtx(cmd) - _, err = cli.Get(ctx, "health") - cancel() - // permission denied is OK since proposal goes through consensus to get it - if err == nil || err == rpctypes.ErrPermissionDenied { - fmt.Printf("%s is healthy: successfully committed proposal: took = %v\n", ep, time.Since(st)) - } else { - errc <- fmt.Errorf("%s is unhealthy: failed to commit proposal: %v", ep, err) - } - }(cfg) - } - - wg.Wait() - close(errc) - - errs := false - for err := range errc { - if err != nil { - errs = true - fmt.Fprintln(os.Stderr, err) - } - } - if errs { - ExitWithError(ExitError, fmt.Errorf("unhealthy cluster")) - } -} - -type epStatus struct { - Ep string `json:"Endpoint"` - Resp *v3.StatusResponse `json:"Status"` -} - -func epStatusCommandFunc(cmd *cobra.Command, args []string) { - c := mustClientFromCmd(cmd) - - statusList := []epStatus{} - var err error - for _, ep := range endpointsFromCluster(cmd) { - ctx, cancel := commandCtx(cmd) - resp, serr := c.Status(ctx, ep) - cancel() - if serr != nil { - err = serr - fmt.Fprintf(os.Stderr, "Failed to get the status of endpoint %s (%v)\n", ep, serr) - continue - } - statusList = append(statusList, epStatus{Ep: ep, Resp: resp}) - } - - display.EndpointStatus(statusList) - - if err != nil { - os.Exit(ExitError) - } -} - -type epHashKV struct { - Ep string `json:"Endpoint"` - Resp *v3.HashKVResponse `json:"HashKV"` -} - -func epHashKVCommandFunc(cmd *cobra.Command, args []string) { - c := mustClientFromCmd(cmd) - - hashList := []epHashKV{} - var err error - for _, ep := range endpointsFromCluster(cmd) { - ctx, cancel := commandCtx(cmd) - resp, serr := c.HashKV(ctx, ep, epHashKVRev) - cancel() - if serr != nil { - err = serr - fmt.Fprintf(os.Stderr, "Failed to get the hash of endpoint %s (%v)\n", ep, serr) - continue - } - hashList = append(hashList, epHashKV{Ep: ep, Resp: resp}) - } - - display.EndpointHashKV(hashList) - - if err != nil { - ExitWithError(ExitError, err) - } -} - -func endpointsFromCluster(cmd *cobra.Command) []string { - if !epClusterEndpoints { - endpoints, err := cmd.Flags().GetStringSlice("endpoints") - if err != nil { - ExitWithError(ExitError, err) - } - return endpoints - } - - sec := secureCfgFromCmd(cmd) - dt := dialTimeoutFromCmd(cmd) - ka := keepAliveTimeFromCmd(cmd) - kat := keepAliveTimeoutFromCmd(cmd) - eps, err := endpointsFromCmd(cmd) - if err != nil { - ExitWithError(ExitError, err) - } - // exclude auth for not asking needless password (MemberList() doesn't need authentication) - - cfg, err := newClientCfg(eps, dt, ka, kat, sec, nil) - if err != nil { - ExitWithError(ExitError, err) - } - c, err := v3.New(*cfg) - if err != nil { - ExitWithError(ExitError, err) - } - - ctx, cancel := commandCtx(cmd) - defer func() { - c.Close() - cancel() - }() - membs, err := c.MemberList(ctx) - if err != nil { - err = fmt.Errorf("failed to fetch endpoints from etcd cluster member list: %v", err) - ExitWithError(ExitError, err) - } - - ret := []string{} - for _, m := range membs.Members { - ret = append(ret, m.ClientURLs...) - } - return ret -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/error.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/error.go deleted file mode 100644 index 314b07f0525e..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/error.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "os" - - "github.com/coreos/etcd/client" -) - -const ( - // http://tldp.org/LDP/abs/html/exitcodes.html - ExitSuccess = iota - ExitError - ExitBadConnection - ExitInvalidInput // for txn, watch command - ExitBadFeature // provided a valid flag with an unsupported value - ExitInterrupted - ExitIO - ExitBadArgs = 128 -) - -func ExitWithError(code int, err error) { - fmt.Fprintln(os.Stderr, "Error:", err) - if cerr, ok := err.(*client.ClusterError); ok { - fmt.Fprintln(os.Stderr, cerr.Detail()) - } - os.Exit(code) -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/get_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/get_command.go deleted file mode 100644 index 5f9c74f3c552..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/get_command.go +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "strings" - - "github.com/coreos/etcd/clientv3" - "github.com/spf13/cobra" -) - -var ( - getConsistency string - getLimit int64 - getSortOrder string - getSortTarget string - getPrefix bool - getFromKey bool - getRev int64 - getKeysOnly bool - printValueOnly bool -) - -// NewGetCommand returns the cobra command for "get". -func NewGetCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "get [options] [range_end]", - Short: "Gets the key or a range of keys", - Run: getCommandFunc, - } - - cmd.Flags().StringVar(&getConsistency, "consistency", "l", "Linearizable(l) or Serializable(s)") - cmd.Flags().StringVar(&getSortOrder, "order", "", "Order of results; ASCEND or DESCEND (ASCEND by default)") - cmd.Flags().StringVar(&getSortTarget, "sort-by", "", "Sort target; CREATE, KEY, MODIFY, VALUE, or VERSION") - cmd.Flags().Int64Var(&getLimit, "limit", 0, "Maximum number of results") - cmd.Flags().BoolVar(&getPrefix, "prefix", false, "Get keys with matching prefix") - cmd.Flags().BoolVar(&getFromKey, "from-key", false, "Get keys that are greater than or equal to the given key using byte compare") - cmd.Flags().Int64Var(&getRev, "rev", 0, "Specify the kv revision") - cmd.Flags().BoolVar(&getKeysOnly, "keys-only", false, "Get only the keys") - cmd.Flags().BoolVar(&printValueOnly, "print-value-only", false, `Only write values when using the "simple" output format`) - return cmd -} - -// getCommandFunc executes the "get" command. -func getCommandFunc(cmd *cobra.Command, args []string) { - key, opts := getGetOp(cmd, args) - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).Get(ctx, key, opts...) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - - if printValueOnly { - dp, simple := (display).(*simplePrinter) - if !simple { - ExitWithError(ExitBadArgs, fmt.Errorf("print-value-only is only for `--write-out=simple`.")) - } - dp.valueOnly = true - } - display.Get(*resp) -} - -func getGetOp(cmd *cobra.Command, args []string) (string, []clientv3.OpOption) { - if len(args) == 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("range command needs arguments.")) - } - - if getPrefix && getFromKey { - ExitWithError(ExitBadArgs, fmt.Errorf("`--prefix` and `--from-key` cannot be set at the same time, choose one.")) - } - - opts := []clientv3.OpOption{} - switch getConsistency { - case "s": - opts = append(opts, clientv3.WithSerializable()) - case "l": - default: - ExitWithError(ExitBadFeature, fmt.Errorf("unknown consistency flag %q", getConsistency)) - } - - key := args[0] - if len(args) > 1 { - if getPrefix || getFromKey { - ExitWithError(ExitBadArgs, fmt.Errorf("too many arguments, only accept one argument when `--prefix` or `--from-key` is set.")) - } - opts = append(opts, clientv3.WithRange(args[1])) - } - - opts = append(opts, clientv3.WithLimit(getLimit)) - if getRev > 0 { - opts = append(opts, clientv3.WithRev(getRev)) - } - - sortByOrder := clientv3.SortNone - sortOrder := strings.ToUpper(getSortOrder) - switch { - case sortOrder == "ASCEND": - sortByOrder = clientv3.SortAscend - case sortOrder == "DESCEND": - sortByOrder = clientv3.SortDescend - case sortOrder == "": - // nothing - default: - ExitWithError(ExitBadFeature, fmt.Errorf("bad sort order %v", getSortOrder)) - } - - sortByTarget := clientv3.SortByKey - sortTarget := strings.ToUpper(getSortTarget) - switch { - case sortTarget == "CREATE": - sortByTarget = clientv3.SortByCreateRevision - case sortTarget == "KEY": - sortByTarget = clientv3.SortByKey - case sortTarget == "MODIFY": - sortByTarget = clientv3.SortByModRevision - case sortTarget == "VALUE": - sortByTarget = clientv3.SortByValue - case sortTarget == "VERSION": - sortByTarget = clientv3.SortByVersion - case sortTarget == "": - // nothing - default: - ExitWithError(ExitBadFeature, fmt.Errorf("bad sort target %v", getSortTarget)) - } - - opts = append(opts, clientv3.WithSort(sortByTarget, sortByOrder)) - - if getPrefix { - if len(key) == 0 { - key = "\x00" - opts = append(opts, clientv3.WithFromKey()) - } else { - opts = append(opts, clientv3.WithPrefix()) - } - } - - if getFromKey { - if len(key) == 0 { - key = "\x00" - } - opts = append(opts, clientv3.WithFromKey()) - } - - if getKeysOnly { - opts = append(opts, clientv3.WithKeysOnly()) - } - - return key, opts -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/global.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/global.go deleted file mode 100644 index c20c940f02ce..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/global.go +++ /dev/null @@ -1,412 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "crypto/tls" - "errors" - "fmt" - "io" - "io/ioutil" - "os" - "strings" - "time" - - "github.com/bgentry/speakeasy" - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/pkg/flags" - "github.com/coreos/etcd/pkg/srv" - "github.com/coreos/etcd/pkg/transport" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "google.golang.org/grpc/grpclog" -) - -// GlobalFlags are flags that defined globally -// and are inherited to all sub-commands. -type GlobalFlags struct { - Insecure bool - InsecureSkipVerify bool - InsecureDiscovery bool - Endpoints []string - DialTimeout time.Duration - CommandTimeOut time.Duration - KeepAliveTime time.Duration - KeepAliveTimeout time.Duration - - TLS transport.TLSInfo - - OutputFormat string - IsHex bool - - User string - - Debug bool -} - -type secureCfg struct { - cert string - key string - cacert string - serverName string - - insecureTransport bool - insecureSkipVerify bool -} - -type authCfg struct { - username string - password string -} - -type discoveryCfg struct { - domain string - insecure bool -} - -var display printer = &simplePrinter{} - -func initDisplayFromCmd(cmd *cobra.Command) { - isHex, err := cmd.Flags().GetBool("hex") - if err != nil { - ExitWithError(ExitError, err) - } - outputType, err := cmd.Flags().GetString("write-out") - if err != nil { - ExitWithError(ExitError, err) - } - if display = NewPrinter(outputType, isHex); display == nil { - ExitWithError(ExitBadFeature, errors.New("unsupported output format")) - } -} - -type clientConfig struct { - endpoints []string - dialTimeout time.Duration - keepAliveTime time.Duration - keepAliveTimeout time.Duration - scfg *secureCfg - acfg *authCfg -} - -type discardValue struct{} - -func (*discardValue) String() string { return "" } -func (*discardValue) Set(string) error { return nil } -func (*discardValue) Type() string { return "" } - -func clientConfigFromCmd(cmd *cobra.Command) *clientConfig { - fs := cmd.InheritedFlags() - if strings.HasPrefix(cmd.Use, "watch") { - // silence "pkg/flags: unrecognized environment variable ETCDCTL_WATCH_KEY=foo" warnings - // silence "pkg/flags: unrecognized environment variable ETCDCTL_WATCH_RANGE_END=bar" warnings - fs.AddFlag(&pflag.Flag{Name: "watch-key", Value: &discardValue{}}) - fs.AddFlag(&pflag.Flag{Name: "watch-range-end", Value: &discardValue{}}) - } - flags.SetPflagsFromEnv("ETCDCTL", fs) - - debug, err := cmd.Flags().GetBool("debug") - if err != nil { - ExitWithError(ExitError, err) - } - if debug { - clientv3.SetLogger(grpclog.NewLoggerV2WithVerbosity(os.Stderr, os.Stderr, os.Stderr, 4)) - fs.VisitAll(func(f *pflag.Flag) { - fmt.Fprintf(os.Stderr, "%s=%v\n", flags.FlagToEnv("ETCDCTL", f.Name), f.Value) - }) - } else { - clientv3.SetLogger(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, ioutil.Discard)) - } - - cfg := &clientConfig{} - cfg.endpoints, err = endpointsFromCmd(cmd) - if err != nil { - ExitWithError(ExitError, err) - } - - cfg.dialTimeout = dialTimeoutFromCmd(cmd) - cfg.keepAliveTime = keepAliveTimeFromCmd(cmd) - cfg.keepAliveTimeout = keepAliveTimeoutFromCmd(cmd) - - cfg.scfg = secureCfgFromCmd(cmd) - cfg.acfg = authCfgFromCmd(cmd) - - initDisplayFromCmd(cmd) - return cfg -} - -func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client { - cfg := clientConfigFromCmd(cmd) - return cfg.mustClient() -} - -func (cc *clientConfig) mustClient() *clientv3.Client { - cfg, err := newClientCfg(cc.endpoints, cc.dialTimeout, cc.keepAliveTime, cc.keepAliveTimeout, cc.scfg, cc.acfg) - if err != nil { - ExitWithError(ExitBadArgs, err) - } - - client, err := clientv3.New(*cfg) - if err != nil { - ExitWithError(ExitBadConnection, err) - } - - return client -} - -func newClientCfg(endpoints []string, dialTimeout, keepAliveTime, keepAliveTimeout time.Duration, scfg *secureCfg, acfg *authCfg) (*clientv3.Config, error) { - // set tls if any one tls option set - var cfgtls *transport.TLSInfo - tlsinfo := transport.TLSInfo{} - if scfg.cert != "" { - tlsinfo.CertFile = scfg.cert - cfgtls = &tlsinfo - } - - if scfg.key != "" { - tlsinfo.KeyFile = scfg.key - cfgtls = &tlsinfo - } - - if scfg.cacert != "" { - tlsinfo.CAFile = scfg.cacert - cfgtls = &tlsinfo - } - - if scfg.serverName != "" { - tlsinfo.ServerName = scfg.serverName - cfgtls = &tlsinfo - } - - cfg := &clientv3.Config{ - Endpoints: endpoints, - DialTimeout: dialTimeout, - DialKeepAliveTime: keepAliveTime, - DialKeepAliveTimeout: keepAliveTimeout, - } - - if cfgtls != nil { - clientTLS, err := cfgtls.ClientConfig() - if err != nil { - return nil, err - } - cfg.TLS = clientTLS - } - - // if key/cert is not given but user wants secure connection, we - // should still setup an empty tls configuration for gRPC to setup - // secure connection. - if cfg.TLS == nil && !scfg.insecureTransport { - cfg.TLS = &tls.Config{} - } - - // If the user wants to skip TLS verification then we should set - // the InsecureSkipVerify flag in tls configuration. - if scfg.insecureSkipVerify && cfg.TLS != nil { - cfg.TLS.InsecureSkipVerify = true - } - - if acfg != nil { - cfg.Username = acfg.username - cfg.Password = acfg.password - } - - return cfg, nil -} - -func argOrStdin(args []string, stdin io.Reader, i int) (string, error) { - if i < len(args) { - return args[i], nil - } - bytes, err := ioutil.ReadAll(stdin) - if string(bytes) == "" || err != nil { - return "", errors.New("no available argument and stdin") - } - return string(bytes), nil -} - -func dialTimeoutFromCmd(cmd *cobra.Command) time.Duration { - dialTimeout, err := cmd.Flags().GetDuration("dial-timeout") - if err != nil { - ExitWithError(ExitError, err) - } - return dialTimeout -} - -func keepAliveTimeFromCmd(cmd *cobra.Command) time.Duration { - keepAliveTime, err := cmd.Flags().GetDuration("keepalive-time") - if err != nil { - ExitWithError(ExitError, err) - } - return keepAliveTime -} - -func keepAliveTimeoutFromCmd(cmd *cobra.Command) time.Duration { - keepAliveTimeout, err := cmd.Flags().GetDuration("keepalive-timeout") - if err != nil { - ExitWithError(ExitError, err) - } - return keepAliveTimeout -} - -func secureCfgFromCmd(cmd *cobra.Command) *secureCfg { - cert, key, cacert := keyAndCertFromCmd(cmd) - insecureTr := insecureTransportFromCmd(cmd) - skipVerify := insecureSkipVerifyFromCmd(cmd) - discoveryCfg := discoveryCfgFromCmd(cmd) - - if discoveryCfg.insecure { - discoveryCfg.domain = "" - } - - return &secureCfg{ - cert: cert, - key: key, - cacert: cacert, - serverName: discoveryCfg.domain, - - insecureTransport: insecureTr, - insecureSkipVerify: skipVerify, - } -} - -func insecureTransportFromCmd(cmd *cobra.Command) bool { - insecureTr, err := cmd.Flags().GetBool("insecure-transport") - if err != nil { - ExitWithError(ExitError, err) - } - return insecureTr -} - -func insecureSkipVerifyFromCmd(cmd *cobra.Command) bool { - skipVerify, err := cmd.Flags().GetBool("insecure-skip-tls-verify") - if err != nil { - ExitWithError(ExitError, err) - } - return skipVerify -} - -func keyAndCertFromCmd(cmd *cobra.Command) (cert, key, cacert string) { - var err error - if cert, err = cmd.Flags().GetString("cert"); err != nil { - ExitWithError(ExitBadArgs, err) - } else if cert == "" && cmd.Flags().Changed("cert") { - ExitWithError(ExitBadArgs, errors.New("empty string is passed to --cert option")) - } - - if key, err = cmd.Flags().GetString("key"); err != nil { - ExitWithError(ExitBadArgs, err) - } else if key == "" && cmd.Flags().Changed("key") { - ExitWithError(ExitBadArgs, errors.New("empty string is passed to --key option")) - } - - if cacert, err = cmd.Flags().GetString("cacert"); err != nil { - ExitWithError(ExitBadArgs, err) - } else if cacert == "" && cmd.Flags().Changed("cacert") { - ExitWithError(ExitBadArgs, errors.New("empty string is passed to --cacert option")) - } - - return cert, key, cacert -} - -func authCfgFromCmd(cmd *cobra.Command) *authCfg { - userFlag, err := cmd.Flags().GetString("user") - if err != nil { - ExitWithError(ExitBadArgs, err) - } - - if userFlag == "" { - return nil - } - - var cfg authCfg - - splitted := strings.SplitN(userFlag, ":", 2) - if len(splitted) < 2 { - cfg.username = userFlag - cfg.password, err = speakeasy.Ask("Password: ") - if err != nil { - ExitWithError(ExitError, err) - } - } else { - cfg.username = splitted[0] - cfg.password = splitted[1] - } - - return &cfg -} - -func insecureDiscoveryFromCmd(cmd *cobra.Command) bool { - discovery, err := cmd.Flags().GetBool("insecure-discovery") - if err != nil { - ExitWithError(ExitError, err) - } - return discovery -} - -func discoverySrvFromCmd(cmd *cobra.Command) string { - domainStr, err := cmd.Flags().GetString("discovery-srv") - if err != nil { - ExitWithError(ExitBadArgs, err) - } - return domainStr -} - -func discoveryCfgFromCmd(cmd *cobra.Command) *discoveryCfg { - return &discoveryCfg{ - domain: discoverySrvFromCmd(cmd), - insecure: insecureDiscoveryFromCmd(cmd), - } -} - -func endpointsFromCmd(cmd *cobra.Command) ([]string, error) { - eps, err := endpointsFromFlagValue(cmd) - if err != nil { - return nil, err - } - // If domain discovery returns no endpoints, check endpoints flag - if len(eps) == 0 { - eps, err = cmd.Flags().GetStringSlice("endpoints") - } - return eps, err -} - -func endpointsFromFlagValue(cmd *cobra.Command) ([]string, error) { - discoveryCfg := discoveryCfgFromCmd(cmd) - - // If we still don't have domain discovery, return nothing - if discoveryCfg.domain == "" { - return []string{}, nil - } - - srvs, err := srv.GetClient("etcd-client", discoveryCfg.domain) - if err != nil { - return nil, err - } - eps := srvs.Endpoints - if discoveryCfg.insecure { - return eps, err - } - // strip insecure connections - ret := []string{} - for _, ep := range eps { - if strings.HasPrefix(ep, "http://") { - fmt.Fprintf(os.Stderr, "ignoring discovered insecure endpoint %q\n", ep) - continue - } - ret = append(ret, ep) - } - return ret, err -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/lease_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/lease_command.go deleted file mode 100644 index ecfe3a6fb638..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/lease_command.go +++ /dev/null @@ -1,207 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "fmt" - "strconv" - - v3 "github.com/coreos/etcd/clientv3" - - "github.com/spf13/cobra" -) - -// NewLeaseCommand returns the cobra command for "lease". -func NewLeaseCommand() *cobra.Command { - lc := &cobra.Command{ - Use: "lease ", - Short: "Lease related commands", - } - - lc.AddCommand(NewLeaseGrantCommand()) - lc.AddCommand(NewLeaseRevokeCommand()) - lc.AddCommand(NewLeaseTimeToLiveCommand()) - lc.AddCommand(NewLeaseListCommand()) - lc.AddCommand(NewLeaseKeepAliveCommand()) - - return lc -} - -// NewLeaseGrantCommand returns the cobra command for "lease grant". -func NewLeaseGrantCommand() *cobra.Command { - lc := &cobra.Command{ - Use: "grant ", - Short: "Creates leases", - - Run: leaseGrantCommandFunc, - } - - return lc -} - -// leaseGrantCommandFunc executes the "lease grant" command. -func leaseGrantCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("lease grant command needs TTL argument.")) - } - - ttl, err := strconv.ParseInt(args[0], 10, 64) - if err != nil { - ExitWithError(ExitBadArgs, fmt.Errorf("bad TTL (%v)", err)) - } - - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).Grant(ctx, ttl) - cancel() - if err != nil { - ExitWithError(ExitError, fmt.Errorf("failed to grant lease (%v)\n", err)) - } - display.Grant(*resp) -} - -// NewLeaseRevokeCommand returns the cobra command for "lease revoke". -func NewLeaseRevokeCommand() *cobra.Command { - lc := &cobra.Command{ - Use: "revoke ", - Short: "Revokes leases", - - Run: leaseRevokeCommandFunc, - } - - return lc -} - -// leaseRevokeCommandFunc executes the "lease grant" command. -func leaseRevokeCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("lease revoke command needs 1 argument")) - } - - id := leaseFromArgs(args[0]) - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).Revoke(ctx, id) - cancel() - if err != nil { - ExitWithError(ExitError, fmt.Errorf("failed to revoke lease (%v)\n", err)) - } - display.Revoke(id, *resp) -} - -var timeToLiveKeys bool - -// NewLeaseTimeToLiveCommand returns the cobra command for "lease timetolive". -func NewLeaseTimeToLiveCommand() *cobra.Command { - lc := &cobra.Command{ - Use: "timetolive [options]", - Short: "Get lease information", - - Run: leaseTimeToLiveCommandFunc, - } - lc.Flags().BoolVar(&timeToLiveKeys, "keys", false, "Get keys attached to this lease") - - return lc -} - -// leaseTimeToLiveCommandFunc executes the "lease timetolive" command. -func leaseTimeToLiveCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("lease timetolive command needs lease ID as argument")) - } - var opts []v3.LeaseOption - if timeToLiveKeys { - opts = append(opts, v3.WithAttachedKeys()) - } - resp, rerr := mustClientFromCmd(cmd).TimeToLive(context.TODO(), leaseFromArgs(args[0]), opts...) - if rerr != nil { - ExitWithError(ExitBadConnection, rerr) - } - display.TimeToLive(*resp, timeToLiveKeys) -} - -// NewLeaseListCommand returns the cobra command for "lease list". -func NewLeaseListCommand() *cobra.Command { - lc := &cobra.Command{ - Use: "list", - Short: "List all active leases", - Run: leaseListCommandFunc, - } - return lc -} - -// leaseListCommandFunc executes the "lease list" command. -func leaseListCommandFunc(cmd *cobra.Command, args []string) { - resp, rerr := mustClientFromCmd(cmd).Leases(context.TODO()) - if rerr != nil { - ExitWithError(ExitBadConnection, rerr) - } - display.Leases(*resp) -} - -var ( - leaseKeepAliveOnce bool -) - -// NewLeaseKeepAliveCommand returns the cobra command for "lease keep-alive". -func NewLeaseKeepAliveCommand() *cobra.Command { - lc := &cobra.Command{ - Use: "keep-alive [options] ", - Short: "Keeps leases alive (renew)", - - Run: leaseKeepAliveCommandFunc, - } - - lc.Flags().BoolVar(&leaseKeepAliveOnce, "once", false, "Resets the keep-alive time to its original value and exits immediately") - - return lc -} - -// leaseKeepAliveCommandFunc executes the "lease keep-alive" command. -func leaseKeepAliveCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("lease keep-alive command needs lease ID as argument")) - } - - id := leaseFromArgs(args[0]) - - if leaseKeepAliveOnce { - respc, kerr := mustClientFromCmd(cmd).KeepAliveOnce(context.TODO(), id) - if kerr != nil { - ExitWithError(ExitBadConnection, kerr) - } - display.KeepAlive(*respc) - return - } - - respc, kerr := mustClientFromCmd(cmd).KeepAlive(context.TODO(), id) - if kerr != nil { - ExitWithError(ExitBadConnection, kerr) - } - for resp := range respc { - display.KeepAlive(*resp) - } - - if _, ok := (display).(*simplePrinter); ok { - fmt.Printf("lease %016x expired or revoked.\n", id) - } -} - -func leaseFromArgs(arg string) v3.LeaseID { - id, err := strconv.ParseInt(arg, 16, 64) - if err != nil { - ExitWithError(ExitBadArgs, fmt.Errorf("bad lease ID arg (%v), expecting ID in Hex", err)) - } - return v3.LeaseID(id) -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/lock_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/lock_command.go deleted file mode 100644 index 74ebac81e340..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/lock_command.go +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "errors" - "fmt" - "os" - "os/exec" - "os/signal" - "syscall" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/concurrency" - - "github.com/spf13/cobra" -) - -var lockTTL = 10 - -// NewLockCommand returns the cobra command for "lock". -func NewLockCommand() *cobra.Command { - c := &cobra.Command{ - Use: "lock [exec-command arg1 arg2 ...]", - Short: "Acquires a named lock", - Run: lockCommandFunc, - } - c.Flags().IntVarP(&lockTTL, "ttl", "", lockTTL, "timeout for session") - return c -} - -func lockCommandFunc(cmd *cobra.Command, args []string) { - if len(args) == 0 { - ExitWithError(ExitBadArgs, errors.New("lock takes a lock name argument and an optional command to execute.")) - } - c := mustClientFromCmd(cmd) - if err := lockUntilSignal(c, args[0], args[1:]); err != nil { - ExitWithError(ExitError, err) - } -} - -func lockUntilSignal(c *clientv3.Client, lockname string, cmdArgs []string) error { - s, err := concurrency.NewSession(c, concurrency.WithTTL(lockTTL)) - if err != nil { - return err - } - - m := concurrency.NewMutex(s, lockname) - ctx, cancel := context.WithCancel(context.TODO()) - - // unlock in case of ordinary shutdown - donec := make(chan struct{}) - sigc := make(chan os.Signal, 1) - signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM) - go func() { - <-sigc - cancel() - close(donec) - }() - - if err := m.Lock(ctx); err != nil { - return err - } - - if len(cmdArgs) > 0 { - cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...) - cmd.Env = append(environLockResponse(m), os.Environ()...) - cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr - err := cmd.Run() - unlockErr := m.Unlock(context.TODO()) - if err != nil { - return err - } - return unlockErr - } - - k, kerr := c.Get(ctx, m.Key()) - if kerr != nil { - return kerr - } - if len(k.Kvs) == 0 { - return errors.New("lock lost on init") - } - display.Get(*k) - - select { - case <-donec: - return m.Unlock(context.TODO()) - case <-s.Done(): - } - - return errors.New("session expired") -} - -func environLockResponse(m *concurrency.Mutex) []string { - return []string{ - "ETCD_LOCK_KEY=" + m.Key(), - fmt.Sprintf("ETCD_LOCK_REV=%d", m.Header().Revision), - } -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/make_mirror_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/make_mirror_command.go deleted file mode 100644 index 8afa479d49bf..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/make_mirror_command.go +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "errors" - "fmt" - "strings" - "sync/atomic" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/mirror" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - "github.com/coreos/etcd/mvcc/mvccpb" - - "github.com/spf13/cobra" -) - -var ( - mminsecureTr bool - mmcert string - mmkey string - mmcacert string - mmprefix string - mmdestprefix string - mmnodestprefix bool -) - -// NewMakeMirrorCommand returns the cobra command for "makeMirror". -func NewMakeMirrorCommand() *cobra.Command { - c := &cobra.Command{ - Use: "make-mirror [options] ", - Short: "Makes a mirror at the destination etcd cluster", - Run: makeMirrorCommandFunc, - } - - c.Flags().StringVar(&mmprefix, "prefix", "", "Key-value prefix to mirror") - c.Flags().StringVar(&mmdestprefix, "dest-prefix", "", "destination prefix to mirror a prefix to a different prefix in the destination cluster") - c.Flags().BoolVar(&mmnodestprefix, "no-dest-prefix", false, "mirror key-values to the root of the destination cluster") - c.Flags().StringVar(&mmcert, "dest-cert", "", "Identify secure client using this TLS certificate file for the destination cluster") - c.Flags().StringVar(&mmkey, "dest-key", "", "Identify secure client using this TLS key file") - c.Flags().StringVar(&mmcacert, "dest-cacert", "", "Verify certificates of TLS enabled secure servers using this CA bundle") - // TODO: secure by default when etcd enables secure gRPC by default. - c.Flags().BoolVar(&mminsecureTr, "dest-insecure-transport", true, "Disable transport security for client connections") - - return c -} - -func makeMirrorCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, errors.New("make-mirror takes one destination argument.")) - } - - dialTimeout := dialTimeoutFromCmd(cmd) - keepAliveTime := keepAliveTimeFromCmd(cmd) - keepAliveTimeout := keepAliveTimeoutFromCmd(cmd) - sec := &secureCfg{ - cert: mmcert, - key: mmkey, - cacert: mmcacert, - insecureTransport: mminsecureTr, - } - - cc := &clientConfig{ - endpoints: []string{args[0]}, - dialTimeout: dialTimeout, - keepAliveTime: keepAliveTime, - keepAliveTimeout: keepAliveTimeout, - scfg: sec, - acfg: nil, - } - dc := cc.mustClient() - c := mustClientFromCmd(cmd) - - err := makeMirror(context.TODO(), c, dc) - ExitWithError(ExitError, err) -} - -func makeMirror(ctx context.Context, c *clientv3.Client, dc *clientv3.Client) error { - total := int64(0) - - go func() { - for { - time.Sleep(30 * time.Second) - fmt.Println(atomic.LoadInt64(&total)) - } - }() - - s := mirror.NewSyncer(c, mmprefix, 0) - - rc, errc := s.SyncBase(ctx) - - // if destination prefix is specified and remove destination prefix is true return error - if mmnodestprefix && len(mmdestprefix) > 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("`--dest-prefix` and `--no-dest-prefix` cannot be set at the same time, choose one.")) - } - - // if remove destination prefix is false and destination prefix is empty set the value of destination prefix same as prefix - if !mmnodestprefix && len(mmdestprefix) == 0 { - mmdestprefix = mmprefix - } - - for r := range rc { - for _, kv := range r.Kvs { - _, err := dc.Put(ctx, modifyPrefix(string(kv.Key)), string(kv.Value)) - if err != nil { - return err - } - atomic.AddInt64(&total, 1) - } - } - - err := <-errc - if err != nil { - return err - } - - wc := s.SyncUpdates(ctx) - - for wr := range wc { - if wr.CompactRevision != 0 { - return rpctypes.ErrCompacted - } - - var lastRev int64 - ops := []clientv3.Op{} - - for _, ev := range wr.Events { - nextRev := ev.Kv.ModRevision - if lastRev != 0 && nextRev > lastRev { - _, err := dc.Txn(ctx).Then(ops...).Commit() - if err != nil { - return err - } - ops = []clientv3.Op{} - } - lastRev = nextRev - switch ev.Type { - case mvccpb.PUT: - ops = append(ops, clientv3.OpPut(modifyPrefix(string(ev.Kv.Key)), string(ev.Kv.Value))) - atomic.AddInt64(&total, 1) - case mvccpb.DELETE: - ops = append(ops, clientv3.OpDelete(modifyPrefix(string(ev.Kv.Key)))) - atomic.AddInt64(&total, 1) - default: - panic("unexpected event type") - } - } - - if len(ops) != 0 { - _, err := dc.Txn(ctx).Then(ops...).Commit() - if err != nil { - return err - } - } - } - - return nil -} - -func modifyPrefix(key string) string { - return strings.Replace(key, mmprefix, mmdestprefix, 1) -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/member_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/member_command.go deleted file mode 100644 index cb4e9d582f9f..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/member_command.go +++ /dev/null @@ -1,217 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "strconv" - "strings" - - "github.com/spf13/cobra" -) - -var memberPeerURLs string - -// NewMemberCommand returns the cobra command for "member". -func NewMemberCommand() *cobra.Command { - mc := &cobra.Command{ - Use: "member ", - Short: "Membership related commands", - } - - mc.AddCommand(NewMemberAddCommand()) - mc.AddCommand(NewMemberRemoveCommand()) - mc.AddCommand(NewMemberUpdateCommand()) - mc.AddCommand(NewMemberListCommand()) - - return mc -} - -// NewMemberAddCommand returns the cobra command for "member add". -func NewMemberAddCommand() *cobra.Command { - cc := &cobra.Command{ - Use: "add [options]", - Short: "Adds a member into the cluster", - - Run: memberAddCommandFunc, - } - - cc.Flags().StringVar(&memberPeerURLs, "peer-urls", "", "comma separated peer URLs for the new member.") - - return cc -} - -// NewMemberRemoveCommand returns the cobra command for "member remove". -func NewMemberRemoveCommand() *cobra.Command { - cc := &cobra.Command{ - Use: "remove ", - Short: "Removes a member from the cluster", - - Run: memberRemoveCommandFunc, - } - - return cc -} - -// NewMemberUpdateCommand returns the cobra command for "member update". -func NewMemberUpdateCommand() *cobra.Command { - cc := &cobra.Command{ - Use: "update [options]", - Short: "Updates a member in the cluster", - - Run: memberUpdateCommandFunc, - } - - cc.Flags().StringVar(&memberPeerURLs, "peer-urls", "", "comma separated peer URLs for the updated member.") - - return cc -} - -// NewMemberListCommand returns the cobra command for "member list". -func NewMemberListCommand() *cobra.Command { - cc := &cobra.Command{ - Use: "list", - Short: "Lists all members in the cluster", - Long: `When --write-out is set to simple, this command prints out comma-separated member lists for each endpoint. -The items in the lists are ID, Status, Name, Peer Addrs, Client Addrs. -`, - - Run: memberListCommandFunc, - } - - return cc -} - -// memberAddCommandFunc executes the "member add" command. -func memberAddCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("member name not provided.")) - } - newMemberName := args[0] - - if len(memberPeerURLs) == 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("member peer urls not provided.")) - } - - urls := strings.Split(memberPeerURLs, ",") - ctx, cancel := commandCtx(cmd) - cli := mustClientFromCmd(cmd) - resp, err := cli.MemberAdd(ctx, urls) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - newID := resp.Member.ID - - display.MemberAdd(*resp) - - if _, ok := (display).(*simplePrinter); ok { - ctx, cancel = commandCtx(cmd) - listResp, err := cli.MemberList(ctx) - // get latest member list; if there's failover new member might have outdated list - for { - if err != nil { - ExitWithError(ExitError, err) - } - if listResp.Header.MemberId == resp.Header.MemberId { - break - } - // quorum get to sync cluster list - gresp, gerr := cli.Get(ctx, "_") - if gerr != nil { - ExitWithError(ExitError, err) - } - resp.Header.MemberId = gresp.Header.MemberId - listResp, err = cli.MemberList(ctx) - } - cancel() - - conf := []string{} - for _, memb := range listResp.Members { - for _, u := range memb.PeerURLs { - n := memb.Name - if memb.ID == newID { - n = newMemberName - } - conf = append(conf, fmt.Sprintf("%s=%s", n, u)) - } - } - - fmt.Print("\n") - fmt.Printf("ETCD_NAME=%q\n", newMemberName) - fmt.Printf("ETCD_INITIAL_CLUSTER=%q\n", strings.Join(conf, ",")) - fmt.Printf("ETCD_INITIAL_ADVERTISE_PEER_URLS=%q\n", memberPeerURLs) - fmt.Printf("ETCD_INITIAL_CLUSTER_STATE=\"existing\"\n") - } -} - -// memberRemoveCommandFunc executes the "member remove" command. -func memberRemoveCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("member ID is not provided")) - } - - id, err := strconv.ParseUint(args[0], 16, 64) - if err != nil { - ExitWithError(ExitBadArgs, fmt.Errorf("bad member ID arg (%v), expecting ID in Hex", err)) - } - - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).MemberRemove(ctx, id) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - display.MemberRemove(id, *resp) -} - -// memberUpdateCommandFunc executes the "member update" command. -func memberUpdateCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("member ID is not provided")) - } - - id, err := strconv.ParseUint(args[0], 16, 64) - if err != nil { - ExitWithError(ExitBadArgs, fmt.Errorf("bad member ID arg (%v), expecting ID in Hex", err)) - } - - if len(memberPeerURLs) == 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("member peer urls not provided.")) - } - - urls := strings.Split(memberPeerURLs, ",") - - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).MemberUpdate(ctx, id, urls) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - - display.MemberUpdate(id, *resp) -} - -// memberListCommandFunc executes the "member list" command. -func memberListCommandFunc(cmd *cobra.Command, args []string) { - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).MemberList(ctx) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - - display.MemberList(*resp) -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/migrate_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/migrate_command.go deleted file mode 100644 index 48c17c8ab4a2..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/migrate_command.go +++ /dev/null @@ -1,402 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "encoding/binary" - "encoding/json" - "fmt" - "io" - "os" - "os/exec" - "path/filepath" - "time" - - "github.com/coreos/etcd/client" - etcdErr "github.com/coreos/etcd/error" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/mvcc/mvccpb" - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/snap" - "github.com/coreos/etcd/store" - "github.com/coreos/etcd/wal" - "github.com/coreos/etcd/wal/walpb" - "github.com/gogo/protobuf/proto" - "github.com/spf13/cobra" -) - -var ( - migrateExcludeTTLKey bool - migrateDatadir string - migrateWALdir string - migrateTransformer string -) - -// NewMigrateCommand returns the cobra command for "migrate". -func NewMigrateCommand() *cobra.Command { - mc := &cobra.Command{ - Use: "migrate", - Short: "Migrates keys in a v2 store to a mvcc store", - Run: migrateCommandFunc, - } - - mc.Flags().BoolVar(&migrateExcludeTTLKey, "no-ttl", false, "Do not convert TTL keys") - mc.Flags().StringVar(&migrateDatadir, "data-dir", "", "Path to the data directory") - mc.Flags().StringVar(&migrateWALdir, "wal-dir", "", "Path to the WAL directory") - mc.Flags().StringVar(&migrateTransformer, "transformer", "", "Path to the user-provided transformer program") - return mc -} - -func migrateCommandFunc(cmd *cobra.Command, args []string) { - var ( - writer io.WriteCloser - reader io.ReadCloser - errc chan error - ) - if migrateTransformer != "" { - writer, reader, errc = startTransformer() - } else { - fmt.Println("using default transformer") - writer, reader, errc = defaultTransformer() - } - - st, index := rebuildStoreV2() - be := prepareBackend() - defer be.Close() - - go func() { - writeStore(writer, st) - writer.Close() - }() - - readKeys(reader, be) - mvcc.UpdateConsistentIndex(be, index) - err := <-errc - if err != nil { - fmt.Println("failed to transform keys") - ExitWithError(ExitError, err) - } - - fmt.Println("finished transforming keys") -} - -func prepareBackend() backend.Backend { - var be backend.Backend - - bch := make(chan struct{}) - dbpath := filepath.Join(migrateDatadir, "member", "snap", "db") - go func() { - defer close(bch) - be = backend.NewDefaultBackend(dbpath) - - }() - select { - case <-bch: - case <-time.After(time.Second): - fmt.Fprintf(os.Stderr, "waiting for etcd to close and release its lock on %q\n", dbpath) - <-bch - } - - tx := be.BatchTx() - tx.Lock() - tx.UnsafeCreateBucket([]byte("key")) - tx.UnsafeCreateBucket([]byte("meta")) - tx.Unlock() - return be -} - -func rebuildStoreV2() (store.Store, uint64) { - var index uint64 - cl := membership.NewCluster("") - - waldir := migrateWALdir - if len(waldir) == 0 { - waldir = filepath.Join(migrateDatadir, "member", "wal") - } - snapdir := filepath.Join(migrateDatadir, "member", "snap") - - ss := snap.New(snapdir) - snapshot, err := ss.Load() - if err != nil && err != snap.ErrNoSnapshot { - ExitWithError(ExitError, err) - } - - var walsnap walpb.Snapshot - if snapshot != nil { - walsnap.Index, walsnap.Term = snapshot.Metadata.Index, snapshot.Metadata.Term - index = snapshot.Metadata.Index - } - - w, err := wal.OpenForRead(waldir, walsnap) - if err != nil { - ExitWithError(ExitError, err) - } - defer w.Close() - - _, _, ents, err := w.ReadAll() - if err != nil { - ExitWithError(ExitError, err) - } - - st := store.New() - if snapshot != nil { - err := st.Recovery(snapshot.Data) - if err != nil { - ExitWithError(ExitError, err) - } - } - - cl.SetStore(st) - cl.Recover(api.UpdateCapability) - - applier := etcdserver.NewApplierV2(st, cl) - for _, ent := range ents { - if ent.Type == raftpb.EntryConfChange { - var cc raftpb.ConfChange - pbutil.MustUnmarshal(&cc, ent.Data) - applyConf(cc, cl) - continue - } - - var raftReq pb.InternalRaftRequest - if !pbutil.MaybeUnmarshal(&raftReq, ent.Data) { // backward compatible - var r pb.Request - pbutil.MustUnmarshal(&r, ent.Data) - applyRequest(&r, applier) - } else { - if raftReq.V2 != nil { - req := raftReq.V2 - applyRequest(req, applier) - } - } - if ent.Index > index { - index = ent.Index - } - } - - return st, index -} - -func applyConf(cc raftpb.ConfChange, cl *membership.RaftCluster) { - if err := cl.ValidateConfigurationChange(cc); err != nil { - return - } - switch cc.Type { - case raftpb.ConfChangeAddNode: - m := new(membership.Member) - if err := json.Unmarshal(cc.Context, m); err != nil { - panic(err) - } - cl.AddMember(m) - case raftpb.ConfChangeRemoveNode: - cl.RemoveMember(types.ID(cc.NodeID)) - case raftpb.ConfChangeUpdateNode: - m := new(membership.Member) - if err := json.Unmarshal(cc.Context, m); err != nil { - panic(err) - } - cl.UpdateRaftAttributes(m.ID, m.RaftAttributes) - } -} - -func applyRequest(req *pb.Request, applyV2 etcdserver.ApplierV2) { - r := (*etcdserver.RequestV2)(req) - r.TTLOptions() - switch r.Method { - case "POST": - applyV2.Post(r) - case "PUT": - applyV2.Put(r) - case "DELETE": - applyV2.Delete(r) - case "QGET": - applyV2.QGet(r) - case "SYNC": - applyV2.Sync(r) - default: - panic("unknown command") - } -} - -func writeStore(w io.Writer, st store.Store) uint64 { - all, err := st.Get("/1", true, true) - if err != nil { - if eerr, ok := err.(*etcdErr.Error); ok && eerr.ErrorCode == etcdErr.EcodeKeyNotFound { - fmt.Println("no v2 keys to migrate") - os.Exit(0) - } - ExitWithError(ExitError, err) - } - return writeKeys(w, all.Node) -} - -func writeKeys(w io.Writer, n *store.NodeExtern) uint64 { - maxIndex := n.ModifiedIndex - - nodes := n.Nodes - // remove store v2 bucket prefix - n.Key = n.Key[2:] - if n.Key == "" { - n.Key = "/" - } - if n.Dir { - n.Nodes = nil - } - if !migrateExcludeTTLKey || n.TTL == 0 { - b, err := json.Marshal(n) - if err != nil { - ExitWithError(ExitError, err) - } - fmt.Fprint(w, string(b)) - } - for _, nn := range nodes { - max := writeKeys(w, nn) - if max > maxIndex { - maxIndex = max - } - } - return maxIndex -} - -func readKeys(r io.Reader, be backend.Backend) error { - for { - length64, err := readInt64(r) - if err != nil { - if err == io.EOF { - return nil - } - return err - } - - buf := make([]byte, int(length64)) - if _, err = io.ReadFull(r, buf); err != nil { - return err - } - - var kv mvccpb.KeyValue - err = proto.Unmarshal(buf, &kv) - if err != nil { - return err - } - - mvcc.WriteKV(be, kv) - } -} - -func readInt64(r io.Reader) (int64, error) { - var n int64 - err := binary.Read(r, binary.LittleEndian, &n) - return n, err -} - -func startTransformer() (io.WriteCloser, io.ReadCloser, chan error) { - cmd := exec.Command(migrateTransformer) - cmd.Stderr = os.Stderr - - writer, err := cmd.StdinPipe() - if err != nil { - ExitWithError(ExitError, err) - } - - reader, rerr := cmd.StdoutPipe() - if rerr != nil { - ExitWithError(ExitError, rerr) - } - - if err := cmd.Start(); err != nil { - ExitWithError(ExitError, err) - } - - errc := make(chan error, 1) - - go func() { - errc <- cmd.Wait() - }() - - return writer, reader, errc -} - -func defaultTransformer() (io.WriteCloser, io.ReadCloser, chan error) { - // transformer decodes v2 keys from sr - sr, sw := io.Pipe() - // transformer encodes v3 keys into dw - dr, dw := io.Pipe() - - decoder := json.NewDecoder(sr) - - errc := make(chan error, 1) - - go func() { - defer func() { - sr.Close() - dw.Close() - }() - - for decoder.More() { - node := &client.Node{} - if err := decoder.Decode(node); err != nil { - errc <- err - return - } - - kv := transform(node) - if kv == nil { - continue - } - - data, err := proto.Marshal(kv) - if err != nil { - errc <- err - return - } - buf := make([]byte, 8) - binary.LittleEndian.PutUint64(buf, uint64(len(data))) - if _, err := dw.Write(buf); err != nil { - errc <- err - return - } - if _, err := dw.Write(data); err != nil { - errc <- err - return - } - } - - errc <- nil - }() - - return sw, dr, errc -} - -func transform(n *client.Node) *mvccpb.KeyValue { - const unKnownVersion = 1 - if n.Dir { - return nil - } - kv := &mvccpb.KeyValue{ - Key: []byte(n.Key), - Value: []byte(n.Value), - CreateRevision: int64(n.CreatedIndex), - ModRevision: int64(n.ModifiedIndex), - Version: unKnownVersion, - } - return kv -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/move_leader_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/move_leader_command.go deleted file mode 100644 index 5fdecf95a817..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/move_leader_command.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "strconv" - - "github.com/coreos/etcd/clientv3" - "github.com/spf13/cobra" -) - -// NewMoveLeaderCommand returns the cobra command for "move-leader". -func NewMoveLeaderCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "move-leader ", - Short: "Transfers leadership to another etcd cluster member.", - Run: transferLeadershipCommandFunc, - } - return cmd -} - -// transferLeadershipCommandFunc executes the "compaction" command. -func transferLeadershipCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("move-leader command needs 1 argument")) - } - target, err := strconv.ParseUint(args[0], 16, 64) - if err != nil { - ExitWithError(ExitBadArgs, err) - } - - c := mustClientFromCmd(cmd) - eps := c.Endpoints() - c.Close() - - ctx, cancel := commandCtx(cmd) - - // find current leader - var leaderCli *clientv3.Client - var leaderID uint64 - for _, ep := range eps { - cfg := clientConfigFromCmd(cmd) - cfg.endpoints = []string{ep} - cli := cfg.mustClient() - resp, serr := cli.Status(ctx, ep) - if serr != nil { - ExitWithError(ExitError, serr) - } - - if resp.Header.GetMemberId() == resp.Leader { - leaderCli = cli - leaderID = resp.Leader - break - } - cli.Close() - } - if leaderCli == nil { - ExitWithError(ExitBadArgs, fmt.Errorf("no leader endpoint given at %v", eps)) - } - - var resp *clientv3.MoveLeaderResponse - resp, err = leaderCli.MoveLeader(ctx, target) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - - display.MoveLeader(leaderID, target, *resp) -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer.go deleted file mode 100644 index b0c2d6cad652..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer.go +++ /dev/null @@ -1,211 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "errors" - "fmt" - "strings" - - v3 "github.com/coreos/etcd/clientv3" - "github.com/dustin/go-humanize" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -type printer interface { - Del(v3.DeleteResponse) - Get(v3.GetResponse) - Put(v3.PutResponse) - Txn(v3.TxnResponse) - Watch(v3.WatchResponse) - - Grant(r v3.LeaseGrantResponse) - Revoke(id v3.LeaseID, r v3.LeaseRevokeResponse) - KeepAlive(r v3.LeaseKeepAliveResponse) - TimeToLive(r v3.LeaseTimeToLiveResponse, keys bool) - Leases(r v3.LeaseLeasesResponse) - - MemberAdd(v3.MemberAddResponse) - MemberRemove(id uint64, r v3.MemberRemoveResponse) - MemberUpdate(id uint64, r v3.MemberUpdateResponse) - MemberList(v3.MemberListResponse) - - EndpointStatus([]epStatus) - EndpointHashKV([]epHashKV) - MoveLeader(leader, target uint64, r v3.MoveLeaderResponse) - - Alarm(v3.AlarmResponse) - DBStatus(dbstatus) - - RoleAdd(role string, r v3.AuthRoleAddResponse) - RoleGet(role string, r v3.AuthRoleGetResponse) - RoleDelete(role string, r v3.AuthRoleDeleteResponse) - RoleList(v3.AuthRoleListResponse) - RoleGrantPermission(role string, r v3.AuthRoleGrantPermissionResponse) - RoleRevokePermission(role string, key string, end string, r v3.AuthRoleRevokePermissionResponse) - - UserAdd(user string, r v3.AuthUserAddResponse) - UserGet(user string, r v3.AuthUserGetResponse) - UserList(r v3.AuthUserListResponse) - UserChangePassword(v3.AuthUserChangePasswordResponse) - UserGrantRole(user string, role string, r v3.AuthUserGrantRoleResponse) - UserRevokeRole(user string, role string, r v3.AuthUserRevokeRoleResponse) - UserDelete(user string, r v3.AuthUserDeleteResponse) -} - -func NewPrinter(printerType string, isHex bool) printer { - switch printerType { - case "simple": - return &simplePrinter{isHex: isHex} - case "fields": - return &fieldsPrinter{newPrinterUnsupported("fields")} - case "json": - return newJSONPrinter() - case "protobuf": - return newPBPrinter() - case "table": - return &tablePrinter{newPrinterUnsupported("table")} - } - return nil -} - -type printerRPC struct { - printer - p func(interface{}) -} - -func (p *printerRPC) Del(r v3.DeleteResponse) { p.p((*pb.DeleteRangeResponse)(&r)) } -func (p *printerRPC) Get(r v3.GetResponse) { p.p((*pb.RangeResponse)(&r)) } -func (p *printerRPC) Put(r v3.PutResponse) { p.p((*pb.PutResponse)(&r)) } -func (p *printerRPC) Txn(r v3.TxnResponse) { p.p((*pb.TxnResponse)(&r)) } -func (p *printerRPC) Watch(r v3.WatchResponse) { p.p(&r) } - -func (p *printerRPC) Grant(r v3.LeaseGrantResponse) { p.p(r) } -func (p *printerRPC) Revoke(id v3.LeaseID, r v3.LeaseRevokeResponse) { p.p(r) } -func (p *printerRPC) KeepAlive(r v3.LeaseKeepAliveResponse) { p.p(r) } -func (p *printerRPC) TimeToLive(r v3.LeaseTimeToLiveResponse, keys bool) { p.p(&r) } -func (p *printerRPC) Leases(r v3.LeaseLeasesResponse) { p.p(&r) } - -func (p *printerRPC) MemberAdd(r v3.MemberAddResponse) { p.p((*pb.MemberAddResponse)(&r)) } -func (p *printerRPC) MemberRemove(id uint64, r v3.MemberRemoveResponse) { - p.p((*pb.MemberRemoveResponse)(&r)) -} -func (p *printerRPC) MemberUpdate(id uint64, r v3.MemberUpdateResponse) { - p.p((*pb.MemberUpdateResponse)(&r)) -} -func (p *printerRPC) MemberList(r v3.MemberListResponse) { p.p((*pb.MemberListResponse)(&r)) } -func (p *printerRPC) Alarm(r v3.AlarmResponse) { p.p((*pb.AlarmResponse)(&r)) } -func (p *printerRPC) MoveLeader(leader, target uint64, r v3.MoveLeaderResponse) { - p.p((*pb.MoveLeaderResponse)(&r)) -} -func (p *printerRPC) RoleAdd(_ string, r v3.AuthRoleAddResponse) { p.p((*pb.AuthRoleAddResponse)(&r)) } -func (p *printerRPC) RoleGet(_ string, r v3.AuthRoleGetResponse) { p.p((*pb.AuthRoleGetResponse)(&r)) } -func (p *printerRPC) RoleDelete(_ string, r v3.AuthRoleDeleteResponse) { - p.p((*pb.AuthRoleDeleteResponse)(&r)) -} -func (p *printerRPC) RoleList(r v3.AuthRoleListResponse) { p.p((*pb.AuthRoleListResponse)(&r)) } -func (p *printerRPC) RoleGrantPermission(_ string, r v3.AuthRoleGrantPermissionResponse) { - p.p((*pb.AuthRoleGrantPermissionResponse)(&r)) -} -func (p *printerRPC) RoleRevokePermission(_ string, _ string, _ string, r v3.AuthRoleRevokePermissionResponse) { - p.p((*pb.AuthRoleRevokePermissionResponse)(&r)) -} -func (p *printerRPC) UserAdd(_ string, r v3.AuthUserAddResponse) { p.p((*pb.AuthUserAddResponse)(&r)) } -func (p *printerRPC) UserGet(_ string, r v3.AuthUserGetResponse) { p.p((*pb.AuthUserGetResponse)(&r)) } -func (p *printerRPC) UserList(r v3.AuthUserListResponse) { p.p((*pb.AuthUserListResponse)(&r)) } -func (p *printerRPC) UserChangePassword(r v3.AuthUserChangePasswordResponse) { - p.p((*pb.AuthUserChangePasswordResponse)(&r)) -} -func (p *printerRPC) UserGrantRole(_ string, _ string, r v3.AuthUserGrantRoleResponse) { - p.p((*pb.AuthUserGrantRoleResponse)(&r)) -} -func (p *printerRPC) UserRevokeRole(_ string, _ string, r v3.AuthUserRevokeRoleResponse) { - p.p((*pb.AuthUserRevokeRoleResponse)(&r)) -} -func (p *printerRPC) UserDelete(_ string, r v3.AuthUserDeleteResponse) { - p.p((*pb.AuthUserDeleteResponse)(&r)) -} - -type printerUnsupported struct{ printerRPC } - -func newPrinterUnsupported(n string) printer { - f := func(interface{}) { - ExitWithError(ExitBadFeature, errors.New(n+" not supported as output format")) - } - return &printerUnsupported{printerRPC{nil, f}} -} - -func (p *printerUnsupported) EndpointStatus([]epStatus) { p.p(nil) } -func (p *printerUnsupported) EndpointHashKV([]epHashKV) { p.p(nil) } -func (p *printerUnsupported) DBStatus(dbstatus) { p.p(nil) } - -func (p *printerUnsupported) MoveLeader(leader, target uint64, r v3.MoveLeaderResponse) { p.p(nil) } - -func makeMemberListTable(r v3.MemberListResponse) (hdr []string, rows [][]string) { - hdr = []string{"ID", "Status", "Name", "Peer Addrs", "Client Addrs"} - for _, m := range r.Members { - status := "started" - if len(m.Name) == 0 { - status = "unstarted" - } - rows = append(rows, []string{ - fmt.Sprintf("%x", m.ID), - status, - m.Name, - strings.Join(m.PeerURLs, ","), - strings.Join(m.ClientURLs, ","), - }) - } - return hdr, rows -} - -func makeEndpointStatusTable(statusList []epStatus) (hdr []string, rows [][]string) { - hdr = []string{"endpoint", "ID", "version", "db size", "is leader", "raft term", "raft index"} - for _, status := range statusList { - rows = append(rows, []string{ - status.Ep, - fmt.Sprintf("%x", status.Resp.Header.MemberId), - status.Resp.Version, - humanize.Bytes(uint64(status.Resp.DbSize)), - fmt.Sprint(status.Resp.Leader == status.Resp.Header.MemberId), - fmt.Sprint(status.Resp.RaftTerm), - fmt.Sprint(status.Resp.RaftIndex), - }) - } - return hdr, rows -} - -func makeEndpointHashKVTable(hashList []epHashKV) (hdr []string, rows [][]string) { - hdr = []string{"endpoint", "hash"} - for _, h := range hashList { - rows = append(rows, []string{ - h.Ep, - fmt.Sprint(h.Resp.Hash), - }) - } - return hdr, rows -} - -func makeDBStatusTable(ds dbstatus) (hdr []string, rows [][]string) { - hdr = []string{"hash", "revision", "total keys", "total size"} - rows = append(rows, []string{ - fmt.Sprintf("%x", ds.Hash), - fmt.Sprint(ds.Revision), - fmt.Sprint(ds.TotalKey), - humanize.Bytes(uint64(ds.TotalSize)), - }) - return hdr, rows -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_fields.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_fields.go deleted file mode 100644 index 24ff283a8cac..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_fields.go +++ /dev/null @@ -1,213 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - - v3 "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - spb "github.com/coreos/etcd/mvcc/mvccpb" -) - -type fieldsPrinter struct{ printer } - -func (p *fieldsPrinter) kv(pfx string, kv *spb.KeyValue) { - fmt.Printf("\"%sKey\" : %q\n", pfx, string(kv.Key)) - fmt.Printf("\"%sCreateRevision\" : %d\n", pfx, kv.CreateRevision) - fmt.Printf("\"%sModRevision\" : %d\n", pfx, kv.ModRevision) - fmt.Printf("\"%sVersion\" : %d\n", pfx, kv.Version) - fmt.Printf("\"%sValue\" : %q\n", pfx, string(kv.Value)) - fmt.Printf("\"%sLease\" : %d\n", pfx, kv.Lease) -} - -func (p *fieldsPrinter) hdr(h *pb.ResponseHeader) { - fmt.Println(`"ClusterID" :`, h.ClusterId) - fmt.Println(`"MemberID" :`, h.MemberId) - fmt.Println(`"Revision" :`, h.Revision) - fmt.Println(`"RaftTerm" :`, h.RaftTerm) -} - -func (p *fieldsPrinter) Del(r v3.DeleteResponse) { - p.hdr(r.Header) - fmt.Println(`"Deleted" :`, r.Deleted) - for _, kv := range r.PrevKvs { - p.kv("Prev", kv) - } -} - -func (p *fieldsPrinter) Get(r v3.GetResponse) { - p.hdr(r.Header) - for _, kv := range r.Kvs { - p.kv("", kv) - } - fmt.Println(`"More" :`, r.More) - fmt.Println(`"Count" :`, r.Count) -} - -func (p *fieldsPrinter) Put(r v3.PutResponse) { - p.hdr(r.Header) - if r.PrevKv != nil { - p.kv("Prev", r.PrevKv) - } -} - -func (p *fieldsPrinter) Txn(r v3.TxnResponse) { - p.hdr(r.Header) - fmt.Println(`"Succeeded" :`, r.Succeeded) - for _, resp := range r.Responses { - switch v := resp.Response.(type) { - case *pb.ResponseOp_ResponseDeleteRange: - p.Del((v3.DeleteResponse)(*v.ResponseDeleteRange)) - case *pb.ResponseOp_ResponsePut: - p.Put((v3.PutResponse)(*v.ResponsePut)) - case *pb.ResponseOp_ResponseRange: - p.Get((v3.GetResponse)(*v.ResponseRange)) - default: - fmt.Printf("\"Unknown\" : %q\n", fmt.Sprintf("%+v", v)) - } - } -} - -func (p *fieldsPrinter) Watch(resp v3.WatchResponse) { - p.hdr(&resp.Header) - for _, e := range resp.Events { - fmt.Println(`"Type" :`, e.Type) - if e.PrevKv != nil { - p.kv("Prev", e.PrevKv) - } - p.kv("", e.Kv) - } -} - -func (p *fieldsPrinter) Grant(r v3.LeaseGrantResponse) { - p.hdr(r.ResponseHeader) - fmt.Println(`"ID" :`, r.ID) - fmt.Println(`"TTL" :`, r.TTL) -} - -func (p *fieldsPrinter) Revoke(id v3.LeaseID, r v3.LeaseRevokeResponse) { - p.hdr(r.Header) -} - -func (p *fieldsPrinter) KeepAlive(r v3.LeaseKeepAliveResponse) { - p.hdr(r.ResponseHeader) - fmt.Println(`"ID" :`, r.ID) - fmt.Println(`"TTL" :`, r.TTL) -} - -func (p *fieldsPrinter) TimeToLive(r v3.LeaseTimeToLiveResponse, keys bool) { - p.hdr(r.ResponseHeader) - fmt.Println(`"ID" :`, r.ID) - fmt.Println(`"TTL" :`, r.TTL) - fmt.Println(`"GrantedTTL" :`, r.GrantedTTL) - for _, k := range r.Keys { - fmt.Printf("\"Key\" : %q\n", string(k)) - } -} - -func (p *fieldsPrinter) Leases(r v3.LeaseLeasesResponse) { - p.hdr(r.ResponseHeader) - for _, item := range r.Leases { - fmt.Println(`"ID" :`, item.ID) - } -} - -func (p *fieldsPrinter) MemberList(r v3.MemberListResponse) { - p.hdr(r.Header) - for _, m := range r.Members { - fmt.Println(`"ID" :`, m.ID) - fmt.Printf("\"Name\" : %q\n", m.Name) - for _, u := range m.PeerURLs { - fmt.Printf("\"PeerURL\" : %q\n", u) - } - for _, u := range m.ClientURLs { - fmt.Printf("\"ClientURL\" : %q\n", u) - } - fmt.Println() - } -} - -func (p *fieldsPrinter) EndpointStatus(eps []epStatus) { - for _, ep := range eps { - p.hdr(ep.Resp.Header) - fmt.Printf("\"Version\" : %q\n", ep.Resp.Version) - fmt.Println(`"DBSize" :`, ep.Resp.DbSize) - fmt.Println(`"Leader" :`, ep.Resp.Leader) - fmt.Println(`"RaftIndex" :`, ep.Resp.RaftIndex) - fmt.Println(`"RaftTerm" :`, ep.Resp.RaftTerm) - fmt.Printf("\"Endpoint\" : %q\n", ep.Ep) - fmt.Println() - } -} - -func (p *fieldsPrinter) EndpointHashKV(hs []epHashKV) { - for _, h := range hs { - p.hdr(h.Resp.Header) - fmt.Printf("\"Endpoint\" : %q\n", h.Ep) - fmt.Println(`"Hash" :`, h.Resp.Hash) - fmt.Println() - } -} - -func (p *fieldsPrinter) Alarm(r v3.AlarmResponse) { - p.hdr(r.Header) - for _, a := range r.Alarms { - fmt.Println(`"MemberID" :`, a.MemberID) - fmt.Println(`"AlarmType" :`, a.Alarm) - fmt.Println() - } -} - -func (p *fieldsPrinter) DBStatus(r dbstatus) { - fmt.Println(`"Hash" :`, r.Hash) - fmt.Println(`"Revision" :`, r.Revision) - fmt.Println(`"Keys" :`, r.TotalKey) - fmt.Println(`"Size" :`, r.TotalSize) -} - -func (p *fieldsPrinter) RoleAdd(role string, r v3.AuthRoleAddResponse) { p.hdr(r.Header) } -func (p *fieldsPrinter) RoleGet(role string, r v3.AuthRoleGetResponse) { - p.hdr(r.Header) - for _, p := range r.Perm { - fmt.Println(`"PermType" : `, p.PermType.String()) - fmt.Printf("\"Key\" : %q\n", string(p.Key)) - fmt.Printf("\"RangeEnd\" : %q\n", string(p.RangeEnd)) - } -} -func (p *fieldsPrinter) RoleDelete(role string, r v3.AuthRoleDeleteResponse) { p.hdr(r.Header) } -func (p *fieldsPrinter) RoleList(r v3.AuthRoleListResponse) { - p.hdr(r.Header) - fmt.Printf(`"Roles" :`) - for _, r := range r.Roles { - fmt.Printf(" %q", r) - } - fmt.Println() -} -func (p *fieldsPrinter) RoleGrantPermission(role string, r v3.AuthRoleGrantPermissionResponse) { - p.hdr(r.Header) -} -func (p *fieldsPrinter) RoleRevokePermission(role string, key string, end string, r v3.AuthRoleRevokePermissionResponse) { - p.hdr(r.Header) -} -func (p *fieldsPrinter) UserAdd(user string, r v3.AuthUserAddResponse) { p.hdr(r.Header) } -func (p *fieldsPrinter) UserChangePassword(r v3.AuthUserChangePasswordResponse) { p.hdr(r.Header) } -func (p *fieldsPrinter) UserGrantRole(user string, role string, r v3.AuthUserGrantRoleResponse) { - p.hdr(r.Header) -} -func (p *fieldsPrinter) UserRevokeRole(user string, role string, r v3.AuthUserRevokeRoleResponse) { - p.hdr(r.Header) -} -func (p *fieldsPrinter) UserDelete(user string, r v3.AuthUserDeleteResponse) { p.hdr(r.Header) } diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_json.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_json.go deleted file mode 100644 index 19b3a5e688bc..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_json.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "encoding/json" - "fmt" - "os" -) - -type jsonPrinter struct{ printer } - -func newJSONPrinter() printer { - return &jsonPrinter{ - &printerRPC{newPrinterUnsupported("json"), printJSON}, - } -} - -func (p *jsonPrinter) EndpointStatus(r []epStatus) { printJSON(r) } -func (p *jsonPrinter) EndpointHashKV(r []epHashKV) { printJSON(r) } -func (p *jsonPrinter) DBStatus(r dbstatus) { printJSON(r) } - -func printJSON(v interface{}) { - b, err := json.Marshal(v) - if err != nil { - fmt.Fprintf(os.Stderr, "%v\n", err) - return - } - fmt.Println(string(b)) -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_protobuf.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_protobuf.go deleted file mode 100644 index c5109c5c2eef..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_protobuf.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "os" - - v3 "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - mvccpb "github.com/coreos/etcd/mvcc/mvccpb" -) - -type pbPrinter struct{ printer } - -type pbMarshal interface { - Marshal() ([]byte, error) -} - -func newPBPrinter() printer { - return &pbPrinter{ - &printerRPC{newPrinterUnsupported("protobuf"), printPB}, - } -} - -func (p *pbPrinter) Watch(r v3.WatchResponse) { - evs := make([]*mvccpb.Event, len(r.Events)) - for i, ev := range r.Events { - evs[i] = (*mvccpb.Event)(ev) - } - wr := pb.WatchResponse{ - Header: &r.Header, - Events: evs, - CompactRevision: r.CompactRevision, - Canceled: r.Canceled, - Created: r.Created, - } - printPB(&wr) -} - -func printPB(v interface{}) { - m, ok := v.(pbMarshal) - if !ok { - ExitWithError(ExitBadFeature, fmt.Errorf("marshal unsupported for type %T (%v)", v, v)) - } - b, err := m.Marshal() - if err != nil { - fmt.Fprintf(os.Stderr, "%v\n", err) - return - } - fmt.Print(string(b)) -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_simple.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_simple.go deleted file mode 100644 index 2f4f53201c80..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_simple.go +++ /dev/null @@ -1,271 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "strings" - - v3 "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/pkg/types" -) - -type simplePrinter struct { - isHex bool - valueOnly bool -} - -func (s *simplePrinter) Del(resp v3.DeleteResponse) { - fmt.Println(resp.Deleted) - for _, kv := range resp.PrevKvs { - printKV(s.isHex, s.valueOnly, kv) - } -} - -func (s *simplePrinter) Get(resp v3.GetResponse) { - for _, kv := range resp.Kvs { - printKV(s.isHex, s.valueOnly, kv) - } -} - -func (s *simplePrinter) Put(r v3.PutResponse) { - fmt.Println("OK") - if r.PrevKv != nil { - printKV(s.isHex, s.valueOnly, r.PrevKv) - } -} - -func (s *simplePrinter) Txn(resp v3.TxnResponse) { - if resp.Succeeded { - fmt.Println("SUCCESS") - } else { - fmt.Println("FAILURE") - } - - for _, r := range resp.Responses { - fmt.Println("") - switch v := r.Response.(type) { - case *pb.ResponseOp_ResponseDeleteRange: - s.Del((v3.DeleteResponse)(*v.ResponseDeleteRange)) - case *pb.ResponseOp_ResponsePut: - s.Put((v3.PutResponse)(*v.ResponsePut)) - case *pb.ResponseOp_ResponseRange: - s.Get(((v3.GetResponse)(*v.ResponseRange))) - default: - fmt.Printf("unexpected response %+v\n", r) - } - } -} - -func (s *simplePrinter) Watch(resp v3.WatchResponse) { - for _, e := range resp.Events { - fmt.Println(e.Type) - if e.PrevKv != nil { - printKV(s.isHex, s.valueOnly, e.PrevKv) - } - printKV(s.isHex, s.valueOnly, e.Kv) - } -} - -func (s *simplePrinter) Grant(resp v3.LeaseGrantResponse) { - fmt.Printf("lease %016x granted with TTL(%ds)\n", resp.ID, resp.TTL) -} - -func (p *simplePrinter) Revoke(id v3.LeaseID, r v3.LeaseRevokeResponse) { - fmt.Printf("lease %016x revoked\n", id) -} - -func (p *simplePrinter) KeepAlive(resp v3.LeaseKeepAliveResponse) { - fmt.Printf("lease %016x keepalived with TTL(%d)\n", resp.ID, resp.TTL) -} - -func (s *simplePrinter) TimeToLive(resp v3.LeaseTimeToLiveResponse, keys bool) { - if resp.GrantedTTL == 0 && resp.TTL == -1 { - fmt.Printf("lease %016x already expired\n", resp.ID) - return - } - - txt := fmt.Sprintf("lease %016x granted with TTL(%ds), remaining(%ds)", resp.ID, resp.GrantedTTL, resp.TTL) - if keys { - ks := make([]string, len(resp.Keys)) - for i := range resp.Keys { - ks[i] = string(resp.Keys[i]) - } - txt += fmt.Sprintf(", attached keys(%v)", ks) - } - fmt.Println(txt) -} - -func (s *simplePrinter) Leases(resp v3.LeaseLeasesResponse) { - fmt.Printf("found %d leases\n", len(resp.Leases)) - for _, item := range resp.Leases { - fmt.Printf("%016x\n", item.ID) - } -} - -func (s *simplePrinter) Alarm(resp v3.AlarmResponse) { - for _, e := range resp.Alarms { - fmt.Printf("%+v\n", e) - } -} - -func (s *simplePrinter) MemberAdd(r v3.MemberAddResponse) { - fmt.Printf("Member %16x added to cluster %16x\n", r.Member.ID, r.Header.ClusterId) -} - -func (s *simplePrinter) MemberRemove(id uint64, r v3.MemberRemoveResponse) { - fmt.Printf("Member %16x removed from cluster %16x\n", id, r.Header.ClusterId) -} - -func (s *simplePrinter) MemberUpdate(id uint64, r v3.MemberUpdateResponse) { - fmt.Printf("Member %16x updated in cluster %16x\n", id, r.Header.ClusterId) -} - -func (s *simplePrinter) MemberList(resp v3.MemberListResponse) { - _, rows := makeMemberListTable(resp) - for _, row := range rows { - fmt.Println(strings.Join(row, ", ")) - } -} - -func (s *simplePrinter) EndpointStatus(statusList []epStatus) { - _, rows := makeEndpointStatusTable(statusList) - for _, row := range rows { - fmt.Println(strings.Join(row, ", ")) - } -} - -func (s *simplePrinter) EndpointHashKV(hashList []epHashKV) { - _, rows := makeEndpointHashKVTable(hashList) - for _, row := range rows { - fmt.Println(strings.Join(row, ", ")) - } -} - -func (s *simplePrinter) DBStatus(ds dbstatus) { - _, rows := makeDBStatusTable(ds) - for _, row := range rows { - fmt.Println(strings.Join(row, ", ")) - } -} - -func (s *simplePrinter) MoveLeader(leader, target uint64, r v3.MoveLeaderResponse) { - fmt.Printf("Leadership transferred from %s to %s\n", types.ID(leader), types.ID(target)) -} - -func (s *simplePrinter) RoleAdd(role string, r v3.AuthRoleAddResponse) { - fmt.Printf("Role %s created\n", role) -} - -func (s *simplePrinter) RoleGet(role string, r v3.AuthRoleGetResponse) { - fmt.Printf("Role %s\n", role) - fmt.Println("KV Read:") - - printRange := func(perm *v3.Permission) { - sKey := string(perm.Key) - sRangeEnd := string(perm.RangeEnd) - if strings.Compare(sRangeEnd, "\x00") != 0 { - fmt.Printf("\t[%s, %s)", sKey, sRangeEnd) - } else { - fmt.Printf("\t[%s, ", sKey) - } - if strings.Compare(v3.GetPrefixRangeEnd(sKey), sRangeEnd) == 0 { - fmt.Printf(" (prefix %s)", sKey) - } - fmt.Printf("\n") - } - - for _, perm := range r.Perm { - if perm.PermType == v3.PermRead || perm.PermType == v3.PermReadWrite { - if len(perm.RangeEnd) == 0 { - fmt.Printf("\t%s\n", string(perm.Key)) - } else { - printRange((*v3.Permission)(perm)) - } - } - } - fmt.Println("KV Write:") - for _, perm := range r.Perm { - if perm.PermType == v3.PermWrite || perm.PermType == v3.PermReadWrite { - if len(perm.RangeEnd) == 0 { - fmt.Printf("\t%s\n", string(perm.Key)) - } else { - printRange((*v3.Permission)(perm)) - } - } - } -} - -func (s *simplePrinter) RoleList(r v3.AuthRoleListResponse) { - for _, role := range r.Roles { - fmt.Printf("%s\n", role) - } -} - -func (s *simplePrinter) RoleDelete(role string, r v3.AuthRoleDeleteResponse) { - fmt.Printf("Role %s deleted\n", role) -} - -func (s *simplePrinter) RoleGrantPermission(role string, r v3.AuthRoleGrantPermissionResponse) { - fmt.Printf("Role %s updated\n", role) -} - -func (s *simplePrinter) RoleRevokePermission(role string, key string, end string, r v3.AuthRoleRevokePermissionResponse) { - if len(end) == 0 { - fmt.Printf("Permission of key %s is revoked from role %s\n", key, role) - return - } - if strings.Compare(end, "\x00") != 0 { - fmt.Printf("Permission of range [%s, %s) is revoked from role %s\n", key, end, role) - } else { - fmt.Printf("Permission of range [%s, is revoked from role %s\n", key, role) - } -} - -func (s *simplePrinter) UserAdd(name string, r v3.AuthUserAddResponse) { - fmt.Printf("User %s created\n", name) -} - -func (s *simplePrinter) UserGet(name string, r v3.AuthUserGetResponse) { - fmt.Printf("User: %s\n", name) - fmt.Printf("Roles:") - for _, role := range r.Roles { - fmt.Printf(" %s", role) - } - fmt.Printf("\n") -} - -func (s *simplePrinter) UserChangePassword(v3.AuthUserChangePasswordResponse) { - fmt.Println("Password updated") -} - -func (s *simplePrinter) UserGrantRole(user string, role string, r v3.AuthUserGrantRoleResponse) { - fmt.Printf("Role %s is granted to user %s\n", role, user) -} - -func (s *simplePrinter) UserRevokeRole(user string, role string, r v3.AuthUserRevokeRoleResponse) { - fmt.Printf("Role %s is revoked from user %s\n", role, user) -} - -func (s *simplePrinter) UserDelete(user string, r v3.AuthUserDeleteResponse) { - fmt.Printf("User %s deleted\n", user) -} - -func (s *simplePrinter) UserList(r v3.AuthUserListResponse) { - for _, user := range r.Users { - fmt.Printf("%s\n", user) - } -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_table.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_table.go deleted file mode 100644 index 1aea61a8456f..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/printer_table.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "os" - - "github.com/olekukonko/tablewriter" - - v3 "github.com/coreos/etcd/clientv3" -) - -type tablePrinter struct{ printer } - -func (tp *tablePrinter) MemberList(r v3.MemberListResponse) { - hdr, rows := makeMemberListTable(r) - table := tablewriter.NewWriter(os.Stdout) - table.SetHeader(hdr) - for _, row := range rows { - table.Append(row) - } - table.SetAlignment(tablewriter.ALIGN_RIGHT) - table.Render() -} -func (tp *tablePrinter) EndpointStatus(r []epStatus) { - hdr, rows := makeEndpointStatusTable(r) - table := tablewriter.NewWriter(os.Stdout) - table.SetHeader(hdr) - for _, row := range rows { - table.Append(row) - } - table.SetAlignment(tablewriter.ALIGN_RIGHT) - table.Render() -} -func (tp *tablePrinter) EndpointHashKV(r []epHashKV) { - hdr, rows := makeEndpointHashKVTable(r) - table := tablewriter.NewWriter(os.Stdout) - table.SetHeader(hdr) - for _, row := range rows { - table.Append(row) - } - table.SetAlignment(tablewriter.ALIGN_RIGHT) - table.Render() -} -func (tp *tablePrinter) DBStatus(r dbstatus) { - hdr, rows := makeDBStatusTable(r) - table := tablewriter.NewWriter(os.Stdout) - table.SetHeader(hdr) - for _, row := range rows { - table.Append(row) - } - table.SetAlignment(tablewriter.ALIGN_RIGHT) - table.Render() -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/put_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/put_command.go deleted file mode 100644 index a72f0c4dcf57..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/put_command.go +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "os" - "strconv" - - "github.com/coreos/etcd/clientv3" - "github.com/spf13/cobra" -) - -var ( - leaseStr string - putPrevKV bool - putIgnoreVal bool - putIgnoreLease bool -) - -// NewPutCommand returns the cobra command for "put". -func NewPutCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "put [options] ( can also be given from stdin)", - Short: "Puts the given key into the store", - Long: ` -Puts the given key into the store. - -When begins with '-', is interpreted as a flag. -Insert '--' for workaround: - -$ put -- -$ put -- - -If isn't given as a command line argument and '--ignore-value' is not specified, -this command tries to read the value from standard input. - -If isn't given as a command line argument and '--ignore-lease' is not specified, -this command tries to read the value from standard input. - -For example, -$ cat file | put -will store the content of the file to . -`, - Run: putCommandFunc, - } - cmd.Flags().StringVar(&leaseStr, "lease", "0", "lease ID (in hexadecimal) to attach to the key") - cmd.Flags().BoolVar(&putPrevKV, "prev-kv", false, "return the previous key-value pair before modification") - cmd.Flags().BoolVar(&putIgnoreVal, "ignore-value", false, "updates the key using its current value") - cmd.Flags().BoolVar(&putIgnoreLease, "ignore-lease", false, "updates the key using its current lease") - return cmd -} - -// putCommandFunc executes the "put" command. -func putCommandFunc(cmd *cobra.Command, args []string) { - key, value, opts := getPutOp(cmd, args) - - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).Put(ctx, key, value, opts...) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - display.Put(*resp) -} - -func getPutOp(cmd *cobra.Command, args []string) (string, string, []clientv3.OpOption) { - if len(args) == 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("put command needs 1 argument and input from stdin or 2 arguments.")) - } - - key := args[0] - if putIgnoreVal && len(args) > 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("put command needs only 1 argument when 'ignore-value' is set.")) - } - - var value string - var err error - if !putIgnoreVal { - value, err = argOrStdin(args, os.Stdin, 1) - if err != nil { - ExitWithError(ExitBadArgs, fmt.Errorf("put command needs 1 argument and input from stdin or 2 arguments.")) - } - } - - id, err := strconv.ParseInt(leaseStr, 16, 64) - if err != nil { - ExitWithError(ExitBadArgs, fmt.Errorf("bad lease ID (%v), expecting ID in Hex", err)) - } - - opts := []clientv3.OpOption{} - if id != 0 { - opts = append(opts, clientv3.WithLease(clientv3.LeaseID(id))) - } - if putPrevKV { - opts = append(opts, clientv3.WithPrevKV()) - } - if putIgnoreVal { - opts = append(opts, clientv3.WithIgnoreValue()) - } - if putIgnoreLease { - opts = append(opts, clientv3.WithIgnoreLease()) - } - - return key, value, opts -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/role_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/role_command.go deleted file mode 100644 index 39c52d313a14..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/role_command.go +++ /dev/null @@ -1,244 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "fmt" - - "github.com/coreos/etcd/clientv3" - "github.com/spf13/cobra" -) - -var ( - rolePermPrefix bool - rolePermFromKey bool -) - -// NewRoleCommand returns the cobra command for "role". -func NewRoleCommand() *cobra.Command { - ac := &cobra.Command{ - Use: "role ", - Short: "Role related commands", - } - - ac.AddCommand(newRoleAddCommand()) - ac.AddCommand(newRoleDeleteCommand()) - ac.AddCommand(newRoleGetCommand()) - ac.AddCommand(newRoleListCommand()) - ac.AddCommand(newRoleGrantPermissionCommand()) - ac.AddCommand(newRoleRevokePermissionCommand()) - - return ac -} - -func newRoleAddCommand() *cobra.Command { - return &cobra.Command{ - Use: "add ", - Short: "Adds a new role", - Run: roleAddCommandFunc, - } -} - -func newRoleDeleteCommand() *cobra.Command { - return &cobra.Command{ - Use: "delete ", - Short: "Deletes a role", - Run: roleDeleteCommandFunc, - } -} - -func newRoleGetCommand() *cobra.Command { - return &cobra.Command{ - Use: "get ", - Short: "Gets detailed information of a role", - Run: roleGetCommandFunc, - } -} - -func newRoleListCommand() *cobra.Command { - return &cobra.Command{ - Use: "list", - Short: "Lists all roles", - Run: roleListCommandFunc, - } -} - -func newRoleGrantPermissionCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "grant-permission [options] [endkey]", - Short: "Grants a key to a role", - Run: roleGrantPermissionCommandFunc, - } - - cmd.Flags().BoolVar(&rolePermPrefix, "prefix", false, "grant a prefix permission") - cmd.Flags().BoolVar(&rolePermFromKey, "from-key", false, "grant a permission of keys that are greater than or equal to the given key using byte compare") - - return cmd -} - -func newRoleRevokePermissionCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "revoke-permission [endkey]", - Short: "Revokes a key from a role", - Run: roleRevokePermissionCommandFunc, - } - - cmd.Flags().BoolVar(&rolePermPrefix, "prefix", false, "revoke a prefix permission") - cmd.Flags().BoolVar(&rolePermFromKey, "from-key", false, "revoke a permission of keys that are greater than or equal to the given key using byte compare") - - return cmd -} - -// roleAddCommandFunc executes the "role add" command. -func roleAddCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("role add command requires role name as its argument.")) - } - - resp, err := mustClientFromCmd(cmd).Auth.RoleAdd(context.TODO(), args[0]) - if err != nil { - ExitWithError(ExitError, err) - } - - display.RoleAdd(args[0], *resp) -} - -// roleDeleteCommandFunc executes the "role delete" command. -func roleDeleteCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("role delete command requires role name as its argument.")) - } - - resp, err := mustClientFromCmd(cmd).Auth.RoleDelete(context.TODO(), args[0]) - if err != nil { - ExitWithError(ExitError, err) - } - - display.RoleDelete(args[0], *resp) -} - -// roleGetCommandFunc executes the "role get" command. -func roleGetCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("role get command requires role name as its argument.")) - } - - name := args[0] - resp, err := mustClientFromCmd(cmd).Auth.RoleGet(context.TODO(), name) - if err != nil { - ExitWithError(ExitError, err) - } - - display.RoleGet(name, *resp) -} - -// roleListCommandFunc executes the "role list" command. -func roleListCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("role list command requires no arguments.")) - } - - resp, err := mustClientFromCmd(cmd).Auth.RoleList(context.TODO()) - if err != nil { - ExitWithError(ExitError, err) - } - - display.RoleList(*resp) -} - -// roleGrantPermissionCommandFunc executes the "role grant-permission" command. -func roleGrantPermissionCommandFunc(cmd *cobra.Command, args []string) { - if len(args) < 3 { - ExitWithError(ExitBadArgs, fmt.Errorf("role grant command requires role name, permission type, and key [endkey] as its argument.")) - } - - perm, err := clientv3.StrToPermissionType(args[1]) - if err != nil { - ExitWithError(ExitBadArgs, err) - } - - key, rangeEnd := permRange(args[2:]) - resp, err := mustClientFromCmd(cmd).Auth.RoleGrantPermission(context.TODO(), args[0], key, rangeEnd, perm) - if err != nil { - ExitWithError(ExitError, err) - } - - display.RoleGrantPermission(args[0], *resp) -} - -// roleRevokePermissionCommandFunc executes the "role revoke-permission" command. -func roleRevokePermissionCommandFunc(cmd *cobra.Command, args []string) { - if len(args) < 2 { - ExitWithError(ExitBadArgs, fmt.Errorf("role revoke-permission command requires role name and key [endkey] as its argument.")) - } - - key, rangeEnd := permRange(args[1:]) - resp, err := mustClientFromCmd(cmd).Auth.RoleRevokePermission(context.TODO(), args[0], key, rangeEnd) - if err != nil { - ExitWithError(ExitError, err) - } - display.RoleRevokePermission(args[0], args[1], rangeEnd, *resp) -} - -func permRange(args []string) (string, string) { - key := args[0] - var rangeEnd string - if len(key) == 0 { - if rolePermPrefix && rolePermFromKey { - ExitWithError(ExitBadArgs, fmt.Errorf("--from-key and --prefix flags are mutually exclusive")) - } - - // Range permission is expressed as adt.BytesAffineInterval, - // so the empty prefix which should be matched with every key must be like this ["\x00", ). - key = "\x00" - if rolePermPrefix || rolePermFromKey { - // For the both cases of prefix and from-key, a permission with an empty key - // should allow access to the entire key space. - // 0x00 will be treated as open ended in server side. - rangeEnd = "\x00" - } - } else { - var err error - rangeEnd, err = rangeEndFromPermFlags(args[0:]) - if err != nil { - ExitWithError(ExitBadArgs, err) - } - } - return key, rangeEnd -} - -func rangeEndFromPermFlags(args []string) (string, error) { - if len(args) == 1 { - if rolePermPrefix { - if rolePermFromKey { - return "", fmt.Errorf("--from-key and --prefix flags are mutually exclusive") - } - return clientv3.GetPrefixRangeEnd(args[0]), nil - } - if rolePermFromKey { - return "\x00", nil - } - // single key case - return "", nil - } - if rolePermPrefix { - return "", fmt.Errorf("unexpected endkey argument with --prefix flag") - } - if rolePermFromKey { - return "", fmt.Errorf("unexpected endkey argument with --from-key flag") - } - return args[1], nil -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/snapshot_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/snapshot_command.go deleted file mode 100644 index 297c9c0b93c2..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/snapshot_command.go +++ /dev/null @@ -1,475 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "crypto/sha256" - "encoding/binary" - "encoding/json" - "fmt" - "hash/crc32" - "io" - "math" - "os" - "path/filepath" - "reflect" - "strings" - - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/pkg/fileutil" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/snap" - "github.com/coreos/etcd/store" - "github.com/coreos/etcd/wal" - "github.com/coreos/etcd/wal/walpb" - - bolt "github.com/coreos/bbolt" - "github.com/spf13/cobra" -) - -const ( - defaultName = "default" - defaultInitialAdvertisePeerURLs = "http://localhost:2380" -) - -var ( - restoreCluster string - restoreClusterToken string - restoreDataDir string - restoreWalDir string - restorePeerURLs string - restoreName string - skipHashCheck bool -) - -// NewSnapshotCommand returns the cobra command for "snapshot". -func NewSnapshotCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "snapshot ", - Short: "Manages etcd node snapshots", - } - cmd.AddCommand(NewSnapshotSaveCommand()) - cmd.AddCommand(NewSnapshotRestoreCommand()) - cmd.AddCommand(newSnapshotStatusCommand()) - return cmd -} - -func NewSnapshotSaveCommand() *cobra.Command { - return &cobra.Command{ - Use: "save ", - Short: "Stores an etcd node backend snapshot to a given file", - Run: snapshotSaveCommandFunc, - } -} - -func newSnapshotStatusCommand() *cobra.Command { - return &cobra.Command{ - Use: "status ", - Short: "Gets backend snapshot status of a given file", - Long: `When --write-out is set to simple, this command prints out comma-separated status lists for each endpoint. -The items in the lists are hash, revision, total keys, total size. -`, - Run: snapshotStatusCommandFunc, - } -} - -func NewSnapshotRestoreCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "restore [options]", - Short: "Restores an etcd member snapshot to an etcd directory", - Run: snapshotRestoreCommandFunc, - } - cmd.Flags().StringVar(&restoreDataDir, "data-dir", "", "Path to the data directory") - cmd.Flags().StringVar(&restoreWalDir, "wal-dir", "", "Path to the WAL directory (use --data-dir if none given)") - cmd.Flags().StringVar(&restoreCluster, "initial-cluster", initialClusterFromName(defaultName), "Initial cluster configuration for restore bootstrap") - cmd.Flags().StringVar(&restoreClusterToken, "initial-cluster-token", "etcd-cluster", "Initial cluster token for the etcd cluster during restore bootstrap") - cmd.Flags().StringVar(&restorePeerURLs, "initial-advertise-peer-urls", defaultInitialAdvertisePeerURLs, "List of this member's peer URLs to advertise to the rest of the cluster") - cmd.Flags().StringVar(&restoreName, "name", defaultName, "Human-readable name for this member") - cmd.Flags().BoolVar(&skipHashCheck, "skip-hash-check", false, "Ignore snapshot integrity hash value (required if copied from data directory)") - - return cmd -} - -func snapshotSaveCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - err := fmt.Errorf("snapshot save expects one argument") - ExitWithError(ExitBadArgs, err) - } - - path := args[0] - - partpath := path + ".part" - f, err := os.Create(partpath) - - if err != nil { - exiterr := fmt.Errorf("could not open %s (%v)", partpath, err) - ExitWithError(ExitBadArgs, exiterr) - } - - c := mustClientFromCmd(cmd) - r, serr := c.Snapshot(context.TODO()) - if serr != nil { - os.RemoveAll(partpath) - ExitWithError(ExitInterrupted, serr) - } - if _, rerr := io.Copy(f, r); rerr != nil { - os.RemoveAll(partpath) - ExitWithError(ExitInterrupted, rerr) - } - - fileutil.Fsync(f) - - f.Close() - - if rerr := os.Rename(partpath, path); rerr != nil { - exiterr := fmt.Errorf("could not rename %s to %s (%v)", partpath, path, rerr) - ExitWithError(ExitIO, exiterr) - } - fmt.Printf("Snapshot saved at %s\n", path) -} - -func snapshotStatusCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - err := fmt.Errorf("snapshot status requires exactly one argument") - ExitWithError(ExitBadArgs, err) - } - initDisplayFromCmd(cmd) - ds := dbStatus(args[0]) - display.DBStatus(ds) -} - -func snapshotRestoreCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - err := fmt.Errorf("snapshot restore requires exactly one argument") - ExitWithError(ExitBadArgs, err) - } - - urlmap, uerr := types.NewURLsMap(restoreCluster) - if uerr != nil { - ExitWithError(ExitBadArgs, uerr) - } - - cfg := etcdserver.ServerConfig{ - InitialClusterToken: restoreClusterToken, - InitialPeerURLsMap: urlmap, - PeerURLs: types.MustNewURLs(strings.Split(restorePeerURLs, ",")), - Name: restoreName, - } - if err := cfg.VerifyBootstrap(); err != nil { - ExitWithError(ExitBadArgs, err) - } - - cl, cerr := membership.NewClusterFromURLsMap(restoreClusterToken, urlmap) - if cerr != nil { - ExitWithError(ExitBadArgs, cerr) - } - - basedir := restoreDataDir - if basedir == "" { - basedir = restoreName + ".etcd" - } - - waldir := restoreWalDir - if waldir == "" { - waldir = filepath.Join(basedir, "member", "wal") - } - snapdir := filepath.Join(basedir, "member", "snap") - - if _, err := os.Stat(basedir); err == nil { - ExitWithError(ExitInvalidInput, fmt.Errorf("data-dir %q exists", basedir)) - } - - makeDB(snapdir, args[0], len(cl.Members())) - makeWALAndSnap(waldir, snapdir, cl) -} - -func initialClusterFromName(name string) string { - n := name - if name == "" { - n = defaultName - } - return fmt.Sprintf("%s=http://localhost:2380", n) -} - -// makeWAL creates a WAL for the initial cluster -func makeWALAndSnap(waldir, snapdir string, cl *membership.RaftCluster) { - if err := fileutil.CreateDirAll(waldir); err != nil { - ExitWithError(ExitIO, err) - } - - // add members again to persist them to the store we create. - st := store.New(etcdserver.StoreClusterPrefix, etcdserver.StoreKeysPrefix) - cl.SetStore(st) - for _, m := range cl.Members() { - cl.AddMember(m) - } - - m := cl.MemberByName(restoreName) - md := &etcdserverpb.Metadata{NodeID: uint64(m.ID), ClusterID: uint64(cl.ID())} - metadata, merr := md.Marshal() - if merr != nil { - ExitWithError(ExitInvalidInput, merr) - } - - w, walerr := wal.Create(waldir, metadata) - if walerr != nil { - ExitWithError(ExitIO, walerr) - } - defer w.Close() - - peers := make([]raft.Peer, len(cl.MemberIDs())) - for i, id := range cl.MemberIDs() { - ctx, err := json.Marshal((*cl).Member(id)) - if err != nil { - ExitWithError(ExitInvalidInput, err) - } - peers[i] = raft.Peer{ID: uint64(id), Context: ctx} - } - - ents := make([]raftpb.Entry, len(peers)) - nodeIDs := make([]uint64, len(peers)) - for i, p := range peers { - nodeIDs[i] = p.ID - cc := raftpb.ConfChange{ - Type: raftpb.ConfChangeAddNode, - NodeID: p.ID, - Context: p.Context} - d, err := cc.Marshal() - if err != nil { - ExitWithError(ExitInvalidInput, err) - } - e := raftpb.Entry{ - Type: raftpb.EntryConfChange, - Term: 1, - Index: uint64(i + 1), - Data: d, - } - ents[i] = e - } - - commit, term := uint64(len(ents)), uint64(1) - - if err := w.Save(raftpb.HardState{ - Term: term, - Vote: peers[0].ID, - Commit: commit}, ents); err != nil { - ExitWithError(ExitIO, err) - } - - b, berr := st.Save() - if berr != nil { - ExitWithError(ExitError, berr) - } - - raftSnap := raftpb.Snapshot{ - Data: b, - Metadata: raftpb.SnapshotMetadata{ - Index: commit, - Term: term, - ConfState: raftpb.ConfState{ - Nodes: nodeIDs, - }, - }, - } - snapshotter := snap.New(snapdir) - if err := snapshotter.SaveSnap(raftSnap); err != nil { - panic(err) - } - - if err := w.SaveSnapshot(walpb.Snapshot{Index: commit, Term: term}); err != nil { - ExitWithError(ExitIO, err) - } -} - -// initIndex implements ConsistentIndexGetter so the snapshot won't block -// the new raft instance by waiting for a future raft index. -type initIndex int - -func (i *initIndex) ConsistentIndex() uint64 { return uint64(*i) } - -// makeDB copies the database snapshot to the snapshot directory -func makeDB(snapdir, dbfile string, commit int) { - f, ferr := os.OpenFile(dbfile, os.O_RDONLY, 0600) - if ferr != nil { - ExitWithError(ExitInvalidInput, ferr) - } - defer f.Close() - - // get snapshot integrity hash - if _, err := f.Seek(-sha256.Size, io.SeekEnd); err != nil { - ExitWithError(ExitIO, err) - } - sha := make([]byte, sha256.Size) - if _, err := f.Read(sha); err != nil { - ExitWithError(ExitIO, err) - } - if _, err := f.Seek(0, io.SeekStart); err != nil { - ExitWithError(ExitIO, err) - } - - if err := fileutil.CreateDirAll(snapdir); err != nil { - ExitWithError(ExitIO, err) - } - - dbpath := filepath.Join(snapdir, "db") - db, dberr := os.OpenFile(dbpath, os.O_RDWR|os.O_CREATE, 0600) - if dberr != nil { - ExitWithError(ExitIO, dberr) - } - if _, err := io.Copy(db, f); err != nil { - ExitWithError(ExitIO, err) - } - - // truncate away integrity hash, if any. - off, serr := db.Seek(0, io.SeekEnd) - if serr != nil { - ExitWithError(ExitIO, serr) - } - hasHash := (off % 512) == sha256.Size - if hasHash { - if err := db.Truncate(off - sha256.Size); err != nil { - ExitWithError(ExitIO, err) - } - } - - if !hasHash && !skipHashCheck { - err := fmt.Errorf("snapshot missing hash but --skip-hash-check=false") - ExitWithError(ExitBadArgs, err) - } - - if hasHash && !skipHashCheck { - // check for match - if _, err := db.Seek(0, io.SeekStart); err != nil { - ExitWithError(ExitIO, err) - } - h := sha256.New() - if _, err := io.Copy(h, db); err != nil { - ExitWithError(ExitIO, err) - } - dbsha := h.Sum(nil) - if !reflect.DeepEqual(sha, dbsha) { - err := fmt.Errorf("expected sha256 %v, got %v", sha, dbsha) - ExitWithError(ExitInvalidInput, err) - } - } - - // db hash is OK, can now modify DB so it can be part of a new cluster - db.Close() - - // update consistentIndex so applies go through on etcdserver despite - // having a new raft instance - be := backend.NewDefaultBackend(dbpath) - // a lessor never timeouts leases - lessor := lease.NewLessor(be, math.MaxInt64) - s := mvcc.NewStore(be, lessor, (*initIndex)(&commit)) - txn := s.Write() - btx := be.BatchTx() - del := func(k, v []byte) error { - txn.DeleteRange(k, nil) - return nil - } - - // delete stored members from old cluster since using new members - btx.UnsafeForEach([]byte("members"), del) - // todo: add back new members when we start to deprecate old snap file. - btx.UnsafeForEach([]byte("members_removed"), del) - // trigger write-out of new consistent index - txn.End() - s.Commit() - s.Close() - be.Close() -} - -type dbstatus struct { - Hash uint32 `json:"hash"` - Revision int64 `json:"revision"` - TotalKey int `json:"totalKey"` - TotalSize int64 `json:"totalSize"` -} - -func dbStatus(p string) dbstatus { - if _, err := os.Stat(p); err != nil { - ExitWithError(ExitError, err) - } - - ds := dbstatus{} - - db, err := bolt.Open(p, 0400, &bolt.Options{ReadOnly: true}) - if err != nil { - ExitWithError(ExitError, err) - } - defer db.Close() - - h := crc32.New(crc32.MakeTable(crc32.Castagnoli)) - - err = db.View(func(tx *bolt.Tx) error { - // check snapshot file integrity first - var dbErrStrings []string - for dbErr := range tx.Check() { - dbErrStrings = append(dbErrStrings, dbErr.Error()) - } - if len(dbErrStrings) > 0 { - return fmt.Errorf("snapshot file integrity check failed. %d errors found.\n"+strings.Join(dbErrStrings, "\n"), len(dbErrStrings)) - } - ds.TotalSize = tx.Size() - c := tx.Cursor() - for next, _ := c.First(); next != nil; next, _ = c.Next() { - b := tx.Bucket(next) - if b == nil { - return fmt.Errorf("cannot get hash of bucket %s", string(next)) - } - h.Write(next) - iskeyb := (string(next) == "key") - b.ForEach(func(k, v []byte) error { - h.Write(k) - h.Write(v) - if iskeyb { - rev := bytesToRev(k) - ds.Revision = rev.main - } - ds.TotalKey++ - return nil - }) - } - return nil - }) - - if err != nil { - ExitWithError(ExitError, err) - } - - ds.Hash = h.Sum32() - return ds -} - -type revision struct { - main int64 - sub int64 -} - -func bytesToRev(bytes []byte) revision { - return revision{ - main: int64(binary.BigEndian.Uint64(bytes[0:8])), - sub: int64(binary.BigEndian.Uint64(bytes[9:])), - } -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/txn_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/txn_command.go deleted file mode 100644 index eec1e0916c30..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/txn_command.go +++ /dev/null @@ -1,209 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "bufio" - "context" - "fmt" - "os" - "strconv" - "strings" - - "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "github.com/spf13/cobra" -) - -var ( - txnInteractive bool -) - -// NewTxnCommand returns the cobra command for "txn". -func NewTxnCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "txn [options]", - Short: "Txn processes all the requests in one transaction", - Run: txnCommandFunc, - } - cmd.Flags().BoolVarP(&txnInteractive, "interactive", "i", false, "Input transaction in interactive mode") - return cmd -} - -// txnCommandFunc executes the "txn" command. -func txnCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("txn command does not accept argument.")) - } - - reader := bufio.NewReader(os.Stdin) - - txn := mustClientFromCmd(cmd).Txn(context.Background()) - promptInteractive("compares:") - txn.If(readCompares(reader)...) - promptInteractive("success requests (get, put, del):") - txn.Then(readOps(reader)...) - promptInteractive("failure requests (get, put, del):") - txn.Else(readOps(reader)...) - - resp, err := txn.Commit() - if err != nil { - ExitWithError(ExitError, err) - } - - display.Txn(*resp) -} - -func promptInteractive(s string) { - if txnInteractive { - fmt.Println(s) - } -} - -func readCompares(r *bufio.Reader) (cmps []clientv3.Cmp) { - for { - line, err := r.ReadString('\n') - if err != nil { - ExitWithError(ExitInvalidInput, err) - } - - // remove space from the line - line = strings.TrimSpace(line) - if len(line) == 0 { - break - } - - cmp, err := parseCompare(line) - if err != nil { - ExitWithError(ExitInvalidInput, err) - } - cmps = append(cmps, *cmp) - } - - return cmps -} - -func readOps(r *bufio.Reader) (ops []clientv3.Op) { - for { - line, err := r.ReadString('\n') - if err != nil { - ExitWithError(ExitInvalidInput, err) - } - - // remove space from the line - line = strings.TrimSpace(line) - if len(line) == 0 { - break - } - - op, err := parseRequestUnion(line) - if err != nil { - ExitWithError(ExitInvalidInput, err) - } - ops = append(ops, *op) - } - - return ops -} - -func parseRequestUnion(line string) (*clientv3.Op, error) { - args := argify(line) - if len(args) < 2 { - return nil, fmt.Errorf("invalid txn compare request: %s", line) - } - - opc := make(chan clientv3.Op, 1) - - put := NewPutCommand() - put.Run = func(cmd *cobra.Command, args []string) { - key, value, opts := getPutOp(cmd, args) - opc <- clientv3.OpPut(key, value, opts...) - } - get := NewGetCommand() - get.Run = func(cmd *cobra.Command, args []string) { - key, opts := getGetOp(cmd, args) - opc <- clientv3.OpGet(key, opts...) - } - del := NewDelCommand() - del.Run = func(cmd *cobra.Command, args []string) { - key, opts := getDelOp(cmd, args) - opc <- clientv3.OpDelete(key, opts...) - } - cmds := &cobra.Command{SilenceErrors: true} - cmds.AddCommand(put, get, del) - - cmds.SetArgs(args) - if err := cmds.Execute(); err != nil { - return nil, fmt.Errorf("invalid txn request: %s", line) - } - - op := <-opc - return &op, nil -} - -func parseCompare(line string) (*clientv3.Cmp, error) { - var ( - key string - op string - val string - ) - - lparenSplit := strings.SplitN(line, "(", 2) - if len(lparenSplit) != 2 { - return nil, fmt.Errorf("malformed comparison: %s", line) - } - - target := lparenSplit[0] - n, serr := fmt.Sscanf(lparenSplit[1], "%q) %s %q", &key, &op, &val) - if n != 3 { - return nil, fmt.Errorf("malformed comparison: %s; got %s(%q) %s %q", line, target, key, op, val) - } - if serr != nil { - return nil, fmt.Errorf("malformed comparison: %s (%v)", line, serr) - } - - var ( - v int64 - err error - cmp clientv3.Cmp - ) - switch target { - case "ver", "version": - if v, err = strconv.ParseInt(val, 10, 64); err == nil { - cmp = clientv3.Compare(clientv3.Version(key), op, v) - } - case "c", "create": - if v, err = strconv.ParseInt(val, 10, 64); err == nil { - cmp = clientv3.Compare(clientv3.CreateRevision(key), op, v) - } - case "m", "mod": - if v, err = strconv.ParseInt(val, 10, 64); err == nil { - cmp = clientv3.Compare(clientv3.ModRevision(key), op, v) - } - case "val", "value": - cmp = clientv3.Compare(clientv3.Value(key), op, val) - case "lease": - cmp = clientv3.Compare(clientv3.Cmp{Target: pb.Compare_LEASE}, op, val) - default: - return nil, fmt.Errorf("malformed comparison: %s (unknown target %s)", line, target) - } - - if err != nil { - return nil, fmt.Errorf("invalid txn compare request: %s", line) - } - - return &cmp, nil -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/user_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/user_command.go deleted file mode 100644 index 4df56f720a19..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/user_command.go +++ /dev/null @@ -1,280 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "fmt" - "strings" - - "github.com/bgentry/speakeasy" - "github.com/spf13/cobra" -) - -var ( - userShowDetail bool -) - -// NewUserCommand returns the cobra command for "user". -func NewUserCommand() *cobra.Command { - ac := &cobra.Command{ - Use: "user ", - Short: "User related commands", - } - - ac.AddCommand(newUserAddCommand()) - ac.AddCommand(newUserDeleteCommand()) - ac.AddCommand(newUserGetCommand()) - ac.AddCommand(newUserListCommand()) - ac.AddCommand(newUserChangePasswordCommand()) - ac.AddCommand(newUserGrantRoleCommand()) - ac.AddCommand(newUserRevokeRoleCommand()) - - return ac -} - -var ( - passwordInteractive bool -) - -func newUserAddCommand() *cobra.Command { - cmd := cobra.Command{ - Use: "add [options]", - Short: "Adds a new user", - Run: userAddCommandFunc, - } - - cmd.Flags().BoolVar(&passwordInteractive, "interactive", true, "Read password from stdin instead of interactive terminal") - - return &cmd -} - -func newUserDeleteCommand() *cobra.Command { - return &cobra.Command{ - Use: "delete ", - Short: "Deletes a user", - Run: userDeleteCommandFunc, - } -} - -func newUserGetCommand() *cobra.Command { - cmd := cobra.Command{ - Use: "get [options]", - Short: "Gets detailed information of a user", - Run: userGetCommandFunc, - } - - cmd.Flags().BoolVar(&userShowDetail, "detail", false, "Show permissions of roles granted to the user") - - return &cmd -} - -func newUserListCommand() *cobra.Command { - return &cobra.Command{ - Use: "list", - Short: "Lists all users", - Run: userListCommandFunc, - } -} - -func newUserChangePasswordCommand() *cobra.Command { - cmd := cobra.Command{ - Use: "passwd [options]", - Short: "Changes password of user", - Run: userChangePasswordCommandFunc, - } - - cmd.Flags().BoolVar(&passwordInteractive, "interactive", true, "If true, read password from stdin instead of interactive terminal") - - return &cmd -} - -func newUserGrantRoleCommand() *cobra.Command { - return &cobra.Command{ - Use: "grant-role ", - Short: "Grants a role to a user", - Run: userGrantRoleCommandFunc, - } -} - -func newUserRevokeRoleCommand() *cobra.Command { - return &cobra.Command{ - Use: "revoke-role ", - Short: "Revokes a role from a user", - Run: userRevokeRoleCommandFunc, - } -} - -// userAddCommandFunc executes the "user add" command. -func userAddCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("user add command requires user name as its argument.")) - } - - var password string - var user string - - splitted := strings.SplitN(args[0], ":", 2) - if len(splitted) < 2 { - user = args[0] - if !passwordInteractive { - fmt.Scanf("%s", &password) - } else { - password = readPasswordInteractive(args[0]) - } - } else { - user = splitted[0] - password = splitted[1] - if len(user) == 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("empty user name is not allowed.")) - } - } - - resp, err := mustClientFromCmd(cmd).Auth.UserAdd(context.TODO(), user, password) - if err != nil { - ExitWithError(ExitError, err) - } - - display.UserAdd(user, *resp) -} - -// userDeleteCommandFunc executes the "user delete" command. -func userDeleteCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("user delete command requires user name as its argument.")) - } - - resp, err := mustClientFromCmd(cmd).Auth.UserDelete(context.TODO(), args[0]) - if err != nil { - ExitWithError(ExitError, err) - } - display.UserDelete(args[0], *resp) -} - -// userGetCommandFunc executes the "user get" command. -func userGetCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("user get command requires user name as its argument.")) - } - - name := args[0] - client := mustClientFromCmd(cmd) - resp, err := client.Auth.UserGet(context.TODO(), name) - if err != nil { - ExitWithError(ExitError, err) - } - - if userShowDetail { - fmt.Printf("User: %s\n", name) - for _, role := range resp.Roles { - fmt.Printf("\n") - roleResp, err := client.Auth.RoleGet(context.TODO(), role) - if err != nil { - ExitWithError(ExitError, err) - } - display.RoleGet(role, *roleResp) - } - } else { - display.UserGet(name, *resp) - } -} - -// userListCommandFunc executes the "user list" command. -func userListCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("user list command requires no arguments.")) - } - - resp, err := mustClientFromCmd(cmd).Auth.UserList(context.TODO()) - if err != nil { - ExitWithError(ExitError, err) - } - - display.UserList(*resp) -} - -// userChangePasswordCommandFunc executes the "user passwd" command. -func userChangePasswordCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("user passwd command requires user name as its argument.")) - } - - var password string - - if !passwordInteractive { - fmt.Scanf("%s", &password) - } else { - password = readPasswordInteractive(args[0]) - } - - resp, err := mustClientFromCmd(cmd).Auth.UserChangePassword(context.TODO(), args[0], password) - if err != nil { - ExitWithError(ExitError, err) - } - - display.UserChangePassword(*resp) -} - -// userGrantRoleCommandFunc executes the "user grant-role" command. -func userGrantRoleCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 2 { - ExitWithError(ExitBadArgs, fmt.Errorf("user grant command requires user name and role name as its argument.")) - } - - resp, err := mustClientFromCmd(cmd).Auth.UserGrantRole(context.TODO(), args[0], args[1]) - if err != nil { - ExitWithError(ExitError, err) - } - - display.UserGrantRole(args[0], args[1], *resp) -} - -// userRevokeRoleCommandFunc executes the "user revoke-role" command. -func userRevokeRoleCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 2 { - ExitWithError(ExitBadArgs, fmt.Errorf("user revoke-role requires user name and role name as its argument.")) - } - - resp, err := mustClientFromCmd(cmd).Auth.UserRevokeRole(context.TODO(), args[0], args[1]) - if err != nil { - ExitWithError(ExitError, err) - } - - display.UserRevokeRole(args[0], args[1], *resp) -} - -func readPasswordInteractive(name string) string { - prompt1 := fmt.Sprintf("Password of %s: ", name) - password1, err1 := speakeasy.Ask(prompt1) - if err1 != nil { - ExitWithError(ExitBadArgs, fmt.Errorf("failed to ask password: %s.", err1)) - } - - if len(password1) == 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("empty password")) - } - - prompt2 := fmt.Sprintf("Type password of %s again for confirmation: ", name) - password2, err2 := speakeasy.Ask(prompt2) - if err2 != nil { - ExitWithError(ExitBadArgs, fmt.Errorf("failed to ask password: %s.", err2)) - } - - if strings.Compare(password1, password2) != 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("given passwords are different.")) - } - - return password1 -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/util.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/util.go deleted file mode 100644 index addd023db08f..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/util.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "encoding/hex" - "fmt" - "regexp" - - pb "github.com/coreos/etcd/mvcc/mvccpb" - - "github.com/spf13/cobra" -) - -func printKV(isHex bool, valueOnly bool, kv *pb.KeyValue) { - k, v := string(kv.Key), string(kv.Value) - if isHex { - k = addHexPrefix(hex.EncodeToString(kv.Key)) - v = addHexPrefix(hex.EncodeToString(kv.Value)) - } - if !valueOnly { - fmt.Println(k) - } - fmt.Println(v) -} - -func addHexPrefix(s string) string { - ns := make([]byte, len(s)*2) - for i := 0; i < len(s); i += 2 { - ns[i*2] = '\\' - ns[i*2+1] = 'x' - ns[i*2+2] = s[i] - ns[i*2+3] = s[i+1] - } - return string(ns) -} - -func argify(s string) []string { - r := regexp.MustCompile(`"(?:[^"\\]|\\.)*"|'[^']*'|[^'"\s]\S*[^'"\s]?`) - args := r.FindAllString(s, -1) - for i := range args { - if len(args[i]) == 0 { - continue - } - if args[i][0] == '\'' { - // 'single-quoted string' - args[i] = args[i][1 : len(args)-1] - } else if args[i][0] == '"' { - // "double quoted string" - if _, err := fmt.Sscanf(args[i], "%q", &args[i]); err != nil { - ExitWithError(ExitInvalidInput, err) - } - } - } - return args -} - -func commandCtx(cmd *cobra.Command) (context.Context, context.CancelFunc) { - timeOut, err := cmd.Flags().GetDuration("command-timeout") - if err != nil { - ExitWithError(ExitError, err) - } - return context.WithTimeout(context.Background(), timeOut) -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/version_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/version_command.go deleted file mode 100644 index 9fa990f1f4c1..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/version_command.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - - "github.com/coreos/etcd/version" - "github.com/spf13/cobra" -) - -// NewVersionCommand prints out the version of etcd. -func NewVersionCommand() *cobra.Command { - return &cobra.Command{ - Use: "version", - Short: "Prints the version of etcdctl", - Run: versionCommandFunc, - } -} - -func versionCommandFunc(cmd *cobra.Command, args []string) { - fmt.Println("etcdctl version:", version.Version) - fmt.Println("API version:", version.APIVersion) -} diff --git a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/watch_command.go b/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/watch_command.go deleted file mode 100644 index 1a2cc4213f5b..000000000000 --- a/vendor/github.com/coreos/etcd/etcdctl/ctlv3/command/watch_command.go +++ /dev/null @@ -1,347 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "bufio" - "context" - "errors" - "fmt" - "os" - "os/exec" - "strings" - - "github.com/coreos/etcd/clientv3" - - "github.com/spf13/cobra" -) - -var ( - errBadArgsNum = errors.New("bad number of arguments") - errBadArgsNumConflictEnv = errors.New("bad number of arguments (found conflicting environment key)") - errBadArgsNumSeparator = errors.New("bad number of arguments (found separator --, but no commands)") - errBadArgsInteractiveWatch = errors.New("args[0] must be 'watch' for interactive calls") -) - -var ( - watchRev int64 - watchPrefix bool - watchInteractive bool - watchPrevKey bool -) - -// NewWatchCommand returns the cobra command for "watch". -func NewWatchCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "watch [options] [key or prefix] [range_end] [--] [exec-command arg1 arg2 ...]", - Short: "Watches events stream on keys or prefixes", - Run: watchCommandFunc, - } - - cmd.Flags().BoolVarP(&watchInteractive, "interactive", "i", false, "Interactive mode") - cmd.Flags().BoolVar(&watchPrefix, "prefix", false, "Watch on a prefix if prefix is set") - cmd.Flags().Int64Var(&watchRev, "rev", 0, "Revision to start watching") - cmd.Flags().BoolVar(&watchPrevKey, "prev-kv", false, "get the previous key-value pair before the event happens") - - return cmd -} - -// watchCommandFunc executes the "watch" command. -func watchCommandFunc(cmd *cobra.Command, args []string) { - envKey, envRange := os.Getenv("ETCDCTL_WATCH_KEY"), os.Getenv("ETCDCTL_WATCH_RANGE_END") - if envKey == "" && envRange != "" { - ExitWithError(ExitBadArgs, fmt.Errorf("ETCDCTL_WATCH_KEY is empty but got ETCDCTL_WATCH_RANGE_END=%q", envRange)) - } - - if watchInteractive { - watchInteractiveFunc(cmd, os.Args, envKey, envRange) - return - } - - watchArgs, execArgs, err := parseWatchArgs(os.Args, args, envKey, envRange, false) - if err != nil { - ExitWithError(ExitBadArgs, err) - } - - c := mustClientFromCmd(cmd) - wc, err := getWatchChan(c, watchArgs) - if err != nil { - ExitWithError(ExitBadArgs, err) - } - - printWatchCh(c, wc, execArgs) - if err = c.Close(); err != nil { - ExitWithError(ExitBadConnection, err) - } - ExitWithError(ExitInterrupted, fmt.Errorf("watch is canceled by the server")) -} - -func watchInteractiveFunc(cmd *cobra.Command, osArgs []string, envKey, envRange string) { - c := mustClientFromCmd(cmd) - - reader := bufio.NewReader(os.Stdin) - - for { - l, err := reader.ReadString('\n') - if err != nil { - ExitWithError(ExitInvalidInput, fmt.Errorf("Error reading watch request line: %v", err)) - } - l = strings.TrimSuffix(l, "\n") - - args := argify(l) - if len(args) < 2 && envKey == "" { - fmt.Fprintf(os.Stderr, "Invalid command %s (command type or key is not provided)\n", l) - continue - } - - if args[0] != "watch" { - fmt.Fprintf(os.Stderr, "Invalid command %s (only support watch)\n", l) - continue - } - - watchArgs, execArgs, perr := parseWatchArgs(osArgs, args, envKey, envRange, true) - if perr != nil { - ExitWithError(ExitBadArgs, perr) - } - - ch, err := getWatchChan(c, watchArgs) - if err != nil { - fmt.Fprintf(os.Stderr, "Invalid command %s (%v)\n", l, err) - continue - } - go printWatchCh(c, ch, execArgs) - } -} - -func getWatchChan(c *clientv3.Client, args []string) (clientv3.WatchChan, error) { - if len(args) < 1 { - return nil, errBadArgsNum - } - - key := args[0] - opts := []clientv3.OpOption{clientv3.WithRev(watchRev)} - if len(args) == 2 { - if watchPrefix { - return nil, fmt.Errorf("`range_end` and `--prefix` are mutually exclusive") - } - opts = append(opts, clientv3.WithRange(args[1])) - } - if watchPrefix { - opts = append(opts, clientv3.WithPrefix()) - } - if watchPrevKey { - opts = append(opts, clientv3.WithPrevKV()) - } - return c.Watch(clientv3.WithRequireLeader(context.Background()), key, opts...), nil -} - -func printWatchCh(c *clientv3.Client, ch clientv3.WatchChan, execArgs []string) { - for resp := range ch { - if resp.Canceled { - fmt.Fprintf(os.Stderr, "watch was canceled (%v)\n", resp.Err()) - } - display.Watch(resp) - - if len(execArgs) > 0 { - for _, ev := range resp.Events { - cmd := exec.CommandContext(c.Ctx(), execArgs[0], execArgs[1:]...) - cmd.Env = os.Environ() - cmd.Env = append(cmd.Env, fmt.Sprintf("ETCD_WATCH_REVISION=%d", resp.Header.Revision)) - cmd.Env = append(cmd.Env, fmt.Sprintf("ETCD_WATCH_EVENT_TYPE=%q", ev.Type)) - cmd.Env = append(cmd.Env, fmt.Sprintf("ETCD_WATCH_KEY=%q", ev.Kv.Key)) - cmd.Env = append(cmd.Env, fmt.Sprintf("ETCD_WATCH_VALUE=%q", ev.Kv.Value)) - cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr - if err := cmd.Run(); err != nil { - fmt.Fprintf(os.Stderr, "command %q error (%v)\n", execArgs, err) - os.Exit(1) - } - } - } - } -} - -// "commandArgs" is the command arguments after "spf13/cobra" parses -// all "watch" command flags, strips out special characters (e.g. "--"). -// "orArgs" is the raw arguments passed to "watch" command -// (e.g. ./bin/etcdctl watch foo --rev 1 bar). -// "--" characters are invalid arguments for "spf13/cobra" library, -// so no need to handle such cases. -func parseWatchArgs(osArgs, commandArgs []string, envKey, envRange string, interactive bool) (watchArgs []string, execArgs []string, err error) { - rawArgs := make([]string, len(osArgs)) - copy(rawArgs, osArgs) - watchArgs = make([]string, len(commandArgs)) - copy(watchArgs, commandArgs) - - // remove preceding commands (e.g. ./bin/etcdctl watch) - // handle "./bin/etcdctl watch foo -- echo watch event" - for idx := range rawArgs { - if rawArgs[idx] == "watch" { - rawArgs = rawArgs[idx+1:] - break - } - } - - // remove preceding commands (e.g. "watch foo bar" in interactive mode) - // handle "./bin/etcdctl watch foo -- echo watch event" - if interactive { - if watchArgs[0] != "watch" { - // "watch" not found - watchPrefix, watchRev, watchPrevKey = false, 0, false - return nil, nil, errBadArgsInteractiveWatch - } - watchArgs = watchArgs[1:] - } - - execIdx, execExist := 0, false - if !interactive { - for execIdx = range rawArgs { - if rawArgs[execIdx] == "--" { - execExist = true - break - } - } - if execExist && execIdx == len(rawArgs)-1 { - // "watch foo bar --" should error - return nil, nil, errBadArgsNumSeparator - } - // "watch" with no argument should error - if !execExist && len(rawArgs) < 1 && envKey == "" { - return nil, nil, errBadArgsNum - } - if execExist && envKey != "" { - // "ETCDCTL_WATCH_KEY=foo watch foo -- echo 1" should error - // (watchArgs==["foo","echo","1"]) - widx, ridx := len(watchArgs)-1, len(rawArgs)-1 - for ; widx >= 0; widx-- { - if watchArgs[widx] == rawArgs[ridx] { - ridx-- - continue - } - // watchArgs has extra: - // ETCDCTL_WATCH_KEY=foo watch foo -- echo 1 - // watchArgs: foo echo 1 - if ridx == execIdx { - return nil, nil, errBadArgsNumConflictEnv - } - } - } - // check conflicting arguments - // e.g. "watch --rev 1 -- echo Hello World" has no conflict - if !execExist && len(watchArgs) > 0 && envKey != "" { - // "ETCDCTL_WATCH_KEY=foo watch foo" should error - // (watchArgs==["foo"]) - return nil, nil, errBadArgsNumConflictEnv - } - } else { - for execIdx = range watchArgs { - if watchArgs[execIdx] == "--" { - execExist = true - break - } - } - if execExist && execIdx == len(watchArgs)-1 { - // "watch foo bar --" should error - watchPrefix, watchRev, watchPrevKey = false, 0, false - return nil, nil, errBadArgsNumSeparator - } - - flagset := NewWatchCommand().Flags() - if err := flagset.Parse(watchArgs); err != nil { - watchPrefix, watchRev, watchPrevKey = false, 0, false - return nil, nil, err - } - pArgs := flagset.Args() - - // "watch" with no argument should error - if !execExist && envKey == "" && len(pArgs) < 1 { - watchPrefix, watchRev, watchPrevKey = false, 0, false - return nil, nil, errBadArgsNum - } - // check conflicting arguments - // e.g. "watch --rev 1 -- echo Hello World" has no conflict - if !execExist && len(pArgs) > 0 && envKey != "" { - // "ETCDCTL_WATCH_KEY=foo watch foo" should error - // (watchArgs==["foo"]) - watchPrefix, watchRev, watchPrevKey = false, 0, false - return nil, nil, errBadArgsNumConflictEnv - } - } - - argsWithSep := rawArgs - if interactive { - // interactive mode directly passes "--" to the command args - argsWithSep = watchArgs - } - - idx, foundSep := 0, false - for idx = range argsWithSep { - if argsWithSep[idx] == "--" { - foundSep = true - break - } - } - if foundSep { - execArgs = argsWithSep[idx+1:] - } - - if interactive { - flagset := NewWatchCommand().Flags() - if err := flagset.Parse(argsWithSep); err != nil { - return nil, nil, err - } - watchArgs = flagset.Args() - - watchPrefix, err = flagset.GetBool("prefix") - if err != nil { - return nil, nil, err - } - watchRev, err = flagset.GetInt64("rev") - if err != nil { - return nil, nil, err - } - watchPrevKey, err = flagset.GetBool("prev-kv") - if err != nil { - return nil, nil, err - } - } - - // "ETCDCTL_WATCH_KEY=foo watch -- echo hello" - // should translate "watch foo -- echo hello" - // (watchArgs=["echo","hello"] should be ["foo","echo","hello"]) - if envKey != "" { - ranges := []string{envKey} - if envRange != "" { - ranges = append(ranges, envRange) - } - watchArgs = append(ranges, watchArgs...) - } - - if !foundSep { - return watchArgs, nil, nil - } - - // "watch foo bar --rev 1 -- echo hello" or "watch foo --rev 1 bar -- echo hello", - // then "watchArgs" is "foo bar echo hello" - // so need ignore args after "argsWithSep[idx]", which is "--" - endIdx := 0 - for endIdx = len(watchArgs) - 1; endIdx >= 0; endIdx-- { - if watchArgs[endIdx] == argsWithSep[idx+1] { - break - } - } - watchArgs = watchArgs[:endIdx] - - return watchArgs, execArgs, nil -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/capability.go b/vendor/github.com/coreos/etcd/etcdserver/api/capability.go deleted file mode 100644 index eb34383d7f97..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/capability.go +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package api - -import ( - "sync" - - "github.com/coreos/etcd/version" - "github.com/coreos/go-semver/semver" - "github.com/coreos/pkg/capnslog" -) - -type Capability string - -const ( - AuthCapability Capability = "auth" - V3rpcCapability Capability = "v3rpc" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdserver/api") - - // capabilityMaps is a static map of version to capability map. - capabilityMaps = map[string]map[Capability]bool{ - "3.0.0": {AuthCapability: true, V3rpcCapability: true}, - "3.1.0": {AuthCapability: true, V3rpcCapability: true}, - "3.2.0": {AuthCapability: true, V3rpcCapability: true}, - "3.3.0": {AuthCapability: true, V3rpcCapability: true}, - } - - enableMapMu sync.RWMutex - // enabledMap points to a map in capabilityMaps - enabledMap map[Capability]bool - - curVersion *semver.Version -) - -func init() { - enabledMap = map[Capability]bool{ - AuthCapability: true, - V3rpcCapability: true, - } -} - -// UpdateCapability updates the enabledMap when the cluster version increases. -func UpdateCapability(v *semver.Version) { - if v == nil { - // if recovered but version was never set by cluster - return - } - enableMapMu.Lock() - if curVersion != nil && !curVersion.LessThan(*v) { - enableMapMu.Unlock() - return - } - curVersion = v - enabledMap = capabilityMaps[curVersion.String()] - enableMapMu.Unlock() - plog.Infof("enabled capabilities for version %s", version.Cluster(v.String())) -} - -func IsCapabilityEnabled(c Capability) bool { - enableMapMu.RLock() - defer enableMapMu.RUnlock() - if enabledMap == nil { - return false - } - return enabledMap[c] -} - -func EnableCapability(c Capability) { - enableMapMu.Lock() - defer enableMapMu.Unlock() - enabledMap[c] = true -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/cluster.go b/vendor/github.com/coreos/etcd/etcdserver/api/cluster.go deleted file mode 100644 index 654c25804cec..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/cluster.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package api - -import ( - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/pkg/types" - - "github.com/coreos/go-semver/semver" -) - -// Cluster is an interface representing a collection of members in one etcd cluster. -type Cluster interface { - // ID returns the cluster ID - ID() types.ID - // ClientURLs returns an aggregate set of all URLs on which this - // cluster is listening for client requests - ClientURLs() []string - // Members returns a slice of members sorted by their ID - Members() []*membership.Member - // Member retrieves a particular member based on ID, or nil if the - // member does not exist in the cluster - Member(id types.ID) *membership.Member - // Version is the cluster-wide minimum major.minor version. - Version() *semver.Version -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/doc.go b/vendor/github.com/coreos/etcd/etcdserver/api/doc.go deleted file mode 100644 index f44881be663e..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package api manages the capabilities and features that are exposed to clients by the etcd cluster. -package api diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/etcdhttp/base.go b/vendor/github.com/coreos/etcd/etcdserver/api/etcdhttp/base.go deleted file mode 100644 index f0d3b0bd3d2a..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/etcdhttp/base.go +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdhttp - -import ( - "encoding/json" - "expvar" - "fmt" - "net/http" - "strings" - - etcdErr "github.com/coreos/etcd/error" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api" - "github.com/coreos/etcd/etcdserver/api/v2http/httptypes" - "github.com/coreos/etcd/pkg/logutil" - "github.com/coreos/etcd/version" - "github.com/coreos/pkg/capnslog" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdserver/api/etcdhttp") - mlog = logutil.NewMergeLogger(plog) -) - -const ( - configPath = "/config" - varsPath = "/debug/vars" - versionPath = "/version" -) - -// HandleBasic adds handlers to a mux for serving JSON etcd client requests -// that do not access the v2 store. -func HandleBasic(mux *http.ServeMux, server etcdserver.ServerPeer) { - mux.HandleFunc(varsPath, serveVars) - mux.HandleFunc(configPath+"/local/log", logHandleFunc) - HandleMetricsHealth(mux, server) - mux.HandleFunc(versionPath, versionHandler(server.Cluster(), serveVersion)) -} - -func versionHandler(c api.Cluster, fn func(http.ResponseWriter, *http.Request, string)) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - v := c.Version() - if v != nil { - fn(w, r, v.String()) - } else { - fn(w, r, "not_decided") - } - } -} - -func serveVersion(w http.ResponseWriter, r *http.Request, clusterV string) { - if !allowMethod(w, r, "GET") { - return - } - vs := version.Versions{ - Server: version.Version, - Cluster: clusterV, - } - - w.Header().Set("Content-Type", "application/json") - b, err := json.Marshal(&vs) - if err != nil { - plog.Panicf("cannot marshal versions to json (%v)", err) - } - w.Write(b) -} - -func logHandleFunc(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r, "PUT") { - return - } - - in := struct{ Level string }{} - - d := json.NewDecoder(r.Body) - if err := d.Decode(&in); err != nil { - WriteError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Invalid json body")) - return - } - - logl, err := capnslog.ParseLevel(strings.ToUpper(in.Level)) - if err != nil { - WriteError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Invalid log level "+in.Level)) - return - } - - plog.Noticef("globalLogLevel set to %q", logl.String()) - capnslog.SetGlobalLogLevel(logl) - w.WriteHeader(http.StatusNoContent) -} - -func serveVars(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r, "GET") { - return - } - - w.Header().Set("Content-Type", "application/json; charset=utf-8") - fmt.Fprintf(w, "{\n") - first := true - expvar.Do(func(kv expvar.KeyValue) { - if !first { - fmt.Fprintf(w, ",\n") - } - first = false - fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value) - }) - fmt.Fprintf(w, "\n}\n") -} - -func allowMethod(w http.ResponseWriter, r *http.Request, m string) bool { - if m == r.Method { - return true - } - w.Header().Set("Allow", m) - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return false -} - -// WriteError logs and writes the given Error to the ResponseWriter -// If Error is an etcdErr, it is rendered to the ResponseWriter -// Otherwise, it is assumed to be a StatusInternalServerError -func WriteError(w http.ResponseWriter, r *http.Request, err error) { - if err == nil { - return - } - switch e := err.(type) { - case *etcdErr.Error: - e.WriteTo(w) - case *httptypes.HTTPError: - if et := e.WriteTo(w); et != nil { - plog.Debugf("error writing HTTPError (%v) to %s", et, r.RemoteAddr) - } - default: - switch err { - case etcdserver.ErrTimeoutDueToLeaderFail, etcdserver.ErrTimeoutDueToConnectionLost, etcdserver.ErrNotEnoughStartedMembers, etcdserver.ErrUnhealthy: - mlog.MergeError(err) - default: - mlog.MergeErrorf("got unexpected response error (%v)", err) - } - herr := httptypes.NewHTTPError(http.StatusInternalServerError, "Internal Server Error") - if et := herr.WriteTo(w); et != nil { - plog.Debugf("error writing HTTPError (%v) to %s", et, r.RemoteAddr) - } - } -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/etcdhttp/doc.go b/vendor/github.com/coreos/etcd/etcdserver/api/etcdhttp/doc.go deleted file mode 100644 index a03b626204f7..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/etcdhttp/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package etcdhttp implements HTTP transportation layer for etcdserver. -package etcdhttp diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/etcdhttp/metrics.go b/vendor/github.com/coreos/etcd/etcdserver/api/etcdhttp/metrics.go deleted file mode 100644 index e947abfdd0d1..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/etcdhttp/metrics.go +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdhttp - -import ( - "context" - "encoding/json" - "net/http" - "time" - - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/raft" - - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promhttp" -) - -const ( - PathMetrics = "/metrics" - PathHealth = "/health" -) - -// HandleMetricsHealth registers metrics and health handlers. -func HandleMetricsHealth(mux *http.ServeMux, srv etcdserver.ServerV2) { - mux.Handle(PathMetrics, promhttp.Handler()) - mux.Handle(PathHealth, NewHealthHandler(func() Health { return checkHealth(srv) })) -} - -// HandlePrometheus registers prometheus handler on '/metrics'. -func HandlePrometheus(mux *http.ServeMux) { - mux.Handle(PathMetrics, promhttp.Handler()) -} - -// NewHealthHandler handles '/health' requests. -func NewHealthHandler(hfunc func() Health) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - if r.Method != http.MethodGet { - w.Header().Set("Allow", http.MethodGet) - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return - } - h := hfunc() - d, _ := json.Marshal(h) - if h.Health != "true" { - http.Error(w, string(d), http.StatusServiceUnavailable) - return - } - w.WriteHeader(http.StatusOK) - w.Write(d) - } -} - -var ( - healthSuccess = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "health_success", - Help: "The total number of successful health checks", - }) - healthFailed = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "health_failures", - Help: "The total number of failed health checks", - }) -) - -func init() { - prometheus.MustRegister(healthSuccess) - prometheus.MustRegister(healthFailed) -} - -// Health defines etcd server health status. -// TODO: remove manual parsing in etcdctl cluster-health -type Health struct { - Health string `json:"health"` -} - -// TODO: server NOSPACE, etcdserver.ErrNoLeader in health API - -func checkHealth(srv etcdserver.ServerV2) Health { - h := Health{Health: "true"} - - as := srv.Alarms() - if len(as) > 0 { - h.Health = "false" - } - - if h.Health == "true" { - if uint64(srv.Leader()) == raft.None { - h.Health = "false" - } - } - - if h.Health == "true" { - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - _, err := srv.Do(ctx, etcdserverpb.Request{Method: "QGET"}) - cancel() - if err != nil { - h.Health = "false" - } - } - - if h.Health == "true" { - healthSuccess.Inc() - } else { - healthFailed.Inc() - } - return h -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/etcdhttp/peer.go b/vendor/github.com/coreos/etcd/etcdserver/api/etcdhttp/peer.go deleted file mode 100644 index 0a9213b01a9b..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/etcdhttp/peer.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdhttp - -import ( - "encoding/json" - "net/http" - - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api" - "github.com/coreos/etcd/lease/leasehttp" - "github.com/coreos/etcd/rafthttp" -) - -const ( - peerMembersPrefix = "/members" -) - -// NewPeerHandler generates an http.Handler to handle etcd peer requests. -func NewPeerHandler(s etcdserver.ServerPeer) http.Handler { - return newPeerHandler(s.Cluster(), s.RaftHandler(), s.LeaseHandler()) -} - -func newPeerHandler(cluster api.Cluster, raftHandler http.Handler, leaseHandler http.Handler) http.Handler { - mh := &peerMembersHandler{ - cluster: cluster, - } - - mux := http.NewServeMux() - mux.HandleFunc("/", http.NotFound) - mux.Handle(rafthttp.RaftPrefix, raftHandler) - mux.Handle(rafthttp.RaftPrefix+"/", raftHandler) - mux.Handle(peerMembersPrefix, mh) - if leaseHandler != nil { - mux.Handle(leasehttp.LeasePrefix, leaseHandler) - mux.Handle(leasehttp.LeaseInternalPrefix, leaseHandler) - } - mux.HandleFunc(versionPath, versionHandler(cluster, serveVersion)) - return mux -} - -type peerMembersHandler struct { - cluster api.Cluster -} - -func (h *peerMembersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r, "GET") { - return - } - w.Header().Set("X-Etcd-Cluster-ID", h.cluster.ID().String()) - - if r.URL.Path != peerMembersPrefix { - http.Error(w, "bad path", http.StatusBadRequest) - return - } - ms := h.cluster.Members() - w.Header().Set("Content-Type", "application/json") - if err := json.NewEncoder(w).Encode(ms); err != nil { - plog.Warningf("failed to encode members response (%v)", err) - } -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v2http/capability.go b/vendor/github.com/coreos/etcd/etcdserver/api/v2http/capability.go deleted file mode 100644 index fa0bcca5e846..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v2http/capability.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2http - -import ( - "fmt" - "net/http" - - "github.com/coreos/etcd/etcdserver/api" - "github.com/coreos/etcd/etcdserver/api/v2http/httptypes" -) - -func capabilityHandler(c api.Capability, fn func(http.ResponseWriter, *http.Request)) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - if !api.IsCapabilityEnabled(c) { - notCapable(w, r, c) - return - } - fn(w, r) - } -} - -func notCapable(w http.ResponseWriter, r *http.Request, c api.Capability) { - herr := httptypes.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Not capable of accessing %s feature during rolling upgrades.", c)) - if err := herr.WriteTo(w); err != nil { - plog.Debugf("error writing HTTPError (%v) to %s", err, r.RemoteAddr) - } -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v2http/client.go b/vendor/github.com/coreos/etcd/etcdserver/api/v2http/client.go deleted file mode 100644 index 6aaf3db360be..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v2http/client.go +++ /dev/null @@ -1,719 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2http - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "net/http" - "net/url" - "path" - "strconv" - "strings" - "time" - - etcdErr "github.com/coreos/etcd/error" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api" - "github.com/coreos/etcd/etcdserver/api/etcdhttp" - "github.com/coreos/etcd/etcdserver/api/v2http/httptypes" - "github.com/coreos/etcd/etcdserver/auth" - "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/etcdserver/stats" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/store" - - "github.com/jonboulle/clockwork" -) - -const ( - authPrefix = "/v2/auth" - keysPrefix = "/v2/keys" - machinesPrefix = "/v2/machines" - membersPrefix = "/v2/members" - statsPrefix = "/v2/stats" -) - -// NewClientHandler generates a muxed http.Handler with the given parameters to serve etcd client requests. -func NewClientHandler(server etcdserver.ServerPeer, timeout time.Duration) http.Handler { - mux := http.NewServeMux() - etcdhttp.HandleBasic(mux, server) - handleV2(mux, server, timeout) - return requestLogger(mux) -} - -func handleV2(mux *http.ServeMux, server etcdserver.ServerV2, timeout time.Duration) { - sec := auth.NewStore(server, timeout) - kh := &keysHandler{ - sec: sec, - server: server, - cluster: server.Cluster(), - timeout: timeout, - clientCertAuthEnabled: server.ClientCertAuthEnabled(), - } - - sh := &statsHandler{ - stats: server, - } - - mh := &membersHandler{ - sec: sec, - server: server, - cluster: server.Cluster(), - timeout: timeout, - clock: clockwork.NewRealClock(), - clientCertAuthEnabled: server.ClientCertAuthEnabled(), - } - - mah := &machinesHandler{cluster: server.Cluster()} - - sech := &authHandler{ - sec: sec, - cluster: server.Cluster(), - clientCertAuthEnabled: server.ClientCertAuthEnabled(), - } - mux.HandleFunc("/", http.NotFound) - mux.Handle(keysPrefix, kh) - mux.Handle(keysPrefix+"/", kh) - mux.HandleFunc(statsPrefix+"/store", sh.serveStore) - mux.HandleFunc(statsPrefix+"/self", sh.serveSelf) - mux.HandleFunc(statsPrefix+"/leader", sh.serveLeader) - mux.Handle(membersPrefix, mh) - mux.Handle(membersPrefix+"/", mh) - mux.Handle(machinesPrefix, mah) - handleAuth(mux, sech) -} - -type keysHandler struct { - sec auth.Store - server etcdserver.ServerV2 - cluster api.Cluster - timeout time.Duration - clientCertAuthEnabled bool -} - -func (h *keysHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "HEAD", "GET", "PUT", "POST", "DELETE") { - return - } - - w.Header().Set("X-Etcd-Cluster-ID", h.cluster.ID().String()) - - ctx, cancel := context.WithTimeout(context.Background(), h.timeout) - defer cancel() - clock := clockwork.NewRealClock() - startTime := clock.Now() - rr, noValueOnSuccess, err := parseKeyRequest(r, clock) - if err != nil { - writeKeyError(w, err) - return - } - // The path must be valid at this point (we've parsed the request successfully). - if !hasKeyPrefixAccess(h.sec, r, r.URL.Path[len(keysPrefix):], rr.Recursive, h.clientCertAuthEnabled) { - writeKeyNoAuth(w) - return - } - if !rr.Wait { - reportRequestReceived(rr) - } - resp, err := h.server.Do(ctx, rr) - if err != nil { - err = trimErrorPrefix(err, etcdserver.StoreKeysPrefix) - writeKeyError(w, err) - reportRequestFailed(rr, err) - return - } - switch { - case resp.Event != nil: - if err := writeKeyEvent(w, resp, noValueOnSuccess); err != nil { - // Should never be reached - plog.Errorf("error writing event (%v)", err) - } - reportRequestCompleted(rr, resp, startTime) - case resp.Watcher != nil: - ctx, cancel := context.WithTimeout(context.Background(), defaultWatchTimeout) - defer cancel() - handleKeyWatch(ctx, w, resp, rr.Stream) - default: - writeKeyError(w, errors.New("received response with no Event/Watcher!")) - } -} - -type machinesHandler struct { - cluster api.Cluster -} - -func (h *machinesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET", "HEAD") { - return - } - endpoints := h.cluster.ClientURLs() - w.Write([]byte(strings.Join(endpoints, ", "))) -} - -type membersHandler struct { - sec auth.Store - server etcdserver.ServerV2 - cluster api.Cluster - timeout time.Duration - clock clockwork.Clock - clientCertAuthEnabled bool -} - -func (h *membersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET", "POST", "DELETE", "PUT") { - return - } - if !hasWriteRootAccess(h.sec, r, h.clientCertAuthEnabled) { - writeNoAuth(w, r) - return - } - w.Header().Set("X-Etcd-Cluster-ID", h.cluster.ID().String()) - - ctx, cancel := context.WithTimeout(context.Background(), h.timeout) - defer cancel() - - switch r.Method { - case "GET": - switch trimPrefix(r.URL.Path, membersPrefix) { - case "": - mc := newMemberCollection(h.cluster.Members()) - w.Header().Set("Content-Type", "application/json") - if err := json.NewEncoder(w).Encode(mc); err != nil { - plog.Warningf("failed to encode members response (%v)", err) - } - case "leader": - id := h.server.Leader() - if id == 0 { - writeError(w, r, httptypes.NewHTTPError(http.StatusServiceUnavailable, "During election")) - return - } - m := newMember(h.cluster.Member(id)) - w.Header().Set("Content-Type", "application/json") - if err := json.NewEncoder(w).Encode(m); err != nil { - plog.Warningf("failed to encode members response (%v)", err) - } - default: - writeError(w, r, httptypes.NewHTTPError(http.StatusNotFound, "Not found")) - } - case "POST": - req := httptypes.MemberCreateRequest{} - if ok := unmarshalRequest(r, &req, w); !ok { - return - } - now := h.clock.Now() - m := membership.NewMember("", req.PeerURLs, "", &now) - _, err := h.server.AddMember(ctx, *m) - switch { - case err == membership.ErrIDExists || err == membership.ErrPeerURLexists: - writeError(w, r, httptypes.NewHTTPError(http.StatusConflict, err.Error())) - return - case err != nil: - plog.Errorf("error adding member %s (%v)", m.ID, err) - writeError(w, r, err) - return - } - res := newMember(m) - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusCreated) - if err := json.NewEncoder(w).Encode(res); err != nil { - plog.Warningf("failed to encode members response (%v)", err) - } - case "DELETE": - id, ok := getID(r.URL.Path, w) - if !ok { - return - } - _, err := h.server.RemoveMember(ctx, uint64(id)) - switch { - case err == membership.ErrIDRemoved: - writeError(w, r, httptypes.NewHTTPError(http.StatusGone, fmt.Sprintf("Member permanently removed: %s", id))) - case err == membership.ErrIDNotFound: - writeError(w, r, httptypes.NewHTTPError(http.StatusNotFound, fmt.Sprintf("No such member: %s", id))) - case err != nil: - plog.Errorf("error removing member %s (%v)", id, err) - writeError(w, r, err) - default: - w.WriteHeader(http.StatusNoContent) - } - case "PUT": - id, ok := getID(r.URL.Path, w) - if !ok { - return - } - req := httptypes.MemberUpdateRequest{} - if ok := unmarshalRequest(r, &req, w); !ok { - return - } - m := membership.Member{ - ID: id, - RaftAttributes: membership.RaftAttributes{PeerURLs: req.PeerURLs.StringSlice()}, - } - _, err := h.server.UpdateMember(ctx, m) - switch { - case err == membership.ErrPeerURLexists: - writeError(w, r, httptypes.NewHTTPError(http.StatusConflict, err.Error())) - case err == membership.ErrIDNotFound: - writeError(w, r, httptypes.NewHTTPError(http.StatusNotFound, fmt.Sprintf("No such member: %s", id))) - case err != nil: - plog.Errorf("error updating member %s (%v)", m.ID, err) - writeError(w, r, err) - default: - w.WriteHeader(http.StatusNoContent) - } - } -} - -type statsHandler struct { - stats stats.Stats -} - -func (h *statsHandler) serveStore(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET") { - return - } - w.Header().Set("Content-Type", "application/json") - w.Write(h.stats.StoreStats()) -} - -func (h *statsHandler) serveSelf(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET") { - return - } - w.Header().Set("Content-Type", "application/json") - w.Write(h.stats.SelfStats()) -} - -func (h *statsHandler) serveLeader(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET") { - return - } - stats := h.stats.LeaderStats() - if stats == nil { - etcdhttp.WriteError(w, r, httptypes.NewHTTPError(http.StatusForbidden, "not current leader")) - return - } - w.Header().Set("Content-Type", "application/json") - w.Write(stats) -} - -// parseKeyRequest converts a received http.Request on keysPrefix to -// a server Request, performing validation of supplied fields as appropriate. -// If any validation fails, an empty Request and non-nil error is returned. -func parseKeyRequest(r *http.Request, clock clockwork.Clock) (etcdserverpb.Request, bool, error) { - var noValueOnSuccess bool - emptyReq := etcdserverpb.Request{} - - err := r.ParseForm() - if err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidForm, - err.Error(), - ) - } - - if !strings.HasPrefix(r.URL.Path, keysPrefix) { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidForm, - "incorrect key prefix", - ) - } - p := path.Join(etcdserver.StoreKeysPrefix, r.URL.Path[len(keysPrefix):]) - - var pIdx, wIdx uint64 - if pIdx, err = getUint64(r.Form, "prevIndex"); err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeIndexNaN, - `invalid value for "prevIndex"`, - ) - } - if wIdx, err = getUint64(r.Form, "waitIndex"); err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeIndexNaN, - `invalid value for "waitIndex"`, - ) - } - - var rec, sort, wait, dir, quorum, stream bool - if rec, err = getBool(r.Form, "recursive"); err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - `invalid value for "recursive"`, - ) - } - if sort, err = getBool(r.Form, "sorted"); err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - `invalid value for "sorted"`, - ) - } - if wait, err = getBool(r.Form, "wait"); err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - `invalid value for "wait"`, - ) - } - // TODO(jonboulle): define what parameters dir is/isn't compatible with? - if dir, err = getBool(r.Form, "dir"); err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - `invalid value for "dir"`, - ) - } - if quorum, err = getBool(r.Form, "quorum"); err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - `invalid value for "quorum"`, - ) - } - if stream, err = getBool(r.Form, "stream"); err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - `invalid value for "stream"`, - ) - } - - if wait && r.Method != "GET" { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - `"wait" can only be used with GET requests`, - ) - } - - pV := r.FormValue("prevValue") - if _, ok := r.Form["prevValue"]; ok && pV == "" { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodePrevValueRequired, - `"prevValue" cannot be empty`, - ) - } - - if noValueOnSuccess, err = getBool(r.Form, "noValueOnSuccess"); err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - `invalid value for "noValueOnSuccess"`, - ) - } - - // TTL is nullable, so leave it null if not specified - // or an empty string - var ttl *uint64 - if len(r.FormValue("ttl")) > 0 { - i, err := getUint64(r.Form, "ttl") - if err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeTTLNaN, - `invalid value for "ttl"`, - ) - } - ttl = &i - } - - // prevExist is nullable, so leave it null if not specified - var pe *bool - if _, ok := r.Form["prevExist"]; ok { - bv, err := getBool(r.Form, "prevExist") - if err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - "invalid value for prevExist", - ) - } - pe = &bv - } - - // refresh is nullable, so leave it null if not specified - var refresh *bool - if _, ok := r.Form["refresh"]; ok { - bv, err := getBool(r.Form, "refresh") - if err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - "invalid value for refresh", - ) - } - refresh = &bv - if refresh != nil && *refresh { - val := r.FormValue("value") - if _, ok := r.Form["value"]; ok && val != "" { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeRefreshValue, - `A value was provided on a refresh`, - ) - } - if ttl == nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeRefreshTTLRequired, - `No TTL value set`, - ) - } - } - } - - rr := etcdserverpb.Request{ - Method: r.Method, - Path: p, - Val: r.FormValue("value"), - Dir: dir, - PrevValue: pV, - PrevIndex: pIdx, - PrevExist: pe, - Wait: wait, - Since: wIdx, - Recursive: rec, - Sorted: sort, - Quorum: quorum, - Stream: stream, - } - - if pe != nil { - rr.PrevExist = pe - } - - if refresh != nil { - rr.Refresh = refresh - } - - // Null TTL is equivalent to unset Expiration - if ttl != nil { - expr := time.Duration(*ttl) * time.Second - rr.Expiration = clock.Now().Add(expr).UnixNano() - } - - return rr, noValueOnSuccess, nil -} - -// writeKeyEvent trims the prefix of key path in a single Event under -// StoreKeysPrefix, serializes it and writes the resulting JSON to the given -// ResponseWriter, along with the appropriate headers. -func writeKeyEvent(w http.ResponseWriter, resp etcdserver.Response, noValueOnSuccess bool) error { - ev := resp.Event - if ev == nil { - return errors.New("cannot write empty Event!") - } - w.Header().Set("Content-Type", "application/json") - w.Header().Set("X-Etcd-Index", fmt.Sprint(ev.EtcdIndex)) - w.Header().Set("X-Raft-Index", fmt.Sprint(resp.Index)) - w.Header().Set("X-Raft-Term", fmt.Sprint(resp.Term)) - - if ev.IsCreated() { - w.WriteHeader(http.StatusCreated) - } - - ev = trimEventPrefix(ev, etcdserver.StoreKeysPrefix) - if noValueOnSuccess && - (ev.Action == store.Set || ev.Action == store.CompareAndSwap || - ev.Action == store.Create || ev.Action == store.Update) { - ev.Node = nil - ev.PrevNode = nil - } - return json.NewEncoder(w).Encode(ev) -} - -func writeKeyNoAuth(w http.ResponseWriter) { - e := etcdErr.NewError(etcdErr.EcodeUnauthorized, "Insufficient credentials", 0) - e.WriteTo(w) -} - -// writeKeyError logs and writes the given Error to the ResponseWriter. -// If Error is not an etcdErr, the error will be converted to an etcd error. -func writeKeyError(w http.ResponseWriter, err error) { - if err == nil { - return - } - switch e := err.(type) { - case *etcdErr.Error: - e.WriteTo(w) - default: - switch err { - case etcdserver.ErrTimeoutDueToLeaderFail, etcdserver.ErrTimeoutDueToConnectionLost: - mlog.MergeError(err) - default: - mlog.MergeErrorf("got unexpected response error (%v)", err) - } - ee := etcdErr.NewError(etcdErr.EcodeRaftInternal, err.Error(), 0) - ee.WriteTo(w) - } -} - -func handleKeyWatch(ctx context.Context, w http.ResponseWriter, resp etcdserver.Response, stream bool) { - wa := resp.Watcher - defer wa.Remove() - ech := wa.EventChan() - var nch <-chan bool - if x, ok := w.(http.CloseNotifier); ok { - nch = x.CloseNotify() - } - - w.Header().Set("Content-Type", "application/json") - w.Header().Set("X-Etcd-Index", fmt.Sprint(wa.StartIndex())) - w.Header().Set("X-Raft-Index", fmt.Sprint(resp.Index)) - w.Header().Set("X-Raft-Term", fmt.Sprint(resp.Term)) - w.WriteHeader(http.StatusOK) - - // Ensure headers are flushed early, in case of long polling - w.(http.Flusher).Flush() - - for { - select { - case <-nch: - // Client closed connection. Nothing to do. - return - case <-ctx.Done(): - // Timed out. net/http will close the connection for us, so nothing to do. - return - case ev, ok := <-ech: - if !ok { - // If the channel is closed this may be an indication of - // that notifications are much more than we are able to - // send to the client in time. Then we simply end streaming. - return - } - ev = trimEventPrefix(ev, etcdserver.StoreKeysPrefix) - if err := json.NewEncoder(w).Encode(ev); err != nil { - // Should never be reached - plog.Warningf("error writing event (%v)", err) - return - } - if !stream { - return - } - w.(http.Flusher).Flush() - } - } -} - -func trimEventPrefix(ev *store.Event, prefix string) *store.Event { - if ev == nil { - return nil - } - // Since the *Event may reference one in the store history - // history, we must copy it before modifying - e := ev.Clone() - trimNodeExternPrefix(e.Node, prefix) - trimNodeExternPrefix(e.PrevNode, prefix) - return e -} - -func trimNodeExternPrefix(n *store.NodeExtern, prefix string) { - if n == nil { - return - } - n.Key = strings.TrimPrefix(n.Key, prefix) - for _, nn := range n.Nodes { - trimNodeExternPrefix(nn, prefix) - } -} - -func trimErrorPrefix(err error, prefix string) error { - if e, ok := err.(*etcdErr.Error); ok { - e.Cause = strings.TrimPrefix(e.Cause, prefix) - } - return err -} - -func unmarshalRequest(r *http.Request, req json.Unmarshaler, w http.ResponseWriter) bool { - ctype := r.Header.Get("Content-Type") - semicolonPosition := strings.Index(ctype, ";") - if semicolonPosition != -1 { - ctype = strings.TrimSpace(strings.ToLower(ctype[0:semicolonPosition])) - } - if ctype != "application/json" { - writeError(w, r, httptypes.NewHTTPError(http.StatusUnsupportedMediaType, fmt.Sprintf("Bad Content-Type %s, accept application/json", ctype))) - return false - } - b, err := ioutil.ReadAll(r.Body) - if err != nil { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, err.Error())) - return false - } - if err := req.UnmarshalJSON(b); err != nil { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, err.Error())) - return false - } - return true -} - -func getID(p string, w http.ResponseWriter) (types.ID, bool) { - idStr := trimPrefix(p, membersPrefix) - if idStr == "" { - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return 0, false - } - id, err := types.IDFromString(idStr) - if err != nil { - writeError(w, nil, httptypes.NewHTTPError(http.StatusNotFound, fmt.Sprintf("No such member: %s", idStr))) - return 0, false - } - return id, true -} - -// getUint64 extracts a uint64 by the given key from a Form. If the key does -// not exist in the form, 0 is returned. If the key exists but the value is -// badly formed, an error is returned. If multiple values are present only the -// first is considered. -func getUint64(form url.Values, key string) (i uint64, err error) { - if vals, ok := form[key]; ok { - i, err = strconv.ParseUint(vals[0], 10, 64) - } - return -} - -// getBool extracts a bool by the given key from a Form. If the key does not -// exist in the form, false is returned. If the key exists but the value is -// badly formed, an error is returned. If multiple values are present only the -// first is considered. -func getBool(form url.Values, key string) (b bool, err error) { - if vals, ok := form[key]; ok { - b, err = strconv.ParseBool(vals[0]) - } - return -} - -// trimPrefix removes a given prefix and any slash following the prefix -// e.g.: trimPrefix("foo", "foo") == trimPrefix("foo/", "foo") == "" -func trimPrefix(p, prefix string) (s string) { - s = strings.TrimPrefix(p, prefix) - s = strings.TrimPrefix(s, "/") - return -} - -func newMemberCollection(ms []*membership.Member) *httptypes.MemberCollection { - c := httptypes.MemberCollection(make([]httptypes.Member, len(ms))) - - for i, m := range ms { - c[i] = newMember(m) - } - - return &c -} - -func newMember(m *membership.Member) httptypes.Member { - tm := httptypes.Member{ - ID: m.ID.String(), - Name: m.Name, - PeerURLs: make([]string, len(m.PeerURLs)), - ClientURLs: make([]string, len(m.ClientURLs)), - } - - copy(tm.PeerURLs, m.PeerURLs) - copy(tm.ClientURLs, m.ClientURLs) - - return tm -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v2http/client_auth.go b/vendor/github.com/coreos/etcd/etcdserver/api/v2http/client_auth.go deleted file mode 100644 index 606e2e00b3ed..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v2http/client_auth.go +++ /dev/null @@ -1,543 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2http - -import ( - "encoding/json" - "net/http" - "path" - "strings" - - "github.com/coreos/etcd/etcdserver/api" - "github.com/coreos/etcd/etcdserver/api/v2http/httptypes" - "github.com/coreos/etcd/etcdserver/auth" -) - -type authHandler struct { - sec auth.Store - cluster api.Cluster - clientCertAuthEnabled bool -} - -func hasWriteRootAccess(sec auth.Store, r *http.Request, clientCertAuthEnabled bool) bool { - if r.Method == "GET" || r.Method == "HEAD" { - return true - } - return hasRootAccess(sec, r, clientCertAuthEnabled) -} - -func userFromBasicAuth(sec auth.Store, r *http.Request) *auth.User { - username, password, ok := r.BasicAuth() - if !ok { - plog.Warningf("auth: malformed basic auth encoding") - return nil - } - user, err := sec.GetUser(username) - if err != nil { - return nil - } - - ok = sec.CheckPassword(user, password) - if !ok { - plog.Warningf("auth: incorrect password for user: %s", username) - return nil - } - return &user -} - -func userFromClientCertificate(sec auth.Store, r *http.Request) *auth.User { - if r.TLS == nil { - return nil - } - - for _, chains := range r.TLS.VerifiedChains { - for _, chain := range chains { - plog.Debugf("auth: found common name %s.\n", chain.Subject.CommonName) - user, err := sec.GetUser(chain.Subject.CommonName) - if err == nil { - plog.Debugf("auth: authenticated user %s by cert common name.", user.User) - return &user - } - } - } - return nil -} - -func hasRootAccess(sec auth.Store, r *http.Request, clientCertAuthEnabled bool) bool { - if sec == nil { - // No store means no auth available, eg, tests. - return true - } - if !sec.AuthEnabled() { - return true - } - - var rootUser *auth.User - if r.Header.Get("Authorization") == "" && clientCertAuthEnabled { - rootUser = userFromClientCertificate(sec, r) - if rootUser == nil { - return false - } - } else { - rootUser = userFromBasicAuth(sec, r) - if rootUser == nil { - return false - } - } - - for _, role := range rootUser.Roles { - if role == auth.RootRoleName { - return true - } - } - plog.Warningf("auth: user %s does not have the %s role for resource %s.", rootUser.User, auth.RootRoleName, r.URL.Path) - return false -} - -func hasKeyPrefixAccess(sec auth.Store, r *http.Request, key string, recursive, clientCertAuthEnabled bool) bool { - if sec == nil { - // No store means no auth available, eg, tests. - return true - } - if !sec.AuthEnabled() { - return true - } - - var user *auth.User - if r.Header.Get("Authorization") == "" { - if clientCertAuthEnabled { - user = userFromClientCertificate(sec, r) - } - if user == nil { - return hasGuestAccess(sec, r, key) - } - } else { - user = userFromBasicAuth(sec, r) - if user == nil { - return false - } - } - - writeAccess := r.Method != "GET" && r.Method != "HEAD" - for _, roleName := range user.Roles { - role, err := sec.GetRole(roleName) - if err != nil { - continue - } - if recursive { - if role.HasRecursiveAccess(key, writeAccess) { - return true - } - } else if role.HasKeyAccess(key, writeAccess) { - return true - } - } - plog.Warningf("auth: invalid access for user %s on key %s.", user.User, key) - return false -} - -func hasGuestAccess(sec auth.Store, r *http.Request, key string) bool { - writeAccess := r.Method != "GET" && r.Method != "HEAD" - role, err := sec.GetRole(auth.GuestRoleName) - if err != nil { - return false - } - if role.HasKeyAccess(key, writeAccess) { - return true - } - plog.Warningf("auth: invalid access for unauthenticated user on resource %s.", key) - return false -} - -func writeNoAuth(w http.ResponseWriter, r *http.Request) { - herr := httptypes.NewHTTPError(http.StatusUnauthorized, "Insufficient credentials") - if err := herr.WriteTo(w); err != nil { - plog.Debugf("error writing HTTPError (%v) to %s", err, r.RemoteAddr) - } -} - -func handleAuth(mux *http.ServeMux, sh *authHandler) { - mux.HandleFunc(authPrefix+"/roles", capabilityHandler(api.AuthCapability, sh.baseRoles)) - mux.HandleFunc(authPrefix+"/roles/", capabilityHandler(api.AuthCapability, sh.handleRoles)) - mux.HandleFunc(authPrefix+"/users", capabilityHandler(api.AuthCapability, sh.baseUsers)) - mux.HandleFunc(authPrefix+"/users/", capabilityHandler(api.AuthCapability, sh.handleUsers)) - mux.HandleFunc(authPrefix+"/enable", capabilityHandler(api.AuthCapability, sh.enableDisable)) -} - -func (sh *authHandler) baseRoles(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET") { - return - } - if !hasRootAccess(sh.sec, r, sh.clientCertAuthEnabled) { - writeNoAuth(w, r) - return - } - - w.Header().Set("X-Etcd-Cluster-ID", sh.cluster.ID().String()) - w.Header().Set("Content-Type", "application/json") - - roles, err := sh.sec.AllRoles() - if err != nil { - writeError(w, r, err) - return - } - if roles == nil { - roles = make([]string, 0) - } - - err = r.ParseForm() - if err != nil { - writeError(w, r, err) - return - } - - var rolesCollections struct { - Roles []auth.Role `json:"roles"` - } - for _, roleName := range roles { - var role auth.Role - role, err = sh.sec.GetRole(roleName) - if err != nil { - writeError(w, r, err) - return - } - rolesCollections.Roles = append(rolesCollections.Roles, role) - } - err = json.NewEncoder(w).Encode(rolesCollections) - - if err != nil { - plog.Warningf("baseRoles error encoding on %s", r.URL) - writeError(w, r, err) - return - } -} - -func (sh *authHandler) handleRoles(w http.ResponseWriter, r *http.Request) { - subpath := path.Clean(r.URL.Path[len(authPrefix):]) - // Split "/roles/rolename/command". - // First item is an empty string, second is "roles" - pieces := strings.Split(subpath, "/") - if len(pieces) == 2 { - sh.baseRoles(w, r) - return - } - if len(pieces) != 3 { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Invalid path")) - return - } - sh.forRole(w, r, pieces[2]) -} - -func (sh *authHandler) forRole(w http.ResponseWriter, r *http.Request, role string) { - if !allowMethod(w, r.Method, "GET", "PUT", "DELETE") { - return - } - if !hasRootAccess(sh.sec, r, sh.clientCertAuthEnabled) { - writeNoAuth(w, r) - return - } - w.Header().Set("X-Etcd-Cluster-ID", sh.cluster.ID().String()) - w.Header().Set("Content-Type", "application/json") - - switch r.Method { - case "GET": - data, err := sh.sec.GetRole(role) - if err != nil { - writeError(w, r, err) - return - } - err = json.NewEncoder(w).Encode(data) - if err != nil { - plog.Warningf("forRole error encoding on %s", r.URL) - return - } - return - case "PUT": - var in auth.Role - err := json.NewDecoder(r.Body).Decode(&in) - if err != nil { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Invalid JSON in request body.")) - return - } - if in.Role != role { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Role JSON name does not match the name in the URL")) - return - } - - var out auth.Role - - // create - if in.Grant.IsEmpty() && in.Revoke.IsEmpty() { - err = sh.sec.CreateRole(in) - if err != nil { - writeError(w, r, err) - return - } - w.WriteHeader(http.StatusCreated) - out = in - } else { - if !in.Permissions.IsEmpty() { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Role JSON contains both permissions and grant/revoke")) - return - } - out, err = sh.sec.UpdateRole(in) - if err != nil { - writeError(w, r, err) - return - } - w.WriteHeader(http.StatusOK) - } - - err = json.NewEncoder(w).Encode(out) - if err != nil { - plog.Warningf("forRole error encoding on %s", r.URL) - return - } - return - case "DELETE": - err := sh.sec.DeleteRole(role) - if err != nil { - writeError(w, r, err) - return - } - } -} - -type userWithRoles struct { - User string `json:"user"` - Roles []auth.Role `json:"roles,omitempty"` -} - -type usersCollections struct { - Users []userWithRoles `json:"users"` -} - -func (sh *authHandler) baseUsers(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET") { - return - } - if !hasRootAccess(sh.sec, r, sh.clientCertAuthEnabled) { - writeNoAuth(w, r) - return - } - w.Header().Set("X-Etcd-Cluster-ID", sh.cluster.ID().String()) - w.Header().Set("Content-Type", "application/json") - - users, err := sh.sec.AllUsers() - if err != nil { - writeError(w, r, err) - return - } - if users == nil { - users = make([]string, 0) - } - - err = r.ParseForm() - if err != nil { - writeError(w, r, err) - return - } - - ucs := usersCollections{} - for _, userName := range users { - var user auth.User - user, err = sh.sec.GetUser(userName) - if err != nil { - writeError(w, r, err) - return - } - - uwr := userWithRoles{User: user.User} - for _, roleName := range user.Roles { - var role auth.Role - role, err = sh.sec.GetRole(roleName) - if err != nil { - continue - } - uwr.Roles = append(uwr.Roles, role) - } - - ucs.Users = append(ucs.Users, uwr) - } - err = json.NewEncoder(w).Encode(ucs) - - if err != nil { - plog.Warningf("baseUsers error encoding on %s", r.URL) - writeError(w, r, err) - return - } -} - -func (sh *authHandler) handleUsers(w http.ResponseWriter, r *http.Request) { - subpath := path.Clean(r.URL.Path[len(authPrefix):]) - // Split "/users/username". - // First item is an empty string, second is "users" - pieces := strings.Split(subpath, "/") - if len(pieces) == 2 { - sh.baseUsers(w, r) - return - } - if len(pieces) != 3 { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Invalid path")) - return - } - sh.forUser(w, r, pieces[2]) -} - -func (sh *authHandler) forUser(w http.ResponseWriter, r *http.Request, user string) { - if !allowMethod(w, r.Method, "GET", "PUT", "DELETE") { - return - } - if !hasRootAccess(sh.sec, r, sh.clientCertAuthEnabled) { - writeNoAuth(w, r) - return - } - w.Header().Set("X-Etcd-Cluster-ID", sh.cluster.ID().String()) - w.Header().Set("Content-Type", "application/json") - - switch r.Method { - case "GET": - u, err := sh.sec.GetUser(user) - if err != nil { - writeError(w, r, err) - return - } - - err = r.ParseForm() - if err != nil { - writeError(w, r, err) - return - } - - uwr := userWithRoles{User: u.User} - for _, roleName := range u.Roles { - var role auth.Role - role, err = sh.sec.GetRole(roleName) - if err != nil { - writeError(w, r, err) - return - } - uwr.Roles = append(uwr.Roles, role) - } - err = json.NewEncoder(w).Encode(uwr) - - if err != nil { - plog.Warningf("forUser error encoding on %s", r.URL) - return - } - return - case "PUT": - var u auth.User - err := json.NewDecoder(r.Body).Decode(&u) - if err != nil { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Invalid JSON in request body.")) - return - } - if u.User != user { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "User JSON name does not match the name in the URL")) - return - } - - var ( - out auth.User - created bool - ) - - if len(u.Grant) == 0 && len(u.Revoke) == 0 { - // create or update - if len(u.Roles) != 0 { - out, err = sh.sec.CreateUser(u) - } else { - // if user passes in both password and roles, we are unsure about his/her - // intention. - out, created, err = sh.sec.CreateOrUpdateUser(u) - } - - if err != nil { - writeError(w, r, err) - return - } - } else { - // update case - if len(u.Roles) != 0 { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "User JSON contains both roles and grant/revoke")) - return - } - out, err = sh.sec.UpdateUser(u) - if err != nil { - writeError(w, r, err) - return - } - } - - if created { - w.WriteHeader(http.StatusCreated) - } else { - w.WriteHeader(http.StatusOK) - } - - out.Password = "" - - err = json.NewEncoder(w).Encode(out) - if err != nil { - plog.Warningf("forUser error encoding on %s", r.URL) - return - } - return - case "DELETE": - err := sh.sec.DeleteUser(user) - if err != nil { - writeError(w, r, err) - return - } - } -} - -type enabled struct { - Enabled bool `json:"enabled"` -} - -func (sh *authHandler) enableDisable(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET", "PUT", "DELETE") { - return - } - if !hasWriteRootAccess(sh.sec, r, sh.clientCertAuthEnabled) { - writeNoAuth(w, r) - return - } - w.Header().Set("X-Etcd-Cluster-ID", sh.cluster.ID().String()) - w.Header().Set("Content-Type", "application/json") - isEnabled := sh.sec.AuthEnabled() - switch r.Method { - case "GET": - jsonDict := enabled{isEnabled} - err := json.NewEncoder(w).Encode(jsonDict) - if err != nil { - plog.Warningf("error encoding auth state on %s", r.URL) - } - case "PUT": - err := sh.sec.EnableAuth() - if err != nil { - writeError(w, r, err) - return - } - case "DELETE": - err := sh.sec.DisableAuth() - if err != nil { - writeError(w, r, err) - return - } - } -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v2http/doc.go b/vendor/github.com/coreos/etcd/etcdserver/api/v2http/doc.go deleted file mode 100644 index 475c4b1f95a3..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v2http/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v2http provides etcd client and server implementations. -package v2http diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v2http/http.go b/vendor/github.com/coreos/etcd/etcdserver/api/v2http/http.go deleted file mode 100644 index 589c172dbbb4..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v2http/http.go +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2http - -import ( - "math" - "net/http" - "strings" - "time" - - "github.com/coreos/etcd/etcdserver/api/etcdhttp" - "github.com/coreos/etcd/etcdserver/api/v2http/httptypes" - "github.com/coreos/etcd/etcdserver/auth" - "github.com/coreos/etcd/pkg/logutil" - - "github.com/coreos/pkg/capnslog" -) - -const ( - // time to wait for a Watch request - defaultWatchTimeout = time.Duration(math.MaxInt64) -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdserver/api/v2http") - mlog = logutil.NewMergeLogger(plog) -) - -func writeError(w http.ResponseWriter, r *http.Request, err error) { - if err == nil { - return - } - if e, ok := err.(auth.Error); ok { - herr := httptypes.NewHTTPError(e.HTTPStatus(), e.Error()) - if et := herr.WriteTo(w); et != nil { - plog.Debugf("error writing HTTPError (%v) to %s", et, r.RemoteAddr) - } - return - } - etcdhttp.WriteError(w, r, err) -} - -// allowMethod verifies that the given method is one of the allowed methods, -// and if not, it writes an error to w. A boolean is returned indicating -// whether or not the method is allowed. -func allowMethod(w http.ResponseWriter, m string, ms ...string) bool { - for _, meth := range ms { - if m == meth { - return true - } - } - w.Header().Set("Allow", strings.Join(ms, ",")) - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return false -} - -func requestLogger(handler http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - plog.Debugf("[%s] %s remote:%s", r.Method, r.RequestURI, r.RemoteAddr) - handler.ServeHTTP(w, r) - }) -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v2http/httptypes/errors.go b/vendor/github.com/coreos/etcd/etcdserver/api/v2http/httptypes/errors.go deleted file mode 100644 index 0657604ca976..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v2http/httptypes/errors.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package httptypes - -import ( - "encoding/json" - "net/http" - - "github.com/coreos/pkg/capnslog" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdserver/api/v2http/httptypes") -) - -type HTTPError struct { - Message string `json:"message"` - // Code is the HTTP status code - Code int `json:"-"` -} - -func (e HTTPError) Error() string { - return e.Message -} - -func (e HTTPError) WriteTo(w http.ResponseWriter) error { - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(e.Code) - b, err := json.Marshal(e) - if err != nil { - plog.Panicf("marshal HTTPError should never fail (%v)", err) - } - if _, err := w.Write(b); err != nil { - return err - } - return nil -} - -func NewHTTPError(code int, m string) *HTTPError { - return &HTTPError{ - Message: m, - Code: code, - } -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v2http/httptypes/member.go b/vendor/github.com/coreos/etcd/etcdserver/api/v2http/httptypes/member.go deleted file mode 100644 index 738d74432f84..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v2http/httptypes/member.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package httptypes defines how etcd's HTTP API entities are serialized to and -// deserialized from JSON. -package httptypes - -import ( - "encoding/json" - - "github.com/coreos/etcd/pkg/types" -) - -type Member struct { - ID string `json:"id"` - Name string `json:"name"` - PeerURLs []string `json:"peerURLs"` - ClientURLs []string `json:"clientURLs"` -} - -type MemberCreateRequest struct { - PeerURLs types.URLs -} - -type MemberUpdateRequest struct { - MemberCreateRequest -} - -func (m *MemberCreateRequest) UnmarshalJSON(data []byte) error { - s := struct { - PeerURLs []string `json:"peerURLs"` - }{} - - err := json.Unmarshal(data, &s) - if err != nil { - return err - } - - urls, err := types.NewURLs(s.PeerURLs) - if err != nil { - return err - } - - m.PeerURLs = urls - return nil -} - -type MemberCollection []Member - -func (c *MemberCollection) MarshalJSON() ([]byte, error) { - d := struct { - Members []Member `json:"members"` - }{ - Members: []Member(*c), - } - - return json.Marshal(d) -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v2http/metrics.go b/vendor/github.com/coreos/etcd/etcdserver/api/v2http/metrics.go deleted file mode 100644 index fdfb0c6070f9..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v2http/metrics.go +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2http - -import ( - "strconv" - "time" - - "net/http" - - etcdErr "github.com/coreos/etcd/error" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/v2http/httptypes" - "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/prometheus/client_golang/prometheus" -) - -var ( - incomingEvents = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "http", - Name: "received_total", - Help: "Counter of requests received into the system (successfully parsed and authd).", - }, []string{"method"}) - - failedEvents = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "http", - Name: "failed_total", - Help: "Counter of handle failures of requests (non-watches), by method (GET/PUT etc.) and code (400, 500 etc.).", - }, []string{"method", "code"}) - - successfulEventsHandlingTime = prometheus.NewHistogramVec( - prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "http", - Name: "successful_duration_seconds", - Help: "Bucketed histogram of processing time (s) of successfully handled requests (non-watches), by method (GET/PUT etc.).", - Buckets: prometheus.ExponentialBuckets(0.0005, 2, 13), - }, []string{"method"}) -) - -func init() { - prometheus.MustRegister(incomingEvents) - prometheus.MustRegister(failedEvents) - prometheus.MustRegister(successfulEventsHandlingTime) -} - -func reportRequestReceived(request etcdserverpb.Request) { - incomingEvents.WithLabelValues(methodFromRequest(request)).Inc() -} - -func reportRequestCompleted(request etcdserverpb.Request, response etcdserver.Response, startTime time.Time) { - method := methodFromRequest(request) - successfulEventsHandlingTime.WithLabelValues(method).Observe(time.Since(startTime).Seconds()) -} - -func reportRequestFailed(request etcdserverpb.Request, err error) { - method := methodFromRequest(request) - failedEvents.WithLabelValues(method, strconv.Itoa(codeFromError(err))).Inc() -} - -func methodFromRequest(request etcdserverpb.Request) string { - if request.Method == "GET" && request.Quorum { - return "QGET" - } - return request.Method -} - -func codeFromError(err error) int { - if err == nil { - return http.StatusInternalServerError - } - switch e := err.(type) { - case *etcdErr.Error: - return (*etcdErr.Error)(e).StatusCode() - case *httptypes.HTTPError: - return (*httptypes.HTTPError)(e).Code - default: - return http.StatusInternalServerError - } -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v2v3/cluster.go b/vendor/github.com/coreos/etcd/etcdserver/api/v2v3/cluster.go deleted file mode 100644 index b53e6d7c8b55..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v2v3/cluster.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2v3 - -import ( - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/pkg/types" - - "github.com/coreos/go-semver/semver" -) - -func (s *v2v3Server) ID() types.ID { - // TODO: use an actual member ID - return types.ID(0xe7cd2f00d) -} -func (s *v2v3Server) ClientURLs() []string { panic("STUB") } -func (s *v2v3Server) Members() []*membership.Member { panic("STUB") } -func (s *v2v3Server) Member(id types.ID) *membership.Member { panic("STUB") } -func (s *v2v3Server) Version() *semver.Version { panic("STUB") } diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v2v3/doc.go b/vendor/github.com/coreos/etcd/etcdserver/api/v2v3/doc.go deleted file mode 100644 index 2ff372f18760..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v2v3/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v2v3 provides a ServerV2 implementation backed by clientv3.Client. -package v2v3 diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v2v3/server.go b/vendor/github.com/coreos/etcd/etcdserver/api/v2v3/server.go deleted file mode 100644 index 2ef63ce68444..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v2v3/server.go +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2v3 - -import ( - "context" - "net/http" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/pkg/types" - - "github.com/coreos/go-semver/semver" -) - -type fakeStats struct{} - -func (s *fakeStats) SelfStats() []byte { return nil } -func (s *fakeStats) LeaderStats() []byte { return nil } -func (s *fakeStats) StoreStats() []byte { return nil } - -type v2v3Server struct { - c *clientv3.Client - store *v2v3Store - fakeStats -} - -func NewServer(c *clientv3.Client, pfx string) etcdserver.ServerPeer { - return &v2v3Server{c: c, store: newStore(c, pfx)} -} - -func (s *v2v3Server) ClientCertAuthEnabled() bool { return false } - -func (s *v2v3Server) LeaseHandler() http.Handler { panic("STUB: lease handler") } -func (s *v2v3Server) RaftHandler() http.Handler { panic("STUB: raft handler") } - -func (s *v2v3Server) Leader() types.ID { - ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second) - defer cancel() - resp, err := s.c.Status(ctx, s.c.Endpoints()[0]) - if err != nil { - return 0 - } - return types.ID(resp.Leader) -} - -func (s *v2v3Server) AddMember(ctx context.Context, memb membership.Member) ([]*membership.Member, error) { - resp, err := s.c.MemberAdd(ctx, memb.PeerURLs) - if err != nil { - return nil, err - } - return v3MembersToMembership(resp.Members), nil -} - -func (s *v2v3Server) RemoveMember(ctx context.Context, id uint64) ([]*membership.Member, error) { - resp, err := s.c.MemberRemove(ctx, id) - if err != nil { - return nil, err - } - return v3MembersToMembership(resp.Members), nil -} - -func (s *v2v3Server) UpdateMember(ctx context.Context, m membership.Member) ([]*membership.Member, error) { - resp, err := s.c.MemberUpdate(ctx, uint64(m.ID), m.PeerURLs) - if err != nil { - return nil, err - } - return v3MembersToMembership(resp.Members), nil -} - -func v3MembersToMembership(v3membs []*pb.Member) []*membership.Member { - membs := make([]*membership.Member, len(v3membs)) - for i, m := range v3membs { - membs[i] = &membership.Member{ - ID: types.ID(m.ID), - RaftAttributes: membership.RaftAttributes{ - PeerURLs: m.PeerURLs, - }, - Attributes: membership.Attributes{ - Name: m.Name, - ClientURLs: m.ClientURLs, - }, - } - } - return membs -} - -func (s *v2v3Server) ClusterVersion() *semver.Version { return s.Version() } -func (s *v2v3Server) Cluster() api.Cluster { return s } -func (s *v2v3Server) Alarms() []*pb.AlarmMember { return nil } - -func (s *v2v3Server) Do(ctx context.Context, r pb.Request) (etcdserver.Response, error) { - applier := etcdserver.NewApplierV2(s.store, nil) - reqHandler := etcdserver.NewStoreRequestV2Handler(s.store, applier) - req := (*etcdserver.RequestV2)(&r) - resp, err := req.Handle(ctx, reqHandler) - if resp.Err != nil { - return resp, resp.Err - } - return resp, err -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v2v3/store.go b/vendor/github.com/coreos/etcd/etcdserver/api/v2v3/store.go deleted file mode 100644 index 444f93f3a8e7..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v2v3/store.go +++ /dev/null @@ -1,620 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2v3 - -import ( - "context" - "fmt" - "path" - "strings" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/concurrency" - etcdErr "github.com/coreos/etcd/error" - "github.com/coreos/etcd/mvcc/mvccpb" - "github.com/coreos/etcd/store" -) - -// store implements the Store interface for V2 using -// a v3 client. -type v2v3Store struct { - c *clientv3.Client - // pfx is the v3 prefix where keys should be stored. - pfx string - ctx context.Context -} - -const maxPathDepth = 63 - -var errUnsupported = fmt.Errorf("TTLs are unsupported") - -func NewStore(c *clientv3.Client, pfx string) store.Store { return newStore(c, pfx) } - -func newStore(c *clientv3.Client, pfx string) *v2v3Store { return &v2v3Store{c, pfx, c.Ctx()} } - -func (s *v2v3Store) Index() uint64 { panic("STUB") } - -func (s *v2v3Store) Get(nodePath string, recursive, sorted bool) (*store.Event, error) { - key := s.mkPath(nodePath) - resp, err := s.c.Txn(s.ctx).Then( - clientv3.OpGet(key+"/"), - clientv3.OpGet(key), - ).Commit() - if err != nil { - return nil, err - } - - if kvs := resp.Responses[0].GetResponseRange().Kvs; len(kvs) != 0 || isRoot(nodePath) { - nodes, err := s.getDir(nodePath, recursive, sorted, resp.Header.Revision) - if err != nil { - return nil, err - } - cidx, midx := uint64(0), uint64(0) - if len(kvs) > 0 { - cidx, midx = mkV2Rev(kvs[0].CreateRevision), mkV2Rev(kvs[0].ModRevision) - } - return &store.Event{ - Action: store.Get, - Node: &store.NodeExtern{ - Key: nodePath, - Dir: true, - Nodes: nodes, - CreatedIndex: cidx, - ModifiedIndex: midx, - }, - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil - } - - kvs := resp.Responses[1].GetResponseRange().Kvs - if len(kvs) == 0 { - return nil, etcdErr.NewError(etcdErr.EcodeKeyNotFound, nodePath, mkV2Rev(resp.Header.Revision)) - } - - return &store.Event{ - Action: store.Get, - Node: s.mkV2Node(kvs[0]), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) getDir(nodePath string, recursive, sorted bool, rev int64) ([]*store.NodeExtern, error) { - rootNodes, err := s.getDirDepth(nodePath, 1, rev) - if err != nil || !recursive { - return rootNodes, err - } - nextNodes := rootNodes - nodes := make(map[string]*store.NodeExtern) - // Breadth walk the subdirectories - for i := 2; len(nextNodes) > 0; i++ { - for _, n := range nextNodes { - nodes[n.Key] = n - if parent := nodes[path.Dir(n.Key)]; parent != nil { - parent.Nodes = append(parent.Nodes, n) - } - } - if nextNodes, err = s.getDirDepth(nodePath, i, rev); err != nil { - return nil, err - } - } - return rootNodes, nil -} - -func (s *v2v3Store) getDirDepth(nodePath string, depth int, rev int64) ([]*store.NodeExtern, error) { - pd := s.mkPathDepth(nodePath, depth) - resp, err := s.c.Get(s.ctx, pd, clientv3.WithPrefix(), clientv3.WithRev(rev)) - if err != nil { - return nil, err - } - - nodes := make([]*store.NodeExtern, len(resp.Kvs)) - for i, kv := range resp.Kvs { - nodes[i] = s.mkV2Node(kv) - } - return nodes, nil -} - -func (s *v2v3Store) Set( - nodePath string, - dir bool, - value string, - expireOpts store.TTLOptionSet, -) (*store.Event, error) { - if expireOpts.Refresh || !expireOpts.ExpireTime.IsZero() { - return nil, errUnsupported - } - - if isRoot(nodePath) { - return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, nodePath, 0) - } - - ecode := 0 - applyf := func(stm concurrency.STM) error { - parent := path.Dir(nodePath) - if !isRoot(parent) && stm.Rev(s.mkPath(parent)+"/") == 0 { - ecode = etcdErr.EcodeKeyNotFound - return nil - } - - key := s.mkPath(nodePath) - if dir { - if stm.Rev(key) != 0 { - // exists as non-dir - ecode = etcdErr.EcodeNotDir - return nil - } - key = key + "/" - } else if stm.Rev(key+"/") != 0 { - ecode = etcdErr.EcodeNotFile - return nil - } - stm.Put(key, value, clientv3.WithPrevKV()) - stm.Put(s.mkActionKey(), store.Set) - return nil - } - - resp, err := s.newSTM(applyf) - if err != nil { - return nil, err - } - if ecode != 0 { - return nil, etcdErr.NewError(ecode, nodePath, mkV2Rev(resp.Header.Revision)) - } - - createRev := resp.Header.Revision - var pn *store.NodeExtern - if pkv := prevKeyFromPuts(resp); pkv != nil { - pn = s.mkV2Node(pkv) - createRev = pkv.CreateRevision - } - - vp := &value - if dir { - vp = nil - } - return &store.Event{ - Action: store.Set, - Node: &store.NodeExtern{ - Key: nodePath, - Value: vp, - Dir: dir, - ModifiedIndex: mkV2Rev(resp.Header.Revision), - CreatedIndex: mkV2Rev(createRev), - }, - PrevNode: pn, - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) Update(nodePath, newValue string, expireOpts store.TTLOptionSet) (*store.Event, error) { - if isRoot(nodePath) { - return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, nodePath, 0) - } - - if expireOpts.Refresh || !expireOpts.ExpireTime.IsZero() { - return nil, errUnsupported - } - - key := s.mkPath(nodePath) - ecode := 0 - applyf := func(stm concurrency.STM) error { - if rev := stm.Rev(key + "/"); rev != 0 { - ecode = etcdErr.EcodeNotFile - return nil - } - if rev := stm.Rev(key); rev == 0 { - ecode = etcdErr.EcodeKeyNotFound - return nil - } - stm.Put(key, newValue, clientv3.WithPrevKV()) - stm.Put(s.mkActionKey(), store.Update) - return nil - } - - resp, err := s.newSTM(applyf) - if err != nil { - return nil, err - } - if ecode != 0 { - return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, mkV2Rev(resp.Header.Revision)) - } - - pkv := prevKeyFromPuts(resp) - return &store.Event{ - Action: store.Update, - Node: &store.NodeExtern{ - Key: nodePath, - Value: &newValue, - ModifiedIndex: mkV2Rev(resp.Header.Revision), - CreatedIndex: mkV2Rev(pkv.CreateRevision), - }, - PrevNode: s.mkV2Node(pkv), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) Create( - nodePath string, - dir bool, - value string, - unique bool, - expireOpts store.TTLOptionSet, -) (*store.Event, error) { - if isRoot(nodePath) { - return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, nodePath, 0) - } - if expireOpts.Refresh || !expireOpts.ExpireTime.IsZero() { - return nil, errUnsupported - } - ecode := 0 - applyf := func(stm concurrency.STM) error { - ecode = 0 - key := s.mkPath(nodePath) - if unique { - // append unique item under the node path - for { - key = nodePath + "/" + fmt.Sprintf("%020s", time.Now()) - key = path.Clean(path.Join("/", key)) - key = s.mkPath(key) - if stm.Rev(key) == 0 { - break - } - } - } - if stm.Rev(key) > 0 || stm.Rev(key+"/") > 0 { - ecode = etcdErr.EcodeNodeExist - return nil - } - // build path if any directories in path do not exist - dirs := []string{} - for p := path.Dir(nodePath); !isRoot(p); p = path.Dir(p) { - pp := s.mkPath(p) - if stm.Rev(pp) > 0 { - ecode = etcdErr.EcodeNotDir - return nil - } - if stm.Rev(pp+"/") == 0 { - dirs = append(dirs, pp+"/") - } - } - for _, d := range dirs { - stm.Put(d, "") - } - - if dir { - // directories marked with extra slash in key name - key += "/" - } - stm.Put(key, value) - stm.Put(s.mkActionKey(), store.Create) - return nil - } - - resp, err := s.newSTM(applyf) - if err != nil { - return nil, err - } - if ecode != 0 { - return nil, etcdErr.NewError(ecode, nodePath, mkV2Rev(resp.Header.Revision)) - } - - var v *string - if !dir { - v = &value - } - - return &store.Event{ - Action: store.Create, - Node: &store.NodeExtern{ - Key: nodePath, - Value: v, - Dir: dir, - ModifiedIndex: mkV2Rev(resp.Header.Revision), - CreatedIndex: mkV2Rev(resp.Header.Revision), - }, - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) CompareAndSwap( - nodePath string, - prevValue string, - prevIndex uint64, - value string, - expireOpts store.TTLOptionSet, -) (*store.Event, error) { - if isRoot(nodePath) { - return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, nodePath, 0) - } - if expireOpts.Refresh || !expireOpts.ExpireTime.IsZero() { - return nil, errUnsupported - } - - key := s.mkPath(nodePath) - resp, err := s.c.Txn(s.ctx).If( - s.mkCompare(nodePath, prevValue, prevIndex)..., - ).Then( - clientv3.OpPut(key, value, clientv3.WithPrevKV()), - clientv3.OpPut(s.mkActionKey(), store.CompareAndSwap), - ).Else( - clientv3.OpGet(key), - clientv3.OpGet(key+"/"), - ).Commit() - - if err != nil { - return nil, err - } - if !resp.Succeeded { - return nil, compareFail(nodePath, prevValue, prevIndex, resp) - } - - pkv := resp.Responses[0].GetResponsePut().PrevKv - return &store.Event{ - Action: store.CompareAndSwap, - Node: &store.NodeExtern{ - Key: nodePath, - Value: &value, - CreatedIndex: mkV2Rev(pkv.CreateRevision), - ModifiedIndex: mkV2Rev(resp.Header.Revision), - }, - PrevNode: s.mkV2Node(pkv), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) Delete(nodePath string, dir, recursive bool) (*store.Event, error) { - if isRoot(nodePath) { - return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, nodePath, 0) - } - if !dir && !recursive { - return s.deleteNode(nodePath) - } - if !recursive { - return s.deleteEmptyDir(nodePath) - } - - dels := make([]clientv3.Op, maxPathDepth+1) - dels[0] = clientv3.OpDelete(s.mkPath(nodePath)+"/", clientv3.WithPrevKV()) - for i := 1; i < maxPathDepth; i++ { - dels[i] = clientv3.OpDelete(s.mkPathDepth(nodePath, i), clientv3.WithPrefix()) - } - dels[maxPathDepth] = clientv3.OpPut(s.mkActionKey(), store.Delete) - - resp, err := s.c.Txn(s.ctx).If( - clientv3.Compare(clientv3.Version(s.mkPath(nodePath)+"/"), ">", 0), - clientv3.Compare(clientv3.Version(s.mkPathDepth(nodePath, maxPathDepth)+"/"), "=", 0), - ).Then( - dels..., - ).Commit() - if err != nil { - return nil, err - } - if !resp.Succeeded { - return nil, etcdErr.NewError(etcdErr.EcodeNodeExist, nodePath, mkV2Rev(resp.Header.Revision)) - } - dresp := resp.Responses[0].GetResponseDeleteRange() - return &store.Event{ - Action: store.Delete, - PrevNode: s.mkV2Node(dresp.PrevKvs[0]), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) deleteEmptyDir(nodePath string) (*store.Event, error) { - resp, err := s.c.Txn(s.ctx).If( - clientv3.Compare(clientv3.Version(s.mkPathDepth(nodePath, 1)), "=", 0).WithPrefix(), - ).Then( - clientv3.OpDelete(s.mkPath(nodePath)+"/", clientv3.WithPrevKV()), - clientv3.OpPut(s.mkActionKey(), store.Delete), - ).Commit() - if err != nil { - return nil, err - } - if !resp.Succeeded { - return nil, etcdErr.NewError(etcdErr.EcodeDirNotEmpty, nodePath, mkV2Rev(resp.Header.Revision)) - } - dresp := resp.Responses[0].GetResponseDeleteRange() - if len(dresp.PrevKvs) == 0 { - return nil, etcdErr.NewError(etcdErr.EcodeNodeExist, nodePath, mkV2Rev(resp.Header.Revision)) - } - return &store.Event{ - Action: store.Delete, - PrevNode: s.mkV2Node(dresp.PrevKvs[0]), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) deleteNode(nodePath string) (*store.Event, error) { - resp, err := s.c.Txn(s.ctx).If( - clientv3.Compare(clientv3.Version(s.mkPath(nodePath)+"/"), "=", 0), - ).Then( - clientv3.OpDelete(s.mkPath(nodePath), clientv3.WithPrevKV()), - clientv3.OpPut(s.mkActionKey(), store.Delete), - ).Commit() - if err != nil { - return nil, err - } - if !resp.Succeeded { - return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, mkV2Rev(resp.Header.Revision)) - } - pkvs := resp.Responses[0].GetResponseDeleteRange().PrevKvs - if len(pkvs) == 0 { - return nil, etcdErr.NewError(etcdErr.EcodeKeyNotFound, nodePath, mkV2Rev(resp.Header.Revision)) - } - pkv := pkvs[0] - return &store.Event{ - Action: store.Delete, - Node: &store.NodeExtern{ - Key: nodePath, - CreatedIndex: mkV2Rev(pkv.CreateRevision), - ModifiedIndex: mkV2Rev(resp.Header.Revision), - }, - PrevNode: s.mkV2Node(pkv), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) CompareAndDelete(nodePath, prevValue string, prevIndex uint64) (*store.Event, error) { - if isRoot(nodePath) { - return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, nodePath, 0) - } - - key := s.mkPath(nodePath) - resp, err := s.c.Txn(s.ctx).If( - s.mkCompare(nodePath, prevValue, prevIndex)..., - ).Then( - clientv3.OpDelete(key, clientv3.WithPrevKV()), - clientv3.OpPut(s.mkActionKey(), store.CompareAndDelete), - ).Else( - clientv3.OpGet(key), - clientv3.OpGet(key+"/"), - ).Commit() - - if err != nil { - return nil, err - } - if !resp.Succeeded { - return nil, compareFail(nodePath, prevValue, prevIndex, resp) - } - - // len(pkvs) > 1 since txn only succeeds when key exists - pkv := resp.Responses[0].GetResponseDeleteRange().PrevKvs[0] - return &store.Event{ - Action: store.CompareAndDelete, - Node: &store.NodeExtern{ - Key: nodePath, - CreatedIndex: mkV2Rev(pkv.CreateRevision), - ModifiedIndex: mkV2Rev(resp.Header.Revision), - }, - PrevNode: s.mkV2Node(pkv), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func compareFail(nodePath, prevValue string, prevIndex uint64, resp *clientv3.TxnResponse) error { - if dkvs := resp.Responses[1].GetResponseRange().Kvs; len(dkvs) > 0 { - return etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, mkV2Rev(resp.Header.Revision)) - } - kvs := resp.Responses[0].GetResponseRange().Kvs - if len(kvs) == 0 { - return etcdErr.NewError(etcdErr.EcodeKeyNotFound, nodePath, mkV2Rev(resp.Header.Revision)) - } - kv := kvs[0] - indexMatch := (prevIndex == 0 || kv.ModRevision == int64(prevIndex)) - valueMatch := (prevValue == "" || string(kv.Value) == prevValue) - var cause string - switch { - case indexMatch && !valueMatch: - cause = fmt.Sprintf("[%v != %v]", prevValue, string(kv.Value)) - case valueMatch && !indexMatch: - cause = fmt.Sprintf("[%v != %v]", prevIndex, kv.ModRevision) - default: - cause = fmt.Sprintf("[%v != %v] [%v != %v]", prevValue, string(kv.Value), prevIndex, kv.ModRevision) - } - return etcdErr.NewError(etcdErr.EcodeTestFailed, cause, mkV2Rev(resp.Header.Revision)) -} - -func (s *v2v3Store) mkCompare(nodePath, prevValue string, prevIndex uint64) []clientv3.Cmp { - key := s.mkPath(nodePath) - cmps := []clientv3.Cmp{clientv3.Compare(clientv3.Version(key), ">", 0)} - if prevIndex != 0 { - cmps = append(cmps, clientv3.Compare(clientv3.ModRevision(key), "=", mkV3Rev(prevIndex))) - } - if prevValue != "" { - cmps = append(cmps, clientv3.Compare(clientv3.Value(key), "=", prevValue)) - } - return cmps -} - -func (s *v2v3Store) JsonStats() []byte { panic("STUB") } -func (s *v2v3Store) DeleteExpiredKeys(cutoff time.Time) { panic("STUB") } - -func (s *v2v3Store) Version() int { return 2 } - -// TODO: move this out of the Store interface? - -func (s *v2v3Store) Save() ([]byte, error) { panic("STUB") } -func (s *v2v3Store) Recovery(state []byte) error { panic("STUB") } -func (s *v2v3Store) Clone() store.Store { panic("STUB") } -func (s *v2v3Store) SaveNoCopy() ([]byte, error) { panic("STUB") } -func (s *v2v3Store) HasTTLKeys() bool { panic("STUB") } - -func (s *v2v3Store) mkPath(nodePath string) string { return s.mkPathDepth(nodePath, 0) } - -func (s *v2v3Store) mkNodePath(p string) string { - return path.Clean(p[len(s.pfx)+len("/k/000/"):]) -} - -// mkPathDepth makes a path to a key that encodes its directory depth -// for fast directory listing. If a depth is provided, it is added -// to the computed depth. -func (s *v2v3Store) mkPathDepth(nodePath string, depth int) string { - normalForm := path.Clean(path.Join("/", nodePath)) - n := strings.Count(normalForm, "/") + depth - return fmt.Sprintf("%s/%03d/k/%s", s.pfx, n, normalForm) -} - -func (s *v2v3Store) mkActionKey() string { return s.pfx + "/act" } - -func isRoot(s string) bool { return len(s) == 0 || s == "/" || s == "/0" || s == "/1" } - -func mkV2Rev(v3Rev int64) uint64 { - if v3Rev == 0 { - return 0 - } - return uint64(v3Rev - 1) -} - -func mkV3Rev(v2Rev uint64) int64 { - if v2Rev == 0 { - return 0 - } - return int64(v2Rev + 1) -} - -// mkV2Node creates a V2 NodeExtern from a V3 KeyValue -func (s *v2v3Store) mkV2Node(kv *mvccpb.KeyValue) *store.NodeExtern { - if kv == nil { - return nil - } - n := &store.NodeExtern{ - Key: string(s.mkNodePath(string(kv.Key))), - Dir: kv.Key[len(kv.Key)-1] == '/', - CreatedIndex: mkV2Rev(kv.CreateRevision), - ModifiedIndex: mkV2Rev(kv.ModRevision), - } - if !n.Dir { - v := string(kv.Value) - n.Value = &v - } - return n -} - -// prevKeyFromPuts gets the prev key that is being put; ignores -// the put action response. -func prevKeyFromPuts(resp *clientv3.TxnResponse) *mvccpb.KeyValue { - for _, r := range resp.Responses { - pkv := r.GetResponsePut().PrevKv - if pkv != nil && pkv.CreateRevision > 0 { - return pkv - } - } - return nil -} - -func (s *v2v3Store) newSTM(applyf func(concurrency.STM) error) (*clientv3.TxnResponse, error) { - return concurrency.NewSTM(s.c, applyf, concurrency.WithIsolation(concurrency.Serializable)) -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v2v3/watcher.go b/vendor/github.com/coreos/etcd/etcdserver/api/v2v3/watcher.go deleted file mode 100644 index 1c2680e744a1..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v2v3/watcher.go +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2v3 - -import ( - "context" - "strings" - - "github.com/coreos/etcd/clientv3" - etcdErr "github.com/coreos/etcd/error" - "github.com/coreos/etcd/store" -) - -func (s *v2v3Store) Watch(prefix string, recursive, stream bool, sinceIndex uint64) (store.Watcher, error) { - ctx, cancel := context.WithCancel(s.ctx) - wch := s.c.Watch( - ctx, - // TODO: very pricey; use a single store-wide watch in future - s.pfx, - clientv3.WithPrefix(), - clientv3.WithRev(int64(sinceIndex)), - clientv3.WithCreatedNotify(), - clientv3.WithPrevKV()) - resp, ok := <-wch - if err := resp.Err(); err != nil || !ok { - cancel() - return nil, etcdErr.NewError(etcdErr.EcodeRaftInternal, prefix, 0) - } - - evc, donec := make(chan *store.Event), make(chan struct{}) - go func() { - defer func() { - close(evc) - close(donec) - }() - for resp := range wch { - for _, ev := range s.mkV2Events(resp) { - k := ev.Node.Key - if recursive { - if !strings.HasPrefix(k, prefix) { - continue - } - // accept events on hidden keys given in prefix - k = strings.Replace(k, prefix, "/", 1) - // ignore hidden keys deeper than prefix - if strings.Contains(k, "/_") { - continue - } - } - if !recursive && k != prefix { - continue - } - select { - case evc <- ev: - case <-ctx.Done(): - return - } - if !stream { - return - } - } - } - }() - - return &v2v3Watcher{ - startRev: resp.Header.Revision, - evc: evc, - donec: donec, - cancel: cancel, - }, nil -} - -func (s *v2v3Store) mkV2Events(wr clientv3.WatchResponse) (evs []*store.Event) { - ak := s.mkActionKey() - for _, rev := range mkRevs(wr) { - var act, key *clientv3.Event - for _, ev := range rev { - if string(ev.Kv.Key) == ak { - act = ev - } else if key != nil && len(key.Kv.Key) < len(ev.Kv.Key) { - // use longest key to ignore intermediate new - // directories from Create. - key = ev - } else if key == nil { - key = ev - } - } - v2ev := &store.Event{ - Action: string(act.Kv.Value), - Node: s.mkV2Node(key.Kv), - PrevNode: s.mkV2Node(key.PrevKv), - EtcdIndex: mkV2Rev(wr.Header.Revision), - } - evs = append(evs, v2ev) - } - return evs -} - -func mkRevs(wr clientv3.WatchResponse) (revs [][]*clientv3.Event) { - var curRev []*clientv3.Event - for _, ev := range wr.Events { - if curRev != nil && ev.Kv.ModRevision != curRev[0].Kv.ModRevision { - revs = append(revs, curRev) - curRev = nil - } - curRev = append(curRev, ev) - } - if curRev != nil { - revs = append(revs, curRev) - } - return revs -} - -type v2v3Watcher struct { - startRev int64 - evc chan *store.Event - donec chan struct{} - cancel context.CancelFunc -} - -func (w *v2v3Watcher) StartIndex() uint64 { return mkV2Rev(w.startRev) } - -func (w *v2v3Watcher) Remove() { - w.cancel() - <-w.donec -} - -func (w *v2v3Watcher) EventChan() chan *store.Event { return w.evc } diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3client/doc.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3client/doc.go deleted file mode 100644 index 310715f5cd74..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3client/doc.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v3client provides clientv3 interfaces from an etcdserver. -// -// Use v3client by creating an EtcdServer instance, then wrapping it with v3client.New: -// -// import ( -// "context" -// -// "github.com/coreos/etcd/embed" -// "github.com/coreos/etcd/etcdserver/api/v3client" -// ) -// -// ... -// -// // create an embedded EtcdServer from the default configuration -// cfg := embed.NewConfig() -// cfg.Dir = "default.etcd" -// e, err := embed.StartEtcd(cfg) -// if err != nil { -// // handle error! -// } -// -// // wrap the EtcdServer with v3client -// cli := v3client.New(e.Server) -// -// // use like an ordinary clientv3 -// resp, err := cli.Put(context.TODO(), "some-key", "it works!") -// if err != nil { -// // handle error! -// } -// -package v3client diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3client/v3client.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3client/v3client.go deleted file mode 100644 index ab48ea75b91b..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3client/v3client.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3client - -import ( - "context" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/v3rpc" - "github.com/coreos/etcd/proxy/grpcproxy/adapter" -) - -// New creates a clientv3 client that wraps an in-process EtcdServer. Instead -// of making gRPC calls through sockets, the client makes direct function calls -// to the etcd server through its api/v3rpc function interfaces. -func New(s *etcdserver.EtcdServer) *clientv3.Client { - c := clientv3.NewCtxClient(context.Background()) - - kvc := adapter.KvServerToKvClient(v3rpc.NewQuotaKVServer(s)) - c.KV = clientv3.NewKVFromKVClient(kvc, c) - - lc := adapter.LeaseServerToLeaseClient(v3rpc.NewQuotaLeaseServer(s)) - c.Lease = clientv3.NewLeaseFromLeaseClient(lc, c, time.Second) - - wc := adapter.WatchServerToWatchClient(v3rpc.NewWatchServer(s)) - c.Watcher = &watchWrapper{clientv3.NewWatchFromWatchClient(wc, c)} - - mc := adapter.MaintenanceServerToMaintenanceClient(v3rpc.NewMaintenanceServer(s)) - c.Maintenance = clientv3.NewMaintenanceFromMaintenanceClient(mc, c) - - clc := adapter.ClusterServerToClusterClient(v3rpc.NewClusterServer(s)) - c.Cluster = clientv3.NewClusterFromClusterClient(clc, c) - - // TODO: implement clientv3.Auth interface? - - return c -} - -// BlankContext implements Stringer on a context so the ctx string doesn't -// depend on the context's WithValue data, which tends to be unsynchronized -// (e.g., x/net/trace), causing ctx.String() to throw data races. -type blankContext struct{ context.Context } - -func (*blankContext) String() string { return "(blankCtx)" } - -// watchWrapper wraps clientv3 watch calls to blank out the context -// to avoid races on trace data. -type watchWrapper struct{ clientv3.Watcher } - -func (ww *watchWrapper) Watch(ctx context.Context, key string, opts ...clientv3.OpOption) clientv3.WatchChan { - return ww.Watcher.Watch(&blankContext{ctx}, key, opts...) -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3election/doc.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3election/doc.go deleted file mode 100644 index d6fefd741500..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3election/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v3election provides a v3 election service from an etcdserver. -package v3election diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3election/election.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3election/election.go deleted file mode 100644 index c66d7a38290d..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3election/election.go +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3election - -import ( - "context" - "errors" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/concurrency" - epb "github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb" -) - -// ErrMissingLeaderKey is returned when election API request -// is missing the "leader" field. -var ErrMissingLeaderKey = errors.New(`"leader" field must be provided`) - -type electionServer struct { - c *clientv3.Client -} - -func NewElectionServer(c *clientv3.Client) epb.ElectionServer { - return &electionServer{c} -} - -func (es *electionServer) Campaign(ctx context.Context, req *epb.CampaignRequest) (*epb.CampaignResponse, error) { - s, err := es.session(ctx, req.Lease) - if err != nil { - return nil, err - } - e := concurrency.NewElection(s, string(req.Name)) - if err = e.Campaign(ctx, string(req.Value)); err != nil { - return nil, err - } - return &epb.CampaignResponse{ - Header: e.Header(), - Leader: &epb.LeaderKey{ - Name: req.Name, - Key: []byte(e.Key()), - Rev: e.Rev(), - Lease: int64(s.Lease()), - }, - }, nil -} - -func (es *electionServer) Proclaim(ctx context.Context, req *epb.ProclaimRequest) (*epb.ProclaimResponse, error) { - if req.Leader == nil { - return nil, ErrMissingLeaderKey - } - s, err := es.session(ctx, req.Leader.Lease) - if err != nil { - return nil, err - } - e := concurrency.ResumeElection(s, string(req.Leader.Name), string(req.Leader.Key), req.Leader.Rev) - if err := e.Proclaim(ctx, string(req.Value)); err != nil { - return nil, err - } - return &epb.ProclaimResponse{Header: e.Header()}, nil -} - -func (es *electionServer) Observe(req *epb.LeaderRequest, stream epb.Election_ObserveServer) error { - s, err := es.session(stream.Context(), -1) - if err != nil { - return err - } - e := concurrency.NewElection(s, string(req.Name)) - ch := e.Observe(stream.Context()) - for stream.Context().Err() == nil { - select { - case <-stream.Context().Done(): - case resp, ok := <-ch: - if !ok { - return nil - } - lresp := &epb.LeaderResponse{Header: resp.Header, Kv: resp.Kvs[0]} - if err := stream.Send(lresp); err != nil { - return err - } - } - } - return stream.Context().Err() -} - -func (es *electionServer) Leader(ctx context.Context, req *epb.LeaderRequest) (*epb.LeaderResponse, error) { - s, err := es.session(ctx, -1) - if err != nil { - return nil, err - } - l, lerr := concurrency.NewElection(s, string(req.Name)).Leader(ctx) - if lerr != nil { - return nil, lerr - } - return &epb.LeaderResponse{Header: l.Header, Kv: l.Kvs[0]}, nil -} - -func (es *electionServer) Resign(ctx context.Context, req *epb.ResignRequest) (*epb.ResignResponse, error) { - if req.Leader == nil { - return nil, ErrMissingLeaderKey - } - s, err := es.session(ctx, req.Leader.Lease) - if err != nil { - return nil, err - } - e := concurrency.ResumeElection(s, string(req.Leader.Name), string(req.Leader.Key), req.Leader.Rev) - if err := e.Resign(ctx); err != nil { - return nil, err - } - return &epb.ResignResponse{Header: e.Header()}, nil -} - -func (es *electionServer) session(ctx context.Context, lease int64) (*concurrency.Session, error) { - s, err := concurrency.NewSession( - es.c, - concurrency.WithLease(clientv3.LeaseID(lease)), - concurrency.WithContext(ctx), - ) - if err != nil { - return nil, err - } - s.Orphan() - return s, nil -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb/gw/v3election.pb.gw.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb/gw/v3election.pb.gw.go deleted file mode 100644 index 58368bbfb30c..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb/gw/v3election.pb.gw.go +++ /dev/null @@ -1,313 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: etcdserver/api/v3election/v3electionpb/v3election.proto - -/* -Package v3electionpb is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package gw - -import ( - "github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb" - "io" - "net/http" - - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "golang.org/x/net/context" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/status" -) - -var _ codes.Code -var _ io.Reader -var _ status.Status -var _ = runtime.String -var _ = utilities.NewDoubleArray - -func request_Election_Campaign_0(ctx context.Context, marshaler runtime.Marshaler, client v3electionpb.ElectionClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3electionpb.CampaignRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Campaign(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Election_Proclaim_0(ctx context.Context, marshaler runtime.Marshaler, client v3electionpb.ElectionClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3electionpb.ProclaimRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Proclaim(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Election_Leader_0(ctx context.Context, marshaler runtime.Marshaler, client v3electionpb.ElectionClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3electionpb.LeaderRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Leader(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Election_Observe_0(ctx context.Context, marshaler runtime.Marshaler, client v3electionpb.ElectionClient, req *http.Request, pathParams map[string]string) (v3electionpb.Election_ObserveClient, runtime.ServerMetadata, error) { - var protoReq v3electionpb.LeaderRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - stream, err := client.Observe(ctx, &protoReq) - if err != nil { - return nil, metadata, err - } - header, err := stream.Header() - if err != nil { - return nil, metadata, err - } - metadata.HeaderMD = header - return stream, metadata, nil - -} - -func request_Election_Resign_0(ctx context.Context, marshaler runtime.Marshaler, client v3electionpb.ElectionClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3electionpb.ResignRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Resign(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -// RegisterElectionHandlerFromEndpoint is same as RegisterElectionHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterElectionHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterElectionHandler(ctx, mux, conn) -} - -// RegisterElectionHandler registers the http handlers for service Election to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterElectionHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterElectionHandlerClient(ctx, mux, v3electionpb.NewElectionClient(conn)) -} - -// RegisterElectionHandler registers the http handlers for service Election to "mux". -// The handlers forward requests to the grpc endpoint over the given implementation of "ElectionClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "ElectionClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "ElectionClient" to call the correct interceptors. -func RegisterElectionHandlerClient(ctx context.Context, mux *runtime.ServeMux, client v3electionpb.ElectionClient) error { - - mux.Handle("POST", pattern_Election_Campaign_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Election_Campaign_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Election_Campaign_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Election_Proclaim_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Election_Proclaim_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Election_Proclaim_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Election_Leader_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Election_Leader_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Election_Leader_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Election_Observe_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Election_Observe_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Election_Observe_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Election_Resign_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Election_Resign_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Election_Resign_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Election_Campaign_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "election", "campaign"}, "")) - - pattern_Election_Proclaim_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "election", "proclaim"}, "")) - - pattern_Election_Leader_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "election", "leader"}, "")) - - pattern_Election_Observe_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "election", "observe"}, "")) - - pattern_Election_Resign_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "election", "resign"}, "")) -) - -var ( - forward_Election_Campaign_0 = runtime.ForwardResponseMessage - - forward_Election_Proclaim_0 = runtime.ForwardResponseMessage - - forward_Election_Leader_0 = runtime.ForwardResponseMessage - - forward_Election_Observe_0 = runtime.ForwardResponseStream - - forward_Election_Resign_0 = runtime.ForwardResponseMessage -) diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb/v3election.pb.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb/v3election.pb.go deleted file mode 100644 index e298e452119d..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb/v3election.pb.go +++ /dev/null @@ -1,2079 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: v3election.proto - -/* - Package v3electionpb is a generated protocol buffer package. - - It is generated from these files: - v3election.proto - - It has these top-level messages: - CampaignRequest - CampaignResponse - LeaderKey - LeaderRequest - LeaderResponse - ResignRequest - ResignResponse - ProclaimRequest - ProclaimResponse -*/ -package v3electionpb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - etcdserverpb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - mvccpb "github.com/coreos/etcd/mvcc/mvccpb" - - context "golang.org/x/net/context" - - grpc "google.golang.org/grpc" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type CampaignRequest struct { - // name is the election's identifier for the campaign. - Name []byte `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - // lease is the ID of the lease attached to leadership of the election. If the - // lease expires or is revoked before resigning leadership, then the - // leadership is transferred to the next campaigner, if any. - Lease int64 `protobuf:"varint,2,opt,name=lease,proto3" json:"lease,omitempty"` - // value is the initial proclaimed value set when the campaigner wins the - // election. - Value []byte `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty"` -} - -func (m *CampaignRequest) Reset() { *m = CampaignRequest{} } -func (m *CampaignRequest) String() string { return proto.CompactTextString(m) } -func (*CampaignRequest) ProtoMessage() {} -func (*CampaignRequest) Descriptor() ([]byte, []int) { return fileDescriptorV3Election, []int{0} } - -func (m *CampaignRequest) GetName() []byte { - if m != nil { - return m.Name - } - return nil -} - -func (m *CampaignRequest) GetLease() int64 { - if m != nil { - return m.Lease - } - return 0 -} - -func (m *CampaignRequest) GetValue() []byte { - if m != nil { - return m.Value - } - return nil -} - -type CampaignResponse struct { - Header *etcdserverpb.ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // leader describes the resources used for holding leadereship of the election. - Leader *LeaderKey `protobuf:"bytes,2,opt,name=leader" json:"leader,omitempty"` -} - -func (m *CampaignResponse) Reset() { *m = CampaignResponse{} } -func (m *CampaignResponse) String() string { return proto.CompactTextString(m) } -func (*CampaignResponse) ProtoMessage() {} -func (*CampaignResponse) Descriptor() ([]byte, []int) { return fileDescriptorV3Election, []int{1} } - -func (m *CampaignResponse) GetHeader() *etcdserverpb.ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *CampaignResponse) GetLeader() *LeaderKey { - if m != nil { - return m.Leader - } - return nil -} - -type LeaderKey struct { - // name is the election identifier that correponds to the leadership key. - Name []byte `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - // key is an opaque key representing the ownership of the election. If the key - // is deleted, then leadership is lost. - Key []byte `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` - // rev is the creation revision of the key. It can be used to test for ownership - // of an election during transactions by testing the key's creation revision - // matches rev. - Rev int64 `protobuf:"varint,3,opt,name=rev,proto3" json:"rev,omitempty"` - // lease is the lease ID of the election leader. - Lease int64 `protobuf:"varint,4,opt,name=lease,proto3" json:"lease,omitempty"` -} - -func (m *LeaderKey) Reset() { *m = LeaderKey{} } -func (m *LeaderKey) String() string { return proto.CompactTextString(m) } -func (*LeaderKey) ProtoMessage() {} -func (*LeaderKey) Descriptor() ([]byte, []int) { return fileDescriptorV3Election, []int{2} } - -func (m *LeaderKey) GetName() []byte { - if m != nil { - return m.Name - } - return nil -} - -func (m *LeaderKey) GetKey() []byte { - if m != nil { - return m.Key - } - return nil -} - -func (m *LeaderKey) GetRev() int64 { - if m != nil { - return m.Rev - } - return 0 -} - -func (m *LeaderKey) GetLease() int64 { - if m != nil { - return m.Lease - } - return 0 -} - -type LeaderRequest struct { - // name is the election identifier for the leadership information. - Name []byte `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` -} - -func (m *LeaderRequest) Reset() { *m = LeaderRequest{} } -func (m *LeaderRequest) String() string { return proto.CompactTextString(m) } -func (*LeaderRequest) ProtoMessage() {} -func (*LeaderRequest) Descriptor() ([]byte, []int) { return fileDescriptorV3Election, []int{3} } - -func (m *LeaderRequest) GetName() []byte { - if m != nil { - return m.Name - } - return nil -} - -type LeaderResponse struct { - Header *etcdserverpb.ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // kv is the key-value pair representing the latest leader update. - Kv *mvccpb.KeyValue `protobuf:"bytes,2,opt,name=kv" json:"kv,omitempty"` -} - -func (m *LeaderResponse) Reset() { *m = LeaderResponse{} } -func (m *LeaderResponse) String() string { return proto.CompactTextString(m) } -func (*LeaderResponse) ProtoMessage() {} -func (*LeaderResponse) Descriptor() ([]byte, []int) { return fileDescriptorV3Election, []int{4} } - -func (m *LeaderResponse) GetHeader() *etcdserverpb.ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *LeaderResponse) GetKv() *mvccpb.KeyValue { - if m != nil { - return m.Kv - } - return nil -} - -type ResignRequest struct { - // leader is the leadership to relinquish by resignation. - Leader *LeaderKey `protobuf:"bytes,1,opt,name=leader" json:"leader,omitempty"` -} - -func (m *ResignRequest) Reset() { *m = ResignRequest{} } -func (m *ResignRequest) String() string { return proto.CompactTextString(m) } -func (*ResignRequest) ProtoMessage() {} -func (*ResignRequest) Descriptor() ([]byte, []int) { return fileDescriptorV3Election, []int{5} } - -func (m *ResignRequest) GetLeader() *LeaderKey { - if m != nil { - return m.Leader - } - return nil -} - -type ResignResponse struct { - Header *etcdserverpb.ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *ResignResponse) Reset() { *m = ResignResponse{} } -func (m *ResignResponse) String() string { return proto.CompactTextString(m) } -func (*ResignResponse) ProtoMessage() {} -func (*ResignResponse) Descriptor() ([]byte, []int) { return fileDescriptorV3Election, []int{6} } - -func (m *ResignResponse) GetHeader() *etcdserverpb.ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type ProclaimRequest struct { - // leader is the leadership hold on the election. - Leader *LeaderKey `protobuf:"bytes,1,opt,name=leader" json:"leader,omitempty"` - // value is an update meant to overwrite the leader's current value. - Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` -} - -func (m *ProclaimRequest) Reset() { *m = ProclaimRequest{} } -func (m *ProclaimRequest) String() string { return proto.CompactTextString(m) } -func (*ProclaimRequest) ProtoMessage() {} -func (*ProclaimRequest) Descriptor() ([]byte, []int) { return fileDescriptorV3Election, []int{7} } - -func (m *ProclaimRequest) GetLeader() *LeaderKey { - if m != nil { - return m.Leader - } - return nil -} - -func (m *ProclaimRequest) GetValue() []byte { - if m != nil { - return m.Value - } - return nil -} - -type ProclaimResponse struct { - Header *etcdserverpb.ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *ProclaimResponse) Reset() { *m = ProclaimResponse{} } -func (m *ProclaimResponse) String() string { return proto.CompactTextString(m) } -func (*ProclaimResponse) ProtoMessage() {} -func (*ProclaimResponse) Descriptor() ([]byte, []int) { return fileDescriptorV3Election, []int{8} } - -func (m *ProclaimResponse) GetHeader() *etcdserverpb.ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func init() { - proto.RegisterType((*CampaignRequest)(nil), "v3electionpb.CampaignRequest") - proto.RegisterType((*CampaignResponse)(nil), "v3electionpb.CampaignResponse") - proto.RegisterType((*LeaderKey)(nil), "v3electionpb.LeaderKey") - proto.RegisterType((*LeaderRequest)(nil), "v3electionpb.LeaderRequest") - proto.RegisterType((*LeaderResponse)(nil), "v3electionpb.LeaderResponse") - proto.RegisterType((*ResignRequest)(nil), "v3electionpb.ResignRequest") - proto.RegisterType((*ResignResponse)(nil), "v3electionpb.ResignResponse") - proto.RegisterType((*ProclaimRequest)(nil), "v3electionpb.ProclaimRequest") - proto.RegisterType((*ProclaimResponse)(nil), "v3electionpb.ProclaimResponse") -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// Client API for Election service - -type ElectionClient interface { - // Campaign waits to acquire leadership in an election, returning a LeaderKey - // representing the leadership if successful. The LeaderKey can then be used - // to issue new values on the election, transactionally guard API requests on - // leadership still being held, and resign from the election. - Campaign(ctx context.Context, in *CampaignRequest, opts ...grpc.CallOption) (*CampaignResponse, error) - // Proclaim updates the leader's posted value with a new value. - Proclaim(ctx context.Context, in *ProclaimRequest, opts ...grpc.CallOption) (*ProclaimResponse, error) - // Leader returns the current election proclamation, if any. - Leader(ctx context.Context, in *LeaderRequest, opts ...grpc.CallOption) (*LeaderResponse, error) - // Observe streams election proclamations in-order as made by the election's - // elected leaders. - Observe(ctx context.Context, in *LeaderRequest, opts ...grpc.CallOption) (Election_ObserveClient, error) - // Resign releases election leadership so other campaigners may acquire - // leadership on the election. - Resign(ctx context.Context, in *ResignRequest, opts ...grpc.CallOption) (*ResignResponse, error) -} - -type electionClient struct { - cc *grpc.ClientConn -} - -func NewElectionClient(cc *grpc.ClientConn) ElectionClient { - return &electionClient{cc} -} - -func (c *electionClient) Campaign(ctx context.Context, in *CampaignRequest, opts ...grpc.CallOption) (*CampaignResponse, error) { - out := new(CampaignResponse) - err := grpc.Invoke(ctx, "/v3electionpb.Election/Campaign", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *electionClient) Proclaim(ctx context.Context, in *ProclaimRequest, opts ...grpc.CallOption) (*ProclaimResponse, error) { - out := new(ProclaimResponse) - err := grpc.Invoke(ctx, "/v3electionpb.Election/Proclaim", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *electionClient) Leader(ctx context.Context, in *LeaderRequest, opts ...grpc.CallOption) (*LeaderResponse, error) { - out := new(LeaderResponse) - err := grpc.Invoke(ctx, "/v3electionpb.Election/Leader", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *electionClient) Observe(ctx context.Context, in *LeaderRequest, opts ...grpc.CallOption) (Election_ObserveClient, error) { - stream, err := grpc.NewClientStream(ctx, &_Election_serviceDesc.Streams[0], c.cc, "/v3electionpb.Election/Observe", opts...) - if err != nil { - return nil, err - } - x := &electionObserveClient{stream} - if err := x.ClientStream.SendMsg(in); err != nil { - return nil, err - } - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - return x, nil -} - -type Election_ObserveClient interface { - Recv() (*LeaderResponse, error) - grpc.ClientStream -} - -type electionObserveClient struct { - grpc.ClientStream -} - -func (x *electionObserveClient) Recv() (*LeaderResponse, error) { - m := new(LeaderResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *electionClient) Resign(ctx context.Context, in *ResignRequest, opts ...grpc.CallOption) (*ResignResponse, error) { - out := new(ResignResponse) - err := grpc.Invoke(ctx, "/v3electionpb.Election/Resign", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for Election service - -type ElectionServer interface { - // Campaign waits to acquire leadership in an election, returning a LeaderKey - // representing the leadership if successful. The LeaderKey can then be used - // to issue new values on the election, transactionally guard API requests on - // leadership still being held, and resign from the election. - Campaign(context.Context, *CampaignRequest) (*CampaignResponse, error) - // Proclaim updates the leader's posted value with a new value. - Proclaim(context.Context, *ProclaimRequest) (*ProclaimResponse, error) - // Leader returns the current election proclamation, if any. - Leader(context.Context, *LeaderRequest) (*LeaderResponse, error) - // Observe streams election proclamations in-order as made by the election's - // elected leaders. - Observe(*LeaderRequest, Election_ObserveServer) error - // Resign releases election leadership so other campaigners may acquire - // leadership on the election. - Resign(context.Context, *ResignRequest) (*ResignResponse, error) -} - -func RegisterElectionServer(s *grpc.Server, srv ElectionServer) { - s.RegisterService(&_Election_serviceDesc, srv) -} - -func _Election_Campaign_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(CampaignRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ElectionServer).Campaign(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/v3electionpb.Election/Campaign", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ElectionServer).Campaign(ctx, req.(*CampaignRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Election_Proclaim_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ProclaimRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ElectionServer).Proclaim(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/v3electionpb.Election/Proclaim", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ElectionServer).Proclaim(ctx, req.(*ProclaimRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Election_Leader_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(LeaderRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ElectionServer).Leader(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/v3electionpb.Election/Leader", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ElectionServer).Leader(ctx, req.(*LeaderRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Election_Observe_Handler(srv interface{}, stream grpc.ServerStream) error { - m := new(LeaderRequest) - if err := stream.RecvMsg(m); err != nil { - return err - } - return srv.(ElectionServer).Observe(m, &electionObserveServer{stream}) -} - -type Election_ObserveServer interface { - Send(*LeaderResponse) error - grpc.ServerStream -} - -type electionObserveServer struct { - grpc.ServerStream -} - -func (x *electionObserveServer) Send(m *LeaderResponse) error { - return x.ServerStream.SendMsg(m) -} - -func _Election_Resign_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ResignRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ElectionServer).Resign(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/v3electionpb.Election/Resign", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ElectionServer).Resign(ctx, req.(*ResignRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Election_serviceDesc = grpc.ServiceDesc{ - ServiceName: "v3electionpb.Election", - HandlerType: (*ElectionServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Campaign", - Handler: _Election_Campaign_Handler, - }, - { - MethodName: "Proclaim", - Handler: _Election_Proclaim_Handler, - }, - { - MethodName: "Leader", - Handler: _Election_Leader_Handler, - }, - { - MethodName: "Resign", - Handler: _Election_Resign_Handler, - }, - }, - Streams: []grpc.StreamDesc{ - { - StreamName: "Observe", - Handler: _Election_Observe_Handler, - ServerStreams: true, - }, - }, - Metadata: "v3election.proto", -} - -func (m *CampaignRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *CampaignRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Election(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if m.Lease != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Lease)) - } - if len(m.Value) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintV3Election(dAtA, i, uint64(len(m.Value))) - i += copy(dAtA[i:], m.Value) - } - return i, nil -} - -func (m *CampaignResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *CampaignResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Header.Size())) - n1, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - } - if m.Leader != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Leader.Size())) - n2, err := m.Leader.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - } - return i, nil -} - -func (m *LeaderKey) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaderKey) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Election(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.Key) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintV3Election(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - if m.Rev != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Rev)) - } - if m.Lease != 0 { - dAtA[i] = 0x20 - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Lease)) - } - return i, nil -} - -func (m *LeaderRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaderRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Election(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - return i, nil -} - -func (m *LeaderResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaderResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Header.Size())) - n3, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n3 - } - if m.Kv != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Kv.Size())) - n4, err := m.Kv.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n4 - } - return i, nil -} - -func (m *ResignRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ResignRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Leader != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Leader.Size())) - n5, err := m.Leader.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n5 - } - return i, nil -} - -func (m *ResignResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ResignResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Header.Size())) - n6, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n6 - } - return i, nil -} - -func (m *ProclaimRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ProclaimRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Leader != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Leader.Size())) - n7, err := m.Leader.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n7 - } - if len(m.Value) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintV3Election(dAtA, i, uint64(len(m.Value))) - i += copy(dAtA[i:], m.Value) - } - return i, nil -} - -func (m *ProclaimResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ProclaimResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Header.Size())) - n8, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n8 - } - return i, nil -} - -func encodeVarintV3Election(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *CampaignRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovV3Election(uint64(l)) - } - if m.Lease != 0 { - n += 1 + sovV3Election(uint64(m.Lease)) - } - l = len(m.Value) - if l > 0 { - n += 1 + l + sovV3Election(uint64(l)) - } - return n -} - -func (m *CampaignResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - if m.Leader != nil { - l = m.Leader.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - return n -} - -func (m *LeaderKey) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovV3Election(uint64(l)) - } - l = len(m.Key) - if l > 0 { - n += 1 + l + sovV3Election(uint64(l)) - } - if m.Rev != 0 { - n += 1 + sovV3Election(uint64(m.Rev)) - } - if m.Lease != 0 { - n += 1 + sovV3Election(uint64(m.Lease)) - } - return n -} - -func (m *LeaderRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovV3Election(uint64(l)) - } - return n -} - -func (m *LeaderResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - if m.Kv != nil { - l = m.Kv.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - return n -} - -func (m *ResignRequest) Size() (n int) { - var l int - _ = l - if m.Leader != nil { - l = m.Leader.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - return n -} - -func (m *ResignResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - return n -} - -func (m *ProclaimRequest) Size() (n int) { - var l int - _ = l - if m.Leader != nil { - l = m.Leader.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - l = len(m.Value) - if l > 0 { - n += 1 + l + sovV3Election(uint64(l)) - } - return n -} - -func (m *ProclaimResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - return n -} - -func sovV3Election(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozV3Election(x uint64) (n int) { - return sovV3Election(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *CampaignRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: CampaignRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: CampaignRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = append(m.Name[:0], dAtA[iNdEx:postIndex]...) - if m.Name == nil { - m.Name = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Lease", wireType) - } - m.Lease = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Lease |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...) - if m.Value == nil { - m.Value = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *CampaignResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: CampaignResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: CampaignResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &etcdserverpb.ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Leader", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Leader == nil { - m.Leader = &LeaderKey{} - } - if err := m.Leader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaderKey) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaderKey: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaderKey: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = append(m.Name[:0], dAtA[iNdEx:postIndex]...) - if m.Name == nil { - m.Name = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Rev", wireType) - } - m.Rev = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Rev |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Lease", wireType) - } - m.Lease = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Lease |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaderRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaderRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaderRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = append(m.Name[:0], dAtA[iNdEx:postIndex]...) - if m.Name == nil { - m.Name = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaderResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaderResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaderResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &etcdserverpb.ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Kv", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Kv == nil { - m.Kv = &mvccpb.KeyValue{} - } - if err := m.Kv.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ResignRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ResignRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ResignRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Leader", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Leader == nil { - m.Leader = &LeaderKey{} - } - if err := m.Leader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ResignResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ResignResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ResignResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &etcdserverpb.ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ProclaimRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ProclaimRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ProclaimRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Leader", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Leader == nil { - m.Leader = &LeaderKey{} - } - if err := m.Leader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...) - if m.Value == nil { - m.Value = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ProclaimResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ProclaimResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ProclaimResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &etcdserverpb.ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipV3Election(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Election - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Election - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Election - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthV3Election - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Election - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipV3Election(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthV3Election = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowV3Election = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("v3election.proto", fileDescriptorV3Election) } - -var fileDescriptorV3Election = []byte{ - // 538 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0x65, 0x9d, 0x10, 0xca, 0x90, 0xb6, 0x96, 0x55, 0xa9, 0x69, 0x48, 0xad, 0x68, 0x8b, 0x50, - 0x95, 0x83, 0x17, 0x35, 0x9c, 0x72, 0x42, 0x20, 0x50, 0xa5, 0x22, 0x01, 0x3e, 0x20, 0x38, 0xae, - 0xdd, 0x91, 0x1b, 0xc5, 0xf1, 0x1a, 0xdb, 0xb5, 0x94, 0x2b, 0xbf, 0xc0, 0x85, 0x7f, 0xe0, 0x47, - 0x38, 0x22, 0xf1, 0x03, 0x28, 0xf0, 0x21, 0x68, 0x77, 0x6d, 0xec, 0xb8, 0x21, 0x42, 0xe4, 0x62, - 0x8d, 0x67, 0x9e, 0xe7, 0xcd, 0x7b, 0x3b, 0x6b, 0x30, 0xf3, 0x31, 0x86, 0xe8, 0x67, 0x53, 0x11, - 0x39, 0x71, 0x22, 0x32, 0x61, 0x75, 0xab, 0x4c, 0xec, 0xf5, 0x0f, 0x02, 0x11, 0x08, 0x55, 0x60, - 0x32, 0xd2, 0x98, 0xfe, 0x43, 0xcc, 0xfc, 0x4b, 0x26, 0x1f, 0x29, 0x26, 0x39, 0x26, 0xb5, 0x30, - 0xf6, 0x58, 0x12, 0xfb, 0x05, 0xee, 0x48, 0xe1, 0xe6, 0xb9, 0xef, 0xab, 0x47, 0xec, 0xb1, 0x59, - 0x5e, 0x94, 0x06, 0x81, 0x10, 0x41, 0x88, 0x8c, 0xc7, 0x53, 0xc6, 0xa3, 0x48, 0x64, 0x5c, 0x32, - 0xa6, 0xba, 0x4a, 0xdf, 0xc0, 0xfe, 0x33, 0x3e, 0x8f, 0xf9, 0x34, 0x88, 0x5c, 0xfc, 0x70, 0x8d, - 0x69, 0x66, 0x59, 0xd0, 0x8e, 0xf8, 0x1c, 0x7b, 0x64, 0x48, 0x4e, 0xbb, 0xae, 0x8a, 0xad, 0x03, - 0xb8, 0x1d, 0x22, 0x4f, 0xb1, 0x67, 0x0c, 0xc9, 0x69, 0xcb, 0xd5, 0x2f, 0x32, 0x9b, 0xf3, 0xf0, - 0x1a, 0x7b, 0x2d, 0x05, 0xd5, 0x2f, 0x74, 0x01, 0x66, 0xd5, 0x32, 0x8d, 0x45, 0x94, 0xa2, 0xf5, - 0x18, 0x3a, 0x57, 0xc8, 0x2f, 0x31, 0x51, 0x5d, 0xef, 0x9d, 0x0d, 0x9c, 0xba, 0x10, 0xa7, 0xc4, - 0x9d, 0x2b, 0x8c, 0x5b, 0x60, 0x2d, 0x06, 0x9d, 0x50, 0x7f, 0x65, 0xa8, 0xaf, 0x0e, 0x9d, 0xba, - 0x65, 0xce, 0x4b, 0x55, 0xbb, 0xc0, 0x85, 0x5b, 0xc0, 0xe8, 0x7b, 0xb8, 0xfb, 0x27, 0xb9, 0x56, - 0x87, 0x09, 0xad, 0x19, 0x2e, 0x54, 0xbb, 0xae, 0x2b, 0x43, 0x99, 0x49, 0x30, 0x57, 0x0a, 0x5a, - 0xae, 0x0c, 0x2b, 0xad, 0xed, 0x9a, 0x56, 0x7a, 0x02, 0xbb, 0xba, 0xf5, 0x06, 0x9b, 0xe8, 0x15, - 0xec, 0x95, 0xa0, 0xad, 0x84, 0x0f, 0xc1, 0x98, 0xe5, 0x85, 0x68, 0xd3, 0xd1, 0x27, 0xea, 0x5c, - 0xe0, 0xe2, 0xad, 0x34, 0xd8, 0x35, 0x66, 0x39, 0x7d, 0x02, 0xbb, 0x2e, 0xa6, 0xb5, 0x53, 0xab, - 0xbc, 0x22, 0xff, 0xe6, 0xd5, 0x0b, 0xd8, 0x2b, 0x3b, 0x6c, 0x33, 0x2b, 0x7d, 0x07, 0xfb, 0xaf, - 0x13, 0xe1, 0x87, 0x7c, 0x3a, 0xff, 0xdf, 0x59, 0xaa, 0x45, 0x32, 0xea, 0x8b, 0x74, 0x0e, 0x66, - 0xd5, 0x79, 0x9b, 0x19, 0xcf, 0xbe, 0xb4, 0x61, 0xe7, 0x79, 0x31, 0x80, 0x25, 0x60, 0xa7, 0xdc, - 0x4f, 0xeb, 0x78, 0x75, 0xb2, 0xc6, 0x55, 0xe8, 0xdb, 0x7f, 0x2b, 0x6b, 0x16, 0xfa, 0xe0, 0xe3, - 0xf7, 0x5f, 0x9f, 0x0c, 0x9b, 0x1e, 0xb1, 0x7c, 0xec, 0x61, 0xc6, 0x59, 0x09, 0x66, 0x7e, 0x01, - 0x9d, 0x90, 0x91, 0x24, 0x2c, 0x75, 0x34, 0x09, 0x1b, 0xce, 0x35, 0x09, 0x9b, 0xf2, 0x37, 0x10, - 0xc6, 0x05, 0x54, 0x12, 0x06, 0xd0, 0xd1, 0x1e, 0x5b, 0xf7, 0xd7, 0x39, 0x5f, 0x92, 0x0d, 0xd6, - 0x17, 0x0b, 0x2a, 0xaa, 0xa8, 0x06, 0xf4, 0xf0, 0x06, 0x95, 0x3e, 0x34, 0x49, 0x34, 0x83, 0x3b, - 0xaf, 0x3c, 0x65, 0xfe, 0x36, 0x4c, 0x27, 0x8a, 0xe9, 0x98, 0xf6, 0x6e, 0x30, 0x09, 0xdd, 0x7c, - 0x42, 0x46, 0x8f, 0x88, 0x54, 0xa5, 0x17, 0xb6, 0xc9, 0xb5, 0x72, 0x11, 0x9a, 0x5c, 0xab, 0x3b, - 0xbe, 0x41, 0x55, 0xa2, 0x80, 0x13, 0x32, 0x7a, 0x6a, 0x7e, 0x5d, 0xda, 0xe4, 0xdb, 0xd2, 0x26, - 0x3f, 0x96, 0x36, 0xf9, 0xfc, 0xd3, 0xbe, 0xe5, 0x75, 0xd4, 0xcf, 0x72, 0xfc, 0x3b, 0x00, 0x00, - 0xff, 0xff, 0xdc, 0xa9, 0x0e, 0xdf, 0xc5, 0x05, 0x00, 0x00, -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3lock/doc.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3lock/doc.go deleted file mode 100644 index e0a1008abc9e..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3lock/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v3lock provides a v3 locking service from an etcdserver. -package v3lock diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3lock/lock.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3lock/lock.go deleted file mode 100644 index a5efcbab5b56..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3lock/lock.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3lock - -import ( - "context" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/concurrency" - "github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb" -) - -type lockServer struct { - c *clientv3.Client -} - -func NewLockServer(c *clientv3.Client) v3lockpb.LockServer { - return &lockServer{c} -} - -func (ls *lockServer) Lock(ctx context.Context, req *v3lockpb.LockRequest) (*v3lockpb.LockResponse, error) { - s, err := concurrency.NewSession( - ls.c, - concurrency.WithLease(clientv3.LeaseID(req.Lease)), - concurrency.WithContext(ctx), - ) - if err != nil { - return nil, err - } - s.Orphan() - m := concurrency.NewMutex(s, string(req.Name)) - if err = m.Lock(ctx); err != nil { - return nil, err - } - return &v3lockpb.LockResponse{Header: m.Header(), Key: []byte(m.Key())}, nil -} - -func (ls *lockServer) Unlock(ctx context.Context, req *v3lockpb.UnlockRequest) (*v3lockpb.UnlockResponse, error) { - resp, err := ls.c.Delete(ctx, string(req.Key)) - if err != nil { - return nil, err - } - return &v3lockpb.UnlockResponse{Header: resp.Header}, nil -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb/gw/v3lock.pb.gw.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb/gw/v3lock.pb.gw.go deleted file mode 100644 index efecc45dba36..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb/gw/v3lock.pb.gw.go +++ /dev/null @@ -1,167 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: etcdserver/api/v3lock/v3lockpb/v3lock.proto - -/* -Package v3lockpb is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package gw - -import ( - "github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb" - "io" - "net/http" - - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "golang.org/x/net/context" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/status" -) - -var _ codes.Code -var _ io.Reader -var _ status.Status -var _ = runtime.String -var _ = utilities.NewDoubleArray - -func request_Lock_Lock_0(ctx context.Context, marshaler runtime.Marshaler, client v3lockpb.LockClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3lockpb.LockRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Lock(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Lock_Unlock_0(ctx context.Context, marshaler runtime.Marshaler, client v3lockpb.LockClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3lockpb.UnlockRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Unlock(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -// RegisterLockHandlerFromEndpoint is same as RegisterLockHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterLockHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterLockHandler(ctx, mux, conn) -} - -// RegisterLockHandler registers the http handlers for service Lock to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterLockHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterLockHandlerClient(ctx, mux, v3lockpb.NewLockClient(conn)) -} - -// RegisterLockHandler registers the http handlers for service Lock to "mux". -// The handlers forward requests to the grpc endpoint over the given implementation of "LockClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "LockClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "LockClient" to call the correct interceptors. -func RegisterLockHandlerClient(ctx context.Context, mux *runtime.ServeMux, client v3lockpb.LockClient) error { - - mux.Handle("POST", pattern_Lock_Lock_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lock_Lock_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lock_Lock_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lock_Unlock_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lock_Unlock_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lock_Unlock_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Lock_Lock_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 1}, []string{"v3beta", "lock"}, "")) - - pattern_Lock_Unlock_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "lock", "unlock"}, "")) -) - -var ( - forward_Lock_Lock_0 = runtime.ForwardResponseMessage - - forward_Lock_Unlock_0 = runtime.ForwardResponseMessage -) diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb/v3lock.pb.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb/v3lock.pb.go deleted file mode 100644 index 071d0ae242b2..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb/v3lock.pb.go +++ /dev/null @@ -1,959 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: v3lock.proto - -/* - Package v3lockpb is a generated protocol buffer package. - - It is generated from these files: - v3lock.proto - - It has these top-level messages: - LockRequest - LockResponse - UnlockRequest - UnlockResponse -*/ -package v3lockpb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - etcdserverpb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - context "golang.org/x/net/context" - - grpc "google.golang.org/grpc" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type LockRequest struct { - // name is the identifier for the distributed shared lock to be acquired. - Name []byte `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - // lease is the ID of the lease that will be attached to ownership of the - // lock. If the lease expires or is revoked and currently holds the lock, - // the lock is automatically released. Calls to Lock with the same lease will - // be treated as a single acquistion; locking twice with the same lease is a - // no-op. - Lease int64 `protobuf:"varint,2,opt,name=lease,proto3" json:"lease,omitempty"` -} - -func (m *LockRequest) Reset() { *m = LockRequest{} } -func (m *LockRequest) String() string { return proto.CompactTextString(m) } -func (*LockRequest) ProtoMessage() {} -func (*LockRequest) Descriptor() ([]byte, []int) { return fileDescriptorV3Lock, []int{0} } - -func (m *LockRequest) GetName() []byte { - if m != nil { - return m.Name - } - return nil -} - -func (m *LockRequest) GetLease() int64 { - if m != nil { - return m.Lease - } - return 0 -} - -type LockResponse struct { - Header *etcdserverpb.ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // key is a key that will exist on etcd for the duration that the Lock caller - // owns the lock. Users should not modify this key or the lock may exhibit - // undefined behavior. - Key []byte `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` -} - -func (m *LockResponse) Reset() { *m = LockResponse{} } -func (m *LockResponse) String() string { return proto.CompactTextString(m) } -func (*LockResponse) ProtoMessage() {} -func (*LockResponse) Descriptor() ([]byte, []int) { return fileDescriptorV3Lock, []int{1} } - -func (m *LockResponse) GetHeader() *etcdserverpb.ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *LockResponse) GetKey() []byte { - if m != nil { - return m.Key - } - return nil -} - -type UnlockRequest struct { - // key is the lock ownership key granted by Lock. - Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` -} - -func (m *UnlockRequest) Reset() { *m = UnlockRequest{} } -func (m *UnlockRequest) String() string { return proto.CompactTextString(m) } -func (*UnlockRequest) ProtoMessage() {} -func (*UnlockRequest) Descriptor() ([]byte, []int) { return fileDescriptorV3Lock, []int{2} } - -func (m *UnlockRequest) GetKey() []byte { - if m != nil { - return m.Key - } - return nil -} - -type UnlockResponse struct { - Header *etcdserverpb.ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *UnlockResponse) Reset() { *m = UnlockResponse{} } -func (m *UnlockResponse) String() string { return proto.CompactTextString(m) } -func (*UnlockResponse) ProtoMessage() {} -func (*UnlockResponse) Descriptor() ([]byte, []int) { return fileDescriptorV3Lock, []int{3} } - -func (m *UnlockResponse) GetHeader() *etcdserverpb.ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func init() { - proto.RegisterType((*LockRequest)(nil), "v3lockpb.LockRequest") - proto.RegisterType((*LockResponse)(nil), "v3lockpb.LockResponse") - proto.RegisterType((*UnlockRequest)(nil), "v3lockpb.UnlockRequest") - proto.RegisterType((*UnlockResponse)(nil), "v3lockpb.UnlockResponse") -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// Client API for Lock service - -type LockClient interface { - // Lock acquires a distributed shared lock on a given named lock. - // On success, it will return a unique key that exists so long as the - // lock is held by the caller. This key can be used in conjunction with - // transactions to safely ensure updates to etcd only occur while holding - // lock ownership. The lock is held until Unlock is called on the key or the - // lease associate with the owner expires. - Lock(ctx context.Context, in *LockRequest, opts ...grpc.CallOption) (*LockResponse, error) - // Unlock takes a key returned by Lock and releases the hold on lock. The - // next Lock caller waiting for the lock will then be woken up and given - // ownership of the lock. - Unlock(ctx context.Context, in *UnlockRequest, opts ...grpc.CallOption) (*UnlockResponse, error) -} - -type lockClient struct { - cc *grpc.ClientConn -} - -func NewLockClient(cc *grpc.ClientConn) LockClient { - return &lockClient{cc} -} - -func (c *lockClient) Lock(ctx context.Context, in *LockRequest, opts ...grpc.CallOption) (*LockResponse, error) { - out := new(LockResponse) - err := grpc.Invoke(ctx, "/v3lockpb.Lock/Lock", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *lockClient) Unlock(ctx context.Context, in *UnlockRequest, opts ...grpc.CallOption) (*UnlockResponse, error) { - out := new(UnlockResponse) - err := grpc.Invoke(ctx, "/v3lockpb.Lock/Unlock", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for Lock service - -type LockServer interface { - // Lock acquires a distributed shared lock on a given named lock. - // On success, it will return a unique key that exists so long as the - // lock is held by the caller. This key can be used in conjunction with - // transactions to safely ensure updates to etcd only occur while holding - // lock ownership. The lock is held until Unlock is called on the key or the - // lease associate with the owner expires. - Lock(context.Context, *LockRequest) (*LockResponse, error) - // Unlock takes a key returned by Lock and releases the hold on lock. The - // next Lock caller waiting for the lock will then be woken up and given - // ownership of the lock. - Unlock(context.Context, *UnlockRequest) (*UnlockResponse, error) -} - -func RegisterLockServer(s *grpc.Server, srv LockServer) { - s.RegisterService(&_Lock_serviceDesc, srv) -} - -func _Lock_Lock_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(LockRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(LockServer).Lock(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/v3lockpb.Lock/Lock", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(LockServer).Lock(ctx, req.(*LockRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Lock_Unlock_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(UnlockRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(LockServer).Unlock(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/v3lockpb.Lock/Unlock", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(LockServer).Unlock(ctx, req.(*UnlockRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Lock_serviceDesc = grpc.ServiceDesc{ - ServiceName: "v3lockpb.Lock", - HandlerType: (*LockServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Lock", - Handler: _Lock_Lock_Handler, - }, - { - MethodName: "Unlock", - Handler: _Lock_Unlock_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "v3lock.proto", -} - -func (m *LockRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LockRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Lock(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if m.Lease != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintV3Lock(dAtA, i, uint64(m.Lease)) - } - return i, nil -} - -func (m *LockResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LockResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Lock(dAtA, i, uint64(m.Header.Size())) - n1, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - } - if len(m.Key) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintV3Lock(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - return i, nil -} - -func (m *UnlockRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *UnlockRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Key) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Lock(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - return i, nil -} - -func (m *UnlockResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *UnlockResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Lock(dAtA, i, uint64(m.Header.Size())) - n2, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - } - return i, nil -} - -func encodeVarintV3Lock(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *LockRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovV3Lock(uint64(l)) - } - if m.Lease != 0 { - n += 1 + sovV3Lock(uint64(m.Lease)) - } - return n -} - -func (m *LockResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovV3Lock(uint64(l)) - } - l = len(m.Key) - if l > 0 { - n += 1 + l + sovV3Lock(uint64(l)) - } - return n -} - -func (m *UnlockRequest) Size() (n int) { - var l int - _ = l - l = len(m.Key) - if l > 0 { - n += 1 + l + sovV3Lock(uint64(l)) - } - return n -} - -func (m *UnlockResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovV3Lock(uint64(l)) - } - return n -} - -func sovV3Lock(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozV3Lock(x uint64) (n int) { - return sovV3Lock(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *LockRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LockRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LockRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Lock - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = append(m.Name[:0], dAtA[iNdEx:postIndex]...) - if m.Name == nil { - m.Name = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Lease", wireType) - } - m.Lease = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Lease |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipV3Lock(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Lock - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LockResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LockResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LockResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Lock - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &etcdserverpb.ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Lock - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Lock(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Lock - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *UnlockRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: UnlockRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: UnlockRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Lock - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Lock(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Lock - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *UnlockResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: UnlockResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: UnlockResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Lock - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &etcdserverpb.ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Lock(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Lock - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipV3Lock(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Lock - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Lock - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Lock - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthV3Lock - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Lock - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipV3Lock(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthV3Lock = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowV3Lock = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("v3lock.proto", fileDescriptorV3Lock) } - -var fileDescriptorV3Lock = []byte{ - // 335 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x29, 0x33, 0xce, 0xc9, - 0x4f, 0xce, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x80, 0xf0, 0x0a, 0x92, 0xa4, 0x44, - 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x82, 0xfa, 0x20, 0x16, 0x44, 0x5e, 0x4a, 0x2d, 0xb5, 0x24, 0x39, - 0x45, 0x1f, 0x44, 0x14, 0xa7, 0x16, 0x95, 0xa5, 0x16, 0x21, 0x31, 0x0b, 0x92, 0xf4, 0x8b, 0x0a, - 0x92, 0xa1, 0xea, 0x64, 0xd2, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0x13, 0x0b, 0x32, 0xf5, 0x13, - 0xf3, 0xf2, 0xf2, 0x4b, 0x12, 0x4b, 0x32, 0xf3, 0xf3, 0x8a, 0x21, 0xb2, 0x4a, 0xe6, 0x5c, 0xdc, - 0x3e, 0xf9, 0xc9, 0xd9, 0x41, 0xa9, 0x85, 0xa5, 0xa9, 0xc5, 0x25, 0x42, 0x42, 0x5c, 0x2c, 0x79, - 0x89, 0xb9, 0xa9, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x3c, 0x41, 0x60, 0xb6, 0x90, 0x08, 0x17, 0x6b, - 0x4e, 0x6a, 0x62, 0x71, 0xaa, 0x04, 0x93, 0x02, 0xa3, 0x06, 0x73, 0x10, 0x84, 0xa3, 0x14, 0xc6, - 0xc5, 0x03, 0xd1, 0x58, 0x5c, 0x90, 0x9f, 0x57, 0x9c, 0x2a, 0x64, 0xc2, 0xc5, 0x96, 0x91, 0x9a, - 0x98, 0x92, 0x5a, 0x04, 0xd6, 0xcb, 0x6d, 0x24, 0xa3, 0x87, 0xec, 0x1e, 0x3d, 0x98, 0x3a, 0x0f, - 0xb0, 0x9a, 0x20, 0xa8, 0x5a, 0x21, 0x01, 0x2e, 0xe6, 0xec, 0xd4, 0x4a, 0xb0, 0xc9, 0x3c, 0x41, - 0x20, 0xa6, 0x92, 0x22, 0x17, 0x6f, 0x68, 0x5e, 0x0e, 0x92, 0x93, 0xa0, 0x4a, 0x18, 0x11, 0x4a, - 0xdc, 0xb8, 0xf8, 0x60, 0x4a, 0x28, 0xb1, 0xdc, 0x68, 0x07, 0x23, 0x17, 0x0b, 0xc8, 0x0f, 0x42, - 0xc1, 0x50, 0x5a, 0x54, 0x0f, 0x16, 0xe6, 0x7a, 0x48, 0x81, 0x22, 0x25, 0x86, 0x2e, 0x0c, 0x31, - 0x4d, 0x49, 0xa6, 0xe9, 0xf2, 0x93, 0xc9, 0x4c, 0x62, 0x4a, 0x82, 0xfa, 0x65, 0xc6, 0x49, 0xa9, - 0x25, 0x89, 0xfa, 0x20, 0x45, 0x60, 0xc2, 0x8a, 0x51, 0x4b, 0x28, 0x9a, 0x8b, 0x0d, 0xe2, 0x4a, - 0x21, 0x71, 0x84, 0x7e, 0x14, 0xaf, 0x49, 0x49, 0x60, 0x4a, 0x40, 0x8d, 0x96, 0x03, 0x1b, 0x2d, - 0xa1, 0x24, 0x8c, 0x62, 0x74, 0x69, 0x1e, 0xd4, 0x70, 0x27, 0x81, 0x13, 0x8f, 0xe4, 0x18, 0x2f, - 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc6, 0x63, 0x39, 0x86, 0x24, 0x36, 0x70, 0x7c, - 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x10, 0x82, 0x89, 0xf0, 0x45, 0x02, 0x00, 0x00, -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/auth.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/auth.go deleted file mode 100644 index ca8e53ad0498..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/auth.go +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - - "github.com/coreos/etcd/etcdserver" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -type AuthServer struct { - authenticator etcdserver.Authenticator -} - -func NewAuthServer(s *etcdserver.EtcdServer) *AuthServer { - return &AuthServer{authenticator: s} -} - -func (as *AuthServer) AuthEnable(ctx context.Context, r *pb.AuthEnableRequest) (*pb.AuthEnableResponse, error) { - resp, err := as.authenticator.AuthEnable(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) AuthDisable(ctx context.Context, r *pb.AuthDisableRequest) (*pb.AuthDisableResponse, error) { - resp, err := as.authenticator.AuthDisable(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) Authenticate(ctx context.Context, r *pb.AuthenticateRequest) (*pb.AuthenticateResponse, error) { - resp, err := as.authenticator.Authenticate(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) RoleAdd(ctx context.Context, r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) { - resp, err := as.authenticator.RoleAdd(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) RoleDelete(ctx context.Context, r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) { - resp, err := as.authenticator.RoleDelete(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) RoleGet(ctx context.Context, r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) { - resp, err := as.authenticator.RoleGet(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) RoleList(ctx context.Context, r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) { - resp, err := as.authenticator.RoleList(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) RoleRevokePermission(ctx context.Context, r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) { - resp, err := as.authenticator.RoleRevokePermission(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) RoleGrantPermission(ctx context.Context, r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) { - resp, err := as.authenticator.RoleGrantPermission(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserAdd(ctx context.Context, r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) { - resp, err := as.authenticator.UserAdd(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserDelete(ctx context.Context, r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) { - resp, err := as.authenticator.UserDelete(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserGet(ctx context.Context, r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) { - resp, err := as.authenticator.UserGet(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserList(ctx context.Context, r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) { - resp, err := as.authenticator.UserList(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserGrantRole(ctx context.Context, r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) { - resp, err := as.authenticator.UserGrantRole(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserRevokeRole(ctx context.Context, r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) { - resp, err := as.authenticator.UserRevokeRole(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserChangePassword(ctx context.Context, r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) { - resp, err := as.authenticator.UserChangePassword(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/codec.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/codec.go deleted file mode 100644 index 17a2c87ae61d..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/codec.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import "github.com/gogo/protobuf/proto" - -type codec struct{} - -func (c *codec) Marshal(v interface{}) ([]byte, error) { - b, err := proto.Marshal(v.(proto.Message)) - sentBytes.Add(float64(len(b))) - return b, err -} - -func (c *codec) Unmarshal(data []byte, v interface{}) error { - receivedBytes.Add(float64(len(data))) - return proto.Unmarshal(data, v.(proto.Message)) -} - -func (c *codec) String() string { - return "proto" -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/grpc.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/grpc.go deleted file mode 100644 index c97e7466215a..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/grpc.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "crypto/tls" - "math" - - "github.com/coreos/etcd/etcdserver" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "github.com/grpc-ecosystem/go-grpc-middleware" - "github.com/grpc-ecosystem/go-grpc-prometheus" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials" - "google.golang.org/grpc/health" - healthpb "google.golang.org/grpc/health/grpc_health_v1" -) - -const ( - grpcOverheadBytes = 512 * 1024 - maxStreams = math.MaxUint32 - maxSendBytes = math.MaxInt32 -) - -func Server(s *etcdserver.EtcdServer, tls *tls.Config, gopts ...grpc.ServerOption) *grpc.Server { - var opts []grpc.ServerOption - opts = append(opts, grpc.CustomCodec(&codec{})) - if tls != nil { - opts = append(opts, grpc.Creds(credentials.NewTLS(tls))) - } - opts = append(opts, grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer( - newLogUnaryInterceptor(s), - newUnaryInterceptor(s), - grpc_prometheus.UnaryServerInterceptor, - ))) - opts = append(opts, grpc.StreamInterceptor(grpc_middleware.ChainStreamServer( - newStreamInterceptor(s), - grpc_prometheus.StreamServerInterceptor, - ))) - opts = append(opts, grpc.MaxRecvMsgSize(int(s.Cfg.MaxRequestBytes+grpcOverheadBytes))) - opts = append(opts, grpc.MaxSendMsgSize(maxSendBytes)) - opts = append(opts, grpc.MaxConcurrentStreams(maxStreams)) - grpcServer := grpc.NewServer(append(opts, gopts...)...) - - pb.RegisterKVServer(grpcServer, NewQuotaKVServer(s)) - pb.RegisterWatchServer(grpcServer, NewWatchServer(s)) - pb.RegisterLeaseServer(grpcServer, NewQuotaLeaseServer(s)) - pb.RegisterClusterServer(grpcServer, NewClusterServer(s)) - pb.RegisterAuthServer(grpcServer, NewAuthServer(s)) - pb.RegisterMaintenanceServer(grpcServer, NewMaintenanceServer(s)) - - // server should register all the services manually - // use empty service name for all etcd services' health status, - // see https://github.com/grpc/grpc/blob/master/doc/health-checking.md for more - hsrv := health.NewServer() - hsrv.SetServingStatus("", healthpb.HealthCheckResponse_SERVING) - healthpb.RegisterHealthServer(grpcServer, hsrv) - - // set zero values for metrics registered for this grpc server - grpc_prometheus.Register(grpcServer) - - return grpcServer -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/header.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/header.go deleted file mode 100644 index 75da52fb8d16..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/header.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "github.com/coreos/etcd/etcdserver" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -type header struct { - clusterID int64 - memberID int64 - raftTimer etcdserver.RaftTimer - rev func() int64 -} - -func newHeader(s *etcdserver.EtcdServer) header { - return header{ - clusterID: int64(s.Cluster().ID()), - memberID: int64(s.ID()), - raftTimer: s, - rev: func() int64 { return s.KV().Rev() }, - } -} - -// fill populates pb.ResponseHeader using etcdserver information -func (h *header) fill(rh *pb.ResponseHeader) { - if rh == nil { - plog.Panic("unexpected nil resp.Header") - } - rh.ClusterId = uint64(h.clusterID) - rh.MemberId = uint64(h.memberID) - rh.RaftTerm = h.raftTimer.Term() - if rh.Revision == 0 { - rh.Revision = h.rev() - } -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/interceptor.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/interceptor.go deleted file mode 100644 index d594ae7f154c..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/interceptor.go +++ /dev/null @@ -1,263 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - "sync" - "time" - - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "go.uber.org/zap" - "google.golang.org/grpc" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/peer" -) - -const ( - maxNoLeaderCnt = 3 -) - -type streamsMap struct { - mu sync.Mutex - streams map[grpc.ServerStream]struct{} -} - -func newUnaryInterceptor(s *etcdserver.EtcdServer) grpc.UnaryServerInterceptor { - return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - if !api.IsCapabilityEnabled(api.V3rpcCapability) { - return nil, rpctypes.ErrGRPCNotCapable - } - - md, ok := metadata.FromIncomingContext(ctx) - if ok { - if ks := md[rpctypes.MetadataRequireLeaderKey]; len(ks) > 0 && ks[0] == rpctypes.MetadataHasLeader { - if s.Leader() == types.ID(raft.None) { - return nil, rpctypes.ErrGRPCNoLeader - } - } - } - - return handler(ctx, req) - } -} - -func newLogUnaryInterceptor(s *etcdserver.EtcdServer) grpc.UnaryServerInterceptor { - return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - startTime := time.Now() - resp, err := handler(ctx, req) - defer logUnaryRequestStats(ctx, nil, info, startTime, req, resp) - return resp, err - } -} - -func logUnaryRequestStats(ctx context.Context, lg *zap.Logger, info *grpc.UnaryServerInfo, startTime time.Time, req interface{}, resp interface{}) { - duration := time.Since(startTime) - remote := "No remote client info." - peerInfo, ok := peer.FromContext(ctx) - if ok { - remote = peerInfo.Addr.String() - } - var responseType string = info.FullMethod - var reqCount, respCount int64 - var reqSize, respSize int - var reqContent string - switch _resp := resp.(type) { - case *pb.RangeResponse: - _req, ok := req.(*pb.RangeRequest) - if ok { - reqCount = 0 - reqSize = _req.Size() - reqContent = _req.String() - } - if _resp != nil { - respCount = _resp.GetCount() - respSize = _resp.Size() - } - case *pb.PutResponse: - _req, ok := req.(*pb.PutRequest) - if ok { - reqCount = 1 - reqSize = _req.Size() - reqContent = pb.NewLoggablePutRequest(_req).String() - // redact value field from request content, see PR #9821 - } - if _resp != nil { - respCount = 0 - respSize = _resp.Size() - } - case *pb.DeleteRangeResponse: - _req, ok := req.(*pb.DeleteRangeRequest) - if ok { - reqCount = 0 - reqSize = _req.Size() - reqContent = _req.String() - } - if _resp != nil { - respCount = _resp.GetDeleted() - respSize = _resp.Size() - } - case *pb.TxnResponse: - _req, ok := req.(*pb.TxnRequest) - if ok && _resp != nil { - if _resp.GetSucceeded() { // determine the 'actual' count and size of request based on success or failure - reqCount = int64(len(_req.GetSuccess())) - reqSize = 0 - for _, r := range _req.GetSuccess() { - reqSize += r.Size() - } - } else { - reqCount = int64(len(_req.GetFailure())) - reqSize = 0 - for _, r := range _req.GetFailure() { - reqSize += r.Size() - } - } - reqContent = pb.NewLoggableTxnRequest(_req).String() - // redact value field from request content, see PR #9821 - } - if _resp != nil { - respCount = 0 - respSize = _resp.Size() - } - default: - reqCount = -1 - reqSize = -1 - respCount = -1 - respSize = -1 - } - - logGenericRequestStats(lg, startTime, duration, remote, responseType, reqCount, reqSize, respCount, respSize, reqContent) -} - -func logGenericRequestStats(lg *zap.Logger, startTime time.Time, duration time.Duration, remote string, responseType string, - reqCount int64, reqSize int, respCount int64, respSize int, reqContent string) { - if lg == nil { - plog.Debugf("start time = %v, "+ - "time spent = %v, "+ - "remote = %s, "+ - "response type = %s, "+ - "request count = %d, "+ - "request size = %d, "+ - "response count = %d, "+ - "response size = %d, "+ - "request content = %s", - startTime, duration, remote, responseType, reqCount, reqSize, respCount, respSize, reqContent, - ) - } else { - lg.Debug("request stats", - zap.Time("start time", startTime), - zap.Duration("time spent", duration), - zap.String("remote", remote), - zap.String("response type", responseType), - zap.Int64("request count", reqCount), - zap.Int("request size", reqSize), - zap.Int64("response count", respCount), - zap.Int("response size", respSize), - zap.String("request content", reqContent), - ) - } -} - -func newStreamInterceptor(s *etcdserver.EtcdServer) grpc.StreamServerInterceptor { - smap := monitorLeader(s) - - return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { - if !api.IsCapabilityEnabled(api.V3rpcCapability) { - return rpctypes.ErrGRPCNotCapable - } - - md, ok := metadata.FromIncomingContext(ss.Context()) - if ok { - if ks := md[rpctypes.MetadataRequireLeaderKey]; len(ks) > 0 && ks[0] == rpctypes.MetadataHasLeader { - if s.Leader() == types.ID(raft.None) { - return rpctypes.ErrGRPCNoLeader - } - - cctx, cancel := context.WithCancel(ss.Context()) - ss = serverStreamWithCtx{ctx: cctx, cancel: &cancel, ServerStream: ss} - - smap.mu.Lock() - smap.streams[ss] = struct{}{} - smap.mu.Unlock() - - defer func() { - smap.mu.Lock() - delete(smap.streams, ss) - smap.mu.Unlock() - cancel() - }() - - } - } - - return handler(srv, ss) - } -} - -type serverStreamWithCtx struct { - grpc.ServerStream - ctx context.Context - cancel *context.CancelFunc -} - -func (ssc serverStreamWithCtx) Context() context.Context { return ssc.ctx } - -func monitorLeader(s *etcdserver.EtcdServer) *streamsMap { - smap := &streamsMap{ - streams: make(map[grpc.ServerStream]struct{}), - } - - go func() { - election := time.Duration(s.Cfg.TickMs) * time.Duration(s.Cfg.ElectionTicks) * time.Millisecond - noLeaderCnt := 0 - - for { - select { - case <-s.StopNotify(): - return - case <-time.After(election): - if s.Leader() == types.ID(raft.None) { - noLeaderCnt++ - } else { - noLeaderCnt = 0 - } - - // We are more conservative on canceling existing streams. Reconnecting streams - // cost much more than just rejecting new requests. So we wait until the member - // cannot find a leader for maxNoLeaderCnt election timeouts to cancel existing streams. - if noLeaderCnt >= maxNoLeaderCnt { - smap.mu.Lock() - for ss := range smap.streams { - if ssWithCtx, ok := ss.(serverStreamWithCtx); ok { - (*ssWithCtx.cancel)() - <-ss.Context().Done() - } - } - smap.streams = make(map[grpc.ServerStream]struct{}) - smap.mu.Unlock() - } - } - } - }() - - return smap -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/key.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/key.go deleted file mode 100644 index 9781bddda9c1..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/key.go +++ /dev/null @@ -1,277 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v3rpc implements etcd v3 RPC system based on gRPC. -package v3rpc - -import ( - "context" - - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/pkg/adt" - - "github.com/coreos/pkg/capnslog" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdserver/api/v3rpc") -) - -type kvServer struct { - hdr header - kv etcdserver.RaftKV - // maxTxnOps is the max operations per txn. - // e.g suppose maxTxnOps = 128. - // Txn.Success can have at most 128 operations, - // and Txn.Failure can have at most 128 operations. - maxTxnOps uint -} - -func NewKVServer(s *etcdserver.EtcdServer) pb.KVServer { - return &kvServer{hdr: newHeader(s), kv: s, maxTxnOps: s.Cfg.MaxTxnOps} -} - -func (s *kvServer) Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, error) { - if err := checkRangeRequest(r); err != nil { - return nil, err - } - - resp, err := s.kv.Range(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - - s.hdr.fill(resp.Header) - return resp, nil -} - -func (s *kvServer) Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error) { - if err := checkPutRequest(r); err != nil { - return nil, err - } - - resp, err := s.kv.Put(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - - s.hdr.fill(resp.Header) - return resp, nil -} - -func (s *kvServer) DeleteRange(ctx context.Context, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) { - if err := checkDeleteRequest(r); err != nil { - return nil, err - } - - resp, err := s.kv.DeleteRange(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - - s.hdr.fill(resp.Header) - return resp, nil -} - -func (s *kvServer) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error) { - if err := checkTxnRequest(r, int(s.maxTxnOps)); err != nil { - return nil, err - } - // check for forbidden put/del overlaps after checking request to avoid quadratic blowup - if _, _, err := checkIntervals(r.Success); err != nil { - return nil, err - } - if _, _, err := checkIntervals(r.Failure); err != nil { - return nil, err - } - - resp, err := s.kv.Txn(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - - s.hdr.fill(resp.Header) - return resp, nil -} - -func (s *kvServer) Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error) { - resp, err := s.kv.Compact(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - - s.hdr.fill(resp.Header) - return resp, nil -} - -func checkRangeRequest(r *pb.RangeRequest) error { - if len(r.Key) == 0 { - return rpctypes.ErrGRPCEmptyKey - } - return nil -} - -func checkPutRequest(r *pb.PutRequest) error { - if len(r.Key) == 0 { - return rpctypes.ErrGRPCEmptyKey - } - if r.IgnoreValue && len(r.Value) != 0 { - return rpctypes.ErrGRPCValueProvided - } - if r.IgnoreLease && r.Lease != 0 { - return rpctypes.ErrGRPCLeaseProvided - } - return nil -} - -func checkDeleteRequest(r *pb.DeleteRangeRequest) error { - if len(r.Key) == 0 { - return rpctypes.ErrGRPCEmptyKey - } - return nil -} - -func checkTxnRequest(r *pb.TxnRequest, maxTxnOps int) error { - opc := len(r.Compare) - if opc < len(r.Success) { - opc = len(r.Success) - } - if opc < len(r.Failure) { - opc = len(r.Failure) - } - if opc > maxTxnOps { - return rpctypes.ErrGRPCTooManyOps - } - - for _, c := range r.Compare { - if len(c.Key) == 0 { - return rpctypes.ErrGRPCEmptyKey - } - } - for _, u := range r.Success { - if err := checkRequestOp(u, maxTxnOps-opc); err != nil { - return err - } - } - for _, u := range r.Failure { - if err := checkRequestOp(u, maxTxnOps-opc); err != nil { - return err - } - } - - return nil -} - -// checkIntervals tests whether puts and deletes overlap for a list of ops. If -// there is an overlap, returns an error. If no overlap, return put and delete -// sets for recursive evaluation. -func checkIntervals(reqs []*pb.RequestOp) (map[string]struct{}, adt.IntervalTree, error) { - var dels adt.IntervalTree - - // collect deletes from this level; build first to check lower level overlapped puts - for _, req := range reqs { - tv, ok := req.Request.(*pb.RequestOp_RequestDeleteRange) - if !ok { - continue - } - dreq := tv.RequestDeleteRange - if dreq == nil { - continue - } - var iv adt.Interval - if len(dreq.RangeEnd) != 0 { - iv = adt.NewStringAffineInterval(string(dreq.Key), string(dreq.RangeEnd)) - } else { - iv = adt.NewStringAffinePoint(string(dreq.Key)) - } - dels.Insert(iv, struct{}{}) - } - - // collect children puts/deletes - puts := make(map[string]struct{}) - for _, req := range reqs { - tv, ok := req.Request.(*pb.RequestOp_RequestTxn) - if !ok { - continue - } - putsThen, delsThen, err := checkIntervals(tv.RequestTxn.Success) - if err != nil { - return nil, dels, err - } - putsElse, delsElse, err := checkIntervals(tv.RequestTxn.Failure) - if err != nil { - return nil, dels, err - } - for k := range putsThen { - if _, ok := puts[k]; ok { - return nil, dels, rpctypes.ErrGRPCDuplicateKey - } - if dels.Intersects(adt.NewStringAffinePoint(k)) { - return nil, dels, rpctypes.ErrGRPCDuplicateKey - } - puts[k] = struct{}{} - } - for k := range putsElse { - if _, ok := puts[k]; ok { - // if key is from putsThen, overlap is OK since - // either then/else are mutually exclusive - if _, isSafe := putsThen[k]; !isSafe { - return nil, dels, rpctypes.ErrGRPCDuplicateKey - } - } - if dels.Intersects(adt.NewStringAffinePoint(k)) { - return nil, dels, rpctypes.ErrGRPCDuplicateKey - } - puts[k] = struct{}{} - } - dels.Union(delsThen, adt.NewStringAffineInterval("\x00", "")) - dels.Union(delsElse, adt.NewStringAffineInterval("\x00", "")) - } - - // collect and check this level's puts - for _, req := range reqs { - tv, ok := req.Request.(*pb.RequestOp_RequestPut) - if !ok || tv.RequestPut == nil { - continue - } - k := string(tv.RequestPut.Key) - if _, ok := puts[k]; ok { - return nil, dels, rpctypes.ErrGRPCDuplicateKey - } - if dels.Intersects(adt.NewStringAffinePoint(k)) { - return nil, dels, rpctypes.ErrGRPCDuplicateKey - } - puts[k] = struct{}{} - } - return puts, dels, nil -} - -func checkRequestOp(u *pb.RequestOp, maxTxnOps int) error { - // TODO: ensure only one of the field is set. - switch uv := u.Request.(type) { - case *pb.RequestOp_RequestRange: - return checkRangeRequest(uv.RequestRange) - case *pb.RequestOp_RequestPut: - return checkPutRequest(uv.RequestPut) - case *pb.RequestOp_RequestDeleteRange: - return checkDeleteRequest(uv.RequestDeleteRange) - case *pb.RequestOp_RequestTxn: - return checkTxnRequest(uv.RequestTxn, maxTxnOps) - default: - // empty op / nil entry - return rpctypes.ErrGRPCKeyNotFound - } -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/lease.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/lease.go deleted file mode 100644 index 5b4f2b142281..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/lease.go +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - "io" - - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/lease" -) - -type LeaseServer struct { - hdr header - le etcdserver.Lessor -} - -func NewLeaseServer(s *etcdserver.EtcdServer) pb.LeaseServer { - return &LeaseServer{le: s, hdr: newHeader(s)} -} - -func (ls *LeaseServer) LeaseGrant(ctx context.Context, cr *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - resp, err := ls.le.LeaseGrant(ctx, cr) - - if err != nil { - return nil, togRPCError(err) - } - ls.hdr.fill(resp.Header) - return resp, nil -} - -func (ls *LeaseServer) LeaseRevoke(ctx context.Context, rr *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) { - resp, err := ls.le.LeaseRevoke(ctx, rr) - if err != nil { - return nil, togRPCError(err) - } - ls.hdr.fill(resp.Header) - return resp, nil -} - -func (ls *LeaseServer) LeaseTimeToLive(ctx context.Context, rr *pb.LeaseTimeToLiveRequest) (*pb.LeaseTimeToLiveResponse, error) { - resp, err := ls.le.LeaseTimeToLive(ctx, rr) - if err != nil && err != lease.ErrLeaseNotFound { - return nil, togRPCError(err) - } - if err == lease.ErrLeaseNotFound { - resp = &pb.LeaseTimeToLiveResponse{ - Header: &pb.ResponseHeader{}, - ID: rr.ID, - TTL: -1, - } - } - ls.hdr.fill(resp.Header) - return resp, nil -} - -func (ls *LeaseServer) LeaseLeases(ctx context.Context, rr *pb.LeaseLeasesRequest) (*pb.LeaseLeasesResponse, error) { - resp, err := ls.le.LeaseLeases(ctx, rr) - if err != nil && err != lease.ErrLeaseNotFound { - return nil, togRPCError(err) - } - if err == lease.ErrLeaseNotFound { - resp = &pb.LeaseLeasesResponse{ - Header: &pb.ResponseHeader{}, - Leases: []*pb.LeaseStatus{}, - } - } - ls.hdr.fill(resp.Header) - return resp, nil -} - -func (ls *LeaseServer) LeaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) (err error) { - errc := make(chan error, 1) - go func() { - errc <- ls.leaseKeepAlive(stream) - }() - select { - case err = <-errc: - case <-stream.Context().Done(): - // the only server-side cancellation is noleader for now. - err = stream.Context().Err() - if err == context.Canceled { - err = rpctypes.ErrGRPCNoLeader - } - } - return err -} - -func (ls *LeaseServer) leaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) error { - for { - req, err := stream.Recv() - if err == io.EOF { - return nil - } - if err != nil { - if isClientCtxErr(stream.Context().Err(), err) { - plog.Debugf("failed to receive lease keepalive request from gRPC stream (%q)", err.Error()) - } else { - plog.Warningf("failed to receive lease keepalive request from gRPC stream (%q)", err.Error()) - } - return err - } - - // Create header before we sent out the renew request. - // This can make sure that the revision is strictly smaller or equal to - // when the keepalive happened at the local server (when the local server is the leader) - // or remote leader. - // Without this, a lease might be revoked at rev 3 but client can see the keepalive succeeded - // at rev 4. - resp := &pb.LeaseKeepAliveResponse{ID: req.ID, Header: &pb.ResponseHeader{}} - ls.hdr.fill(resp.Header) - - ttl, err := ls.le.LeaseRenew(stream.Context(), lease.LeaseID(req.ID)) - if err == lease.ErrLeaseNotFound { - err = nil - ttl = 0 - } - - if err != nil { - return togRPCError(err) - } - - resp.TTL = ttl - err = stream.Send(resp) - if err != nil { - if isClientCtxErr(stream.Context().Err(), err) { - plog.Debugf("failed to send lease keepalive response to gRPC stream (%q)", err.Error()) - } else { - plog.Warningf("failed to send lease keepalive response to gRPC stream (%q)", err.Error()) - } - return err - } - } -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/maintenance.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/maintenance.go deleted file mode 100644 index c9df1800db28..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/maintenance.go +++ /dev/null @@ -1,229 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - "crypto/sha256" - "io" - - "github.com/coreos/etcd/auth" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/version" -) - -type KVGetter interface { - KV() mvcc.ConsistentWatchableKV -} - -type BackendGetter interface { - Backend() backend.Backend -} - -type Alarmer interface { - Alarm(ctx context.Context, ar *pb.AlarmRequest) (*pb.AlarmResponse, error) -} - -type LeaderTransferrer interface { - MoveLeader(ctx context.Context, lead, target uint64) error -} - -type RaftStatusGetter interface { - etcdserver.RaftTimer - ID() types.ID - Leader() types.ID -} - -type AuthGetter interface { - AuthInfoFromCtx(ctx context.Context) (*auth.AuthInfo, error) - AuthStore() auth.AuthStore -} - -type maintenanceServer struct { - rg RaftStatusGetter - kg KVGetter - bg BackendGetter - a Alarmer - lt LeaderTransferrer - hdr header -} - -func NewMaintenanceServer(s *etcdserver.EtcdServer) pb.MaintenanceServer { - srv := &maintenanceServer{rg: s, kg: s, bg: s, a: s, lt: s, hdr: newHeader(s)} - return &authMaintenanceServer{srv, s} -} - -func (ms *maintenanceServer) Defragment(ctx context.Context, sr *pb.DefragmentRequest) (*pb.DefragmentResponse, error) { - plog.Noticef("starting to defragment the storage backend...") - err := ms.bg.Backend().Defrag() - if err != nil { - plog.Errorf("failed to defragment the storage backend (%v)", err) - return nil, err - } - plog.Noticef("finished defragmenting the storage backend") - return &pb.DefragmentResponse{}, nil -} - -func (ms *maintenanceServer) Snapshot(sr *pb.SnapshotRequest, srv pb.Maintenance_SnapshotServer) error { - snap := ms.bg.Backend().Snapshot() - pr, pw := io.Pipe() - - defer pr.Close() - - go func() { - snap.WriteTo(pw) - if err := snap.Close(); err != nil { - plog.Errorf("error closing snapshot (%v)", err) - } - pw.Close() - }() - - // send file data - h := sha256.New() - br := int64(0) - buf := make([]byte, 32*1024) - sz := snap.Size() - for br < sz { - n, err := io.ReadFull(pr, buf) - if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF { - return togRPCError(err) - } - br += int64(n) - resp := &pb.SnapshotResponse{ - RemainingBytes: uint64(sz - br), - Blob: buf[:n], - } - if err = srv.Send(resp); err != nil { - return togRPCError(err) - } - h.Write(buf[:n]) - } - - // send sha - sha := h.Sum(nil) - hresp := &pb.SnapshotResponse{RemainingBytes: 0, Blob: sha} - if err := srv.Send(hresp); err != nil { - return togRPCError(err) - } - - return nil -} - -func (ms *maintenanceServer) Hash(ctx context.Context, r *pb.HashRequest) (*pb.HashResponse, error) { - h, rev, err := ms.kg.KV().Hash() - if err != nil { - return nil, togRPCError(err) - } - resp := &pb.HashResponse{Header: &pb.ResponseHeader{Revision: rev}, Hash: h} - ms.hdr.fill(resp.Header) - return resp, nil -} - -func (ms *maintenanceServer) HashKV(ctx context.Context, r *pb.HashKVRequest) (*pb.HashKVResponse, error) { - h, rev, compactRev, err := ms.kg.KV().HashByRev(r.Revision) - if err != nil { - return nil, togRPCError(err) - } - - resp := &pb.HashKVResponse{Header: &pb.ResponseHeader{Revision: rev}, Hash: h, CompactRevision: compactRev} - ms.hdr.fill(resp.Header) - return resp, nil -} - -func (ms *maintenanceServer) Alarm(ctx context.Context, ar *pb.AlarmRequest) (*pb.AlarmResponse, error) { - return ms.a.Alarm(ctx, ar) -} - -func (ms *maintenanceServer) Status(ctx context.Context, ar *pb.StatusRequest) (*pb.StatusResponse, error) { - resp := &pb.StatusResponse{ - Header: &pb.ResponseHeader{Revision: ms.hdr.rev()}, - Version: version.Version, - DbSize: ms.bg.Backend().Size(), - Leader: uint64(ms.rg.Leader()), - RaftIndex: ms.rg.Index(), - RaftTerm: ms.rg.Term(), - } - ms.hdr.fill(resp.Header) - return resp, nil -} - -func (ms *maintenanceServer) MoveLeader(ctx context.Context, tr *pb.MoveLeaderRequest) (*pb.MoveLeaderResponse, error) { - if ms.rg.ID() != ms.rg.Leader() { - return nil, rpctypes.ErrGRPCNotLeader - } - - if err := ms.lt.MoveLeader(ctx, uint64(ms.rg.Leader()), tr.TargetID); err != nil { - return nil, togRPCError(err) - } - return &pb.MoveLeaderResponse{}, nil -} - -type authMaintenanceServer struct { - *maintenanceServer - ag AuthGetter -} - -func (ams *authMaintenanceServer) isAuthenticated(ctx context.Context) error { - authInfo, err := ams.ag.AuthInfoFromCtx(ctx) - if err != nil { - return err - } - - return ams.ag.AuthStore().IsAdminPermitted(authInfo) -} - -func (ams *authMaintenanceServer) Defragment(ctx context.Context, sr *pb.DefragmentRequest) (*pb.DefragmentResponse, error) { - if err := ams.isAuthenticated(ctx); err != nil { - return nil, err - } - - return ams.maintenanceServer.Defragment(ctx, sr) -} - -func (ams *authMaintenanceServer) Snapshot(sr *pb.SnapshotRequest, srv pb.Maintenance_SnapshotServer) error { - if err := ams.isAuthenticated(srv.Context()); err != nil { - return err - } - - return ams.maintenanceServer.Snapshot(sr, srv) -} - -func (ams *authMaintenanceServer) Hash(ctx context.Context, r *pb.HashRequest) (*pb.HashResponse, error) { - if err := ams.isAuthenticated(ctx); err != nil { - return nil, err - } - - return ams.maintenanceServer.Hash(ctx, r) -} - -func (ams *authMaintenanceServer) HashKV(ctx context.Context, r *pb.HashKVRequest) (*pb.HashKVResponse, error) { - if err := ams.isAuthenticated(ctx); err != nil { - return nil, err - } - return ams.maintenanceServer.HashKV(ctx, r) -} - -func (ams *authMaintenanceServer) Status(ctx context.Context, ar *pb.StatusRequest) (*pb.StatusResponse, error) { - return ams.maintenanceServer.Status(ctx, ar) -} - -func (ams *authMaintenanceServer) MoveLeader(ctx context.Context, tr *pb.MoveLeaderRequest) (*pb.MoveLeaderResponse, error) { - return ams.maintenanceServer.MoveLeader(ctx, tr) -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/member.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/member.go deleted file mode 100644 index cbe7b470ab93..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/member.go +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - "time" - - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/pkg/types" -) - -type ClusterServer struct { - cluster api.Cluster - server etcdserver.ServerV3 -} - -func NewClusterServer(s etcdserver.ServerV3) *ClusterServer { - return &ClusterServer{ - cluster: s.Cluster(), - server: s, - } -} - -func (cs *ClusterServer) MemberAdd(ctx context.Context, r *pb.MemberAddRequest) (*pb.MemberAddResponse, error) { - urls, err := types.NewURLs(r.PeerURLs) - if err != nil { - return nil, rpctypes.ErrGRPCMemberBadURLs - } - - now := time.Now() - m := membership.NewMember("", urls, "", &now) - membs, merr := cs.server.AddMember(ctx, *m) - if merr != nil { - return nil, togRPCError(merr) - } - - return &pb.MemberAddResponse{ - Header: cs.header(), - Member: &pb.Member{ID: uint64(m.ID), PeerURLs: m.PeerURLs}, - Members: membersToProtoMembers(membs), - }, nil -} - -func (cs *ClusterServer) MemberRemove(ctx context.Context, r *pb.MemberRemoveRequest) (*pb.MemberRemoveResponse, error) { - membs, err := cs.server.RemoveMember(ctx, r.ID) - if err != nil { - return nil, togRPCError(err) - } - return &pb.MemberRemoveResponse{Header: cs.header(), Members: membersToProtoMembers(membs)}, nil -} - -func (cs *ClusterServer) MemberUpdate(ctx context.Context, r *pb.MemberUpdateRequest) (*pb.MemberUpdateResponse, error) { - m := membership.Member{ - ID: types.ID(r.ID), - RaftAttributes: membership.RaftAttributes{PeerURLs: r.PeerURLs}, - } - membs, err := cs.server.UpdateMember(ctx, m) - if err != nil { - return nil, togRPCError(err) - } - return &pb.MemberUpdateResponse{Header: cs.header(), Members: membersToProtoMembers(membs)}, nil -} - -func (cs *ClusterServer) MemberList(ctx context.Context, r *pb.MemberListRequest) (*pb.MemberListResponse, error) { - membs := membersToProtoMembers(cs.cluster.Members()) - return &pb.MemberListResponse{Header: cs.header(), Members: membs}, nil -} - -func (cs *ClusterServer) header() *pb.ResponseHeader { - return &pb.ResponseHeader{ClusterId: uint64(cs.cluster.ID()), MemberId: uint64(cs.server.ID()), RaftTerm: cs.server.Term()} -} - -func membersToProtoMembers(membs []*membership.Member) []*pb.Member { - protoMembs := make([]*pb.Member, len(membs)) - for i := range membs { - protoMembs[i] = &pb.Member{ - Name: membs[i].Name, - ID: uint64(membs[i].ID), - PeerURLs: membs[i].PeerURLs, - ClientURLs: membs[i].ClientURLs, - } - } - return protoMembs -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/metrics.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/metrics.go deleted file mode 100644 index 6cb41a61e565..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/metrics.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import "github.com/prometheus/client_golang/prometheus" - -var ( - sentBytes = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "client_grpc_sent_bytes_total", - Help: "The total number of bytes sent to grpc clients.", - }) - - receivedBytes = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "client_grpc_received_bytes_total", - Help: "The total number of bytes received from grpc clients.", - }) -) - -func init() { - prometheus.MustRegister(sentBytes) - prometheus.MustRegister(receivedBytes) -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/quota.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/quota.go deleted file mode 100644 index 02d99609d885..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/quota.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/pkg/types" -) - -type quotaKVServer struct { - pb.KVServer - qa quotaAlarmer -} - -type quotaAlarmer struct { - q etcdserver.Quota - a Alarmer - id types.ID -} - -// check whether request satisfies the quota. If there is not enough space, -// ignore request and raise the free space alarm. -func (qa *quotaAlarmer) check(ctx context.Context, r interface{}) error { - if qa.q.Available(r) { - return nil - } - req := &pb.AlarmRequest{ - MemberID: uint64(qa.id), - Action: pb.AlarmRequest_ACTIVATE, - Alarm: pb.AlarmType_NOSPACE, - } - qa.a.Alarm(ctx, req) - return rpctypes.ErrGRPCNoSpace -} - -func NewQuotaKVServer(s *etcdserver.EtcdServer) pb.KVServer { - return "aKVServer{ - NewKVServer(s), - quotaAlarmer{etcdserver.NewBackendQuota(s), s, s.ID()}, - } -} - -func (s *quotaKVServer) Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error) { - if err := s.qa.check(ctx, r); err != nil { - return nil, err - } - return s.KVServer.Put(ctx, r) -} - -func (s *quotaKVServer) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error) { - if err := s.qa.check(ctx, r); err != nil { - return nil, err - } - return s.KVServer.Txn(ctx, r) -} - -type quotaLeaseServer struct { - pb.LeaseServer - qa quotaAlarmer -} - -func (s *quotaLeaseServer) LeaseGrant(ctx context.Context, cr *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - if err := s.qa.check(ctx, cr); err != nil { - return nil, err - } - return s.LeaseServer.LeaseGrant(ctx, cr) -} - -func NewQuotaLeaseServer(s *etcdserver.EtcdServer) pb.LeaseServer { - return "aLeaseServer{ - NewLeaseServer(s), - quotaAlarmer{etcdserver.NewBackendQuota(s), s, s.ID()}, - } -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes/doc.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes/doc.go deleted file mode 100644 index f72c6a644f33..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package rpctypes has types and values shared by the etcd server and client for v3 RPC interaction. -package rpctypes diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes/error.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes/error.go deleted file mode 100644 index 55eab38ef17b..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes/error.go +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rpctypes - -import ( - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -// server-side error -var ( - ErrGRPCEmptyKey = status.New(codes.InvalidArgument, "etcdserver: key is not provided").Err() - ErrGRPCKeyNotFound = status.New(codes.InvalidArgument, "etcdserver: key not found").Err() - ErrGRPCValueProvided = status.New(codes.InvalidArgument, "etcdserver: value is provided").Err() - ErrGRPCLeaseProvided = status.New(codes.InvalidArgument, "etcdserver: lease is provided").Err() - ErrGRPCTooManyOps = status.New(codes.InvalidArgument, "etcdserver: too many operations in txn request").Err() - ErrGRPCDuplicateKey = status.New(codes.InvalidArgument, "etcdserver: duplicate key given in txn request").Err() - ErrGRPCCompacted = status.New(codes.OutOfRange, "etcdserver: mvcc: required revision has been compacted").Err() - ErrGRPCFutureRev = status.New(codes.OutOfRange, "etcdserver: mvcc: required revision is a future revision").Err() - ErrGRPCNoSpace = status.New(codes.ResourceExhausted, "etcdserver: mvcc: database space exceeded").Err() - - ErrGRPCLeaseNotFound = status.New(codes.NotFound, "etcdserver: requested lease not found").Err() - ErrGRPCLeaseExist = status.New(codes.FailedPrecondition, "etcdserver: lease already exists").Err() - ErrGRPCLeaseTTLTooLarge = status.New(codes.OutOfRange, "etcdserver: too large lease TTL").Err() - - ErrGRPCMemberExist = status.New(codes.FailedPrecondition, "etcdserver: member ID already exist").Err() - ErrGRPCPeerURLExist = status.New(codes.FailedPrecondition, "etcdserver: Peer URLs already exists").Err() - ErrGRPCMemberNotEnoughStarted = status.New(codes.FailedPrecondition, "etcdserver: re-configuration failed due to not enough started members").Err() - ErrGRPCMemberBadURLs = status.New(codes.InvalidArgument, "etcdserver: given member URLs are invalid").Err() - ErrGRPCMemberNotFound = status.New(codes.NotFound, "etcdserver: member not found").Err() - - ErrGRPCRequestTooLarge = status.New(codes.InvalidArgument, "etcdserver: request is too large").Err() - ErrGRPCRequestTooManyRequests = status.New(codes.ResourceExhausted, "etcdserver: too many requests").Err() - - ErrGRPCRootUserNotExist = status.New(codes.FailedPrecondition, "etcdserver: root user does not exist").Err() - ErrGRPCRootRoleNotExist = status.New(codes.FailedPrecondition, "etcdserver: root user does not have root role").Err() - ErrGRPCUserAlreadyExist = status.New(codes.FailedPrecondition, "etcdserver: user name already exists").Err() - ErrGRPCUserEmpty = status.New(codes.InvalidArgument, "etcdserver: user name is empty").Err() - ErrGRPCUserNotFound = status.New(codes.FailedPrecondition, "etcdserver: user name not found").Err() - ErrGRPCRoleAlreadyExist = status.New(codes.FailedPrecondition, "etcdserver: role name already exists").Err() - ErrGRPCRoleNotFound = status.New(codes.FailedPrecondition, "etcdserver: role name not found").Err() - ErrGRPCAuthFailed = status.New(codes.InvalidArgument, "etcdserver: authentication failed, invalid user ID or password").Err() - ErrGRPCPermissionDenied = status.New(codes.PermissionDenied, "etcdserver: permission denied").Err() - ErrGRPCRoleNotGranted = status.New(codes.FailedPrecondition, "etcdserver: role is not granted to the user").Err() - ErrGRPCPermissionNotGranted = status.New(codes.FailedPrecondition, "etcdserver: permission is not granted to the role").Err() - ErrGRPCAuthNotEnabled = status.New(codes.FailedPrecondition, "etcdserver: authentication is not enabled").Err() - ErrGRPCInvalidAuthToken = status.New(codes.Unauthenticated, "etcdserver: invalid auth token").Err() - ErrGRPCInvalidAuthMgmt = status.New(codes.InvalidArgument, "etcdserver: invalid auth management").Err() - - ErrGRPCNoLeader = status.New(codes.Unavailable, "etcdserver: no leader").Err() - ErrGRPCNotLeader = status.New(codes.FailedPrecondition, "etcdserver: not leader").Err() - ErrGRPCNotCapable = status.New(codes.Unavailable, "etcdserver: not capable").Err() - ErrGRPCStopped = status.New(codes.Unavailable, "etcdserver: server stopped").Err() - ErrGRPCTimeout = status.New(codes.Unavailable, "etcdserver: request timed out").Err() - ErrGRPCTimeoutDueToLeaderFail = status.New(codes.Unavailable, "etcdserver: request timed out, possibly due to previous leader failure").Err() - ErrGRPCTimeoutDueToConnectionLost = status.New(codes.Unavailable, "etcdserver: request timed out, possibly due to connection lost").Err() - ErrGRPCUnhealthy = status.New(codes.Unavailable, "etcdserver: unhealthy cluster").Err() - ErrGRPCCorrupt = status.New(codes.DataLoss, "etcdserver: corrupt cluster").Err() - - errStringToError = map[string]error{ - ErrorDesc(ErrGRPCEmptyKey): ErrGRPCEmptyKey, - ErrorDesc(ErrGRPCKeyNotFound): ErrGRPCKeyNotFound, - ErrorDesc(ErrGRPCValueProvided): ErrGRPCValueProvided, - ErrorDesc(ErrGRPCLeaseProvided): ErrGRPCLeaseProvided, - - ErrorDesc(ErrGRPCTooManyOps): ErrGRPCTooManyOps, - ErrorDesc(ErrGRPCDuplicateKey): ErrGRPCDuplicateKey, - ErrorDesc(ErrGRPCCompacted): ErrGRPCCompacted, - ErrorDesc(ErrGRPCFutureRev): ErrGRPCFutureRev, - ErrorDesc(ErrGRPCNoSpace): ErrGRPCNoSpace, - - ErrorDesc(ErrGRPCLeaseNotFound): ErrGRPCLeaseNotFound, - ErrorDesc(ErrGRPCLeaseExist): ErrGRPCLeaseExist, - ErrorDesc(ErrGRPCLeaseTTLTooLarge): ErrGRPCLeaseTTLTooLarge, - - ErrorDesc(ErrGRPCMemberExist): ErrGRPCMemberExist, - ErrorDesc(ErrGRPCPeerURLExist): ErrGRPCPeerURLExist, - ErrorDesc(ErrGRPCMemberNotEnoughStarted): ErrGRPCMemberNotEnoughStarted, - ErrorDesc(ErrGRPCMemberBadURLs): ErrGRPCMemberBadURLs, - ErrorDesc(ErrGRPCMemberNotFound): ErrGRPCMemberNotFound, - - ErrorDesc(ErrGRPCRequestTooLarge): ErrGRPCRequestTooLarge, - ErrorDesc(ErrGRPCRequestTooManyRequests): ErrGRPCRequestTooManyRequests, - - ErrorDesc(ErrGRPCRootUserNotExist): ErrGRPCRootUserNotExist, - ErrorDesc(ErrGRPCRootRoleNotExist): ErrGRPCRootRoleNotExist, - ErrorDesc(ErrGRPCUserAlreadyExist): ErrGRPCUserAlreadyExist, - ErrorDesc(ErrGRPCUserEmpty): ErrGRPCUserEmpty, - ErrorDesc(ErrGRPCUserNotFound): ErrGRPCUserNotFound, - ErrorDesc(ErrGRPCRoleAlreadyExist): ErrGRPCRoleAlreadyExist, - ErrorDesc(ErrGRPCRoleNotFound): ErrGRPCRoleNotFound, - ErrorDesc(ErrGRPCAuthFailed): ErrGRPCAuthFailed, - ErrorDesc(ErrGRPCPermissionDenied): ErrGRPCPermissionDenied, - ErrorDesc(ErrGRPCRoleNotGranted): ErrGRPCRoleNotGranted, - ErrorDesc(ErrGRPCPermissionNotGranted): ErrGRPCPermissionNotGranted, - ErrorDesc(ErrGRPCAuthNotEnabled): ErrGRPCAuthNotEnabled, - ErrorDesc(ErrGRPCInvalidAuthToken): ErrGRPCInvalidAuthToken, - ErrorDesc(ErrGRPCInvalidAuthMgmt): ErrGRPCInvalidAuthMgmt, - - ErrorDesc(ErrGRPCNoLeader): ErrGRPCNoLeader, - ErrorDesc(ErrGRPCNotLeader): ErrGRPCNotLeader, - ErrorDesc(ErrGRPCNotCapable): ErrGRPCNotCapable, - ErrorDesc(ErrGRPCStopped): ErrGRPCStopped, - ErrorDesc(ErrGRPCTimeout): ErrGRPCTimeout, - ErrorDesc(ErrGRPCTimeoutDueToLeaderFail): ErrGRPCTimeoutDueToLeaderFail, - ErrorDesc(ErrGRPCTimeoutDueToConnectionLost): ErrGRPCTimeoutDueToConnectionLost, - ErrorDesc(ErrGRPCUnhealthy): ErrGRPCUnhealthy, - ErrorDesc(ErrGRPCCorrupt): ErrGRPCCorrupt, - } -) - -// client-side error -var ( - ErrEmptyKey = Error(ErrGRPCEmptyKey) - ErrKeyNotFound = Error(ErrGRPCKeyNotFound) - ErrValueProvided = Error(ErrGRPCValueProvided) - ErrLeaseProvided = Error(ErrGRPCLeaseProvided) - ErrTooManyOps = Error(ErrGRPCTooManyOps) - ErrDuplicateKey = Error(ErrGRPCDuplicateKey) - ErrCompacted = Error(ErrGRPCCompacted) - ErrFutureRev = Error(ErrGRPCFutureRev) - ErrNoSpace = Error(ErrGRPCNoSpace) - - ErrLeaseNotFound = Error(ErrGRPCLeaseNotFound) - ErrLeaseExist = Error(ErrGRPCLeaseExist) - ErrLeaseTTLTooLarge = Error(ErrGRPCLeaseTTLTooLarge) - - ErrMemberExist = Error(ErrGRPCMemberExist) - ErrPeerURLExist = Error(ErrGRPCPeerURLExist) - ErrMemberNotEnoughStarted = Error(ErrGRPCMemberNotEnoughStarted) - ErrMemberBadURLs = Error(ErrGRPCMemberBadURLs) - ErrMemberNotFound = Error(ErrGRPCMemberNotFound) - - ErrRequestTooLarge = Error(ErrGRPCRequestTooLarge) - ErrTooManyRequests = Error(ErrGRPCRequestTooManyRequests) - - ErrRootUserNotExist = Error(ErrGRPCRootUserNotExist) - ErrRootRoleNotExist = Error(ErrGRPCRootRoleNotExist) - ErrUserAlreadyExist = Error(ErrGRPCUserAlreadyExist) - ErrUserEmpty = Error(ErrGRPCUserEmpty) - ErrUserNotFound = Error(ErrGRPCUserNotFound) - ErrRoleAlreadyExist = Error(ErrGRPCRoleAlreadyExist) - ErrRoleNotFound = Error(ErrGRPCRoleNotFound) - ErrAuthFailed = Error(ErrGRPCAuthFailed) - ErrPermissionDenied = Error(ErrGRPCPermissionDenied) - ErrRoleNotGranted = Error(ErrGRPCRoleNotGranted) - ErrPermissionNotGranted = Error(ErrGRPCPermissionNotGranted) - ErrAuthNotEnabled = Error(ErrGRPCAuthNotEnabled) - ErrInvalidAuthToken = Error(ErrGRPCInvalidAuthToken) - ErrInvalidAuthMgmt = Error(ErrGRPCInvalidAuthMgmt) - - ErrNoLeader = Error(ErrGRPCNoLeader) - ErrNotLeader = Error(ErrGRPCNotLeader) - ErrNotCapable = Error(ErrGRPCNotCapable) - ErrStopped = Error(ErrGRPCStopped) - ErrTimeout = Error(ErrGRPCTimeout) - ErrTimeoutDueToLeaderFail = Error(ErrGRPCTimeoutDueToLeaderFail) - ErrTimeoutDueToConnectionLost = Error(ErrGRPCTimeoutDueToConnectionLost) - ErrUnhealthy = Error(ErrGRPCUnhealthy) - ErrCorrupt = Error(ErrGRPCCorrupt) -) - -// EtcdError defines gRPC server errors. -// (https://github.com/grpc/grpc-go/blob/master/rpc_util.go#L319-L323) -type EtcdError struct { - code codes.Code - desc string -} - -// Code returns grpc/codes.Code. -// TODO: define clientv3/codes.Code. -func (e EtcdError) Code() codes.Code { - return e.code -} - -func (e EtcdError) Error() string { - return e.desc -} - -func Error(err error) error { - if err == nil { - return nil - } - verr, ok := errStringToError[ErrorDesc(err)] - if !ok { // not gRPC error - return err - } - ev, ok := status.FromError(verr) - var desc string - if ok { - desc = ev.Message() - } else { - desc = verr.Error() - } - return EtcdError{code: ev.Code(), desc: desc} -} - -func ErrorDesc(err error) string { - if s, ok := status.FromError(err); ok { - return s.Message() - } - return err.Error() -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes/md.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes/md.go deleted file mode 100644 index 5c590e1aec99..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes/md.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rpctypes - -var ( - MetadataRequireLeaderKey = "hasleader" - MetadataHasLeader = "true" -) diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/util.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/util.go deleted file mode 100644 index 799c1197d8dd..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/util.go +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - "strings" - - "github.com/coreos/etcd/auth" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/mvcc" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -var toGRPCErrorMap = map[error]error{ - membership.ErrIDRemoved: rpctypes.ErrGRPCMemberNotFound, - membership.ErrIDNotFound: rpctypes.ErrGRPCMemberNotFound, - membership.ErrIDExists: rpctypes.ErrGRPCMemberExist, - membership.ErrPeerURLexists: rpctypes.ErrGRPCPeerURLExist, - etcdserver.ErrNotEnoughStartedMembers: rpctypes.ErrMemberNotEnoughStarted, - - mvcc.ErrCompacted: rpctypes.ErrGRPCCompacted, - mvcc.ErrFutureRev: rpctypes.ErrGRPCFutureRev, - etcdserver.ErrRequestTooLarge: rpctypes.ErrGRPCRequestTooLarge, - etcdserver.ErrNoSpace: rpctypes.ErrGRPCNoSpace, - etcdserver.ErrTooManyRequests: rpctypes.ErrTooManyRequests, - - etcdserver.ErrNoLeader: rpctypes.ErrGRPCNoLeader, - etcdserver.ErrNotLeader: rpctypes.ErrGRPCNotLeader, - etcdserver.ErrStopped: rpctypes.ErrGRPCStopped, - etcdserver.ErrTimeout: rpctypes.ErrGRPCTimeout, - etcdserver.ErrTimeoutDueToLeaderFail: rpctypes.ErrGRPCTimeoutDueToLeaderFail, - etcdserver.ErrTimeoutDueToConnectionLost: rpctypes.ErrGRPCTimeoutDueToConnectionLost, - etcdserver.ErrUnhealthy: rpctypes.ErrGRPCUnhealthy, - etcdserver.ErrKeyNotFound: rpctypes.ErrGRPCKeyNotFound, - etcdserver.ErrCorrupt: rpctypes.ErrGRPCCorrupt, - - lease.ErrLeaseNotFound: rpctypes.ErrGRPCLeaseNotFound, - lease.ErrLeaseExists: rpctypes.ErrGRPCLeaseExist, - lease.ErrLeaseTTLTooLarge: rpctypes.ErrGRPCLeaseTTLTooLarge, - - auth.ErrRootUserNotExist: rpctypes.ErrGRPCRootUserNotExist, - auth.ErrRootRoleNotExist: rpctypes.ErrGRPCRootRoleNotExist, - auth.ErrUserAlreadyExist: rpctypes.ErrGRPCUserAlreadyExist, - auth.ErrUserEmpty: rpctypes.ErrGRPCUserEmpty, - auth.ErrUserNotFound: rpctypes.ErrGRPCUserNotFound, - auth.ErrRoleAlreadyExist: rpctypes.ErrGRPCRoleAlreadyExist, - auth.ErrRoleNotFound: rpctypes.ErrGRPCRoleNotFound, - auth.ErrAuthFailed: rpctypes.ErrGRPCAuthFailed, - auth.ErrPermissionDenied: rpctypes.ErrGRPCPermissionDenied, - auth.ErrRoleNotGranted: rpctypes.ErrGRPCRoleNotGranted, - auth.ErrPermissionNotGranted: rpctypes.ErrGRPCPermissionNotGranted, - auth.ErrAuthNotEnabled: rpctypes.ErrGRPCAuthNotEnabled, - auth.ErrInvalidAuthToken: rpctypes.ErrGRPCInvalidAuthToken, - auth.ErrInvalidAuthMgmt: rpctypes.ErrGRPCInvalidAuthMgmt, -} - -func togRPCError(err error) error { - // let gRPC server convert to codes.Canceled, codes.DeadlineExceeded - if err == context.Canceled || err == context.DeadlineExceeded { - return err - } - grpcErr, ok := toGRPCErrorMap[err] - if !ok { - return status.Error(codes.Unknown, err.Error()) - } - return grpcErr -} - -func isClientCtxErr(ctxErr error, err error) bool { - if ctxErr != nil { - return true - } - - ev, ok := status.FromError(err) - if !ok { - return false - } - - switch ev.Code() { - case codes.Canceled, codes.DeadlineExceeded: - // client-side context cancel or deadline exceeded - // "rpc error: code = Canceled desc = context canceled" - // "rpc error: code = DeadlineExceeded desc = context deadline exceeded" - return true - case codes.Unavailable: - msg := ev.Message() - // client-side context cancel or deadline exceeded with TLS ("http2.errClientDisconnected") - // "rpc error: code = Unavailable desc = client disconnected" - if msg == "client disconnected" { - return true - } - // "grpc/transport.ClientTransport.CloseStream" on canceled streams - // "rpc error: code = Unavailable desc = stream error: stream ID 21; CANCEL") - if strings.HasPrefix(msg, "stream error: ") && strings.HasSuffix(msg, "; CANCEL") { - return true - } - } - return false -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/watch.go b/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/watch.go deleted file mode 100644 index dd4f329515d1..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/watch.go +++ /dev/null @@ -1,447 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - "io" - "sync" - "time" - - "github.com/coreos/etcd/auth" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -type watchServer struct { - clusterID int64 - memberID int64 - raftTimer etcdserver.RaftTimer - watchable mvcc.WatchableKV - - ag AuthGetter -} - -func NewWatchServer(s *etcdserver.EtcdServer) pb.WatchServer { - return &watchServer{ - clusterID: int64(s.Cluster().ID()), - memberID: int64(s.ID()), - raftTimer: s, - watchable: s.Watchable(), - ag: s, - } -} - -var ( - // External test can read this with GetProgressReportInterval() - // and change this to a small value to finish fast with - // SetProgressReportInterval(). - progressReportInterval = 10 * time.Minute - progressReportIntervalMu sync.RWMutex -) - -func GetProgressReportInterval() time.Duration { - progressReportIntervalMu.RLock() - defer progressReportIntervalMu.RUnlock() - return progressReportInterval -} - -func SetProgressReportInterval(newTimeout time.Duration) { - progressReportIntervalMu.Lock() - defer progressReportIntervalMu.Unlock() - progressReportInterval = newTimeout -} - -const ( - // We send ctrl response inside the read loop. We do not want - // send to block read, but we still want ctrl response we sent to - // be serialized. Thus we use a buffered chan to solve the problem. - // A small buffer should be OK for most cases, since we expect the - // ctrl requests are infrequent. - ctrlStreamBufLen = 16 -) - -// serverWatchStream is an etcd server side stream. It receives requests -// from client side gRPC stream. It receives watch events from mvcc.WatchStream, -// and creates responses that forwarded to gRPC stream. -// It also forwards control message like watch created and canceled. -type serverWatchStream struct { - clusterID int64 - memberID int64 - raftTimer etcdserver.RaftTimer - - watchable mvcc.WatchableKV - - gRPCStream pb.Watch_WatchServer - watchStream mvcc.WatchStream - ctrlStream chan *pb.WatchResponse - - // mu protects progress, prevKV - mu sync.Mutex - // progress tracks the watchID that stream might need to send - // progress to. - // TODO: combine progress and prevKV into a single struct? - progress map[mvcc.WatchID]bool - prevKV map[mvcc.WatchID]bool - - // closec indicates the stream is closed. - closec chan struct{} - - // wg waits for the send loop to complete - wg sync.WaitGroup - - ag AuthGetter -} - -func (ws *watchServer) Watch(stream pb.Watch_WatchServer) (err error) { - sws := serverWatchStream{ - clusterID: ws.clusterID, - memberID: ws.memberID, - raftTimer: ws.raftTimer, - - watchable: ws.watchable, - - gRPCStream: stream, - watchStream: ws.watchable.NewWatchStream(), - // chan for sending control response like watcher created and canceled. - ctrlStream: make(chan *pb.WatchResponse, ctrlStreamBufLen), - progress: make(map[mvcc.WatchID]bool), - prevKV: make(map[mvcc.WatchID]bool), - closec: make(chan struct{}), - - ag: ws.ag, - } - - sws.wg.Add(1) - go func() { - sws.sendLoop() - sws.wg.Done() - }() - - errc := make(chan error, 1) - // Ideally recvLoop would also use sws.wg to signal its completion - // but when stream.Context().Done() is closed, the stream's recv - // may continue to block since it uses a different context, leading to - // deadlock when calling sws.close(). - go func() { - if rerr := sws.recvLoop(); rerr != nil { - if isClientCtxErr(stream.Context().Err(), rerr) { - plog.Debugf("failed to receive watch request from gRPC stream (%q)", rerr.Error()) - } else { - plog.Warningf("failed to receive watch request from gRPC stream (%q)", rerr.Error()) - } - errc <- rerr - } - }() - select { - case err = <-errc: - close(sws.ctrlStream) - case <-stream.Context().Done(): - err = stream.Context().Err() - // the only server-side cancellation is noleader for now. - if err == context.Canceled { - err = rpctypes.ErrGRPCNoLeader - } - } - sws.close() - return err -} - -func (sws *serverWatchStream) isWatchPermitted(wcr *pb.WatchCreateRequest) bool { - authInfo, err := sws.ag.AuthInfoFromCtx(sws.gRPCStream.Context()) - if err != nil { - return false - } - if authInfo == nil { - // if auth is enabled, IsRangePermitted() can cause an error - authInfo = &auth.AuthInfo{} - } - - return sws.ag.AuthStore().IsRangePermitted(authInfo, wcr.Key, wcr.RangeEnd) == nil -} - -func (sws *serverWatchStream) recvLoop() error { - for { - req, err := sws.gRPCStream.Recv() - if err == io.EOF { - return nil - } - if err != nil { - return err - } - - switch uv := req.RequestUnion.(type) { - case *pb.WatchRequest_CreateRequest: - if uv.CreateRequest == nil { - break - } - - creq := uv.CreateRequest - if len(creq.Key) == 0 { - // \x00 is the smallest key - creq.Key = []byte{0} - } - if len(creq.RangeEnd) == 0 { - // force nil since watchstream.Watch distinguishes - // between nil and []byte{} for single key / >= - creq.RangeEnd = nil - } - if len(creq.RangeEnd) == 1 && creq.RangeEnd[0] == 0 { - // support >= key queries - creq.RangeEnd = []byte{} - } - - if !sws.isWatchPermitted(creq) { - wr := &pb.WatchResponse{ - Header: sws.newResponseHeader(sws.watchStream.Rev()), - WatchId: -1, - Canceled: true, - Created: true, - CancelReason: rpctypes.ErrGRPCPermissionDenied.Error(), - } - - select { - case sws.ctrlStream <- wr: - case <-sws.closec: - } - return nil - } - - filters := FiltersFromRequest(creq) - - wsrev := sws.watchStream.Rev() - rev := creq.StartRevision - if rev == 0 { - rev = wsrev + 1 - } - id := sws.watchStream.Watch(creq.Key, creq.RangeEnd, rev, filters...) - if id != -1 { - sws.mu.Lock() - if creq.ProgressNotify { - sws.progress[id] = true - } - if creq.PrevKv { - sws.prevKV[id] = true - } - sws.mu.Unlock() - } - wr := &pb.WatchResponse{ - Header: sws.newResponseHeader(wsrev), - WatchId: int64(id), - Created: true, - Canceled: id == -1, - } - select { - case sws.ctrlStream <- wr: - case <-sws.closec: - return nil - } - case *pb.WatchRequest_CancelRequest: - if uv.CancelRequest != nil { - id := uv.CancelRequest.WatchId - err := sws.watchStream.Cancel(mvcc.WatchID(id)) - if err == nil { - sws.ctrlStream <- &pb.WatchResponse{ - Header: sws.newResponseHeader(sws.watchStream.Rev()), - WatchId: id, - Canceled: true, - } - sws.mu.Lock() - delete(sws.progress, mvcc.WatchID(id)) - delete(sws.prevKV, mvcc.WatchID(id)) - sws.mu.Unlock() - } - } - default: - // we probably should not shutdown the entire stream when - // receive an valid command. - // so just do nothing instead. - continue - } - } -} - -func (sws *serverWatchStream) sendLoop() { - // watch ids that are currently active - ids := make(map[mvcc.WatchID]struct{}) - // watch responses pending on a watch id creation message - pending := make(map[mvcc.WatchID][]*pb.WatchResponse) - - interval := GetProgressReportInterval() - progressTicker := time.NewTicker(interval) - - defer func() { - progressTicker.Stop() - // drain the chan to clean up pending events - for ws := range sws.watchStream.Chan() { - mvcc.ReportEventReceived(len(ws.Events)) - } - for _, wrs := range pending { - for _, ws := range wrs { - mvcc.ReportEventReceived(len(ws.Events)) - } - } - }() - - for { - select { - case wresp, ok := <-sws.watchStream.Chan(): - if !ok { - return - } - - // TODO: evs is []mvccpb.Event type - // either return []*mvccpb.Event from the mvcc package - // or define protocol buffer with []mvccpb.Event. - evs := wresp.Events - events := make([]*mvccpb.Event, len(evs)) - sws.mu.Lock() - needPrevKV := sws.prevKV[wresp.WatchID] - sws.mu.Unlock() - for i := range evs { - events[i] = &evs[i] - - if needPrevKV { - opt := mvcc.RangeOptions{Rev: evs[i].Kv.ModRevision - 1} - r, err := sws.watchable.Range(evs[i].Kv.Key, nil, opt) - if err == nil && len(r.KVs) != 0 { - events[i].PrevKv = &(r.KVs[0]) - } - } - } - - canceled := wresp.CompactRevision != 0 - wr := &pb.WatchResponse{ - Header: sws.newResponseHeader(wresp.Revision), - WatchId: int64(wresp.WatchID), - Events: events, - CompactRevision: wresp.CompactRevision, - Canceled: canceled, - } - - if _, hasId := ids[wresp.WatchID]; !hasId { - // buffer if id not yet announced - wrs := append(pending[wresp.WatchID], wr) - pending[wresp.WatchID] = wrs - continue - } - - mvcc.ReportEventReceived(len(evs)) - if err := sws.gRPCStream.Send(wr); err != nil { - if isClientCtxErr(sws.gRPCStream.Context().Err(), err) { - plog.Debugf("failed to send watch response to gRPC stream (%q)", err.Error()) - } else { - plog.Warningf("failed to send watch response to gRPC stream (%q)", err.Error()) - } - return - } - - sws.mu.Lock() - if len(evs) > 0 && sws.progress[wresp.WatchID] { - // elide next progress update if sent a key update - sws.progress[wresp.WatchID] = false - } - sws.mu.Unlock() - - case c, ok := <-sws.ctrlStream: - if !ok { - return - } - - if err := sws.gRPCStream.Send(c); err != nil { - if isClientCtxErr(sws.gRPCStream.Context().Err(), err) { - plog.Debugf("failed to send watch control response to gRPC stream (%q)", err.Error()) - } else { - plog.Warningf("failed to send watch control response to gRPC stream (%q)", err.Error()) - } - return - } - - // track id creation - wid := mvcc.WatchID(c.WatchId) - if c.Canceled { - delete(ids, wid) - continue - } - if c.Created { - // flush buffered events - ids[wid] = struct{}{} - for _, v := range pending[wid] { - mvcc.ReportEventReceived(len(v.Events)) - if err := sws.gRPCStream.Send(v); err != nil { - if isClientCtxErr(sws.gRPCStream.Context().Err(), err) { - plog.Debugf("failed to send pending watch response to gRPC stream (%q)", err.Error()) - } else { - plog.Warningf("failed to send pending watch response to gRPC stream (%q)", err.Error()) - } - return - } - } - delete(pending, wid) - } - case <-progressTicker.C: - sws.mu.Lock() - for id, ok := range sws.progress { - if ok { - sws.watchStream.RequestProgress(id) - } - sws.progress[id] = true - } - sws.mu.Unlock() - case <-sws.closec: - return - } - } -} - -func (sws *serverWatchStream) close() { - sws.watchStream.Close() - close(sws.closec) - sws.wg.Wait() -} - -func (sws *serverWatchStream) newResponseHeader(rev int64) *pb.ResponseHeader { - return &pb.ResponseHeader{ - ClusterId: uint64(sws.clusterID), - MemberId: uint64(sws.memberID), - Revision: rev, - RaftTerm: sws.raftTimer.Term(), - } -} - -func filterNoDelete(e mvccpb.Event) bool { - return e.Type == mvccpb.DELETE -} - -func filterNoPut(e mvccpb.Event) bool { - return e.Type == mvccpb.PUT -} - -func FiltersFromRequest(creq *pb.WatchCreateRequest) []mvcc.FilterFunc { - filters := make([]mvcc.FilterFunc, 0, len(creq.Filters)) - for _, ft := range creq.Filters { - switch ft { - case pb.WatchCreateRequest_NOPUT: - filters = append(filters, filterNoPut) - case pb.WatchCreateRequest_NODELETE: - filters = append(filters, filterNoDelete) - default: - } - } - return filters -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/apply.go b/vendor/github.com/coreos/etcd/etcdserver/apply.go deleted file mode 100644 index 93e78e390c80..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/apply.go +++ /dev/null @@ -1,972 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "bytes" - "context" - "sort" - "time" - - "github.com/coreos/etcd/auth" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/mvcc/mvccpb" - "github.com/coreos/etcd/pkg/types" - - "github.com/gogo/protobuf/proto" -) - -const ( - warnApplyDuration = 100 * time.Millisecond -) - -type applyResult struct { - resp proto.Message - err error - // physc signals the physical effect of the request has completed in addition - // to being logically reflected by the node. Currently only used for - // Compaction requests. - physc <-chan struct{} -} - -// applierV3 is the interface for processing V3 raft messages -type applierV3 interface { - Apply(r *pb.InternalRaftRequest) *applyResult - - Put(txn mvcc.TxnWrite, p *pb.PutRequest) (*pb.PutResponse, error) - Range(txn mvcc.TxnRead, r *pb.RangeRequest) (*pb.RangeResponse, error) - DeleteRange(txn mvcc.TxnWrite, dr *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) - Txn(rt *pb.TxnRequest) (*pb.TxnResponse, error) - Compaction(compaction *pb.CompactionRequest) (*pb.CompactionResponse, <-chan struct{}, error) - - LeaseGrant(lc *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) - LeaseRevoke(lc *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) - - Alarm(*pb.AlarmRequest) (*pb.AlarmResponse, error) - - Authenticate(r *pb.InternalAuthenticateRequest) (*pb.AuthenticateResponse, error) - - AuthEnable() (*pb.AuthEnableResponse, error) - AuthDisable() (*pb.AuthDisableResponse, error) - - UserAdd(ua *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) - UserDelete(ua *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) - UserChangePassword(ua *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) - UserGrantRole(ua *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) - UserGet(ua *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) - UserRevokeRole(ua *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) - RoleAdd(ua *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) - RoleGrantPermission(ua *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) - RoleGet(ua *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) - RoleRevokePermission(ua *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) - RoleDelete(ua *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) - UserList(ua *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) - RoleList(ua *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) -} - -type checkReqFunc func(mvcc.ReadView, *pb.RequestOp) error - -type applierV3backend struct { - s *EtcdServer - - checkPut checkReqFunc - checkRange checkReqFunc -} - -func (s *EtcdServer) newApplierV3Backend() applierV3 { - base := &applierV3backend{s: s} - base.checkPut = func(rv mvcc.ReadView, req *pb.RequestOp) error { - return base.checkRequestPut(rv, req) - } - base.checkRange = func(rv mvcc.ReadView, req *pb.RequestOp) error { - return base.checkRequestRange(rv, req) - } - return base -} - -func (s *EtcdServer) newApplierV3() applierV3 { - return newAuthApplierV3( - s.AuthStore(), - newQuotaApplierV3(s, s.newApplierV3Backend()), - s.lessor, - ) -} - -func (a *applierV3backend) Apply(r *pb.InternalRaftRequest) *applyResult { - ar := &applyResult{} - defer func(start time.Time) { - warnOfExpensiveRequest(start, &pb.InternalRaftStringer{Request: r}, ar.resp, ar.err) - }(time.Now()) - - // call into a.s.applyV3.F instead of a.F so upper appliers can check individual calls - switch { - case r.Range != nil: - ar.resp, ar.err = a.s.applyV3.Range(nil, r.Range) - case r.Put != nil: - ar.resp, ar.err = a.s.applyV3.Put(nil, r.Put) - case r.DeleteRange != nil: - ar.resp, ar.err = a.s.applyV3.DeleteRange(nil, r.DeleteRange) - case r.Txn != nil: - ar.resp, ar.err = a.s.applyV3.Txn(r.Txn) - case r.Compaction != nil: - ar.resp, ar.physc, ar.err = a.s.applyV3.Compaction(r.Compaction) - case r.LeaseGrant != nil: - ar.resp, ar.err = a.s.applyV3.LeaseGrant(r.LeaseGrant) - case r.LeaseRevoke != nil: - ar.resp, ar.err = a.s.applyV3.LeaseRevoke(r.LeaseRevoke) - case r.Alarm != nil: - ar.resp, ar.err = a.s.applyV3.Alarm(r.Alarm) - case r.Authenticate != nil: - ar.resp, ar.err = a.s.applyV3.Authenticate(r.Authenticate) - case r.AuthEnable != nil: - ar.resp, ar.err = a.s.applyV3.AuthEnable() - case r.AuthDisable != nil: - ar.resp, ar.err = a.s.applyV3.AuthDisable() - case r.AuthUserAdd != nil: - ar.resp, ar.err = a.s.applyV3.UserAdd(r.AuthUserAdd) - case r.AuthUserDelete != nil: - ar.resp, ar.err = a.s.applyV3.UserDelete(r.AuthUserDelete) - case r.AuthUserChangePassword != nil: - ar.resp, ar.err = a.s.applyV3.UserChangePassword(r.AuthUserChangePassword) - case r.AuthUserGrantRole != nil: - ar.resp, ar.err = a.s.applyV3.UserGrantRole(r.AuthUserGrantRole) - case r.AuthUserGet != nil: - ar.resp, ar.err = a.s.applyV3.UserGet(r.AuthUserGet) - case r.AuthUserRevokeRole != nil: - ar.resp, ar.err = a.s.applyV3.UserRevokeRole(r.AuthUserRevokeRole) - case r.AuthRoleAdd != nil: - ar.resp, ar.err = a.s.applyV3.RoleAdd(r.AuthRoleAdd) - case r.AuthRoleGrantPermission != nil: - ar.resp, ar.err = a.s.applyV3.RoleGrantPermission(r.AuthRoleGrantPermission) - case r.AuthRoleGet != nil: - ar.resp, ar.err = a.s.applyV3.RoleGet(r.AuthRoleGet) - case r.AuthRoleRevokePermission != nil: - ar.resp, ar.err = a.s.applyV3.RoleRevokePermission(r.AuthRoleRevokePermission) - case r.AuthRoleDelete != nil: - ar.resp, ar.err = a.s.applyV3.RoleDelete(r.AuthRoleDelete) - case r.AuthUserList != nil: - ar.resp, ar.err = a.s.applyV3.UserList(r.AuthUserList) - case r.AuthRoleList != nil: - ar.resp, ar.err = a.s.applyV3.RoleList(r.AuthRoleList) - default: - panic("not implemented") - } - return ar -} - -func (a *applierV3backend) Put(txn mvcc.TxnWrite, p *pb.PutRequest) (resp *pb.PutResponse, err error) { - resp = &pb.PutResponse{} - resp.Header = &pb.ResponseHeader{} - - val, leaseID := p.Value, lease.LeaseID(p.Lease) - if txn == nil { - if leaseID != lease.NoLease { - if l := a.s.lessor.Lookup(leaseID); l == nil { - return nil, lease.ErrLeaseNotFound - } - } - txn = a.s.KV().Write() - defer txn.End() - } - - var rr *mvcc.RangeResult - if p.IgnoreValue || p.IgnoreLease || p.PrevKv { - rr, err = txn.Range(p.Key, nil, mvcc.RangeOptions{}) - if err != nil { - return nil, err - } - } - if p.IgnoreValue || p.IgnoreLease { - if rr == nil || len(rr.KVs) == 0 { - // ignore_{lease,value} flag expects previous key-value pair - return nil, ErrKeyNotFound - } - } - if p.IgnoreValue { - val = rr.KVs[0].Value - } - if p.IgnoreLease { - leaseID = lease.LeaseID(rr.KVs[0].Lease) - } - if p.PrevKv { - if rr != nil && len(rr.KVs) != 0 { - resp.PrevKv = &rr.KVs[0] - } - } - - resp.Header.Revision = txn.Put(p.Key, val, leaseID) - return resp, nil -} - -func (a *applierV3backend) DeleteRange(txn mvcc.TxnWrite, dr *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) { - resp := &pb.DeleteRangeResponse{} - resp.Header = &pb.ResponseHeader{} - end := mkGteRange(dr.RangeEnd) - - if txn == nil { - txn = a.s.kv.Write() - defer txn.End() - } - - if dr.PrevKv { - rr, err := txn.Range(dr.Key, end, mvcc.RangeOptions{}) - if err != nil { - return nil, err - } - if rr != nil { - resp.PrevKvs = make([]*mvccpb.KeyValue, len(rr.KVs)) - for i := range rr.KVs { - resp.PrevKvs[i] = &rr.KVs[i] - } - } - } - - resp.Deleted, resp.Header.Revision = txn.DeleteRange(dr.Key, end) - return resp, nil -} - -func (a *applierV3backend) Range(txn mvcc.TxnRead, r *pb.RangeRequest) (*pb.RangeResponse, error) { - resp := &pb.RangeResponse{} - resp.Header = &pb.ResponseHeader{} - - if txn == nil { - txn = a.s.kv.Read() - defer txn.End() - } - - limit := r.Limit - if r.SortOrder != pb.RangeRequest_NONE || - r.MinModRevision != 0 || r.MaxModRevision != 0 || - r.MinCreateRevision != 0 || r.MaxCreateRevision != 0 { - // fetch everything; sort and truncate afterwards - limit = 0 - } - if limit > 0 { - // fetch one extra for 'more' flag - limit = limit + 1 - } - - ro := mvcc.RangeOptions{ - Limit: limit, - Rev: r.Revision, - Count: r.CountOnly, - } - - rr, err := txn.Range(r.Key, mkGteRange(r.RangeEnd), ro) - if err != nil { - return nil, err - } - - if r.MaxModRevision != 0 { - f := func(kv *mvccpb.KeyValue) bool { return kv.ModRevision > r.MaxModRevision } - pruneKVs(rr, f) - } - if r.MinModRevision != 0 { - f := func(kv *mvccpb.KeyValue) bool { return kv.ModRevision < r.MinModRevision } - pruneKVs(rr, f) - } - if r.MaxCreateRevision != 0 { - f := func(kv *mvccpb.KeyValue) bool { return kv.CreateRevision > r.MaxCreateRevision } - pruneKVs(rr, f) - } - if r.MinCreateRevision != 0 { - f := func(kv *mvccpb.KeyValue) bool { return kv.CreateRevision < r.MinCreateRevision } - pruneKVs(rr, f) - } - - sortOrder := r.SortOrder - if r.SortTarget != pb.RangeRequest_KEY && sortOrder == pb.RangeRequest_NONE { - // Since current mvcc.Range implementation returns results - // sorted by keys in lexiographically ascending order, - // sort ASCEND by default only when target is not 'KEY' - sortOrder = pb.RangeRequest_ASCEND - } - if sortOrder != pb.RangeRequest_NONE { - var sorter sort.Interface - switch { - case r.SortTarget == pb.RangeRequest_KEY: - sorter = &kvSortByKey{&kvSort{rr.KVs}} - case r.SortTarget == pb.RangeRequest_VERSION: - sorter = &kvSortByVersion{&kvSort{rr.KVs}} - case r.SortTarget == pb.RangeRequest_CREATE: - sorter = &kvSortByCreate{&kvSort{rr.KVs}} - case r.SortTarget == pb.RangeRequest_MOD: - sorter = &kvSortByMod{&kvSort{rr.KVs}} - case r.SortTarget == pb.RangeRequest_VALUE: - sorter = &kvSortByValue{&kvSort{rr.KVs}} - } - switch { - case sortOrder == pb.RangeRequest_ASCEND: - sort.Sort(sorter) - case sortOrder == pb.RangeRequest_DESCEND: - sort.Sort(sort.Reverse(sorter)) - } - } - - if r.Limit > 0 && len(rr.KVs) > int(r.Limit) { - rr.KVs = rr.KVs[:r.Limit] - resp.More = true - } - - resp.Header.Revision = rr.Rev - resp.Count = int64(rr.Count) - resp.Kvs = make([]*mvccpb.KeyValue, len(rr.KVs)) - for i := range rr.KVs { - if r.KeysOnly { - rr.KVs[i].Value = nil - } - resp.Kvs[i] = &rr.KVs[i] - } - return resp, nil -} - -func (a *applierV3backend) Txn(rt *pb.TxnRequest) (*pb.TxnResponse, error) { - isWrite := !isTxnReadonly(rt) - txn := mvcc.NewReadOnlyTxnWrite(a.s.KV().Read()) - - txnPath := compareToPath(txn, rt) - if isWrite { - if _, err := checkRequests(txn, rt, txnPath, a.checkPut); err != nil { - txn.End() - return nil, err - } - } - if _, err := checkRequests(txn, rt, txnPath, a.checkRange); err != nil { - txn.End() - return nil, err - } - - txnResp, _ := newTxnResp(rt, txnPath) - - // When executing mutable txn ops, etcd must hold the txn lock so - // readers do not see any intermediate results. Since writes are - // serialized on the raft loop, the revision in the read view will - // be the revision of the write txn. - if isWrite { - txn.End() - txn = a.s.KV().Write() - } - a.applyTxn(txn, rt, txnPath, txnResp) - rev := txn.Rev() - if len(txn.Changes()) != 0 { - rev++ - } - txn.End() - - txnResp.Header.Revision = rev - return txnResp, nil -} - -// newTxnResp allocates a txn response for a txn request given a path. -func newTxnResp(rt *pb.TxnRequest, txnPath []bool) (txnResp *pb.TxnResponse, txnCount int) { - reqs := rt.Success - if !txnPath[0] { - reqs = rt.Failure - } - resps := make([]*pb.ResponseOp, len(reqs)) - txnResp = &pb.TxnResponse{ - Responses: resps, - Succeeded: txnPath[0], - Header: &pb.ResponseHeader{}, - } - for i, req := range reqs { - switch tv := req.Request.(type) { - case *pb.RequestOp_RequestRange: - resps[i] = &pb.ResponseOp{Response: &pb.ResponseOp_ResponseRange{}} - case *pb.RequestOp_RequestPut: - resps[i] = &pb.ResponseOp{Response: &pb.ResponseOp_ResponsePut{}} - case *pb.RequestOp_RequestDeleteRange: - resps[i] = &pb.ResponseOp{Response: &pb.ResponseOp_ResponseDeleteRange{}} - case *pb.RequestOp_RequestTxn: - resp, txns := newTxnResp(tv.RequestTxn, txnPath[1:]) - resps[i] = &pb.ResponseOp{Response: &pb.ResponseOp_ResponseTxn{ResponseTxn: resp}} - txnPath = txnPath[1+txns:] - txnCount += txns + 1 - default: - } - } - return txnResp, txnCount -} - -func compareToPath(rv mvcc.ReadView, rt *pb.TxnRequest) []bool { - txnPath := make([]bool, 1) - ops := rt.Success - if txnPath[0] = applyCompares(rv, rt.Compare); !txnPath[0] { - ops = rt.Failure - } - for _, op := range ops { - tv, ok := op.Request.(*pb.RequestOp_RequestTxn) - if !ok || tv.RequestTxn == nil { - continue - } - txnPath = append(txnPath, compareToPath(rv, tv.RequestTxn)...) - } - return txnPath -} - -func applyCompares(rv mvcc.ReadView, cmps []*pb.Compare) bool { - for _, c := range cmps { - if !applyCompare(rv, c) { - return false - } - } - return true -} - -// applyCompare applies the compare request. -// If the comparison succeeds, it returns true. Otherwise, returns false. -func applyCompare(rv mvcc.ReadView, c *pb.Compare) bool { - // TODO: possible optimizations - // * chunk reads for large ranges to conserve memory - // * rewrite rules for common patterns: - // ex. "[a, b) createrev > 0" => "limit 1 /\ kvs > 0" - // * caching - rr, err := rv.Range(c.Key, mkGteRange(c.RangeEnd), mvcc.RangeOptions{}) - if err != nil { - return false - } - if len(rr.KVs) == 0 { - if c.Target == pb.Compare_VALUE { - // Always fail if comparing a value on a key/keys that doesn't exist; - // nil == empty string in grpc; no way to represent missing value - return false - } - return compareKV(c, mvccpb.KeyValue{}) - } - for _, kv := range rr.KVs { - if !compareKV(c, kv) { - return false - } - } - return true -} - -func compareKV(c *pb.Compare, ckv mvccpb.KeyValue) bool { - var result int - rev := int64(0) - switch c.Target { - case pb.Compare_VALUE: - v := []byte{} - if tv, _ := c.TargetUnion.(*pb.Compare_Value); tv != nil { - v = tv.Value - } - result = bytes.Compare(ckv.Value, v) - case pb.Compare_CREATE: - if tv, _ := c.TargetUnion.(*pb.Compare_CreateRevision); tv != nil { - rev = tv.CreateRevision - } - result = compareInt64(ckv.CreateRevision, rev) - case pb.Compare_MOD: - if tv, _ := c.TargetUnion.(*pb.Compare_ModRevision); tv != nil { - rev = tv.ModRevision - } - result = compareInt64(ckv.ModRevision, rev) - case pb.Compare_VERSION: - if tv, _ := c.TargetUnion.(*pb.Compare_Version); tv != nil { - rev = tv.Version - } - result = compareInt64(ckv.Version, rev) - case pb.Compare_LEASE: - if tv, _ := c.TargetUnion.(*pb.Compare_Lease); tv != nil { - rev = tv.Lease - } - result = compareInt64(ckv.Lease, rev) - } - switch c.Result { - case pb.Compare_EQUAL: - return result == 0 - case pb.Compare_NOT_EQUAL: - return result != 0 - case pb.Compare_GREATER: - return result > 0 - case pb.Compare_LESS: - return result < 0 - } - return true -} - -func (a *applierV3backend) applyTxn(txn mvcc.TxnWrite, rt *pb.TxnRequest, txnPath []bool, tresp *pb.TxnResponse) (txns int) { - reqs := rt.Success - if !txnPath[0] { - reqs = rt.Failure - } - for i, req := range reqs { - respi := tresp.Responses[i].Response - switch tv := req.Request.(type) { - case *pb.RequestOp_RequestRange: - resp, err := a.Range(txn, tv.RequestRange) - if err != nil { - plog.Panicf("unexpected error during txn: %v", err) - } - respi.(*pb.ResponseOp_ResponseRange).ResponseRange = resp - case *pb.RequestOp_RequestPut: - resp, err := a.Put(txn, tv.RequestPut) - if err != nil { - plog.Panicf("unexpected error during txn: %v", err) - } - respi.(*pb.ResponseOp_ResponsePut).ResponsePut = resp - case *pb.RequestOp_RequestDeleteRange: - resp, err := a.DeleteRange(txn, tv.RequestDeleteRange) - if err != nil { - plog.Panicf("unexpected error during txn: %v", err) - } - respi.(*pb.ResponseOp_ResponseDeleteRange).ResponseDeleteRange = resp - case *pb.RequestOp_RequestTxn: - resp := respi.(*pb.ResponseOp_ResponseTxn).ResponseTxn - applyTxns := a.applyTxn(txn, tv.RequestTxn, txnPath[1:], resp) - txns += applyTxns + 1 - txnPath = txnPath[applyTxns+1:] - default: - // empty union - } - } - return txns -} - -func (a *applierV3backend) Compaction(compaction *pb.CompactionRequest) (*pb.CompactionResponse, <-chan struct{}, error) { - resp := &pb.CompactionResponse{} - resp.Header = &pb.ResponseHeader{} - ch, err := a.s.KV().Compact(compaction.Revision) - if err != nil { - return nil, ch, err - } - // get the current revision. which key to get is not important. - rr, _ := a.s.KV().Range([]byte("compaction"), nil, mvcc.RangeOptions{}) - resp.Header.Revision = rr.Rev - return resp, ch, err -} - -func (a *applierV3backend) LeaseGrant(lc *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - l, err := a.s.lessor.Grant(lease.LeaseID(lc.ID), lc.TTL) - resp := &pb.LeaseGrantResponse{} - if err == nil { - resp.ID = int64(l.ID) - resp.TTL = l.TTL() - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) LeaseRevoke(lc *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) { - err := a.s.lessor.Revoke(lease.LeaseID(lc.ID)) - return &pb.LeaseRevokeResponse{Header: newHeader(a.s)}, err -} - -func (a *applierV3backend) Alarm(ar *pb.AlarmRequest) (*pb.AlarmResponse, error) { - resp := &pb.AlarmResponse{} - oldCount := len(a.s.alarmStore.Get(ar.Alarm)) - - switch ar.Action { - case pb.AlarmRequest_GET: - resp.Alarms = a.s.alarmStore.Get(ar.Alarm) - case pb.AlarmRequest_ACTIVATE: - m := a.s.alarmStore.Activate(types.ID(ar.MemberID), ar.Alarm) - if m == nil { - break - } - resp.Alarms = append(resp.Alarms, m) - activated := oldCount == 0 && len(a.s.alarmStore.Get(m.Alarm)) == 1 - if !activated { - break - } - - plog.Warningf("alarm %v raised by peer %s", m.Alarm, types.ID(m.MemberID)) - switch m.Alarm { - case pb.AlarmType_CORRUPT: - a.s.applyV3 = newApplierV3Corrupt(a) - case pb.AlarmType_NOSPACE: - a.s.applyV3 = newApplierV3Capped(a) - default: - plog.Errorf("unimplemented alarm activation (%+v)", m) - } - case pb.AlarmRequest_DEACTIVATE: - m := a.s.alarmStore.Deactivate(types.ID(ar.MemberID), ar.Alarm) - if m == nil { - break - } - resp.Alarms = append(resp.Alarms, m) - deactivated := oldCount > 0 && len(a.s.alarmStore.Get(ar.Alarm)) == 0 - if !deactivated { - break - } - - switch m.Alarm { - case pb.AlarmType_NOSPACE, pb.AlarmType_CORRUPT: - // TODO: check kv hash before deactivating CORRUPT? - plog.Infof("alarm disarmed %+v", ar) - a.s.applyV3 = a.s.newApplierV3() - default: - plog.Errorf("unimplemented alarm deactivation (%+v)", m) - } - default: - return nil, nil - } - return resp, nil -} - -type applierV3Capped struct { - applierV3 - q backendQuota -} - -// newApplierV3Capped creates an applyV3 that will reject Puts and transactions -// with Puts so that the number of keys in the store is capped. -func newApplierV3Capped(base applierV3) applierV3 { return &applierV3Capped{applierV3: base} } - -func (a *applierV3Capped) Put(txn mvcc.TxnWrite, p *pb.PutRequest) (*pb.PutResponse, error) { - return nil, ErrNoSpace -} - -func (a *applierV3Capped) Txn(r *pb.TxnRequest) (*pb.TxnResponse, error) { - if a.q.Cost(r) > 0 { - return nil, ErrNoSpace - } - return a.applierV3.Txn(r) -} - -func (a *applierV3Capped) LeaseGrant(lc *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - return nil, ErrNoSpace -} - -func (a *applierV3backend) AuthEnable() (*pb.AuthEnableResponse, error) { - err := a.s.AuthStore().AuthEnable() - if err != nil { - return nil, err - } - return &pb.AuthEnableResponse{Header: newHeader(a.s)}, nil -} - -func (a *applierV3backend) AuthDisable() (*pb.AuthDisableResponse, error) { - a.s.AuthStore().AuthDisable() - return &pb.AuthDisableResponse{Header: newHeader(a.s)}, nil -} - -func (a *applierV3backend) Authenticate(r *pb.InternalAuthenticateRequest) (*pb.AuthenticateResponse, error) { - ctx := context.WithValue(context.WithValue(a.s.ctx, auth.AuthenticateParamIndex{}, a.s.consistIndex.ConsistentIndex()), auth.AuthenticateParamSimpleTokenPrefix{}, r.SimpleToken) - resp, err := a.s.AuthStore().Authenticate(ctx, r.Name, r.Password) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserAdd(r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) { - resp, err := a.s.AuthStore().UserAdd(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserDelete(r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) { - resp, err := a.s.AuthStore().UserDelete(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserChangePassword(r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) { - resp, err := a.s.AuthStore().UserChangePassword(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserGrantRole(r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) { - resp, err := a.s.AuthStore().UserGrantRole(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserGet(r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) { - resp, err := a.s.AuthStore().UserGet(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserRevokeRole(r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) { - resp, err := a.s.AuthStore().UserRevokeRole(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) RoleAdd(r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) { - resp, err := a.s.AuthStore().RoleAdd(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) RoleGrantPermission(r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) { - resp, err := a.s.AuthStore().RoleGrantPermission(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) RoleGet(r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) { - resp, err := a.s.AuthStore().RoleGet(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) RoleRevokePermission(r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) { - resp, err := a.s.AuthStore().RoleRevokePermission(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) RoleDelete(r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) { - resp, err := a.s.AuthStore().RoleDelete(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserList(r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) { - resp, err := a.s.AuthStore().UserList(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) RoleList(r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) { - resp, err := a.s.AuthStore().RoleList(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -type quotaApplierV3 struct { - applierV3 - q Quota -} - -func newQuotaApplierV3(s *EtcdServer, app applierV3) applierV3 { - return "aApplierV3{app, NewBackendQuota(s)} -} - -func (a *quotaApplierV3) Put(txn mvcc.TxnWrite, p *pb.PutRequest) (*pb.PutResponse, error) { - ok := a.q.Available(p) - resp, err := a.applierV3.Put(txn, p) - if err == nil && !ok { - err = ErrNoSpace - } - return resp, err -} - -func (a *quotaApplierV3) Txn(rt *pb.TxnRequest) (*pb.TxnResponse, error) { - ok := a.q.Available(rt) - resp, err := a.applierV3.Txn(rt) - if err == nil && !ok { - err = ErrNoSpace - } - return resp, err -} - -func (a *quotaApplierV3) LeaseGrant(lc *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - ok := a.q.Available(lc) - resp, err := a.applierV3.LeaseGrant(lc) - if err == nil && !ok { - err = ErrNoSpace - } - return resp, err -} - -type kvSort struct{ kvs []mvccpb.KeyValue } - -func (s *kvSort) Swap(i, j int) { - t := s.kvs[i] - s.kvs[i] = s.kvs[j] - s.kvs[j] = t -} -func (s *kvSort) Len() int { return len(s.kvs) } - -type kvSortByKey struct{ *kvSort } - -func (s *kvSortByKey) Less(i, j int) bool { - return bytes.Compare(s.kvs[i].Key, s.kvs[j].Key) < 0 -} - -type kvSortByVersion struct{ *kvSort } - -func (s *kvSortByVersion) Less(i, j int) bool { - return (s.kvs[i].Version - s.kvs[j].Version) < 0 -} - -type kvSortByCreate struct{ *kvSort } - -func (s *kvSortByCreate) Less(i, j int) bool { - return (s.kvs[i].CreateRevision - s.kvs[j].CreateRevision) < 0 -} - -type kvSortByMod struct{ *kvSort } - -func (s *kvSortByMod) Less(i, j int) bool { - return (s.kvs[i].ModRevision - s.kvs[j].ModRevision) < 0 -} - -type kvSortByValue struct{ *kvSort } - -func (s *kvSortByValue) Less(i, j int) bool { - return bytes.Compare(s.kvs[i].Value, s.kvs[j].Value) < 0 -} - -func checkRequests(rv mvcc.ReadView, rt *pb.TxnRequest, txnPath []bool, f checkReqFunc) (int, error) { - txnCount := 0 - reqs := rt.Success - if !txnPath[0] { - reqs = rt.Failure - } - for _, req := range reqs { - if tv, ok := req.Request.(*pb.RequestOp_RequestTxn); ok && tv.RequestTxn != nil { - txns, err := checkRequests(rv, tv.RequestTxn, txnPath[1:], f) - if err != nil { - return 0, err - } - txnCount += txns + 1 - txnPath = txnPath[txns+1:] - continue - } - if err := f(rv, req); err != nil { - return 0, err - } - } - return txnCount, nil -} - -func (a *applierV3backend) checkRequestPut(rv mvcc.ReadView, reqOp *pb.RequestOp) error { - tv, ok := reqOp.Request.(*pb.RequestOp_RequestPut) - if !ok || tv.RequestPut == nil { - return nil - } - req := tv.RequestPut - if req.IgnoreValue || req.IgnoreLease { - // expects previous key-value, error if not exist - rr, err := rv.Range(req.Key, nil, mvcc.RangeOptions{}) - if err != nil { - return err - } - if rr == nil || len(rr.KVs) == 0 { - return ErrKeyNotFound - } - } - if lease.LeaseID(req.Lease) != lease.NoLease { - if l := a.s.lessor.Lookup(lease.LeaseID(req.Lease)); l == nil { - return lease.ErrLeaseNotFound - } - } - return nil -} - -func (a *applierV3backend) checkRequestRange(rv mvcc.ReadView, reqOp *pb.RequestOp) error { - tv, ok := reqOp.Request.(*pb.RequestOp_RequestRange) - if !ok || tv.RequestRange == nil { - return nil - } - req := tv.RequestRange - switch { - case req.Revision == 0: - return nil - case req.Revision > rv.Rev(): - return mvcc.ErrFutureRev - case req.Revision < rv.FirstRev(): - return mvcc.ErrCompacted - } - return nil -} - -func compareInt64(a, b int64) int { - switch { - case a < b: - return -1 - case a > b: - return 1 - default: - return 0 - } -} - -// mkGteRange determines if the range end is a >= range. This works around grpc -// sending empty byte strings as nil; >= is encoded in the range end as '\0'. -// If it is a GTE range, then []byte{} is returned to indicate the empty byte -// string (vs nil being no byte string). -func mkGteRange(rangeEnd []byte) []byte { - if len(rangeEnd) == 1 && rangeEnd[0] == 0 { - return []byte{} - } - return rangeEnd -} - -func noSideEffect(r *pb.InternalRaftRequest) bool { - return r.Range != nil || r.AuthUserGet != nil || r.AuthRoleGet != nil -} - -func removeNeedlessRangeReqs(txn *pb.TxnRequest) { - f := func(ops []*pb.RequestOp) []*pb.RequestOp { - j := 0 - for i := 0; i < len(ops); i++ { - if _, ok := ops[i].Request.(*pb.RequestOp_RequestRange); ok { - continue - } - ops[j] = ops[i] - j++ - } - - return ops[:j] - } - - txn.Success = f(txn.Success) - txn.Failure = f(txn.Failure) -} - -func pruneKVs(rr *mvcc.RangeResult, isPrunable func(*mvccpb.KeyValue) bool) { - j := 0 - for i := range rr.KVs { - rr.KVs[j] = rr.KVs[i] - if !isPrunable(&rr.KVs[i]) { - j++ - } - } - rr.KVs = rr.KVs[:j] -} - -func newHeader(s *EtcdServer) *pb.ResponseHeader { - return &pb.ResponseHeader{ - ClusterId: uint64(s.Cluster().ID()), - MemberId: uint64(s.ID()), - Revision: s.KV().Rev(), - RaftTerm: s.Term(), - } -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/apply_auth.go b/vendor/github.com/coreos/etcd/etcdserver/apply_auth.go deleted file mode 100644 index ec9391435dab..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/apply_auth.go +++ /dev/null @@ -1,245 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "sync" - - "github.com/coreos/etcd/auth" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/mvcc" -) - -type authApplierV3 struct { - applierV3 - as auth.AuthStore - lessor lease.Lessor - - // mu serializes Apply so that user isn't corrupted and so that - // serialized requests don't leak data from TOCTOU errors - mu sync.Mutex - - authInfo auth.AuthInfo -} - -func newAuthApplierV3(as auth.AuthStore, base applierV3, lessor lease.Lessor) *authApplierV3 { - return &authApplierV3{applierV3: base, as: as, lessor: lessor} -} - -func (aa *authApplierV3) Apply(r *pb.InternalRaftRequest) *applyResult { - aa.mu.Lock() - defer aa.mu.Unlock() - if r.Header != nil { - // backward-compatible with pre-3.0 releases when internalRaftRequest - // does not have header field - aa.authInfo.Username = r.Header.Username - aa.authInfo.Revision = r.Header.AuthRevision - } - if needAdminPermission(r) { - if err := aa.as.IsAdminPermitted(&aa.authInfo); err != nil { - aa.authInfo.Username = "" - aa.authInfo.Revision = 0 - return &applyResult{err: err} - } - } - ret := aa.applierV3.Apply(r) - aa.authInfo.Username = "" - aa.authInfo.Revision = 0 - return ret -} - -func (aa *authApplierV3) Put(txn mvcc.TxnWrite, r *pb.PutRequest) (*pb.PutResponse, error) { - if err := aa.as.IsPutPermitted(&aa.authInfo, r.Key); err != nil { - return nil, err - } - - if err := aa.checkLeasePuts(lease.LeaseID(r.Lease)); err != nil { - // The specified lease is already attached with a key that cannot - // be written by this user. It means the user cannot revoke the - // lease so attaching the lease to the newly written key should - // be forbidden. - return nil, err - } - - if r.PrevKv { - err := aa.as.IsRangePermitted(&aa.authInfo, r.Key, nil) - if err != nil { - return nil, err - } - } - return aa.applierV3.Put(txn, r) -} - -func (aa *authApplierV3) Range(txn mvcc.TxnRead, r *pb.RangeRequest) (*pb.RangeResponse, error) { - if err := aa.as.IsRangePermitted(&aa.authInfo, r.Key, r.RangeEnd); err != nil { - return nil, err - } - return aa.applierV3.Range(txn, r) -} - -func (aa *authApplierV3) DeleteRange(txn mvcc.TxnWrite, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) { - if err := aa.as.IsDeleteRangePermitted(&aa.authInfo, r.Key, r.RangeEnd); err != nil { - return nil, err - } - if r.PrevKv { - err := aa.as.IsRangePermitted(&aa.authInfo, r.Key, r.RangeEnd) - if err != nil { - return nil, err - } - } - - return aa.applierV3.DeleteRange(txn, r) -} - -func checkTxnReqsPermission(as auth.AuthStore, ai *auth.AuthInfo, reqs []*pb.RequestOp) error { - for _, requ := range reqs { - switch tv := requ.Request.(type) { - case *pb.RequestOp_RequestRange: - if tv.RequestRange == nil { - continue - } - - if err := as.IsRangePermitted(ai, tv.RequestRange.Key, tv.RequestRange.RangeEnd); err != nil { - return err - } - - case *pb.RequestOp_RequestPut: - if tv.RequestPut == nil { - continue - } - - if err := as.IsPutPermitted(ai, tv.RequestPut.Key); err != nil { - return err - } - - case *pb.RequestOp_RequestDeleteRange: - if tv.RequestDeleteRange == nil { - continue - } - - if tv.RequestDeleteRange.PrevKv { - err := as.IsRangePermitted(ai, tv.RequestDeleteRange.Key, tv.RequestDeleteRange.RangeEnd) - if err != nil { - return err - } - } - - err := as.IsDeleteRangePermitted(ai, tv.RequestDeleteRange.Key, tv.RequestDeleteRange.RangeEnd) - if err != nil { - return err - } - } - } - - return nil -} - -func checkTxnAuth(as auth.AuthStore, ai *auth.AuthInfo, rt *pb.TxnRequest) error { - for _, c := range rt.Compare { - if err := as.IsRangePermitted(ai, c.Key, c.RangeEnd); err != nil { - return err - } - } - if err := checkTxnReqsPermission(as, ai, rt.Success); err != nil { - return err - } - if err := checkTxnReqsPermission(as, ai, rt.Failure); err != nil { - return err - } - return nil -} - -func (aa *authApplierV3) Txn(rt *pb.TxnRequest) (*pb.TxnResponse, error) { - if err := checkTxnAuth(aa.as, &aa.authInfo, rt); err != nil { - return nil, err - } - return aa.applierV3.Txn(rt) -} - -func (aa *authApplierV3) LeaseRevoke(lc *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) { - if err := aa.checkLeasePuts(lease.LeaseID(lc.ID)); err != nil { - return nil, err - } - return aa.applierV3.LeaseRevoke(lc) -} - -func (aa *authApplierV3) checkLeasePuts(leaseID lease.LeaseID) error { - lease := aa.lessor.Lookup(leaseID) - if lease != nil { - for _, key := range lease.Keys() { - if err := aa.as.IsPutPermitted(&aa.authInfo, []byte(key)); err != nil { - return err - } - } - } - - return nil -} - -func (aa *authApplierV3) UserGet(r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) { - err := aa.as.IsAdminPermitted(&aa.authInfo) - if err != nil && r.Name != aa.authInfo.Username { - aa.authInfo.Username = "" - aa.authInfo.Revision = 0 - return &pb.AuthUserGetResponse{}, err - } - - return aa.applierV3.UserGet(r) -} - -func (aa *authApplierV3) RoleGet(r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) { - err := aa.as.IsAdminPermitted(&aa.authInfo) - if err != nil && !aa.as.HasRole(aa.authInfo.Username, r.Role) { - aa.authInfo.Username = "" - aa.authInfo.Revision = 0 - return &pb.AuthRoleGetResponse{}, err - } - - return aa.applierV3.RoleGet(r) -} - -func needAdminPermission(r *pb.InternalRaftRequest) bool { - switch { - case r.AuthEnable != nil: - return true - case r.AuthDisable != nil: - return true - case r.AuthUserAdd != nil: - return true - case r.AuthUserDelete != nil: - return true - case r.AuthUserChangePassword != nil: - return true - case r.AuthUserGrantRole != nil: - return true - case r.AuthUserRevokeRole != nil: - return true - case r.AuthRoleAdd != nil: - return true - case r.AuthRoleGrantPermission != nil: - return true - case r.AuthRoleRevokePermission != nil: - return true - case r.AuthRoleDelete != nil: - return true - case r.AuthUserList != nil: - return true - case r.AuthRoleList != nil: - return true - default: - return false - } -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/apply_v2.go b/vendor/github.com/coreos/etcd/etcdserver/apply_v2.go deleted file mode 100644 index a49b6823da99..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/apply_v2.go +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "encoding/json" - "path" - "time" - - "github.com/coreos/etcd/etcdserver/api" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/store" - "github.com/coreos/go-semver/semver" -) - -// ApplierV2 is the interface for processing V2 raft messages -type ApplierV2 interface { - Delete(r *RequestV2) Response - Post(r *RequestV2) Response - Put(r *RequestV2) Response - QGet(r *RequestV2) Response - Sync(r *RequestV2) Response -} - -func NewApplierV2(s store.Store, c *membership.RaftCluster) ApplierV2 { - return &applierV2store{store: s, cluster: c} -} - -type applierV2store struct { - store store.Store - cluster *membership.RaftCluster -} - -func (a *applierV2store) Delete(r *RequestV2) Response { - switch { - case r.PrevIndex > 0 || r.PrevValue != "": - return toResponse(a.store.CompareAndDelete(r.Path, r.PrevValue, r.PrevIndex)) - default: - return toResponse(a.store.Delete(r.Path, r.Dir, r.Recursive)) - } -} - -func (a *applierV2store) Post(r *RequestV2) Response { - return toResponse(a.store.Create(r.Path, r.Dir, r.Val, true, r.TTLOptions())) -} - -func (a *applierV2store) Put(r *RequestV2) Response { - ttlOptions := r.TTLOptions() - exists, existsSet := pbutil.GetBool(r.PrevExist) - switch { - case existsSet: - if exists { - if r.PrevIndex == 0 && r.PrevValue == "" { - return toResponse(a.store.Update(r.Path, r.Val, ttlOptions)) - } - return toResponse(a.store.CompareAndSwap(r.Path, r.PrevValue, r.PrevIndex, r.Val, ttlOptions)) - } - return toResponse(a.store.Create(r.Path, r.Dir, r.Val, false, ttlOptions)) - case r.PrevIndex > 0 || r.PrevValue != "": - return toResponse(a.store.CompareAndSwap(r.Path, r.PrevValue, r.PrevIndex, r.Val, ttlOptions)) - default: - if storeMemberAttributeRegexp.MatchString(r.Path) { - id := membership.MustParseMemberIDFromKey(path.Dir(r.Path)) - var attr membership.Attributes - if err := json.Unmarshal([]byte(r.Val), &attr); err != nil { - plog.Panicf("unmarshal %s should never fail: %v", r.Val, err) - } - if a.cluster != nil { - a.cluster.UpdateAttributes(id, attr) - } - // return an empty response since there is no consumer. - return Response{} - } - if r.Path == membership.StoreClusterVersionKey() { - if a.cluster != nil { - a.cluster.SetVersion(semver.Must(semver.NewVersion(r.Val)), api.UpdateCapability) - } - // return an empty response since there is no consumer. - return Response{} - } - return toResponse(a.store.Set(r.Path, r.Dir, r.Val, ttlOptions)) - } -} - -func (a *applierV2store) QGet(r *RequestV2) Response { - return toResponse(a.store.Get(r.Path, r.Recursive, r.Sorted)) -} - -func (a *applierV2store) Sync(r *RequestV2) Response { - a.store.DeleteExpiredKeys(time.Unix(0, r.Time)) - return Response{} -} - -// applyV2Request interprets r as a call to store.X and returns a Response interpreted -// from store.Event -func (s *EtcdServer) applyV2Request(r *RequestV2) Response { - defer warnOfExpensiveRequest(time.Now(), r, nil, nil) - - switch r.Method { - case "POST": - return s.applyV2.Post(r) - case "PUT": - return s.applyV2.Put(r) - case "DELETE": - return s.applyV2.Delete(r) - case "QGET": - return s.applyV2.QGet(r) - case "SYNC": - return s.applyV2.Sync(r) - default: - // This should never be reached, but just in case: - return Response{Err: ErrUnknownMethod} - } -} - -func (r *RequestV2) TTLOptions() store.TTLOptionSet { - refresh, _ := pbutil.GetBool(r.Refresh) - ttlOptions := store.TTLOptionSet{Refresh: refresh} - if r.Expiration != 0 { - ttlOptions.ExpireTime = time.Unix(0, r.Expiration) - } - return ttlOptions -} - -func toResponse(ev *store.Event, err error) Response { - return Response{Event: ev, Err: err} -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/auth/auth.go b/vendor/github.com/coreos/etcd/etcdserver/auth/auth.go deleted file mode 100644 index 8991675cc71c..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/auth/auth.go +++ /dev/null @@ -1,648 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package auth implements etcd authentication. -package auth - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "path" - "reflect" - "sort" - "strings" - "time" - - etcderr "github.com/coreos/etcd/error" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/pkg/capnslog" - - "golang.org/x/crypto/bcrypt" -) - -const ( - // StorePermsPrefix is the internal prefix of the storage layer dedicated to storing user data. - StorePermsPrefix = "/2" - - // RootRoleName is the name of the ROOT role, with privileges to manage the cluster. - RootRoleName = "root" - - // GuestRoleName is the name of the role that defines the privileges of an unauthenticated user. - GuestRoleName = "guest" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdserver/auth") -) - -var rootRole = Role{ - Role: RootRoleName, - Permissions: Permissions{ - KV: RWPermission{ - Read: []string{"/*"}, - Write: []string{"/*"}, - }, - }, -} - -var guestRole = Role{ - Role: GuestRoleName, - Permissions: Permissions{ - KV: RWPermission{ - Read: []string{"/*"}, - Write: []string{"/*"}, - }, - }, -} - -type doer interface { - Do(context.Context, etcdserverpb.Request) (etcdserver.Response, error) -} - -type Store interface { - AllUsers() ([]string, error) - GetUser(name string) (User, error) - CreateOrUpdateUser(user User) (out User, created bool, err error) - CreateUser(user User) (User, error) - DeleteUser(name string) error - UpdateUser(user User) (User, error) - AllRoles() ([]string, error) - GetRole(name string) (Role, error) - CreateRole(role Role) error - DeleteRole(name string) error - UpdateRole(role Role) (Role, error) - AuthEnabled() bool - EnableAuth() error - DisableAuth() error - PasswordStore -} - -type PasswordStore interface { - CheckPassword(user User, password string) bool - HashPassword(password string) (string, error) -} - -type store struct { - server doer - timeout time.Duration - ensuredOnce bool - - PasswordStore -} - -type User struct { - User string `json:"user"` - Password string `json:"password,omitempty"` - Roles []string `json:"roles"` - Grant []string `json:"grant,omitempty"` - Revoke []string `json:"revoke,omitempty"` -} - -type Role struct { - Role string `json:"role"` - Permissions Permissions `json:"permissions"` - Grant *Permissions `json:"grant,omitempty"` - Revoke *Permissions `json:"revoke,omitempty"` -} - -type Permissions struct { - KV RWPermission `json:"kv"` -} - -func (p *Permissions) IsEmpty() bool { - return p == nil || (len(p.KV.Read) == 0 && len(p.KV.Write) == 0) -} - -type RWPermission struct { - Read []string `json:"read"` - Write []string `json:"write"` -} - -type Error struct { - Status int - Errmsg string -} - -func (ae Error) Error() string { return ae.Errmsg } -func (ae Error) HTTPStatus() int { return ae.Status } - -func authErr(hs int, s string, v ...interface{}) Error { - return Error{Status: hs, Errmsg: fmt.Sprintf("auth: "+s, v...)} -} - -func NewStore(server doer, timeout time.Duration) Store { - s := &store{ - server: server, - timeout: timeout, - PasswordStore: passwordStore{}, - } - return s -} - -// passwordStore implements PasswordStore using bcrypt to hash user passwords -type passwordStore struct{} - -func (_ passwordStore) CheckPassword(user User, password string) bool { - err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password)) - return err == nil -} - -func (_ passwordStore) HashPassword(password string) (string, error) { - hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) - return string(hash), err -} - -func (s *store) AllUsers() ([]string, error) { - resp, err := s.requestResource("/users/", false, false) - if err != nil { - if e, ok := err.(*etcderr.Error); ok { - if e.ErrorCode == etcderr.EcodeKeyNotFound { - return []string{}, nil - } - } - return nil, err - } - var nodes []string - for _, n := range resp.Event.Node.Nodes { - _, user := path.Split(n.Key) - nodes = append(nodes, user) - } - sort.Strings(nodes) - return nodes, nil -} - -func (s *store) GetUser(name string) (User, error) { return s.getUser(name, false) } - -// CreateOrUpdateUser should be only used for creating the new user or when you are not -// sure if it is a create or update. (When only password is passed in, we are not sure -// if it is a update or create) -func (s *store) CreateOrUpdateUser(user User) (out User, created bool, err error) { - _, err = s.getUser(user.User, true) - if err == nil { - out, err = s.UpdateUser(user) - return out, false, err - } - u, err := s.CreateUser(user) - return u, true, err -} - -func (s *store) CreateUser(user User) (User, error) { - // Attach root role to root user. - if user.User == "root" { - user = attachRootRole(user) - } - u, err := s.createUserInternal(user) - if err == nil { - plog.Noticef("created user %s", user.User) - } - return u, err -} - -func (s *store) createUserInternal(user User) (User, error) { - if user.Password == "" { - return user, authErr(http.StatusBadRequest, "Cannot create user %s with an empty password", user.User) - } - hash, err := s.HashPassword(user.Password) - if err != nil { - return user, err - } - user.Password = hash - - _, err = s.createResource("/users/"+user.User, user) - if err != nil { - if e, ok := err.(*etcderr.Error); ok { - if e.ErrorCode == etcderr.EcodeNodeExist { - return user, authErr(http.StatusConflict, "User %s already exists.", user.User) - } - } - } - return user, err -} - -func (s *store) DeleteUser(name string) error { - if s.AuthEnabled() && name == "root" { - return authErr(http.StatusForbidden, "Cannot delete root user while auth is enabled.") - } - _, err := s.deleteResource("/users/" + name) - if err != nil { - if e, ok := err.(*etcderr.Error); ok { - if e.ErrorCode == etcderr.EcodeKeyNotFound { - return authErr(http.StatusNotFound, "User %s does not exist", name) - } - } - return err - } - plog.Noticef("deleted user %s", name) - return nil -} - -func (s *store) UpdateUser(user User) (User, error) { - old, err := s.getUser(user.User, true) - if err != nil { - if e, ok := err.(*etcderr.Error); ok { - if e.ErrorCode == etcderr.EcodeKeyNotFound { - return user, authErr(http.StatusNotFound, "User %s doesn't exist.", user.User) - } - } - return old, err - } - - newUser, err := old.merge(user, s.PasswordStore) - if err != nil { - return old, err - } - if reflect.DeepEqual(old, newUser) { - return old, authErr(http.StatusBadRequest, "User not updated. Use grant/revoke/password to update the user.") - } - _, err = s.updateResource("/users/"+user.User, newUser) - if err == nil { - plog.Noticef("updated user %s", user.User) - } - return newUser, err -} - -func (s *store) AllRoles() ([]string, error) { - nodes := []string{RootRoleName} - resp, err := s.requestResource("/roles/", false, false) - if err != nil { - if e, ok := err.(*etcderr.Error); ok { - if e.ErrorCode == etcderr.EcodeKeyNotFound { - return nodes, nil - } - } - return nil, err - } - for _, n := range resp.Event.Node.Nodes { - _, role := path.Split(n.Key) - nodes = append(nodes, role) - } - sort.Strings(nodes) - return nodes, nil -} - -func (s *store) GetRole(name string) (Role, error) { return s.getRole(name, false) } - -func (s *store) CreateRole(role Role) error { - if role.Role == RootRoleName { - return authErr(http.StatusForbidden, "Cannot modify role %s: is root role.", role.Role) - } - _, err := s.createResource("/roles/"+role.Role, role) - if err != nil { - if e, ok := err.(*etcderr.Error); ok { - if e.ErrorCode == etcderr.EcodeNodeExist { - return authErr(http.StatusConflict, "Role %s already exists.", role.Role) - } - } - } - if err == nil { - plog.Noticef("created new role %s", role.Role) - } - return err -} - -func (s *store) DeleteRole(name string) error { - if name == RootRoleName { - return authErr(http.StatusForbidden, "Cannot modify role %s: is root role.", name) - } - _, err := s.deleteResource("/roles/" + name) - if err != nil { - if e, ok := err.(*etcderr.Error); ok { - if e.ErrorCode == etcderr.EcodeKeyNotFound { - return authErr(http.StatusNotFound, "Role %s doesn't exist.", name) - } - } - } - if err == nil { - plog.Noticef("deleted role %s", name) - } - return err -} - -func (s *store) UpdateRole(role Role) (Role, error) { - if role.Role == RootRoleName { - return Role{}, authErr(http.StatusForbidden, "Cannot modify role %s: is root role.", role.Role) - } - old, err := s.getRole(role.Role, true) - if err != nil { - if e, ok := err.(*etcderr.Error); ok { - if e.ErrorCode == etcderr.EcodeKeyNotFound { - return role, authErr(http.StatusNotFound, "Role %s doesn't exist.", role.Role) - } - } - return old, err - } - newRole, err := old.merge(role) - if err != nil { - return old, err - } - if reflect.DeepEqual(old, newRole) { - return old, authErr(http.StatusBadRequest, "Role not updated. Use grant/revoke to update the role.") - } - _, err = s.updateResource("/roles/"+role.Role, newRole) - if err == nil { - plog.Noticef("updated role %s", role.Role) - } - return newRole, err -} - -func (s *store) AuthEnabled() bool { - return s.detectAuth() -} - -func (s *store) EnableAuth() error { - if s.AuthEnabled() { - return authErr(http.StatusConflict, "already enabled") - } - - if _, err := s.getUser("root", true); err != nil { - return authErr(http.StatusConflict, "No root user available, please create one") - } - if _, err := s.getRole(GuestRoleName, true); err != nil { - plog.Printf("no guest role access found, creating default") - if err := s.CreateRole(guestRole); err != nil { - plog.Errorf("error creating guest role. aborting auth enable.") - return err - } - } - - if err := s.enableAuth(); err != nil { - plog.Errorf("error enabling auth (%v)", err) - return err - } - - plog.Noticef("auth: enabled auth") - return nil -} - -func (s *store) DisableAuth() error { - if !s.AuthEnabled() { - return authErr(http.StatusConflict, "already disabled") - } - - err := s.disableAuth() - if err == nil { - plog.Noticef("auth: disabled auth") - } else { - plog.Errorf("error disabling auth (%v)", err) - } - return err -} - -// merge applies the properties of the passed-in User to the User on which it -// is called and returns a new User with these modifications applied. Think of -// all Users as immutable sets of data. Merge allows you to perform the set -// operations (desired grants and revokes) atomically -func (ou User) merge(nu User, s PasswordStore) (User, error) { - var out User - if ou.User != nu.User { - return out, authErr(http.StatusConflict, "Merging user data with conflicting usernames: %s %s", ou.User, nu.User) - } - out.User = ou.User - if nu.Password != "" { - hash, err := s.HashPassword(nu.Password) - if err != nil { - return ou, err - } - out.Password = hash - } else { - out.Password = ou.Password - } - currentRoles := types.NewUnsafeSet(ou.Roles...) - for _, g := range nu.Grant { - if currentRoles.Contains(g) { - plog.Noticef("granting duplicate role %s for user %s", g, nu.User) - return User{}, authErr(http.StatusConflict, fmt.Sprintf("Granting duplicate role %s for user %s", g, nu.User)) - } - currentRoles.Add(g) - } - for _, r := range nu.Revoke { - if !currentRoles.Contains(r) { - plog.Noticef("revoking ungranted role %s for user %s", r, nu.User) - return User{}, authErr(http.StatusConflict, fmt.Sprintf("Revoking ungranted role %s for user %s", r, nu.User)) - } - currentRoles.Remove(r) - } - out.Roles = currentRoles.Values() - sort.Strings(out.Roles) - return out, nil -} - -// merge for a role works the same as User above -- atomic Role application to -// each of the substructures. -func (r Role) merge(n Role) (Role, error) { - var out Role - var err error - if r.Role != n.Role { - return out, authErr(http.StatusConflict, "Merging role with conflicting names: %s %s", r.Role, n.Role) - } - out.Role = r.Role - out.Permissions, err = r.Permissions.Grant(n.Grant) - if err != nil { - return out, err - } - out.Permissions, err = out.Permissions.Revoke(n.Revoke) - return out, err -} - -func (r Role) HasKeyAccess(key string, write bool) bool { - if r.Role == RootRoleName { - return true - } - return r.Permissions.KV.HasAccess(key, write) -} - -func (r Role) HasRecursiveAccess(key string, write bool) bool { - if r.Role == RootRoleName { - return true - } - return r.Permissions.KV.HasRecursiveAccess(key, write) -} - -// Grant adds a set of permissions to the permission object on which it is called, -// returning a new permission object. -func (p Permissions) Grant(n *Permissions) (Permissions, error) { - var out Permissions - var err error - if n == nil { - return p, nil - } - out.KV, err = p.KV.Grant(n.KV) - return out, err -} - -// Revoke removes a set of permissions to the permission object on which it is called, -// returning a new permission object. -func (p Permissions) Revoke(n *Permissions) (Permissions, error) { - var out Permissions - var err error - if n == nil { - return p, nil - } - out.KV, err = p.KV.Revoke(n.KV) - return out, err -} - -// Grant adds a set of permissions to the permission object on which it is called, -// returning a new permission object. -func (rw RWPermission) Grant(n RWPermission) (RWPermission, error) { - var out RWPermission - currentRead := types.NewUnsafeSet(rw.Read...) - for _, r := range n.Read { - if currentRead.Contains(r) { - return out, authErr(http.StatusConflict, "Granting duplicate read permission %s", r) - } - currentRead.Add(r) - } - currentWrite := types.NewUnsafeSet(rw.Write...) - for _, w := range n.Write { - if currentWrite.Contains(w) { - return out, authErr(http.StatusConflict, "Granting duplicate write permission %s", w) - } - currentWrite.Add(w) - } - out.Read = currentRead.Values() - out.Write = currentWrite.Values() - sort.Strings(out.Read) - sort.Strings(out.Write) - return out, nil -} - -// Revoke removes a set of permissions to the permission object on which it is called, -// returning a new permission object. -func (rw RWPermission) Revoke(n RWPermission) (RWPermission, error) { - var out RWPermission - currentRead := types.NewUnsafeSet(rw.Read...) - for _, r := range n.Read { - if !currentRead.Contains(r) { - plog.Noticef("revoking ungranted read permission %s", r) - continue - } - currentRead.Remove(r) - } - currentWrite := types.NewUnsafeSet(rw.Write...) - for _, w := range n.Write { - if !currentWrite.Contains(w) { - plog.Noticef("revoking ungranted write permission %s", w) - continue - } - currentWrite.Remove(w) - } - out.Read = currentRead.Values() - out.Write = currentWrite.Values() - sort.Strings(out.Read) - sort.Strings(out.Write) - return out, nil -} - -func (rw RWPermission) HasAccess(key string, write bool) bool { - var list []string - if write { - list = rw.Write - } else { - list = rw.Read - } - for _, pat := range list { - match, err := simpleMatch(pat, key) - if err == nil && match { - return true - } - } - return false -} - -func (rw RWPermission) HasRecursiveAccess(key string, write bool) bool { - list := rw.Read - if write { - list = rw.Write - } - for _, pat := range list { - match, err := prefixMatch(pat, key) - if err == nil && match { - return true - } - } - return false -} - -func simpleMatch(pattern string, key string) (match bool, err error) { - if pattern[len(pattern)-1] == '*' { - return strings.HasPrefix(key, pattern[:len(pattern)-1]), nil - } - return key == pattern, nil -} - -func prefixMatch(pattern string, key string) (match bool, err error) { - if pattern[len(pattern)-1] != '*' { - return false, nil - } - return strings.HasPrefix(key, pattern[:len(pattern)-1]), nil -} - -func attachRootRole(u User) User { - inRoles := false - for _, r := range u.Roles { - if r == RootRoleName { - inRoles = true - break - } - } - if !inRoles { - u.Roles = append(u.Roles, RootRoleName) - } - return u -} - -func (s *store) getUser(name string, quorum bool) (User, error) { - resp, err := s.requestResource("/users/"+name, false, quorum) - if err != nil { - if e, ok := err.(*etcderr.Error); ok { - if e.ErrorCode == etcderr.EcodeKeyNotFound { - return User{}, authErr(http.StatusNotFound, "User %s does not exist.", name) - } - } - return User{}, err - } - var u User - err = json.Unmarshal([]byte(*resp.Event.Node.Value), &u) - if err != nil { - return u, err - } - // Attach root role to root user. - if u.User == "root" { - u = attachRootRole(u) - } - return u, nil -} - -func (s *store) getRole(name string, quorum bool) (Role, error) { - if name == RootRoleName { - return rootRole, nil - } - resp, err := s.requestResource("/roles/"+name, false, quorum) - if err != nil { - if e, ok := err.(*etcderr.Error); ok { - if e.ErrorCode == etcderr.EcodeKeyNotFound { - return Role{}, authErr(http.StatusNotFound, "Role %s does not exist.", name) - } - } - return Role{}, err - } - var r Role - err = json.Unmarshal([]byte(*resp.Event.Node.Value), &r) - return r, err -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/auth/auth_requests.go b/vendor/github.com/coreos/etcd/etcdserver/auth/auth_requests.go deleted file mode 100644 index 2464828e6546..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/auth/auth_requests.go +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth - -import ( - "context" - "encoding/json" - "path" - - etcderr "github.com/coreos/etcd/error" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -func (s *store) ensureAuthDirectories() error { - if s.ensuredOnce { - return nil - } - for _, res := range []string{StorePermsPrefix, StorePermsPrefix + "/users/", StorePermsPrefix + "/roles/"} { - ctx, cancel := context.WithTimeout(context.Background(), s.timeout) - defer cancel() - pe := false - rr := etcdserverpb.Request{ - Method: "PUT", - Path: res, - Dir: true, - PrevExist: &pe, - } - _, err := s.server.Do(ctx, rr) - if err != nil { - if e, ok := err.(*etcderr.Error); ok { - if e.ErrorCode == etcderr.EcodeNodeExist { - continue - } - } - plog.Errorf("failed to create auth directories in the store (%v)", err) - return err - } - } - ctx, cancel := context.WithTimeout(context.Background(), s.timeout) - defer cancel() - pe := false - rr := etcdserverpb.Request{ - Method: "PUT", - Path: StorePermsPrefix + "/enabled", - Val: "false", - PrevExist: &pe, - } - _, err := s.server.Do(ctx, rr) - if err != nil { - if e, ok := err.(*etcderr.Error); ok { - if e.ErrorCode == etcderr.EcodeNodeExist { - s.ensuredOnce = true - return nil - } - } - return err - } - s.ensuredOnce = true - return nil -} - -func (s *store) enableAuth() error { - _, err := s.updateResource("/enabled", true) - return err -} -func (s *store) disableAuth() error { - _, err := s.updateResource("/enabled", false) - return err -} - -func (s *store) detectAuth() bool { - if s.server == nil { - return false - } - value, err := s.requestResource("/enabled", false, false) - if err != nil { - if e, ok := err.(*etcderr.Error); ok { - if e.ErrorCode == etcderr.EcodeKeyNotFound { - return false - } - } - plog.Errorf("failed to detect auth settings (%s)", err) - return false - } - - var u bool - err = json.Unmarshal([]byte(*value.Event.Node.Value), &u) - if err != nil { - plog.Errorf("internal bookkeeping value for enabled isn't valid JSON (%v)", err) - return false - } - return u -} - -func (s *store) requestResource(res string, dir, quorum bool) (etcdserver.Response, error) { - ctx, cancel := context.WithTimeout(context.Background(), s.timeout) - defer cancel() - p := path.Join(StorePermsPrefix, res) - method := "GET" - if quorum { - method = "QGET" - } - rr := etcdserverpb.Request{ - Method: method, - Path: p, - Dir: dir, - } - return s.server.Do(ctx, rr) -} - -func (s *store) updateResource(res string, value interface{}) (etcdserver.Response, error) { - return s.setResource(res, value, true) -} -func (s *store) createResource(res string, value interface{}) (etcdserver.Response, error) { - return s.setResource(res, value, false) -} -func (s *store) setResource(res string, value interface{}, prevexist bool) (etcdserver.Response, error) { - err := s.ensureAuthDirectories() - if err != nil { - return etcdserver.Response{}, err - } - ctx, cancel := context.WithTimeout(context.Background(), s.timeout) - defer cancel() - data, err := json.Marshal(value) - if err != nil { - return etcdserver.Response{}, err - } - p := path.Join(StorePermsPrefix, res) - rr := etcdserverpb.Request{ - Method: "PUT", - Path: p, - Val: string(data), - PrevExist: &prevexist, - } - return s.server.Do(ctx, rr) -} - -func (s *store) deleteResource(res string) (etcdserver.Response, error) { - err := s.ensureAuthDirectories() - if err != nil { - return etcdserver.Response{}, err - } - ctx, cancel := context.WithTimeout(context.Background(), s.timeout) - defer cancel() - pex := true - p := path.Join(StorePermsPrefix, res) - rr := etcdserverpb.Request{ - Method: "DELETE", - Path: p, - PrevExist: &pex, - } - return s.server.Do(ctx, rr) -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/backend.go b/vendor/github.com/coreos/etcd/etcdserver/backend.go deleted file mode 100644 index 647773d474f6..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/backend.go +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "fmt" - "os" - "time" - - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/snap" -) - -func newBackend(cfg ServerConfig) backend.Backend { - bcfg := backend.DefaultBackendConfig() - bcfg.Path = cfg.backendPath() - if cfg.QuotaBackendBytes > 0 && cfg.QuotaBackendBytes != DefaultQuotaBytes { - // permit 10% excess over quota for disarm - bcfg.MmapSize = uint64(cfg.QuotaBackendBytes + cfg.QuotaBackendBytes/10) - } - return backend.New(bcfg) -} - -// openSnapshotBackend renames a snapshot db to the current etcd db and opens it. -func openSnapshotBackend(cfg ServerConfig, ss *snap.Snapshotter, snapshot raftpb.Snapshot) (backend.Backend, error) { - snapPath, err := ss.DBFilePath(snapshot.Metadata.Index) - if err != nil { - return nil, fmt.Errorf("database snapshot file path error: %v", err) - } - if err := os.Rename(snapPath, cfg.backendPath()); err != nil { - return nil, fmt.Errorf("rename snapshot file error: %v", err) - } - return openBackend(cfg), nil -} - -// openBackend returns a backend using the current etcd db. -func openBackend(cfg ServerConfig) backend.Backend { - fn := cfg.backendPath() - beOpened := make(chan backend.Backend) - go func() { - beOpened <- newBackend(cfg) - }() - select { - case be := <-beOpened: - return be - case <-time.After(10 * time.Second): - plog.Warningf("another etcd process is using %q and holds the file lock, or loading backend file is taking >10 seconds", fn) - plog.Warningf("waiting for it to exit before starting...") - } - return <-beOpened -} - -// recoverBackendSnapshot recovers the DB from a snapshot in case etcd crashes -// before updating the backend db after persisting raft snapshot to disk, -// violating the invariant snapshot.Metadata.Index < db.consistentIndex. In this -// case, replace the db with the snapshot db sent by the leader. -func recoverSnapshotBackend(cfg ServerConfig, oldbe backend.Backend, snapshot raftpb.Snapshot) (backend.Backend, error) { - var cIndex consistentIndex - kv := mvcc.New(oldbe, &lease.FakeLessor{}, &cIndex) - defer kv.Close() - if snapshot.Metadata.Index <= kv.ConsistentIndex() { - return oldbe, nil - } - oldbe.Close() - return openSnapshotBackend(cfg, snap.New(cfg.SnapDir()), snapshot) -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/cluster_util.go b/vendor/github.com/coreos/etcd/etcdserver/cluster_util.go deleted file mode 100644 index f44862a46380..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/cluster_util.go +++ /dev/null @@ -1,258 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "sort" - "time" - - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/version" - "github.com/coreos/go-semver/semver" -) - -// isMemberBootstrapped tries to check if the given member has been bootstrapped -// in the given cluster. -func isMemberBootstrapped(cl *membership.RaftCluster, member string, rt http.RoundTripper, timeout time.Duration) bool { - rcl, err := getClusterFromRemotePeers(getRemotePeerURLs(cl, member), timeout, false, rt) - if err != nil { - return false - } - id := cl.MemberByName(member).ID - m := rcl.Member(id) - if m == nil { - return false - } - if len(m.ClientURLs) > 0 { - return true - } - return false -} - -// GetClusterFromRemotePeers takes a set of URLs representing etcd peers, and -// attempts to construct a Cluster by accessing the members endpoint on one of -// these URLs. The first URL to provide a response is used. If no URLs provide -// a response, or a Cluster cannot be successfully created from a received -// response, an error is returned. -// Each request has a 10-second timeout. Because the upper limit of TTL is 5s, -// 10 second is enough for building connection and finishing request. -func GetClusterFromRemotePeers(urls []string, rt http.RoundTripper) (*membership.RaftCluster, error) { - return getClusterFromRemotePeers(urls, 10*time.Second, true, rt) -} - -// If logerr is true, it prints out more error messages. -func getClusterFromRemotePeers(urls []string, timeout time.Duration, logerr bool, rt http.RoundTripper) (*membership.RaftCluster, error) { - cc := &http.Client{ - Transport: rt, - Timeout: timeout, - } - for _, u := range urls { - resp, err := cc.Get(u + "/members") - if err != nil { - if logerr { - plog.Warningf("could not get cluster response from %s: %v", u, err) - } - continue - } - b, err := ioutil.ReadAll(resp.Body) - resp.Body.Close() - if err != nil { - if logerr { - plog.Warningf("could not read the body of cluster response: %v", err) - } - continue - } - var membs []*membership.Member - if err = json.Unmarshal(b, &membs); err != nil { - if logerr { - plog.Warningf("could not unmarshal cluster response: %v", err) - } - continue - } - id, err := types.IDFromString(resp.Header.Get("X-Etcd-Cluster-ID")) - if err != nil { - if logerr { - plog.Warningf("could not parse the cluster ID from cluster res: %v", err) - } - continue - } - - // check the length of membership members - // if the membership members are present then prepare and return raft cluster - // if membership members are not present then the raft cluster formed will be - // an invalid empty cluster hence return failed to get raft cluster member(s) from the given urls error - if len(membs) > 0 { - return membership.NewClusterFromMembers("", id, membs), nil - } - - return nil, fmt.Errorf("failed to get raft cluster member(s) from the given urls.") - } - return nil, fmt.Errorf("could not retrieve cluster information from the given urls") -} - -// getRemotePeerURLs returns peer urls of remote members in the cluster. The -// returned list is sorted in ascending lexicographical order. -func getRemotePeerURLs(cl *membership.RaftCluster, local string) []string { - us := make([]string, 0) - for _, m := range cl.Members() { - if m.Name == local { - continue - } - us = append(us, m.PeerURLs...) - } - sort.Strings(us) - return us -} - -// getVersions returns the versions of the members in the given cluster. -// The key of the returned map is the member's ID. The value of the returned map -// is the semver versions string, including server and cluster. -// If it fails to get the version of a member, the key will be nil. -func getVersions(cl *membership.RaftCluster, local types.ID, rt http.RoundTripper) map[string]*version.Versions { - members := cl.Members() - vers := make(map[string]*version.Versions) - for _, m := range members { - if m.ID == local { - cv := "not_decided" - if cl.Version() != nil { - cv = cl.Version().String() - } - vers[m.ID.String()] = &version.Versions{Server: version.Version, Cluster: cv} - continue - } - ver, err := getVersion(m, rt) - if err != nil { - plog.Warningf("cannot get the version of member %s (%v)", m.ID, err) - vers[m.ID.String()] = nil - } else { - vers[m.ID.String()] = ver - } - } - return vers -} - -// decideClusterVersion decides the cluster version based on the versions map. -// The returned version is the min server version in the map, or nil if the min -// version in unknown. -func decideClusterVersion(vers map[string]*version.Versions) *semver.Version { - var cv *semver.Version - lv := semver.Must(semver.NewVersion(version.Version)) - - for mid, ver := range vers { - if ver == nil { - return nil - } - v, err := semver.NewVersion(ver.Server) - if err != nil { - plog.Errorf("cannot understand the version of member %s (%v)", mid, err) - return nil - } - if lv.LessThan(*v) { - plog.Warningf("the local etcd version %s is not up-to-date", lv.String()) - plog.Warningf("member %s has a higher version %s", mid, ver.Server) - } - if cv == nil { - cv = v - } else if v.LessThan(*cv) { - cv = v - } - } - return cv -} - -// isCompatibleWithCluster return true if the local member has a compatible version with -// the current running cluster. -// The version is considered as compatible when at least one of the other members in the cluster has a -// cluster version in the range of [MinClusterVersion, Version] and no known members has a cluster version -// out of the range. -// We set this rule since when the local member joins, another member might be offline. -func isCompatibleWithCluster(cl *membership.RaftCluster, local types.ID, rt http.RoundTripper) bool { - vers := getVersions(cl, local, rt) - minV := semver.Must(semver.NewVersion(version.MinClusterVersion)) - maxV := semver.Must(semver.NewVersion(version.Version)) - maxV = &semver.Version{ - Major: maxV.Major, - Minor: maxV.Minor, - } - - return isCompatibleWithVers(vers, local, minV, maxV) -} - -func isCompatibleWithVers(vers map[string]*version.Versions, local types.ID, minV, maxV *semver.Version) bool { - var ok bool - for id, v := range vers { - // ignore comparison with local version - if id == local.String() { - continue - } - if v == nil { - continue - } - clusterv, err := semver.NewVersion(v.Cluster) - if err != nil { - plog.Errorf("cannot understand the cluster version of member %s (%v)", id, err) - continue - } - if clusterv.LessThan(*minV) { - plog.Warningf("the running cluster version(%v) is lower than the minimal cluster version(%v) supported", clusterv.String(), minV.String()) - return false - } - if maxV.LessThan(*clusterv) { - plog.Warningf("the running cluster version(%v) is higher than the maximum cluster version(%v) supported", clusterv.String(), maxV.String()) - return false - } - ok = true - } - return ok -} - -// getVersion returns the Versions of the given member via its -// peerURLs. Returns the last error if it fails to get the version. -func getVersion(m *membership.Member, rt http.RoundTripper) (*version.Versions, error) { - cc := &http.Client{ - Transport: rt, - } - var ( - err error - resp *http.Response - ) - - for _, u := range m.PeerURLs { - resp, err = cc.Get(u + "/version") - if err != nil { - plog.Warningf("failed to reach the peerURL(%s) of member %s (%v)", u, m.ID, err) - continue - } - var b []byte - b, err = ioutil.ReadAll(resp.Body) - resp.Body.Close() - if err != nil { - plog.Warningf("failed to read out the response body from the peerURL(%s) of member %s (%v)", u, m.ID, err) - continue - } - var vers version.Versions - if err = json.Unmarshal(b, &vers); err != nil { - plog.Warningf("failed to unmarshal the response body got from the peerURL(%s) of member %s (%v)", u, m.ID, err) - continue - } - return &vers, nil - } - return nil, err -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/config.go b/vendor/github.com/coreos/etcd/etcdserver/config.go deleted file mode 100644 index 295d95299a20..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/config.go +++ /dev/null @@ -1,282 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "context" - "fmt" - "path/filepath" - "sort" - "strings" - "time" - - "github.com/coreos/etcd/pkg/netutil" - "github.com/coreos/etcd/pkg/transport" - "github.com/coreos/etcd/pkg/types" -) - -// ServerConfig holds the configuration of etcd as taken from the command line or discovery. -type ServerConfig struct { - Name string - DiscoveryURL string - DiscoveryProxy string - ClientURLs types.URLs - PeerURLs types.URLs - DataDir string - // DedicatedWALDir config will make the etcd to write the WAL to the WALDir - // rather than the dataDir/member/wal. - DedicatedWALDir string - SnapCount uint64 - MaxSnapFiles uint - MaxWALFiles uint - InitialPeerURLsMap types.URLsMap - InitialClusterToken string - NewCluster bool - ForceNewCluster bool - PeerTLSInfo transport.TLSInfo - - TickMs uint - ElectionTicks int - - // InitialElectionTickAdvance is true, then local member fast-forwards - // election ticks to speed up "initial" leader election trigger. This - // benefits the case of larger election ticks. For instance, cross - // datacenter deployment may require longer election timeout of 10-second. - // If true, local node does not need wait up to 10-second. Instead, - // forwards its election ticks to 8-second, and have only 2-second left - // before leader election. - // - // Major assumptions are that: - // - cluster has no active leader thus advancing ticks enables faster - // leader election, or - // - cluster already has an established leader, and rejoining follower - // is likely to receive heartbeats from the leader after tick advance - // and before election timeout. - // - // However, when network from leader to rejoining follower is congested, - // and the follower does not receive leader heartbeat within left election - // ticks, disruptive election has to happen thus affecting cluster - // availabilities. - // - // Disabling this would slow down initial bootstrap process for cross - // datacenter deployments. Make your own tradeoffs by configuring - // --initial-election-tick-advance at the cost of slow initial bootstrap. - // - // If single-node, it advances ticks regardless. - // - // See https://github.com/coreos/etcd/issues/9333 for more detail. - InitialElectionTickAdvance bool - - BootstrapTimeout time.Duration - - AutoCompactionRetention time.Duration - AutoCompactionMode string - QuotaBackendBytes int64 - MaxTxnOps uint - - // MaxRequestBytes is the maximum request size to send over raft. - MaxRequestBytes uint - - StrictReconfigCheck bool - - // ClientCertAuthEnabled is true when cert has been signed by the client CA. - ClientCertAuthEnabled bool - - AuthToken string - - // InitialCorruptCheck is true to check data corruption on boot - // before serving any peer/client traffic. - InitialCorruptCheck bool - CorruptCheckTime time.Duration - - Debug bool -} - -// VerifyBootstrap sanity-checks the initial config for bootstrap case -// and returns an error for things that should never happen. -func (c *ServerConfig) VerifyBootstrap() error { - if err := c.hasLocalMember(); err != nil { - return err - } - if err := c.advertiseMatchesCluster(); err != nil { - return err - } - if checkDuplicateURL(c.InitialPeerURLsMap) { - return fmt.Errorf("initial cluster %s has duplicate url", c.InitialPeerURLsMap) - } - if c.InitialPeerURLsMap.String() == "" && c.DiscoveryURL == "" { - return fmt.Errorf("initial cluster unset and no discovery URL found") - } - return nil -} - -// VerifyJoinExisting sanity-checks the initial config for join existing cluster -// case and returns an error for things that should never happen. -func (c *ServerConfig) VerifyJoinExisting() error { - // The member has announced its peer urls to the cluster before starting; no need to - // set the configuration again. - if err := c.hasLocalMember(); err != nil { - return err - } - if checkDuplicateURL(c.InitialPeerURLsMap) { - return fmt.Errorf("initial cluster %s has duplicate url", c.InitialPeerURLsMap) - } - if c.DiscoveryURL != "" { - return fmt.Errorf("discovery URL should not be set when joining existing initial cluster") - } - return nil -} - -// hasLocalMember checks that the cluster at least contains the local server. -func (c *ServerConfig) hasLocalMember() error { - if urls := c.InitialPeerURLsMap[c.Name]; urls == nil { - return fmt.Errorf("couldn't find local name %q in the initial cluster configuration", c.Name) - } - return nil -} - -// advertiseMatchesCluster confirms peer URLs match those in the cluster peer list. -func (c *ServerConfig) advertiseMatchesCluster() error { - urls, apurls := c.InitialPeerURLsMap[c.Name], c.PeerURLs.StringSlice() - urls.Sort() - sort.Strings(apurls) - ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second) - defer cancel() - ok, err := netutil.URLStringsEqual(ctx, apurls, urls.StringSlice()) - if ok { - return nil - } - - initMap, apMap := make(map[string]struct{}), make(map[string]struct{}) - for _, url := range c.PeerURLs { - apMap[url.String()] = struct{}{} - } - for _, url := range c.InitialPeerURLsMap[c.Name] { - initMap[url.String()] = struct{}{} - } - - missing := []string{} - for url := range initMap { - if _, ok := apMap[url]; !ok { - missing = append(missing, url) - } - } - if len(missing) > 0 { - for i := range missing { - missing[i] = c.Name + "=" + missing[i] - } - mstr := strings.Join(missing, ",") - apStr := strings.Join(apurls, ",") - return fmt.Errorf("--initial-cluster has %s but missing from --initial-advertise-peer-urls=%s (%v)", mstr, apStr, err) - } - - for url := range apMap { - if _, ok := initMap[url]; !ok { - missing = append(missing, url) - } - } - if len(missing) > 0 { - mstr := strings.Join(missing, ",") - umap := types.URLsMap(map[string]types.URLs{c.Name: c.PeerURLs}) - return fmt.Errorf("--initial-advertise-peer-urls has %s but missing from --initial-cluster=%s", mstr, umap.String()) - } - - // resolved URLs from "--initial-advertise-peer-urls" and "--initial-cluster" did not match or failed - apStr := strings.Join(apurls, ",") - umap := types.URLsMap(map[string]types.URLs{c.Name: c.PeerURLs}) - return fmt.Errorf("failed to resolve %s to match --initial-cluster=%s (%v)", apStr, umap.String(), err) -} - -func (c *ServerConfig) MemberDir() string { return filepath.Join(c.DataDir, "member") } - -func (c *ServerConfig) WALDir() string { - if c.DedicatedWALDir != "" { - return c.DedicatedWALDir - } - return filepath.Join(c.MemberDir(), "wal") -} - -func (c *ServerConfig) SnapDir() string { return filepath.Join(c.MemberDir(), "snap") } - -func (c *ServerConfig) ShouldDiscover() bool { return c.DiscoveryURL != "" } - -// ReqTimeout returns timeout for request to finish. -func (c *ServerConfig) ReqTimeout() time.Duration { - // 5s for queue waiting, computation and disk IO delay - // + 2 * election timeout for possible leader election - return 5*time.Second + 2*time.Duration(c.ElectionTicks*int(c.TickMs))*time.Millisecond -} - -func (c *ServerConfig) electionTimeout() time.Duration { - return time.Duration(c.ElectionTicks*int(c.TickMs)) * time.Millisecond -} - -func (c *ServerConfig) peerDialTimeout() time.Duration { - // 1s for queue wait and election timeout - return time.Second + time.Duration(c.ElectionTicks*int(c.TickMs))*time.Millisecond -} - -func (c *ServerConfig) PrintWithInitial() { c.print(true) } - -func (c *ServerConfig) Print() { c.print(false) } - -func (c *ServerConfig) print(initial bool) { - plog.Infof("name = %s", c.Name) - if c.ForceNewCluster { - plog.Infof("force new cluster") - } - plog.Infof("data dir = %s", c.DataDir) - plog.Infof("member dir = %s", c.MemberDir()) - if c.DedicatedWALDir != "" { - plog.Infof("dedicated WAL dir = %s", c.DedicatedWALDir) - } - plog.Infof("heartbeat = %dms", c.TickMs) - plog.Infof("election = %dms", c.ElectionTicks*int(c.TickMs)) - plog.Infof("snapshot count = %d", c.SnapCount) - if len(c.DiscoveryURL) != 0 { - plog.Infof("discovery URL= %s", c.DiscoveryURL) - if len(c.DiscoveryProxy) != 0 { - plog.Infof("discovery proxy = %s", c.DiscoveryProxy) - } - } - plog.Infof("advertise client URLs = %s", c.ClientURLs) - if initial { - plog.Infof("initial advertise peer URLs = %s", c.PeerURLs) - plog.Infof("initial cluster = %s", c.InitialPeerURLsMap) - } -} - -func checkDuplicateURL(urlsmap types.URLsMap) bool { - um := make(map[string]bool) - for _, urls := range urlsmap { - for _, url := range urls { - u := url.String() - if um[u] { - return true - } - um[u] = true - } - } - return false -} - -func (c *ServerConfig) bootstrapTimeout() time.Duration { - if c.BootstrapTimeout != 0 { - return c.BootstrapTimeout - } - return time.Second -} - -func (c *ServerConfig) backendPath() string { return filepath.Join(c.SnapDir(), "db") } diff --git a/vendor/github.com/coreos/etcd/etcdserver/consistent_index.go b/vendor/github.com/coreos/etcd/etcdserver/consistent_index.go deleted file mode 100644 index d513f6708d33..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/consistent_index.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "sync/atomic" -) - -// consistentIndex represents the offset of an entry in a consistent replica log. -// It implements the mvcc.ConsistentIndexGetter interface. -// It is always set to the offset of current entry before executing the entry, -// so ConsistentWatchableKV could get the consistent index from it. -type consistentIndex uint64 - -func (i *consistentIndex) setConsistentIndex(v uint64) { - atomic.StoreUint64((*uint64)(i), v) -} - -func (i *consistentIndex) ConsistentIndex() uint64 { - return atomic.LoadUint64((*uint64)(i)) -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/corrupt.go b/vendor/github.com/coreos/etcd/etcdserver/corrupt.go deleted file mode 100644 index d998ec590207..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/corrupt.go +++ /dev/null @@ -1,262 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "context" - "fmt" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/pkg/types" -) - -// CheckInitialHashKV compares initial hash values with its peers -// before serving any peer/client traffic. Only mismatch when hashes -// are different at requested revision, with same compact revision. -func (s *EtcdServer) CheckInitialHashKV() error { - if !s.Cfg.InitialCorruptCheck { - return nil - } - - plog.Infof("%s starting initial corruption check with timeout %v...", s.ID(), s.Cfg.ReqTimeout()) - h, rev, crev, err := s.kv.HashByRev(0) - if err != nil { - return fmt.Errorf("%s failed to fetch hash (%v)", s.ID(), err) - } - peers := s.getPeerHashKVs(rev) - mismatch := 0 - for _, p := range peers { - if p.resp != nil { - peerID := types.ID(p.resp.Header.MemberId) - if h != p.resp.Hash { - if crev == p.resp.CompactRevision { - plog.Errorf("%s's hash %d != %s's hash %d (revision %d, peer revision %d, compact revision %d)", s.ID(), h, peerID, p.resp.Hash, rev, p.resp.Header.Revision, crev) - mismatch++ - } else { - plog.Warningf("%s cannot check hash of peer(%s): peer has a different compact revision %d (revision:%d)", s.ID(), peerID, p.resp.CompactRevision, rev) - } - } - continue - } - if p.err != nil { - switch p.err { - case rpctypes.ErrFutureRev: - plog.Warningf("%s cannot check the hash of peer(%q) at revision %d: peer is lagging behind(%q)", s.ID(), p.eps, rev, p.err.Error()) - case rpctypes.ErrCompacted: - plog.Warningf("%s cannot check the hash of peer(%q) at revision %d: local node is lagging behind(%q)", s.ID(), p.eps, rev, p.err.Error()) - } - } - } - if mismatch > 0 { - return fmt.Errorf("%s found data inconsistency with peers", s.ID()) - } - - plog.Infof("%s succeeded on initial corruption checking: no corruption", s.ID()) - return nil -} - -func (s *EtcdServer) monitorKVHash() { - t := s.Cfg.CorruptCheckTime - if t == 0 { - return - } - plog.Infof("enabled corruption checking with %s interval", t) - for { - select { - case <-s.stopping: - return - case <-time.After(t): - } - if !s.isLeader() { - continue - } - if err := s.checkHashKV(); err != nil { - plog.Debugf("check hash kv failed %v", err) - } - } -} - -func (s *EtcdServer) checkHashKV() error { - h, rev, crev, err := s.kv.HashByRev(0) - if err != nil { - plog.Fatalf("failed to hash kv store (%v)", err) - } - peers := s.getPeerHashKVs(rev) - - ctx, cancel := context.WithTimeout(context.Background(), s.Cfg.ReqTimeout()) - err = s.linearizableReadNotify(ctx) - cancel() - if err != nil { - return err - } - - h2, rev2, crev2, err := s.kv.HashByRev(0) - if err != nil { - plog.Warningf("failed to hash kv store (%v)", err) - return err - } - - alarmed := false - mismatch := func(id uint64) { - if alarmed { - return - } - alarmed = true - a := &pb.AlarmRequest{ - MemberID: uint64(id), - Action: pb.AlarmRequest_ACTIVATE, - Alarm: pb.AlarmType_CORRUPT, - } - s.goAttach(func() { - s.raftRequest(s.ctx, pb.InternalRaftRequest{Alarm: a}) - }) - } - - if h2 != h && rev2 == rev && crev == crev2 { - plog.Warningf("mismatched hashes %d and %d for revision %d", h, h2, rev) - mismatch(uint64(s.ID())) - } - - for _, p := range peers { - if p.resp == nil { - continue - } - id := p.resp.Header.MemberId - - // leader expects follower's latest revision less than or equal to leader's - if p.resp.Header.Revision > rev2 { - plog.Warningf( - "revision %d from member %v, expected at most %d", - p.resp.Header.Revision, - types.ID(id), - rev2) - mismatch(id) - } - - // leader expects follower's latest compact revision less than or equal to leader's - if p.resp.CompactRevision > crev2 { - plog.Warningf( - "compact revision %d from member %v, expected at most %d", - p.resp.CompactRevision, - types.ID(id), - crev2, - ) - mismatch(id) - } - - // follower's compact revision is leader's old one, then hashes must match - if p.resp.CompactRevision == crev && p.resp.Hash != h { - plog.Warningf( - "hash %d at revision %d from member %v, expected hash %d", - p.resp.Hash, - rev, - types.ID(id), - h, - ) - mismatch(id) - } - } - return nil -} - -type peerHashKVResp struct { - resp *clientv3.HashKVResponse - err error - eps []string -} - -func (s *EtcdServer) getPeerHashKVs(rev int64) (resps []*peerHashKVResp) { - // TODO: handle the case when "s.cluster.Members" have not - // been populated (e.g. no snapshot to load from disk) - mbs := s.cluster.Members() - pURLs := make([][]string, len(mbs)) - for _, m := range mbs { - if m.ID == s.ID() { - continue - } - pURLs = append(pURLs, m.PeerURLs) - } - - for _, purls := range pURLs { - if len(purls) == 0 { - continue - } - cli, cerr := clientv3.New(clientv3.Config{ - DialTimeout: s.Cfg.ReqTimeout(), - Endpoints: purls, - }) - if cerr != nil { - plog.Warningf("%s failed to create client to peer %q for hash checking (%q)", s.ID(), purls, cerr.Error()) - continue - } - - respsLen := len(resps) - for _, c := range cli.Endpoints() { - ctx, cancel := context.WithTimeout(context.Background(), s.Cfg.ReqTimeout()) - var resp *clientv3.HashKVResponse - resp, cerr = cli.HashKV(ctx, c, rev) - cancel() - if cerr == nil { - resps = append(resps, &peerHashKVResp{resp: resp}) - break - } - plog.Warningf("%s hash-kv error %q on peer %q with revision %d", s.ID(), cerr.Error(), c, rev) - } - cli.Close() - - if respsLen == len(resps) { - resps = append(resps, &peerHashKVResp{err: cerr, eps: purls}) - } - } - return resps -} - -type applierV3Corrupt struct { - applierV3 -} - -func newApplierV3Corrupt(a applierV3) *applierV3Corrupt { return &applierV3Corrupt{a} } - -func (a *applierV3Corrupt) Put(txn mvcc.TxnWrite, p *pb.PutRequest) (*pb.PutResponse, error) { - return nil, ErrCorrupt -} - -func (a *applierV3Corrupt) Range(txn mvcc.TxnRead, p *pb.RangeRequest) (*pb.RangeResponse, error) { - return nil, ErrCorrupt -} - -func (a *applierV3Corrupt) DeleteRange(txn mvcc.TxnWrite, p *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) { - return nil, ErrCorrupt -} - -func (a *applierV3Corrupt) Txn(rt *pb.TxnRequest) (*pb.TxnResponse, error) { - return nil, ErrCorrupt -} - -func (a *applierV3Corrupt) Compaction(compaction *pb.CompactionRequest) (*pb.CompactionResponse, <-chan struct{}, error) { - return nil, nil, ErrCorrupt -} - -func (a *applierV3Corrupt) LeaseGrant(lc *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - return nil, ErrCorrupt -} - -func (a *applierV3Corrupt) LeaseRevoke(lc *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) { - return nil, ErrCorrupt -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/doc.go b/vendor/github.com/coreos/etcd/etcdserver/doc.go deleted file mode 100644 index b195d2d167a6..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package etcdserver defines how etcd servers interact and store their states. -package etcdserver diff --git a/vendor/github.com/coreos/etcd/etcdserver/errors.go b/vendor/github.com/coreos/etcd/etcdserver/errors.go deleted file mode 100644 index fb93c4b2a1dd..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/errors.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "errors" - "fmt" -) - -var ( - ErrUnknownMethod = errors.New("etcdserver: unknown method") - ErrStopped = errors.New("etcdserver: server stopped") - ErrCanceled = errors.New("etcdserver: request cancelled") - ErrTimeout = errors.New("etcdserver: request timed out") - ErrTimeoutDueToLeaderFail = errors.New("etcdserver: request timed out, possibly due to previous leader failure") - ErrTimeoutDueToConnectionLost = errors.New("etcdserver: request timed out, possibly due to connection lost") - ErrTimeoutLeaderTransfer = errors.New("etcdserver: request timed out, leader transfer took too long") - ErrNotEnoughStartedMembers = errors.New("etcdserver: re-configuration failed due to not enough started members") - ErrNoLeader = errors.New("etcdserver: no leader") - ErrNotLeader = errors.New("etcdserver: not leader") - ErrRequestTooLarge = errors.New("etcdserver: request is too large") - ErrNoSpace = errors.New("etcdserver: no space") - ErrTooManyRequests = errors.New("etcdserver: too many requests") - ErrUnhealthy = errors.New("etcdserver: unhealthy cluster") - ErrKeyNotFound = errors.New("etcdserver: key not found") - ErrCorrupt = errors.New("etcdserver: corrupt cluster") -) - -type DiscoveryError struct { - Op string - Err error -} - -func (e DiscoveryError) Error() string { - return fmt.Sprintf("failed to %s discovery cluster (%v)", e.Op, e.Err) -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/etcdserver.pb.go b/vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/etcdserver.pb.go deleted file mode 100644 index 90045a5c9759..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/etcdserver.pb.go +++ /dev/null @@ -1,1035 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: etcdserver.proto - -/* - Package etcdserverpb is a generated protocol buffer package. - - It is generated from these files: - etcdserver.proto - raft_internal.proto - rpc.proto - - It has these top-level messages: - Request - Metadata - RequestHeader - InternalRaftRequest - EmptyResponse - InternalAuthenticateRequest - ResponseHeader - RangeRequest - RangeResponse - PutRequest - PutResponse - DeleteRangeRequest - DeleteRangeResponse - RequestOp - ResponseOp - Compare - TxnRequest - TxnResponse - CompactionRequest - CompactionResponse - HashRequest - HashKVRequest - HashKVResponse - HashResponse - SnapshotRequest - SnapshotResponse - WatchRequest - WatchCreateRequest - WatchCancelRequest - WatchResponse - LeaseGrantRequest - LeaseGrantResponse - LeaseRevokeRequest - LeaseRevokeResponse - LeaseKeepAliveRequest - LeaseKeepAliveResponse - LeaseTimeToLiveRequest - LeaseTimeToLiveResponse - LeaseLeasesRequest - LeaseStatus - LeaseLeasesResponse - Member - MemberAddRequest - MemberAddResponse - MemberRemoveRequest - MemberRemoveResponse - MemberUpdateRequest - MemberUpdateResponse - MemberListRequest - MemberListResponse - DefragmentRequest - DefragmentResponse - MoveLeaderRequest - MoveLeaderResponse - AlarmRequest - AlarmMember - AlarmResponse - StatusRequest - StatusResponse - AuthEnableRequest - AuthDisableRequest - AuthenticateRequest - AuthUserAddRequest - AuthUserGetRequest - AuthUserDeleteRequest - AuthUserChangePasswordRequest - AuthUserGrantRoleRequest - AuthUserRevokeRoleRequest - AuthRoleAddRequest - AuthRoleGetRequest - AuthUserListRequest - AuthRoleListRequest - AuthRoleDeleteRequest - AuthRoleGrantPermissionRequest - AuthRoleRevokePermissionRequest - AuthEnableResponse - AuthDisableResponse - AuthenticateResponse - AuthUserAddResponse - AuthUserGetResponse - AuthUserDeleteResponse - AuthUserChangePasswordResponse - AuthUserGrantRoleResponse - AuthUserRevokeRoleResponse - AuthRoleAddResponse - AuthRoleGetResponse - AuthRoleListResponse - AuthUserListResponse - AuthRoleDeleteResponse - AuthRoleGrantPermissionResponse - AuthRoleRevokePermissionResponse -*/ -package etcdserverpb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type Request struct { - ID uint64 `protobuf:"varint,1,opt,name=ID" json:"ID"` - Method string `protobuf:"bytes,2,opt,name=Method" json:"Method"` - Path string `protobuf:"bytes,3,opt,name=Path" json:"Path"` - Val string `protobuf:"bytes,4,opt,name=Val" json:"Val"` - Dir bool `protobuf:"varint,5,opt,name=Dir" json:"Dir"` - PrevValue string `protobuf:"bytes,6,opt,name=PrevValue" json:"PrevValue"` - PrevIndex uint64 `protobuf:"varint,7,opt,name=PrevIndex" json:"PrevIndex"` - PrevExist *bool `protobuf:"varint,8,opt,name=PrevExist" json:"PrevExist,omitempty"` - Expiration int64 `protobuf:"varint,9,opt,name=Expiration" json:"Expiration"` - Wait bool `protobuf:"varint,10,opt,name=Wait" json:"Wait"` - Since uint64 `protobuf:"varint,11,opt,name=Since" json:"Since"` - Recursive bool `protobuf:"varint,12,opt,name=Recursive" json:"Recursive"` - Sorted bool `protobuf:"varint,13,opt,name=Sorted" json:"Sorted"` - Quorum bool `protobuf:"varint,14,opt,name=Quorum" json:"Quorum"` - Time int64 `protobuf:"varint,15,opt,name=Time" json:"Time"` - Stream bool `protobuf:"varint,16,opt,name=Stream" json:"Stream"` - Refresh *bool `protobuf:"varint,17,opt,name=Refresh" json:"Refresh,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Request) Reset() { *m = Request{} } -func (m *Request) String() string { return proto.CompactTextString(m) } -func (*Request) ProtoMessage() {} -func (*Request) Descriptor() ([]byte, []int) { return fileDescriptorEtcdserver, []int{0} } - -type Metadata struct { - NodeID uint64 `protobuf:"varint,1,opt,name=NodeID" json:"NodeID"` - ClusterID uint64 `protobuf:"varint,2,opt,name=ClusterID" json:"ClusterID"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Metadata) Reset() { *m = Metadata{} } -func (m *Metadata) String() string { return proto.CompactTextString(m) } -func (*Metadata) ProtoMessage() {} -func (*Metadata) Descriptor() ([]byte, []int) { return fileDescriptorEtcdserver, []int{1} } - -func init() { - proto.RegisterType((*Request)(nil), "etcdserverpb.Request") - proto.RegisterType((*Metadata)(nil), "etcdserverpb.Metadata") -} -func (m *Request) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Request) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(m.ID)) - dAtA[i] = 0x12 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(len(m.Method))) - i += copy(dAtA[i:], m.Method) - dAtA[i] = 0x1a - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(len(m.Path))) - i += copy(dAtA[i:], m.Path) - dAtA[i] = 0x22 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(len(m.Val))) - i += copy(dAtA[i:], m.Val) - dAtA[i] = 0x28 - i++ - if m.Dir { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - dAtA[i] = 0x32 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(len(m.PrevValue))) - i += copy(dAtA[i:], m.PrevValue) - dAtA[i] = 0x38 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(m.PrevIndex)) - if m.PrevExist != nil { - dAtA[i] = 0x40 - i++ - if *m.PrevExist { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - dAtA[i] = 0x48 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(m.Expiration)) - dAtA[i] = 0x50 - i++ - if m.Wait { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - dAtA[i] = 0x58 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(m.Since)) - dAtA[i] = 0x60 - i++ - if m.Recursive { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - dAtA[i] = 0x68 - i++ - if m.Sorted { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - dAtA[i] = 0x70 - i++ - if m.Quorum { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - dAtA[i] = 0x78 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(m.Time)) - dAtA[i] = 0x80 - i++ - dAtA[i] = 0x1 - i++ - if m.Stream { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - if m.Refresh != nil { - dAtA[i] = 0x88 - i++ - dAtA[i] = 0x1 - i++ - if *m.Refresh { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *Metadata) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Metadata) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(m.NodeID)) - dAtA[i] = 0x10 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(m.ClusterID)) - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func encodeVarintEtcdserver(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *Request) Size() (n int) { - var l int - _ = l - n += 1 + sovEtcdserver(uint64(m.ID)) - l = len(m.Method) - n += 1 + l + sovEtcdserver(uint64(l)) - l = len(m.Path) - n += 1 + l + sovEtcdserver(uint64(l)) - l = len(m.Val) - n += 1 + l + sovEtcdserver(uint64(l)) - n += 2 - l = len(m.PrevValue) - n += 1 + l + sovEtcdserver(uint64(l)) - n += 1 + sovEtcdserver(uint64(m.PrevIndex)) - if m.PrevExist != nil { - n += 2 - } - n += 1 + sovEtcdserver(uint64(m.Expiration)) - n += 2 - n += 1 + sovEtcdserver(uint64(m.Since)) - n += 2 - n += 2 - n += 2 - n += 1 + sovEtcdserver(uint64(m.Time)) - n += 3 - if m.Refresh != nil { - n += 3 - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *Metadata) Size() (n int) { - var l int - _ = l - n += 1 + sovEtcdserver(uint64(m.NodeID)) - n += 1 + sovEtcdserver(uint64(m.ClusterID)) - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func sovEtcdserver(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozEtcdserver(x uint64) (n int) { - return sovEtcdserver(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Request) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Request: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Request: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Method", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthEtcdserver - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Method = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Path", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthEtcdserver - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Path = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Val", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthEtcdserver - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Val = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Dir", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Dir = bool(v != 0) - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PrevValue", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthEtcdserver - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PrevValue = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 7: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PrevIndex", wireType) - } - m.PrevIndex = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.PrevIndex |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PrevExist", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - b := bool(v != 0) - m.PrevExist = &b - case 9: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Expiration", wireType) - } - m.Expiration = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Expiration |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 10: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Wait", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Wait = bool(v != 0) - case 11: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Since", wireType) - } - m.Since = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Since |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 12: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Recursive", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Recursive = bool(v != 0) - case 13: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Sorted", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Sorted = bool(v != 0) - case 14: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Quorum", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Quorum = bool(v != 0) - case 15: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Time", wireType) - } - m.Time = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Time |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 16: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Stream", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Stream = bool(v != 0) - case 17: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Refresh", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - b := bool(v != 0) - m.Refresh = &b - default: - iNdEx = preIndex - skippy, err := skipEtcdserver(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthEtcdserver - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Metadata) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Metadata: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Metadata: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field NodeID", wireType) - } - m.NodeID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.NodeID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClusterID", wireType) - } - m.ClusterID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ClusterID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipEtcdserver(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthEtcdserver - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipEtcdserver(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthEtcdserver - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipEtcdserver(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthEtcdserver = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowEtcdserver = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("etcdserver.proto", fileDescriptorEtcdserver) } - -var fileDescriptorEtcdserver = []byte{ - // 380 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0xd2, 0xdd, 0x6e, 0xda, 0x30, - 0x14, 0x07, 0x70, 0x0c, 0xe1, 0xcb, 0x63, 0x1b, 0xb3, 0xd0, 0x74, 0x84, 0xa6, 0x2c, 0x42, 0xbb, - 0xc8, 0xd5, 0xf6, 0x0e, 0x2c, 0x5c, 0x44, 0x2a, 0x15, 0x0d, 0x15, 0xbd, 0x76, 0xc9, 0x29, 0x58, - 0x02, 0x4c, 0x1d, 0x07, 0xf1, 0x06, 0x7d, 0x85, 0x3e, 0x12, 0x97, 0x7d, 0x82, 0xaa, 0xa5, 0x2f, - 0x52, 0x39, 0x24, 0xc4, 0xed, 0x5d, 0xf4, 0xfb, 0x9f, 0x1c, 0x1f, 0x7f, 0xd0, 0x2e, 0xea, 0x79, - 0x9c, 0xa0, 0xda, 0xa1, 0xfa, 0xbb, 0x55, 0x52, 0x4b, 0xd6, 0x29, 0x65, 0x7b, 0xdb, 0xef, 0x2d, - 0xe4, 0x42, 0x66, 0xc1, 0x3f, 0xf3, 0x75, 0xaa, 0x19, 0x3c, 0x38, 0xb4, 0x19, 0xe1, 0x7d, 0x8a, - 0x89, 0x66, 0x3d, 0x5a, 0x0d, 0x03, 0x20, 0x1e, 0xf1, 0x9d, 0xa1, 0x73, 0x78, 0xfe, 0x5d, 0x89, - 0xaa, 0x61, 0xc0, 0x7e, 0xd1, 0xc6, 0x18, 0xf5, 0x52, 0xc6, 0x50, 0xf5, 0x88, 0xdf, 0xce, 0x93, - 0xdc, 0x18, 0x50, 0x67, 0xc2, 0xf5, 0x12, 0x6a, 0x56, 0x96, 0x09, 0xfb, 0x49, 0x6b, 0x33, 0xbe, - 0x02, 0xc7, 0x0a, 0x0c, 0x18, 0x0f, 0x84, 0x82, 0xba, 0x47, 0xfc, 0x56, 0xe1, 0x81, 0x50, 0x6c, - 0x40, 0xdb, 0x13, 0x85, 0xbb, 0x19, 0x5f, 0xa5, 0x08, 0x0d, 0xeb, 0xaf, 0x92, 0x8b, 0x9a, 0x70, - 0x13, 0xe3, 0x1e, 0x9a, 0xd6, 0xa0, 0x25, 0x17, 0x35, 0xa3, 0xbd, 0x48, 0x34, 0xb4, 0xce, 0xab, - 0x90, 0xa8, 0x64, 0xf6, 0x87, 0xd2, 0xd1, 0x7e, 0x2b, 0x14, 0xd7, 0x42, 0x6e, 0xa0, 0xed, 0x11, - 0xbf, 0x96, 0x37, 0xb2, 0xdc, 0xec, 0xed, 0x86, 0x0b, 0x0d, 0xd4, 0x1a, 0x35, 0x13, 0xd6, 0xa7, - 0xf5, 0xa9, 0xd8, 0xcc, 0x11, 0xbe, 0x58, 0x33, 0x9c, 0xc8, 0xac, 0x1f, 0xe1, 0x3c, 0x55, 0x89, - 0xd8, 0x21, 0x74, 0xac, 0x5f, 0x4b, 0x36, 0x67, 0x3a, 0x95, 0x4a, 0x63, 0x0c, 0x5f, 0xad, 0x82, - 0xdc, 0x4c, 0x7a, 0x95, 0x4a, 0x95, 0xae, 0xe1, 0x9b, 0x9d, 0x9e, 0xcc, 0x4c, 0x75, 0x2d, 0xd6, - 0x08, 0xdf, 0xad, 0xa9, 0x33, 0xc9, 0xba, 0x6a, 0x85, 0x7c, 0x0d, 0xdd, 0x0f, 0x5d, 0x33, 0x63, - 0xae, 0xb9, 0xe8, 0x3b, 0x85, 0xc9, 0x12, 0x7e, 0x58, 0xa7, 0x52, 0xe0, 0xe0, 0x82, 0xb6, 0xc6, - 0xa8, 0x79, 0xcc, 0x35, 0x37, 0x9d, 0x2e, 0x65, 0x8c, 0x9f, 0x5e, 0x43, 0x6e, 0x66, 0x87, 0xff, - 0x57, 0x69, 0xa2, 0x51, 0x85, 0x41, 0xf6, 0x28, 0xce, 0xb7, 0x70, 0xe6, 0x61, 0xef, 0xf0, 0xea, - 0x56, 0x0e, 0x47, 0x97, 0x3c, 0x1d, 0x5d, 0xf2, 0x72, 0x74, 0xc9, 0xe3, 0x9b, 0x5b, 0x79, 0x0f, - 0x00, 0x00, 0xff, 0xff, 0xee, 0x40, 0xba, 0xd6, 0xa4, 0x02, 0x00, 0x00, -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/gw/rpc.pb.gw.go b/vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/gw/rpc.pb.gw.go deleted file mode 100644 index c50525ba392d..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/gw/rpc.pb.gw.go +++ /dev/null @@ -1,2134 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: etcdserver/etcdserverpb/rpc.proto - -/* -Package etcdserverpb is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package gw - -import ( - "github.com/coreos/etcd/etcdserver/etcdserverpb" - "io" - "net/http" - - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "golang.org/x/net/context" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/status" -) - -var _ codes.Code -var _ io.Reader -var _ status.Status -var _ = runtime.String -var _ = utilities.NewDoubleArray - -func request_KV_Range_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.KVClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.RangeRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Range(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_KV_Put_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.KVClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.PutRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Put(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_KV_DeleteRange_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.KVClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.DeleteRangeRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.DeleteRange(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_KV_Txn_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.KVClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.TxnRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Txn(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_KV_Compact_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.KVClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.CompactionRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Compact(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Watch_Watch_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.WatchClient, req *http.Request, pathParams map[string]string) (etcdserverpb.Watch_WatchClient, runtime.ServerMetadata, error) { - var metadata runtime.ServerMetadata - stream, err := client.Watch(ctx) - if err != nil { - grpclog.Printf("Failed to start streaming: %v", err) - return nil, metadata, err - } - dec := marshaler.NewDecoder(req.Body) - handleSend := func() error { - var protoReq etcdserverpb.WatchRequest - err = dec.Decode(&protoReq) - if err == io.EOF { - return err - } - if err != nil { - grpclog.Printf("Failed to decode request: %v", err) - return err - } - if err = stream.Send(&protoReq); err != nil { - grpclog.Printf("Failed to send request: %v", err) - return err - } - return nil - } - if err := handleSend(); err != nil { - if cerr := stream.CloseSend(); cerr != nil { - grpclog.Printf("Failed to terminate client stream: %v", cerr) - } - if err == io.EOF { - return stream, metadata, nil - } - return nil, metadata, err - } - go func() { - for { - if err := handleSend(); err != nil { - break - } - } - if err := stream.CloseSend(); err != nil { - grpclog.Printf("Failed to terminate client stream: %v", err) - } - }() - header, err := stream.Header() - if err != nil { - grpclog.Printf("Failed to get header from client: %v", err) - return nil, metadata, err - } - metadata.HeaderMD = header - return stream, metadata, nil -} - -func request_Lease_LeaseGrant_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.LeaseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseGrantRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.LeaseGrant(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Lease_LeaseRevoke_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.LeaseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseRevokeRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.LeaseRevoke(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Lease_LeaseKeepAlive_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.LeaseClient, req *http.Request, pathParams map[string]string) (etcdserverpb.Lease_LeaseKeepAliveClient, runtime.ServerMetadata, error) { - var metadata runtime.ServerMetadata - stream, err := client.LeaseKeepAlive(ctx) - if err != nil { - grpclog.Printf("Failed to start streaming: %v", err) - return nil, metadata, err - } - dec := marshaler.NewDecoder(req.Body) - handleSend := func() error { - var protoReq etcdserverpb.LeaseKeepAliveRequest - err = dec.Decode(&protoReq) - if err == io.EOF { - return err - } - if err != nil { - grpclog.Printf("Failed to decode request: %v", err) - return err - } - if err = stream.Send(&protoReq); err != nil { - grpclog.Printf("Failed to send request: %v", err) - return err - } - return nil - } - if err := handleSend(); err != nil { - if cerr := stream.CloseSend(); cerr != nil { - grpclog.Printf("Failed to terminate client stream: %v", cerr) - } - if err == io.EOF { - return stream, metadata, nil - } - return nil, metadata, err - } - go func() { - for { - if err := handleSend(); err != nil { - break - } - } - if err := stream.CloseSend(); err != nil { - grpclog.Printf("Failed to terminate client stream: %v", err) - } - }() - header, err := stream.Header() - if err != nil { - grpclog.Printf("Failed to get header from client: %v", err) - return nil, metadata, err - } - metadata.HeaderMD = header - return stream, metadata, nil -} - -func request_Lease_LeaseTimeToLive_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.LeaseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseTimeToLiveRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.LeaseTimeToLive(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Lease_LeaseLeases_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.LeaseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseLeasesRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.LeaseLeases(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Cluster_MemberAdd_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.ClusterClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MemberAddRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.MemberAdd(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Cluster_MemberRemove_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.ClusterClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MemberRemoveRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.MemberRemove(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Cluster_MemberUpdate_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.ClusterClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MemberUpdateRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.MemberUpdate(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Cluster_MemberList_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.ClusterClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MemberListRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.MemberList(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Maintenance_Alarm_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AlarmRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Alarm(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Maintenance_Status_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.StatusRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Status(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Maintenance_Defragment_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.DefragmentRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Defragment(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Maintenance_Hash_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.HashRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Hash(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Maintenance_HashKV_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.HashKVRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.HashKV(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Maintenance_Snapshot_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (etcdserverpb.Maintenance_SnapshotClient, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.SnapshotRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - stream, err := client.Snapshot(ctx, &protoReq) - if err != nil { - return nil, metadata, err - } - header, err := stream.Header() - if err != nil { - return nil, metadata, err - } - metadata.HeaderMD = header - return stream, metadata, nil - -} - -func request_Maintenance_MoveLeader_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MoveLeaderRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.MoveLeader(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_AuthEnable_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthEnableRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.AuthEnable(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_AuthDisable_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthDisableRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.AuthDisable(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_Authenticate_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthenticateRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Authenticate(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_UserAdd_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserAddRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserAdd(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_UserGet_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserGetRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserGet(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_UserList_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserListRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserList(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_UserDelete_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserDeleteRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserDelete(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_UserChangePassword_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserChangePasswordRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserChangePassword(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_UserGrantRole_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserGrantRoleRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserGrantRole(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_UserRevokeRole_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserRevokeRoleRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserRevokeRole(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_RoleAdd_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleAddRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RoleAdd(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_RoleGet_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleGetRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RoleGet(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_RoleList_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleListRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RoleList(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_RoleDelete_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleDeleteRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RoleDelete(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_RoleGrantPermission_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleGrantPermissionRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RoleGrantPermission(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_RoleRevokePermission_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleRevokePermissionRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RoleRevokePermission(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -// RegisterKVHandlerFromEndpoint is same as RegisterKVHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterKVHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterKVHandler(ctx, mux, conn) -} - -// RegisterKVHandler registers the http handlers for service KV to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterKVHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterKVHandlerClient(ctx, mux, etcdserverpb.NewKVClient(conn)) -} - -// RegisterKVHandler registers the http handlers for service KV to "mux". -// The handlers forward requests to the grpc endpoint over the given implementation of "KVClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "KVClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "KVClient" to call the correct interceptors. -func RegisterKVHandlerClient(ctx context.Context, mux *runtime.ServeMux, client etcdserverpb.KVClient) error { - - mux.Handle("POST", pattern_KV_Range_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_KV_Range_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_Range_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_KV_Put_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_KV_Put_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_Put_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_KV_DeleteRange_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_KV_DeleteRange_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_DeleteRange_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_KV_Txn_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_KV_Txn_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_Txn_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_KV_Compact_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_KV_Compact_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_Compact_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_KV_Range_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "kv", "range"}, "")) - - pattern_KV_Put_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "kv", "put"}, "")) - - pattern_KV_DeleteRange_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "kv", "deleterange"}, "")) - - pattern_KV_Txn_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "kv", "txn"}, "")) - - pattern_KV_Compact_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "kv", "compaction"}, "")) -) - -var ( - forward_KV_Range_0 = runtime.ForwardResponseMessage - - forward_KV_Put_0 = runtime.ForwardResponseMessage - - forward_KV_DeleteRange_0 = runtime.ForwardResponseMessage - - forward_KV_Txn_0 = runtime.ForwardResponseMessage - - forward_KV_Compact_0 = runtime.ForwardResponseMessage -) - -// RegisterWatchHandlerFromEndpoint is same as RegisterWatchHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterWatchHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterWatchHandler(ctx, mux, conn) -} - -// RegisterWatchHandler registers the http handlers for service Watch to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterWatchHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterWatchHandlerClient(ctx, mux, etcdserverpb.NewWatchClient(conn)) -} - -// RegisterWatchHandler registers the http handlers for service Watch to "mux". -// The handlers forward requests to the grpc endpoint over the given implementation of "WatchClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "WatchClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "WatchClient" to call the correct interceptors. -func RegisterWatchHandlerClient(ctx context.Context, mux *runtime.ServeMux, client etcdserverpb.WatchClient) error { - - mux.Handle("POST", pattern_Watch_Watch_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Watch_Watch_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Watch_Watch_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Watch_Watch_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v3beta", "watch"}, "")) -) - -var ( - forward_Watch_Watch_0 = runtime.ForwardResponseStream -) - -// RegisterLeaseHandlerFromEndpoint is same as RegisterLeaseHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterLeaseHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterLeaseHandler(ctx, mux, conn) -} - -// RegisterLeaseHandler registers the http handlers for service Lease to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterLeaseHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterLeaseHandlerClient(ctx, mux, etcdserverpb.NewLeaseClient(conn)) -} - -// RegisterLeaseHandler registers the http handlers for service Lease to "mux". -// The handlers forward requests to the grpc endpoint over the given implementation of "LeaseClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "LeaseClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "LeaseClient" to call the correct interceptors. -func RegisterLeaseHandlerClient(ctx context.Context, mux *runtime.ServeMux, client etcdserverpb.LeaseClient) error { - - mux.Handle("POST", pattern_Lease_LeaseGrant_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lease_LeaseGrant_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseGrant_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseRevoke_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lease_LeaseRevoke_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseRevoke_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseKeepAlive_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lease_LeaseKeepAlive_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseKeepAlive_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseTimeToLive_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lease_LeaseTimeToLive_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseTimeToLive_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseLeases_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lease_LeaseLeases_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseLeases_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Lease_LeaseGrant_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "lease", "grant"}, "")) - - pattern_Lease_LeaseRevoke_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "kv", "lease", "revoke"}, "")) - - pattern_Lease_LeaseKeepAlive_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "lease", "keepalive"}, "")) - - pattern_Lease_LeaseTimeToLive_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "kv", "lease", "timetolive"}, "")) - - pattern_Lease_LeaseLeases_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "kv", "lease", "leases"}, "")) -) - -var ( - forward_Lease_LeaseGrant_0 = runtime.ForwardResponseMessage - - forward_Lease_LeaseRevoke_0 = runtime.ForwardResponseMessage - - forward_Lease_LeaseKeepAlive_0 = runtime.ForwardResponseStream - - forward_Lease_LeaseTimeToLive_0 = runtime.ForwardResponseMessage - - forward_Lease_LeaseLeases_0 = runtime.ForwardResponseMessage -) - -// RegisterClusterHandlerFromEndpoint is same as RegisterClusterHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterClusterHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterClusterHandler(ctx, mux, conn) -} - -// RegisterClusterHandler registers the http handlers for service Cluster to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterClusterHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterClusterHandlerClient(ctx, mux, etcdserverpb.NewClusterClient(conn)) -} - -// RegisterClusterHandler registers the http handlers for service Cluster to "mux". -// The handlers forward requests to the grpc endpoint over the given implementation of "ClusterClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "ClusterClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "ClusterClient" to call the correct interceptors. -func RegisterClusterHandlerClient(ctx context.Context, mux *runtime.ServeMux, client etcdserverpb.ClusterClient) error { - - mux.Handle("POST", pattern_Cluster_MemberAdd_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Cluster_MemberAdd_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Cluster_MemberAdd_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Cluster_MemberRemove_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Cluster_MemberRemove_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Cluster_MemberRemove_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Cluster_MemberUpdate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Cluster_MemberUpdate_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Cluster_MemberUpdate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Cluster_MemberList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Cluster_MemberList_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Cluster_MemberList_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Cluster_MemberAdd_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "cluster", "member", "add"}, "")) - - pattern_Cluster_MemberRemove_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "cluster", "member", "remove"}, "")) - - pattern_Cluster_MemberUpdate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "cluster", "member", "update"}, "")) - - pattern_Cluster_MemberList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "cluster", "member", "list"}, "")) -) - -var ( - forward_Cluster_MemberAdd_0 = runtime.ForwardResponseMessage - - forward_Cluster_MemberRemove_0 = runtime.ForwardResponseMessage - - forward_Cluster_MemberUpdate_0 = runtime.ForwardResponseMessage - - forward_Cluster_MemberList_0 = runtime.ForwardResponseMessage -) - -// RegisterMaintenanceHandlerFromEndpoint is same as RegisterMaintenanceHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterMaintenanceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterMaintenanceHandler(ctx, mux, conn) -} - -// RegisterMaintenanceHandler registers the http handlers for service Maintenance to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterMaintenanceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterMaintenanceHandlerClient(ctx, mux, etcdserverpb.NewMaintenanceClient(conn)) -} - -// RegisterMaintenanceHandler registers the http handlers for service Maintenance to "mux". -// The handlers forward requests to the grpc endpoint over the given implementation of "MaintenanceClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "MaintenanceClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "MaintenanceClient" to call the correct interceptors. -func RegisterMaintenanceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client etcdserverpb.MaintenanceClient) error { - - mux.Handle("POST", pattern_Maintenance_Alarm_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_Alarm_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Alarm_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_Status_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_Status_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Status_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_Defragment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_Defragment_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Defragment_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_Hash_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_Hash_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Hash_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_HashKV_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_HashKV_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_HashKV_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_Snapshot_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_Snapshot_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Snapshot_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_MoveLeader_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_MoveLeader_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_MoveLeader_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Maintenance_Alarm_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "maintenance", "alarm"}, "")) - - pattern_Maintenance_Status_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "maintenance", "status"}, "")) - - pattern_Maintenance_Defragment_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "maintenance", "defragment"}, "")) - - pattern_Maintenance_Hash_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "maintenance", "hash"}, "")) - - pattern_Maintenance_HashKV_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "maintenance", "hash"}, "")) - - pattern_Maintenance_Snapshot_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "maintenance", "snapshot"}, "")) - - pattern_Maintenance_MoveLeader_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "maintenance", "transfer-leadership"}, "")) -) - -var ( - forward_Maintenance_Alarm_0 = runtime.ForwardResponseMessage - - forward_Maintenance_Status_0 = runtime.ForwardResponseMessage - - forward_Maintenance_Defragment_0 = runtime.ForwardResponseMessage - - forward_Maintenance_Hash_0 = runtime.ForwardResponseMessage - - forward_Maintenance_HashKV_0 = runtime.ForwardResponseMessage - - forward_Maintenance_Snapshot_0 = runtime.ForwardResponseStream - - forward_Maintenance_MoveLeader_0 = runtime.ForwardResponseMessage -) - -// RegisterAuthHandlerFromEndpoint is same as RegisterAuthHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterAuthHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterAuthHandler(ctx, mux, conn) -} - -// RegisterAuthHandler registers the http handlers for service Auth to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterAuthHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterAuthHandlerClient(ctx, mux, etcdserverpb.NewAuthClient(conn)) -} - -// RegisterAuthHandler registers the http handlers for service Auth to "mux". -// The handlers forward requests to the grpc endpoint over the given implementation of "AuthClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "AuthClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "AuthClient" to call the correct interceptors. -func RegisterAuthHandlerClient(ctx context.Context, mux *runtime.ServeMux, client etcdserverpb.AuthClient) error { - - mux.Handle("POST", pattern_Auth_AuthEnable_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_AuthEnable_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_AuthEnable_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_AuthDisable_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_AuthDisable_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_AuthDisable_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_Authenticate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_Authenticate_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_Authenticate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserAdd_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserAdd_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserAdd_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserGet_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserGet_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserGet_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserList_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserList_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserDelete_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserDelete_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserDelete_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserChangePassword_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserChangePassword_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserChangePassword_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserGrantRole_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserGrantRole_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserGrantRole_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserRevokeRole_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserRevokeRole_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserRevokeRole_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleAdd_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_RoleAdd_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleAdd_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleGet_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_RoleGet_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleGet_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_RoleList_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleList_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleDelete_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_RoleDelete_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleDelete_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleGrantPermission_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_RoleGrantPermission_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleGrantPermission_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleRevokePermission_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_RoleRevokePermission_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleRevokePermission_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Auth_AuthEnable_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "auth", "enable"}, "")) - - pattern_Auth_AuthDisable_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "auth", "disable"}, "")) - - pattern_Auth_Authenticate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "auth", "authenticate"}, "")) - - pattern_Auth_UserAdd_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "user", "add"}, "")) - - pattern_Auth_UserGet_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "user", "get"}, "")) - - pattern_Auth_UserList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "user", "list"}, "")) - - pattern_Auth_UserDelete_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "user", "delete"}, "")) - - pattern_Auth_UserChangePassword_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "user", "changepw"}, "")) - - pattern_Auth_UserGrantRole_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "user", "grant"}, "")) - - pattern_Auth_UserRevokeRole_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "user", "revoke"}, "")) - - pattern_Auth_RoleAdd_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "role", "add"}, "")) - - pattern_Auth_RoleGet_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "role", "get"}, "")) - - pattern_Auth_RoleList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "role", "list"}, "")) - - pattern_Auth_RoleDelete_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "role", "delete"}, "")) - - pattern_Auth_RoleGrantPermission_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "role", "grant"}, "")) - - pattern_Auth_RoleRevokePermission_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "role", "revoke"}, "")) -) - -var ( - forward_Auth_AuthEnable_0 = runtime.ForwardResponseMessage - - forward_Auth_AuthDisable_0 = runtime.ForwardResponseMessage - - forward_Auth_Authenticate_0 = runtime.ForwardResponseMessage - - forward_Auth_UserAdd_0 = runtime.ForwardResponseMessage - - forward_Auth_UserGet_0 = runtime.ForwardResponseMessage - - forward_Auth_UserList_0 = runtime.ForwardResponseMessage - - forward_Auth_UserDelete_0 = runtime.ForwardResponseMessage - - forward_Auth_UserChangePassword_0 = runtime.ForwardResponseMessage - - forward_Auth_UserGrantRole_0 = runtime.ForwardResponseMessage - - forward_Auth_UserRevokeRole_0 = runtime.ForwardResponseMessage - - forward_Auth_RoleAdd_0 = runtime.ForwardResponseMessage - - forward_Auth_RoleGet_0 = runtime.ForwardResponseMessage - - forward_Auth_RoleList_0 = runtime.ForwardResponseMessage - - forward_Auth_RoleDelete_0 = runtime.ForwardResponseMessage - - forward_Auth_RoleGrantPermission_0 = runtime.ForwardResponseMessage - - forward_Auth_RoleRevokePermission_0 = runtime.ForwardResponseMessage -) diff --git a/vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/raft_internal.pb.go b/vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/raft_internal.pb.go deleted file mode 100644 index 3084c6cbf864..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/raft_internal.pb.go +++ /dev/null @@ -1,2077 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: raft_internal.proto - -package etcdserverpb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -type RequestHeader struct { - ID uint64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` - // username is a username that is associated with an auth token of gRPC connection - Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"` - // auth_revision is a revision number of auth.authStore. It is not related to mvcc - AuthRevision uint64 `protobuf:"varint,3,opt,name=auth_revision,json=authRevision,proto3" json:"auth_revision,omitempty"` -} - -func (m *RequestHeader) Reset() { *m = RequestHeader{} } -func (m *RequestHeader) String() string { return proto.CompactTextString(m) } -func (*RequestHeader) ProtoMessage() {} -func (*RequestHeader) Descriptor() ([]byte, []int) { return fileDescriptorRaftInternal, []int{0} } - -// An InternalRaftRequest is the union of all requests which can be -// sent via raft. -type InternalRaftRequest struct { - Header *RequestHeader `protobuf:"bytes,100,opt,name=header" json:"header,omitempty"` - ID uint64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` - V2 *Request `protobuf:"bytes,2,opt,name=v2" json:"v2,omitempty"` - Range *RangeRequest `protobuf:"bytes,3,opt,name=range" json:"range,omitempty"` - Put *PutRequest `protobuf:"bytes,4,opt,name=put" json:"put,omitempty"` - DeleteRange *DeleteRangeRequest `protobuf:"bytes,5,opt,name=delete_range,json=deleteRange" json:"delete_range,omitempty"` - Txn *TxnRequest `protobuf:"bytes,6,opt,name=txn" json:"txn,omitempty"` - Compaction *CompactionRequest `protobuf:"bytes,7,opt,name=compaction" json:"compaction,omitempty"` - LeaseGrant *LeaseGrantRequest `protobuf:"bytes,8,opt,name=lease_grant,json=leaseGrant" json:"lease_grant,omitempty"` - LeaseRevoke *LeaseRevokeRequest `protobuf:"bytes,9,opt,name=lease_revoke,json=leaseRevoke" json:"lease_revoke,omitempty"` - Alarm *AlarmRequest `protobuf:"bytes,10,opt,name=alarm" json:"alarm,omitempty"` - AuthEnable *AuthEnableRequest `protobuf:"bytes,1000,opt,name=auth_enable,json=authEnable" json:"auth_enable,omitempty"` - AuthDisable *AuthDisableRequest `protobuf:"bytes,1011,opt,name=auth_disable,json=authDisable" json:"auth_disable,omitempty"` - Authenticate *InternalAuthenticateRequest `protobuf:"bytes,1012,opt,name=authenticate" json:"authenticate,omitempty"` - AuthUserAdd *AuthUserAddRequest `protobuf:"bytes,1100,opt,name=auth_user_add,json=authUserAdd" json:"auth_user_add,omitempty"` - AuthUserDelete *AuthUserDeleteRequest `protobuf:"bytes,1101,opt,name=auth_user_delete,json=authUserDelete" json:"auth_user_delete,omitempty"` - AuthUserGet *AuthUserGetRequest `protobuf:"bytes,1102,opt,name=auth_user_get,json=authUserGet" json:"auth_user_get,omitempty"` - AuthUserChangePassword *AuthUserChangePasswordRequest `protobuf:"bytes,1103,opt,name=auth_user_change_password,json=authUserChangePassword" json:"auth_user_change_password,omitempty"` - AuthUserGrantRole *AuthUserGrantRoleRequest `protobuf:"bytes,1104,opt,name=auth_user_grant_role,json=authUserGrantRole" json:"auth_user_grant_role,omitempty"` - AuthUserRevokeRole *AuthUserRevokeRoleRequest `protobuf:"bytes,1105,opt,name=auth_user_revoke_role,json=authUserRevokeRole" json:"auth_user_revoke_role,omitempty"` - AuthUserList *AuthUserListRequest `protobuf:"bytes,1106,opt,name=auth_user_list,json=authUserList" json:"auth_user_list,omitempty"` - AuthRoleList *AuthRoleListRequest `protobuf:"bytes,1107,opt,name=auth_role_list,json=authRoleList" json:"auth_role_list,omitempty"` - AuthRoleAdd *AuthRoleAddRequest `protobuf:"bytes,1200,opt,name=auth_role_add,json=authRoleAdd" json:"auth_role_add,omitempty"` - AuthRoleDelete *AuthRoleDeleteRequest `protobuf:"bytes,1201,opt,name=auth_role_delete,json=authRoleDelete" json:"auth_role_delete,omitempty"` - AuthRoleGet *AuthRoleGetRequest `protobuf:"bytes,1202,opt,name=auth_role_get,json=authRoleGet" json:"auth_role_get,omitempty"` - AuthRoleGrantPermission *AuthRoleGrantPermissionRequest `protobuf:"bytes,1203,opt,name=auth_role_grant_permission,json=authRoleGrantPermission" json:"auth_role_grant_permission,omitempty"` - AuthRoleRevokePermission *AuthRoleRevokePermissionRequest `protobuf:"bytes,1204,opt,name=auth_role_revoke_permission,json=authRoleRevokePermission" json:"auth_role_revoke_permission,omitempty"` -} - -func (m *InternalRaftRequest) Reset() { *m = InternalRaftRequest{} } -func (m *InternalRaftRequest) String() string { return proto.CompactTextString(m) } -func (*InternalRaftRequest) ProtoMessage() {} -func (*InternalRaftRequest) Descriptor() ([]byte, []int) { return fileDescriptorRaftInternal, []int{1} } - -type EmptyResponse struct { -} - -func (m *EmptyResponse) Reset() { *m = EmptyResponse{} } -func (m *EmptyResponse) String() string { return proto.CompactTextString(m) } -func (*EmptyResponse) ProtoMessage() {} -func (*EmptyResponse) Descriptor() ([]byte, []int) { return fileDescriptorRaftInternal, []int{2} } - -// What is the difference between AuthenticateRequest (defined in rpc.proto) and InternalAuthenticateRequest? -// InternalAuthenticateRequest has a member that is filled by etcdserver and shouldn't be user-facing. -// For avoiding misusage the field, we have an internal version of AuthenticateRequest. -type InternalAuthenticateRequest struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` - // simple_token is generated in API layer (etcdserver/v3_server.go) - SimpleToken string `protobuf:"bytes,3,opt,name=simple_token,json=simpleToken,proto3" json:"simple_token,omitempty"` -} - -func (m *InternalAuthenticateRequest) Reset() { *m = InternalAuthenticateRequest{} } -func (m *InternalAuthenticateRequest) String() string { return proto.CompactTextString(m) } -func (*InternalAuthenticateRequest) ProtoMessage() {} -func (*InternalAuthenticateRequest) Descriptor() ([]byte, []int) { - return fileDescriptorRaftInternal, []int{3} -} - -func init() { - proto.RegisterType((*RequestHeader)(nil), "etcdserverpb.RequestHeader") - proto.RegisterType((*InternalRaftRequest)(nil), "etcdserverpb.InternalRaftRequest") - proto.RegisterType((*EmptyResponse)(nil), "etcdserverpb.EmptyResponse") - proto.RegisterType((*InternalAuthenticateRequest)(nil), "etcdserverpb.InternalAuthenticateRequest") -} -func (m *RequestHeader) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *RequestHeader) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.ID)) - } - if len(m.Username) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(len(m.Username))) - i += copy(dAtA[i:], m.Username) - } - if m.AuthRevision != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthRevision)) - } - return i, nil -} - -func (m *InternalRaftRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *InternalRaftRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.ID)) - } - if m.V2 != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.V2.Size())) - n1, err := m.V2.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - } - if m.Range != nil { - dAtA[i] = 0x1a - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.Range.Size())) - n2, err := m.Range.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - } - if m.Put != nil { - dAtA[i] = 0x22 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.Put.Size())) - n3, err := m.Put.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n3 - } - if m.DeleteRange != nil { - dAtA[i] = 0x2a - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.DeleteRange.Size())) - n4, err := m.DeleteRange.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n4 - } - if m.Txn != nil { - dAtA[i] = 0x32 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.Txn.Size())) - n5, err := m.Txn.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n5 - } - if m.Compaction != nil { - dAtA[i] = 0x3a - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.Compaction.Size())) - n6, err := m.Compaction.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n6 - } - if m.LeaseGrant != nil { - dAtA[i] = 0x42 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.LeaseGrant.Size())) - n7, err := m.LeaseGrant.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n7 - } - if m.LeaseRevoke != nil { - dAtA[i] = 0x4a - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.LeaseRevoke.Size())) - n8, err := m.LeaseRevoke.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n8 - } - if m.Alarm != nil { - dAtA[i] = 0x52 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.Alarm.Size())) - n9, err := m.Alarm.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n9 - } - if m.Header != nil { - dAtA[i] = 0xa2 - i++ - dAtA[i] = 0x6 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.Header.Size())) - n10, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n10 - } - if m.AuthEnable != nil { - dAtA[i] = 0xc2 - i++ - dAtA[i] = 0x3e - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthEnable.Size())) - n11, err := m.AuthEnable.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n11 - } - if m.AuthDisable != nil { - dAtA[i] = 0x9a - i++ - dAtA[i] = 0x3f - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthDisable.Size())) - n12, err := m.AuthDisable.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n12 - } - if m.Authenticate != nil { - dAtA[i] = 0xa2 - i++ - dAtA[i] = 0x3f - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.Authenticate.Size())) - n13, err := m.Authenticate.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n13 - } - if m.AuthUserAdd != nil { - dAtA[i] = 0xe2 - i++ - dAtA[i] = 0x44 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthUserAdd.Size())) - n14, err := m.AuthUserAdd.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n14 - } - if m.AuthUserDelete != nil { - dAtA[i] = 0xea - i++ - dAtA[i] = 0x44 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthUserDelete.Size())) - n15, err := m.AuthUserDelete.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n15 - } - if m.AuthUserGet != nil { - dAtA[i] = 0xf2 - i++ - dAtA[i] = 0x44 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthUserGet.Size())) - n16, err := m.AuthUserGet.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n16 - } - if m.AuthUserChangePassword != nil { - dAtA[i] = 0xfa - i++ - dAtA[i] = 0x44 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthUserChangePassword.Size())) - n17, err := m.AuthUserChangePassword.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n17 - } - if m.AuthUserGrantRole != nil { - dAtA[i] = 0x82 - i++ - dAtA[i] = 0x45 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthUserGrantRole.Size())) - n18, err := m.AuthUserGrantRole.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n18 - } - if m.AuthUserRevokeRole != nil { - dAtA[i] = 0x8a - i++ - dAtA[i] = 0x45 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthUserRevokeRole.Size())) - n19, err := m.AuthUserRevokeRole.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n19 - } - if m.AuthUserList != nil { - dAtA[i] = 0x92 - i++ - dAtA[i] = 0x45 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthUserList.Size())) - n20, err := m.AuthUserList.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n20 - } - if m.AuthRoleList != nil { - dAtA[i] = 0x9a - i++ - dAtA[i] = 0x45 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthRoleList.Size())) - n21, err := m.AuthRoleList.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n21 - } - if m.AuthRoleAdd != nil { - dAtA[i] = 0x82 - i++ - dAtA[i] = 0x4b - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthRoleAdd.Size())) - n22, err := m.AuthRoleAdd.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n22 - } - if m.AuthRoleDelete != nil { - dAtA[i] = 0x8a - i++ - dAtA[i] = 0x4b - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthRoleDelete.Size())) - n23, err := m.AuthRoleDelete.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n23 - } - if m.AuthRoleGet != nil { - dAtA[i] = 0x92 - i++ - dAtA[i] = 0x4b - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthRoleGet.Size())) - n24, err := m.AuthRoleGet.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n24 - } - if m.AuthRoleGrantPermission != nil { - dAtA[i] = 0x9a - i++ - dAtA[i] = 0x4b - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthRoleGrantPermission.Size())) - n25, err := m.AuthRoleGrantPermission.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n25 - } - if m.AuthRoleRevokePermission != nil { - dAtA[i] = 0xa2 - i++ - dAtA[i] = 0x4b - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthRoleRevokePermission.Size())) - n26, err := m.AuthRoleRevokePermission.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n26 - } - return i, nil -} - -func (m *EmptyResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *EmptyResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *InternalAuthenticateRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *InternalAuthenticateRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.Password) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(len(m.Password))) - i += copy(dAtA[i:], m.Password) - } - if len(m.SimpleToken) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(len(m.SimpleToken))) - i += copy(dAtA[i:], m.SimpleToken) - } - return i, nil -} - -func encodeVarintRaftInternal(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *RequestHeader) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovRaftInternal(uint64(m.ID)) - } - l = len(m.Username) - if l > 0 { - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.AuthRevision != 0 { - n += 1 + sovRaftInternal(uint64(m.AuthRevision)) - } - return n -} - -func (m *InternalRaftRequest) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovRaftInternal(uint64(m.ID)) - } - if m.V2 != nil { - l = m.V2.Size() - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.Range != nil { - l = m.Range.Size() - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.Put != nil { - l = m.Put.Size() - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.DeleteRange != nil { - l = m.DeleteRange.Size() - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.Txn != nil { - l = m.Txn.Size() - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.Compaction != nil { - l = m.Compaction.Size() - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.LeaseGrant != nil { - l = m.LeaseGrant.Size() - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.LeaseRevoke != nil { - l = m.LeaseRevoke.Size() - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.Alarm != nil { - l = m.Alarm.Size() - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.Header != nil { - l = m.Header.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthEnable != nil { - l = m.AuthEnable.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthDisable != nil { - l = m.AuthDisable.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.Authenticate != nil { - l = m.Authenticate.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthUserAdd != nil { - l = m.AuthUserAdd.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthUserDelete != nil { - l = m.AuthUserDelete.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthUserGet != nil { - l = m.AuthUserGet.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthUserChangePassword != nil { - l = m.AuthUserChangePassword.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthUserGrantRole != nil { - l = m.AuthUserGrantRole.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthUserRevokeRole != nil { - l = m.AuthUserRevokeRole.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthUserList != nil { - l = m.AuthUserList.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthRoleList != nil { - l = m.AuthRoleList.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthRoleAdd != nil { - l = m.AuthRoleAdd.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthRoleDelete != nil { - l = m.AuthRoleDelete.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthRoleGet != nil { - l = m.AuthRoleGet.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthRoleGrantPermission != nil { - l = m.AuthRoleGrantPermission.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthRoleRevokePermission != nil { - l = m.AuthRoleRevokePermission.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - return n -} - -func (m *EmptyResponse) Size() (n int) { - var l int - _ = l - return n -} - -func (m *InternalAuthenticateRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRaftInternal(uint64(l)) - } - l = len(m.Password) - if l > 0 { - n += 1 + l + sovRaftInternal(uint64(l)) - } - l = len(m.SimpleToken) - if l > 0 { - n += 1 + l + sovRaftInternal(uint64(l)) - } - return n -} - -func sovRaftInternal(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozRaftInternal(x uint64) (n int) { - return sovRaftInternal(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *RequestHeader) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: RequestHeader: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: RequestHeader: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Username", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Username = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthRevision", wireType) - } - m.AuthRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.AuthRevision |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRaftInternal(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaftInternal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *InternalRaftRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: InternalRaftRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: InternalRaftRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field V2", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.V2 == nil { - m.V2 = &Request{} - } - if err := m.V2.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Range", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Range == nil { - m.Range = &RangeRequest{} - } - if err := m.Range.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Put", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Put == nil { - m.Put = &PutRequest{} - } - if err := m.Put.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field DeleteRange", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.DeleteRange == nil { - m.DeleteRange = &DeleteRangeRequest{} - } - if err := m.DeleteRange.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Txn", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Txn == nil { - m.Txn = &TxnRequest{} - } - if err := m.Txn.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Compaction", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Compaction == nil { - m.Compaction = &CompactionRequest{} - } - if err := m.Compaction.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 8: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field LeaseGrant", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.LeaseGrant == nil { - m.LeaseGrant = &LeaseGrantRequest{} - } - if err := m.LeaseGrant.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 9: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field LeaseRevoke", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.LeaseRevoke == nil { - m.LeaseRevoke = &LeaseRevokeRequest{} - } - if err := m.LeaseRevoke.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 10: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Alarm", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Alarm == nil { - m.Alarm = &AlarmRequest{} - } - if err := m.Alarm.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 100: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &RequestHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1000: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthEnable", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthEnable == nil { - m.AuthEnable = &AuthEnableRequest{} - } - if err := m.AuthEnable.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1011: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthDisable", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthDisable == nil { - m.AuthDisable = &AuthDisableRequest{} - } - if err := m.AuthDisable.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1012: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Authenticate", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Authenticate == nil { - m.Authenticate = &InternalAuthenticateRequest{} - } - if err := m.Authenticate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1100: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthUserAdd", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthUserAdd == nil { - m.AuthUserAdd = &AuthUserAddRequest{} - } - if err := m.AuthUserAdd.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1101: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthUserDelete", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthUserDelete == nil { - m.AuthUserDelete = &AuthUserDeleteRequest{} - } - if err := m.AuthUserDelete.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1102: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthUserGet", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthUserGet == nil { - m.AuthUserGet = &AuthUserGetRequest{} - } - if err := m.AuthUserGet.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1103: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthUserChangePassword", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthUserChangePassword == nil { - m.AuthUserChangePassword = &AuthUserChangePasswordRequest{} - } - if err := m.AuthUserChangePassword.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1104: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthUserGrantRole", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthUserGrantRole == nil { - m.AuthUserGrantRole = &AuthUserGrantRoleRequest{} - } - if err := m.AuthUserGrantRole.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1105: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthUserRevokeRole", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthUserRevokeRole == nil { - m.AuthUserRevokeRole = &AuthUserRevokeRoleRequest{} - } - if err := m.AuthUserRevokeRole.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1106: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthUserList", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthUserList == nil { - m.AuthUserList = &AuthUserListRequest{} - } - if err := m.AuthUserList.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1107: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthRoleList", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthRoleList == nil { - m.AuthRoleList = &AuthRoleListRequest{} - } - if err := m.AuthRoleList.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1200: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthRoleAdd", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthRoleAdd == nil { - m.AuthRoleAdd = &AuthRoleAddRequest{} - } - if err := m.AuthRoleAdd.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1201: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthRoleDelete", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthRoleDelete == nil { - m.AuthRoleDelete = &AuthRoleDeleteRequest{} - } - if err := m.AuthRoleDelete.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1202: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthRoleGet", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthRoleGet == nil { - m.AuthRoleGet = &AuthRoleGetRequest{} - } - if err := m.AuthRoleGet.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1203: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthRoleGrantPermission", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthRoleGrantPermission == nil { - m.AuthRoleGrantPermission = &AuthRoleGrantPermissionRequest{} - } - if err := m.AuthRoleGrantPermission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1204: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthRoleRevokePermission", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthRoleRevokePermission == nil { - m.AuthRoleRevokePermission = &AuthRoleRevokePermissionRequest{} - } - if err := m.AuthRoleRevokePermission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRaftInternal(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaftInternal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *EmptyResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: EmptyResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: EmptyResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRaftInternal(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaftInternal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *InternalAuthenticateRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: InternalAuthenticateRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: InternalAuthenticateRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Password", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Password = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SimpleToken", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SimpleToken = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRaftInternal(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaftInternal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipRaftInternal(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthRaftInternal - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipRaftInternal(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthRaftInternal = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowRaftInternal = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("raft_internal.proto", fileDescriptorRaftInternal) } - -var fileDescriptorRaftInternal = []byte{ - // 837 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x96, 0xdd, 0x52, 0xd3, 0x40, - 0x14, 0xc7, 0x69, 0xf9, 0xec, 0xb6, 0x54, 0x5c, 0x40, 0xd7, 0x32, 0x53, 0xa1, 0x8c, 0x8a, 0x5f, - 0xe8, 0x94, 0x07, 0xd0, 0x4a, 0x19, 0x60, 0x86, 0x61, 0x98, 0x0c, 0xce, 0x38, 0xe3, 0x45, 0x5c, - 0x9a, 0x43, 0x1b, 0x49, 0x93, 0xb8, 0xd9, 0x56, 0x7c, 0x13, 0x1f, 0xc3, 0xaf, 0x87, 0xe0, 0xc2, - 0x0f, 0xd4, 0x17, 0x50, 0xbc, 0xf1, 0xca, 0x1b, 0x7d, 0x00, 0x67, 0x3f, 0x92, 0x34, 0x6d, 0xca, - 0x5d, 0x72, 0xce, 0xff, 0xfc, 0xce, 0xd9, 0xec, 0x7f, 0xbb, 0x45, 0xb3, 0x8c, 0x1e, 0x72, 0xd3, - 0x76, 0x39, 0x30, 0x97, 0x3a, 0xab, 0x3e, 0xf3, 0xb8, 0x87, 0x0b, 0xc0, 0x1b, 0x56, 0x00, 0xac, - 0x0b, 0xcc, 0x3f, 0x28, 0xcd, 0x35, 0xbd, 0xa6, 0x27, 0x13, 0xf7, 0xc4, 0x93, 0xd2, 0x94, 0x66, - 0x62, 0x8d, 0x8e, 0xe4, 0x98, 0xdf, 0x50, 0x8f, 0x95, 0x67, 0x68, 0xda, 0x80, 0x17, 0x1d, 0x08, - 0xf8, 0x16, 0x50, 0x0b, 0x18, 0x2e, 0xa2, 0xec, 0x76, 0x9d, 0x64, 0x16, 0x33, 0x2b, 0x63, 0x46, - 0x76, 0xbb, 0x8e, 0x4b, 0x68, 0xaa, 0x13, 0x88, 0x96, 0x6d, 0x20, 0xd9, 0xc5, 0xcc, 0x4a, 0xce, - 0x88, 0xde, 0xf1, 0x32, 0x9a, 0xa6, 0x1d, 0xde, 0x32, 0x19, 0x74, 0xed, 0xc0, 0xf6, 0x5c, 0x32, - 0x2a, 0xcb, 0x0a, 0x22, 0x68, 0xe8, 0x58, 0xe5, 0x4f, 0x11, 0xcd, 0x6e, 0xeb, 0xa9, 0x0d, 0x7a, - 0xc8, 0x75, 0xbb, 0x81, 0x46, 0xd7, 0x50, 0xb6, 0x5b, 0x95, 0x2d, 0xf2, 0xd5, 0xf9, 0xd5, 0xde, - 0x75, 0xad, 0xea, 0x12, 0x23, 0xdb, 0xad, 0xe2, 0xfb, 0x68, 0x9c, 0x51, 0xb7, 0x09, 0xb2, 0x57, - 0xbe, 0x5a, 0xea, 0x53, 0x8a, 0x54, 0x28, 0x57, 0x42, 0x7c, 0x0b, 0x8d, 0xfa, 0x1d, 0x4e, 0xc6, - 0xa4, 0x9e, 0x24, 0xf5, 0x7b, 0x9d, 0x70, 0x1e, 0x43, 0x88, 0xf0, 0x3a, 0x2a, 0x58, 0xe0, 0x00, - 0x07, 0x53, 0x35, 0x19, 0x97, 0x45, 0x8b, 0xc9, 0xa2, 0xba, 0x54, 0x24, 0x5a, 0xe5, 0xad, 0x38, - 0x26, 0x1a, 0xf2, 0x63, 0x97, 0x4c, 0xa4, 0x35, 0xdc, 0x3f, 0x76, 0xa3, 0x86, 0xfc, 0xd8, 0xc5, - 0x0f, 0x10, 0x6a, 0x78, 0x6d, 0x9f, 0x36, 0xb8, 0xf8, 0x7e, 0x93, 0xb2, 0xe4, 0x6a, 0xb2, 0x64, - 0x3d, 0xca, 0x87, 0x95, 0x3d, 0x25, 0xf8, 0x21, 0xca, 0x3b, 0x40, 0x03, 0x30, 0x9b, 0x8c, 0xba, - 0x9c, 0x4c, 0xa5, 0x11, 0x76, 0x84, 0x60, 0x53, 0xe4, 0x23, 0x82, 0x13, 0x85, 0xc4, 0x9a, 0x15, - 0x81, 0x41, 0xd7, 0x3b, 0x02, 0x92, 0x4b, 0x5b, 0xb3, 0x44, 0x18, 0x52, 0x10, 0xad, 0xd9, 0x89, - 0x63, 0x62, 0x5b, 0xa8, 0x43, 0x59, 0x9b, 0xa0, 0xb4, 0x6d, 0xa9, 0x89, 0x54, 0xb4, 0x2d, 0x52, - 0x88, 0xd7, 0xd0, 0x44, 0x4b, 0x5a, 0x8e, 0x58, 0xb2, 0x64, 0x21, 0x75, 0xcf, 0x95, 0x2b, 0x0d, - 0x2d, 0xc5, 0x35, 0x94, 0x97, 0x8e, 0x03, 0x97, 0x1e, 0x38, 0x40, 0x7e, 0xa7, 0x7e, 0xb0, 0x5a, - 0x87, 0xb7, 0x36, 0xa4, 0x20, 0x5a, 0x2e, 0x8d, 0x42, 0xb8, 0x8e, 0xa4, 0x3f, 0x4d, 0xcb, 0x0e, - 0x24, 0xe3, 0xef, 0x64, 0xda, 0x7a, 0x05, 0xa3, 0xae, 0x14, 0xd1, 0x7a, 0x69, 0x1c, 0xc3, 0xbb, - 0x8a, 0x02, 0x2e, 0xb7, 0x1b, 0x94, 0x03, 0xf9, 0xa7, 0x28, 0x37, 0x93, 0x94, 0xd0, 0xf7, 0xb5, - 0x1e, 0x69, 0x88, 0x4b, 0xd4, 0xe3, 0x0d, 0x7d, 0x94, 0xc4, 0xd9, 0x32, 0xa9, 0x65, 0x91, 0x8f, - 0x53, 0xc3, 0xc6, 0x7a, 0x1c, 0x00, 0xab, 0x59, 0x56, 0x62, 0x2c, 0x1d, 0xc3, 0xbb, 0x68, 0x26, - 0xc6, 0x28, 0x4f, 0x92, 0x4f, 0x8a, 0xb4, 0x9c, 0x4e, 0xd2, 0x66, 0xd6, 0xb0, 0x22, 0x4d, 0x84, - 0x93, 0x63, 0x35, 0x81, 0x93, 0xcf, 0xe7, 0x8e, 0xb5, 0x09, 0x7c, 0x60, 0xac, 0x4d, 0xe0, 0xb8, - 0x89, 0xae, 0xc4, 0x98, 0x46, 0x4b, 0x9c, 0x12, 0xd3, 0xa7, 0x41, 0xf0, 0xd2, 0x63, 0x16, 0xf9, - 0xa2, 0x90, 0xb7, 0xd3, 0x91, 0xeb, 0x52, 0xbd, 0xa7, 0xc5, 0x21, 0xfd, 0x12, 0x4d, 0x4d, 0xe3, - 0x27, 0x68, 0xae, 0x67, 0x5e, 0x61, 0x6f, 0x93, 0x79, 0x0e, 0x90, 0x53, 0xd5, 0xe3, 0xfa, 0x90, - 0xb1, 0xe5, 0xd1, 0xf0, 0xe2, 0xad, 0xbe, 0x48, 0xfb, 0x33, 0xf8, 0x29, 0x9a, 0x8f, 0xc9, 0xea, - 0xa4, 0x28, 0xf4, 0x57, 0x85, 0xbe, 0x91, 0x8e, 0xd6, 0x47, 0xa6, 0x87, 0x8d, 0xe9, 0x40, 0x0a, - 0x6f, 0xa1, 0x62, 0x0c, 0x77, 0xec, 0x80, 0x93, 0x6f, 0x8a, 0xba, 0x94, 0x4e, 0xdd, 0xb1, 0x03, - 0x9e, 0xf0, 0x51, 0x18, 0x8c, 0x48, 0x62, 0x34, 0x45, 0xfa, 0x3e, 0x94, 0x24, 0x5a, 0x0f, 0x90, - 0xc2, 0x60, 0xb4, 0xf5, 0x92, 0x24, 0x1c, 0xf9, 0x26, 0x37, 0x6c, 0xeb, 0x45, 0x4d, 0xbf, 0x23, - 0x75, 0x2c, 0x72, 0xa4, 0xc4, 0x68, 0x47, 0xbe, 0xcd, 0x0d, 0x73, 0xa4, 0xa8, 0x4a, 0x71, 0x64, - 0x1c, 0x4e, 0x8e, 0x25, 0x1c, 0xf9, 0xee, 0xdc, 0xb1, 0xfa, 0x1d, 0xa9, 0x63, 0xf8, 0x39, 0x2a, - 0xf5, 0x60, 0xa4, 0x51, 0x7c, 0x60, 0x6d, 0x3b, 0x90, 0xf7, 0xd8, 0x7b, 0xc5, 0xbc, 0x33, 0x84, - 0x29, 0xe4, 0x7b, 0x91, 0x3a, 0xe4, 0x5f, 0xa6, 0xe9, 0x79, 0xdc, 0x46, 0x0b, 0x71, 0x2f, 0x6d, - 0x9d, 0x9e, 0x66, 0x1f, 0x54, 0xb3, 0xbb, 0xe9, 0xcd, 0x94, 0x4b, 0x06, 0xbb, 0x11, 0x3a, 0x44, - 0x50, 0xb9, 0x80, 0xa6, 0x37, 0xda, 0x3e, 0x7f, 0x65, 0x40, 0xe0, 0x7b, 0x6e, 0x00, 0x15, 0x1f, - 0x2d, 0x9c, 0xf3, 0x43, 0x84, 0x31, 0x1a, 0x93, 0xb7, 0x7b, 0x46, 0xde, 0xee, 0xf2, 0x59, 0xdc, - 0xfa, 0xd1, 0xf9, 0xd4, 0xb7, 0x7e, 0xf8, 0x8e, 0x97, 0x50, 0x21, 0xb0, 0xdb, 0xbe, 0x03, 0x26, - 0xf7, 0x8e, 0x40, 0x5d, 0xfa, 0x39, 0x23, 0xaf, 0x62, 0xfb, 0x22, 0xf4, 0x68, 0xee, 0xe4, 0x67, - 0x79, 0xe4, 0xe4, 0xac, 0x9c, 0x39, 0x3d, 0x2b, 0x67, 0x7e, 0x9c, 0x95, 0x33, 0xaf, 0x7f, 0x95, - 0x47, 0x0e, 0x26, 0xe4, 0x5f, 0x8e, 0xb5, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xff, 0xc9, 0xfc, - 0x0e, 0xca, 0x08, 0x00, 0x00, -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/raft_internal_stringer.go b/vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/raft_internal_stringer.go deleted file mode 100644 index 3d3536a326dd..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/raft_internal_stringer.go +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserverpb - -import ( - "fmt" - "strings" - - proto "github.com/golang/protobuf/proto" -) - -// InternalRaftStringer implements custom proto Stringer: -// redact password, replace value fields with value_size fields. -type InternalRaftStringer struct { - Request *InternalRaftRequest -} - -func (as *InternalRaftStringer) String() string { - switch { - case as.Request.LeaseGrant != nil: - return fmt.Sprintf("header:<%s> lease_grant:", - as.Request.Header.String(), - as.Request.LeaseGrant.TTL, - as.Request.LeaseGrant.ID, - ) - case as.Request.LeaseRevoke != nil: - return fmt.Sprintf("header:<%s> lease_revoke:", - as.Request.Header.String(), - as.Request.LeaseRevoke.ID, - ) - case as.Request.Authenticate != nil: - return fmt.Sprintf("header:<%s> authenticate:", - as.Request.Header.String(), - as.Request.Authenticate.Name, - as.Request.Authenticate.SimpleToken, - ) - case as.Request.AuthUserAdd != nil: - return fmt.Sprintf("header:<%s> auth_user_add:", - as.Request.Header.String(), - as.Request.AuthUserAdd.Name, - ) - case as.Request.AuthUserChangePassword != nil: - return fmt.Sprintf("header:<%s> auth_user_change_password:", - as.Request.Header.String(), - as.Request.AuthUserChangePassword.Name, - ) - case as.Request.Put != nil: - return fmt.Sprintf("header:<%s> put:<%s>", - as.Request.Header.String(), - NewLoggablePutRequest(as.Request.Put).String(), - ) - case as.Request.Txn != nil: - return fmt.Sprintf("header:<%s> txn:<%s>", - as.Request.Header.String(), - NewLoggableTxnRequest(as.Request.Txn).String(), - ) - default: - // nothing to redact - } - return as.Request.String() -} - -// txnRequestStringer implements a custom proto String to replace value bytes fields with value size -// fields in any nested txn and put operations. -type txnRequestStringer struct { - Request *TxnRequest -} - -func NewLoggableTxnRequest(request *TxnRequest) *txnRequestStringer { - return &txnRequestStringer{request} -} - -func (as *txnRequestStringer) String() string { - var compare []string - for _, c := range as.Request.Compare { - switch cv := c.TargetUnion.(type) { - case *Compare_Value: - compare = append(compare, newLoggableValueCompare(c, cv).String()) - default: - // nothing to redact - compare = append(compare, c.String()) - } - } - var success []string - for _, s := range as.Request.Success { - success = append(success, newLoggableRequestOp(s).String()) - } - var failure []string - for _, f := range as.Request.Failure { - failure = append(failure, newLoggableRequestOp(f).String()) - } - return fmt.Sprintf("compare:<%s> success:<%s> failure:<%s>", - strings.Join(compare, " "), - strings.Join(success, " "), - strings.Join(failure, " "), - ) -} - -// requestOpStringer implements a custom proto String to replace value bytes fields with value -// size fields in any nested txn and put operations. -type requestOpStringer struct { - Op *RequestOp -} - -func newLoggableRequestOp(op *RequestOp) *requestOpStringer { - return &requestOpStringer{op} -} - -func (as *requestOpStringer) String() string { - switch op := as.Op.Request.(type) { - case *RequestOp_RequestPut: - return fmt.Sprintf("request_put:<%s>", NewLoggablePutRequest(op.RequestPut).String()) - case *RequestOp_RequestTxn: - return fmt.Sprintf("request_txn:<%s>", NewLoggableTxnRequest(op.RequestTxn).String()) - default: - // nothing to redact - } - return as.Op.String() -} - -// loggableValueCompare implements a custom proto String for Compare.Value union member types to -// replace the value bytes field with a value size field. -// To preserve proto encoding of the key and range_end bytes, a faked out proto type is used here. -type loggableValueCompare struct { - Result Compare_CompareResult `protobuf:"varint,1,opt,name=result,proto3,enum=etcdserverpb.Compare_CompareResult"` - Target Compare_CompareTarget `protobuf:"varint,2,opt,name=target,proto3,enum=etcdserverpb.Compare_CompareTarget"` - Key []byte `protobuf:"bytes,3,opt,name=key,proto3"` - ValueSize int `protobuf:"bytes,7,opt,name=value_size,proto3"` - RangeEnd []byte `protobuf:"bytes,64,opt,name=range_end,proto3"` -} - -func newLoggableValueCompare(c *Compare, cv *Compare_Value) *loggableValueCompare { - return &loggableValueCompare{ - c.Result, - c.Target, - c.Key, - len(cv.Value), - c.RangeEnd, - } -} - -func (m *loggableValueCompare) Reset() { *m = loggableValueCompare{} } -func (m *loggableValueCompare) String() string { return proto.CompactTextString(m) } -func (*loggableValueCompare) ProtoMessage() {} - -// loggablePutRequest implements a custom proto String to replace value bytes field with a value -// size field. -// To preserve proto encoding of the key bytes, a faked out proto type is used here. -type loggablePutRequest struct { - Key []byte `protobuf:"bytes,1,opt,name=key,proto3"` - ValueSize int `protobuf:"varint,2,opt,name=value_size,proto3"` - Lease int64 `protobuf:"varint,3,opt,name=lease,proto3"` - PrevKv bool `protobuf:"varint,4,opt,name=prev_kv,proto3"` - IgnoreValue bool `protobuf:"varint,5,opt,name=ignore_value,proto3"` - IgnoreLease bool `protobuf:"varint,6,opt,name=ignore_lease,proto3"` -} - -func NewLoggablePutRequest(request *PutRequest) *loggablePutRequest { - return &loggablePutRequest{ - request.Key, - len(request.Value), - request.Lease, - request.PrevKv, - request.IgnoreValue, - request.IgnoreLease, - } -} - -func (m *loggablePutRequest) Reset() { *m = loggablePutRequest{} } -func (m *loggablePutRequest) String() string { return proto.CompactTextString(m) } -func (*loggablePutRequest) ProtoMessage() {} diff --git a/vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/rpc.pb.go b/vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/rpc.pb.go deleted file mode 100644 index 40147f935ab2..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/etcdserverpb/rpc.pb.go +++ /dev/null @@ -1,18665 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: rpc.proto - -package etcdserverpb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - mvccpb "github.com/coreos/etcd/mvcc/mvccpb" - - authpb "github.com/coreos/etcd/auth/authpb" - - context "golang.org/x/net/context" - - grpc "google.golang.org/grpc" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -type AlarmType int32 - -const ( - AlarmType_NONE AlarmType = 0 - AlarmType_NOSPACE AlarmType = 1 - AlarmType_CORRUPT AlarmType = 2 -) - -var AlarmType_name = map[int32]string{ - 0: "NONE", - 1: "NOSPACE", - 2: "CORRUPT", -} -var AlarmType_value = map[string]int32{ - "NONE": 0, - "NOSPACE": 1, - "CORRUPT": 2, -} - -func (x AlarmType) String() string { - return proto.EnumName(AlarmType_name, int32(x)) -} -func (AlarmType) EnumDescriptor() ([]byte, []int) { return fileDescriptorRpc, []int{0} } - -type RangeRequest_SortOrder int32 - -const ( - RangeRequest_NONE RangeRequest_SortOrder = 0 - RangeRequest_ASCEND RangeRequest_SortOrder = 1 - RangeRequest_DESCEND RangeRequest_SortOrder = 2 -) - -var RangeRequest_SortOrder_name = map[int32]string{ - 0: "NONE", - 1: "ASCEND", - 2: "DESCEND", -} -var RangeRequest_SortOrder_value = map[string]int32{ - "NONE": 0, - "ASCEND": 1, - "DESCEND": 2, -} - -func (x RangeRequest_SortOrder) String() string { - return proto.EnumName(RangeRequest_SortOrder_name, int32(x)) -} -func (RangeRequest_SortOrder) EnumDescriptor() ([]byte, []int) { return fileDescriptorRpc, []int{1, 0} } - -type RangeRequest_SortTarget int32 - -const ( - RangeRequest_KEY RangeRequest_SortTarget = 0 - RangeRequest_VERSION RangeRequest_SortTarget = 1 - RangeRequest_CREATE RangeRequest_SortTarget = 2 - RangeRequest_MOD RangeRequest_SortTarget = 3 - RangeRequest_VALUE RangeRequest_SortTarget = 4 -) - -var RangeRequest_SortTarget_name = map[int32]string{ - 0: "KEY", - 1: "VERSION", - 2: "CREATE", - 3: "MOD", - 4: "VALUE", -} -var RangeRequest_SortTarget_value = map[string]int32{ - "KEY": 0, - "VERSION": 1, - "CREATE": 2, - "MOD": 3, - "VALUE": 4, -} - -func (x RangeRequest_SortTarget) String() string { - return proto.EnumName(RangeRequest_SortTarget_name, int32(x)) -} -func (RangeRequest_SortTarget) EnumDescriptor() ([]byte, []int) { return fileDescriptorRpc, []int{1, 1} } - -type Compare_CompareResult int32 - -const ( - Compare_EQUAL Compare_CompareResult = 0 - Compare_GREATER Compare_CompareResult = 1 - Compare_LESS Compare_CompareResult = 2 - Compare_NOT_EQUAL Compare_CompareResult = 3 -) - -var Compare_CompareResult_name = map[int32]string{ - 0: "EQUAL", - 1: "GREATER", - 2: "LESS", - 3: "NOT_EQUAL", -} -var Compare_CompareResult_value = map[string]int32{ - "EQUAL": 0, - "GREATER": 1, - "LESS": 2, - "NOT_EQUAL": 3, -} - -func (x Compare_CompareResult) String() string { - return proto.EnumName(Compare_CompareResult_name, int32(x)) -} -func (Compare_CompareResult) EnumDescriptor() ([]byte, []int) { return fileDescriptorRpc, []int{9, 0} } - -type Compare_CompareTarget int32 - -const ( - Compare_VERSION Compare_CompareTarget = 0 - Compare_CREATE Compare_CompareTarget = 1 - Compare_MOD Compare_CompareTarget = 2 - Compare_VALUE Compare_CompareTarget = 3 - Compare_LEASE Compare_CompareTarget = 4 -) - -var Compare_CompareTarget_name = map[int32]string{ - 0: "VERSION", - 1: "CREATE", - 2: "MOD", - 3: "VALUE", - 4: "LEASE", -} -var Compare_CompareTarget_value = map[string]int32{ - "VERSION": 0, - "CREATE": 1, - "MOD": 2, - "VALUE": 3, - "LEASE": 4, -} - -func (x Compare_CompareTarget) String() string { - return proto.EnumName(Compare_CompareTarget_name, int32(x)) -} -func (Compare_CompareTarget) EnumDescriptor() ([]byte, []int) { return fileDescriptorRpc, []int{9, 1} } - -type WatchCreateRequest_FilterType int32 - -const ( - // filter out put event. - WatchCreateRequest_NOPUT WatchCreateRequest_FilterType = 0 - // filter out delete event. - WatchCreateRequest_NODELETE WatchCreateRequest_FilterType = 1 -) - -var WatchCreateRequest_FilterType_name = map[int32]string{ - 0: "NOPUT", - 1: "NODELETE", -} -var WatchCreateRequest_FilterType_value = map[string]int32{ - "NOPUT": 0, - "NODELETE": 1, -} - -func (x WatchCreateRequest_FilterType) String() string { - return proto.EnumName(WatchCreateRequest_FilterType_name, int32(x)) -} -func (WatchCreateRequest_FilterType) EnumDescriptor() ([]byte, []int) { - return fileDescriptorRpc, []int{21, 0} -} - -type AlarmRequest_AlarmAction int32 - -const ( - AlarmRequest_GET AlarmRequest_AlarmAction = 0 - AlarmRequest_ACTIVATE AlarmRequest_AlarmAction = 1 - AlarmRequest_DEACTIVATE AlarmRequest_AlarmAction = 2 -) - -var AlarmRequest_AlarmAction_name = map[int32]string{ - 0: "GET", - 1: "ACTIVATE", - 2: "DEACTIVATE", -} -var AlarmRequest_AlarmAction_value = map[string]int32{ - "GET": 0, - "ACTIVATE": 1, - "DEACTIVATE": 2, -} - -func (x AlarmRequest_AlarmAction) String() string { - return proto.EnumName(AlarmRequest_AlarmAction_name, int32(x)) -} -func (AlarmRequest_AlarmAction) EnumDescriptor() ([]byte, []int) { - return fileDescriptorRpc, []int{48, 0} -} - -type ResponseHeader struct { - // cluster_id is the ID of the cluster which sent the response. - ClusterId uint64 `protobuf:"varint,1,opt,name=cluster_id,json=clusterId,proto3" json:"cluster_id,omitempty"` - // member_id is the ID of the member which sent the response. - MemberId uint64 `protobuf:"varint,2,opt,name=member_id,json=memberId,proto3" json:"member_id,omitempty"` - // revision is the key-value store revision when the request was applied. - Revision int64 `protobuf:"varint,3,opt,name=revision,proto3" json:"revision,omitempty"` - // raft_term is the raft term when the request was applied. - RaftTerm uint64 `protobuf:"varint,4,opt,name=raft_term,json=raftTerm,proto3" json:"raft_term,omitempty"` -} - -func (m *ResponseHeader) Reset() { *m = ResponseHeader{} } -func (m *ResponseHeader) String() string { return proto.CompactTextString(m) } -func (*ResponseHeader) ProtoMessage() {} -func (*ResponseHeader) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{0} } - -func (m *ResponseHeader) GetClusterId() uint64 { - if m != nil { - return m.ClusterId - } - return 0 -} - -func (m *ResponseHeader) GetMemberId() uint64 { - if m != nil { - return m.MemberId - } - return 0 -} - -func (m *ResponseHeader) GetRevision() int64 { - if m != nil { - return m.Revision - } - return 0 -} - -func (m *ResponseHeader) GetRaftTerm() uint64 { - if m != nil { - return m.RaftTerm - } - return 0 -} - -type RangeRequest struct { - // key is the first key for the range. If range_end is not given, the request only looks up key. - Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - // range_end is the upper bound on the requested range [key, range_end). - // If range_end is '\0', the range is all keys >= key. - // If range_end is key plus one (e.g., "aa"+1 == "ab", "a\xff"+1 == "b"), - // then the range request gets all keys prefixed with key. - // If both key and range_end are '\0', then the range request returns all keys. - RangeEnd []byte `protobuf:"bytes,2,opt,name=range_end,json=rangeEnd,proto3" json:"range_end,omitempty"` - // limit is a limit on the number of keys returned for the request. When limit is set to 0, - // it is treated as no limit. - Limit int64 `protobuf:"varint,3,opt,name=limit,proto3" json:"limit,omitempty"` - // revision is the point-in-time of the key-value store to use for the range. - // If revision is less or equal to zero, the range is over the newest key-value store. - // If the revision has been compacted, ErrCompacted is returned as a response. - Revision int64 `protobuf:"varint,4,opt,name=revision,proto3" json:"revision,omitempty"` - // sort_order is the order for returned sorted results. - SortOrder RangeRequest_SortOrder `protobuf:"varint,5,opt,name=sort_order,json=sortOrder,proto3,enum=etcdserverpb.RangeRequest_SortOrder" json:"sort_order,omitempty"` - // sort_target is the key-value field to use for sorting. - SortTarget RangeRequest_SortTarget `protobuf:"varint,6,opt,name=sort_target,json=sortTarget,proto3,enum=etcdserverpb.RangeRequest_SortTarget" json:"sort_target,omitempty"` - // serializable sets the range request to use serializable member-local reads. - // Range requests are linearizable by default; linearizable requests have higher - // latency and lower throughput than serializable requests but reflect the current - // consensus of the cluster. For better performance, in exchange for possible stale reads, - // a serializable range request is served locally without needing to reach consensus - // with other nodes in the cluster. - Serializable bool `protobuf:"varint,7,opt,name=serializable,proto3" json:"serializable,omitempty"` - // keys_only when set returns only the keys and not the values. - KeysOnly bool `protobuf:"varint,8,opt,name=keys_only,json=keysOnly,proto3" json:"keys_only,omitempty"` - // count_only when set returns only the count of the keys in the range. - CountOnly bool `protobuf:"varint,9,opt,name=count_only,json=countOnly,proto3" json:"count_only,omitempty"` - // min_mod_revision is the lower bound for returned key mod revisions; all keys with - // lesser mod revisions will be filtered away. - MinModRevision int64 `protobuf:"varint,10,opt,name=min_mod_revision,json=minModRevision,proto3" json:"min_mod_revision,omitempty"` - // max_mod_revision is the upper bound for returned key mod revisions; all keys with - // greater mod revisions will be filtered away. - MaxModRevision int64 `protobuf:"varint,11,opt,name=max_mod_revision,json=maxModRevision,proto3" json:"max_mod_revision,omitempty"` - // min_create_revision is the lower bound for returned key create revisions; all keys with - // lesser create trevisions will be filtered away. - MinCreateRevision int64 `protobuf:"varint,12,opt,name=min_create_revision,json=minCreateRevision,proto3" json:"min_create_revision,omitempty"` - // max_create_revision is the upper bound for returned key create revisions; all keys with - // greater create revisions will be filtered away. - MaxCreateRevision int64 `protobuf:"varint,13,opt,name=max_create_revision,json=maxCreateRevision,proto3" json:"max_create_revision,omitempty"` -} - -func (m *RangeRequest) Reset() { *m = RangeRequest{} } -func (m *RangeRequest) String() string { return proto.CompactTextString(m) } -func (*RangeRequest) ProtoMessage() {} -func (*RangeRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{1} } - -func (m *RangeRequest) GetKey() []byte { - if m != nil { - return m.Key - } - return nil -} - -func (m *RangeRequest) GetRangeEnd() []byte { - if m != nil { - return m.RangeEnd - } - return nil -} - -func (m *RangeRequest) GetLimit() int64 { - if m != nil { - return m.Limit - } - return 0 -} - -func (m *RangeRequest) GetRevision() int64 { - if m != nil { - return m.Revision - } - return 0 -} - -func (m *RangeRequest) GetSortOrder() RangeRequest_SortOrder { - if m != nil { - return m.SortOrder - } - return RangeRequest_NONE -} - -func (m *RangeRequest) GetSortTarget() RangeRequest_SortTarget { - if m != nil { - return m.SortTarget - } - return RangeRequest_KEY -} - -func (m *RangeRequest) GetSerializable() bool { - if m != nil { - return m.Serializable - } - return false -} - -func (m *RangeRequest) GetKeysOnly() bool { - if m != nil { - return m.KeysOnly - } - return false -} - -func (m *RangeRequest) GetCountOnly() bool { - if m != nil { - return m.CountOnly - } - return false -} - -func (m *RangeRequest) GetMinModRevision() int64 { - if m != nil { - return m.MinModRevision - } - return 0 -} - -func (m *RangeRequest) GetMaxModRevision() int64 { - if m != nil { - return m.MaxModRevision - } - return 0 -} - -func (m *RangeRequest) GetMinCreateRevision() int64 { - if m != nil { - return m.MinCreateRevision - } - return 0 -} - -func (m *RangeRequest) GetMaxCreateRevision() int64 { - if m != nil { - return m.MaxCreateRevision - } - return 0 -} - -type RangeResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // kvs is the list of key-value pairs matched by the range request. - // kvs is empty when count is requested. - Kvs []*mvccpb.KeyValue `protobuf:"bytes,2,rep,name=kvs" json:"kvs,omitempty"` - // more indicates if there are more keys to return in the requested range. - More bool `protobuf:"varint,3,opt,name=more,proto3" json:"more,omitempty"` - // count is set to the number of keys within the range when requested. - Count int64 `protobuf:"varint,4,opt,name=count,proto3" json:"count,omitempty"` -} - -func (m *RangeResponse) Reset() { *m = RangeResponse{} } -func (m *RangeResponse) String() string { return proto.CompactTextString(m) } -func (*RangeResponse) ProtoMessage() {} -func (*RangeResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{2} } - -func (m *RangeResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *RangeResponse) GetKvs() []*mvccpb.KeyValue { - if m != nil { - return m.Kvs - } - return nil -} - -func (m *RangeResponse) GetMore() bool { - if m != nil { - return m.More - } - return false -} - -func (m *RangeResponse) GetCount() int64 { - if m != nil { - return m.Count - } - return 0 -} - -type PutRequest struct { - // key is the key, in bytes, to put into the key-value store. - Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - // value is the value, in bytes, to associate with the key in the key-value store. - Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` - // lease is the lease ID to associate with the key in the key-value store. A lease - // value of 0 indicates no lease. - Lease int64 `protobuf:"varint,3,opt,name=lease,proto3" json:"lease,omitempty"` - // If prev_kv is set, etcd gets the previous key-value pair before changing it. - // The previous key-value pair will be returned in the put response. - PrevKv bool `protobuf:"varint,4,opt,name=prev_kv,json=prevKv,proto3" json:"prev_kv,omitempty"` - // If ignore_value is set, etcd updates the key using its current value. - // Returns an error if the key does not exist. - IgnoreValue bool `protobuf:"varint,5,opt,name=ignore_value,json=ignoreValue,proto3" json:"ignore_value,omitempty"` - // If ignore_lease is set, etcd updates the key using its current lease. - // Returns an error if the key does not exist. - IgnoreLease bool `protobuf:"varint,6,opt,name=ignore_lease,json=ignoreLease,proto3" json:"ignore_lease,omitempty"` -} - -func (m *PutRequest) Reset() { *m = PutRequest{} } -func (m *PutRequest) String() string { return proto.CompactTextString(m) } -func (*PutRequest) ProtoMessage() {} -func (*PutRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{3} } - -func (m *PutRequest) GetKey() []byte { - if m != nil { - return m.Key - } - return nil -} - -func (m *PutRequest) GetValue() []byte { - if m != nil { - return m.Value - } - return nil -} - -func (m *PutRequest) GetLease() int64 { - if m != nil { - return m.Lease - } - return 0 -} - -func (m *PutRequest) GetPrevKv() bool { - if m != nil { - return m.PrevKv - } - return false -} - -func (m *PutRequest) GetIgnoreValue() bool { - if m != nil { - return m.IgnoreValue - } - return false -} - -func (m *PutRequest) GetIgnoreLease() bool { - if m != nil { - return m.IgnoreLease - } - return false -} - -type PutResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // if prev_kv is set in the request, the previous key-value pair will be returned. - PrevKv *mvccpb.KeyValue `protobuf:"bytes,2,opt,name=prev_kv,json=prevKv" json:"prev_kv,omitempty"` -} - -func (m *PutResponse) Reset() { *m = PutResponse{} } -func (m *PutResponse) String() string { return proto.CompactTextString(m) } -func (*PutResponse) ProtoMessage() {} -func (*PutResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{4} } - -func (m *PutResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *PutResponse) GetPrevKv() *mvccpb.KeyValue { - if m != nil { - return m.PrevKv - } - return nil -} - -type DeleteRangeRequest struct { - // key is the first key to delete in the range. - Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - // range_end is the key following the last key to delete for the range [key, range_end). - // If range_end is not given, the range is defined to contain only the key argument. - // If range_end is one bit larger than the given key, then the range is all the keys - // with the prefix (the given key). - // If range_end is '\0', the range is all keys greater than or equal to the key argument. - RangeEnd []byte `protobuf:"bytes,2,opt,name=range_end,json=rangeEnd,proto3" json:"range_end,omitempty"` - // If prev_kv is set, etcd gets the previous key-value pairs before deleting it. - // The previous key-value pairs will be returned in the delete response. - PrevKv bool `protobuf:"varint,3,opt,name=prev_kv,json=prevKv,proto3" json:"prev_kv,omitempty"` -} - -func (m *DeleteRangeRequest) Reset() { *m = DeleteRangeRequest{} } -func (m *DeleteRangeRequest) String() string { return proto.CompactTextString(m) } -func (*DeleteRangeRequest) ProtoMessage() {} -func (*DeleteRangeRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{5} } - -func (m *DeleteRangeRequest) GetKey() []byte { - if m != nil { - return m.Key - } - return nil -} - -func (m *DeleteRangeRequest) GetRangeEnd() []byte { - if m != nil { - return m.RangeEnd - } - return nil -} - -func (m *DeleteRangeRequest) GetPrevKv() bool { - if m != nil { - return m.PrevKv - } - return false -} - -type DeleteRangeResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // deleted is the number of keys deleted by the delete range request. - Deleted int64 `protobuf:"varint,2,opt,name=deleted,proto3" json:"deleted,omitempty"` - // if prev_kv is set in the request, the previous key-value pairs will be returned. - PrevKvs []*mvccpb.KeyValue `protobuf:"bytes,3,rep,name=prev_kvs,json=prevKvs" json:"prev_kvs,omitempty"` -} - -func (m *DeleteRangeResponse) Reset() { *m = DeleteRangeResponse{} } -func (m *DeleteRangeResponse) String() string { return proto.CompactTextString(m) } -func (*DeleteRangeResponse) ProtoMessage() {} -func (*DeleteRangeResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{6} } - -func (m *DeleteRangeResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *DeleteRangeResponse) GetDeleted() int64 { - if m != nil { - return m.Deleted - } - return 0 -} - -func (m *DeleteRangeResponse) GetPrevKvs() []*mvccpb.KeyValue { - if m != nil { - return m.PrevKvs - } - return nil -} - -type RequestOp struct { - // request is a union of request types accepted by a transaction. - // - // Types that are valid to be assigned to Request: - // *RequestOp_RequestRange - // *RequestOp_RequestPut - // *RequestOp_RequestDeleteRange - // *RequestOp_RequestTxn - Request isRequestOp_Request `protobuf_oneof:"request"` -} - -func (m *RequestOp) Reset() { *m = RequestOp{} } -func (m *RequestOp) String() string { return proto.CompactTextString(m) } -func (*RequestOp) ProtoMessage() {} -func (*RequestOp) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{7} } - -type isRequestOp_Request interface { - isRequestOp_Request() - MarshalTo([]byte) (int, error) - Size() int -} - -type RequestOp_RequestRange struct { - RequestRange *RangeRequest `protobuf:"bytes,1,opt,name=request_range,json=requestRange,oneof"` -} -type RequestOp_RequestPut struct { - RequestPut *PutRequest `protobuf:"bytes,2,opt,name=request_put,json=requestPut,oneof"` -} -type RequestOp_RequestDeleteRange struct { - RequestDeleteRange *DeleteRangeRequest `protobuf:"bytes,3,opt,name=request_delete_range,json=requestDeleteRange,oneof"` -} -type RequestOp_RequestTxn struct { - RequestTxn *TxnRequest `protobuf:"bytes,4,opt,name=request_txn,json=requestTxn,oneof"` -} - -func (*RequestOp_RequestRange) isRequestOp_Request() {} -func (*RequestOp_RequestPut) isRequestOp_Request() {} -func (*RequestOp_RequestDeleteRange) isRequestOp_Request() {} -func (*RequestOp_RequestTxn) isRequestOp_Request() {} - -func (m *RequestOp) GetRequest() isRequestOp_Request { - if m != nil { - return m.Request - } - return nil -} - -func (m *RequestOp) GetRequestRange() *RangeRequest { - if x, ok := m.GetRequest().(*RequestOp_RequestRange); ok { - return x.RequestRange - } - return nil -} - -func (m *RequestOp) GetRequestPut() *PutRequest { - if x, ok := m.GetRequest().(*RequestOp_RequestPut); ok { - return x.RequestPut - } - return nil -} - -func (m *RequestOp) GetRequestDeleteRange() *DeleteRangeRequest { - if x, ok := m.GetRequest().(*RequestOp_RequestDeleteRange); ok { - return x.RequestDeleteRange - } - return nil -} - -func (m *RequestOp) GetRequestTxn() *TxnRequest { - if x, ok := m.GetRequest().(*RequestOp_RequestTxn); ok { - return x.RequestTxn - } - return nil -} - -// XXX_OneofFuncs is for the internal use of the proto package. -func (*RequestOp) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { - return _RequestOp_OneofMarshaler, _RequestOp_OneofUnmarshaler, _RequestOp_OneofSizer, []interface{}{ - (*RequestOp_RequestRange)(nil), - (*RequestOp_RequestPut)(nil), - (*RequestOp_RequestDeleteRange)(nil), - (*RequestOp_RequestTxn)(nil), - } -} - -func _RequestOp_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { - m := msg.(*RequestOp) - // request - switch x := m.Request.(type) { - case *RequestOp_RequestRange: - _ = b.EncodeVarint(1<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.RequestRange); err != nil { - return err - } - case *RequestOp_RequestPut: - _ = b.EncodeVarint(2<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.RequestPut); err != nil { - return err - } - case *RequestOp_RequestDeleteRange: - _ = b.EncodeVarint(3<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.RequestDeleteRange); err != nil { - return err - } - case *RequestOp_RequestTxn: - _ = b.EncodeVarint(4<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.RequestTxn); err != nil { - return err - } - case nil: - default: - return fmt.Errorf("RequestOp.Request has unexpected type %T", x) - } - return nil -} - -func _RequestOp_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { - m := msg.(*RequestOp) - switch tag { - case 1: // request.request_range - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(RangeRequest) - err := b.DecodeMessage(msg) - m.Request = &RequestOp_RequestRange{msg} - return true, err - case 2: // request.request_put - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(PutRequest) - err := b.DecodeMessage(msg) - m.Request = &RequestOp_RequestPut{msg} - return true, err - case 3: // request.request_delete_range - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(DeleteRangeRequest) - err := b.DecodeMessage(msg) - m.Request = &RequestOp_RequestDeleteRange{msg} - return true, err - case 4: // request.request_txn - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(TxnRequest) - err := b.DecodeMessage(msg) - m.Request = &RequestOp_RequestTxn{msg} - return true, err - default: - return false, nil - } -} - -func _RequestOp_OneofSizer(msg proto.Message) (n int) { - m := msg.(*RequestOp) - // request - switch x := m.Request.(type) { - case *RequestOp_RequestRange: - s := proto.Size(x.RequestRange) - n += proto.SizeVarint(1<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case *RequestOp_RequestPut: - s := proto.Size(x.RequestPut) - n += proto.SizeVarint(2<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case *RequestOp_RequestDeleteRange: - s := proto.Size(x.RequestDeleteRange) - n += proto.SizeVarint(3<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case *RequestOp_RequestTxn: - s := proto.Size(x.RequestTxn) - n += proto.SizeVarint(4<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case nil: - default: - panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) - } - return n -} - -type ResponseOp struct { - // response is a union of response types returned by a transaction. - // - // Types that are valid to be assigned to Response: - // *ResponseOp_ResponseRange - // *ResponseOp_ResponsePut - // *ResponseOp_ResponseDeleteRange - // *ResponseOp_ResponseTxn - Response isResponseOp_Response `protobuf_oneof:"response"` -} - -func (m *ResponseOp) Reset() { *m = ResponseOp{} } -func (m *ResponseOp) String() string { return proto.CompactTextString(m) } -func (*ResponseOp) ProtoMessage() {} -func (*ResponseOp) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{8} } - -type isResponseOp_Response interface { - isResponseOp_Response() - MarshalTo([]byte) (int, error) - Size() int -} - -type ResponseOp_ResponseRange struct { - ResponseRange *RangeResponse `protobuf:"bytes,1,opt,name=response_range,json=responseRange,oneof"` -} -type ResponseOp_ResponsePut struct { - ResponsePut *PutResponse `protobuf:"bytes,2,opt,name=response_put,json=responsePut,oneof"` -} -type ResponseOp_ResponseDeleteRange struct { - ResponseDeleteRange *DeleteRangeResponse `protobuf:"bytes,3,opt,name=response_delete_range,json=responseDeleteRange,oneof"` -} -type ResponseOp_ResponseTxn struct { - ResponseTxn *TxnResponse `protobuf:"bytes,4,opt,name=response_txn,json=responseTxn,oneof"` -} - -func (*ResponseOp_ResponseRange) isResponseOp_Response() {} -func (*ResponseOp_ResponsePut) isResponseOp_Response() {} -func (*ResponseOp_ResponseDeleteRange) isResponseOp_Response() {} -func (*ResponseOp_ResponseTxn) isResponseOp_Response() {} - -func (m *ResponseOp) GetResponse() isResponseOp_Response { - if m != nil { - return m.Response - } - return nil -} - -func (m *ResponseOp) GetResponseRange() *RangeResponse { - if x, ok := m.GetResponse().(*ResponseOp_ResponseRange); ok { - return x.ResponseRange - } - return nil -} - -func (m *ResponseOp) GetResponsePut() *PutResponse { - if x, ok := m.GetResponse().(*ResponseOp_ResponsePut); ok { - return x.ResponsePut - } - return nil -} - -func (m *ResponseOp) GetResponseDeleteRange() *DeleteRangeResponse { - if x, ok := m.GetResponse().(*ResponseOp_ResponseDeleteRange); ok { - return x.ResponseDeleteRange - } - return nil -} - -func (m *ResponseOp) GetResponseTxn() *TxnResponse { - if x, ok := m.GetResponse().(*ResponseOp_ResponseTxn); ok { - return x.ResponseTxn - } - return nil -} - -// XXX_OneofFuncs is for the internal use of the proto package. -func (*ResponseOp) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { - return _ResponseOp_OneofMarshaler, _ResponseOp_OneofUnmarshaler, _ResponseOp_OneofSizer, []interface{}{ - (*ResponseOp_ResponseRange)(nil), - (*ResponseOp_ResponsePut)(nil), - (*ResponseOp_ResponseDeleteRange)(nil), - (*ResponseOp_ResponseTxn)(nil), - } -} - -func _ResponseOp_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { - m := msg.(*ResponseOp) - // response - switch x := m.Response.(type) { - case *ResponseOp_ResponseRange: - _ = b.EncodeVarint(1<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.ResponseRange); err != nil { - return err - } - case *ResponseOp_ResponsePut: - _ = b.EncodeVarint(2<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.ResponsePut); err != nil { - return err - } - case *ResponseOp_ResponseDeleteRange: - _ = b.EncodeVarint(3<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.ResponseDeleteRange); err != nil { - return err - } - case *ResponseOp_ResponseTxn: - _ = b.EncodeVarint(4<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.ResponseTxn); err != nil { - return err - } - case nil: - default: - return fmt.Errorf("ResponseOp.Response has unexpected type %T", x) - } - return nil -} - -func _ResponseOp_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { - m := msg.(*ResponseOp) - switch tag { - case 1: // response.response_range - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(RangeResponse) - err := b.DecodeMessage(msg) - m.Response = &ResponseOp_ResponseRange{msg} - return true, err - case 2: // response.response_put - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(PutResponse) - err := b.DecodeMessage(msg) - m.Response = &ResponseOp_ResponsePut{msg} - return true, err - case 3: // response.response_delete_range - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(DeleteRangeResponse) - err := b.DecodeMessage(msg) - m.Response = &ResponseOp_ResponseDeleteRange{msg} - return true, err - case 4: // response.response_txn - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(TxnResponse) - err := b.DecodeMessage(msg) - m.Response = &ResponseOp_ResponseTxn{msg} - return true, err - default: - return false, nil - } -} - -func _ResponseOp_OneofSizer(msg proto.Message) (n int) { - m := msg.(*ResponseOp) - // response - switch x := m.Response.(type) { - case *ResponseOp_ResponseRange: - s := proto.Size(x.ResponseRange) - n += proto.SizeVarint(1<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case *ResponseOp_ResponsePut: - s := proto.Size(x.ResponsePut) - n += proto.SizeVarint(2<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case *ResponseOp_ResponseDeleteRange: - s := proto.Size(x.ResponseDeleteRange) - n += proto.SizeVarint(3<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case *ResponseOp_ResponseTxn: - s := proto.Size(x.ResponseTxn) - n += proto.SizeVarint(4<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case nil: - default: - panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) - } - return n -} - -type Compare struct { - // result is logical comparison operation for this comparison. - Result Compare_CompareResult `protobuf:"varint,1,opt,name=result,proto3,enum=etcdserverpb.Compare_CompareResult" json:"result,omitempty"` - // target is the key-value field to inspect for the comparison. - Target Compare_CompareTarget `protobuf:"varint,2,opt,name=target,proto3,enum=etcdserverpb.Compare_CompareTarget" json:"target,omitempty"` - // key is the subject key for the comparison operation. - Key []byte `protobuf:"bytes,3,opt,name=key,proto3" json:"key,omitempty"` - // Types that are valid to be assigned to TargetUnion: - // *Compare_Version - // *Compare_CreateRevision - // *Compare_ModRevision - // *Compare_Value - // *Compare_Lease - TargetUnion isCompare_TargetUnion `protobuf_oneof:"target_union"` - // range_end compares the given target to all keys in the range [key, range_end). - // See RangeRequest for more details on key ranges. - RangeEnd []byte `protobuf:"bytes,64,opt,name=range_end,json=rangeEnd,proto3" json:"range_end,omitempty"` -} - -func (m *Compare) Reset() { *m = Compare{} } -func (m *Compare) String() string { return proto.CompactTextString(m) } -func (*Compare) ProtoMessage() {} -func (*Compare) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{9} } - -type isCompare_TargetUnion interface { - isCompare_TargetUnion() - MarshalTo([]byte) (int, error) - Size() int -} - -type Compare_Version struct { - Version int64 `protobuf:"varint,4,opt,name=version,proto3,oneof"` -} -type Compare_CreateRevision struct { - CreateRevision int64 `protobuf:"varint,5,opt,name=create_revision,json=createRevision,proto3,oneof"` -} -type Compare_ModRevision struct { - ModRevision int64 `protobuf:"varint,6,opt,name=mod_revision,json=modRevision,proto3,oneof"` -} -type Compare_Value struct { - Value []byte `protobuf:"bytes,7,opt,name=value,proto3,oneof"` -} -type Compare_Lease struct { - Lease int64 `protobuf:"varint,8,opt,name=lease,proto3,oneof"` -} - -func (*Compare_Version) isCompare_TargetUnion() {} -func (*Compare_CreateRevision) isCompare_TargetUnion() {} -func (*Compare_ModRevision) isCompare_TargetUnion() {} -func (*Compare_Value) isCompare_TargetUnion() {} -func (*Compare_Lease) isCompare_TargetUnion() {} - -func (m *Compare) GetTargetUnion() isCompare_TargetUnion { - if m != nil { - return m.TargetUnion - } - return nil -} - -func (m *Compare) GetResult() Compare_CompareResult { - if m != nil { - return m.Result - } - return Compare_EQUAL -} - -func (m *Compare) GetTarget() Compare_CompareTarget { - if m != nil { - return m.Target - } - return Compare_VERSION -} - -func (m *Compare) GetKey() []byte { - if m != nil { - return m.Key - } - return nil -} - -func (m *Compare) GetVersion() int64 { - if x, ok := m.GetTargetUnion().(*Compare_Version); ok { - return x.Version - } - return 0 -} - -func (m *Compare) GetCreateRevision() int64 { - if x, ok := m.GetTargetUnion().(*Compare_CreateRevision); ok { - return x.CreateRevision - } - return 0 -} - -func (m *Compare) GetModRevision() int64 { - if x, ok := m.GetTargetUnion().(*Compare_ModRevision); ok { - return x.ModRevision - } - return 0 -} - -func (m *Compare) GetValue() []byte { - if x, ok := m.GetTargetUnion().(*Compare_Value); ok { - return x.Value - } - return nil -} - -func (m *Compare) GetLease() int64 { - if x, ok := m.GetTargetUnion().(*Compare_Lease); ok { - return x.Lease - } - return 0 -} - -func (m *Compare) GetRangeEnd() []byte { - if m != nil { - return m.RangeEnd - } - return nil -} - -// XXX_OneofFuncs is for the internal use of the proto package. -func (*Compare) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { - return _Compare_OneofMarshaler, _Compare_OneofUnmarshaler, _Compare_OneofSizer, []interface{}{ - (*Compare_Version)(nil), - (*Compare_CreateRevision)(nil), - (*Compare_ModRevision)(nil), - (*Compare_Value)(nil), - (*Compare_Lease)(nil), - } -} - -func _Compare_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { - m := msg.(*Compare) - // target_union - switch x := m.TargetUnion.(type) { - case *Compare_Version: - _ = b.EncodeVarint(4<<3 | proto.WireVarint) - _ = b.EncodeVarint(uint64(x.Version)) - case *Compare_CreateRevision: - _ = b.EncodeVarint(5<<3 | proto.WireVarint) - _ = b.EncodeVarint(uint64(x.CreateRevision)) - case *Compare_ModRevision: - _ = b.EncodeVarint(6<<3 | proto.WireVarint) - _ = b.EncodeVarint(uint64(x.ModRevision)) - case *Compare_Value: - _ = b.EncodeVarint(7<<3 | proto.WireBytes) - _ = b.EncodeRawBytes(x.Value) - case *Compare_Lease: - _ = b.EncodeVarint(8<<3 | proto.WireVarint) - _ = b.EncodeVarint(uint64(x.Lease)) - case nil: - default: - return fmt.Errorf("Compare.TargetUnion has unexpected type %T", x) - } - return nil -} - -func _Compare_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { - m := msg.(*Compare) - switch tag { - case 4: // target_union.version - if wire != proto.WireVarint { - return true, proto.ErrInternalBadWireType - } - x, err := b.DecodeVarint() - m.TargetUnion = &Compare_Version{int64(x)} - return true, err - case 5: // target_union.create_revision - if wire != proto.WireVarint { - return true, proto.ErrInternalBadWireType - } - x, err := b.DecodeVarint() - m.TargetUnion = &Compare_CreateRevision{int64(x)} - return true, err - case 6: // target_union.mod_revision - if wire != proto.WireVarint { - return true, proto.ErrInternalBadWireType - } - x, err := b.DecodeVarint() - m.TargetUnion = &Compare_ModRevision{int64(x)} - return true, err - case 7: // target_union.value - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - x, err := b.DecodeRawBytes(true) - m.TargetUnion = &Compare_Value{x} - return true, err - case 8: // target_union.lease - if wire != proto.WireVarint { - return true, proto.ErrInternalBadWireType - } - x, err := b.DecodeVarint() - m.TargetUnion = &Compare_Lease{int64(x)} - return true, err - default: - return false, nil - } -} - -func _Compare_OneofSizer(msg proto.Message) (n int) { - m := msg.(*Compare) - // target_union - switch x := m.TargetUnion.(type) { - case *Compare_Version: - n += proto.SizeVarint(4<<3 | proto.WireVarint) - n += proto.SizeVarint(uint64(x.Version)) - case *Compare_CreateRevision: - n += proto.SizeVarint(5<<3 | proto.WireVarint) - n += proto.SizeVarint(uint64(x.CreateRevision)) - case *Compare_ModRevision: - n += proto.SizeVarint(6<<3 | proto.WireVarint) - n += proto.SizeVarint(uint64(x.ModRevision)) - case *Compare_Value: - n += proto.SizeVarint(7<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(len(x.Value))) - n += len(x.Value) - case *Compare_Lease: - n += proto.SizeVarint(8<<3 | proto.WireVarint) - n += proto.SizeVarint(uint64(x.Lease)) - case nil: - default: - panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) - } - return n -} - -// From google paxosdb paper: -// Our implementation hinges around a powerful primitive which we call MultiOp. All other database -// operations except for iteration are implemented as a single call to MultiOp. A MultiOp is applied atomically -// and consists of three components: -// 1. A list of tests called guard. Each test in guard checks a single entry in the database. It may check -// for the absence or presence of a value, or compare with a given value. Two different tests in the guard -// may apply to the same or different entries in the database. All tests in the guard are applied and -// MultiOp returns the results. If all tests are true, MultiOp executes t op (see item 2 below), otherwise -// it executes f op (see item 3 below). -// 2. A list of database operations called t op. Each operation in the list is either an insert, delete, or -// lookup operation, and applies to a single database entry. Two different operations in the list may apply -// to the same or different entries in the database. These operations are executed -// if guard evaluates to -// true. -// 3. A list of database operations called f op. Like t op, but executed if guard evaluates to false. -type TxnRequest struct { - // compare is a list of predicates representing a conjunction of terms. - // If the comparisons succeed, then the success requests will be processed in order, - // and the response will contain their respective responses in order. - // If the comparisons fail, then the failure requests will be processed in order, - // and the response will contain their respective responses in order. - Compare []*Compare `protobuf:"bytes,1,rep,name=compare" json:"compare,omitempty"` - // success is a list of requests which will be applied when compare evaluates to true. - Success []*RequestOp `protobuf:"bytes,2,rep,name=success" json:"success,omitempty"` - // failure is a list of requests which will be applied when compare evaluates to false. - Failure []*RequestOp `protobuf:"bytes,3,rep,name=failure" json:"failure,omitempty"` -} - -func (m *TxnRequest) Reset() { *m = TxnRequest{} } -func (m *TxnRequest) String() string { return proto.CompactTextString(m) } -func (*TxnRequest) ProtoMessage() {} -func (*TxnRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{10} } - -func (m *TxnRequest) GetCompare() []*Compare { - if m != nil { - return m.Compare - } - return nil -} - -func (m *TxnRequest) GetSuccess() []*RequestOp { - if m != nil { - return m.Success - } - return nil -} - -func (m *TxnRequest) GetFailure() []*RequestOp { - if m != nil { - return m.Failure - } - return nil -} - -type TxnResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // succeeded is set to true if the compare evaluated to true or false otherwise. - Succeeded bool `protobuf:"varint,2,opt,name=succeeded,proto3" json:"succeeded,omitempty"` - // responses is a list of responses corresponding to the results from applying - // success if succeeded is true or failure if succeeded is false. - Responses []*ResponseOp `protobuf:"bytes,3,rep,name=responses" json:"responses,omitempty"` -} - -func (m *TxnResponse) Reset() { *m = TxnResponse{} } -func (m *TxnResponse) String() string { return proto.CompactTextString(m) } -func (*TxnResponse) ProtoMessage() {} -func (*TxnResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{11} } - -func (m *TxnResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *TxnResponse) GetSucceeded() bool { - if m != nil { - return m.Succeeded - } - return false -} - -func (m *TxnResponse) GetResponses() []*ResponseOp { - if m != nil { - return m.Responses - } - return nil -} - -// CompactionRequest compacts the key-value store up to a given revision. All superseded keys -// with a revision less than the compaction revision will be removed. -type CompactionRequest struct { - // revision is the key-value store revision for the compaction operation. - Revision int64 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` - // physical is set so the RPC will wait until the compaction is physically - // applied to the local database such that compacted entries are totally - // removed from the backend database. - Physical bool `protobuf:"varint,2,opt,name=physical,proto3" json:"physical,omitempty"` -} - -func (m *CompactionRequest) Reset() { *m = CompactionRequest{} } -func (m *CompactionRequest) String() string { return proto.CompactTextString(m) } -func (*CompactionRequest) ProtoMessage() {} -func (*CompactionRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{12} } - -func (m *CompactionRequest) GetRevision() int64 { - if m != nil { - return m.Revision - } - return 0 -} - -func (m *CompactionRequest) GetPhysical() bool { - if m != nil { - return m.Physical - } - return false -} - -type CompactionResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *CompactionResponse) Reset() { *m = CompactionResponse{} } -func (m *CompactionResponse) String() string { return proto.CompactTextString(m) } -func (*CompactionResponse) ProtoMessage() {} -func (*CompactionResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{13} } - -func (m *CompactionResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type HashRequest struct { -} - -func (m *HashRequest) Reset() { *m = HashRequest{} } -func (m *HashRequest) String() string { return proto.CompactTextString(m) } -func (*HashRequest) ProtoMessage() {} -func (*HashRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{14} } - -type HashKVRequest struct { - // revision is the key-value store revision for the hash operation. - Revision int64 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` -} - -func (m *HashKVRequest) Reset() { *m = HashKVRequest{} } -func (m *HashKVRequest) String() string { return proto.CompactTextString(m) } -func (*HashKVRequest) ProtoMessage() {} -func (*HashKVRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{15} } - -func (m *HashKVRequest) GetRevision() int64 { - if m != nil { - return m.Revision - } - return 0 -} - -type HashKVResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // hash is the hash value computed from the responding member's MVCC keys up to a given revision. - Hash uint32 `protobuf:"varint,2,opt,name=hash,proto3" json:"hash,omitempty"` - // compact_revision is the compacted revision of key-value store when hash begins. - CompactRevision int64 `protobuf:"varint,3,opt,name=compact_revision,json=compactRevision,proto3" json:"compact_revision,omitempty"` -} - -func (m *HashKVResponse) Reset() { *m = HashKVResponse{} } -func (m *HashKVResponse) String() string { return proto.CompactTextString(m) } -func (*HashKVResponse) ProtoMessage() {} -func (*HashKVResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{16} } - -func (m *HashKVResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *HashKVResponse) GetHash() uint32 { - if m != nil { - return m.Hash - } - return 0 -} - -func (m *HashKVResponse) GetCompactRevision() int64 { - if m != nil { - return m.CompactRevision - } - return 0 -} - -type HashResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // hash is the hash value computed from the responding member's KV's backend. - Hash uint32 `protobuf:"varint,2,opt,name=hash,proto3" json:"hash,omitempty"` -} - -func (m *HashResponse) Reset() { *m = HashResponse{} } -func (m *HashResponse) String() string { return proto.CompactTextString(m) } -func (*HashResponse) ProtoMessage() {} -func (*HashResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{17} } - -func (m *HashResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *HashResponse) GetHash() uint32 { - if m != nil { - return m.Hash - } - return 0 -} - -type SnapshotRequest struct { -} - -func (m *SnapshotRequest) Reset() { *m = SnapshotRequest{} } -func (m *SnapshotRequest) String() string { return proto.CompactTextString(m) } -func (*SnapshotRequest) ProtoMessage() {} -func (*SnapshotRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{18} } - -type SnapshotResponse struct { - // header has the current key-value store information. The first header in the snapshot - // stream indicates the point in time of the snapshot. - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // remaining_bytes is the number of blob bytes to be sent after this message - RemainingBytes uint64 `protobuf:"varint,2,opt,name=remaining_bytes,json=remainingBytes,proto3" json:"remaining_bytes,omitempty"` - // blob contains the next chunk of the snapshot in the snapshot stream. - Blob []byte `protobuf:"bytes,3,opt,name=blob,proto3" json:"blob,omitempty"` -} - -func (m *SnapshotResponse) Reset() { *m = SnapshotResponse{} } -func (m *SnapshotResponse) String() string { return proto.CompactTextString(m) } -func (*SnapshotResponse) ProtoMessage() {} -func (*SnapshotResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{19} } - -func (m *SnapshotResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *SnapshotResponse) GetRemainingBytes() uint64 { - if m != nil { - return m.RemainingBytes - } - return 0 -} - -func (m *SnapshotResponse) GetBlob() []byte { - if m != nil { - return m.Blob - } - return nil -} - -type WatchRequest struct { - // request_union is a request to either create a new watcher or cancel an existing watcher. - // - // Types that are valid to be assigned to RequestUnion: - // *WatchRequest_CreateRequest - // *WatchRequest_CancelRequest - RequestUnion isWatchRequest_RequestUnion `protobuf_oneof:"request_union"` -} - -func (m *WatchRequest) Reset() { *m = WatchRequest{} } -func (m *WatchRequest) String() string { return proto.CompactTextString(m) } -func (*WatchRequest) ProtoMessage() {} -func (*WatchRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{20} } - -type isWatchRequest_RequestUnion interface { - isWatchRequest_RequestUnion() - MarshalTo([]byte) (int, error) - Size() int -} - -type WatchRequest_CreateRequest struct { - CreateRequest *WatchCreateRequest `protobuf:"bytes,1,opt,name=create_request,json=createRequest,oneof"` -} -type WatchRequest_CancelRequest struct { - CancelRequest *WatchCancelRequest `protobuf:"bytes,2,opt,name=cancel_request,json=cancelRequest,oneof"` -} - -func (*WatchRequest_CreateRequest) isWatchRequest_RequestUnion() {} -func (*WatchRequest_CancelRequest) isWatchRequest_RequestUnion() {} - -func (m *WatchRequest) GetRequestUnion() isWatchRequest_RequestUnion { - if m != nil { - return m.RequestUnion - } - return nil -} - -func (m *WatchRequest) GetCreateRequest() *WatchCreateRequest { - if x, ok := m.GetRequestUnion().(*WatchRequest_CreateRequest); ok { - return x.CreateRequest - } - return nil -} - -func (m *WatchRequest) GetCancelRequest() *WatchCancelRequest { - if x, ok := m.GetRequestUnion().(*WatchRequest_CancelRequest); ok { - return x.CancelRequest - } - return nil -} - -// XXX_OneofFuncs is for the internal use of the proto package. -func (*WatchRequest) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { - return _WatchRequest_OneofMarshaler, _WatchRequest_OneofUnmarshaler, _WatchRequest_OneofSizer, []interface{}{ - (*WatchRequest_CreateRequest)(nil), - (*WatchRequest_CancelRequest)(nil), - } -} - -func _WatchRequest_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { - m := msg.(*WatchRequest) - // request_union - switch x := m.RequestUnion.(type) { - case *WatchRequest_CreateRequest: - _ = b.EncodeVarint(1<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.CreateRequest); err != nil { - return err - } - case *WatchRequest_CancelRequest: - _ = b.EncodeVarint(2<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.CancelRequest); err != nil { - return err - } - case nil: - default: - return fmt.Errorf("WatchRequest.RequestUnion has unexpected type %T", x) - } - return nil -} - -func _WatchRequest_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { - m := msg.(*WatchRequest) - switch tag { - case 1: // request_union.create_request - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(WatchCreateRequest) - err := b.DecodeMessage(msg) - m.RequestUnion = &WatchRequest_CreateRequest{msg} - return true, err - case 2: // request_union.cancel_request - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(WatchCancelRequest) - err := b.DecodeMessage(msg) - m.RequestUnion = &WatchRequest_CancelRequest{msg} - return true, err - default: - return false, nil - } -} - -func _WatchRequest_OneofSizer(msg proto.Message) (n int) { - m := msg.(*WatchRequest) - // request_union - switch x := m.RequestUnion.(type) { - case *WatchRequest_CreateRequest: - s := proto.Size(x.CreateRequest) - n += proto.SizeVarint(1<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case *WatchRequest_CancelRequest: - s := proto.Size(x.CancelRequest) - n += proto.SizeVarint(2<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case nil: - default: - panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) - } - return n -} - -type WatchCreateRequest struct { - // key is the key to register for watching. - Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - // range_end is the end of the range [key, range_end) to watch. If range_end is not given, - // only the key argument is watched. If range_end is equal to '\0', all keys greater than - // or equal to the key argument are watched. - // If the range_end is one bit larger than the given key, - // then all keys with the prefix (the given key) will be watched. - RangeEnd []byte `protobuf:"bytes,2,opt,name=range_end,json=rangeEnd,proto3" json:"range_end,omitempty"` - // start_revision is an optional revision to watch from (inclusive). No start_revision is "now". - StartRevision int64 `protobuf:"varint,3,opt,name=start_revision,json=startRevision,proto3" json:"start_revision,omitempty"` - // progress_notify is set so that the etcd server will periodically send a WatchResponse with - // no events to the new watcher if there are no recent events. It is useful when clients - // wish to recover a disconnected watcher starting from a recent known revision. - // The etcd server may decide how often it will send notifications based on current load. - ProgressNotify bool `protobuf:"varint,4,opt,name=progress_notify,json=progressNotify,proto3" json:"progress_notify,omitempty"` - // filters filter the events at server side before it sends back to the watcher. - Filters []WatchCreateRequest_FilterType `protobuf:"varint,5,rep,packed,name=filters,enum=etcdserverpb.WatchCreateRequest_FilterType" json:"filters,omitempty"` - // If prev_kv is set, created watcher gets the previous KV before the event happens. - // If the previous KV is already compacted, nothing will be returned. - PrevKv bool `protobuf:"varint,6,opt,name=prev_kv,json=prevKv,proto3" json:"prev_kv,omitempty"` -} - -func (m *WatchCreateRequest) Reset() { *m = WatchCreateRequest{} } -func (m *WatchCreateRequest) String() string { return proto.CompactTextString(m) } -func (*WatchCreateRequest) ProtoMessage() {} -func (*WatchCreateRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{21} } - -func (m *WatchCreateRequest) GetKey() []byte { - if m != nil { - return m.Key - } - return nil -} - -func (m *WatchCreateRequest) GetRangeEnd() []byte { - if m != nil { - return m.RangeEnd - } - return nil -} - -func (m *WatchCreateRequest) GetStartRevision() int64 { - if m != nil { - return m.StartRevision - } - return 0 -} - -func (m *WatchCreateRequest) GetProgressNotify() bool { - if m != nil { - return m.ProgressNotify - } - return false -} - -func (m *WatchCreateRequest) GetFilters() []WatchCreateRequest_FilterType { - if m != nil { - return m.Filters - } - return nil -} - -func (m *WatchCreateRequest) GetPrevKv() bool { - if m != nil { - return m.PrevKv - } - return false -} - -type WatchCancelRequest struct { - // watch_id is the watcher id to cancel so that no more events are transmitted. - WatchId int64 `protobuf:"varint,1,opt,name=watch_id,json=watchId,proto3" json:"watch_id,omitempty"` -} - -func (m *WatchCancelRequest) Reset() { *m = WatchCancelRequest{} } -func (m *WatchCancelRequest) String() string { return proto.CompactTextString(m) } -func (*WatchCancelRequest) ProtoMessage() {} -func (*WatchCancelRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{22} } - -func (m *WatchCancelRequest) GetWatchId() int64 { - if m != nil { - return m.WatchId - } - return 0 -} - -type WatchResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // watch_id is the ID of the watcher that corresponds to the response. - WatchId int64 `protobuf:"varint,2,opt,name=watch_id,json=watchId,proto3" json:"watch_id,omitempty"` - // created is set to true if the response is for a create watch request. - // The client should record the watch_id and expect to receive events for - // the created watcher from the same stream. - // All events sent to the created watcher will attach with the same watch_id. - Created bool `protobuf:"varint,3,opt,name=created,proto3" json:"created,omitempty"` - // canceled is set to true if the response is for a cancel watch request. - // No further events will be sent to the canceled watcher. - Canceled bool `protobuf:"varint,4,opt,name=canceled,proto3" json:"canceled,omitempty"` - // compact_revision is set to the minimum index if a watcher tries to watch - // at a compacted index. - // - // This happens when creating a watcher at a compacted revision or the watcher cannot - // catch up with the progress of the key-value store. - // - // The client should treat the watcher as canceled and should not try to create any - // watcher with the same start_revision again. - CompactRevision int64 `protobuf:"varint,5,opt,name=compact_revision,json=compactRevision,proto3" json:"compact_revision,omitempty"` - // cancel_reason indicates the reason for canceling the watcher. - CancelReason string `protobuf:"bytes,6,opt,name=cancel_reason,json=cancelReason,proto3" json:"cancel_reason,omitempty"` - Events []*mvccpb.Event `protobuf:"bytes,11,rep,name=events" json:"events,omitempty"` -} - -func (m *WatchResponse) Reset() { *m = WatchResponse{} } -func (m *WatchResponse) String() string { return proto.CompactTextString(m) } -func (*WatchResponse) ProtoMessage() {} -func (*WatchResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{23} } - -func (m *WatchResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *WatchResponse) GetWatchId() int64 { - if m != nil { - return m.WatchId - } - return 0 -} - -func (m *WatchResponse) GetCreated() bool { - if m != nil { - return m.Created - } - return false -} - -func (m *WatchResponse) GetCanceled() bool { - if m != nil { - return m.Canceled - } - return false -} - -func (m *WatchResponse) GetCompactRevision() int64 { - if m != nil { - return m.CompactRevision - } - return 0 -} - -func (m *WatchResponse) GetCancelReason() string { - if m != nil { - return m.CancelReason - } - return "" -} - -func (m *WatchResponse) GetEvents() []*mvccpb.Event { - if m != nil { - return m.Events - } - return nil -} - -type LeaseGrantRequest struct { - // TTL is the advisory time-to-live in seconds. Expired lease will return -1. - TTL int64 `protobuf:"varint,1,opt,name=TTL,proto3" json:"TTL,omitempty"` - // ID is the requested ID for the lease. If ID is set to 0, the lessor chooses an ID. - ID int64 `protobuf:"varint,2,opt,name=ID,proto3" json:"ID,omitempty"` -} - -func (m *LeaseGrantRequest) Reset() { *m = LeaseGrantRequest{} } -func (m *LeaseGrantRequest) String() string { return proto.CompactTextString(m) } -func (*LeaseGrantRequest) ProtoMessage() {} -func (*LeaseGrantRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{24} } - -func (m *LeaseGrantRequest) GetTTL() int64 { - if m != nil { - return m.TTL - } - return 0 -} - -func (m *LeaseGrantRequest) GetID() int64 { - if m != nil { - return m.ID - } - return 0 -} - -type LeaseGrantResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // ID is the lease ID for the granted lease. - ID int64 `protobuf:"varint,2,opt,name=ID,proto3" json:"ID,omitempty"` - // TTL is the server chosen lease time-to-live in seconds. - TTL int64 `protobuf:"varint,3,opt,name=TTL,proto3" json:"TTL,omitempty"` - Error string `protobuf:"bytes,4,opt,name=error,proto3" json:"error,omitempty"` -} - -func (m *LeaseGrantResponse) Reset() { *m = LeaseGrantResponse{} } -func (m *LeaseGrantResponse) String() string { return proto.CompactTextString(m) } -func (*LeaseGrantResponse) ProtoMessage() {} -func (*LeaseGrantResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{25} } - -func (m *LeaseGrantResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *LeaseGrantResponse) GetID() int64 { - if m != nil { - return m.ID - } - return 0 -} - -func (m *LeaseGrantResponse) GetTTL() int64 { - if m != nil { - return m.TTL - } - return 0 -} - -func (m *LeaseGrantResponse) GetError() string { - if m != nil { - return m.Error - } - return "" -} - -type LeaseRevokeRequest struct { - // ID is the lease ID to revoke. When the ID is revoked, all associated keys will be deleted. - ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` -} - -func (m *LeaseRevokeRequest) Reset() { *m = LeaseRevokeRequest{} } -func (m *LeaseRevokeRequest) String() string { return proto.CompactTextString(m) } -func (*LeaseRevokeRequest) ProtoMessage() {} -func (*LeaseRevokeRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{26} } - -func (m *LeaseRevokeRequest) GetID() int64 { - if m != nil { - return m.ID - } - return 0 -} - -type LeaseRevokeResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *LeaseRevokeResponse) Reset() { *m = LeaseRevokeResponse{} } -func (m *LeaseRevokeResponse) String() string { return proto.CompactTextString(m) } -func (*LeaseRevokeResponse) ProtoMessage() {} -func (*LeaseRevokeResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{27} } - -func (m *LeaseRevokeResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type LeaseKeepAliveRequest struct { - // ID is the lease ID for the lease to keep alive. - ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` -} - -func (m *LeaseKeepAliveRequest) Reset() { *m = LeaseKeepAliveRequest{} } -func (m *LeaseKeepAliveRequest) String() string { return proto.CompactTextString(m) } -func (*LeaseKeepAliveRequest) ProtoMessage() {} -func (*LeaseKeepAliveRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{28} } - -func (m *LeaseKeepAliveRequest) GetID() int64 { - if m != nil { - return m.ID - } - return 0 -} - -type LeaseKeepAliveResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // ID is the lease ID from the keep alive request. - ID int64 `protobuf:"varint,2,opt,name=ID,proto3" json:"ID,omitempty"` - // TTL is the new time-to-live for the lease. - TTL int64 `protobuf:"varint,3,opt,name=TTL,proto3" json:"TTL,omitempty"` -} - -func (m *LeaseKeepAliveResponse) Reset() { *m = LeaseKeepAliveResponse{} } -func (m *LeaseKeepAliveResponse) String() string { return proto.CompactTextString(m) } -func (*LeaseKeepAliveResponse) ProtoMessage() {} -func (*LeaseKeepAliveResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{29} } - -func (m *LeaseKeepAliveResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *LeaseKeepAliveResponse) GetID() int64 { - if m != nil { - return m.ID - } - return 0 -} - -func (m *LeaseKeepAliveResponse) GetTTL() int64 { - if m != nil { - return m.TTL - } - return 0 -} - -type LeaseTimeToLiveRequest struct { - // ID is the lease ID for the lease. - ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` - // keys is true to query all the keys attached to this lease. - Keys bool `protobuf:"varint,2,opt,name=keys,proto3" json:"keys,omitempty"` -} - -func (m *LeaseTimeToLiveRequest) Reset() { *m = LeaseTimeToLiveRequest{} } -func (m *LeaseTimeToLiveRequest) String() string { return proto.CompactTextString(m) } -func (*LeaseTimeToLiveRequest) ProtoMessage() {} -func (*LeaseTimeToLiveRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{30} } - -func (m *LeaseTimeToLiveRequest) GetID() int64 { - if m != nil { - return m.ID - } - return 0 -} - -func (m *LeaseTimeToLiveRequest) GetKeys() bool { - if m != nil { - return m.Keys - } - return false -} - -type LeaseTimeToLiveResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // ID is the lease ID from the keep alive request. - ID int64 `protobuf:"varint,2,opt,name=ID,proto3" json:"ID,omitempty"` - // TTL is the remaining TTL in seconds for the lease; the lease will expire in under TTL+1 seconds. - TTL int64 `protobuf:"varint,3,opt,name=TTL,proto3" json:"TTL,omitempty"` - // GrantedTTL is the initial granted time in seconds upon lease creation/renewal. - GrantedTTL int64 `protobuf:"varint,4,opt,name=grantedTTL,proto3" json:"grantedTTL,omitempty"` - // Keys is the list of keys attached to this lease. - Keys [][]byte `protobuf:"bytes,5,rep,name=keys" json:"keys,omitempty"` -} - -func (m *LeaseTimeToLiveResponse) Reset() { *m = LeaseTimeToLiveResponse{} } -func (m *LeaseTimeToLiveResponse) String() string { return proto.CompactTextString(m) } -func (*LeaseTimeToLiveResponse) ProtoMessage() {} -func (*LeaseTimeToLiveResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{31} } - -func (m *LeaseTimeToLiveResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *LeaseTimeToLiveResponse) GetID() int64 { - if m != nil { - return m.ID - } - return 0 -} - -func (m *LeaseTimeToLiveResponse) GetTTL() int64 { - if m != nil { - return m.TTL - } - return 0 -} - -func (m *LeaseTimeToLiveResponse) GetGrantedTTL() int64 { - if m != nil { - return m.GrantedTTL - } - return 0 -} - -func (m *LeaseTimeToLiveResponse) GetKeys() [][]byte { - if m != nil { - return m.Keys - } - return nil -} - -type LeaseLeasesRequest struct { -} - -func (m *LeaseLeasesRequest) Reset() { *m = LeaseLeasesRequest{} } -func (m *LeaseLeasesRequest) String() string { return proto.CompactTextString(m) } -func (*LeaseLeasesRequest) ProtoMessage() {} -func (*LeaseLeasesRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{32} } - -type LeaseStatus struct { - ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` -} - -func (m *LeaseStatus) Reset() { *m = LeaseStatus{} } -func (m *LeaseStatus) String() string { return proto.CompactTextString(m) } -func (*LeaseStatus) ProtoMessage() {} -func (*LeaseStatus) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{33} } - -func (m *LeaseStatus) GetID() int64 { - if m != nil { - return m.ID - } - return 0 -} - -type LeaseLeasesResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - Leases []*LeaseStatus `protobuf:"bytes,2,rep,name=leases" json:"leases,omitempty"` -} - -func (m *LeaseLeasesResponse) Reset() { *m = LeaseLeasesResponse{} } -func (m *LeaseLeasesResponse) String() string { return proto.CompactTextString(m) } -func (*LeaseLeasesResponse) ProtoMessage() {} -func (*LeaseLeasesResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{34} } - -func (m *LeaseLeasesResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *LeaseLeasesResponse) GetLeases() []*LeaseStatus { - if m != nil { - return m.Leases - } - return nil -} - -type Member struct { - // ID is the member ID for this member. - ID uint64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` - // name is the human-readable name of the member. If the member is not started, the name will be an empty string. - Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` - // peerURLs is the list of URLs the member exposes to the cluster for communication. - PeerURLs []string `protobuf:"bytes,3,rep,name=peerURLs" json:"peerURLs,omitempty"` - // clientURLs is the list of URLs the member exposes to clients for communication. If the member is not started, clientURLs will be empty. - ClientURLs []string `protobuf:"bytes,4,rep,name=clientURLs" json:"clientURLs,omitempty"` -} - -func (m *Member) Reset() { *m = Member{} } -func (m *Member) String() string { return proto.CompactTextString(m) } -func (*Member) ProtoMessage() {} -func (*Member) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{35} } - -func (m *Member) GetID() uint64 { - if m != nil { - return m.ID - } - return 0 -} - -func (m *Member) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -func (m *Member) GetPeerURLs() []string { - if m != nil { - return m.PeerURLs - } - return nil -} - -func (m *Member) GetClientURLs() []string { - if m != nil { - return m.ClientURLs - } - return nil -} - -type MemberAddRequest struct { - // peerURLs is the list of URLs the added member will use to communicate with the cluster. - PeerURLs []string `protobuf:"bytes,1,rep,name=peerURLs" json:"peerURLs,omitempty"` -} - -func (m *MemberAddRequest) Reset() { *m = MemberAddRequest{} } -func (m *MemberAddRequest) String() string { return proto.CompactTextString(m) } -func (*MemberAddRequest) ProtoMessage() {} -func (*MemberAddRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{36} } - -func (m *MemberAddRequest) GetPeerURLs() []string { - if m != nil { - return m.PeerURLs - } - return nil -} - -type MemberAddResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // member is the member information for the added member. - Member *Member `protobuf:"bytes,2,opt,name=member" json:"member,omitempty"` - // members is a list of all members after adding the new member. - Members []*Member `protobuf:"bytes,3,rep,name=members" json:"members,omitempty"` -} - -func (m *MemberAddResponse) Reset() { *m = MemberAddResponse{} } -func (m *MemberAddResponse) String() string { return proto.CompactTextString(m) } -func (*MemberAddResponse) ProtoMessage() {} -func (*MemberAddResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{37} } - -func (m *MemberAddResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *MemberAddResponse) GetMember() *Member { - if m != nil { - return m.Member - } - return nil -} - -func (m *MemberAddResponse) GetMembers() []*Member { - if m != nil { - return m.Members - } - return nil -} - -type MemberRemoveRequest struct { - // ID is the member ID of the member to remove. - ID uint64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` -} - -func (m *MemberRemoveRequest) Reset() { *m = MemberRemoveRequest{} } -func (m *MemberRemoveRequest) String() string { return proto.CompactTextString(m) } -func (*MemberRemoveRequest) ProtoMessage() {} -func (*MemberRemoveRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{38} } - -func (m *MemberRemoveRequest) GetID() uint64 { - if m != nil { - return m.ID - } - return 0 -} - -type MemberRemoveResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // members is a list of all members after removing the member. - Members []*Member `protobuf:"bytes,2,rep,name=members" json:"members,omitempty"` -} - -func (m *MemberRemoveResponse) Reset() { *m = MemberRemoveResponse{} } -func (m *MemberRemoveResponse) String() string { return proto.CompactTextString(m) } -func (*MemberRemoveResponse) ProtoMessage() {} -func (*MemberRemoveResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{39} } - -func (m *MemberRemoveResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *MemberRemoveResponse) GetMembers() []*Member { - if m != nil { - return m.Members - } - return nil -} - -type MemberUpdateRequest struct { - // ID is the member ID of the member to update. - ID uint64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` - // peerURLs is the new list of URLs the member will use to communicate with the cluster. - PeerURLs []string `protobuf:"bytes,2,rep,name=peerURLs" json:"peerURLs,omitempty"` -} - -func (m *MemberUpdateRequest) Reset() { *m = MemberUpdateRequest{} } -func (m *MemberUpdateRequest) String() string { return proto.CompactTextString(m) } -func (*MemberUpdateRequest) ProtoMessage() {} -func (*MemberUpdateRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{40} } - -func (m *MemberUpdateRequest) GetID() uint64 { - if m != nil { - return m.ID - } - return 0 -} - -func (m *MemberUpdateRequest) GetPeerURLs() []string { - if m != nil { - return m.PeerURLs - } - return nil -} - -type MemberUpdateResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // members is a list of all members after updating the member. - Members []*Member `protobuf:"bytes,2,rep,name=members" json:"members,omitempty"` -} - -func (m *MemberUpdateResponse) Reset() { *m = MemberUpdateResponse{} } -func (m *MemberUpdateResponse) String() string { return proto.CompactTextString(m) } -func (*MemberUpdateResponse) ProtoMessage() {} -func (*MemberUpdateResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{41} } - -func (m *MemberUpdateResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *MemberUpdateResponse) GetMembers() []*Member { - if m != nil { - return m.Members - } - return nil -} - -type MemberListRequest struct { -} - -func (m *MemberListRequest) Reset() { *m = MemberListRequest{} } -func (m *MemberListRequest) String() string { return proto.CompactTextString(m) } -func (*MemberListRequest) ProtoMessage() {} -func (*MemberListRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{42} } - -type MemberListResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // members is a list of all members associated with the cluster. - Members []*Member `protobuf:"bytes,2,rep,name=members" json:"members,omitempty"` -} - -func (m *MemberListResponse) Reset() { *m = MemberListResponse{} } -func (m *MemberListResponse) String() string { return proto.CompactTextString(m) } -func (*MemberListResponse) ProtoMessage() {} -func (*MemberListResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{43} } - -func (m *MemberListResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *MemberListResponse) GetMembers() []*Member { - if m != nil { - return m.Members - } - return nil -} - -type DefragmentRequest struct { -} - -func (m *DefragmentRequest) Reset() { *m = DefragmentRequest{} } -func (m *DefragmentRequest) String() string { return proto.CompactTextString(m) } -func (*DefragmentRequest) ProtoMessage() {} -func (*DefragmentRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{44} } - -type DefragmentResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *DefragmentResponse) Reset() { *m = DefragmentResponse{} } -func (m *DefragmentResponse) String() string { return proto.CompactTextString(m) } -func (*DefragmentResponse) ProtoMessage() {} -func (*DefragmentResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{45} } - -func (m *DefragmentResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type MoveLeaderRequest struct { - // targetID is the node ID for the new leader. - TargetID uint64 `protobuf:"varint,1,opt,name=targetID,proto3" json:"targetID,omitempty"` -} - -func (m *MoveLeaderRequest) Reset() { *m = MoveLeaderRequest{} } -func (m *MoveLeaderRequest) String() string { return proto.CompactTextString(m) } -func (*MoveLeaderRequest) ProtoMessage() {} -func (*MoveLeaderRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{46} } - -func (m *MoveLeaderRequest) GetTargetID() uint64 { - if m != nil { - return m.TargetID - } - return 0 -} - -type MoveLeaderResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *MoveLeaderResponse) Reset() { *m = MoveLeaderResponse{} } -func (m *MoveLeaderResponse) String() string { return proto.CompactTextString(m) } -func (*MoveLeaderResponse) ProtoMessage() {} -func (*MoveLeaderResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{47} } - -func (m *MoveLeaderResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AlarmRequest struct { - // action is the kind of alarm request to issue. The action - // may GET alarm statuses, ACTIVATE an alarm, or DEACTIVATE a - // raised alarm. - Action AlarmRequest_AlarmAction `protobuf:"varint,1,opt,name=action,proto3,enum=etcdserverpb.AlarmRequest_AlarmAction" json:"action,omitempty"` - // memberID is the ID of the member associated with the alarm. If memberID is 0, the - // alarm request covers all members. - MemberID uint64 `protobuf:"varint,2,opt,name=memberID,proto3" json:"memberID,omitempty"` - // alarm is the type of alarm to consider for this request. - Alarm AlarmType `protobuf:"varint,3,opt,name=alarm,proto3,enum=etcdserverpb.AlarmType" json:"alarm,omitempty"` -} - -func (m *AlarmRequest) Reset() { *m = AlarmRequest{} } -func (m *AlarmRequest) String() string { return proto.CompactTextString(m) } -func (*AlarmRequest) ProtoMessage() {} -func (*AlarmRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{48} } - -func (m *AlarmRequest) GetAction() AlarmRequest_AlarmAction { - if m != nil { - return m.Action - } - return AlarmRequest_GET -} - -func (m *AlarmRequest) GetMemberID() uint64 { - if m != nil { - return m.MemberID - } - return 0 -} - -func (m *AlarmRequest) GetAlarm() AlarmType { - if m != nil { - return m.Alarm - } - return AlarmType_NONE -} - -type AlarmMember struct { - // memberID is the ID of the member associated with the raised alarm. - MemberID uint64 `protobuf:"varint,1,opt,name=memberID,proto3" json:"memberID,omitempty"` - // alarm is the type of alarm which has been raised. - Alarm AlarmType `protobuf:"varint,2,opt,name=alarm,proto3,enum=etcdserverpb.AlarmType" json:"alarm,omitempty"` -} - -func (m *AlarmMember) Reset() { *m = AlarmMember{} } -func (m *AlarmMember) String() string { return proto.CompactTextString(m) } -func (*AlarmMember) ProtoMessage() {} -func (*AlarmMember) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{49} } - -func (m *AlarmMember) GetMemberID() uint64 { - if m != nil { - return m.MemberID - } - return 0 -} - -func (m *AlarmMember) GetAlarm() AlarmType { - if m != nil { - return m.Alarm - } - return AlarmType_NONE -} - -type AlarmResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // alarms is a list of alarms associated with the alarm request. - Alarms []*AlarmMember `protobuf:"bytes,2,rep,name=alarms" json:"alarms,omitempty"` -} - -func (m *AlarmResponse) Reset() { *m = AlarmResponse{} } -func (m *AlarmResponse) String() string { return proto.CompactTextString(m) } -func (*AlarmResponse) ProtoMessage() {} -func (*AlarmResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{50} } - -func (m *AlarmResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *AlarmResponse) GetAlarms() []*AlarmMember { - if m != nil { - return m.Alarms - } - return nil -} - -type StatusRequest struct { -} - -func (m *StatusRequest) Reset() { *m = StatusRequest{} } -func (m *StatusRequest) String() string { return proto.CompactTextString(m) } -func (*StatusRequest) ProtoMessage() {} -func (*StatusRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{51} } - -type StatusResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // version is the cluster protocol version used by the responding member. - Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` - // dbSize is the size of the backend database, in bytes, of the responding member. - DbSize int64 `protobuf:"varint,3,opt,name=dbSize,proto3" json:"dbSize,omitempty"` - // leader is the member ID which the responding member believes is the current leader. - Leader uint64 `protobuf:"varint,4,opt,name=leader,proto3" json:"leader,omitempty"` - // raftIndex is the current raft index of the responding member. - RaftIndex uint64 `protobuf:"varint,5,opt,name=raftIndex,proto3" json:"raftIndex,omitempty"` - // raftTerm is the current raft term of the responding member. - RaftTerm uint64 `protobuf:"varint,6,opt,name=raftTerm,proto3" json:"raftTerm,omitempty"` -} - -func (m *StatusResponse) Reset() { *m = StatusResponse{} } -func (m *StatusResponse) String() string { return proto.CompactTextString(m) } -func (*StatusResponse) ProtoMessage() {} -func (*StatusResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{52} } - -func (m *StatusResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *StatusResponse) GetVersion() string { - if m != nil { - return m.Version - } - return "" -} - -func (m *StatusResponse) GetDbSize() int64 { - if m != nil { - return m.DbSize - } - return 0 -} - -func (m *StatusResponse) GetLeader() uint64 { - if m != nil { - return m.Leader - } - return 0 -} - -func (m *StatusResponse) GetRaftIndex() uint64 { - if m != nil { - return m.RaftIndex - } - return 0 -} - -func (m *StatusResponse) GetRaftTerm() uint64 { - if m != nil { - return m.RaftTerm - } - return 0 -} - -type AuthEnableRequest struct { -} - -func (m *AuthEnableRequest) Reset() { *m = AuthEnableRequest{} } -func (m *AuthEnableRequest) String() string { return proto.CompactTextString(m) } -func (*AuthEnableRequest) ProtoMessage() {} -func (*AuthEnableRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{53} } - -type AuthDisableRequest struct { -} - -func (m *AuthDisableRequest) Reset() { *m = AuthDisableRequest{} } -func (m *AuthDisableRequest) String() string { return proto.CompactTextString(m) } -func (*AuthDisableRequest) ProtoMessage() {} -func (*AuthDisableRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{54} } - -type AuthenticateRequest struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` -} - -func (m *AuthenticateRequest) Reset() { *m = AuthenticateRequest{} } -func (m *AuthenticateRequest) String() string { return proto.CompactTextString(m) } -func (*AuthenticateRequest) ProtoMessage() {} -func (*AuthenticateRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{55} } - -func (m *AuthenticateRequest) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -func (m *AuthenticateRequest) GetPassword() string { - if m != nil { - return m.Password - } - return "" -} - -type AuthUserAddRequest struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` -} - -func (m *AuthUserAddRequest) Reset() { *m = AuthUserAddRequest{} } -func (m *AuthUserAddRequest) String() string { return proto.CompactTextString(m) } -func (*AuthUserAddRequest) ProtoMessage() {} -func (*AuthUserAddRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{56} } - -func (m *AuthUserAddRequest) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -func (m *AuthUserAddRequest) GetPassword() string { - if m != nil { - return m.Password - } - return "" -} - -type AuthUserGetRequest struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` -} - -func (m *AuthUserGetRequest) Reset() { *m = AuthUserGetRequest{} } -func (m *AuthUserGetRequest) String() string { return proto.CompactTextString(m) } -func (*AuthUserGetRequest) ProtoMessage() {} -func (*AuthUserGetRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{57} } - -func (m *AuthUserGetRequest) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -type AuthUserDeleteRequest struct { - // name is the name of the user to delete. - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` -} - -func (m *AuthUserDeleteRequest) Reset() { *m = AuthUserDeleteRequest{} } -func (m *AuthUserDeleteRequest) String() string { return proto.CompactTextString(m) } -func (*AuthUserDeleteRequest) ProtoMessage() {} -func (*AuthUserDeleteRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{58} } - -func (m *AuthUserDeleteRequest) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -type AuthUserChangePasswordRequest struct { - // name is the name of the user whose password is being changed. - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - // password is the new password for the user. - Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` -} - -func (m *AuthUserChangePasswordRequest) Reset() { *m = AuthUserChangePasswordRequest{} } -func (m *AuthUserChangePasswordRequest) String() string { return proto.CompactTextString(m) } -func (*AuthUserChangePasswordRequest) ProtoMessage() {} -func (*AuthUserChangePasswordRequest) Descriptor() ([]byte, []int) { - return fileDescriptorRpc, []int{59} -} - -func (m *AuthUserChangePasswordRequest) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -func (m *AuthUserChangePasswordRequest) GetPassword() string { - if m != nil { - return m.Password - } - return "" -} - -type AuthUserGrantRoleRequest struct { - // user is the name of the user which should be granted a given role. - User string `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` - // role is the name of the role to grant to the user. - Role string `protobuf:"bytes,2,opt,name=role,proto3" json:"role,omitempty"` -} - -func (m *AuthUserGrantRoleRequest) Reset() { *m = AuthUserGrantRoleRequest{} } -func (m *AuthUserGrantRoleRequest) String() string { return proto.CompactTextString(m) } -func (*AuthUserGrantRoleRequest) ProtoMessage() {} -func (*AuthUserGrantRoleRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{60} } - -func (m *AuthUserGrantRoleRequest) GetUser() string { - if m != nil { - return m.User - } - return "" -} - -func (m *AuthUserGrantRoleRequest) GetRole() string { - if m != nil { - return m.Role - } - return "" -} - -type AuthUserRevokeRoleRequest struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Role string `protobuf:"bytes,2,opt,name=role,proto3" json:"role,omitempty"` -} - -func (m *AuthUserRevokeRoleRequest) Reset() { *m = AuthUserRevokeRoleRequest{} } -func (m *AuthUserRevokeRoleRequest) String() string { return proto.CompactTextString(m) } -func (*AuthUserRevokeRoleRequest) ProtoMessage() {} -func (*AuthUserRevokeRoleRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{61} } - -func (m *AuthUserRevokeRoleRequest) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -func (m *AuthUserRevokeRoleRequest) GetRole() string { - if m != nil { - return m.Role - } - return "" -} - -type AuthRoleAddRequest struct { - // name is the name of the role to add to the authentication system. - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` -} - -func (m *AuthRoleAddRequest) Reset() { *m = AuthRoleAddRequest{} } -func (m *AuthRoleAddRequest) String() string { return proto.CompactTextString(m) } -func (*AuthRoleAddRequest) ProtoMessage() {} -func (*AuthRoleAddRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{62} } - -func (m *AuthRoleAddRequest) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -type AuthRoleGetRequest struct { - Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` -} - -func (m *AuthRoleGetRequest) Reset() { *m = AuthRoleGetRequest{} } -func (m *AuthRoleGetRequest) String() string { return proto.CompactTextString(m) } -func (*AuthRoleGetRequest) ProtoMessage() {} -func (*AuthRoleGetRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{63} } - -func (m *AuthRoleGetRequest) GetRole() string { - if m != nil { - return m.Role - } - return "" -} - -type AuthUserListRequest struct { -} - -func (m *AuthUserListRequest) Reset() { *m = AuthUserListRequest{} } -func (m *AuthUserListRequest) String() string { return proto.CompactTextString(m) } -func (*AuthUserListRequest) ProtoMessage() {} -func (*AuthUserListRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{64} } - -type AuthRoleListRequest struct { -} - -func (m *AuthRoleListRequest) Reset() { *m = AuthRoleListRequest{} } -func (m *AuthRoleListRequest) String() string { return proto.CompactTextString(m) } -func (*AuthRoleListRequest) ProtoMessage() {} -func (*AuthRoleListRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{65} } - -type AuthRoleDeleteRequest struct { - Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` -} - -func (m *AuthRoleDeleteRequest) Reset() { *m = AuthRoleDeleteRequest{} } -func (m *AuthRoleDeleteRequest) String() string { return proto.CompactTextString(m) } -func (*AuthRoleDeleteRequest) ProtoMessage() {} -func (*AuthRoleDeleteRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{66} } - -func (m *AuthRoleDeleteRequest) GetRole() string { - if m != nil { - return m.Role - } - return "" -} - -type AuthRoleGrantPermissionRequest struct { - // name is the name of the role which will be granted the permission. - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - // perm is the permission to grant to the role. - Perm *authpb.Permission `protobuf:"bytes,2,opt,name=perm" json:"perm,omitempty"` -} - -func (m *AuthRoleGrantPermissionRequest) Reset() { *m = AuthRoleGrantPermissionRequest{} } -func (m *AuthRoleGrantPermissionRequest) String() string { return proto.CompactTextString(m) } -func (*AuthRoleGrantPermissionRequest) ProtoMessage() {} -func (*AuthRoleGrantPermissionRequest) Descriptor() ([]byte, []int) { - return fileDescriptorRpc, []int{67} -} - -func (m *AuthRoleGrantPermissionRequest) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -func (m *AuthRoleGrantPermissionRequest) GetPerm() *authpb.Permission { - if m != nil { - return m.Perm - } - return nil -} - -type AuthRoleRevokePermissionRequest struct { - Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` - Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` - RangeEnd string `protobuf:"bytes,3,opt,name=range_end,json=rangeEnd,proto3" json:"range_end,omitempty"` -} - -func (m *AuthRoleRevokePermissionRequest) Reset() { *m = AuthRoleRevokePermissionRequest{} } -func (m *AuthRoleRevokePermissionRequest) String() string { return proto.CompactTextString(m) } -func (*AuthRoleRevokePermissionRequest) ProtoMessage() {} -func (*AuthRoleRevokePermissionRequest) Descriptor() ([]byte, []int) { - return fileDescriptorRpc, []int{68} -} - -func (m *AuthRoleRevokePermissionRequest) GetRole() string { - if m != nil { - return m.Role - } - return "" -} - -func (m *AuthRoleRevokePermissionRequest) GetKey() string { - if m != nil { - return m.Key - } - return "" -} - -func (m *AuthRoleRevokePermissionRequest) GetRangeEnd() string { - if m != nil { - return m.RangeEnd - } - return "" -} - -type AuthEnableResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthEnableResponse) Reset() { *m = AuthEnableResponse{} } -func (m *AuthEnableResponse) String() string { return proto.CompactTextString(m) } -func (*AuthEnableResponse) ProtoMessage() {} -func (*AuthEnableResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{69} } - -func (m *AuthEnableResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthDisableResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthDisableResponse) Reset() { *m = AuthDisableResponse{} } -func (m *AuthDisableResponse) String() string { return proto.CompactTextString(m) } -func (*AuthDisableResponse) ProtoMessage() {} -func (*AuthDisableResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{70} } - -func (m *AuthDisableResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthenticateResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // token is an authorized token that can be used in succeeding RPCs - Token string `protobuf:"bytes,2,opt,name=token,proto3" json:"token,omitempty"` -} - -func (m *AuthenticateResponse) Reset() { *m = AuthenticateResponse{} } -func (m *AuthenticateResponse) String() string { return proto.CompactTextString(m) } -func (*AuthenticateResponse) ProtoMessage() {} -func (*AuthenticateResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{71} } - -func (m *AuthenticateResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *AuthenticateResponse) GetToken() string { - if m != nil { - return m.Token - } - return "" -} - -type AuthUserAddResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthUserAddResponse) Reset() { *m = AuthUserAddResponse{} } -func (m *AuthUserAddResponse) String() string { return proto.CompactTextString(m) } -func (*AuthUserAddResponse) ProtoMessage() {} -func (*AuthUserAddResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{72} } - -func (m *AuthUserAddResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthUserGetResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - Roles []string `protobuf:"bytes,2,rep,name=roles" json:"roles,omitempty"` -} - -func (m *AuthUserGetResponse) Reset() { *m = AuthUserGetResponse{} } -func (m *AuthUserGetResponse) String() string { return proto.CompactTextString(m) } -func (*AuthUserGetResponse) ProtoMessage() {} -func (*AuthUserGetResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{73} } - -func (m *AuthUserGetResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *AuthUserGetResponse) GetRoles() []string { - if m != nil { - return m.Roles - } - return nil -} - -type AuthUserDeleteResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthUserDeleteResponse) Reset() { *m = AuthUserDeleteResponse{} } -func (m *AuthUserDeleteResponse) String() string { return proto.CompactTextString(m) } -func (*AuthUserDeleteResponse) ProtoMessage() {} -func (*AuthUserDeleteResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{74} } - -func (m *AuthUserDeleteResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthUserChangePasswordResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthUserChangePasswordResponse) Reset() { *m = AuthUserChangePasswordResponse{} } -func (m *AuthUserChangePasswordResponse) String() string { return proto.CompactTextString(m) } -func (*AuthUserChangePasswordResponse) ProtoMessage() {} -func (*AuthUserChangePasswordResponse) Descriptor() ([]byte, []int) { - return fileDescriptorRpc, []int{75} -} - -func (m *AuthUserChangePasswordResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthUserGrantRoleResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthUserGrantRoleResponse) Reset() { *m = AuthUserGrantRoleResponse{} } -func (m *AuthUserGrantRoleResponse) String() string { return proto.CompactTextString(m) } -func (*AuthUserGrantRoleResponse) ProtoMessage() {} -func (*AuthUserGrantRoleResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{76} } - -func (m *AuthUserGrantRoleResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthUserRevokeRoleResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthUserRevokeRoleResponse) Reset() { *m = AuthUserRevokeRoleResponse{} } -func (m *AuthUserRevokeRoleResponse) String() string { return proto.CompactTextString(m) } -func (*AuthUserRevokeRoleResponse) ProtoMessage() {} -func (*AuthUserRevokeRoleResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{77} } - -func (m *AuthUserRevokeRoleResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthRoleAddResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthRoleAddResponse) Reset() { *m = AuthRoleAddResponse{} } -func (m *AuthRoleAddResponse) String() string { return proto.CompactTextString(m) } -func (*AuthRoleAddResponse) ProtoMessage() {} -func (*AuthRoleAddResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{78} } - -func (m *AuthRoleAddResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthRoleGetResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - Perm []*authpb.Permission `protobuf:"bytes,2,rep,name=perm" json:"perm,omitempty"` -} - -func (m *AuthRoleGetResponse) Reset() { *m = AuthRoleGetResponse{} } -func (m *AuthRoleGetResponse) String() string { return proto.CompactTextString(m) } -func (*AuthRoleGetResponse) ProtoMessage() {} -func (*AuthRoleGetResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{79} } - -func (m *AuthRoleGetResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *AuthRoleGetResponse) GetPerm() []*authpb.Permission { - if m != nil { - return m.Perm - } - return nil -} - -type AuthRoleListResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - Roles []string `protobuf:"bytes,2,rep,name=roles" json:"roles,omitempty"` -} - -func (m *AuthRoleListResponse) Reset() { *m = AuthRoleListResponse{} } -func (m *AuthRoleListResponse) String() string { return proto.CompactTextString(m) } -func (*AuthRoleListResponse) ProtoMessage() {} -func (*AuthRoleListResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{80} } - -func (m *AuthRoleListResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *AuthRoleListResponse) GetRoles() []string { - if m != nil { - return m.Roles - } - return nil -} - -type AuthUserListResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - Users []string `protobuf:"bytes,2,rep,name=users" json:"users,omitempty"` -} - -func (m *AuthUserListResponse) Reset() { *m = AuthUserListResponse{} } -func (m *AuthUserListResponse) String() string { return proto.CompactTextString(m) } -func (*AuthUserListResponse) ProtoMessage() {} -func (*AuthUserListResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{81} } - -func (m *AuthUserListResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *AuthUserListResponse) GetUsers() []string { - if m != nil { - return m.Users - } - return nil -} - -type AuthRoleDeleteResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthRoleDeleteResponse) Reset() { *m = AuthRoleDeleteResponse{} } -func (m *AuthRoleDeleteResponse) String() string { return proto.CompactTextString(m) } -func (*AuthRoleDeleteResponse) ProtoMessage() {} -func (*AuthRoleDeleteResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{82} } - -func (m *AuthRoleDeleteResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthRoleGrantPermissionResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthRoleGrantPermissionResponse) Reset() { *m = AuthRoleGrantPermissionResponse{} } -func (m *AuthRoleGrantPermissionResponse) String() string { return proto.CompactTextString(m) } -func (*AuthRoleGrantPermissionResponse) ProtoMessage() {} -func (*AuthRoleGrantPermissionResponse) Descriptor() ([]byte, []int) { - return fileDescriptorRpc, []int{83} -} - -func (m *AuthRoleGrantPermissionResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthRoleRevokePermissionResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthRoleRevokePermissionResponse) Reset() { *m = AuthRoleRevokePermissionResponse{} } -func (m *AuthRoleRevokePermissionResponse) String() string { return proto.CompactTextString(m) } -func (*AuthRoleRevokePermissionResponse) ProtoMessage() {} -func (*AuthRoleRevokePermissionResponse) Descriptor() ([]byte, []int) { - return fileDescriptorRpc, []int{84} -} - -func (m *AuthRoleRevokePermissionResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func init() { - proto.RegisterType((*ResponseHeader)(nil), "etcdserverpb.ResponseHeader") - proto.RegisterType((*RangeRequest)(nil), "etcdserverpb.RangeRequest") - proto.RegisterType((*RangeResponse)(nil), "etcdserverpb.RangeResponse") - proto.RegisterType((*PutRequest)(nil), "etcdserverpb.PutRequest") - proto.RegisterType((*PutResponse)(nil), "etcdserverpb.PutResponse") - proto.RegisterType((*DeleteRangeRequest)(nil), "etcdserverpb.DeleteRangeRequest") - proto.RegisterType((*DeleteRangeResponse)(nil), "etcdserverpb.DeleteRangeResponse") - proto.RegisterType((*RequestOp)(nil), "etcdserverpb.RequestOp") - proto.RegisterType((*ResponseOp)(nil), "etcdserverpb.ResponseOp") - proto.RegisterType((*Compare)(nil), "etcdserverpb.Compare") - proto.RegisterType((*TxnRequest)(nil), "etcdserverpb.TxnRequest") - proto.RegisterType((*TxnResponse)(nil), "etcdserverpb.TxnResponse") - proto.RegisterType((*CompactionRequest)(nil), "etcdserverpb.CompactionRequest") - proto.RegisterType((*CompactionResponse)(nil), "etcdserverpb.CompactionResponse") - proto.RegisterType((*HashRequest)(nil), "etcdserverpb.HashRequest") - proto.RegisterType((*HashKVRequest)(nil), "etcdserverpb.HashKVRequest") - proto.RegisterType((*HashKVResponse)(nil), "etcdserverpb.HashKVResponse") - proto.RegisterType((*HashResponse)(nil), "etcdserverpb.HashResponse") - proto.RegisterType((*SnapshotRequest)(nil), "etcdserverpb.SnapshotRequest") - proto.RegisterType((*SnapshotResponse)(nil), "etcdserverpb.SnapshotResponse") - proto.RegisterType((*WatchRequest)(nil), "etcdserverpb.WatchRequest") - proto.RegisterType((*WatchCreateRequest)(nil), "etcdserverpb.WatchCreateRequest") - proto.RegisterType((*WatchCancelRequest)(nil), "etcdserverpb.WatchCancelRequest") - proto.RegisterType((*WatchResponse)(nil), "etcdserverpb.WatchResponse") - proto.RegisterType((*LeaseGrantRequest)(nil), "etcdserverpb.LeaseGrantRequest") - proto.RegisterType((*LeaseGrantResponse)(nil), "etcdserverpb.LeaseGrantResponse") - proto.RegisterType((*LeaseRevokeRequest)(nil), "etcdserverpb.LeaseRevokeRequest") - proto.RegisterType((*LeaseRevokeResponse)(nil), "etcdserverpb.LeaseRevokeResponse") - proto.RegisterType((*LeaseKeepAliveRequest)(nil), "etcdserverpb.LeaseKeepAliveRequest") - proto.RegisterType((*LeaseKeepAliveResponse)(nil), "etcdserverpb.LeaseKeepAliveResponse") - proto.RegisterType((*LeaseTimeToLiveRequest)(nil), "etcdserverpb.LeaseTimeToLiveRequest") - proto.RegisterType((*LeaseTimeToLiveResponse)(nil), "etcdserverpb.LeaseTimeToLiveResponse") - proto.RegisterType((*LeaseLeasesRequest)(nil), "etcdserverpb.LeaseLeasesRequest") - proto.RegisterType((*LeaseStatus)(nil), "etcdserverpb.LeaseStatus") - proto.RegisterType((*LeaseLeasesResponse)(nil), "etcdserverpb.LeaseLeasesResponse") - proto.RegisterType((*Member)(nil), "etcdserverpb.Member") - proto.RegisterType((*MemberAddRequest)(nil), "etcdserverpb.MemberAddRequest") - proto.RegisterType((*MemberAddResponse)(nil), "etcdserverpb.MemberAddResponse") - proto.RegisterType((*MemberRemoveRequest)(nil), "etcdserverpb.MemberRemoveRequest") - proto.RegisterType((*MemberRemoveResponse)(nil), "etcdserverpb.MemberRemoveResponse") - proto.RegisterType((*MemberUpdateRequest)(nil), "etcdserverpb.MemberUpdateRequest") - proto.RegisterType((*MemberUpdateResponse)(nil), "etcdserverpb.MemberUpdateResponse") - proto.RegisterType((*MemberListRequest)(nil), "etcdserverpb.MemberListRequest") - proto.RegisterType((*MemberListResponse)(nil), "etcdserverpb.MemberListResponse") - proto.RegisterType((*DefragmentRequest)(nil), "etcdserverpb.DefragmentRequest") - proto.RegisterType((*DefragmentResponse)(nil), "etcdserverpb.DefragmentResponse") - proto.RegisterType((*MoveLeaderRequest)(nil), "etcdserverpb.MoveLeaderRequest") - proto.RegisterType((*MoveLeaderResponse)(nil), "etcdserverpb.MoveLeaderResponse") - proto.RegisterType((*AlarmRequest)(nil), "etcdserverpb.AlarmRequest") - proto.RegisterType((*AlarmMember)(nil), "etcdserverpb.AlarmMember") - proto.RegisterType((*AlarmResponse)(nil), "etcdserverpb.AlarmResponse") - proto.RegisterType((*StatusRequest)(nil), "etcdserverpb.StatusRequest") - proto.RegisterType((*StatusResponse)(nil), "etcdserverpb.StatusResponse") - proto.RegisterType((*AuthEnableRequest)(nil), "etcdserverpb.AuthEnableRequest") - proto.RegisterType((*AuthDisableRequest)(nil), "etcdserverpb.AuthDisableRequest") - proto.RegisterType((*AuthenticateRequest)(nil), "etcdserverpb.AuthenticateRequest") - proto.RegisterType((*AuthUserAddRequest)(nil), "etcdserverpb.AuthUserAddRequest") - proto.RegisterType((*AuthUserGetRequest)(nil), "etcdserverpb.AuthUserGetRequest") - proto.RegisterType((*AuthUserDeleteRequest)(nil), "etcdserverpb.AuthUserDeleteRequest") - proto.RegisterType((*AuthUserChangePasswordRequest)(nil), "etcdserverpb.AuthUserChangePasswordRequest") - proto.RegisterType((*AuthUserGrantRoleRequest)(nil), "etcdserverpb.AuthUserGrantRoleRequest") - proto.RegisterType((*AuthUserRevokeRoleRequest)(nil), "etcdserverpb.AuthUserRevokeRoleRequest") - proto.RegisterType((*AuthRoleAddRequest)(nil), "etcdserverpb.AuthRoleAddRequest") - proto.RegisterType((*AuthRoleGetRequest)(nil), "etcdserverpb.AuthRoleGetRequest") - proto.RegisterType((*AuthUserListRequest)(nil), "etcdserverpb.AuthUserListRequest") - proto.RegisterType((*AuthRoleListRequest)(nil), "etcdserverpb.AuthRoleListRequest") - proto.RegisterType((*AuthRoleDeleteRequest)(nil), "etcdserverpb.AuthRoleDeleteRequest") - proto.RegisterType((*AuthRoleGrantPermissionRequest)(nil), "etcdserverpb.AuthRoleGrantPermissionRequest") - proto.RegisterType((*AuthRoleRevokePermissionRequest)(nil), "etcdserverpb.AuthRoleRevokePermissionRequest") - proto.RegisterType((*AuthEnableResponse)(nil), "etcdserverpb.AuthEnableResponse") - proto.RegisterType((*AuthDisableResponse)(nil), "etcdserverpb.AuthDisableResponse") - proto.RegisterType((*AuthenticateResponse)(nil), "etcdserverpb.AuthenticateResponse") - proto.RegisterType((*AuthUserAddResponse)(nil), "etcdserverpb.AuthUserAddResponse") - proto.RegisterType((*AuthUserGetResponse)(nil), "etcdserverpb.AuthUserGetResponse") - proto.RegisterType((*AuthUserDeleteResponse)(nil), "etcdserverpb.AuthUserDeleteResponse") - proto.RegisterType((*AuthUserChangePasswordResponse)(nil), "etcdserverpb.AuthUserChangePasswordResponse") - proto.RegisterType((*AuthUserGrantRoleResponse)(nil), "etcdserverpb.AuthUserGrantRoleResponse") - proto.RegisterType((*AuthUserRevokeRoleResponse)(nil), "etcdserverpb.AuthUserRevokeRoleResponse") - proto.RegisterType((*AuthRoleAddResponse)(nil), "etcdserverpb.AuthRoleAddResponse") - proto.RegisterType((*AuthRoleGetResponse)(nil), "etcdserverpb.AuthRoleGetResponse") - proto.RegisterType((*AuthRoleListResponse)(nil), "etcdserverpb.AuthRoleListResponse") - proto.RegisterType((*AuthUserListResponse)(nil), "etcdserverpb.AuthUserListResponse") - proto.RegisterType((*AuthRoleDeleteResponse)(nil), "etcdserverpb.AuthRoleDeleteResponse") - proto.RegisterType((*AuthRoleGrantPermissionResponse)(nil), "etcdserverpb.AuthRoleGrantPermissionResponse") - proto.RegisterType((*AuthRoleRevokePermissionResponse)(nil), "etcdserverpb.AuthRoleRevokePermissionResponse") - proto.RegisterEnum("etcdserverpb.AlarmType", AlarmType_name, AlarmType_value) - proto.RegisterEnum("etcdserverpb.RangeRequest_SortOrder", RangeRequest_SortOrder_name, RangeRequest_SortOrder_value) - proto.RegisterEnum("etcdserverpb.RangeRequest_SortTarget", RangeRequest_SortTarget_name, RangeRequest_SortTarget_value) - proto.RegisterEnum("etcdserverpb.Compare_CompareResult", Compare_CompareResult_name, Compare_CompareResult_value) - proto.RegisterEnum("etcdserverpb.Compare_CompareTarget", Compare_CompareTarget_name, Compare_CompareTarget_value) - proto.RegisterEnum("etcdserverpb.WatchCreateRequest_FilterType", WatchCreateRequest_FilterType_name, WatchCreateRequest_FilterType_value) - proto.RegisterEnum("etcdserverpb.AlarmRequest_AlarmAction", AlarmRequest_AlarmAction_name, AlarmRequest_AlarmAction_value) -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// Client API for KV service - -type KVClient interface { - // Range gets the keys in the range from the key-value store. - Range(ctx context.Context, in *RangeRequest, opts ...grpc.CallOption) (*RangeResponse, error) - // Put puts the given key into the key-value store. - // A put request increments the revision of the key-value store - // and generates one event in the event history. - Put(ctx context.Context, in *PutRequest, opts ...grpc.CallOption) (*PutResponse, error) - // DeleteRange deletes the given range from the key-value store. - // A delete request increments the revision of the key-value store - // and generates a delete event in the event history for every deleted key. - DeleteRange(ctx context.Context, in *DeleteRangeRequest, opts ...grpc.CallOption) (*DeleteRangeResponse, error) - // Txn processes multiple requests in a single transaction. - // A txn request increments the revision of the key-value store - // and generates events with the same revision for every completed request. - // It is not allowed to modify the same key several times within one txn. - Txn(ctx context.Context, in *TxnRequest, opts ...grpc.CallOption) (*TxnResponse, error) - // Compact compacts the event history in the etcd key-value store. The key-value - // store should be periodically compacted or the event history will continue to grow - // indefinitely. - Compact(ctx context.Context, in *CompactionRequest, opts ...grpc.CallOption) (*CompactionResponse, error) -} - -type kVClient struct { - cc *grpc.ClientConn -} - -func NewKVClient(cc *grpc.ClientConn) KVClient { - return &kVClient{cc} -} - -func (c *kVClient) Range(ctx context.Context, in *RangeRequest, opts ...grpc.CallOption) (*RangeResponse, error) { - out := new(RangeResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.KV/Range", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *kVClient) Put(ctx context.Context, in *PutRequest, opts ...grpc.CallOption) (*PutResponse, error) { - out := new(PutResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.KV/Put", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *kVClient) DeleteRange(ctx context.Context, in *DeleteRangeRequest, opts ...grpc.CallOption) (*DeleteRangeResponse, error) { - out := new(DeleteRangeResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.KV/DeleteRange", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *kVClient) Txn(ctx context.Context, in *TxnRequest, opts ...grpc.CallOption) (*TxnResponse, error) { - out := new(TxnResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.KV/Txn", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *kVClient) Compact(ctx context.Context, in *CompactionRequest, opts ...grpc.CallOption) (*CompactionResponse, error) { - out := new(CompactionResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.KV/Compact", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for KV service - -type KVServer interface { - // Range gets the keys in the range from the key-value store. - Range(context.Context, *RangeRequest) (*RangeResponse, error) - // Put puts the given key into the key-value store. - // A put request increments the revision of the key-value store - // and generates one event in the event history. - Put(context.Context, *PutRequest) (*PutResponse, error) - // DeleteRange deletes the given range from the key-value store. - // A delete request increments the revision of the key-value store - // and generates a delete event in the event history for every deleted key. - DeleteRange(context.Context, *DeleteRangeRequest) (*DeleteRangeResponse, error) - // Txn processes multiple requests in a single transaction. - // A txn request increments the revision of the key-value store - // and generates events with the same revision for every completed request. - // It is not allowed to modify the same key several times within one txn. - Txn(context.Context, *TxnRequest) (*TxnResponse, error) - // Compact compacts the event history in the etcd key-value store. The key-value - // store should be periodically compacted or the event history will continue to grow - // indefinitely. - Compact(context.Context, *CompactionRequest) (*CompactionResponse, error) -} - -func RegisterKVServer(s *grpc.Server, srv KVServer) { - s.RegisterService(&_KV_serviceDesc, srv) -} - -func _KV_Range_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(RangeRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(KVServer).Range(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.KV/Range", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(KVServer).Range(ctx, req.(*RangeRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _KV_Put_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(PutRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(KVServer).Put(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.KV/Put", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(KVServer).Put(ctx, req.(*PutRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _KV_DeleteRange_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(DeleteRangeRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(KVServer).DeleteRange(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.KV/DeleteRange", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(KVServer).DeleteRange(ctx, req.(*DeleteRangeRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _KV_Txn_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(TxnRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(KVServer).Txn(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.KV/Txn", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(KVServer).Txn(ctx, req.(*TxnRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _KV_Compact_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(CompactionRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(KVServer).Compact(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.KV/Compact", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(KVServer).Compact(ctx, req.(*CompactionRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _KV_serviceDesc = grpc.ServiceDesc{ - ServiceName: "etcdserverpb.KV", - HandlerType: (*KVServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Range", - Handler: _KV_Range_Handler, - }, - { - MethodName: "Put", - Handler: _KV_Put_Handler, - }, - { - MethodName: "DeleteRange", - Handler: _KV_DeleteRange_Handler, - }, - { - MethodName: "Txn", - Handler: _KV_Txn_Handler, - }, - { - MethodName: "Compact", - Handler: _KV_Compact_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "rpc.proto", -} - -// Client API for Watch service - -type WatchClient interface { - // Watch watches for events happening or that have happened. Both input and output - // are streams; the input stream is for creating and canceling watchers and the output - // stream sends events. One watch RPC can watch on multiple key ranges, streaming events - // for several watches at once. The entire event history can be watched starting from the - // last compaction revision. - Watch(ctx context.Context, opts ...grpc.CallOption) (Watch_WatchClient, error) -} - -type watchClient struct { - cc *grpc.ClientConn -} - -func NewWatchClient(cc *grpc.ClientConn) WatchClient { - return &watchClient{cc} -} - -func (c *watchClient) Watch(ctx context.Context, opts ...grpc.CallOption) (Watch_WatchClient, error) { - stream, err := grpc.NewClientStream(ctx, &_Watch_serviceDesc.Streams[0], c.cc, "/etcdserverpb.Watch/Watch", opts...) - if err != nil { - return nil, err - } - x := &watchWatchClient{stream} - return x, nil -} - -type Watch_WatchClient interface { - Send(*WatchRequest) error - Recv() (*WatchResponse, error) - grpc.ClientStream -} - -type watchWatchClient struct { - grpc.ClientStream -} - -func (x *watchWatchClient) Send(m *WatchRequest) error { - return x.ClientStream.SendMsg(m) -} - -func (x *watchWatchClient) Recv() (*WatchResponse, error) { - m := new(WatchResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -// Server API for Watch service - -type WatchServer interface { - // Watch watches for events happening or that have happened. Both input and output - // are streams; the input stream is for creating and canceling watchers and the output - // stream sends events. One watch RPC can watch on multiple key ranges, streaming events - // for several watches at once. The entire event history can be watched starting from the - // last compaction revision. - Watch(Watch_WatchServer) error -} - -func RegisterWatchServer(s *grpc.Server, srv WatchServer) { - s.RegisterService(&_Watch_serviceDesc, srv) -} - -func _Watch_Watch_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(WatchServer).Watch(&watchWatchServer{stream}) -} - -type Watch_WatchServer interface { - Send(*WatchResponse) error - Recv() (*WatchRequest, error) - grpc.ServerStream -} - -type watchWatchServer struct { - grpc.ServerStream -} - -func (x *watchWatchServer) Send(m *WatchResponse) error { - return x.ServerStream.SendMsg(m) -} - -func (x *watchWatchServer) Recv() (*WatchRequest, error) { - m := new(WatchRequest) - if err := x.ServerStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -var _Watch_serviceDesc = grpc.ServiceDesc{ - ServiceName: "etcdserverpb.Watch", - HandlerType: (*WatchServer)(nil), - Methods: []grpc.MethodDesc{}, - Streams: []grpc.StreamDesc{ - { - StreamName: "Watch", - Handler: _Watch_Watch_Handler, - ServerStreams: true, - ClientStreams: true, - }, - }, - Metadata: "rpc.proto", -} - -// Client API for Lease service - -type LeaseClient interface { - // LeaseGrant creates a lease which expires if the server does not receive a keepAlive - // within a given time to live period. All keys attached to the lease will be expired and - // deleted if the lease expires. Each expired key generates a delete event in the event history. - LeaseGrant(ctx context.Context, in *LeaseGrantRequest, opts ...grpc.CallOption) (*LeaseGrantResponse, error) - // LeaseRevoke revokes a lease. All keys attached to the lease will expire and be deleted. - LeaseRevoke(ctx context.Context, in *LeaseRevokeRequest, opts ...grpc.CallOption) (*LeaseRevokeResponse, error) - // LeaseKeepAlive keeps the lease alive by streaming keep alive requests from the client - // to the server and streaming keep alive responses from the server to the client. - LeaseKeepAlive(ctx context.Context, opts ...grpc.CallOption) (Lease_LeaseKeepAliveClient, error) - // LeaseTimeToLive retrieves lease information. - LeaseTimeToLive(ctx context.Context, in *LeaseTimeToLiveRequest, opts ...grpc.CallOption) (*LeaseTimeToLiveResponse, error) - // LeaseLeases lists all existing leases. - LeaseLeases(ctx context.Context, in *LeaseLeasesRequest, opts ...grpc.CallOption) (*LeaseLeasesResponse, error) -} - -type leaseClient struct { - cc *grpc.ClientConn -} - -func NewLeaseClient(cc *grpc.ClientConn) LeaseClient { - return &leaseClient{cc} -} - -func (c *leaseClient) LeaseGrant(ctx context.Context, in *LeaseGrantRequest, opts ...grpc.CallOption) (*LeaseGrantResponse, error) { - out := new(LeaseGrantResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Lease/LeaseGrant", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *leaseClient) LeaseRevoke(ctx context.Context, in *LeaseRevokeRequest, opts ...grpc.CallOption) (*LeaseRevokeResponse, error) { - out := new(LeaseRevokeResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Lease/LeaseRevoke", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *leaseClient) LeaseKeepAlive(ctx context.Context, opts ...grpc.CallOption) (Lease_LeaseKeepAliveClient, error) { - stream, err := grpc.NewClientStream(ctx, &_Lease_serviceDesc.Streams[0], c.cc, "/etcdserverpb.Lease/LeaseKeepAlive", opts...) - if err != nil { - return nil, err - } - x := &leaseLeaseKeepAliveClient{stream} - return x, nil -} - -type Lease_LeaseKeepAliveClient interface { - Send(*LeaseKeepAliveRequest) error - Recv() (*LeaseKeepAliveResponse, error) - grpc.ClientStream -} - -type leaseLeaseKeepAliveClient struct { - grpc.ClientStream -} - -func (x *leaseLeaseKeepAliveClient) Send(m *LeaseKeepAliveRequest) error { - return x.ClientStream.SendMsg(m) -} - -func (x *leaseLeaseKeepAliveClient) Recv() (*LeaseKeepAliveResponse, error) { - m := new(LeaseKeepAliveResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *leaseClient) LeaseTimeToLive(ctx context.Context, in *LeaseTimeToLiveRequest, opts ...grpc.CallOption) (*LeaseTimeToLiveResponse, error) { - out := new(LeaseTimeToLiveResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Lease/LeaseTimeToLive", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *leaseClient) LeaseLeases(ctx context.Context, in *LeaseLeasesRequest, opts ...grpc.CallOption) (*LeaseLeasesResponse, error) { - out := new(LeaseLeasesResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Lease/LeaseLeases", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for Lease service - -type LeaseServer interface { - // LeaseGrant creates a lease which expires if the server does not receive a keepAlive - // within a given time to live period. All keys attached to the lease will be expired and - // deleted if the lease expires. Each expired key generates a delete event in the event history. - LeaseGrant(context.Context, *LeaseGrantRequest) (*LeaseGrantResponse, error) - // LeaseRevoke revokes a lease. All keys attached to the lease will expire and be deleted. - LeaseRevoke(context.Context, *LeaseRevokeRequest) (*LeaseRevokeResponse, error) - // LeaseKeepAlive keeps the lease alive by streaming keep alive requests from the client - // to the server and streaming keep alive responses from the server to the client. - LeaseKeepAlive(Lease_LeaseKeepAliveServer) error - // LeaseTimeToLive retrieves lease information. - LeaseTimeToLive(context.Context, *LeaseTimeToLiveRequest) (*LeaseTimeToLiveResponse, error) - // LeaseLeases lists all existing leases. - LeaseLeases(context.Context, *LeaseLeasesRequest) (*LeaseLeasesResponse, error) -} - -func RegisterLeaseServer(s *grpc.Server, srv LeaseServer) { - s.RegisterService(&_Lease_serviceDesc, srv) -} - -func _Lease_LeaseGrant_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(LeaseGrantRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(LeaseServer).LeaseGrant(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Lease/LeaseGrant", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(LeaseServer).LeaseGrant(ctx, req.(*LeaseGrantRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Lease_LeaseRevoke_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(LeaseRevokeRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(LeaseServer).LeaseRevoke(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Lease/LeaseRevoke", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(LeaseServer).LeaseRevoke(ctx, req.(*LeaseRevokeRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Lease_LeaseKeepAlive_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(LeaseServer).LeaseKeepAlive(&leaseLeaseKeepAliveServer{stream}) -} - -type Lease_LeaseKeepAliveServer interface { - Send(*LeaseKeepAliveResponse) error - Recv() (*LeaseKeepAliveRequest, error) - grpc.ServerStream -} - -type leaseLeaseKeepAliveServer struct { - grpc.ServerStream -} - -func (x *leaseLeaseKeepAliveServer) Send(m *LeaseKeepAliveResponse) error { - return x.ServerStream.SendMsg(m) -} - -func (x *leaseLeaseKeepAliveServer) Recv() (*LeaseKeepAliveRequest, error) { - m := new(LeaseKeepAliveRequest) - if err := x.ServerStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func _Lease_LeaseTimeToLive_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(LeaseTimeToLiveRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(LeaseServer).LeaseTimeToLive(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Lease/LeaseTimeToLive", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(LeaseServer).LeaseTimeToLive(ctx, req.(*LeaseTimeToLiveRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Lease_LeaseLeases_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(LeaseLeasesRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(LeaseServer).LeaseLeases(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Lease/LeaseLeases", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(LeaseServer).LeaseLeases(ctx, req.(*LeaseLeasesRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Lease_serviceDesc = grpc.ServiceDesc{ - ServiceName: "etcdserverpb.Lease", - HandlerType: (*LeaseServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "LeaseGrant", - Handler: _Lease_LeaseGrant_Handler, - }, - { - MethodName: "LeaseRevoke", - Handler: _Lease_LeaseRevoke_Handler, - }, - { - MethodName: "LeaseTimeToLive", - Handler: _Lease_LeaseTimeToLive_Handler, - }, - { - MethodName: "LeaseLeases", - Handler: _Lease_LeaseLeases_Handler, - }, - }, - Streams: []grpc.StreamDesc{ - { - StreamName: "LeaseKeepAlive", - Handler: _Lease_LeaseKeepAlive_Handler, - ServerStreams: true, - ClientStreams: true, - }, - }, - Metadata: "rpc.proto", -} - -// Client API for Cluster service - -type ClusterClient interface { - // MemberAdd adds a member into the cluster. - MemberAdd(ctx context.Context, in *MemberAddRequest, opts ...grpc.CallOption) (*MemberAddResponse, error) - // MemberRemove removes an existing member from the cluster. - MemberRemove(ctx context.Context, in *MemberRemoveRequest, opts ...grpc.CallOption) (*MemberRemoveResponse, error) - // MemberUpdate updates the member configuration. - MemberUpdate(ctx context.Context, in *MemberUpdateRequest, opts ...grpc.CallOption) (*MemberUpdateResponse, error) - // MemberList lists all the members in the cluster. - MemberList(ctx context.Context, in *MemberListRequest, opts ...grpc.CallOption) (*MemberListResponse, error) -} - -type clusterClient struct { - cc *grpc.ClientConn -} - -func NewClusterClient(cc *grpc.ClientConn) ClusterClient { - return &clusterClient{cc} -} - -func (c *clusterClient) MemberAdd(ctx context.Context, in *MemberAddRequest, opts ...grpc.CallOption) (*MemberAddResponse, error) { - out := new(MemberAddResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Cluster/MemberAdd", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *clusterClient) MemberRemove(ctx context.Context, in *MemberRemoveRequest, opts ...grpc.CallOption) (*MemberRemoveResponse, error) { - out := new(MemberRemoveResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Cluster/MemberRemove", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *clusterClient) MemberUpdate(ctx context.Context, in *MemberUpdateRequest, opts ...grpc.CallOption) (*MemberUpdateResponse, error) { - out := new(MemberUpdateResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Cluster/MemberUpdate", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *clusterClient) MemberList(ctx context.Context, in *MemberListRequest, opts ...grpc.CallOption) (*MemberListResponse, error) { - out := new(MemberListResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Cluster/MemberList", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for Cluster service - -type ClusterServer interface { - // MemberAdd adds a member into the cluster. - MemberAdd(context.Context, *MemberAddRequest) (*MemberAddResponse, error) - // MemberRemove removes an existing member from the cluster. - MemberRemove(context.Context, *MemberRemoveRequest) (*MemberRemoveResponse, error) - // MemberUpdate updates the member configuration. - MemberUpdate(context.Context, *MemberUpdateRequest) (*MemberUpdateResponse, error) - // MemberList lists all the members in the cluster. - MemberList(context.Context, *MemberListRequest) (*MemberListResponse, error) -} - -func RegisterClusterServer(s *grpc.Server, srv ClusterServer) { - s.RegisterService(&_Cluster_serviceDesc, srv) -} - -func _Cluster_MemberAdd_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MemberAddRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ClusterServer).MemberAdd(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Cluster/MemberAdd", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ClusterServer).MemberAdd(ctx, req.(*MemberAddRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Cluster_MemberRemove_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MemberRemoveRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ClusterServer).MemberRemove(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Cluster/MemberRemove", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ClusterServer).MemberRemove(ctx, req.(*MemberRemoveRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Cluster_MemberUpdate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MemberUpdateRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ClusterServer).MemberUpdate(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Cluster/MemberUpdate", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ClusterServer).MemberUpdate(ctx, req.(*MemberUpdateRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Cluster_MemberList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MemberListRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ClusterServer).MemberList(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Cluster/MemberList", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ClusterServer).MemberList(ctx, req.(*MemberListRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Cluster_serviceDesc = grpc.ServiceDesc{ - ServiceName: "etcdserverpb.Cluster", - HandlerType: (*ClusterServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "MemberAdd", - Handler: _Cluster_MemberAdd_Handler, - }, - { - MethodName: "MemberRemove", - Handler: _Cluster_MemberRemove_Handler, - }, - { - MethodName: "MemberUpdate", - Handler: _Cluster_MemberUpdate_Handler, - }, - { - MethodName: "MemberList", - Handler: _Cluster_MemberList_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "rpc.proto", -} - -// Client API for Maintenance service - -type MaintenanceClient interface { - // Alarm activates, deactivates, and queries alarms regarding cluster health. - Alarm(ctx context.Context, in *AlarmRequest, opts ...grpc.CallOption) (*AlarmResponse, error) - // Status gets the status of the member. - Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*StatusResponse, error) - // Defragment defragments a member's backend database to recover storage space. - Defragment(ctx context.Context, in *DefragmentRequest, opts ...grpc.CallOption) (*DefragmentResponse, error) - // Hash computes the hash of the KV's backend. - // This is designed for testing; do not use this in production when there - // are ongoing transactions. - Hash(ctx context.Context, in *HashRequest, opts ...grpc.CallOption) (*HashResponse, error) - // HashKV computes the hash of all MVCC keys up to a given revision. - HashKV(ctx context.Context, in *HashKVRequest, opts ...grpc.CallOption) (*HashKVResponse, error) - // Snapshot sends a snapshot of the entire backend from a member over a stream to a client. - Snapshot(ctx context.Context, in *SnapshotRequest, opts ...grpc.CallOption) (Maintenance_SnapshotClient, error) - // MoveLeader requests current leader node to transfer its leadership to transferee. - MoveLeader(ctx context.Context, in *MoveLeaderRequest, opts ...grpc.CallOption) (*MoveLeaderResponse, error) -} - -type maintenanceClient struct { - cc *grpc.ClientConn -} - -func NewMaintenanceClient(cc *grpc.ClientConn) MaintenanceClient { - return &maintenanceClient{cc} -} - -func (c *maintenanceClient) Alarm(ctx context.Context, in *AlarmRequest, opts ...grpc.CallOption) (*AlarmResponse, error) { - out := new(AlarmResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Maintenance/Alarm", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *maintenanceClient) Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*StatusResponse, error) { - out := new(StatusResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Maintenance/Status", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *maintenanceClient) Defragment(ctx context.Context, in *DefragmentRequest, opts ...grpc.CallOption) (*DefragmentResponse, error) { - out := new(DefragmentResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Maintenance/Defragment", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *maintenanceClient) Hash(ctx context.Context, in *HashRequest, opts ...grpc.CallOption) (*HashResponse, error) { - out := new(HashResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Maintenance/Hash", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *maintenanceClient) HashKV(ctx context.Context, in *HashKVRequest, opts ...grpc.CallOption) (*HashKVResponse, error) { - out := new(HashKVResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Maintenance/HashKV", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *maintenanceClient) Snapshot(ctx context.Context, in *SnapshotRequest, opts ...grpc.CallOption) (Maintenance_SnapshotClient, error) { - stream, err := grpc.NewClientStream(ctx, &_Maintenance_serviceDesc.Streams[0], c.cc, "/etcdserverpb.Maintenance/Snapshot", opts...) - if err != nil { - return nil, err - } - x := &maintenanceSnapshotClient{stream} - if err := x.ClientStream.SendMsg(in); err != nil { - return nil, err - } - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - return x, nil -} - -type Maintenance_SnapshotClient interface { - Recv() (*SnapshotResponse, error) - grpc.ClientStream -} - -type maintenanceSnapshotClient struct { - grpc.ClientStream -} - -func (x *maintenanceSnapshotClient) Recv() (*SnapshotResponse, error) { - m := new(SnapshotResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *maintenanceClient) MoveLeader(ctx context.Context, in *MoveLeaderRequest, opts ...grpc.CallOption) (*MoveLeaderResponse, error) { - out := new(MoveLeaderResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Maintenance/MoveLeader", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for Maintenance service - -type MaintenanceServer interface { - // Alarm activates, deactivates, and queries alarms regarding cluster health. - Alarm(context.Context, *AlarmRequest) (*AlarmResponse, error) - // Status gets the status of the member. - Status(context.Context, *StatusRequest) (*StatusResponse, error) - // Defragment defragments a member's backend database to recover storage space. - Defragment(context.Context, *DefragmentRequest) (*DefragmentResponse, error) - // Hash computes the hash of the KV's backend. - // This is designed for testing; do not use this in production when there - // are ongoing transactions. - Hash(context.Context, *HashRequest) (*HashResponse, error) - // HashKV computes the hash of all MVCC keys up to a given revision. - HashKV(context.Context, *HashKVRequest) (*HashKVResponse, error) - // Snapshot sends a snapshot of the entire backend from a member over a stream to a client. - Snapshot(*SnapshotRequest, Maintenance_SnapshotServer) error - // MoveLeader requests current leader node to transfer its leadership to transferee. - MoveLeader(context.Context, *MoveLeaderRequest) (*MoveLeaderResponse, error) -} - -func RegisterMaintenanceServer(s *grpc.Server, srv MaintenanceServer) { - s.RegisterService(&_Maintenance_serviceDesc, srv) -} - -func _Maintenance_Alarm_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AlarmRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MaintenanceServer).Alarm(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Maintenance/Alarm", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MaintenanceServer).Alarm(ctx, req.(*AlarmRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Maintenance_Status_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(StatusRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MaintenanceServer).Status(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Maintenance/Status", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MaintenanceServer).Status(ctx, req.(*StatusRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Maintenance_Defragment_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(DefragmentRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MaintenanceServer).Defragment(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Maintenance/Defragment", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MaintenanceServer).Defragment(ctx, req.(*DefragmentRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Maintenance_Hash_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(HashRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MaintenanceServer).Hash(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Maintenance/Hash", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MaintenanceServer).Hash(ctx, req.(*HashRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Maintenance_HashKV_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(HashKVRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MaintenanceServer).HashKV(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Maintenance/HashKV", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MaintenanceServer).HashKV(ctx, req.(*HashKVRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Maintenance_Snapshot_Handler(srv interface{}, stream grpc.ServerStream) error { - m := new(SnapshotRequest) - if err := stream.RecvMsg(m); err != nil { - return err - } - return srv.(MaintenanceServer).Snapshot(m, &maintenanceSnapshotServer{stream}) -} - -type Maintenance_SnapshotServer interface { - Send(*SnapshotResponse) error - grpc.ServerStream -} - -type maintenanceSnapshotServer struct { - grpc.ServerStream -} - -func (x *maintenanceSnapshotServer) Send(m *SnapshotResponse) error { - return x.ServerStream.SendMsg(m) -} - -func _Maintenance_MoveLeader_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MoveLeaderRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MaintenanceServer).MoveLeader(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Maintenance/MoveLeader", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MaintenanceServer).MoveLeader(ctx, req.(*MoveLeaderRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Maintenance_serviceDesc = grpc.ServiceDesc{ - ServiceName: "etcdserverpb.Maintenance", - HandlerType: (*MaintenanceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Alarm", - Handler: _Maintenance_Alarm_Handler, - }, - { - MethodName: "Status", - Handler: _Maintenance_Status_Handler, - }, - { - MethodName: "Defragment", - Handler: _Maintenance_Defragment_Handler, - }, - { - MethodName: "Hash", - Handler: _Maintenance_Hash_Handler, - }, - { - MethodName: "HashKV", - Handler: _Maintenance_HashKV_Handler, - }, - { - MethodName: "MoveLeader", - Handler: _Maintenance_MoveLeader_Handler, - }, - }, - Streams: []grpc.StreamDesc{ - { - StreamName: "Snapshot", - Handler: _Maintenance_Snapshot_Handler, - ServerStreams: true, - }, - }, - Metadata: "rpc.proto", -} - -// Client API for Auth service - -type AuthClient interface { - // AuthEnable enables authentication. - AuthEnable(ctx context.Context, in *AuthEnableRequest, opts ...grpc.CallOption) (*AuthEnableResponse, error) - // AuthDisable disables authentication. - AuthDisable(ctx context.Context, in *AuthDisableRequest, opts ...grpc.CallOption) (*AuthDisableResponse, error) - // Authenticate processes an authenticate request. - Authenticate(ctx context.Context, in *AuthenticateRequest, opts ...grpc.CallOption) (*AuthenticateResponse, error) - // UserAdd adds a new user. - UserAdd(ctx context.Context, in *AuthUserAddRequest, opts ...grpc.CallOption) (*AuthUserAddResponse, error) - // UserGet gets detailed user information. - UserGet(ctx context.Context, in *AuthUserGetRequest, opts ...grpc.CallOption) (*AuthUserGetResponse, error) - // UserList gets a list of all users. - UserList(ctx context.Context, in *AuthUserListRequest, opts ...grpc.CallOption) (*AuthUserListResponse, error) - // UserDelete deletes a specified user. - UserDelete(ctx context.Context, in *AuthUserDeleteRequest, opts ...grpc.CallOption) (*AuthUserDeleteResponse, error) - // UserChangePassword changes the password of a specified user. - UserChangePassword(ctx context.Context, in *AuthUserChangePasswordRequest, opts ...grpc.CallOption) (*AuthUserChangePasswordResponse, error) - // UserGrant grants a role to a specified user. - UserGrantRole(ctx context.Context, in *AuthUserGrantRoleRequest, opts ...grpc.CallOption) (*AuthUserGrantRoleResponse, error) - // UserRevokeRole revokes a role of specified user. - UserRevokeRole(ctx context.Context, in *AuthUserRevokeRoleRequest, opts ...grpc.CallOption) (*AuthUserRevokeRoleResponse, error) - // RoleAdd adds a new role. - RoleAdd(ctx context.Context, in *AuthRoleAddRequest, opts ...grpc.CallOption) (*AuthRoleAddResponse, error) - // RoleGet gets detailed role information. - RoleGet(ctx context.Context, in *AuthRoleGetRequest, opts ...grpc.CallOption) (*AuthRoleGetResponse, error) - // RoleList gets lists of all roles. - RoleList(ctx context.Context, in *AuthRoleListRequest, opts ...grpc.CallOption) (*AuthRoleListResponse, error) - // RoleDelete deletes a specified role. - RoleDelete(ctx context.Context, in *AuthRoleDeleteRequest, opts ...grpc.CallOption) (*AuthRoleDeleteResponse, error) - // RoleGrantPermission grants a permission of a specified key or range to a specified role. - RoleGrantPermission(ctx context.Context, in *AuthRoleGrantPermissionRequest, opts ...grpc.CallOption) (*AuthRoleGrantPermissionResponse, error) - // RoleRevokePermission revokes a key or range permission of a specified role. - RoleRevokePermission(ctx context.Context, in *AuthRoleRevokePermissionRequest, opts ...grpc.CallOption) (*AuthRoleRevokePermissionResponse, error) -} - -type authClient struct { - cc *grpc.ClientConn -} - -func NewAuthClient(cc *grpc.ClientConn) AuthClient { - return &authClient{cc} -} - -func (c *authClient) AuthEnable(ctx context.Context, in *AuthEnableRequest, opts ...grpc.CallOption) (*AuthEnableResponse, error) { - out := new(AuthEnableResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/AuthEnable", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) AuthDisable(ctx context.Context, in *AuthDisableRequest, opts ...grpc.CallOption) (*AuthDisableResponse, error) { - out := new(AuthDisableResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/AuthDisable", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) Authenticate(ctx context.Context, in *AuthenticateRequest, opts ...grpc.CallOption) (*AuthenticateResponse, error) { - out := new(AuthenticateResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/Authenticate", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) UserAdd(ctx context.Context, in *AuthUserAddRequest, opts ...grpc.CallOption) (*AuthUserAddResponse, error) { - out := new(AuthUserAddResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/UserAdd", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) UserGet(ctx context.Context, in *AuthUserGetRequest, opts ...grpc.CallOption) (*AuthUserGetResponse, error) { - out := new(AuthUserGetResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/UserGet", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) UserList(ctx context.Context, in *AuthUserListRequest, opts ...grpc.CallOption) (*AuthUserListResponse, error) { - out := new(AuthUserListResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/UserList", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) UserDelete(ctx context.Context, in *AuthUserDeleteRequest, opts ...grpc.CallOption) (*AuthUserDeleteResponse, error) { - out := new(AuthUserDeleteResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/UserDelete", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) UserChangePassword(ctx context.Context, in *AuthUserChangePasswordRequest, opts ...grpc.CallOption) (*AuthUserChangePasswordResponse, error) { - out := new(AuthUserChangePasswordResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/UserChangePassword", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) UserGrantRole(ctx context.Context, in *AuthUserGrantRoleRequest, opts ...grpc.CallOption) (*AuthUserGrantRoleResponse, error) { - out := new(AuthUserGrantRoleResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/UserGrantRole", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) UserRevokeRole(ctx context.Context, in *AuthUserRevokeRoleRequest, opts ...grpc.CallOption) (*AuthUserRevokeRoleResponse, error) { - out := new(AuthUserRevokeRoleResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/UserRevokeRole", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) RoleAdd(ctx context.Context, in *AuthRoleAddRequest, opts ...grpc.CallOption) (*AuthRoleAddResponse, error) { - out := new(AuthRoleAddResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/RoleAdd", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) RoleGet(ctx context.Context, in *AuthRoleGetRequest, opts ...grpc.CallOption) (*AuthRoleGetResponse, error) { - out := new(AuthRoleGetResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/RoleGet", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) RoleList(ctx context.Context, in *AuthRoleListRequest, opts ...grpc.CallOption) (*AuthRoleListResponse, error) { - out := new(AuthRoleListResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/RoleList", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) RoleDelete(ctx context.Context, in *AuthRoleDeleteRequest, opts ...grpc.CallOption) (*AuthRoleDeleteResponse, error) { - out := new(AuthRoleDeleteResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/RoleDelete", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) RoleGrantPermission(ctx context.Context, in *AuthRoleGrantPermissionRequest, opts ...grpc.CallOption) (*AuthRoleGrantPermissionResponse, error) { - out := new(AuthRoleGrantPermissionResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/RoleGrantPermission", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) RoleRevokePermission(ctx context.Context, in *AuthRoleRevokePermissionRequest, opts ...grpc.CallOption) (*AuthRoleRevokePermissionResponse, error) { - out := new(AuthRoleRevokePermissionResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/RoleRevokePermission", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for Auth service - -type AuthServer interface { - // AuthEnable enables authentication. - AuthEnable(context.Context, *AuthEnableRequest) (*AuthEnableResponse, error) - // AuthDisable disables authentication. - AuthDisable(context.Context, *AuthDisableRequest) (*AuthDisableResponse, error) - // Authenticate processes an authenticate request. - Authenticate(context.Context, *AuthenticateRequest) (*AuthenticateResponse, error) - // UserAdd adds a new user. - UserAdd(context.Context, *AuthUserAddRequest) (*AuthUserAddResponse, error) - // UserGet gets detailed user information. - UserGet(context.Context, *AuthUserGetRequest) (*AuthUserGetResponse, error) - // UserList gets a list of all users. - UserList(context.Context, *AuthUserListRequest) (*AuthUserListResponse, error) - // UserDelete deletes a specified user. - UserDelete(context.Context, *AuthUserDeleteRequest) (*AuthUserDeleteResponse, error) - // UserChangePassword changes the password of a specified user. - UserChangePassword(context.Context, *AuthUserChangePasswordRequest) (*AuthUserChangePasswordResponse, error) - // UserGrant grants a role to a specified user. - UserGrantRole(context.Context, *AuthUserGrantRoleRequest) (*AuthUserGrantRoleResponse, error) - // UserRevokeRole revokes a role of specified user. - UserRevokeRole(context.Context, *AuthUserRevokeRoleRequest) (*AuthUserRevokeRoleResponse, error) - // RoleAdd adds a new role. - RoleAdd(context.Context, *AuthRoleAddRequest) (*AuthRoleAddResponse, error) - // RoleGet gets detailed role information. - RoleGet(context.Context, *AuthRoleGetRequest) (*AuthRoleGetResponse, error) - // RoleList gets lists of all roles. - RoleList(context.Context, *AuthRoleListRequest) (*AuthRoleListResponse, error) - // RoleDelete deletes a specified role. - RoleDelete(context.Context, *AuthRoleDeleteRequest) (*AuthRoleDeleteResponse, error) - // RoleGrantPermission grants a permission of a specified key or range to a specified role. - RoleGrantPermission(context.Context, *AuthRoleGrantPermissionRequest) (*AuthRoleGrantPermissionResponse, error) - // RoleRevokePermission revokes a key or range permission of a specified role. - RoleRevokePermission(context.Context, *AuthRoleRevokePermissionRequest) (*AuthRoleRevokePermissionResponse, error) -} - -func RegisterAuthServer(s *grpc.Server, srv AuthServer) { - s.RegisterService(&_Auth_serviceDesc, srv) -} - -func _Auth_AuthEnable_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthEnableRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).AuthEnable(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/AuthEnable", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).AuthEnable(ctx, req.(*AuthEnableRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_AuthDisable_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthDisableRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).AuthDisable(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/AuthDisable", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).AuthDisable(ctx, req.(*AuthDisableRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_Authenticate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthenticateRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).Authenticate(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/Authenticate", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).Authenticate(ctx, req.(*AuthenticateRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_UserAdd_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthUserAddRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).UserAdd(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/UserAdd", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).UserAdd(ctx, req.(*AuthUserAddRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_UserGet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthUserGetRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).UserGet(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/UserGet", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).UserGet(ctx, req.(*AuthUserGetRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_UserList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthUserListRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).UserList(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/UserList", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).UserList(ctx, req.(*AuthUserListRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_UserDelete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthUserDeleteRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).UserDelete(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/UserDelete", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).UserDelete(ctx, req.(*AuthUserDeleteRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_UserChangePassword_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthUserChangePasswordRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).UserChangePassword(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/UserChangePassword", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).UserChangePassword(ctx, req.(*AuthUserChangePasswordRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_UserGrantRole_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthUserGrantRoleRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).UserGrantRole(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/UserGrantRole", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).UserGrantRole(ctx, req.(*AuthUserGrantRoleRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_UserRevokeRole_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthUserRevokeRoleRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).UserRevokeRole(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/UserRevokeRole", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).UserRevokeRole(ctx, req.(*AuthUserRevokeRoleRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_RoleAdd_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthRoleAddRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).RoleAdd(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/RoleAdd", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).RoleAdd(ctx, req.(*AuthRoleAddRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_RoleGet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthRoleGetRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).RoleGet(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/RoleGet", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).RoleGet(ctx, req.(*AuthRoleGetRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_RoleList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthRoleListRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).RoleList(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/RoleList", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).RoleList(ctx, req.(*AuthRoleListRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_RoleDelete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthRoleDeleteRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).RoleDelete(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/RoleDelete", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).RoleDelete(ctx, req.(*AuthRoleDeleteRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_RoleGrantPermission_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthRoleGrantPermissionRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).RoleGrantPermission(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/RoleGrantPermission", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).RoleGrantPermission(ctx, req.(*AuthRoleGrantPermissionRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_RoleRevokePermission_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthRoleRevokePermissionRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).RoleRevokePermission(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/RoleRevokePermission", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).RoleRevokePermission(ctx, req.(*AuthRoleRevokePermissionRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Auth_serviceDesc = grpc.ServiceDesc{ - ServiceName: "etcdserverpb.Auth", - HandlerType: (*AuthServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "AuthEnable", - Handler: _Auth_AuthEnable_Handler, - }, - { - MethodName: "AuthDisable", - Handler: _Auth_AuthDisable_Handler, - }, - { - MethodName: "Authenticate", - Handler: _Auth_Authenticate_Handler, - }, - { - MethodName: "UserAdd", - Handler: _Auth_UserAdd_Handler, - }, - { - MethodName: "UserGet", - Handler: _Auth_UserGet_Handler, - }, - { - MethodName: "UserList", - Handler: _Auth_UserList_Handler, - }, - { - MethodName: "UserDelete", - Handler: _Auth_UserDelete_Handler, - }, - { - MethodName: "UserChangePassword", - Handler: _Auth_UserChangePassword_Handler, - }, - { - MethodName: "UserGrantRole", - Handler: _Auth_UserGrantRole_Handler, - }, - { - MethodName: "UserRevokeRole", - Handler: _Auth_UserRevokeRole_Handler, - }, - { - MethodName: "RoleAdd", - Handler: _Auth_RoleAdd_Handler, - }, - { - MethodName: "RoleGet", - Handler: _Auth_RoleGet_Handler, - }, - { - MethodName: "RoleList", - Handler: _Auth_RoleList_Handler, - }, - { - MethodName: "RoleDelete", - Handler: _Auth_RoleDelete_Handler, - }, - { - MethodName: "RoleGrantPermission", - Handler: _Auth_RoleGrantPermission_Handler, - }, - { - MethodName: "RoleRevokePermission", - Handler: _Auth_RoleRevokePermission_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "rpc.proto", -} - -func (m *ResponseHeader) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ResponseHeader) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ClusterId != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ClusterId)) - } - if m.MemberId != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.MemberId)) - } - if m.Revision != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Revision)) - } - if m.RaftTerm != 0 { - dAtA[i] = 0x20 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.RaftTerm)) - } - return i, nil -} - -func (m *RangeRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *RangeRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Key) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - if len(m.RangeEnd) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.RangeEnd))) - i += copy(dAtA[i:], m.RangeEnd) - } - if m.Limit != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Limit)) - } - if m.Revision != 0 { - dAtA[i] = 0x20 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Revision)) - } - if m.SortOrder != 0 { - dAtA[i] = 0x28 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.SortOrder)) - } - if m.SortTarget != 0 { - dAtA[i] = 0x30 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.SortTarget)) - } - if m.Serializable { - dAtA[i] = 0x38 - i++ - if m.Serializable { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.KeysOnly { - dAtA[i] = 0x40 - i++ - if m.KeysOnly { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.CountOnly { - dAtA[i] = 0x48 - i++ - if m.CountOnly { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.MinModRevision != 0 { - dAtA[i] = 0x50 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.MinModRevision)) - } - if m.MaxModRevision != 0 { - dAtA[i] = 0x58 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.MaxModRevision)) - } - if m.MinCreateRevision != 0 { - dAtA[i] = 0x60 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.MinCreateRevision)) - } - if m.MaxCreateRevision != 0 { - dAtA[i] = 0x68 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.MaxCreateRevision)) - } - return i, nil -} - -func (m *RangeResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *RangeResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n1, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - } - if len(m.Kvs) > 0 { - for _, msg := range m.Kvs { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - if m.More { - dAtA[i] = 0x18 - i++ - if m.More { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.Count != 0 { - dAtA[i] = 0x20 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Count)) - } - return i, nil -} - -func (m *PutRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *PutRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Key) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - if len(m.Value) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Value))) - i += copy(dAtA[i:], m.Value) - } - if m.Lease != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Lease)) - } - if m.PrevKv { - dAtA[i] = 0x20 - i++ - if m.PrevKv { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.IgnoreValue { - dAtA[i] = 0x28 - i++ - if m.IgnoreValue { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.IgnoreLease { - dAtA[i] = 0x30 - i++ - if m.IgnoreLease { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - return i, nil -} - -func (m *PutResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *PutResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n2, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - } - if m.PrevKv != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.PrevKv.Size())) - n3, err := m.PrevKv.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n3 - } - return i, nil -} - -func (m *DeleteRangeRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *DeleteRangeRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Key) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - if len(m.RangeEnd) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.RangeEnd))) - i += copy(dAtA[i:], m.RangeEnd) - } - if m.PrevKv { - dAtA[i] = 0x18 - i++ - if m.PrevKv { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - return i, nil -} - -func (m *DeleteRangeResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *DeleteRangeResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n4, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n4 - } - if m.Deleted != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Deleted)) - } - if len(m.PrevKvs) > 0 { - for _, msg := range m.PrevKvs { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *RequestOp) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *RequestOp) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Request != nil { - nn5, err := m.Request.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += nn5 - } - return i, nil -} - -func (m *RequestOp_RequestRange) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.RequestRange != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.RequestRange.Size())) - n6, err := m.RequestRange.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n6 - } - return i, nil -} -func (m *RequestOp_RequestPut) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.RequestPut != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.RequestPut.Size())) - n7, err := m.RequestPut.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n7 - } - return i, nil -} -func (m *RequestOp_RequestDeleteRange) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.RequestDeleteRange != nil { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.RequestDeleteRange.Size())) - n8, err := m.RequestDeleteRange.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n8 - } - return i, nil -} -func (m *RequestOp_RequestTxn) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.RequestTxn != nil { - dAtA[i] = 0x22 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.RequestTxn.Size())) - n9, err := m.RequestTxn.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n9 - } - return i, nil -} -func (m *ResponseOp) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ResponseOp) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Response != nil { - nn10, err := m.Response.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += nn10 - } - return i, nil -} - -func (m *ResponseOp_ResponseRange) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.ResponseRange != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ResponseRange.Size())) - n11, err := m.ResponseRange.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n11 - } - return i, nil -} -func (m *ResponseOp_ResponsePut) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.ResponsePut != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ResponsePut.Size())) - n12, err := m.ResponsePut.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n12 - } - return i, nil -} -func (m *ResponseOp_ResponseDeleteRange) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.ResponseDeleteRange != nil { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ResponseDeleteRange.Size())) - n13, err := m.ResponseDeleteRange.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n13 - } - return i, nil -} -func (m *ResponseOp_ResponseTxn) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.ResponseTxn != nil { - dAtA[i] = 0x22 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ResponseTxn.Size())) - n14, err := m.ResponseTxn.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n14 - } - return i, nil -} -func (m *Compare) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Compare) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Result != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Result)) - } - if m.Target != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Target)) - } - if len(m.Key) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - if m.TargetUnion != nil { - nn15, err := m.TargetUnion.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += nn15 - } - if len(m.RangeEnd) > 0 { - dAtA[i] = 0x82 - i++ - dAtA[i] = 0x4 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.RangeEnd))) - i += copy(dAtA[i:], m.RangeEnd) - } - return i, nil -} - -func (m *Compare_Version) MarshalTo(dAtA []byte) (int, error) { - i := 0 - dAtA[i] = 0x20 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Version)) - return i, nil -} -func (m *Compare_CreateRevision) MarshalTo(dAtA []byte) (int, error) { - i := 0 - dAtA[i] = 0x28 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.CreateRevision)) - return i, nil -} -func (m *Compare_ModRevision) MarshalTo(dAtA []byte) (int, error) { - i := 0 - dAtA[i] = 0x30 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ModRevision)) - return i, nil -} -func (m *Compare_Value) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.Value != nil { - dAtA[i] = 0x3a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Value))) - i += copy(dAtA[i:], m.Value) - } - return i, nil -} -func (m *Compare_Lease) MarshalTo(dAtA []byte) (int, error) { - i := 0 - dAtA[i] = 0x40 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Lease)) - return i, nil -} -func (m *TxnRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *TxnRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Compare) > 0 { - for _, msg := range m.Compare { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - if len(m.Success) > 0 { - for _, msg := range m.Success { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - if len(m.Failure) > 0 { - for _, msg := range m.Failure { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *TxnResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *TxnResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n16, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n16 - } - if m.Succeeded { - dAtA[i] = 0x10 - i++ - if m.Succeeded { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if len(m.Responses) > 0 { - for _, msg := range m.Responses { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *CompactionRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *CompactionRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Revision != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Revision)) - } - if m.Physical { - dAtA[i] = 0x10 - i++ - if m.Physical { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - return i, nil -} - -func (m *CompactionResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *CompactionResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n17, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n17 - } - return i, nil -} - -func (m *HashRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *HashRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *HashKVRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *HashKVRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Revision != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Revision)) - } - return i, nil -} - -func (m *HashKVResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *HashKVResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n18, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n18 - } - if m.Hash != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Hash)) - } - if m.CompactRevision != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.CompactRevision)) - } - return i, nil -} - -func (m *HashResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *HashResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n19, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n19 - } - if m.Hash != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Hash)) - } - return i, nil -} - -func (m *SnapshotRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SnapshotRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *SnapshotResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SnapshotResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n20, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n20 - } - if m.RemainingBytes != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.RemainingBytes)) - } - if len(m.Blob) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Blob))) - i += copy(dAtA[i:], m.Blob) - } - return i, nil -} - -func (m *WatchRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *WatchRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.RequestUnion != nil { - nn21, err := m.RequestUnion.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += nn21 - } - return i, nil -} - -func (m *WatchRequest_CreateRequest) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.CreateRequest != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.CreateRequest.Size())) - n22, err := m.CreateRequest.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n22 - } - return i, nil -} -func (m *WatchRequest_CancelRequest) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.CancelRequest != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.CancelRequest.Size())) - n23, err := m.CancelRequest.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n23 - } - return i, nil -} -func (m *WatchCreateRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *WatchCreateRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Key) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - if len(m.RangeEnd) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.RangeEnd))) - i += copy(dAtA[i:], m.RangeEnd) - } - if m.StartRevision != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.StartRevision)) - } - if m.ProgressNotify { - dAtA[i] = 0x20 - i++ - if m.ProgressNotify { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if len(m.Filters) > 0 { - dAtA25 := make([]byte, len(m.Filters)*10) - var j24 int - for _, num := range m.Filters { - for num >= 1<<7 { - dAtA25[j24] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j24++ - } - dAtA25[j24] = uint8(num) - j24++ - } - dAtA[i] = 0x2a - i++ - i = encodeVarintRpc(dAtA, i, uint64(j24)) - i += copy(dAtA[i:], dAtA25[:j24]) - } - if m.PrevKv { - dAtA[i] = 0x30 - i++ - if m.PrevKv { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - return i, nil -} - -func (m *WatchCancelRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *WatchCancelRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.WatchId != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.WatchId)) - } - return i, nil -} - -func (m *WatchResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *WatchResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n26, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n26 - } - if m.WatchId != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.WatchId)) - } - if m.Created { - dAtA[i] = 0x18 - i++ - if m.Created { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.Canceled { - dAtA[i] = 0x20 - i++ - if m.Canceled { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.CompactRevision != 0 { - dAtA[i] = 0x28 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.CompactRevision)) - } - if len(m.CancelReason) > 0 { - dAtA[i] = 0x32 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.CancelReason))) - i += copy(dAtA[i:], m.CancelReason) - } - if len(m.Events) > 0 { - for _, msg := range m.Events { - dAtA[i] = 0x5a - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *LeaseGrantRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseGrantRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.TTL != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.TTL)) - } - if m.ID != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - return i, nil -} - -func (m *LeaseGrantResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseGrantResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n27, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n27 - } - if m.ID != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - if m.TTL != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.TTL)) - } - if len(m.Error) > 0 { - dAtA[i] = 0x22 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Error))) - i += copy(dAtA[i:], m.Error) - } - return i, nil -} - -func (m *LeaseRevokeRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseRevokeRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - return i, nil -} - -func (m *LeaseRevokeResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseRevokeResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n28, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n28 - } - return i, nil -} - -func (m *LeaseKeepAliveRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseKeepAliveRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - return i, nil -} - -func (m *LeaseKeepAliveResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseKeepAliveResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n29, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n29 - } - if m.ID != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - if m.TTL != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.TTL)) - } - return i, nil -} - -func (m *LeaseTimeToLiveRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseTimeToLiveRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - if m.Keys { - dAtA[i] = 0x10 - i++ - if m.Keys { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - return i, nil -} - -func (m *LeaseTimeToLiveResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseTimeToLiveResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n30, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n30 - } - if m.ID != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - if m.TTL != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.TTL)) - } - if m.GrantedTTL != 0 { - dAtA[i] = 0x20 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.GrantedTTL)) - } - if len(m.Keys) > 0 { - for _, b := range m.Keys { - dAtA[i] = 0x2a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(b))) - i += copy(dAtA[i:], b) - } - } - return i, nil -} - -func (m *LeaseLeasesRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseLeasesRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *LeaseStatus) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseStatus) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - return i, nil -} - -func (m *LeaseLeasesResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseLeasesResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n31, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n31 - } - if len(m.Leases) > 0 { - for _, msg := range m.Leases { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *Member) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Member) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - if len(m.Name) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.PeerURLs) > 0 { - for _, s := range m.PeerURLs { - dAtA[i] = 0x1a - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if len(m.ClientURLs) > 0 { - for _, s := range m.ClientURLs { - dAtA[i] = 0x22 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - return i, nil -} - -func (m *MemberAddRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MemberAddRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.PeerURLs) > 0 { - for _, s := range m.PeerURLs { - dAtA[i] = 0xa - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - return i, nil -} - -func (m *MemberAddResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MemberAddResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n32, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n32 - } - if m.Member != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Member.Size())) - n33, err := m.Member.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n33 - } - if len(m.Members) > 0 { - for _, msg := range m.Members { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *MemberRemoveRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MemberRemoveRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - return i, nil -} - -func (m *MemberRemoveResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MemberRemoveResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n34, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n34 - } - if len(m.Members) > 0 { - for _, msg := range m.Members { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *MemberUpdateRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MemberUpdateRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - if len(m.PeerURLs) > 0 { - for _, s := range m.PeerURLs { - dAtA[i] = 0x12 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - return i, nil -} - -func (m *MemberUpdateResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MemberUpdateResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n35, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n35 - } - if len(m.Members) > 0 { - for _, msg := range m.Members { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *MemberListRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MemberListRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *MemberListResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MemberListResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n36, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n36 - } - if len(m.Members) > 0 { - for _, msg := range m.Members { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *DefragmentRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *DefragmentRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *DefragmentResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *DefragmentResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n37, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n37 - } - return i, nil -} - -func (m *MoveLeaderRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MoveLeaderRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.TargetID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.TargetID)) - } - return i, nil -} - -func (m *MoveLeaderResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MoveLeaderResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n38, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n38 - } - return i, nil -} - -func (m *AlarmRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AlarmRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Action != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Action)) - } - if m.MemberID != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.MemberID)) - } - if m.Alarm != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Alarm)) - } - return i, nil -} - -func (m *AlarmMember) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AlarmMember) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.MemberID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.MemberID)) - } - if m.Alarm != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Alarm)) - } - return i, nil -} - -func (m *AlarmResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AlarmResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n39, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n39 - } - if len(m.Alarms) > 0 { - for _, msg := range m.Alarms { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *StatusRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *StatusRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *StatusResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *StatusResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n40, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n40 - } - if len(m.Version) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Version))) - i += copy(dAtA[i:], m.Version) - } - if m.DbSize != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.DbSize)) - } - if m.Leader != 0 { - dAtA[i] = 0x20 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Leader)) - } - if m.RaftIndex != 0 { - dAtA[i] = 0x28 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.RaftIndex)) - } - if m.RaftTerm != 0 { - dAtA[i] = 0x30 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.RaftTerm)) - } - return i, nil -} - -func (m *AuthEnableRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthEnableRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *AuthDisableRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthDisableRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *AuthenticateRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthenticateRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.Password) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Password))) - i += copy(dAtA[i:], m.Password) - } - return i, nil -} - -func (m *AuthUserAddRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserAddRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.Password) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Password))) - i += copy(dAtA[i:], m.Password) - } - return i, nil -} - -func (m *AuthUserGetRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserGetRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - return i, nil -} - -func (m *AuthUserDeleteRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserDeleteRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - return i, nil -} - -func (m *AuthUserChangePasswordRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserChangePasswordRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.Password) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Password))) - i += copy(dAtA[i:], m.Password) - } - return i, nil -} - -func (m *AuthUserGrantRoleRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserGrantRoleRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.User) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.User))) - i += copy(dAtA[i:], m.User) - } - if len(m.Role) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Role))) - i += copy(dAtA[i:], m.Role) - } - return i, nil -} - -func (m *AuthUserRevokeRoleRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserRevokeRoleRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.Role) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Role))) - i += copy(dAtA[i:], m.Role) - } - return i, nil -} - -func (m *AuthRoleAddRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleAddRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - return i, nil -} - -func (m *AuthRoleGetRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleGetRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Role) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Role))) - i += copy(dAtA[i:], m.Role) - } - return i, nil -} - -func (m *AuthUserListRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserListRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *AuthRoleListRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleListRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *AuthRoleDeleteRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleDeleteRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Role) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Role))) - i += copy(dAtA[i:], m.Role) - } - return i, nil -} - -func (m *AuthRoleGrantPermissionRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleGrantPermissionRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if m.Perm != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Perm.Size())) - n41, err := m.Perm.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n41 - } - return i, nil -} - -func (m *AuthRoleRevokePermissionRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleRevokePermissionRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Role) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Role))) - i += copy(dAtA[i:], m.Role) - } - if len(m.Key) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - if len(m.RangeEnd) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.RangeEnd))) - i += copy(dAtA[i:], m.RangeEnd) - } - return i, nil -} - -func (m *AuthEnableResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthEnableResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n42, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n42 - } - return i, nil -} - -func (m *AuthDisableResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthDisableResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n43, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n43 - } - return i, nil -} - -func (m *AuthenticateResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthenticateResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n44, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n44 - } - if len(m.Token) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Token))) - i += copy(dAtA[i:], m.Token) - } - return i, nil -} - -func (m *AuthUserAddResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserAddResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n45, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n45 - } - return i, nil -} - -func (m *AuthUserGetResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserGetResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n46, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n46 - } - if len(m.Roles) > 0 { - for _, s := range m.Roles { - dAtA[i] = 0x12 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - return i, nil -} - -func (m *AuthUserDeleteResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserDeleteResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n47, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n47 - } - return i, nil -} - -func (m *AuthUserChangePasswordResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserChangePasswordResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n48, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n48 - } - return i, nil -} - -func (m *AuthUserGrantRoleResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserGrantRoleResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n49, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n49 - } - return i, nil -} - -func (m *AuthUserRevokeRoleResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserRevokeRoleResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n50, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n50 - } - return i, nil -} - -func (m *AuthRoleAddResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleAddResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n51, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n51 - } - return i, nil -} - -func (m *AuthRoleGetResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleGetResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n52, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n52 - } - if len(m.Perm) > 0 { - for _, msg := range m.Perm { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *AuthRoleListResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleListResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n53, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n53 - } - if len(m.Roles) > 0 { - for _, s := range m.Roles { - dAtA[i] = 0x12 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - return i, nil -} - -func (m *AuthUserListResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserListResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n54, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n54 - } - if len(m.Users) > 0 { - for _, s := range m.Users { - dAtA[i] = 0x12 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - return i, nil -} - -func (m *AuthRoleDeleteResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleDeleteResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n55, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n55 - } - return i, nil -} - -func (m *AuthRoleGrantPermissionResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleGrantPermissionResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n56, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n56 - } - return i, nil -} - -func (m *AuthRoleRevokePermissionResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleRevokePermissionResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n57, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n57 - } - return i, nil -} - -func encodeVarintRpc(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *ResponseHeader) Size() (n int) { - var l int - _ = l - if m.ClusterId != 0 { - n += 1 + sovRpc(uint64(m.ClusterId)) - } - if m.MemberId != 0 { - n += 1 + sovRpc(uint64(m.MemberId)) - } - if m.Revision != 0 { - n += 1 + sovRpc(uint64(m.Revision)) - } - if m.RaftTerm != 0 { - n += 1 + sovRpc(uint64(m.RaftTerm)) - } - return n -} - -func (m *RangeRequest) Size() (n int) { - var l int - _ = l - l = len(m.Key) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.RangeEnd) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.Limit != 0 { - n += 1 + sovRpc(uint64(m.Limit)) - } - if m.Revision != 0 { - n += 1 + sovRpc(uint64(m.Revision)) - } - if m.SortOrder != 0 { - n += 1 + sovRpc(uint64(m.SortOrder)) - } - if m.SortTarget != 0 { - n += 1 + sovRpc(uint64(m.SortTarget)) - } - if m.Serializable { - n += 2 - } - if m.KeysOnly { - n += 2 - } - if m.CountOnly { - n += 2 - } - if m.MinModRevision != 0 { - n += 1 + sovRpc(uint64(m.MinModRevision)) - } - if m.MaxModRevision != 0 { - n += 1 + sovRpc(uint64(m.MaxModRevision)) - } - if m.MinCreateRevision != 0 { - n += 1 + sovRpc(uint64(m.MinCreateRevision)) - } - if m.MaxCreateRevision != 0 { - n += 1 + sovRpc(uint64(m.MaxCreateRevision)) - } - return n -} - -func (m *RangeResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Kvs) > 0 { - for _, e := range m.Kvs { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - if m.More { - n += 2 - } - if m.Count != 0 { - n += 1 + sovRpc(uint64(m.Count)) - } - return n -} - -func (m *PutRequest) Size() (n int) { - var l int - _ = l - l = len(m.Key) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Value) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.Lease != 0 { - n += 1 + sovRpc(uint64(m.Lease)) - } - if m.PrevKv { - n += 2 - } - if m.IgnoreValue { - n += 2 - } - if m.IgnoreLease { - n += 2 - } - return n -} - -func (m *PutResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.PrevKv != nil { - l = m.PrevKv.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *DeleteRangeRequest) Size() (n int) { - var l int - _ = l - l = len(m.Key) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.RangeEnd) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.PrevKv { - n += 2 - } - return n -} - -func (m *DeleteRangeResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.Deleted != 0 { - n += 1 + sovRpc(uint64(m.Deleted)) - } - if len(m.PrevKvs) > 0 { - for _, e := range m.PrevKvs { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *RequestOp) Size() (n int) { - var l int - _ = l - if m.Request != nil { - n += m.Request.Size() - } - return n -} - -func (m *RequestOp_RequestRange) Size() (n int) { - var l int - _ = l - if m.RequestRange != nil { - l = m.RequestRange.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *RequestOp_RequestPut) Size() (n int) { - var l int - _ = l - if m.RequestPut != nil { - l = m.RequestPut.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *RequestOp_RequestDeleteRange) Size() (n int) { - var l int - _ = l - if m.RequestDeleteRange != nil { - l = m.RequestDeleteRange.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *RequestOp_RequestTxn) Size() (n int) { - var l int - _ = l - if m.RequestTxn != nil { - l = m.RequestTxn.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *ResponseOp) Size() (n int) { - var l int - _ = l - if m.Response != nil { - n += m.Response.Size() - } - return n -} - -func (m *ResponseOp_ResponseRange) Size() (n int) { - var l int - _ = l - if m.ResponseRange != nil { - l = m.ResponseRange.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *ResponseOp_ResponsePut) Size() (n int) { - var l int - _ = l - if m.ResponsePut != nil { - l = m.ResponsePut.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *ResponseOp_ResponseDeleteRange) Size() (n int) { - var l int - _ = l - if m.ResponseDeleteRange != nil { - l = m.ResponseDeleteRange.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *ResponseOp_ResponseTxn) Size() (n int) { - var l int - _ = l - if m.ResponseTxn != nil { - l = m.ResponseTxn.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *Compare) Size() (n int) { - var l int - _ = l - if m.Result != 0 { - n += 1 + sovRpc(uint64(m.Result)) - } - if m.Target != 0 { - n += 1 + sovRpc(uint64(m.Target)) - } - l = len(m.Key) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.TargetUnion != nil { - n += m.TargetUnion.Size() - } - l = len(m.RangeEnd) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *Compare_Version) Size() (n int) { - var l int - _ = l - n += 1 + sovRpc(uint64(m.Version)) - return n -} -func (m *Compare_CreateRevision) Size() (n int) { - var l int - _ = l - n += 1 + sovRpc(uint64(m.CreateRevision)) - return n -} -func (m *Compare_ModRevision) Size() (n int) { - var l int - _ = l - n += 1 + sovRpc(uint64(m.ModRevision)) - return n -} -func (m *Compare_Value) Size() (n int) { - var l int - _ = l - if m.Value != nil { - l = len(m.Value) - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *Compare_Lease) Size() (n int) { - var l int - _ = l - n += 1 + sovRpc(uint64(m.Lease)) - return n -} -func (m *TxnRequest) Size() (n int) { - var l int - _ = l - if len(m.Compare) > 0 { - for _, e := range m.Compare { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - if len(m.Success) > 0 { - for _, e := range m.Success { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - if len(m.Failure) > 0 { - for _, e := range m.Failure { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *TxnResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.Succeeded { - n += 2 - } - if len(m.Responses) > 0 { - for _, e := range m.Responses { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *CompactionRequest) Size() (n int) { - var l int - _ = l - if m.Revision != 0 { - n += 1 + sovRpc(uint64(m.Revision)) - } - if m.Physical { - n += 2 - } - return n -} - -func (m *CompactionResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *HashRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *HashKVRequest) Size() (n int) { - var l int - _ = l - if m.Revision != 0 { - n += 1 + sovRpc(uint64(m.Revision)) - } - return n -} - -func (m *HashKVResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.Hash != 0 { - n += 1 + sovRpc(uint64(m.Hash)) - } - if m.CompactRevision != 0 { - n += 1 + sovRpc(uint64(m.CompactRevision)) - } - return n -} - -func (m *HashResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.Hash != 0 { - n += 1 + sovRpc(uint64(m.Hash)) - } - return n -} - -func (m *SnapshotRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *SnapshotResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.RemainingBytes != 0 { - n += 1 + sovRpc(uint64(m.RemainingBytes)) - } - l = len(m.Blob) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *WatchRequest) Size() (n int) { - var l int - _ = l - if m.RequestUnion != nil { - n += m.RequestUnion.Size() - } - return n -} - -func (m *WatchRequest_CreateRequest) Size() (n int) { - var l int - _ = l - if m.CreateRequest != nil { - l = m.CreateRequest.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *WatchRequest_CancelRequest) Size() (n int) { - var l int - _ = l - if m.CancelRequest != nil { - l = m.CancelRequest.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *WatchCreateRequest) Size() (n int) { - var l int - _ = l - l = len(m.Key) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.RangeEnd) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.StartRevision != 0 { - n += 1 + sovRpc(uint64(m.StartRevision)) - } - if m.ProgressNotify { - n += 2 - } - if len(m.Filters) > 0 { - l = 0 - for _, e := range m.Filters { - l += sovRpc(uint64(e)) - } - n += 1 + sovRpc(uint64(l)) + l - } - if m.PrevKv { - n += 2 - } - return n -} - -func (m *WatchCancelRequest) Size() (n int) { - var l int - _ = l - if m.WatchId != 0 { - n += 1 + sovRpc(uint64(m.WatchId)) - } - return n -} - -func (m *WatchResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.WatchId != 0 { - n += 1 + sovRpc(uint64(m.WatchId)) - } - if m.Created { - n += 2 - } - if m.Canceled { - n += 2 - } - if m.CompactRevision != 0 { - n += 1 + sovRpc(uint64(m.CompactRevision)) - } - l = len(m.CancelReason) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Events) > 0 { - for _, e := range m.Events { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *LeaseGrantRequest) Size() (n int) { - var l int - _ = l - if m.TTL != 0 { - n += 1 + sovRpc(uint64(m.TTL)) - } - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - return n -} - -func (m *LeaseGrantResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - if m.TTL != 0 { - n += 1 + sovRpc(uint64(m.TTL)) - } - l = len(m.Error) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *LeaseRevokeRequest) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - return n -} - -func (m *LeaseRevokeResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *LeaseKeepAliveRequest) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - return n -} - -func (m *LeaseKeepAliveResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - if m.TTL != 0 { - n += 1 + sovRpc(uint64(m.TTL)) - } - return n -} - -func (m *LeaseTimeToLiveRequest) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - if m.Keys { - n += 2 - } - return n -} - -func (m *LeaseTimeToLiveResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - if m.TTL != 0 { - n += 1 + sovRpc(uint64(m.TTL)) - } - if m.GrantedTTL != 0 { - n += 1 + sovRpc(uint64(m.GrantedTTL)) - } - if len(m.Keys) > 0 { - for _, b := range m.Keys { - l = len(b) - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *LeaseLeasesRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *LeaseStatus) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - return n -} - -func (m *LeaseLeasesResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Leases) > 0 { - for _, e := range m.Leases { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *Member) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.PeerURLs) > 0 { - for _, s := range m.PeerURLs { - l = len(s) - n += 1 + l + sovRpc(uint64(l)) - } - } - if len(m.ClientURLs) > 0 { - for _, s := range m.ClientURLs { - l = len(s) - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *MemberAddRequest) Size() (n int) { - var l int - _ = l - if len(m.PeerURLs) > 0 { - for _, s := range m.PeerURLs { - l = len(s) - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *MemberAddResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.Member != nil { - l = m.Member.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Members) > 0 { - for _, e := range m.Members { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *MemberRemoveRequest) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - return n -} - -func (m *MemberRemoveResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Members) > 0 { - for _, e := range m.Members { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *MemberUpdateRequest) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - if len(m.PeerURLs) > 0 { - for _, s := range m.PeerURLs { - l = len(s) - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *MemberUpdateResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Members) > 0 { - for _, e := range m.Members { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *MemberListRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *MemberListResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Members) > 0 { - for _, e := range m.Members { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *DefragmentRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *DefragmentResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *MoveLeaderRequest) Size() (n int) { - var l int - _ = l - if m.TargetID != 0 { - n += 1 + sovRpc(uint64(m.TargetID)) - } - return n -} - -func (m *MoveLeaderResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AlarmRequest) Size() (n int) { - var l int - _ = l - if m.Action != 0 { - n += 1 + sovRpc(uint64(m.Action)) - } - if m.MemberID != 0 { - n += 1 + sovRpc(uint64(m.MemberID)) - } - if m.Alarm != 0 { - n += 1 + sovRpc(uint64(m.Alarm)) - } - return n -} - -func (m *AlarmMember) Size() (n int) { - var l int - _ = l - if m.MemberID != 0 { - n += 1 + sovRpc(uint64(m.MemberID)) - } - if m.Alarm != 0 { - n += 1 + sovRpc(uint64(m.Alarm)) - } - return n -} - -func (m *AlarmResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Alarms) > 0 { - for _, e := range m.Alarms { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *StatusRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *StatusResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Version) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.DbSize != 0 { - n += 1 + sovRpc(uint64(m.DbSize)) - } - if m.Leader != 0 { - n += 1 + sovRpc(uint64(m.Leader)) - } - if m.RaftIndex != 0 { - n += 1 + sovRpc(uint64(m.RaftIndex)) - } - if m.RaftTerm != 0 { - n += 1 + sovRpc(uint64(m.RaftTerm)) - } - return n -} - -func (m *AuthEnableRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *AuthDisableRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *AuthenticateRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Password) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserAddRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Password) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserGetRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserDeleteRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserChangePasswordRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Password) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserGrantRoleRequest) Size() (n int) { - var l int - _ = l - l = len(m.User) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Role) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserRevokeRoleRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Role) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthRoleAddRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthRoleGetRequest) Size() (n int) { - var l int - _ = l - l = len(m.Role) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserListRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *AuthRoleListRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *AuthRoleDeleteRequest) Size() (n int) { - var l int - _ = l - l = len(m.Role) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthRoleGrantPermissionRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.Perm != nil { - l = m.Perm.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthRoleRevokePermissionRequest) Size() (n int) { - var l int - _ = l - l = len(m.Role) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Key) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.RangeEnd) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthEnableResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthDisableResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthenticateResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Token) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserAddResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserGetResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Roles) > 0 { - for _, s := range m.Roles { - l = len(s) - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *AuthUserDeleteResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserChangePasswordResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserGrantRoleResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserRevokeRoleResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthRoleAddResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthRoleGetResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Perm) > 0 { - for _, e := range m.Perm { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *AuthRoleListResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Roles) > 0 { - for _, s := range m.Roles { - l = len(s) - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *AuthUserListResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Users) > 0 { - for _, s := range m.Users { - l = len(s) - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *AuthRoleDeleteResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthRoleGrantPermissionResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthRoleRevokePermissionResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func sovRpc(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozRpc(x uint64) (n int) { - return sovRpc(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *ResponseHeader) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ResponseHeader: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ResponseHeader: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClusterId", wireType) - } - m.ClusterId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ClusterId |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MemberId", wireType) - } - m.MemberId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MemberId |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Revision", wireType) - } - m.Revision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Revision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RaftTerm", wireType) - } - m.RaftTerm = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RaftTerm |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *RangeRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: RangeRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: RangeRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RangeEnd", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RangeEnd = append(m.RangeEnd[:0], dAtA[iNdEx:postIndex]...) - if m.RangeEnd == nil { - m.RangeEnd = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Limit", wireType) - } - m.Limit = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Limit |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Revision", wireType) - } - m.Revision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Revision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SortOrder", wireType) - } - m.SortOrder = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.SortOrder |= (RangeRequest_SortOrder(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SortTarget", wireType) - } - m.SortTarget = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.SortTarget |= (RangeRequest_SortTarget(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 7: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Serializable", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Serializable = bool(v != 0) - case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field KeysOnly", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.KeysOnly = bool(v != 0) - case 9: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CountOnly", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.CountOnly = bool(v != 0) - case 10: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MinModRevision", wireType) - } - m.MinModRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MinModRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 11: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MaxModRevision", wireType) - } - m.MaxModRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MaxModRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 12: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MinCreateRevision", wireType) - } - m.MinCreateRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MinCreateRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 13: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MaxCreateRevision", wireType) - } - m.MaxCreateRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MaxCreateRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *RangeResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: RangeResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: RangeResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Kvs", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Kvs = append(m.Kvs, &mvccpb.KeyValue{}) - if err := m.Kvs[len(m.Kvs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field More", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.More = bool(v != 0) - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Count", wireType) - } - m.Count = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Count |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *PutRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: PutRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: PutRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...) - if m.Value == nil { - m.Value = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Lease", wireType) - } - m.Lease = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Lease |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PrevKv", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.PrevKv = bool(v != 0) - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field IgnoreValue", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.IgnoreValue = bool(v != 0) - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field IgnoreLease", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.IgnoreLease = bool(v != 0) - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *PutResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: PutResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: PutResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PrevKv", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.PrevKv == nil { - m.PrevKv = &mvccpb.KeyValue{} - } - if err := m.PrevKv.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *DeleteRangeRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: DeleteRangeRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: DeleteRangeRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RangeEnd", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RangeEnd = append(m.RangeEnd[:0], dAtA[iNdEx:postIndex]...) - if m.RangeEnd == nil { - m.RangeEnd = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PrevKv", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.PrevKv = bool(v != 0) - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *DeleteRangeResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: DeleteRangeResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: DeleteRangeResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Deleted", wireType) - } - m.Deleted = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Deleted |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PrevKvs", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PrevKvs = append(m.PrevKvs, &mvccpb.KeyValue{}) - if err := m.PrevKvs[len(m.PrevKvs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *RequestOp) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: RequestOp: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: RequestOp: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RequestRange", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &RangeRequest{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Request = &RequestOp_RequestRange{v} - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RequestPut", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &PutRequest{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Request = &RequestOp_RequestPut{v} - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RequestDeleteRange", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &DeleteRangeRequest{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Request = &RequestOp_RequestDeleteRange{v} - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RequestTxn", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &TxnRequest{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Request = &RequestOp_RequestTxn{v} - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ResponseOp) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ResponseOp: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ResponseOp: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ResponseRange", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &RangeResponse{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Response = &ResponseOp_ResponseRange{v} - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ResponsePut", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &PutResponse{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Response = &ResponseOp_ResponsePut{v} - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ResponseDeleteRange", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &DeleteRangeResponse{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Response = &ResponseOp_ResponseDeleteRange{v} - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ResponseTxn", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &TxnResponse{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Response = &ResponseOp_ResponseTxn{v} - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Compare) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Compare: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Compare: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Result", wireType) - } - m.Result = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Result |= (Compare_CompareResult(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Target", wireType) - } - m.Target = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Target |= (Compare_CompareTarget(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) - } - var v int64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.TargetUnion = &Compare_Version{v} - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CreateRevision", wireType) - } - var v int64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.TargetUnion = &Compare_CreateRevision{v} - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ModRevision", wireType) - } - var v int64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.TargetUnion = &Compare_ModRevision{v} - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := make([]byte, postIndex-iNdEx) - copy(v, dAtA[iNdEx:postIndex]) - m.TargetUnion = &Compare_Value{v} - iNdEx = postIndex - case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Lease", wireType) - } - var v int64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.TargetUnion = &Compare_Lease{v} - case 64: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RangeEnd", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RangeEnd = append(m.RangeEnd[:0], dAtA[iNdEx:postIndex]...) - if m.RangeEnd == nil { - m.RangeEnd = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *TxnRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: TxnRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: TxnRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Compare", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Compare = append(m.Compare, &Compare{}) - if err := m.Compare[len(m.Compare)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Success", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Success = append(m.Success, &RequestOp{}) - if err := m.Success[len(m.Success)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Failure", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Failure = append(m.Failure, &RequestOp{}) - if err := m.Failure[len(m.Failure)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *TxnResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: TxnResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: TxnResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Succeeded", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Succeeded = bool(v != 0) - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Responses", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Responses = append(m.Responses, &ResponseOp{}) - if err := m.Responses[len(m.Responses)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *CompactionRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: CompactionRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: CompactionRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Revision", wireType) - } - m.Revision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Revision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Physical", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Physical = bool(v != 0) - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *CompactionResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: CompactionResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: CompactionResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *HashRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: HashRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HashRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *HashKVRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: HashKVRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HashKVRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Revision", wireType) - } - m.Revision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Revision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *HashKVResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: HashKVResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HashKVResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType) - } - m.Hash = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Hash |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CompactRevision", wireType) - } - m.CompactRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.CompactRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *HashResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: HashResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HashResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType) - } - m.Hash = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Hash |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *SnapshotRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SnapshotRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SnapshotRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *SnapshotResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SnapshotResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SnapshotResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RemainingBytes", wireType) - } - m.RemainingBytes = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RemainingBytes |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Blob", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Blob = append(m.Blob[:0], dAtA[iNdEx:postIndex]...) - if m.Blob == nil { - m.Blob = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *WatchRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: WatchRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: WatchRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CreateRequest", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &WatchCreateRequest{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.RequestUnion = &WatchRequest_CreateRequest{v} - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CancelRequest", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &WatchCancelRequest{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.RequestUnion = &WatchRequest_CancelRequest{v} - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *WatchCreateRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: WatchCreateRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: WatchCreateRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RangeEnd", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RangeEnd = append(m.RangeEnd[:0], dAtA[iNdEx:postIndex]...) - if m.RangeEnd == nil { - m.RangeEnd = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StartRevision", wireType) - } - m.StartRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StartRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ProgressNotify", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.ProgressNotify = bool(v != 0) - case 5: - if wireType == 0 { - var v WatchCreateRequest_FilterType - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (WatchCreateRequest_FilterType(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Filters = append(m.Filters, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + packedLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - for iNdEx < postIndex { - var v WatchCreateRequest_FilterType - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (WatchCreateRequest_FilterType(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Filters = append(m.Filters, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field Filters", wireType) - } - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PrevKv", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.PrevKv = bool(v != 0) - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *WatchCancelRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: WatchCancelRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: WatchCancelRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field WatchId", wireType) - } - m.WatchId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.WatchId |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *WatchResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: WatchResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: WatchResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field WatchId", wireType) - } - m.WatchId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.WatchId |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Created", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Created = bool(v != 0) - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Canceled", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Canceled = bool(v != 0) - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CompactRevision", wireType) - } - m.CompactRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.CompactRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CancelReason", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.CancelReason = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 11: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Events", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Events = append(m.Events, &mvccpb.Event{}) - if err := m.Events[len(m.Events)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseGrantRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseGrantRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseGrantRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TTL", wireType) - } - m.TTL = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TTL |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseGrantResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseGrantResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseGrantResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TTL", wireType) - } - m.TTL = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TTL |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Error", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Error = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseRevokeRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseRevokeRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseRevokeRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseRevokeResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseRevokeResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseRevokeResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseKeepAliveRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseKeepAliveRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseKeepAliveRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseKeepAliveResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseKeepAliveResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseKeepAliveResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TTL", wireType) - } - m.TTL = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TTL |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseTimeToLiveRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseTimeToLiveRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseTimeToLiveRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Keys", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Keys = bool(v != 0) - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseTimeToLiveResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseTimeToLiveResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseTimeToLiveResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TTL", wireType) - } - m.TTL = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TTL |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field GrantedTTL", wireType) - } - m.GrantedTTL = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.GrantedTTL |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Keys", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Keys = append(m.Keys, make([]byte, postIndex-iNdEx)) - copy(m.Keys[len(m.Keys)-1], dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseLeasesRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseLeasesRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseLeasesRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseStatus) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseStatus: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseStatus: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseLeasesResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseLeasesResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseLeasesResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Leases", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Leases = append(m.Leases, &LeaseStatus{}) - if err := m.Leases[len(m.Leases)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Member) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Member: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Member: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerURLs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerURLs = append(m.PeerURLs, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientURLs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientURLs = append(m.ClientURLs, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MemberAddRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MemberAddRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MemberAddRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerURLs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerURLs = append(m.PeerURLs, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MemberAddResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MemberAddResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MemberAddResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Member", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Member == nil { - m.Member = &Member{} - } - if err := m.Member.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Members", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Members = append(m.Members, &Member{}) - if err := m.Members[len(m.Members)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MemberRemoveRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MemberRemoveRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MemberRemoveRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MemberRemoveResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MemberRemoveResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MemberRemoveResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Members", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Members = append(m.Members, &Member{}) - if err := m.Members[len(m.Members)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MemberUpdateRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MemberUpdateRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MemberUpdateRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerURLs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerURLs = append(m.PeerURLs, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MemberUpdateResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MemberUpdateResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MemberUpdateResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Members", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Members = append(m.Members, &Member{}) - if err := m.Members[len(m.Members)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MemberListRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MemberListRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MemberListRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MemberListResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MemberListResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MemberListResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Members", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Members = append(m.Members, &Member{}) - if err := m.Members[len(m.Members)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *DefragmentRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: DefragmentRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: DefragmentRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *DefragmentResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: DefragmentResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: DefragmentResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MoveLeaderRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MoveLeaderRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MoveLeaderRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TargetID", wireType) - } - m.TargetID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TargetID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MoveLeaderResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MoveLeaderResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MoveLeaderResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AlarmRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AlarmRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AlarmRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Action", wireType) - } - m.Action = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Action |= (AlarmRequest_AlarmAction(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MemberID", wireType) - } - m.MemberID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MemberID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Alarm", wireType) - } - m.Alarm = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Alarm |= (AlarmType(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AlarmMember) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AlarmMember: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AlarmMember: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MemberID", wireType) - } - m.MemberID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MemberID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Alarm", wireType) - } - m.Alarm = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Alarm |= (AlarmType(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AlarmResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AlarmResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AlarmResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Alarms", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Alarms = append(m.Alarms, &AlarmMember{}) - if err := m.Alarms[len(m.Alarms)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *StatusRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: StatusRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: StatusRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *StatusResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: StatusResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: StatusResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Version = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field DbSize", wireType) - } - m.DbSize = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.DbSize |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Leader", wireType) - } - m.Leader = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Leader |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RaftIndex", wireType) - } - m.RaftIndex = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RaftIndex |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RaftTerm", wireType) - } - m.RaftTerm = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RaftTerm |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthEnableRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthEnableRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthEnableRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthDisableRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthDisableRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthDisableRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthenticateRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthenticateRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthenticateRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Password", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Password = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserAddRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserAddRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserAddRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Password", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Password = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserGetRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserGetRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserGetRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserDeleteRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserDeleteRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserDeleteRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserChangePasswordRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserChangePasswordRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserChangePasswordRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Password", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Password = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserGrantRoleRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserGrantRoleRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserGrantRoleRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field User", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.User = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Role", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Role = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserRevokeRoleRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserRevokeRoleRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserRevokeRoleRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Role", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Role = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleAddRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleAddRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleAddRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleGetRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleGetRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleGetRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Role", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Role = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserListRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserListRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserListRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleListRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleListRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleListRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleDeleteRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleDeleteRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleDeleteRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Role", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Role = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleGrantPermissionRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleGrantPermissionRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleGrantPermissionRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Perm", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Perm == nil { - m.Perm = &authpb.Permission{} - } - if err := m.Perm.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleRevokePermissionRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleRevokePermissionRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleRevokePermissionRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Role", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Role = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RangeEnd", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RangeEnd = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthEnableResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthEnableResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthEnableResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthDisableResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthDisableResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthDisableResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthenticateResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthenticateResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthenticateResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Token", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Token = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserAddResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserAddResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserAddResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserGetResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserGetResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserGetResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Roles", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Roles = append(m.Roles, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserDeleteResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserDeleteResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserDeleteResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserChangePasswordResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserChangePasswordResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserChangePasswordResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserGrantRoleResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserGrantRoleResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserGrantRoleResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserRevokeRoleResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserRevokeRoleResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserRevokeRoleResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleAddResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleAddResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleAddResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleGetResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleGetResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleGetResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Perm", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Perm = append(m.Perm, &authpb.Permission{}) - if err := m.Perm[len(m.Perm)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleListResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleListResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleListResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Roles", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Roles = append(m.Roles, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserListResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserListResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserListResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Users", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Users = append(m.Users, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleDeleteResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleDeleteResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleDeleteResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleGrantPermissionResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleGrantPermissionResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleGrantPermissionResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleRevokePermissionResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleRevokePermissionResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleRevokePermissionResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipRpc(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthRpc - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipRpc(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthRpc = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowRpc = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("rpc.proto", fileDescriptorRpc) } - -var fileDescriptorRpc = []byte{ - // 3669 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x5b, 0x5b, 0x6f, 0x23, 0xc7, - 0x72, 0xd6, 0x90, 0x22, 0x29, 0x16, 0x2f, 0xe2, 0xb6, 0xb4, 0xbb, 0x14, 0x77, 0x57, 0xab, 0xed, - 0xbd, 0x69, 0x2f, 0x16, 0x6d, 0xd9, 0xc9, 0xc3, 0x26, 0x30, 0xac, 0x95, 0xe8, 0x95, 0x2c, 0xad, - 0x24, 0x8f, 0xa8, 0xb5, 0x03, 0x38, 0x11, 0x46, 0x64, 0x4b, 0x62, 0x44, 0xce, 0x30, 0x33, 0x43, - 0xae, 0xb4, 0x31, 0x12, 0xc0, 0x71, 0x82, 0xbc, 0xe4, 0x25, 0x06, 0x82, 0xc4, 0xaf, 0x41, 0x60, - 0xf8, 0x07, 0x04, 0xf9, 0x0b, 0x41, 0x5e, 0x12, 0x20, 0x7f, 0xe0, 0xc0, 0xe7, 0xbc, 0x9c, 0x5f, - 0x70, 0x2e, 0x4f, 0x07, 0x7d, 0x9b, 0xe9, 0xb9, 0x51, 0xb2, 0x69, 0xfb, 0x45, 0x3b, 0x5d, 0x5d, - 0x5d, 0x55, 0x5d, 0xdd, 0x55, 0xd5, 0xfd, 0x35, 0x17, 0xf2, 0x76, 0xbf, 0xb5, 0xd4, 0xb7, 0x2d, - 0xd7, 0x42, 0x45, 0xe2, 0xb6, 0xda, 0x0e, 0xb1, 0x87, 0xc4, 0xee, 0x1f, 0xd6, 0x66, 0x8f, 0xad, - 0x63, 0x8b, 0x75, 0xd4, 0xe9, 0x17, 0xe7, 0xa9, 0xcd, 0x51, 0x9e, 0x7a, 0x6f, 0xd8, 0x6a, 0xb1, - 0x3f, 0xfd, 0xc3, 0xfa, 0xe9, 0x50, 0x74, 0xdd, 0x60, 0x5d, 0xc6, 0xc0, 0x3d, 0x61, 0x7f, 0xfa, - 0x87, 0xec, 0x1f, 0xd1, 0x79, 0xf3, 0xd8, 0xb2, 0x8e, 0xbb, 0xa4, 0x6e, 0xf4, 0x3b, 0x75, 0xc3, - 0x34, 0x2d, 0xd7, 0x70, 0x3b, 0x96, 0xe9, 0xf0, 0x5e, 0xfc, 0xf7, 0x1a, 0x94, 0x75, 0xe2, 0xf4, - 0x2d, 0xd3, 0x21, 0xeb, 0xc4, 0x68, 0x13, 0x1b, 0xdd, 0x02, 0x68, 0x75, 0x07, 0x8e, 0x4b, 0xec, - 0x83, 0x4e, 0xbb, 0xaa, 0x2d, 0x68, 0x8b, 0x93, 0x7a, 0x5e, 0x50, 0x36, 0xda, 0xe8, 0x06, 0xe4, - 0x7b, 0xa4, 0x77, 0xc8, 0x7b, 0x53, 0xac, 0x77, 0x8a, 0x13, 0x36, 0xda, 0xa8, 0x06, 0x53, 0x36, - 0x19, 0x76, 0x9c, 0x8e, 0x65, 0x56, 0xd3, 0x0b, 0xda, 0x62, 0x5a, 0xf7, 0xda, 0x74, 0xa0, 0x6d, - 0x1c, 0xb9, 0x07, 0x2e, 0xb1, 0x7b, 0xd5, 0x49, 0x3e, 0x90, 0x12, 0x9a, 0xc4, 0xee, 0xe1, 0x2f, - 0x33, 0x50, 0xd4, 0x0d, 0xf3, 0x98, 0xe8, 0xe4, 0xaf, 0x06, 0xc4, 0x71, 0x51, 0x05, 0xd2, 0xa7, - 0xe4, 0x9c, 0xa9, 0x2f, 0xea, 0xf4, 0x93, 0x8f, 0x37, 0x8f, 0xc9, 0x01, 0x31, 0xb9, 0xe2, 0x22, - 0x1d, 0x6f, 0x1e, 0x93, 0x86, 0xd9, 0x46, 0xb3, 0x90, 0xe9, 0x76, 0x7a, 0x1d, 0x57, 0x68, 0xe5, - 0x8d, 0x80, 0x39, 0x93, 0x21, 0x73, 0x56, 0x01, 0x1c, 0xcb, 0x76, 0x0f, 0x2c, 0xbb, 0x4d, 0xec, - 0x6a, 0x66, 0x41, 0x5b, 0x2c, 0x2f, 0xdf, 0x5b, 0x52, 0x17, 0x62, 0x49, 0x35, 0x68, 0x69, 0xcf, - 0xb2, 0xdd, 0x1d, 0xca, 0xab, 0xe7, 0x1d, 0xf9, 0x89, 0x3e, 0x84, 0x02, 0x13, 0xe2, 0x1a, 0xf6, - 0x31, 0x71, 0xab, 0x59, 0x26, 0xe5, 0xfe, 0x05, 0x52, 0x9a, 0x8c, 0x59, 0x67, 0xea, 0xf9, 0x37, - 0xc2, 0x50, 0x74, 0x88, 0xdd, 0x31, 0xba, 0x9d, 0x37, 0xc6, 0x61, 0x97, 0x54, 0x73, 0x0b, 0xda, - 0xe2, 0x94, 0x1e, 0xa0, 0xd1, 0xf9, 0x9f, 0x92, 0x73, 0xe7, 0xc0, 0x32, 0xbb, 0xe7, 0xd5, 0x29, - 0xc6, 0x30, 0x45, 0x09, 0x3b, 0x66, 0xf7, 0x9c, 0x2d, 0x9a, 0x35, 0x30, 0x5d, 0xde, 0x9b, 0x67, - 0xbd, 0x79, 0x46, 0x61, 0xdd, 0x8b, 0x50, 0xe9, 0x75, 0xcc, 0x83, 0x9e, 0xd5, 0x3e, 0xf0, 0x1c, - 0x02, 0xcc, 0x21, 0xe5, 0x5e, 0xc7, 0x7c, 0x69, 0xb5, 0x75, 0xe9, 0x16, 0xca, 0x69, 0x9c, 0x05, - 0x39, 0x0b, 0x82, 0xd3, 0x38, 0x53, 0x39, 0x97, 0x60, 0x86, 0xca, 0x6c, 0xd9, 0xc4, 0x70, 0x89, - 0xcf, 0x5c, 0x64, 0xcc, 0x57, 0x7a, 0x1d, 0x73, 0x95, 0xf5, 0x04, 0xf8, 0x8d, 0xb3, 0x08, 0x7f, - 0x49, 0xf0, 0x1b, 0x67, 0x41, 0x7e, 0xbc, 0x04, 0x79, 0xcf, 0xe7, 0x68, 0x0a, 0x26, 0xb7, 0x77, - 0xb6, 0x1b, 0x95, 0x09, 0x04, 0x90, 0x5d, 0xd9, 0x5b, 0x6d, 0x6c, 0xaf, 0x55, 0x34, 0x54, 0x80, - 0xdc, 0x5a, 0x83, 0x37, 0x52, 0xf8, 0x39, 0x80, 0xef, 0x5d, 0x94, 0x83, 0xf4, 0x66, 0xe3, 0xcf, - 0x2a, 0x13, 0x94, 0xe7, 0x55, 0x43, 0xdf, 0xdb, 0xd8, 0xd9, 0xae, 0x68, 0x74, 0xf0, 0xaa, 0xde, - 0x58, 0x69, 0x36, 0x2a, 0x29, 0xca, 0xf1, 0x72, 0x67, 0xad, 0x92, 0x46, 0x79, 0xc8, 0xbc, 0x5a, - 0xd9, 0xda, 0x6f, 0x54, 0x26, 0xf1, 0x57, 0x1a, 0x94, 0xc4, 0x7a, 0xf1, 0x98, 0x40, 0xef, 0x41, - 0xf6, 0x84, 0xc5, 0x05, 0xdb, 0x8a, 0x85, 0xe5, 0x9b, 0xa1, 0xc5, 0x0d, 0xc4, 0x8e, 0x2e, 0x78, - 0x11, 0x86, 0xf4, 0xe9, 0xd0, 0xa9, 0xa6, 0x16, 0xd2, 0x8b, 0x85, 0xe5, 0xca, 0x12, 0x0f, 0xd8, - 0xa5, 0x4d, 0x72, 0xfe, 0xca, 0xe8, 0x0e, 0x88, 0x4e, 0x3b, 0x11, 0x82, 0xc9, 0x9e, 0x65, 0x13, - 0xb6, 0x63, 0xa7, 0x74, 0xf6, 0x4d, 0xb7, 0x31, 0x5b, 0x34, 0xb1, 0x5b, 0x79, 0x03, 0x7f, 0xab, - 0x01, 0xec, 0x0e, 0xdc, 0xe4, 0xd0, 0x98, 0x85, 0xcc, 0x90, 0x0a, 0x16, 0x61, 0xc1, 0x1b, 0x2c, - 0x26, 0x88, 0xe1, 0x10, 0x2f, 0x26, 0x68, 0x03, 0x5d, 0x87, 0x5c, 0xdf, 0x26, 0xc3, 0x83, 0xd3, - 0x21, 0x53, 0x32, 0xa5, 0x67, 0x69, 0x73, 0x73, 0x88, 0xee, 0x40, 0xb1, 0x73, 0x6c, 0x5a, 0x36, - 0x39, 0xe0, 0xb2, 0x32, 0xac, 0xb7, 0xc0, 0x69, 0xcc, 0x6e, 0x85, 0x85, 0x0b, 0xce, 0xaa, 0x2c, - 0x5b, 0x94, 0x84, 0x4d, 0x28, 0x30, 0x53, 0xc7, 0x72, 0xdf, 0x23, 0xdf, 0xc6, 0x14, 0x1b, 0x16, - 0x75, 0xa1, 0xb0, 0x1a, 0x7f, 0x06, 0x68, 0x8d, 0x74, 0x89, 0x4b, 0xc6, 0xc9, 0x1e, 0x8a, 0x4f, - 0xd2, 0xaa, 0x4f, 0xf0, 0x3f, 0x6b, 0x30, 0x13, 0x10, 0x3f, 0xd6, 0xb4, 0xaa, 0x90, 0x6b, 0x33, - 0x61, 0xdc, 0x82, 0xb4, 0x2e, 0x9b, 0xe8, 0x09, 0x4c, 0x09, 0x03, 0x9c, 0x6a, 0x3a, 0x61, 0xd3, - 0xe4, 0xb8, 0x4d, 0x0e, 0xfe, 0x36, 0x05, 0x79, 0x31, 0xd1, 0x9d, 0x3e, 0x5a, 0x81, 0x92, 0xcd, - 0x1b, 0x07, 0x6c, 0x3e, 0xc2, 0xa2, 0x5a, 0x72, 0x12, 0x5a, 0x9f, 0xd0, 0x8b, 0x62, 0x08, 0x23, - 0xa3, 0x3f, 0x81, 0x82, 0x14, 0xd1, 0x1f, 0xb8, 0xc2, 0xe5, 0xd5, 0xa0, 0x00, 0x7f, 0xff, 0xad, - 0x4f, 0xe8, 0x20, 0xd8, 0x77, 0x07, 0x2e, 0x6a, 0xc2, 0xac, 0x1c, 0xcc, 0x67, 0x23, 0xcc, 0x48, - 0x33, 0x29, 0x0b, 0x41, 0x29, 0xd1, 0xa5, 0x5a, 0x9f, 0xd0, 0x91, 0x18, 0xaf, 0x74, 0xaa, 0x26, - 0xb9, 0x67, 0x3c, 0x79, 0x47, 0x4c, 0x6a, 0x9e, 0x99, 0x51, 0x93, 0x9a, 0x67, 0xe6, 0xf3, 0x3c, - 0xe4, 0x44, 0x0b, 0xff, 0x57, 0x0a, 0x40, 0xae, 0xc6, 0x4e, 0x1f, 0xad, 0x41, 0xd9, 0x16, 0xad, - 0x80, 0xb7, 0x6e, 0xc4, 0x7a, 0x4b, 0x2c, 0xe2, 0x84, 0x5e, 0x92, 0x83, 0xb8, 0x71, 0xef, 0x43, - 0xd1, 0x93, 0xe2, 0x3b, 0x6c, 0x2e, 0xc6, 0x61, 0x9e, 0x84, 0x82, 0x1c, 0x40, 0x5d, 0xf6, 0x09, - 0x5c, 0xf5, 0xc6, 0xc7, 0xf8, 0xec, 0xce, 0x08, 0x9f, 0x79, 0x02, 0x67, 0xa4, 0x04, 0xd5, 0x6b, - 0xaa, 0x61, 0xbe, 0xdb, 0xe6, 0x62, 0xdc, 0x16, 0x35, 0x8c, 0x3a, 0x0e, 0x68, 0xbd, 0xe4, 0x4d, - 0xfc, 0xeb, 0x34, 0xe4, 0x56, 0xad, 0x5e, 0xdf, 0xb0, 0xe9, 0x6a, 0x64, 0x6d, 0xe2, 0x0c, 0xba, - 0x2e, 0x73, 0x57, 0x79, 0xf9, 0x6e, 0x50, 0xa2, 0x60, 0x93, 0xff, 0xea, 0x8c, 0x55, 0x17, 0x43, - 0xe8, 0x60, 0x51, 0x1e, 0x53, 0x97, 0x18, 0x2c, 0x8a, 0xa3, 0x18, 0x22, 0x03, 0x39, 0xed, 0x07, - 0x72, 0x0d, 0x72, 0x43, 0x62, 0xfb, 0x25, 0x7d, 0x7d, 0x42, 0x97, 0x04, 0xf4, 0x08, 0xa6, 0xc3, - 0xe5, 0x25, 0x23, 0x78, 0xca, 0xad, 0x60, 0x35, 0xba, 0x0b, 0xc5, 0x40, 0x8d, 0xcb, 0x0a, 0xbe, - 0x42, 0x4f, 0x29, 0x71, 0xd7, 0x64, 0x5e, 0xa5, 0xf5, 0xb8, 0xb8, 0x3e, 0x21, 0x33, 0xeb, 0x35, - 0x99, 0x59, 0xa7, 0xc4, 0x28, 0x91, 0x5b, 0x03, 0x49, 0xe6, 0x83, 0x60, 0x92, 0xc1, 0x1f, 0x40, - 0x29, 0xe0, 0x20, 0x5a, 0x77, 0x1a, 0x1f, 0xef, 0xaf, 0x6c, 0xf1, 0x22, 0xf5, 0x82, 0xd5, 0x25, - 0xbd, 0xa2, 0xd1, 0x5a, 0xb7, 0xd5, 0xd8, 0xdb, 0xab, 0xa4, 0x50, 0x09, 0xf2, 0xdb, 0x3b, 0xcd, - 0x03, 0xce, 0x95, 0xc6, 0x2f, 0x3c, 0x09, 0xa2, 0xc8, 0x29, 0xb5, 0x6d, 0x42, 0xa9, 0x6d, 0x9a, - 0xac, 0x6d, 0x29, 0xbf, 0xb6, 0xb1, 0x32, 0xb7, 0xd5, 0x58, 0xd9, 0x6b, 0x54, 0x26, 0x9f, 0x97, - 0xa1, 0xc8, 0xfd, 0x7b, 0x30, 0x30, 0x69, 0xa9, 0xfd, 0x77, 0x0d, 0xc0, 0x8f, 0x26, 0x54, 0x87, - 0x5c, 0x8b, 0xeb, 0xa9, 0x6a, 0x2c, 0x19, 0x5d, 0x8d, 0x5d, 0x32, 0x5d, 0x72, 0xa1, 0x77, 0x20, - 0xe7, 0x0c, 0x5a, 0x2d, 0xe2, 0xc8, 0x92, 0x77, 0x3d, 0x9c, 0x0f, 0x45, 0xb6, 0xd2, 0x25, 0x1f, - 0x1d, 0x72, 0x64, 0x74, 0xba, 0x03, 0x56, 0x00, 0x47, 0x0f, 0x11, 0x7c, 0xf8, 0xdf, 0x34, 0x28, - 0x28, 0x9b, 0xf7, 0x07, 0x26, 0xe1, 0x9b, 0x90, 0x67, 0x36, 0x90, 0xb6, 0x48, 0xc3, 0x53, 0xba, - 0x4f, 0x40, 0x7f, 0x0c, 0x79, 0x19, 0x01, 0x32, 0x13, 0x57, 0xe3, 0xc5, 0xee, 0xf4, 0x75, 0x9f, - 0x15, 0x6f, 0xc2, 0x15, 0xe6, 0x95, 0x16, 0x3d, 0x5c, 0x4b, 0x3f, 0xaa, 0xc7, 0x4f, 0x2d, 0x74, - 0xfc, 0xac, 0xc1, 0x54, 0xff, 0xe4, 0xdc, 0xe9, 0xb4, 0x8c, 0xae, 0xb0, 0xc2, 0x6b, 0xe3, 0x8f, - 0x00, 0xa9, 0xc2, 0xc6, 0x99, 0x2e, 0x2e, 0x41, 0x61, 0xdd, 0x70, 0x4e, 0x84, 0x49, 0xf8, 0x09, - 0x94, 0x68, 0x73, 0xf3, 0xd5, 0x25, 0x6c, 0x64, 0x97, 0x03, 0xc9, 0x3d, 0x96, 0xcf, 0x11, 0x4c, - 0x9e, 0x18, 0xce, 0x09, 0x9b, 0x68, 0x49, 0x67, 0xdf, 0xe8, 0x11, 0x54, 0x5a, 0x7c, 0x92, 0x07, - 0xa1, 0x2b, 0xc3, 0xb4, 0xa0, 0x7b, 0x27, 0xc1, 0x4f, 0xa1, 0xc8, 0xe7, 0xf0, 0x63, 0x1b, 0x81, - 0xaf, 0xc0, 0xf4, 0x9e, 0x69, 0xf4, 0x9d, 0x13, 0x4b, 0x56, 0x37, 0x3a, 0xe9, 0x8a, 0x4f, 0x1b, - 0x4b, 0xe3, 0x43, 0x98, 0xb6, 0x49, 0xcf, 0xe8, 0x98, 0x1d, 0xf3, 0xf8, 0xe0, 0xf0, 0xdc, 0x25, - 0x8e, 0xb8, 0x30, 0x95, 0x3d, 0xf2, 0x73, 0x4a, 0xa5, 0xa6, 0x1d, 0x76, 0xad, 0x43, 0x91, 0xe6, - 0xd8, 0x37, 0xfe, 0x4f, 0x0d, 0x8a, 0x9f, 0x18, 0x6e, 0x4b, 0x2e, 0x1d, 0xda, 0x80, 0xb2, 0x97, - 0xdc, 0x18, 0x45, 0xd8, 0x12, 0x2a, 0xb1, 0x6c, 0x8c, 0x3c, 0x4a, 0xcb, 0xea, 0x58, 0x6a, 0xa9, - 0x04, 0x26, 0xca, 0x30, 0x5b, 0xa4, 0xeb, 0x89, 0x4a, 0x25, 0x8b, 0x62, 0x8c, 0xaa, 0x28, 0x95, - 0xf0, 0x7c, 0xda, 0x3f, 0x7e, 0xf0, 0x5c, 0xf2, 0x75, 0x0a, 0x50, 0xd4, 0x86, 0xef, 0x7b, 0x22, - 0xbb, 0x0f, 0x65, 0xc7, 0x35, 0xec, 0xc8, 0xde, 0x28, 0x31, 0xaa, 0x97, 0xa0, 0x1f, 0xc2, 0x74, - 0xdf, 0xb6, 0x8e, 0x6d, 0xe2, 0x38, 0x07, 0xa6, 0xe5, 0x76, 0x8e, 0xce, 0xc5, 0xa1, 0xb6, 0x2c, - 0xc9, 0xdb, 0x8c, 0x8a, 0x1a, 0x90, 0x3b, 0xea, 0x74, 0x5d, 0x62, 0x3b, 0xd5, 0xcc, 0x42, 0x7a, - 0xb1, 0xbc, 0xfc, 0xe4, 0x22, 0xaf, 0x2d, 0x7d, 0xc8, 0xf8, 0x9b, 0xe7, 0x7d, 0xa2, 0xcb, 0xb1, - 0xea, 0x41, 0x31, 0x1b, 0x38, 0x28, 0xde, 0x07, 0xf0, 0xf9, 0x69, 0xaa, 0xdd, 0xde, 0xd9, 0xdd, - 0x6f, 0x56, 0x26, 0x50, 0x11, 0xa6, 0xb6, 0x77, 0xd6, 0x1a, 0x5b, 0x0d, 0x9a, 0x97, 0x71, 0x5d, - 0xfa, 0x46, 0xf5, 0x21, 0x9a, 0x83, 0xa9, 0xd7, 0x94, 0x2a, 0xef, 0xdb, 0x69, 0x3d, 0xc7, 0xda, - 0x1b, 0x6d, 0xfc, 0x4f, 0x29, 0x28, 0x89, 0x5d, 0x30, 0xd6, 0x56, 0x54, 0x55, 0xa4, 0x02, 0x2a, - 0xe8, 0xa9, 0x94, 0xef, 0x8e, 0xb6, 0x38, 0xfc, 0xca, 0x26, 0xcd, 0x0d, 0x7c, 0xb1, 0x49, 0x5b, - 0xb8, 0xd5, 0x6b, 0xc7, 0x86, 0x6f, 0x26, 0x36, 0x7c, 0xd1, 0x5d, 0x28, 0x79, 0xbb, 0xcd, 0x70, - 0x44, 0xad, 0xcd, 0xeb, 0x45, 0xb9, 0x91, 0x28, 0x0d, 0xdd, 0x87, 0x2c, 0x19, 0x12, 0xd3, 0x75, - 0xaa, 0x05, 0x96, 0x75, 0x4b, 0xf2, 0xfc, 0xdb, 0xa0, 0x54, 0x5d, 0x74, 0xe2, 0x3f, 0x82, 0x2b, - 0xec, 0x9e, 0xf1, 0xc2, 0x36, 0x4c, 0xf5, 0x42, 0xd4, 0x6c, 0x6e, 0x09, 0xd7, 0xd1, 0x4f, 0x54, - 0x86, 0xd4, 0xc6, 0x9a, 0x98, 0x68, 0x6a, 0x63, 0x0d, 0x7f, 0xa1, 0x01, 0x52, 0xc7, 0x8d, 0xe5, - 0xcb, 0x90, 0x70, 0xa9, 0x3e, 0xed, 0xab, 0x9f, 0x85, 0x0c, 0xb1, 0x6d, 0xcb, 0x66, 0x5e, 0xcb, - 0xeb, 0xbc, 0x81, 0xef, 0x09, 0x1b, 0x74, 0x32, 0xb4, 0x4e, 0xbd, 0xc0, 0xe0, 0xd2, 0x34, 0xcf, - 0xd4, 0x4d, 0x98, 0x09, 0x70, 0x8d, 0x95, 0xfd, 0x1f, 0xc2, 0x55, 0x26, 0x6c, 0x93, 0x90, 0xfe, - 0x4a, 0xb7, 0x33, 0x4c, 0xd4, 0xda, 0x87, 0x6b, 0x61, 0xc6, 0x9f, 0xd6, 0x47, 0xf8, 0x4f, 0x85, - 0xc6, 0x66, 0xa7, 0x47, 0x9a, 0xd6, 0x56, 0xb2, 0x6d, 0x34, 0x3b, 0x9e, 0x92, 0x73, 0x47, 0x94, - 0x49, 0xf6, 0x8d, 0xff, 0x43, 0x83, 0xeb, 0x91, 0xe1, 0x3f, 0xf1, 0xaa, 0xce, 0x03, 0x1c, 0xd3, - 0xed, 0x43, 0xda, 0xb4, 0x83, 0xdf, 0xd0, 0x15, 0x8a, 0x67, 0x27, 0x4d, 0x30, 0x45, 0x61, 0xe7, - 0xac, 0x58, 0x73, 0xf6, 0xc7, 0x91, 0x35, 0xe6, 0x16, 0x14, 0x18, 0x61, 0xcf, 0x35, 0xdc, 0x81, - 0x13, 0x59, 0x8c, 0xbf, 0x11, 0x5b, 0x40, 0x0e, 0x1a, 0x6b, 0x5e, 0xef, 0x40, 0x96, 0x1d, 0x4e, - 0xe5, 0xd1, 0x2c, 0x74, 0x1b, 0x50, 0xec, 0xd0, 0x05, 0x23, 0x3e, 0x81, 0xec, 0x4b, 0x86, 0xe8, - 0x29, 0x96, 0x4d, 0xca, 0xa5, 0x30, 0x8d, 0x1e, 0xc7, 0x19, 0xf2, 0x3a, 0xfb, 0x66, 0x27, 0x19, - 0x42, 0xec, 0x7d, 0x7d, 0x8b, 0x9f, 0x98, 0xf2, 0xba, 0xd7, 0xa6, 0x2e, 0x6b, 0x75, 0x3b, 0xc4, - 0x74, 0x59, 0xef, 0x24, 0xeb, 0x55, 0x28, 0x78, 0x09, 0x2a, 0x5c, 0xd3, 0x4a, 0xbb, 0xad, 0x9c, - 0x48, 0x3c, 0x79, 0x5a, 0x50, 0x1e, 0xfe, 0x46, 0x83, 0x2b, 0xca, 0x80, 0xb1, 0x1c, 0xf3, 0x14, - 0xb2, 0x1c, 0xb7, 0x14, 0xc5, 0x6f, 0x36, 0x38, 0x8a, 0xab, 0xd1, 0x05, 0x0f, 0x5a, 0x82, 0x1c, - 0xff, 0x92, 0xc7, 0xc2, 0x78, 0x76, 0xc9, 0x84, 0xef, 0xc3, 0x8c, 0x20, 0x91, 0x9e, 0x15, 0xb7, - 0xb7, 0x99, 0x43, 0xf1, 0xe7, 0x30, 0x1b, 0x64, 0x1b, 0x6b, 0x4a, 0x8a, 0x91, 0xa9, 0xcb, 0x18, - 0xb9, 0x22, 0x8d, 0xdc, 0xef, 0xb7, 0x95, 0x5a, 0x1d, 0x5e, 0x75, 0x75, 0x45, 0x52, 0xa1, 0x15, - 0xf1, 0x26, 0x20, 0x45, 0xfc, 0xac, 0x13, 0x98, 0x91, 0xdb, 0x61, 0xab, 0xe3, 0x78, 0x27, 0xb8, - 0x37, 0x80, 0x54, 0xe2, 0xcf, 0x6d, 0xd0, 0x1a, 0x39, 0xb2, 0x8d, 0xe3, 0x1e, 0xf1, 0xea, 0x13, - 0x3d, 0xcf, 0xab, 0xc4, 0xb1, 0x32, 0x7a, 0x1d, 0xae, 0xbc, 0xb4, 0x86, 0x34, 0x35, 0x50, 0xaa, - 0x1f, 0x32, 0xfc, 0x3e, 0xe7, 0x2d, 0x9b, 0xd7, 0xa6, 0xca, 0xd5, 0x01, 0x63, 0x29, 0xff, 0x5f, - 0x0d, 0x8a, 0x2b, 0x5d, 0xc3, 0xee, 0x49, 0xc5, 0xef, 0x43, 0x96, 0xdf, 0x52, 0x04, 0x30, 0xf0, - 0x20, 0x28, 0x46, 0xe5, 0xe5, 0x8d, 0x15, 0x7e, 0xa7, 0x11, 0xa3, 0xa8, 0xe1, 0xe2, 0xed, 0x60, - 0x2d, 0xf4, 0x96, 0xb0, 0x86, 0xde, 0x82, 0x8c, 0x41, 0x87, 0xb0, 0x14, 0x5c, 0x0e, 0xdf, 0x0f, - 0x99, 0x34, 0x76, 0x38, 0xe3, 0x5c, 0xf8, 0x3d, 0x28, 0x28, 0x1a, 0xe8, 0x0d, 0xf8, 0x45, 0x43, - 0x1c, 0xc0, 0x56, 0x56, 0x9b, 0x1b, 0xaf, 0xf8, 0xc5, 0xb8, 0x0c, 0xb0, 0xd6, 0xf0, 0xda, 0x29, - 0xfc, 0xa9, 0x18, 0x25, 0xf2, 0x9d, 0x6a, 0x8f, 0x96, 0x64, 0x4f, 0xea, 0x52, 0xf6, 0x9c, 0x41, - 0x49, 0x4c, 0x7f, 0xdc, 0xf4, 0xcd, 0xe4, 0x25, 0xa4, 0x6f, 0xc5, 0x78, 0x5d, 0x30, 0xe2, 0x69, - 0x28, 0x89, 0x84, 0x2e, 0xf6, 0xdf, 0xff, 0x68, 0x50, 0x96, 0x94, 0x71, 0x01, 0x4c, 0x89, 0xbd, - 0xf0, 0x0a, 0xe0, 0x21, 0x2f, 0xd7, 0x20, 0xdb, 0x3e, 0xdc, 0xeb, 0xbc, 0x91, 0x60, 0xb3, 0x68, - 0x51, 0x7a, 0x97, 0xeb, 0xe1, 0x2f, 0x3e, 0xa2, 0x45, 0x6f, 0xe1, 0xb6, 0x71, 0xe4, 0x6e, 0x98, - 0x6d, 0x72, 0xc6, 0xce, 0x8d, 0x93, 0xba, 0x4f, 0x60, 0x97, 0x52, 0xf1, 0x32, 0xc4, 0x0e, 0x8b, - 0xea, 0x4b, 0xd1, 0x0c, 0x5c, 0x59, 0x19, 0xb8, 0x27, 0x0d, 0xd3, 0x38, 0xec, 0xca, 0x8c, 0x45, - 0xcb, 0x2c, 0x25, 0xae, 0x75, 0x1c, 0x95, 0xda, 0x80, 0x19, 0x4a, 0x25, 0xa6, 0xdb, 0x69, 0x29, - 0xe9, 0x4d, 0x16, 0x31, 0x2d, 0x54, 0xc4, 0x0c, 0xc7, 0x79, 0x6d, 0xd9, 0x6d, 0x31, 0x35, 0xaf, - 0x8d, 0xd7, 0xb8, 0xf0, 0x7d, 0x27, 0x50, 0xa6, 0xbe, 0xaf, 0x94, 0x45, 0x5f, 0xca, 0x0b, 0xe2, - 0x8e, 0x90, 0x82, 0x9f, 0xc0, 0x55, 0xc9, 0x29, 0xc0, 0xbd, 0x11, 0xcc, 0x3b, 0x70, 0x4b, 0x32, - 0xaf, 0x9e, 0xd0, 0xdb, 0xd3, 0xae, 0x50, 0xf8, 0x43, 0xed, 0x7c, 0x0e, 0x55, 0xcf, 0x4e, 0x76, - 0x58, 0xb6, 0xba, 0xaa, 0x01, 0x03, 0x47, 0xec, 0x99, 0xbc, 0xce, 0xbe, 0x29, 0xcd, 0xb6, 0xba, - 0xde, 0x91, 0x80, 0x7e, 0xe3, 0x55, 0x98, 0x93, 0x32, 0xc4, 0x31, 0x36, 0x28, 0x24, 0x62, 0x50, - 0x9c, 0x10, 0xe1, 0x30, 0x3a, 0x74, 0xb4, 0xdb, 0x55, 0xce, 0xa0, 0x6b, 0x99, 0x4c, 0x4d, 0x91, - 0x79, 0x95, 0xef, 0x08, 0x6a, 0x98, 0x5a, 0x31, 0x04, 0x99, 0x0a, 0x50, 0xc9, 0x62, 0x21, 0x28, - 0x39, 0xb2, 0x10, 0x11, 0xd1, 0x9f, 0xc1, 0xbc, 0x67, 0x04, 0xf5, 0xdb, 0x2e, 0xb1, 0x7b, 0x1d, - 0xc7, 0x51, 0xe0, 0xa0, 0xb8, 0x89, 0x3f, 0x80, 0xc9, 0x3e, 0x11, 0x39, 0xa5, 0xb0, 0x8c, 0x96, - 0xf8, 0xfb, 0xed, 0x92, 0x32, 0x98, 0xf5, 0xe3, 0x36, 0xdc, 0x96, 0xd2, 0xb9, 0x47, 0x63, 0xc5, - 0x87, 0x8d, 0x92, 0xb7, 0x6e, 0xee, 0xd6, 0xe8, 0xad, 0x3b, 0xcd, 0xd7, 0xde, 0x83, 0x28, 0x3f, - 0xe2, 0x8e, 0x94, 0xb1, 0x35, 0x56, 0xad, 0xd8, 0xe4, 0x3e, 0xf5, 0x42, 0x72, 0x2c, 0x61, 0x87, - 0x30, 0x1b, 0x8c, 0xe4, 0xb1, 0xd2, 0xd8, 0x2c, 0x64, 0x5c, 0xeb, 0x94, 0xc8, 0x24, 0xc6, 0x1b, - 0xd2, 0x60, 0x2f, 0xcc, 0xc7, 0x32, 0xd8, 0xf0, 0x85, 0xb1, 0x2d, 0x39, 0xae, 0xbd, 0x74, 0x35, - 0xe5, 0xe1, 0x8b, 0x37, 0xf0, 0x36, 0x5c, 0x0b, 0xa7, 0x89, 0xb1, 0x4c, 0x7e, 0xc5, 0x37, 0x70, - 0x5c, 0x26, 0x19, 0x4b, 0xee, 0xc7, 0x7e, 0x32, 0x50, 0x12, 0xca, 0x58, 0x22, 0x75, 0xa8, 0xc5, - 0xe5, 0x97, 0x1f, 0x63, 0xbf, 0x7a, 0xe9, 0x66, 0x2c, 0x61, 0x8e, 0x2f, 0x6c, 0xfc, 0xe5, 0xf7, - 0x73, 0x44, 0x7a, 0x64, 0x8e, 0x10, 0x41, 0xe2, 0x67, 0xb1, 0x9f, 0x60, 0xd3, 0x09, 0x1d, 0x7e, - 0x02, 0x1d, 0x57, 0x07, 0xad, 0x21, 0x9e, 0x0e, 0xd6, 0x90, 0x1b, 0x5b, 0x4d, 0xbb, 0x63, 0x2d, - 0xc6, 0x27, 0x7e, 0xee, 0x8c, 0x64, 0xe6, 0xb1, 0x04, 0x7f, 0x0a, 0x0b, 0xc9, 0x49, 0x79, 0x1c, - 0xc9, 0x8f, 0xeb, 0x90, 0xf7, 0x0e, 0x94, 0xca, 0x6f, 0x1f, 0x0a, 0x90, 0xdb, 0xde, 0xd9, 0xdb, - 0x5d, 0x59, 0x6d, 0xf0, 0x1f, 0x3f, 0xac, 0xee, 0xe8, 0xfa, 0xfe, 0x6e, 0xb3, 0x92, 0x5a, 0xfe, - 0x6d, 0x1a, 0x52, 0x9b, 0xaf, 0xd0, 0x9f, 0x43, 0x86, 0xbf, 0x04, 0x8e, 0x78, 0xfe, 0xad, 0x8d, - 0x7a, 0xec, 0xc4, 0x37, 0xbe, 0xf8, 0xff, 0x5f, 0x7d, 0x95, 0xba, 0x8a, 0x2b, 0xf5, 0xe1, 0xbb, - 0x87, 0xc4, 0x35, 0xea, 0xa7, 0xc3, 0x3a, 0xab, 0x0f, 0xcf, 0xb4, 0xc7, 0x68, 0x1f, 0xd2, 0xbb, - 0x03, 0x17, 0x25, 0x3e, 0x0d, 0xd7, 0x92, 0xdf, 0x40, 0xf1, 0x1c, 0x13, 0x3c, 0x83, 0xcb, 0x8a, - 0xe0, 0xfe, 0xc0, 0xa5, 0x62, 0x07, 0x50, 0x50, 0x5f, 0x31, 0x2f, 0x7c, 0x33, 0xae, 0x5d, 0xfc, - 0x42, 0x8a, 0xef, 0x30, 0x75, 0x37, 0xf0, 0x35, 0x45, 0x1d, 0x7f, 0x6b, 0x55, 0x67, 0xd3, 0x3c, - 0x33, 0x51, 0xe2, 0xab, 0x72, 0x2d, 0xf9, 0xe1, 0x34, 0x76, 0x36, 0xee, 0x99, 0x49, 0xc5, 0x9a, - 0xe2, 0xdd, 0xb4, 0xe5, 0xa2, 0xdb, 0x31, 0xef, 0x66, 0xea, 0x0b, 0x51, 0x6d, 0x21, 0x99, 0x41, - 0x28, 0x5a, 0x60, 0x8a, 0x6a, 0xf8, 0xaa, 0xa2, 0xa8, 0xe5, 0xb1, 0x3d, 0xd3, 0x1e, 0x2f, 0x1f, - 0x43, 0x86, 0x21, 0xc4, 0xe8, 0x2f, 0xe4, 0x47, 0x2d, 0x06, 0xdb, 0x4e, 0x58, 0xfc, 0x00, 0xb6, - 0x8c, 0xab, 0x4c, 0x19, 0xc2, 0x25, 0xa9, 0x8c, 0x61, 0xc4, 0xcf, 0xb4, 0xc7, 0x8b, 0xda, 0xdb, - 0xda, 0xf2, 0x6f, 0x26, 0x21, 0xc3, 0xe0, 0x22, 0x64, 0x01, 0xf8, 0x68, 0x6a, 0x78, 0x96, 0x11, - 0x7c, 0x36, 0x3c, 0xcb, 0x28, 0x10, 0x8b, 0xe7, 0x99, 0xe2, 0x2a, 0x9e, 0x91, 0x8a, 0x19, 0x12, - 0x55, 0x67, 0xe0, 0x1a, 0xf5, 0xe9, 0x50, 0x00, 0x66, 0x3c, 0xcc, 0x50, 0x9c, 0xc0, 0x00, 0xaa, - 0x1a, 0xde, 0x21, 0x31, 0x88, 0x2a, 0xc6, 0x4c, 0xe7, 0x4d, 0x7c, 0x5d, 0xf1, 0x2c, 0x57, 0x6b, - 0x33, 0x46, 0xaa, 0xf7, 0xef, 0x34, 0x28, 0x07, 0x71, 0x51, 0x74, 0x37, 0x46, 0x72, 0x18, 0x5e, - 0xad, 0xdd, 0x1b, 0xcd, 0x94, 0x64, 0x01, 0x57, 0x7f, 0x4a, 0x48, 0xdf, 0xa0, 0x8c, 0xc2, 0xf1, - 0xe8, 0x1f, 0x34, 0x98, 0x0e, 0x81, 0x9d, 0x28, 0x4e, 0x43, 0x04, 0x4a, 0xad, 0xdd, 0xbf, 0x80, - 0x4b, 0x18, 0xf2, 0x80, 0x19, 0xb2, 0x80, 0x6f, 0x44, 0x5c, 0xe1, 0x76, 0x7a, 0xc4, 0xb5, 0x84, - 0x31, 0xde, 0x32, 0x70, 0x60, 0x32, 0x76, 0x19, 0x02, 0x40, 0x67, 0xec, 0x32, 0x04, 0x51, 0xcd, - 0x11, 0xcb, 0xc0, 0xd1, 0x48, 0xba, 0xc5, 0x7f, 0x97, 0x86, 0xdc, 0x2a, 0xff, 0x05, 0x22, 0x72, - 0x20, 0xef, 0x21, 0x80, 0x68, 0x3e, 0x0e, 0x8d, 0xf1, 0x6f, 0x0b, 0xb5, 0xdb, 0x89, 0xfd, 0x42, - 0xfb, 0x7d, 0xa6, 0xfd, 0x36, 0xae, 0x49, 0xed, 0xe2, 0x87, 0x8e, 0x75, 0x7e, 0xed, 0xaf, 0x1b, - 0xed, 0x36, 0x9d, 0xf8, 0xdf, 0x42, 0x51, 0x85, 0xe9, 0xd0, 0x9d, 0x58, 0x14, 0x48, 0x45, 0xfa, - 0x6a, 0x78, 0x14, 0x8b, 0xd0, 0xbe, 0xc8, 0xb4, 0x63, 0x7c, 0x2b, 0x41, 0xbb, 0xcd, 0xd8, 0x03, - 0x06, 0x70, 0x98, 0x2d, 0xde, 0x80, 0x00, 0x8a, 0x17, 0x6f, 0x40, 0x10, 0xa5, 0xbb, 0xd0, 0x80, - 0x01, 0x63, 0xa7, 0x06, 0xbc, 0x06, 0xf0, 0x41, 0x35, 0x14, 0xeb, 0x57, 0xe5, 0xea, 0x14, 0x0e, - 0xf9, 0x28, 0x1e, 0x17, 0xdd, 0x73, 0x21, 0xd5, 0xdd, 0x8e, 0x43, 0x43, 0x7f, 0xf9, 0x9b, 0x2c, - 0x14, 0x5e, 0x1a, 0x1d, 0xd3, 0x25, 0xa6, 0x61, 0xb6, 0x08, 0x3a, 0x82, 0x0c, 0x2b, 0x8d, 0xe1, - 0x2c, 0xa7, 0x62, 0x4d, 0xe1, 0x2c, 0x17, 0x00, 0x62, 0xf0, 0x3d, 0xa6, 0x79, 0x1e, 0xcf, 0x49, - 0xcd, 0x3d, 0x5f, 0x7c, 0x9d, 0x61, 0x28, 0x74, 0xc2, 0x7f, 0x09, 0x59, 0x01, 0xcf, 0x87, 0x84, - 0x05, 0xb0, 0x95, 0xda, 0xcd, 0xf8, 0xce, 0xa4, 0xed, 0xa5, 0xaa, 0x72, 0x18, 0x2f, 0xd5, 0xf5, - 0x06, 0xc0, 0x07, 0x08, 0xc3, 0xce, 0x8d, 0xe0, 0x89, 0xb5, 0x85, 0x64, 0x06, 0xa1, 0xf7, 0x11, - 0xd3, 0x7b, 0x17, 0xcf, 0xc7, 0xe9, 0x6d, 0x7b, 0xfc, 0x54, 0xf7, 0x21, 0x4c, 0xae, 0x1b, 0xce, - 0x09, 0x0a, 0x15, 0x3b, 0xe5, 0x47, 0x03, 0xb5, 0x5a, 0x5c, 0x97, 0xd0, 0x74, 0x97, 0x69, 0xba, - 0x85, 0xab, 0x71, 0x9a, 0x4e, 0x0c, 0x87, 0x56, 0x0f, 0x74, 0x02, 0x59, 0xfe, 0x3b, 0x82, 0xb0, - 0x2f, 0x03, 0xbf, 0x45, 0x08, 0xfb, 0x32, 0xf8, 0xd3, 0x83, 0xcb, 0x69, 0x72, 0x61, 0x4a, 0x3e, - 0xde, 0xa3, 0x5b, 0xa1, 0xa5, 0x09, 0x3e, 0xf4, 0xd7, 0xe6, 0x93, 0xba, 0x85, 0xbe, 0x87, 0x4c, - 0xdf, 0x1d, 0x7c, 0x33, 0x76, 0xed, 0x04, 0xf7, 0x33, 0xed, 0xf1, 0xdb, 0x1a, 0x2d, 0x13, 0xe0, - 0x83, 0xac, 0x91, 0xe8, 0x08, 0xe3, 0xb5, 0x91, 0xe8, 0x88, 0xe0, 0xb3, 0x78, 0x99, 0x29, 0x7f, - 0x8a, 0x1f, 0xc6, 0x29, 0x77, 0x6d, 0xc3, 0x74, 0x8e, 0x88, 0xfd, 0x16, 0x07, 0xd3, 0x9c, 0x93, - 0x4e, 0x9f, 0x46, 0xca, 0xef, 0xa7, 0x61, 0x92, 0x9e, 0x47, 0x69, 0x79, 0xf6, 0xaf, 0xf1, 0x61, - 0x6b, 0x22, 0xe0, 0x59, 0xd8, 0x9a, 0x28, 0x02, 0x10, 0x2d, 0xcf, 0xec, 0xb7, 0xe6, 0x84, 0x31, - 0x51, 0xaf, 0x3b, 0x50, 0x50, 0xee, 0xfa, 0x28, 0x46, 0x60, 0x10, 0x99, 0x0b, 0xd7, 0x85, 0x18, - 0xa0, 0x00, 0xdf, 0x66, 0x3a, 0xe7, 0xf0, 0x6c, 0x40, 0x67, 0x9b, 0x73, 0x51, 0xa5, 0x7f, 0x0d, - 0x45, 0x15, 0x13, 0x40, 0x31, 0x32, 0x43, 0xc8, 0x5f, 0x38, 0x25, 0xc6, 0x41, 0x0a, 0xd1, 0xec, - 0xe0, 0xfd, 0xae, 0x5e, 0xb2, 0x52, 0xe5, 0x7d, 0xc8, 0x09, 0xa0, 0x20, 0x6e, 0xb6, 0x41, 0xa8, - 0x30, 0x6e, 0xb6, 0x21, 0x94, 0x21, 0x7a, 0xcc, 0x63, 0x5a, 0xe9, 0x7d, 0x48, 0x96, 0x20, 0xa1, - 0xf1, 0x05, 0x71, 0x93, 0x34, 0xfa, 0xd8, 0x57, 0x92, 0x46, 0xe5, 0x2e, 0x3a, 0x4a, 0xe3, 0x31, - 0x71, 0x45, 0x2c, 0xc9, 0x7b, 0x1e, 0x4a, 0x10, 0xa8, 0xa6, 0x7c, 0x3c, 0x8a, 0x25, 0xe9, 0x54, - 0xee, 0x2b, 0x15, 0xf9, 0x1e, 0x7d, 0x0e, 0xe0, 0x43, 0x1a, 0xe1, 0xd3, 0x56, 0x2c, 0x2e, 0x1a, - 0x3e, 0x6d, 0xc5, 0xa3, 0x22, 0xd1, 0xfc, 0xe1, 0xeb, 0xe6, 0x17, 0x03, 0xaa, 0xfd, 0x5f, 0x34, - 0x40, 0x51, 0x04, 0x04, 0x3d, 0x89, 0xd7, 0x10, 0x8b, 0xb8, 0xd6, 0x9e, 0x5e, 0x8e, 0x39, 0xa9, - 0x44, 0xf8, 0x66, 0xb5, 0xd8, 0x88, 0xfe, 0x6b, 0x6a, 0xd8, 0x97, 0x1a, 0x94, 0x02, 0x10, 0x0a, - 0x7a, 0x90, 0xb0, 0xc6, 0x21, 0xd0, 0xb6, 0xf6, 0xf0, 0x42, 0xbe, 0xa4, 0x93, 0x98, 0xb2, 0x23, - 0xe4, 0x41, 0xfc, 0x1f, 0x35, 0x28, 0x07, 0x61, 0x17, 0x94, 0x20, 0x3f, 0x02, 0xfc, 0xd6, 0x16, - 0x2f, 0x66, 0xbc, 0x78, 0xa9, 0xfc, 0xb3, 0x79, 0x1f, 0x72, 0x02, 0xac, 0x89, 0x0b, 0x88, 0x20, - 0x6c, 0x1c, 0x17, 0x10, 0x21, 0xa4, 0x27, 0x21, 0x20, 0x6c, 0xab, 0x4b, 0x94, 0x10, 0x14, 0x88, - 0x4e, 0x92, 0xc6, 0xd1, 0x21, 0x18, 0x82, 0x83, 0x46, 0x69, 0xf4, 0x43, 0x50, 0xc2, 0x39, 0x28, - 0x41, 0xe0, 0x05, 0x21, 0x18, 0x46, 0x83, 0x12, 0x42, 0x90, 0x29, 0x55, 0x42, 0xd0, 0x07, 0x5f, - 0xe2, 0x42, 0x30, 0x82, 0x88, 0xc7, 0x85, 0x60, 0x14, 0xbf, 0x49, 0x58, 0x57, 0xa6, 0x3b, 0x10, - 0x82, 0x33, 0x31, 0x58, 0x0d, 0x7a, 0x9a, 0xe0, 0xd0, 0x58, 0xb0, 0xbd, 0xf6, 0xd6, 0x25, 0xb9, - 0x47, 0xee, 0x7d, 0xbe, 0x14, 0x72, 0xef, 0x7f, 0xad, 0xc1, 0x6c, 0x1c, 0xd6, 0x83, 0x12, 0x74, - 0x25, 0x00, 0xf5, 0xb5, 0xa5, 0xcb, 0xb2, 0x5f, 0xec, 0x35, 0x2f, 0x1a, 0x9e, 0x57, 0xfe, 0xfb, - 0xbb, 0x79, 0xed, 0xff, 0xbe, 0x9b, 0xd7, 0x7e, 0xf1, 0xdd, 0xbc, 0xf6, 0xaf, 0xbf, 0x9c, 0x9f, - 0x38, 0xcc, 0xb2, 0xff, 0xe1, 0xf5, 0xee, 0x1f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x74, 0x55, 0x61, - 0xe6, 0x68, 0x36, 0x00, 0x00, -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/membership/cluster.go b/vendor/github.com/coreos/etcd/etcdserver/membership/cluster.go deleted file mode 100644 index 4f0b1572ef68..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/membership/cluster.go +++ /dev/null @@ -1,512 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package membership - -import ( - "bytes" - "context" - "crypto/sha1" - "encoding/binary" - "encoding/json" - "fmt" - "path" - "sort" - "strings" - "sync" - "time" - - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/pkg/netutil" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/store" - "github.com/coreos/etcd/version" - - "github.com/coreos/go-semver/semver" -) - -// RaftCluster is a list of Members that belong to the same raft cluster -type RaftCluster struct { - id types.ID - token string - - store store.Store - be backend.Backend - - sync.Mutex // guards the fields below - version *semver.Version - members map[types.ID]*Member - // removed contains the ids of removed members in the cluster. - // removed id cannot be reused. - removed map[types.ID]bool -} - -func NewClusterFromURLsMap(token string, urlsmap types.URLsMap) (*RaftCluster, error) { - c := NewCluster(token) - for name, urls := range urlsmap { - m := NewMember(name, urls, token, nil) - if _, ok := c.members[m.ID]; ok { - return nil, fmt.Errorf("member exists with identical ID %v", m) - } - if uint64(m.ID) == raft.None { - return nil, fmt.Errorf("cannot use %x as member id", raft.None) - } - c.members[m.ID] = m - } - c.genID() - return c, nil -} - -func NewClusterFromMembers(token string, id types.ID, membs []*Member) *RaftCluster { - c := NewCluster(token) - c.id = id - for _, m := range membs { - c.members[m.ID] = m - } - return c -} - -func NewCluster(token string) *RaftCluster { - return &RaftCluster{ - token: token, - members: make(map[types.ID]*Member), - removed: make(map[types.ID]bool), - } -} - -func (c *RaftCluster) ID() types.ID { return c.id } - -func (c *RaftCluster) Members() []*Member { - c.Lock() - defer c.Unlock() - var ms MembersByID - for _, m := range c.members { - ms = append(ms, m.Clone()) - } - sort.Sort(ms) - return []*Member(ms) -} - -func (c *RaftCluster) Member(id types.ID) *Member { - c.Lock() - defer c.Unlock() - return c.members[id].Clone() -} - -// MemberByName returns a Member with the given name if exists. -// If more than one member has the given name, it will panic. -func (c *RaftCluster) MemberByName(name string) *Member { - c.Lock() - defer c.Unlock() - var memb *Member - for _, m := range c.members { - if m.Name == name { - if memb != nil { - plog.Panicf("two members with the given name %q exist", name) - } - memb = m - } - } - return memb.Clone() -} - -func (c *RaftCluster) MemberIDs() []types.ID { - c.Lock() - defer c.Unlock() - var ids []types.ID - for _, m := range c.members { - ids = append(ids, m.ID) - } - sort.Sort(types.IDSlice(ids)) - return ids -} - -func (c *RaftCluster) IsIDRemoved(id types.ID) bool { - c.Lock() - defer c.Unlock() - return c.removed[id] -} - -// PeerURLs returns a list of all peer addresses. -// The returned list is sorted in ascending lexicographical order. -func (c *RaftCluster) PeerURLs() []string { - c.Lock() - defer c.Unlock() - urls := make([]string, 0) - for _, p := range c.members { - urls = append(urls, p.PeerURLs...) - } - sort.Strings(urls) - return urls -} - -// ClientURLs returns a list of all client addresses. -// The returned list is sorted in ascending lexicographical order. -func (c *RaftCluster) ClientURLs() []string { - c.Lock() - defer c.Unlock() - urls := make([]string, 0) - for _, p := range c.members { - urls = append(urls, p.ClientURLs...) - } - sort.Strings(urls) - return urls -} - -func (c *RaftCluster) String() string { - c.Lock() - defer c.Unlock() - b := &bytes.Buffer{} - fmt.Fprintf(b, "{ClusterID:%s ", c.id) - var ms []string - for _, m := range c.members { - ms = append(ms, fmt.Sprintf("%+v", m)) - } - fmt.Fprintf(b, "Members:[%s] ", strings.Join(ms, " ")) - var ids []string - for id := range c.removed { - ids = append(ids, id.String()) - } - fmt.Fprintf(b, "RemovedMemberIDs:[%s]}", strings.Join(ids, " ")) - return b.String() -} - -func (c *RaftCluster) genID() { - mIDs := c.MemberIDs() - b := make([]byte, 8*len(mIDs)) - for i, id := range mIDs { - binary.BigEndian.PutUint64(b[8*i:], uint64(id)) - } - hash := sha1.Sum(b) - c.id = types.ID(binary.BigEndian.Uint64(hash[:8])) -} - -func (c *RaftCluster) SetID(id types.ID) { c.id = id } - -func (c *RaftCluster) SetStore(st store.Store) { c.store = st } - -func (c *RaftCluster) SetBackend(be backend.Backend) { - c.be = be - mustCreateBackendBuckets(c.be) -} - -func (c *RaftCluster) Recover(onSet func(*semver.Version)) { - c.Lock() - defer c.Unlock() - - c.members, c.removed = membersFromStore(c.store) - c.version = clusterVersionFromStore(c.store) - mustDetectDowngrade(c.version) - onSet(c.version) - - for _, m := range c.members { - plog.Infof("added member %s %v to cluster %s from store", m.ID, m.PeerURLs, c.id) - } - if c.version != nil { - plog.Infof("set the cluster version to %v from store", version.Cluster(c.version.String())) - } -} - -// ValidateConfigurationChange takes a proposed ConfChange and -// ensures that it is still valid. -func (c *RaftCluster) ValidateConfigurationChange(cc raftpb.ConfChange) error { - members, removed := membersFromStore(c.store) - id := types.ID(cc.NodeID) - if removed[id] { - return ErrIDRemoved - } - switch cc.Type { - case raftpb.ConfChangeAddNode: - if members[id] != nil { - return ErrIDExists - } - urls := make(map[string]bool) - for _, m := range members { - for _, u := range m.PeerURLs { - urls[u] = true - } - } - m := new(Member) - if err := json.Unmarshal(cc.Context, m); err != nil { - plog.Panicf("unmarshal member should never fail: %v", err) - } - for _, u := range m.PeerURLs { - if urls[u] { - return ErrPeerURLexists - } - } - case raftpb.ConfChangeRemoveNode: - if members[id] == nil { - return ErrIDNotFound - } - case raftpb.ConfChangeUpdateNode: - if members[id] == nil { - return ErrIDNotFound - } - urls := make(map[string]bool) - for _, m := range members { - if m.ID == id { - continue - } - for _, u := range m.PeerURLs { - urls[u] = true - } - } - m := new(Member) - if err := json.Unmarshal(cc.Context, m); err != nil { - plog.Panicf("unmarshal member should never fail: %v", err) - } - for _, u := range m.PeerURLs { - if urls[u] { - return ErrPeerURLexists - } - } - default: - plog.Panicf("ConfChange type should be either AddNode, RemoveNode or UpdateNode") - } - return nil -} - -// AddMember adds a new Member into the cluster, and saves the given member's -// raftAttributes into the store. The given member should have empty attributes. -// A Member with a matching id must not exist. -func (c *RaftCluster) AddMember(m *Member) { - c.Lock() - defer c.Unlock() - if c.store != nil { - mustSaveMemberToStore(c.store, m) - } - if c.be != nil { - mustSaveMemberToBackend(c.be, m) - } - - c.members[m.ID] = m - - plog.Infof("added member %s %v to cluster %s", m.ID, m.PeerURLs, c.id) -} - -// RemoveMember removes a member from the store. -// The given id MUST exist, or the function panics. -func (c *RaftCluster) RemoveMember(id types.ID) { - c.Lock() - defer c.Unlock() - if c.store != nil { - mustDeleteMemberFromStore(c.store, id) - } - if c.be != nil { - mustDeleteMemberFromBackend(c.be, id) - } - - delete(c.members, id) - c.removed[id] = true - - plog.Infof("removed member %s from cluster %s", id, c.id) -} - -func (c *RaftCluster) UpdateAttributes(id types.ID, attr Attributes) { - c.Lock() - defer c.Unlock() - if m, ok := c.members[id]; ok { - m.Attributes = attr - if c.store != nil { - mustUpdateMemberAttrInStore(c.store, m) - } - if c.be != nil { - mustSaveMemberToBackend(c.be, m) - } - return - } - _, ok := c.removed[id] - if !ok { - plog.Panicf("error updating attributes of unknown member %s", id) - } - plog.Warningf("skipped updating attributes of removed member %s", id) -} - -func (c *RaftCluster) UpdateRaftAttributes(id types.ID, raftAttr RaftAttributes) { - c.Lock() - defer c.Unlock() - - c.members[id].RaftAttributes = raftAttr - if c.store != nil { - mustUpdateMemberInStore(c.store, c.members[id]) - } - if c.be != nil { - mustSaveMemberToBackend(c.be, c.members[id]) - } - - plog.Noticef("updated member %s %v in cluster %s", id, raftAttr.PeerURLs, c.id) -} - -func (c *RaftCluster) Version() *semver.Version { - c.Lock() - defer c.Unlock() - if c.version == nil { - return nil - } - return semver.Must(semver.NewVersion(c.version.String())) -} - -func (c *RaftCluster) SetVersion(ver *semver.Version, onSet func(*semver.Version)) { - c.Lock() - defer c.Unlock() - if c.version != nil { - plog.Noticef("updated the cluster version from %v to %v", version.Cluster(c.version.String()), version.Cluster(ver.String())) - } else { - plog.Noticef("set the initial cluster version to %v", version.Cluster(ver.String())) - } - c.version = ver - mustDetectDowngrade(c.version) - if c.store != nil { - mustSaveClusterVersionToStore(c.store, ver) - } - if c.be != nil { - mustSaveClusterVersionToBackend(c.be, ver) - } - onSet(ver) -} - -func (c *RaftCluster) IsReadyToAddNewMember() bool { - nmembers := 1 - nstarted := 0 - - for _, member := range c.members { - if member.IsStarted() { - nstarted++ - } - nmembers++ - } - - if nstarted == 1 && nmembers == 2 { - // a case of adding a new node to 1-member cluster for restoring cluster data - // https://github.com/coreos/etcd/blob/master/Documentation/v2/admin_guide.md#restoring-the-cluster - - plog.Debugf("The number of started member is 1. This cluster can accept add member request.") - return true - } - - nquorum := nmembers/2 + 1 - if nstarted < nquorum { - plog.Warningf("Reject add member request: the number of started member (%d) will be less than the quorum number of the cluster (%d)", nstarted, nquorum) - return false - } - - return true -} - -func (c *RaftCluster) IsReadyToRemoveMember(id uint64) bool { - nmembers := 0 - nstarted := 0 - - for _, member := range c.members { - if uint64(member.ID) == id { - continue - } - - if member.IsStarted() { - nstarted++ - } - nmembers++ - } - - nquorum := nmembers/2 + 1 - if nstarted < nquorum { - plog.Warningf("Reject remove member request: the number of started member (%d) will be less than the quorum number of the cluster (%d)", nstarted, nquorum) - return false - } - - return true -} - -func membersFromStore(st store.Store) (map[types.ID]*Member, map[types.ID]bool) { - members := make(map[types.ID]*Member) - removed := make(map[types.ID]bool) - e, err := st.Get(StoreMembersPrefix, true, true) - if err != nil { - if isKeyNotFound(err) { - return members, removed - } - plog.Panicf("get storeMembers should never fail: %v", err) - } - for _, n := range e.Node.Nodes { - var m *Member - m, err = nodeToMember(n) - if err != nil { - plog.Panicf("nodeToMember should never fail: %v", err) - } - members[m.ID] = m - } - - e, err = st.Get(storeRemovedMembersPrefix, true, true) - if err != nil { - if isKeyNotFound(err) { - return members, removed - } - plog.Panicf("get storeRemovedMembers should never fail: %v", err) - } - for _, n := range e.Node.Nodes { - removed[MustParseMemberIDFromKey(n.Key)] = true - } - return members, removed -} - -func clusterVersionFromStore(st store.Store) *semver.Version { - e, err := st.Get(path.Join(storePrefix, "version"), false, false) - if err != nil { - if isKeyNotFound(err) { - return nil - } - plog.Panicf("unexpected error (%v) when getting cluster version from store", err) - } - return semver.Must(semver.NewVersion(*e.Node.Value)) -} - -// ValidateClusterAndAssignIDs validates the local cluster by matching the PeerURLs -// with the existing cluster. If the validation succeeds, it assigns the IDs -// from the existing cluster to the local cluster. -// If the validation fails, an error will be returned. -func ValidateClusterAndAssignIDs(local *RaftCluster, existing *RaftCluster) error { - ems := existing.Members() - lms := local.Members() - if len(ems) != len(lms) { - return fmt.Errorf("member count is unequal") - } - sort.Sort(MembersByPeerURLs(ems)) - sort.Sort(MembersByPeerURLs(lms)) - - ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second) - defer cancel() - for i := range ems { - if ok, err := netutil.URLStringsEqual(ctx, ems[i].PeerURLs, lms[i].PeerURLs); !ok { - return fmt.Errorf("unmatched member while checking PeerURLs (%v)", err) - } - lms[i].ID = ems[i].ID - } - local.members = make(map[types.ID]*Member) - for _, m := range lms { - local.members[m.ID] = m - } - return nil -} - -func mustDetectDowngrade(cv *semver.Version) { - lv := semver.Must(semver.NewVersion(version.Version)) - // only keep major.minor version for comparison against cluster version - lv = &semver.Version{Major: lv.Major, Minor: lv.Minor} - if cv != nil && lv.LessThan(*cv) { - plog.Fatalf("cluster cannot be downgraded (current version: %s is lower than determined cluster version: %s).", version.Version, version.Cluster(cv.String())) - } -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/membership/doc.go b/vendor/github.com/coreos/etcd/etcdserver/membership/doc.go deleted file mode 100644 index b07fb2d92859..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/membership/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package membership describes individual etcd members and clusters of members. -package membership diff --git a/vendor/github.com/coreos/etcd/etcdserver/membership/errors.go b/vendor/github.com/coreos/etcd/etcdserver/membership/errors.go deleted file mode 100644 index e4d36af25477..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/membership/errors.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package membership - -import ( - "errors" - - etcdErr "github.com/coreos/etcd/error" -) - -var ( - ErrIDRemoved = errors.New("membership: ID removed") - ErrIDExists = errors.New("membership: ID exists") - ErrIDNotFound = errors.New("membership: ID not found") - ErrPeerURLexists = errors.New("membership: peerURL exists") -) - -func isKeyNotFound(err error) bool { - e, ok := err.(*etcdErr.Error) - return ok && e.ErrorCode == etcdErr.EcodeKeyNotFound -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/membership/member.go b/vendor/github.com/coreos/etcd/etcdserver/membership/member.go deleted file mode 100644 index 6de74d26f8d4..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/membership/member.go +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package membership - -import ( - "crypto/sha1" - "encoding/binary" - "fmt" - "math/rand" - "sort" - "time" - - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/pkg/capnslog" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdserver/membership") -) - -// RaftAttributes represents the raft related attributes of an etcd member. -type RaftAttributes struct { - // PeerURLs is the list of peers in the raft cluster. - // TODO(philips): ensure these are URLs - PeerURLs []string `json:"peerURLs"` -} - -// Attributes represents all the non-raft related attributes of an etcd member. -type Attributes struct { - Name string `json:"name,omitempty"` - ClientURLs []string `json:"clientURLs,omitempty"` -} - -type Member struct { - ID types.ID `json:"id"` - RaftAttributes - Attributes -} - -// NewMember creates a Member without an ID and generates one based on the -// cluster name, peer URLs, and time. This is used for bootstrapping/adding new member. -func NewMember(name string, peerURLs types.URLs, clusterName string, now *time.Time) *Member { - m := &Member{ - RaftAttributes: RaftAttributes{PeerURLs: peerURLs.StringSlice()}, - Attributes: Attributes{Name: name}, - } - - var b []byte - sort.Strings(m.PeerURLs) - for _, p := range m.PeerURLs { - b = append(b, []byte(p)...) - } - - b = append(b, []byte(clusterName)...) - if now != nil { - b = append(b, []byte(fmt.Sprintf("%d", now.Unix()))...) - } - - hash := sha1.Sum(b) - m.ID = types.ID(binary.BigEndian.Uint64(hash[:8])) - return m -} - -// PickPeerURL chooses a random address from a given Member's PeerURLs. -// It will panic if there is no PeerURLs available in Member. -func (m *Member) PickPeerURL() string { - if len(m.PeerURLs) == 0 { - plog.Panicf("member should always have some peer url") - } - return m.PeerURLs[rand.Intn(len(m.PeerURLs))] -} - -func (m *Member) Clone() *Member { - if m == nil { - return nil - } - mm := &Member{ - ID: m.ID, - Attributes: Attributes{ - Name: m.Name, - }, - } - if m.PeerURLs != nil { - mm.PeerURLs = make([]string, len(m.PeerURLs)) - copy(mm.PeerURLs, m.PeerURLs) - } - if m.ClientURLs != nil { - mm.ClientURLs = make([]string, len(m.ClientURLs)) - copy(mm.ClientURLs, m.ClientURLs) - } - return mm -} - -func (m *Member) IsStarted() bool { - return len(m.Name) != 0 -} - -// MembersByID implements sort by ID interface -type MembersByID []*Member - -func (ms MembersByID) Len() int { return len(ms) } -func (ms MembersByID) Less(i, j int) bool { return ms[i].ID < ms[j].ID } -func (ms MembersByID) Swap(i, j int) { ms[i], ms[j] = ms[j], ms[i] } - -// MembersByPeerURLs implements sort by peer urls interface -type MembersByPeerURLs []*Member - -func (ms MembersByPeerURLs) Len() int { return len(ms) } -func (ms MembersByPeerURLs) Less(i, j int) bool { - return ms[i].PeerURLs[0] < ms[j].PeerURLs[0] -} -func (ms MembersByPeerURLs) Swap(i, j int) { ms[i], ms[j] = ms[j], ms[i] } diff --git a/vendor/github.com/coreos/etcd/etcdserver/membership/store.go b/vendor/github.com/coreos/etcd/etcdserver/membership/store.go deleted file mode 100644 index d3f8f2474a42..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/membership/store.go +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package membership - -import ( - "encoding/json" - "fmt" - "path" - - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/store" - - "github.com/coreos/go-semver/semver" -) - -const ( - attributesSuffix = "attributes" - raftAttributesSuffix = "raftAttributes" - - // the prefix for stroing membership related information in store provided by store pkg. - storePrefix = "/0" -) - -var ( - membersBucketName = []byte("members") - membersRemovedBucketName = []byte("members_removed") - clusterBucketName = []byte("cluster") - - StoreMembersPrefix = path.Join(storePrefix, "members") - storeRemovedMembersPrefix = path.Join(storePrefix, "removed_members") -) - -func mustSaveMemberToBackend(be backend.Backend, m *Member) { - mkey := backendMemberKey(m.ID) - mvalue, err := json.Marshal(m) - if err != nil { - plog.Panicf("marshal raftAttributes should never fail: %v", err) - } - - tx := be.BatchTx() - tx.Lock() - tx.UnsafePut(membersBucketName, mkey, mvalue) - tx.Unlock() -} - -func mustDeleteMemberFromBackend(be backend.Backend, id types.ID) { - mkey := backendMemberKey(id) - - tx := be.BatchTx() - tx.Lock() - tx.UnsafeDelete(membersBucketName, mkey) - tx.UnsafePut(membersRemovedBucketName, mkey, []byte("removed")) - tx.Unlock() -} - -func mustSaveClusterVersionToBackend(be backend.Backend, ver *semver.Version) { - ckey := backendClusterVersionKey() - - tx := be.BatchTx() - tx.Lock() - defer tx.Unlock() - tx.UnsafePut(clusterBucketName, ckey, []byte(ver.String())) -} - -func mustSaveMemberToStore(s store.Store, m *Member) { - b, err := json.Marshal(m.RaftAttributes) - if err != nil { - plog.Panicf("marshal raftAttributes should never fail: %v", err) - } - p := path.Join(MemberStoreKey(m.ID), raftAttributesSuffix) - if _, err := s.Create(p, false, string(b), false, store.TTLOptionSet{ExpireTime: store.Permanent}); err != nil { - plog.Panicf("create raftAttributes should never fail: %v", err) - } -} - -func mustDeleteMemberFromStore(s store.Store, id types.ID) { - if _, err := s.Delete(MemberStoreKey(id), true, true); err != nil { - plog.Panicf("delete member should never fail: %v", err) - } - if _, err := s.Create(RemovedMemberStoreKey(id), false, "", false, store.TTLOptionSet{ExpireTime: store.Permanent}); err != nil { - plog.Panicf("create removedMember should never fail: %v", err) - } -} - -func mustUpdateMemberInStore(s store.Store, m *Member) { - b, err := json.Marshal(m.RaftAttributes) - if err != nil { - plog.Panicf("marshal raftAttributes should never fail: %v", err) - } - p := path.Join(MemberStoreKey(m.ID), raftAttributesSuffix) - if _, err := s.Update(p, string(b), store.TTLOptionSet{ExpireTime: store.Permanent}); err != nil { - plog.Panicf("update raftAttributes should never fail: %v", err) - } -} - -func mustUpdateMemberAttrInStore(s store.Store, m *Member) { - b, err := json.Marshal(m.Attributes) - if err != nil { - plog.Panicf("marshal raftAttributes should never fail: %v", err) - } - p := path.Join(MemberStoreKey(m.ID), attributesSuffix) - if _, err := s.Set(p, false, string(b), store.TTLOptionSet{ExpireTime: store.Permanent}); err != nil { - plog.Panicf("update raftAttributes should never fail: %v", err) - } -} - -func mustSaveClusterVersionToStore(s store.Store, ver *semver.Version) { - if _, err := s.Set(StoreClusterVersionKey(), false, ver.String(), store.TTLOptionSet{ExpireTime: store.Permanent}); err != nil { - plog.Panicf("save cluster version should never fail: %v", err) - } -} - -// nodeToMember builds member from a key value node. -// the child nodes of the given node MUST be sorted by key. -func nodeToMember(n *store.NodeExtern) (*Member, error) { - m := &Member{ID: MustParseMemberIDFromKey(n.Key)} - attrs := make(map[string][]byte) - raftAttrKey := path.Join(n.Key, raftAttributesSuffix) - attrKey := path.Join(n.Key, attributesSuffix) - for _, nn := range n.Nodes { - if nn.Key != raftAttrKey && nn.Key != attrKey { - return nil, fmt.Errorf("unknown key %q", nn.Key) - } - attrs[nn.Key] = []byte(*nn.Value) - } - if data := attrs[raftAttrKey]; data != nil { - if err := json.Unmarshal(data, &m.RaftAttributes); err != nil { - return nil, fmt.Errorf("unmarshal raftAttributes error: %v", err) - } - } else { - return nil, fmt.Errorf("raftAttributes key doesn't exist") - } - if data := attrs[attrKey]; data != nil { - if err := json.Unmarshal(data, &m.Attributes); err != nil { - return m, fmt.Errorf("unmarshal attributes error: %v", err) - } - } - return m, nil -} - -func backendMemberKey(id types.ID) []byte { - return []byte(id.String()) -} - -func backendClusterVersionKey() []byte { - return []byte("clusterVersion") -} - -func mustCreateBackendBuckets(be backend.Backend) { - tx := be.BatchTx() - tx.Lock() - defer tx.Unlock() - tx.UnsafeCreateBucket(membersBucketName) - tx.UnsafeCreateBucket(membersRemovedBucketName) - tx.UnsafeCreateBucket(clusterBucketName) -} - -func MemberStoreKey(id types.ID) string { - return path.Join(StoreMembersPrefix, id.String()) -} - -func StoreClusterVersionKey() string { - return path.Join(storePrefix, "version") -} - -func MemberAttributesStorePath(id types.ID) string { - return path.Join(MemberStoreKey(id), attributesSuffix) -} - -func MustParseMemberIDFromKey(key string) types.ID { - id, err := types.IDFromString(path.Base(key)) - if err != nil { - plog.Panicf("unexpected parse member id error: %v", err) - } - return id -} - -func RemovedMemberStoreKey(id types.ID) string { - return path.Join(storeRemovedMembersPrefix, id.String()) -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/metrics.go b/vendor/github.com/coreos/etcd/etcdserver/metrics.go deleted file mode 100644 index 10f8a475fca7..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/metrics.go +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - goruntime "runtime" - "time" - - "github.com/coreos/etcd/pkg/runtime" - "github.com/coreos/etcd/version" - "github.com/prometheus/client_golang/prometheus" -) - -var ( - hasLeader = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "has_leader", - Help: "Whether or not a leader exists. 1 is existence, 0 is not.", - }) - isLeader = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "is_leader", - Help: "Whether or not this member is a leader. 1 if is, 0 otherwise.", - }) - leaderChanges = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "leader_changes_seen_total", - Help: "The number of leader changes seen.", - }) - heartbeatSendFailures = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "heartbeat_send_failures_total", - Help: "The total number of leader heartbeat send failures (likely overloaded from slow disk).", - }) - slowApplies = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "slow_apply_total", - Help: "The total number of slow apply requests (likely overloaded from slow disk).", - }) - proposalsCommitted = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "proposals_committed_total", - Help: "The total number of consensus proposals committed.", - }) - proposalsApplied = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "proposals_applied_total", - Help: "The total number of consensus proposals applied.", - }) - proposalsPending = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "proposals_pending", - Help: "The current number of pending proposals to commit.", - }) - proposalsFailed = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "proposals_failed_total", - Help: "The total number of failed proposals seen.", - }) - leaseExpired = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "server", - Name: "lease_expired_total", - Help: "The total number of expired leases.", - }) - slowReadIndex = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "slow_read_indexes_total", - Help: "The total number of pending read indexes not in sync with leader's or timed out read index requests.", - }) - readIndexFailed = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "read_indexes_failed_total", - Help: "The total number of failed read indexes seen.", - }) - quotaBackendBytes = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "quota_backend_bytes", - Help: "Current backend storage quota size in bytes.", - }) - currentVersion = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "version", - Help: "Which version is running. 1 for 'server_version' label with current version.", - }, - []string{"server_version"}) - currentGoVersion = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "go_version", - Help: "Which Go version server is running with. 1 for 'server_go_version' label with current version.", - }, - []string{"server_go_version"}) - serverID = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "id", - Help: "Server or member ID in hexadecimal format. 1 for 'server_id' label with current ID.", - }, - []string{"server_id"}) -) - -func init() { - prometheus.MustRegister(hasLeader) - prometheus.MustRegister(isLeader) - prometheus.MustRegister(leaderChanges) - prometheus.MustRegister(heartbeatSendFailures) - prometheus.MustRegister(slowApplies) - prometheus.MustRegister(proposalsCommitted) - prometheus.MustRegister(proposalsApplied) - prometheus.MustRegister(proposalsPending) - prometheus.MustRegister(proposalsFailed) - prometheus.MustRegister(leaseExpired) - prometheus.MustRegister(slowReadIndex) - prometheus.MustRegister(readIndexFailed) - prometheus.MustRegister(quotaBackendBytes) - prometheus.MustRegister(currentVersion) - prometheus.MustRegister(currentGoVersion) - prometheus.MustRegister(serverID) - - currentVersion.With(prometheus.Labels{ - "server_version": version.Version, - }).Set(1) - currentGoVersion.With(prometheus.Labels{ - "server_go_version": goruntime.Version(), - }).Set(1) -} - -func monitorFileDescriptor(done <-chan struct{}) { - ticker := time.NewTicker(5 * time.Second) - defer ticker.Stop() - for { - used, err := runtime.FDUsage() - if err != nil { - plog.Errorf("cannot monitor file descriptor usage (%v)", err) - return - } - limit, err := runtime.FDLimit() - if err != nil { - plog.Errorf("cannot monitor file descriptor usage (%v)", err) - return - } - if used >= limit/5*4 { - plog.Warningf("80%% of the file descriptor limit is used [used = %d, limit = %d]", used, limit) - } - select { - case <-ticker.C: - case <-done: - return - } - } -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/quota.go b/vendor/github.com/coreos/etcd/etcdserver/quota.go deleted file mode 100644 index 882eb76f81b6..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/quota.go +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - -const ( - // DefaultQuotaBytes is the number of bytes the backend Size may - // consume before exceeding the space quota. - DefaultQuotaBytes = int64(2 * 1024 * 1024 * 1024) // 2GB - // MaxQuotaBytes is the maximum number of bytes suggested for a backend - // quota. A larger quota may lead to degraded performance. - MaxQuotaBytes = int64(8 * 1024 * 1024 * 1024) // 8GB -) - -// Quota represents an arbitrary quota against arbitrary requests. Each request -// costs some charge; if there is not enough remaining charge, then there are -// too few resources available within the quota to apply the request. -type Quota interface { - // Available judges whether the given request fits within the quota. - Available(req interface{}) bool - // Cost computes the charge against the quota for a given request. - Cost(req interface{}) int - // Remaining is the amount of charge left for the quota. - Remaining() int64 -} - -type passthroughQuota struct{} - -func (*passthroughQuota) Available(interface{}) bool { return true } -func (*passthroughQuota) Cost(interface{}) int { return 0 } -func (*passthroughQuota) Remaining() int64 { return 1 } - -type backendQuota struct { - s *EtcdServer - maxBackendBytes int64 -} - -const ( - // leaseOverhead is an estimate for the cost of storing a lease - leaseOverhead = 64 - // kvOverhead is an estimate for the cost of storing a key's metadata - kvOverhead = 256 -) - -func NewBackendQuota(s *EtcdServer) Quota { - quotaBackendBytes.Set(float64(s.Cfg.QuotaBackendBytes)) - - if s.Cfg.QuotaBackendBytes < 0 { - // disable quotas if negative - plog.Warningf("disabling backend quota") - return &passthroughQuota{} - } - - if s.Cfg.QuotaBackendBytes == 0 { - // use default size if no quota size given - quotaBackendBytes.Set(float64(DefaultQuotaBytes)) - return &backendQuota{s, DefaultQuotaBytes} - } - - if s.Cfg.QuotaBackendBytes > MaxQuotaBytes { - plog.Warningf("backend quota %v exceeds maximum recommended quota %v", s.Cfg.QuotaBackendBytes, MaxQuotaBytes) - } - return &backendQuota{s, s.Cfg.QuotaBackendBytes} -} - -func (b *backendQuota) Available(v interface{}) bool { - // TODO: maybe optimize backend.Size() - return b.s.Backend().Size()+int64(b.Cost(v)) < b.maxBackendBytes -} - -func (b *backendQuota) Cost(v interface{}) int { - switch r := v.(type) { - case *pb.PutRequest: - return costPut(r) - case *pb.TxnRequest: - return costTxn(r) - case *pb.LeaseGrantRequest: - return leaseOverhead - default: - panic("unexpected cost") - } -} - -func costPut(r *pb.PutRequest) int { return kvOverhead + len(r.Key) + len(r.Value) } - -func costTxnReq(u *pb.RequestOp) int { - r := u.GetRequestPut() - if r == nil { - return 0 - } - return costPut(r) -} - -func costTxn(r *pb.TxnRequest) int { - sizeSuccess := 0 - for _, u := range r.Success { - sizeSuccess += costTxnReq(u) - } - sizeFailure := 0 - for _, u := range r.Failure { - sizeFailure += costTxnReq(u) - } - if sizeFailure > sizeSuccess { - return sizeFailure - } - return sizeSuccess -} - -func (b *backendQuota) Remaining() int64 { - return b.maxBackendBytes - b.s.Backend().Size() -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/raft.go b/vendor/github.com/coreos/etcd/etcdserver/raft.go deleted file mode 100644 index f73df6c7dc0d..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/raft.go +++ /dev/null @@ -1,608 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "encoding/json" - "expvar" - "sort" - "sync" - "sync/atomic" - "time" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/pkg/contention" - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/rafthttp" - "github.com/coreos/etcd/wal" - "github.com/coreos/etcd/wal/walpb" - "github.com/coreos/pkg/capnslog" -) - -const ( - // Number of entries for slow follower to catch-up after compacting - // the raft storage entries. - // We expect the follower has a millisecond level latency with the leader. - // The max throughput is around 10K. Keep a 5K entries is enough for helping - // follower to catch up. - numberOfCatchUpEntries = 5000 - - // The max throughput of etcd will not exceed 100MB/s (100K * 1KB value). - // Assuming the RTT is around 10ms, 1MB max size is large enough. - maxSizePerMsg = 1 * 1024 * 1024 - // Never overflow the rafthttp buffer, which is 4096. - // TODO: a better const? - maxInflightMsgs = 4096 / 8 -) - -var ( - // protects raftStatus - raftStatusMu sync.Mutex - // indirection for expvar func interface - // expvar panics when publishing duplicate name - // expvar does not support remove a registered name - // so only register a func that calls raftStatus - // and change raftStatus as we need. - raftStatus func() raft.Status -) - -func init() { - raft.SetLogger(capnslog.NewPackageLogger("github.com/coreos/etcd", "raft")) - expvar.Publish("raft.status", expvar.Func(func() interface{} { - raftStatusMu.Lock() - defer raftStatusMu.Unlock() - return raftStatus() - })) -} - -type RaftTimer interface { - Index() uint64 - Term() uint64 -} - -// apply contains entries, snapshot to be applied. Once -// an apply is consumed, the entries will be persisted to -// to raft storage concurrently; the application must read -// raftDone before assuming the raft messages are stable. -type apply struct { - entries []raftpb.Entry - snapshot raftpb.Snapshot - // notifyc synchronizes etcd server applies with the raft node - notifyc chan struct{} -} - -type raftNode struct { - // Cache of the latest raft index and raft term the server has seen. - // These three unit64 fields must be the first elements to keep 64-bit - // alignment for atomic access to the fields. - index uint64 - term uint64 - lead uint64 - - tickMu *sync.Mutex - raftNodeConfig - - // a chan to send/receive snapshot - msgSnapC chan raftpb.Message - - // a chan to send out apply - applyc chan apply - - // a chan to send out readState - readStateC chan raft.ReadState - - // utility - ticker *time.Ticker - // contention detectors for raft heartbeat message - td *contention.TimeoutDetector - - stopped chan struct{} - done chan struct{} -} - -type raftNodeConfig struct { - // to check if msg receiver is removed from cluster - isIDRemoved func(id uint64) bool - raft.Node - raftStorage *raft.MemoryStorage - storage Storage - heartbeat time.Duration // for logging - // transport specifies the transport to send and receive msgs to members. - // Sending messages MUST NOT block. It is okay to drop messages, since - // clients should timeout and reissue their messages. - // If transport is nil, server will panic. - transport rafthttp.Transporter -} - -func newRaftNode(cfg raftNodeConfig) *raftNode { - r := &raftNode{ - tickMu: new(sync.Mutex), - raftNodeConfig: cfg, - // set up contention detectors for raft heartbeat message. - // expect to send a heartbeat within 2 heartbeat intervals. - td: contention.NewTimeoutDetector(2 * cfg.heartbeat), - readStateC: make(chan raft.ReadState, 1), - msgSnapC: make(chan raftpb.Message, maxInFlightMsgSnap), - applyc: make(chan apply), - stopped: make(chan struct{}), - done: make(chan struct{}), - } - if r.heartbeat == 0 { - r.ticker = &time.Ticker{} - } else { - r.ticker = time.NewTicker(r.heartbeat) - } - return r -} - -// raft.Node does not have locks in Raft package -func (r *raftNode) tick() { - r.tickMu.Lock() - r.Tick() - r.tickMu.Unlock() -} - -// start prepares and starts raftNode in a new goroutine. It is no longer safe -// to modify the fields after it has been started. -func (r *raftNode) start(rh *raftReadyHandler) { - internalTimeout := time.Second - - go func() { - defer r.onStop() - islead := false - - for { - select { - case <-r.ticker.C: - r.tick() - case rd := <-r.Ready(): - if rd.SoftState != nil { - newLeader := rd.SoftState.Lead != raft.None && atomic.LoadUint64(&r.lead) != rd.SoftState.Lead - if newLeader { - leaderChanges.Inc() - } - - if rd.SoftState.Lead == raft.None { - hasLeader.Set(0) - } else { - hasLeader.Set(1) - } - - atomic.StoreUint64(&r.lead, rd.SoftState.Lead) - islead = rd.RaftState == raft.StateLeader - if islead { - isLeader.Set(1) - } else { - isLeader.Set(0) - } - rh.updateLeadership(newLeader) - r.td.Reset() - } - - if len(rd.ReadStates) != 0 { - select { - case r.readStateC <- rd.ReadStates[len(rd.ReadStates)-1]: - case <-time.After(internalTimeout): - plog.Warningf("timed out sending read state") - case <-r.stopped: - return - } - } - - notifyc := make(chan struct{}, 1) - ap := apply{ - entries: rd.CommittedEntries, - snapshot: rd.Snapshot, - notifyc: notifyc, - } - - updateCommittedIndex(&ap, rh) - - select { - case r.applyc <- ap: - case <-r.stopped: - return - } - - // the leader can write to its disk in parallel with replicating to the followers and them - // writing to their disks. - // For more details, check raft thesis 10.2.1 - if islead { - // gofail: var raftBeforeLeaderSend struct{} - r.transport.Send(r.processMessages(rd.Messages)) - } - - // gofail: var raftBeforeSave struct{} - if err := r.storage.Save(rd.HardState, rd.Entries); err != nil { - plog.Fatalf("raft save state and entries error: %v", err) - } - if !raft.IsEmptyHardState(rd.HardState) { - proposalsCommitted.Set(float64(rd.HardState.Commit)) - } - // gofail: var raftAfterSave struct{} - - if !raft.IsEmptySnap(rd.Snapshot) { - // gofail: var raftBeforeSaveSnap struct{} - if err := r.storage.SaveSnap(rd.Snapshot); err != nil { - plog.Fatalf("raft save snapshot error: %v", err) - } - // etcdserver now claim the snapshot has been persisted onto the disk - notifyc <- struct{}{} - - // gofail: var raftAfterSaveSnap struct{} - r.raftStorage.ApplySnapshot(rd.Snapshot) - plog.Infof("raft applied incoming snapshot at index %d", rd.Snapshot.Metadata.Index) - // gofail: var raftAfterApplySnap struct{} - } - - r.raftStorage.Append(rd.Entries) - - if !islead { - // finish processing incoming messages before we signal raftdone chan - msgs := r.processMessages(rd.Messages) - - // now unblocks 'applyAll' that waits on Raft log disk writes before triggering snapshots - notifyc <- struct{}{} - - // Candidate or follower needs to wait for all pending configuration - // changes to be applied before sending messages. - // Otherwise we might incorrectly count votes (e.g. votes from removed members). - // Also slow machine's follower raft-layer could proceed to become the leader - // on its own single-node cluster, before apply-layer applies the config change. - // We simply wait for ALL pending entries to be applied for now. - // We might improve this later on if it causes unnecessary long blocking issues. - waitApply := false - for _, ent := range rd.CommittedEntries { - if ent.Type == raftpb.EntryConfChange { - waitApply = true - break - } - } - if waitApply { - // blocks until 'applyAll' calls 'applyWait.Trigger' - // to be in sync with scheduled config-change job - // (assume notifyc has cap of 1) - select { - case notifyc <- struct{}{}: - case <-r.stopped: - return - } - } - - // gofail: var raftBeforeFollowerSend struct{} - r.transport.Send(msgs) - } else { - // leader already processed 'MsgSnap' and signaled - notifyc <- struct{}{} - } - - r.Advance() - case <-r.stopped: - return - } - } - }() -} - -func updateCommittedIndex(ap *apply, rh *raftReadyHandler) { - var ci uint64 - if len(ap.entries) != 0 { - ci = ap.entries[len(ap.entries)-1].Index - } - if ap.snapshot.Metadata.Index > ci { - ci = ap.snapshot.Metadata.Index - } - if ci != 0 { - rh.updateCommittedIndex(ci) - } -} - -func (r *raftNode) processMessages(ms []raftpb.Message) []raftpb.Message { - sentAppResp := false - for i := len(ms) - 1; i >= 0; i-- { - if r.isIDRemoved(ms[i].To) { - ms[i].To = 0 - } - - if ms[i].Type == raftpb.MsgAppResp { - if sentAppResp { - ms[i].To = 0 - } else { - sentAppResp = true - } - } - - if ms[i].Type == raftpb.MsgSnap { - // There are two separate data store: the store for v2, and the KV for v3. - // The msgSnap only contains the most recent snapshot of store without KV. - // So we need to redirect the msgSnap to etcd server main loop for merging in the - // current store snapshot and KV snapshot. - select { - case r.msgSnapC <- ms[i]: - default: - // drop msgSnap if the inflight chan if full. - } - ms[i].To = 0 - } - if ms[i].Type == raftpb.MsgHeartbeat { - ok, exceed := r.td.Observe(ms[i].To) - if !ok { - // TODO: limit request rate. - plog.Warningf("failed to send out heartbeat on time (exceeded the %v timeout for %v, to %x)", r.heartbeat, exceed, ms[i].To) - plog.Warningf("server is likely overloaded") - heartbeatSendFailures.Inc() - } - } - } - return ms -} - -func (r *raftNode) apply() chan apply { - return r.applyc -} - -func (r *raftNode) stop() { - r.stopped <- struct{}{} - <-r.done -} - -func (r *raftNode) onStop() { - r.Stop() - r.ticker.Stop() - r.transport.Stop() - if err := r.storage.Close(); err != nil { - plog.Panicf("raft close storage error: %v", err) - } - close(r.done) -} - -// for testing -func (r *raftNode) pauseSending() { - p := r.transport.(rafthttp.Pausable) - p.Pause() -} - -func (r *raftNode) resumeSending() { - p := r.transport.(rafthttp.Pausable) - p.Resume() -} - -// advanceTicks advances ticks of Raft node. -// This can be used for fast-forwarding election -// ticks in multi data-center deployments, thus -// speeding up election process. -func (r *raftNode) advanceTicks(ticks int) { - for i := 0; i < ticks; i++ { - r.tick() - } -} - -func startNode(cfg ServerConfig, cl *membership.RaftCluster, ids []types.ID) (id types.ID, n raft.Node, s *raft.MemoryStorage, w *wal.WAL) { - var err error - member := cl.MemberByName(cfg.Name) - metadata := pbutil.MustMarshal( - &pb.Metadata{ - NodeID: uint64(member.ID), - ClusterID: uint64(cl.ID()), - }, - ) - if w, err = wal.Create(cfg.WALDir(), metadata); err != nil { - plog.Panicf("create wal error: %v", err) - } - peers := make([]raft.Peer, len(ids)) - for i, id := range ids { - ctx, err := json.Marshal((*cl).Member(id)) - if err != nil { - plog.Panicf("marshal member should never fail: %v", err) - } - peers[i] = raft.Peer{ID: uint64(id), Context: ctx} - } - id = member.ID - plog.Infof("starting member %s in cluster %s", id, cl.ID()) - s = raft.NewMemoryStorage() - c := &raft.Config{ - ID: uint64(id), - ElectionTick: cfg.ElectionTicks, - HeartbeatTick: 1, - Storage: s, - MaxSizePerMsg: maxSizePerMsg, - MaxInflightMsgs: maxInflightMsgs, - CheckQuorum: true, - } - - n = raft.StartNode(c, peers) - raftStatusMu.Lock() - raftStatus = n.Status - raftStatusMu.Unlock() - return id, n, s, w -} - -func restartNode(cfg ServerConfig, snapshot *raftpb.Snapshot) (types.ID, *membership.RaftCluster, raft.Node, *raft.MemoryStorage, *wal.WAL) { - var walsnap walpb.Snapshot - if snapshot != nil { - walsnap.Index, walsnap.Term = snapshot.Metadata.Index, snapshot.Metadata.Term - } - w, id, cid, st, ents := readWAL(cfg.WALDir(), walsnap) - - plog.Infof("restarting member %s in cluster %s at commit index %d", id, cid, st.Commit) - cl := membership.NewCluster("") - cl.SetID(cid) - s := raft.NewMemoryStorage() - if snapshot != nil { - s.ApplySnapshot(*snapshot) - } - s.SetHardState(st) - s.Append(ents) - c := &raft.Config{ - ID: uint64(id), - ElectionTick: cfg.ElectionTicks, - HeartbeatTick: 1, - Storage: s, - MaxSizePerMsg: maxSizePerMsg, - MaxInflightMsgs: maxInflightMsgs, - CheckQuorum: true, - } - - n := raft.RestartNode(c) - raftStatusMu.Lock() - raftStatus = n.Status - raftStatusMu.Unlock() - return id, cl, n, s, w -} - -func restartAsStandaloneNode(cfg ServerConfig, snapshot *raftpb.Snapshot) (types.ID, *membership.RaftCluster, raft.Node, *raft.MemoryStorage, *wal.WAL) { - var walsnap walpb.Snapshot - if snapshot != nil { - walsnap.Index, walsnap.Term = snapshot.Metadata.Index, snapshot.Metadata.Term - } - w, id, cid, st, ents := readWAL(cfg.WALDir(), walsnap) - - // discard the previously uncommitted entries - for i, ent := range ents { - if ent.Index > st.Commit { - plog.Infof("discarding %d uncommitted WAL entries ", len(ents)-i) - ents = ents[:i] - break - } - } - - // force append the configuration change entries - toAppEnts := createConfigChangeEnts(getIDs(snapshot, ents), uint64(id), st.Term, st.Commit) - ents = append(ents, toAppEnts...) - - // force commit newly appended entries - err := w.Save(raftpb.HardState{}, toAppEnts) - if err != nil { - plog.Fatalf("%v", err) - } - if len(ents) != 0 { - st.Commit = ents[len(ents)-1].Index - } - - plog.Printf("forcing restart of member %s in cluster %s at commit index %d", id, cid, st.Commit) - cl := membership.NewCluster("") - cl.SetID(cid) - s := raft.NewMemoryStorage() - if snapshot != nil { - s.ApplySnapshot(*snapshot) - } - s.SetHardState(st) - s.Append(ents) - c := &raft.Config{ - ID: uint64(id), - ElectionTick: cfg.ElectionTicks, - HeartbeatTick: 1, - Storage: s, - MaxSizePerMsg: maxSizePerMsg, - MaxInflightMsgs: maxInflightMsgs, - CheckQuorum: true, - } - n := raft.RestartNode(c) - raftStatus = n.Status - return id, cl, n, s, w -} - -// getIDs returns an ordered set of IDs included in the given snapshot and -// the entries. The given snapshot/entries can contain two kinds of -// ID-related entry: -// - ConfChangeAddNode, in which case the contained ID will be added into the set. -// - ConfChangeRemoveNode, in which case the contained ID will be removed from the set. -func getIDs(snap *raftpb.Snapshot, ents []raftpb.Entry) []uint64 { - ids := make(map[uint64]bool) - if snap != nil { - for _, id := range snap.Metadata.ConfState.Nodes { - ids[id] = true - } - } - for _, e := range ents { - if e.Type != raftpb.EntryConfChange { - continue - } - var cc raftpb.ConfChange - pbutil.MustUnmarshal(&cc, e.Data) - switch cc.Type { - case raftpb.ConfChangeAddNode: - ids[cc.NodeID] = true - case raftpb.ConfChangeRemoveNode: - delete(ids, cc.NodeID) - case raftpb.ConfChangeUpdateNode: - // do nothing - default: - plog.Panicf("ConfChange Type should be either ConfChangeAddNode or ConfChangeRemoveNode!") - } - } - sids := make(types.Uint64Slice, 0, len(ids)) - for id := range ids { - sids = append(sids, id) - } - sort.Sort(sids) - return []uint64(sids) -} - -// createConfigChangeEnts creates a series of Raft entries (i.e. -// EntryConfChange) to remove the set of given IDs from the cluster. The ID -// `self` is _not_ removed, even if present in the set. -// If `self` is not inside the given ids, it creates a Raft entry to add a -// default member with the given `self`. -func createConfigChangeEnts(ids []uint64, self uint64, term, index uint64) []raftpb.Entry { - ents := make([]raftpb.Entry, 0) - next := index + 1 - found := false - for _, id := range ids { - if id == self { - found = true - continue - } - cc := &raftpb.ConfChange{ - Type: raftpb.ConfChangeRemoveNode, - NodeID: id, - } - e := raftpb.Entry{ - Type: raftpb.EntryConfChange, - Data: pbutil.MustMarshal(cc), - Term: term, - Index: next, - } - ents = append(ents, e) - next++ - } - if !found { - m := membership.Member{ - ID: types.ID(self), - RaftAttributes: membership.RaftAttributes{PeerURLs: []string{"http://localhost:2380"}}, - } - ctx, err := json.Marshal(m) - if err != nil { - plog.Panicf("marshal member should never fail: %v", err) - } - cc := &raftpb.ConfChange{ - Type: raftpb.ConfChangeAddNode, - NodeID: self, - Context: ctx, - } - e := raftpb.Entry{ - Type: raftpb.EntryConfChange, - Data: pbutil.MustMarshal(cc), - Term: term, - Index: next, - } - ents = append(ents, e) - } - return ents -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/server.go b/vendor/github.com/coreos/etcd/etcdserver/server.go deleted file mode 100644 index 71e2bcf4bc73..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/server.go +++ /dev/null @@ -1,1745 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "context" - "encoding/json" - "expvar" - "fmt" - "math" - "math/rand" - "net/http" - "os" - "path" - "regexp" - "sync" - "sync/atomic" - "time" - - "github.com/coreos/etcd/alarm" - "github.com/coreos/etcd/auth" - "github.com/coreos/etcd/compactor" - "github.com/coreos/etcd/discovery" - "github.com/coreos/etcd/etcdserver/api" - "github.com/coreos/etcd/etcdserver/api/v2http/httptypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/etcdserver/stats" - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/lease/leasehttp" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/pkg/fileutil" - "github.com/coreos/etcd/pkg/idutil" - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/pkg/runtime" - "github.com/coreos/etcd/pkg/schedule" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/pkg/wait" - "github.com/coreos/etcd/raft" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/rafthttp" - "github.com/coreos/etcd/snap" - "github.com/coreos/etcd/store" - "github.com/coreos/etcd/version" - "github.com/coreos/etcd/wal" - - "github.com/coreos/go-semver/semver" - "github.com/coreos/pkg/capnslog" - "github.com/prometheus/client_golang/prometheus" -) - -const ( - DefaultSnapCount = 100000 - - StoreClusterPrefix = "/0" - StoreKeysPrefix = "/1" - - // HealthInterval is the minimum time the cluster should be healthy - // before accepting add member requests. - HealthInterval = 5 * time.Second - - purgeFileInterval = 30 * time.Second - // monitorVersionInterval should be smaller than the timeout - // on the connection. Or we will not be able to reuse the connection - // (since it will timeout). - monitorVersionInterval = rafthttp.ConnWriteTimeout - time.Second - - // max number of in-flight snapshot messages etcdserver allows to have - // This number is more than enough for most clusters with 5 machines. - maxInFlightMsgSnap = 16 - - releaseDelayAfterSnapshot = 30 * time.Second - - // maxPendingRevokes is the maximum number of outstanding expired lease revocations. - maxPendingRevokes = 16 - - recommendedMaxRequestBytes = 10 * 1024 * 1024 -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdserver") - - storeMemberAttributeRegexp = regexp.MustCompile(path.Join(membership.StoreMembersPrefix, "[[:xdigit:]]{1,16}", "attributes")) -) - -func init() { - rand.Seed(time.Now().UnixNano()) - - expvar.Publish( - "file_descriptor_limit", - expvar.Func( - func() interface{} { - n, _ := runtime.FDLimit() - return n - }, - ), - ) -} - -type Response struct { - Term uint64 - Index uint64 - Event *store.Event - Watcher store.Watcher - Err error -} - -type ServerV2 interface { - Server - // Do takes a V2 request and attempts to fulfill it, returning a Response. - Do(ctx context.Context, r pb.Request) (Response, error) - stats.Stats - ClientCertAuthEnabled() bool -} - -type ServerV3 interface { - Server - ID() types.ID - RaftTimer -} - -func (s *EtcdServer) ClientCertAuthEnabled() bool { return s.Cfg.ClientCertAuthEnabled } - -type Server interface { - // Leader returns the ID of the leader Server. - Leader() types.ID - - // AddMember attempts to add a member into the cluster. It will return - // ErrIDRemoved if member ID is removed from the cluster, or return - // ErrIDExists if member ID exists in the cluster. - AddMember(ctx context.Context, memb membership.Member) ([]*membership.Member, error) - // RemoveMember attempts to remove a member from the cluster. It will - // return ErrIDRemoved if member ID is removed from the cluster, or return - // ErrIDNotFound if member ID is not in the cluster. - RemoveMember(ctx context.Context, id uint64) ([]*membership.Member, error) - // UpdateMember attempts to update an existing member in the cluster. It will - // return ErrIDNotFound if the member ID does not exist. - UpdateMember(ctx context.Context, updateMemb membership.Member) ([]*membership.Member, error) - - // ClusterVersion is the cluster-wide minimum major.minor version. - // Cluster version is set to the min version that an etcd member is - // compatible with when first bootstrap. - // - // ClusterVersion is nil until the cluster is bootstrapped (has a quorum). - // - // During a rolling upgrades, the ClusterVersion will be updated - // automatically after a sync. (5 second by default) - // - // The API/raft component can utilize ClusterVersion to determine if - // it can accept a client request or a raft RPC. - // NOTE: ClusterVersion might be nil when etcd 2.1 works with etcd 2.0 and - // the leader is etcd 2.0. etcd 2.0 leader will not update clusterVersion since - // this feature is introduced post 2.0. - ClusterVersion() *semver.Version - Cluster() api.Cluster - Alarms() []*pb.AlarmMember -} - -// EtcdServer is the production implementation of the Server interface -type EtcdServer struct { - // inflightSnapshots holds count the number of snapshots currently inflight. - inflightSnapshots int64 // must use atomic operations to access; keep 64-bit aligned. - appliedIndex uint64 // must use atomic operations to access; keep 64-bit aligned. - committedIndex uint64 // must use atomic operations to access; keep 64-bit aligned. - // consistIndex used to hold the offset of current executing entry - // It is initialized to 0 before executing any entry. - consistIndex consistentIndex // must use atomic operations to access; keep 64-bit aligned. - r raftNode // uses 64-bit atomics; keep 64-bit aligned. - - readych chan struct{} - Cfg ServerConfig - - w wait.Wait - - readMu sync.RWMutex - // read routine notifies etcd server that it waits for reading by sending an empty struct to - // readwaitC - readwaitc chan struct{} - // readNotifier is used to notify the read routine that it can process the request - // when there is no error - readNotifier *notifier - - // stop signals the run goroutine should shutdown. - stop chan struct{} - // stopping is closed by run goroutine on shutdown. - stopping chan struct{} - // done is closed when all goroutines from start() complete. - done chan struct{} - - errorc chan error - id types.ID - attributes membership.Attributes - - cluster *membership.RaftCluster - - store store.Store - snapshotter *snap.Snapshotter - - applyV2 ApplierV2 - - // applyV3 is the applier with auth and quotas - applyV3 applierV3 - // applyV3Base is the core applier without auth or quotas - applyV3Base applierV3 - applyWait wait.WaitTime - - kv mvcc.ConsistentWatchableKV - lessor lease.Lessor - bemu sync.Mutex - be backend.Backend - authStore auth.AuthStore - alarmStore *alarm.AlarmStore - - stats *stats.ServerStats - lstats *stats.LeaderStats - - SyncTicker *time.Ticker - // compactor is used to auto-compact the KV. - compactor compactor.Compactor - - // peerRt used to send requests (version, lease) to peers. - peerRt http.RoundTripper - reqIDGen *idutil.Generator - - // forceVersionC is used to force the version monitor loop - // to detect the cluster version immediately. - forceVersionC chan struct{} - - // wgMu blocks concurrent waitgroup mutation while server stopping - wgMu sync.RWMutex - // wg is used to wait for the go routines that depends on the server state - // to exit when stopping the server. - wg sync.WaitGroup - - // ctx is used for etcd-initiated requests that may need to be canceled - // on etcd server shutdown. - ctx context.Context - cancel context.CancelFunc - - leadTimeMu sync.RWMutex - leadElectedTime time.Time -} - -// NewServer creates a new EtcdServer from the supplied configuration. The -// configuration is considered static for the lifetime of the EtcdServer. -func NewServer(cfg ServerConfig) (srv *EtcdServer, err error) { - st := store.New(StoreClusterPrefix, StoreKeysPrefix) - - var ( - w *wal.WAL - n raft.Node - s *raft.MemoryStorage - id types.ID - cl *membership.RaftCluster - ) - - if cfg.MaxRequestBytes > recommendedMaxRequestBytes { - plog.Warningf("MaxRequestBytes %v exceeds maximum recommended size %v", cfg.MaxRequestBytes, recommendedMaxRequestBytes) - } - - if terr := fileutil.TouchDirAll(cfg.DataDir); terr != nil { - return nil, fmt.Errorf("cannot access data directory: %v", terr) - } - - haveWAL := wal.Exist(cfg.WALDir()) - - if err = fileutil.TouchDirAll(cfg.SnapDir()); err != nil { - plog.Fatalf("create snapshot directory error: %v", err) - } - ss := snap.New(cfg.SnapDir()) - - bepath := cfg.backendPath() - beExist := fileutil.Exist(bepath) - be := openBackend(cfg) - - defer func() { - if err != nil { - be.Close() - } - }() - - prt, err := rafthttp.NewRoundTripper(cfg.PeerTLSInfo, cfg.peerDialTimeout()) - if err != nil { - return nil, err - } - var ( - remotes []*membership.Member - snapshot *raftpb.Snapshot - ) - - switch { - case !haveWAL && !cfg.NewCluster: - if err = cfg.VerifyJoinExisting(); err != nil { - return nil, err - } - cl, err = membership.NewClusterFromURLsMap(cfg.InitialClusterToken, cfg.InitialPeerURLsMap) - if err != nil { - return nil, err - } - existingCluster, gerr := GetClusterFromRemotePeers(getRemotePeerURLs(cl, cfg.Name), prt) - if gerr != nil { - return nil, fmt.Errorf("cannot fetch cluster info from peer urls: %v", gerr) - } - if err = membership.ValidateClusterAndAssignIDs(cl, existingCluster); err != nil { - return nil, fmt.Errorf("error validating peerURLs %s: %v", existingCluster, err) - } - if !isCompatibleWithCluster(cl, cl.MemberByName(cfg.Name).ID, prt) { - return nil, fmt.Errorf("incompatible with current running cluster") - } - - remotes = existingCluster.Members() - cl.SetID(existingCluster.ID()) - cl.SetStore(st) - cl.SetBackend(be) - cfg.Print() - id, n, s, w = startNode(cfg, cl, nil) - case !haveWAL && cfg.NewCluster: - if err = cfg.VerifyBootstrap(); err != nil { - return nil, err - } - cl, err = membership.NewClusterFromURLsMap(cfg.InitialClusterToken, cfg.InitialPeerURLsMap) - if err != nil { - return nil, err - } - m := cl.MemberByName(cfg.Name) - if isMemberBootstrapped(cl, cfg.Name, prt, cfg.bootstrapTimeout()) { - return nil, fmt.Errorf("member %s has already been bootstrapped", m.ID) - } - if cfg.ShouldDiscover() { - var str string - str, err = discovery.JoinCluster(cfg.DiscoveryURL, cfg.DiscoveryProxy, m.ID, cfg.InitialPeerURLsMap.String()) - if err != nil { - return nil, &DiscoveryError{Op: "join", Err: err} - } - var urlsmap types.URLsMap - urlsmap, err = types.NewURLsMap(str) - if err != nil { - return nil, err - } - if checkDuplicateURL(urlsmap) { - return nil, fmt.Errorf("discovery cluster %s has duplicate url", urlsmap) - } - if cl, err = membership.NewClusterFromURLsMap(cfg.InitialClusterToken, urlsmap); err != nil { - return nil, err - } - } - cl.SetStore(st) - cl.SetBackend(be) - cfg.PrintWithInitial() - id, n, s, w = startNode(cfg, cl, cl.MemberIDs()) - case haveWAL: - if err = fileutil.IsDirWriteable(cfg.MemberDir()); err != nil { - return nil, fmt.Errorf("cannot write to member directory: %v", err) - } - - if err = fileutil.IsDirWriteable(cfg.WALDir()); err != nil { - return nil, fmt.Errorf("cannot write to WAL directory: %v", err) - } - - if cfg.ShouldDiscover() { - plog.Warningf("discovery token ignored since a cluster has already been initialized. Valid log found at %q", cfg.WALDir()) - } - snapshot, err = ss.Load() - if err != nil && err != snap.ErrNoSnapshot { - return nil, err - } - if snapshot != nil { - if err = st.Recovery(snapshot.Data); err != nil { - plog.Panicf("recovered store from snapshot error: %v", err) - } - plog.Infof("recovered store from snapshot at index %d", snapshot.Metadata.Index) - if be, err = recoverSnapshotBackend(cfg, be, *snapshot); err != nil { - plog.Panicf("recovering backend from snapshot error: %v", err) - } - } - cfg.Print() - if !cfg.ForceNewCluster { - id, cl, n, s, w = restartNode(cfg, snapshot) - } else { - id, cl, n, s, w = restartAsStandaloneNode(cfg, snapshot) - } - cl.SetStore(st) - cl.SetBackend(be) - cl.Recover(api.UpdateCapability) - if cl.Version() != nil && !cl.Version().LessThan(semver.Version{Major: 3}) && !beExist { - os.RemoveAll(bepath) - return nil, fmt.Errorf("database file (%v) of the backend is missing", bepath) - } - default: - return nil, fmt.Errorf("unsupported bootstrap config") - } - - if terr := fileutil.TouchDirAll(cfg.MemberDir()); terr != nil { - return nil, fmt.Errorf("cannot access member directory: %v", terr) - } - - sstats := stats.NewServerStats(cfg.Name, id.String()) - lstats := stats.NewLeaderStats(id.String()) - - heartbeat := time.Duration(cfg.TickMs) * time.Millisecond - srv = &EtcdServer{ - readych: make(chan struct{}), - Cfg: cfg, - errorc: make(chan error, 1), - store: st, - snapshotter: ss, - r: *newRaftNode( - raftNodeConfig{ - isIDRemoved: func(id uint64) bool { return cl.IsIDRemoved(types.ID(id)) }, - Node: n, - heartbeat: heartbeat, - raftStorage: s, - storage: NewStorage(w, ss), - }, - ), - id: id, - attributes: membership.Attributes{Name: cfg.Name, ClientURLs: cfg.ClientURLs.StringSlice()}, - cluster: cl, - stats: sstats, - lstats: lstats, - SyncTicker: time.NewTicker(500 * time.Millisecond), - peerRt: prt, - reqIDGen: idutil.NewGenerator(uint16(id), time.Now()), - forceVersionC: make(chan struct{}), - } - serverID.With(prometheus.Labels{"server_id": id.String()}).Set(1) - - srv.applyV2 = &applierV2store{store: srv.store, cluster: srv.cluster} - - srv.be = be - minTTL := time.Duration((3*cfg.ElectionTicks)/2) * heartbeat - - // always recover lessor before kv. When we recover the mvcc.KV it will reattach keys to its leases. - // If we recover mvcc.KV first, it will attach the keys to the wrong lessor before it recovers. - srv.lessor = lease.NewLessor(srv.be, int64(math.Ceil(minTTL.Seconds()))) - srv.kv = mvcc.New(srv.be, srv.lessor, &srv.consistIndex) - if beExist { - kvindex := srv.kv.ConsistentIndex() - // TODO: remove kvindex != 0 checking when we do not expect users to upgrade - // etcd from pre-3.0 release. - if snapshot != nil && kvindex < snapshot.Metadata.Index { - if kvindex != 0 { - return nil, fmt.Errorf("database file (%v index %d) does not match with snapshot (index %d).", bepath, kvindex, snapshot.Metadata.Index) - } - plog.Warningf("consistent index never saved (snapshot index=%d)", snapshot.Metadata.Index) - } - } - newSrv := srv // since srv == nil in defer if srv is returned as nil - defer func() { - // closing backend without first closing kv can cause - // resumed compactions to fail with closed tx errors - if err != nil { - newSrv.kv.Close() - } - }() - - srv.consistIndex.setConsistentIndex(srv.kv.ConsistentIndex()) - tp, err := auth.NewTokenProvider(cfg.AuthToken, - func(index uint64) <-chan struct{} { - return srv.applyWait.Wait(index) - }, - ) - if err != nil { - plog.Errorf("failed to create token provider: %s", err) - return nil, err - } - srv.authStore = auth.NewAuthStore(srv.be, tp) - if num := cfg.AutoCompactionRetention; num != 0 { - srv.compactor, err = compactor.New(cfg.AutoCompactionMode, num, srv.kv, srv) - if err != nil { - return nil, err - } - srv.compactor.Run() - } - - srv.applyV3Base = srv.newApplierV3Backend() - if err = srv.restoreAlarms(); err != nil { - return nil, err - } - - // TODO: move transport initialization near the definition of remote - tr := &rafthttp.Transport{ - TLSInfo: cfg.PeerTLSInfo, - DialTimeout: cfg.peerDialTimeout(), - ID: id, - URLs: cfg.PeerURLs, - ClusterID: cl.ID(), - Raft: srv, - Snapshotter: ss, - ServerStats: sstats, - LeaderStats: lstats, - ErrorC: srv.errorc, - } - if err = tr.Start(); err != nil { - return nil, err - } - // add all remotes into transport - for _, m := range remotes { - if m.ID != id { - tr.AddRemote(m.ID, m.PeerURLs) - } - } - for _, m := range cl.Members() { - if m.ID != id { - tr.AddPeer(m.ID, m.PeerURLs) - } - } - srv.r.transport = tr - - return srv, nil -} - -func (s *EtcdServer) adjustTicks() { - clusterN := len(s.cluster.Members()) - - // single-node fresh start, or single-node recovers from snapshot - if clusterN == 1 { - ticks := s.Cfg.ElectionTicks - 1 - plog.Infof("%s as single-node; fast-forwarding %d ticks (election ticks %d)", s.ID(), ticks, s.Cfg.ElectionTicks) - s.r.advanceTicks(ticks) - return - } - - if !s.Cfg.InitialElectionTickAdvance { - plog.Infof("skipping initial election tick advance (election tick %d)", s.Cfg.ElectionTicks) - return - } - - // retry up to "rafthttp.ConnReadTimeout", which is 5-sec - // until peer connection reports; otherwise: - // 1. all connections failed, or - // 2. no active peers, or - // 3. restarted single-node with no snapshot - // then, do nothing, because advancing ticks would have no effect - waitTime := rafthttp.ConnReadTimeout - itv := 50 * time.Millisecond - for i := int64(0); i < int64(waitTime/itv); i++ { - select { - case <-time.After(itv): - case <-s.stopping: - return - } - - peerN := s.r.transport.ActivePeers() - if peerN > 1 { - // multi-node received peer connection reports - // adjust ticks, in case slow leader message receive - ticks := s.Cfg.ElectionTicks - 2 - plog.Infof("%s initialzed peer connection; fast-forwarding %d ticks (election ticks %d) with %d active peer(s)", s.ID(), ticks, s.Cfg.ElectionTicks, peerN) - s.r.advanceTicks(ticks) - return - } - } -} - -// Start performs any initialization of the Server necessary for it to -// begin serving requests. It must be called before Do or Process. -// Start must be non-blocking; any long-running server functionality -// should be implemented in goroutines. -func (s *EtcdServer) Start() { - s.start() - s.goAttach(func() { s.adjustTicks() }) - s.goAttach(func() { s.publish(s.Cfg.ReqTimeout()) }) - s.goAttach(s.purgeFile) - s.goAttach(func() { monitorFileDescriptor(s.stopping) }) - s.goAttach(s.monitorVersions) - s.goAttach(s.linearizableReadLoop) - s.goAttach(s.monitorKVHash) -} - -// start prepares and starts server in a new goroutine. It is no longer safe to -// modify a server's fields after it has been sent to Start. -// This function is just used for testing. -func (s *EtcdServer) start() { - if s.Cfg.SnapCount == 0 { - plog.Infof("set snapshot count to default %d", DefaultSnapCount) - s.Cfg.SnapCount = DefaultSnapCount - } - s.w = wait.New() - s.applyWait = wait.NewTimeList() - s.done = make(chan struct{}) - s.stop = make(chan struct{}) - s.stopping = make(chan struct{}) - s.ctx, s.cancel = context.WithCancel(context.Background()) - s.readwaitc = make(chan struct{}, 1) - s.readNotifier = newNotifier() - if s.ClusterVersion() != nil { - plog.Infof("starting server... [version: %v, cluster version: %v]", version.Version, version.Cluster(s.ClusterVersion().String())) - } else { - plog.Infof("starting server... [version: %v, cluster version: to_be_decided]", version.Version) - } - // TODO: if this is an empty log, writes all peer infos - // into the first entry - go s.run() -} - -func (s *EtcdServer) purgeFile() { - var dberrc, serrc, werrc <-chan error - if s.Cfg.MaxSnapFiles > 0 { - dberrc = fileutil.PurgeFile(s.Cfg.SnapDir(), "snap.db", s.Cfg.MaxSnapFiles, purgeFileInterval, s.done) - serrc = fileutil.PurgeFile(s.Cfg.SnapDir(), "snap", s.Cfg.MaxSnapFiles, purgeFileInterval, s.done) - } - if s.Cfg.MaxWALFiles > 0 { - werrc = fileutil.PurgeFile(s.Cfg.WALDir(), "wal", s.Cfg.MaxWALFiles, purgeFileInterval, s.done) - } - select { - case e := <-dberrc: - plog.Fatalf("failed to purge snap db file %v", e) - case e := <-serrc: - plog.Fatalf("failed to purge snap file %v", e) - case e := <-werrc: - plog.Fatalf("failed to purge wal file %v", e) - case <-s.stopping: - return - } -} - -func (s *EtcdServer) ID() types.ID { return s.id } - -func (s *EtcdServer) Cluster() api.Cluster { return s.cluster } - -func (s *EtcdServer) ApplyWait() <-chan struct{} { return s.applyWait.Wait(s.getCommittedIndex()) } - -type ServerPeer interface { - ServerV2 - RaftHandler() http.Handler - LeaseHandler() http.Handler -} - -func (s *EtcdServer) LeaseHandler() http.Handler { - if s.lessor == nil { - return nil - } - return leasehttp.NewHandler(s.lessor, s.ApplyWait) -} - -func (s *EtcdServer) RaftHandler() http.Handler { return s.r.transport.Handler() } - -// Process takes a raft message and applies it to the server's raft state -// machine, respecting any timeout of the given context. -func (s *EtcdServer) Process(ctx context.Context, m raftpb.Message) error { - if s.cluster.IsIDRemoved(types.ID(m.From)) { - plog.Warningf("reject message from removed member %s", types.ID(m.From).String()) - return httptypes.NewHTTPError(http.StatusForbidden, "cannot process message from removed member") - } - if m.Type == raftpb.MsgApp { - s.stats.RecvAppendReq(types.ID(m.From).String(), m.Size()) - } - return s.r.Step(ctx, m) -} - -func (s *EtcdServer) IsIDRemoved(id uint64) bool { return s.cluster.IsIDRemoved(types.ID(id)) } - -func (s *EtcdServer) ReportUnreachable(id uint64) { s.r.ReportUnreachable(id) } - -// ReportSnapshot reports snapshot sent status to the raft state machine, -// and clears the used snapshot from the snapshot store. -func (s *EtcdServer) ReportSnapshot(id uint64, status raft.SnapshotStatus) { - s.r.ReportSnapshot(id, status) -} - -type etcdProgress struct { - confState raftpb.ConfState - snapi uint64 - appliedt uint64 - appliedi uint64 -} - -// raftReadyHandler contains a set of EtcdServer operations to be called by raftNode, -// and helps decouple state machine logic from Raft algorithms. -// TODO: add a state machine interface to apply the commit entries and do snapshot/recover -type raftReadyHandler struct { - updateLeadership func(newLeader bool) - updateCommittedIndex func(uint64) -} - -func (s *EtcdServer) run() { - sn, err := s.r.raftStorage.Snapshot() - if err != nil { - plog.Panicf("get snapshot from raft storage error: %v", err) - } - - // asynchronously accept apply packets, dispatch progress in-order - sched := schedule.NewFIFOScheduler() - - var ( - smu sync.RWMutex - syncC <-chan time.Time - ) - setSyncC := func(ch <-chan time.Time) { - smu.Lock() - syncC = ch - smu.Unlock() - } - getSyncC := func() (ch <-chan time.Time) { - smu.RLock() - ch = syncC - smu.RUnlock() - return - } - rh := &raftReadyHandler{ - updateLeadership: func(newLeader bool) { - if !s.isLeader() { - if s.lessor != nil { - s.lessor.Demote() - } - if s.compactor != nil { - s.compactor.Pause() - } - setSyncC(nil) - } else { - if newLeader { - t := time.Now() - s.leadTimeMu.Lock() - s.leadElectedTime = t - s.leadTimeMu.Unlock() - } - setSyncC(s.SyncTicker.C) - if s.compactor != nil { - s.compactor.Resume() - } - } - - // TODO: remove the nil checking - // current test utility does not provide the stats - if s.stats != nil { - s.stats.BecomeLeader() - } - }, - updateCommittedIndex: func(ci uint64) { - cci := s.getCommittedIndex() - if ci > cci { - s.setCommittedIndex(ci) - } - }, - } - s.r.start(rh) - - ep := etcdProgress{ - confState: sn.Metadata.ConfState, - snapi: sn.Metadata.Index, - appliedt: sn.Metadata.Term, - appliedi: sn.Metadata.Index, - } - - defer func() { - s.wgMu.Lock() // block concurrent waitgroup adds in goAttach while stopping - close(s.stopping) - s.wgMu.Unlock() - s.cancel() - - sched.Stop() - - // wait for gouroutines before closing raft so wal stays open - s.wg.Wait() - - s.SyncTicker.Stop() - - // must stop raft after scheduler-- etcdserver can leak rafthttp pipelines - // by adding a peer after raft stops the transport - s.r.stop() - - // kv, lessor and backend can be nil if running without v3 enabled - // or running unit tests. - if s.lessor != nil { - s.lessor.Stop() - } - if s.kv != nil { - s.kv.Close() - } - if s.authStore != nil { - s.authStore.Close() - } - if s.be != nil { - s.be.Close() - } - if s.compactor != nil { - s.compactor.Stop() - } - close(s.done) - }() - - var expiredLeaseC <-chan []*lease.Lease - if s.lessor != nil { - expiredLeaseC = s.lessor.ExpiredLeasesC() - } - - for { - select { - case ap := <-s.r.apply(): - f := func(context.Context) { s.applyAll(&ep, &ap) } - sched.Schedule(f) - case leases := <-expiredLeaseC: - s.goAttach(func() { - // Increases throughput of expired leases deletion process through parallelization - c := make(chan struct{}, maxPendingRevokes) - for _, lease := range leases { - select { - case c <- struct{}{}: - case <-s.stopping: - return - } - lid := lease.ID - s.goAttach(func() { - ctx := s.authStore.WithRoot(s.ctx) - _, lerr := s.LeaseRevoke(ctx, &pb.LeaseRevokeRequest{ID: int64(lid)}) - if lerr == nil { - leaseExpired.Inc() - } else { - plog.Warningf("failed to revoke %016x (%q)", lid, lerr.Error()) - } - - <-c - }) - } - }) - case err := <-s.errorc: - plog.Errorf("%s", err) - plog.Infof("the data-dir used by this member must be removed.") - return - case <-getSyncC(): - if s.store.HasTTLKeys() { - s.sync(s.Cfg.ReqTimeout()) - } - case <-s.stop: - return - } - } -} - -func (s *EtcdServer) applyAll(ep *etcdProgress, apply *apply) { - s.applySnapshot(ep, apply) - s.applyEntries(ep, apply) - - proposalsApplied.Set(float64(ep.appliedi)) - s.applyWait.Trigger(ep.appliedi) - // wait for the raft routine to finish the disk writes before triggering a - // snapshot. or applied index might be greater than the last index in raft - // storage, since the raft routine might be slower than apply routine. - <-apply.notifyc - - s.triggerSnapshot(ep) - select { - // snapshot requested via send() - case m := <-s.r.msgSnapC: - merged := s.createMergedSnapshotMessage(m, ep.appliedt, ep.appliedi, ep.confState) - s.sendMergedSnap(merged) - default: - } -} - -func (s *EtcdServer) applySnapshot(ep *etcdProgress, apply *apply) { - if raft.IsEmptySnap(apply.snapshot) { - return - } - - plog.Infof("applying snapshot at index %d...", ep.snapi) - defer plog.Infof("finished applying incoming snapshot at index %d", ep.snapi) - - if apply.snapshot.Metadata.Index <= ep.appliedi { - plog.Panicf("snapshot index [%d] should > appliedi[%d] + 1", - apply.snapshot.Metadata.Index, ep.appliedi) - } - - // wait for raftNode to persist snapshot onto the disk - <-apply.notifyc - - newbe, err := openSnapshotBackend(s.Cfg, s.snapshotter, apply.snapshot) - if err != nil { - plog.Panic(err) - } - - // always recover lessor before kv. When we recover the mvcc.KV it will reattach keys to its leases. - // If we recover mvcc.KV first, it will attach the keys to the wrong lessor before it recovers. - if s.lessor != nil { - plog.Info("recovering lessor...") - s.lessor.Recover(newbe, func() lease.TxnDelete { return s.kv.Write() }) - plog.Info("finished recovering lessor") - } - - plog.Info("restoring mvcc store...") - - if err := s.kv.Restore(newbe); err != nil { - plog.Panicf("restore KV error: %v", err) - } - s.consistIndex.setConsistentIndex(s.kv.ConsistentIndex()) - - plog.Info("finished restoring mvcc store") - - // Closing old backend might block until all the txns - // on the backend are finished. - // We do not want to wait on closing the old backend. - s.bemu.Lock() - oldbe := s.be - go func() { - plog.Info("closing old backend...") - defer plog.Info("finished closing old backend") - - if err := oldbe.Close(); err != nil { - plog.Panicf("close backend error: %v", err) - } - }() - - s.be = newbe - s.bemu.Unlock() - - plog.Info("recovering alarms...") - if err := s.restoreAlarms(); err != nil { - plog.Panicf("restore alarms error: %v", err) - } - plog.Info("finished recovering alarms") - - if s.authStore != nil { - plog.Info("recovering auth store...") - s.authStore.Recover(newbe) - plog.Info("finished recovering auth store") - } - - plog.Info("recovering store v2...") - if err := s.store.Recovery(apply.snapshot.Data); err != nil { - plog.Panicf("recovery store error: %v", err) - } - plog.Info("finished recovering store v2") - - s.cluster.SetBackend(s.be) - plog.Info("recovering cluster configuration...") - s.cluster.Recover(api.UpdateCapability) - plog.Info("finished recovering cluster configuration") - - plog.Info("removing old peers from network...") - // recover raft transport - s.r.transport.RemoveAllPeers() - plog.Info("finished removing old peers from network") - - plog.Info("adding peers from new cluster configuration into network...") - for _, m := range s.cluster.Members() { - if m.ID == s.ID() { - continue - } - s.r.transport.AddPeer(m.ID, m.PeerURLs) - } - plog.Info("finished adding peers from new cluster configuration into network...") - - ep.appliedt = apply.snapshot.Metadata.Term - ep.appliedi = apply.snapshot.Metadata.Index - ep.snapi = ep.appliedi - ep.confState = apply.snapshot.Metadata.ConfState -} - -func (s *EtcdServer) applyEntries(ep *etcdProgress, apply *apply) { - if len(apply.entries) == 0 { - return - } - firsti := apply.entries[0].Index - if firsti > ep.appliedi+1 { - plog.Panicf("first index of committed entry[%d] should <= appliedi[%d] + 1", firsti, ep.appliedi) - } - var ents []raftpb.Entry - if ep.appliedi+1-firsti < uint64(len(apply.entries)) { - ents = apply.entries[ep.appliedi+1-firsti:] - } - if len(ents) == 0 { - return - } - var shouldstop bool - if ep.appliedt, ep.appliedi, shouldstop = s.apply(ents, &ep.confState); shouldstop { - go s.stopWithDelay(10*100*time.Millisecond, fmt.Errorf("the member has been permanently removed from the cluster")) - } -} - -func (s *EtcdServer) triggerSnapshot(ep *etcdProgress) { - if ep.appliedi-ep.snapi <= s.Cfg.SnapCount { - return - } - - plog.Infof("start to snapshot (applied: %d, lastsnap: %d)", ep.appliedi, ep.snapi) - s.snapshot(ep.appliedi, ep.confState) - ep.snapi = ep.appliedi -} - -func (s *EtcdServer) isMultiNode() bool { - return s.cluster != nil && len(s.cluster.MemberIDs()) > 1 -} - -func (s *EtcdServer) isLeader() bool { - return uint64(s.ID()) == s.Lead() -} - -// MoveLeader transfers the leader to the given transferee. -func (s *EtcdServer) MoveLeader(ctx context.Context, lead, transferee uint64) error { - now := time.Now() - interval := time.Duration(s.Cfg.TickMs) * time.Millisecond - - plog.Infof("%s starts leadership transfer from %s to %s", s.ID(), types.ID(lead), types.ID(transferee)) - s.r.TransferLeadership(ctx, lead, transferee) - for s.Lead() != transferee { - select { - case <-ctx.Done(): // time out - return ErrTimeoutLeaderTransfer - case <-time.After(interval): - } - } - - // TODO: drain all requests, or drop all messages to the old leader - - plog.Infof("%s finished leadership transfer from %s to %s (took %v)", s.ID(), types.ID(lead), types.ID(transferee), time.Since(now)) - return nil -} - -// TransferLeadership transfers the leader to the chosen transferee. -func (s *EtcdServer) TransferLeadership() error { - if !s.isLeader() { - plog.Printf("skipped leadership transfer for stopping non-leader member") - return nil - } - - if !s.isMultiNode() { - plog.Printf("skipped leadership transfer for single member cluster") - return nil - } - - transferee, ok := longestConnected(s.r.transport, s.cluster.MemberIDs()) - if !ok { - return ErrUnhealthy - } - - tm := s.Cfg.ReqTimeout() - ctx, cancel := context.WithTimeout(s.ctx, tm) - err := s.MoveLeader(ctx, s.Lead(), uint64(transferee)) - cancel() - return err -} - -// HardStop stops the server without coordination with other members in the cluster. -func (s *EtcdServer) HardStop() { - select { - case s.stop <- struct{}{}: - case <-s.done: - return - } - <-s.done -} - -// Stop stops the server gracefully, and shuts down the running goroutine. -// Stop should be called after a Start(s), otherwise it will block forever. -// When stopping leader, Stop transfers its leadership to one of its peers -// before stopping the server. -// Stop terminates the Server and performs any necessary finalization. -// Do and Process cannot be called after Stop has been invoked. -func (s *EtcdServer) Stop() { - if err := s.TransferLeadership(); err != nil { - plog.Warningf("%s failed to transfer leadership (%v)", s.ID(), err) - } - s.HardStop() -} - -// ReadyNotify returns a channel that will be closed when the server -// is ready to serve client requests -func (s *EtcdServer) ReadyNotify() <-chan struct{} { return s.readych } - -func (s *EtcdServer) stopWithDelay(d time.Duration, err error) { - select { - case <-time.After(d): - case <-s.done: - } - select { - case s.errorc <- err: - default: - } -} - -// StopNotify returns a channel that receives a empty struct -// when the server is stopped. -func (s *EtcdServer) StopNotify() <-chan struct{} { return s.done } - -func (s *EtcdServer) SelfStats() []byte { return s.stats.JSON() } - -func (s *EtcdServer) LeaderStats() []byte { - lead := atomic.LoadUint64(&s.r.lead) - if lead != uint64(s.id) { - return nil - } - return s.lstats.JSON() -} - -func (s *EtcdServer) StoreStats() []byte { return s.store.JsonStats() } - -func (s *EtcdServer) checkMembershipOperationPermission(ctx context.Context) error { - if s.authStore == nil { - // In the context of ordinary etcd process, s.authStore will never be nil. - // This branch is for handling cases in server_test.go - return nil - } - - // Note that this permission check is done in the API layer, - // so TOCTOU problem can be caused potentially in a schedule like this: - // update membership with user A -> revoke root role of A -> apply membership change - // in the state machine layer - // However, both of membership change and role management requires the root privilege. - // So careful operation by admins can prevent the problem. - authInfo, err := s.AuthInfoFromCtx(ctx) - if err != nil { - return err - } - - return s.AuthStore().IsAdminPermitted(authInfo) -} - -func (s *EtcdServer) AddMember(ctx context.Context, memb membership.Member) ([]*membership.Member, error) { - if err := s.checkMembershipOperationPermission(ctx); err != nil { - return nil, err - } - - if s.Cfg.StrictReconfigCheck { - // by default StrictReconfigCheck is enabled; reject new members if unhealthy - if !s.cluster.IsReadyToAddNewMember() { - plog.Warningf("not enough started members, rejecting member add %+v", memb) - return nil, ErrNotEnoughStartedMembers - } - if !isConnectedFullySince(s.r.transport, time.Now().Add(-HealthInterval), s.ID(), s.cluster.Members()) { - plog.Warningf("not healthy for reconfigure, rejecting member add %+v", memb) - return nil, ErrUnhealthy - } - } - - // TODO: move Member to protobuf type - b, err := json.Marshal(memb) - if err != nil { - return nil, err - } - cc := raftpb.ConfChange{ - Type: raftpb.ConfChangeAddNode, - NodeID: uint64(memb.ID), - Context: b, - } - return s.configure(ctx, cc) -} - -func (s *EtcdServer) RemoveMember(ctx context.Context, id uint64) ([]*membership.Member, error) { - if err := s.checkMembershipOperationPermission(ctx); err != nil { - return nil, err - } - - // by default StrictReconfigCheck is enabled; reject removal if leads to quorum loss - if err := s.mayRemoveMember(types.ID(id)); err != nil { - return nil, err - } - - cc := raftpb.ConfChange{ - Type: raftpb.ConfChangeRemoveNode, - NodeID: id, - } - return s.configure(ctx, cc) -} - -func (s *EtcdServer) mayRemoveMember(id types.ID) error { - if !s.Cfg.StrictReconfigCheck { - return nil - } - - if !s.cluster.IsReadyToRemoveMember(uint64(id)) { - plog.Warningf("not enough started members, rejecting remove member %s", id) - return ErrNotEnoughStartedMembers - } - - // downed member is safe to remove since it's not part of the active quorum - if t := s.r.transport.ActiveSince(id); id != s.ID() && t.IsZero() { - return nil - } - - // protect quorum if some members are down - m := s.cluster.Members() - active := numConnectedSince(s.r.transport, time.Now().Add(-HealthInterval), s.ID(), m) - if (active - 1) < 1+((len(m)-1)/2) { - plog.Warningf("reconfigure breaks active quorum, rejecting remove member %s", id) - return ErrUnhealthy - } - - return nil -} - -func (s *EtcdServer) UpdateMember(ctx context.Context, memb membership.Member) ([]*membership.Member, error) { - b, merr := json.Marshal(memb) - if merr != nil { - return nil, merr - } - - if err := s.checkMembershipOperationPermission(ctx); err != nil { - return nil, err - } - cc := raftpb.ConfChange{ - Type: raftpb.ConfChangeUpdateNode, - NodeID: uint64(memb.ID), - Context: b, - } - return s.configure(ctx, cc) -} - -// Implement the RaftTimer interface - -func (s *EtcdServer) Index() uint64 { return atomic.LoadUint64(&s.r.index) } - -func (s *EtcdServer) Term() uint64 { return atomic.LoadUint64(&s.r.term) } - -// Lead is only for testing purposes. -// TODO: add Raft server interface to expose raft related info: -// Index, Term, Lead, Committed, Applied, LastIndex, etc. -func (s *EtcdServer) Lead() uint64 { return atomic.LoadUint64(&s.r.lead) } - -func (s *EtcdServer) Leader() types.ID { return types.ID(s.Lead()) } - -type confChangeResponse struct { - membs []*membership.Member - err error -} - -// configure sends a configuration change through consensus and -// then waits for it to be applied to the server. It -// will block until the change is performed or there is an error. -func (s *EtcdServer) configure(ctx context.Context, cc raftpb.ConfChange) ([]*membership.Member, error) { - cc.ID = s.reqIDGen.Next() - ch := s.w.Register(cc.ID) - start := time.Now() - if err := s.r.ProposeConfChange(ctx, cc); err != nil { - s.w.Trigger(cc.ID, nil) - return nil, err - } - select { - case x := <-ch: - if x == nil { - plog.Panicf("configure trigger value should never be nil") - } - resp := x.(*confChangeResponse) - return resp.membs, resp.err - case <-ctx.Done(): - s.w.Trigger(cc.ID, nil) // GC wait - return nil, s.parseProposeCtxErr(ctx.Err(), start) - case <-s.stopping: - return nil, ErrStopped - } -} - -// sync proposes a SYNC request and is non-blocking. -// This makes no guarantee that the request will be proposed or performed. -// The request will be canceled after the given timeout. -func (s *EtcdServer) sync(timeout time.Duration) { - req := pb.Request{ - Method: "SYNC", - ID: s.reqIDGen.Next(), - Time: time.Now().UnixNano(), - } - data := pbutil.MustMarshal(&req) - // There is no promise that node has leader when do SYNC request, - // so it uses goroutine to propose. - ctx, cancel := context.WithTimeout(s.ctx, timeout) - s.goAttach(func() { - s.r.Propose(ctx, data) - cancel() - }) -} - -// publish registers server information into the cluster. The information -// is the JSON representation of this server's member struct, updated with the -// static clientURLs of the server. -// The function keeps attempting to register until it succeeds, -// or its server is stopped. -func (s *EtcdServer) publish(timeout time.Duration) { - b, err := json.Marshal(s.attributes) - if err != nil { - plog.Panicf("json marshal error: %v", err) - return - } - req := pb.Request{ - Method: "PUT", - Path: membership.MemberAttributesStorePath(s.id), - Val: string(b), - } - - for { - ctx, cancel := context.WithTimeout(s.ctx, timeout) - _, err := s.Do(ctx, req) - cancel() - switch err { - case nil: - close(s.readych) - plog.Infof("published %+v to cluster %s", s.attributes, s.cluster.ID()) - return - case ErrStopped: - plog.Infof("aborting publish because server is stopped") - return - default: - plog.Errorf("publish error: %v", err) - } - } -} - -func (s *EtcdServer) sendMergedSnap(merged snap.Message) { - atomic.AddInt64(&s.inflightSnapshots, 1) - - s.r.transport.SendSnapshot(merged) - s.goAttach(func() { - select { - case ok := <-merged.CloseNotify(): - // delay releasing inflight snapshot for another 30 seconds to - // block log compaction. - // If the follower still fails to catch up, it is probably just too slow - // to catch up. We cannot avoid the snapshot cycle anyway. - if ok { - select { - case <-time.After(releaseDelayAfterSnapshot): - case <-s.stopping: - } - } - atomic.AddInt64(&s.inflightSnapshots, -1) - case <-s.stopping: - return - } - }) -} - -// apply takes entries received from Raft (after it has been committed) and -// applies them to the current state of the EtcdServer. -// The given entries should not be empty. -func (s *EtcdServer) apply(es []raftpb.Entry, confState *raftpb.ConfState) (appliedt uint64, appliedi uint64, shouldStop bool) { - for i := range es { - e := es[i] - switch e.Type { - case raftpb.EntryNormal: - s.applyEntryNormal(&e) - case raftpb.EntryConfChange: - // set the consistent index of current executing entry - if e.Index > s.consistIndex.ConsistentIndex() { - s.consistIndex.setConsistentIndex(e.Index) - } - var cc raftpb.ConfChange - pbutil.MustUnmarshal(&cc, e.Data) - removedSelf, err := s.applyConfChange(cc, confState) - s.setAppliedIndex(e.Index) - shouldStop = shouldStop || removedSelf - s.w.Trigger(cc.ID, &confChangeResponse{s.cluster.Members(), err}) - default: - plog.Panicf("entry type should be either EntryNormal or EntryConfChange") - } - atomic.StoreUint64(&s.r.index, e.Index) - atomic.StoreUint64(&s.r.term, e.Term) - appliedt = e.Term - appliedi = e.Index - } - return appliedt, appliedi, shouldStop -} - -// applyEntryNormal apples an EntryNormal type raftpb request to the EtcdServer -func (s *EtcdServer) applyEntryNormal(e *raftpb.Entry) { - shouldApplyV3 := false - if e.Index > s.consistIndex.ConsistentIndex() { - // set the consistent index of current executing entry - s.consistIndex.setConsistentIndex(e.Index) - shouldApplyV3 = true - } - defer s.setAppliedIndex(e.Index) - - // raft state machine may generate noop entry when leader confirmation. - // skip it in advance to avoid some potential bug in the future - if len(e.Data) == 0 { - select { - case s.forceVersionC <- struct{}{}: - default: - } - // promote lessor when the local member is leader and finished - // applying all entries from the last term. - if s.isLeader() { - s.lessor.Promote(s.Cfg.electionTimeout()) - } - return - } - - var raftReq pb.InternalRaftRequest - if !pbutil.MaybeUnmarshal(&raftReq, e.Data) { // backward compatible - var r pb.Request - rp := &r - pbutil.MustUnmarshal(rp, e.Data) - s.w.Trigger(r.ID, s.applyV2Request((*RequestV2)(rp))) - return - } - if raftReq.V2 != nil { - req := (*RequestV2)(raftReq.V2) - s.w.Trigger(req.ID, s.applyV2Request(req)) - return - } - - // do not re-apply applied entries. - if !shouldApplyV3 { - return - } - - id := raftReq.ID - if id == 0 { - id = raftReq.Header.ID - } - - var ar *applyResult - needResult := s.w.IsRegistered(id) - if needResult || !noSideEffect(&raftReq) { - if !needResult && raftReq.Txn != nil { - removeNeedlessRangeReqs(raftReq.Txn) - } - ar = s.applyV3.Apply(&raftReq) - } - - if ar == nil { - return - } - - if ar.err != ErrNoSpace || len(s.alarmStore.Get(pb.AlarmType_NOSPACE)) > 0 { - s.w.Trigger(id, ar) - return - } - - plog.Errorf("applying raft message exceeded backend quota") - s.goAttach(func() { - a := &pb.AlarmRequest{ - MemberID: uint64(s.ID()), - Action: pb.AlarmRequest_ACTIVATE, - Alarm: pb.AlarmType_NOSPACE, - } - s.raftRequest(s.ctx, pb.InternalRaftRequest{Alarm: a}) - s.w.Trigger(id, ar) - }) -} - -// applyConfChange applies a ConfChange to the server. It is only -// invoked with a ConfChange that has already passed through Raft -func (s *EtcdServer) applyConfChange(cc raftpb.ConfChange, confState *raftpb.ConfState) (bool, error) { - if err := s.cluster.ValidateConfigurationChange(cc); err != nil { - cc.NodeID = raft.None - s.r.ApplyConfChange(cc) - return false, err - } - *confState = *s.r.ApplyConfChange(cc) - switch cc.Type { - case raftpb.ConfChangeAddNode: - m := new(membership.Member) - if err := json.Unmarshal(cc.Context, m); err != nil { - plog.Panicf("unmarshal member should never fail: %v", err) - } - if cc.NodeID != uint64(m.ID) { - plog.Panicf("nodeID should always be equal to member ID") - } - s.cluster.AddMember(m) - if m.ID != s.id { - s.r.transport.AddPeer(m.ID, m.PeerURLs) - } - case raftpb.ConfChangeRemoveNode: - id := types.ID(cc.NodeID) - s.cluster.RemoveMember(id) - if id == s.id { - return true, nil - } - s.r.transport.RemovePeer(id) - case raftpb.ConfChangeUpdateNode: - m := new(membership.Member) - if err := json.Unmarshal(cc.Context, m); err != nil { - plog.Panicf("unmarshal member should never fail: %v", err) - } - if cc.NodeID != uint64(m.ID) { - plog.Panicf("nodeID should always be equal to member ID") - } - s.cluster.UpdateRaftAttributes(m.ID, m.RaftAttributes) - if m.ID != s.id { - s.r.transport.UpdatePeer(m.ID, m.PeerURLs) - } - } - return false, nil -} - -// TODO: non-blocking snapshot -func (s *EtcdServer) snapshot(snapi uint64, confState raftpb.ConfState) { - clone := s.store.Clone() - // commit kv to write metadata (for example: consistent index) to disk. - // KV().commit() updates the consistent index in backend. - // All operations that update consistent index must be called sequentially - // from applyAll function. - // So KV().Commit() cannot run in parallel with apply. It has to be called outside - // the go routine created below. - s.KV().Commit() - - s.goAttach(func() { - d, err := clone.SaveNoCopy() - // TODO: current store will never fail to do a snapshot - // what should we do if the store might fail? - if err != nil { - plog.Panicf("store save should never fail: %v", err) - } - snap, err := s.r.raftStorage.CreateSnapshot(snapi, &confState, d) - if err != nil { - // the snapshot was done asynchronously with the progress of raft. - // raft might have already got a newer snapshot. - if err == raft.ErrSnapOutOfDate { - return - } - plog.Panicf("unexpected create snapshot error %v", err) - } - // SaveSnap saves the snapshot and releases the locked wal files - // to the snapshot index. - if err = s.r.storage.SaveSnap(snap); err != nil { - plog.Fatalf("save snapshot error: %v", err) - } - plog.Infof("saved snapshot at index %d", snap.Metadata.Index) - - // When sending a snapshot, etcd will pause compaction. - // After receives a snapshot, the slow follower needs to get all the entries right after - // the snapshot sent to catch up. If we do not pause compaction, the log entries right after - // the snapshot sent might already be compacted. It happens when the snapshot takes long time - // to send and save. Pausing compaction avoids triggering a snapshot sending cycle. - if atomic.LoadInt64(&s.inflightSnapshots) != 0 { - plog.Infof("skip compaction since there is an inflight snapshot") - return - } - - // keep some in memory log entries for slow followers. - compacti := uint64(1) - if snapi > numberOfCatchUpEntries { - compacti = snapi - numberOfCatchUpEntries - } - err = s.r.raftStorage.Compact(compacti) - if err != nil { - // the compaction was done asynchronously with the progress of raft. - // raft log might already been compact. - if err == raft.ErrCompacted { - return - } - plog.Panicf("unexpected compaction error %v", err) - } - plog.Infof("compacted raft log at %d", compacti) - }) -} - -// CutPeer drops messages to the specified peer. -func (s *EtcdServer) CutPeer(id types.ID) { - tr, ok := s.r.transport.(*rafthttp.Transport) - if ok { - tr.CutPeer(id) - } -} - -// MendPeer recovers the message dropping behavior of the given peer. -func (s *EtcdServer) MendPeer(id types.ID) { - tr, ok := s.r.transport.(*rafthttp.Transport) - if ok { - tr.MendPeer(id) - } -} - -func (s *EtcdServer) PauseSending() { s.r.pauseSending() } - -func (s *EtcdServer) ResumeSending() { s.r.resumeSending() } - -func (s *EtcdServer) ClusterVersion() *semver.Version { - if s.cluster == nil { - return nil - } - return s.cluster.Version() -} - -// monitorVersions checks the member's version every monitorVersionInterval. -// It updates the cluster version if all members agrees on a higher one. -// It prints out log if there is a member with a higher version than the -// local version. -func (s *EtcdServer) monitorVersions() { - for { - select { - case <-s.forceVersionC: - case <-time.After(monitorVersionInterval): - case <-s.stopping: - return - } - - if s.Leader() != s.ID() { - continue - } - - v := decideClusterVersion(getVersions(s.cluster, s.id, s.peerRt)) - if v != nil { - // only keep major.minor version for comparison - v = &semver.Version{ - Major: v.Major, - Minor: v.Minor, - } - } - - // if the current version is nil: - // 1. use the decided version if possible - // 2. or use the min cluster version - if s.cluster.Version() == nil { - verStr := version.MinClusterVersion - if v != nil { - verStr = v.String() - } - s.goAttach(func() { s.updateClusterVersion(verStr) }) - continue - } - - // update cluster version only if the decided version is greater than - // the current cluster version - if v != nil && s.cluster.Version().LessThan(*v) { - s.goAttach(func() { s.updateClusterVersion(v.String()) }) - } - } -} - -func (s *EtcdServer) updateClusterVersion(ver string) { - if s.cluster.Version() == nil { - plog.Infof("setting up the initial cluster version to %s", version.Cluster(ver)) - } else { - plog.Infof("updating the cluster version from %s to %s", version.Cluster(s.cluster.Version().String()), version.Cluster(ver)) - } - req := pb.Request{ - Method: "PUT", - Path: membership.StoreClusterVersionKey(), - Val: ver, - } - ctx, cancel := context.WithTimeout(s.ctx, s.Cfg.ReqTimeout()) - _, err := s.Do(ctx, req) - cancel() - switch err { - case nil: - return - case ErrStopped: - plog.Infof("aborting update cluster version because server is stopped") - return - default: - plog.Errorf("error updating cluster version (%v)", err) - } -} - -func (s *EtcdServer) parseProposeCtxErr(err error, start time.Time) error { - switch err { - case context.Canceled: - return ErrCanceled - case context.DeadlineExceeded: - s.leadTimeMu.RLock() - curLeadElected := s.leadElectedTime - s.leadTimeMu.RUnlock() - prevLeadLost := curLeadElected.Add(-2 * time.Duration(s.Cfg.ElectionTicks) * time.Duration(s.Cfg.TickMs) * time.Millisecond) - if start.After(prevLeadLost) && start.Before(curLeadElected) { - return ErrTimeoutDueToLeaderFail - } - - lead := types.ID(atomic.LoadUint64(&s.r.lead)) - switch lead { - case types.ID(raft.None): - // TODO: return error to specify it happens because the cluster does not have leader now - case s.ID(): - if !isConnectedToQuorumSince(s.r.transport, start, s.ID(), s.cluster.Members()) { - return ErrTimeoutDueToConnectionLost - } - default: - if !isConnectedSince(s.r.transport, start, lead) { - return ErrTimeoutDueToConnectionLost - } - } - - return ErrTimeout - default: - return err - } -} - -func (s *EtcdServer) KV() mvcc.ConsistentWatchableKV { return s.kv } -func (s *EtcdServer) Backend() backend.Backend { - s.bemu.Lock() - defer s.bemu.Unlock() - return s.be -} - -func (s *EtcdServer) AuthStore() auth.AuthStore { return s.authStore } - -func (s *EtcdServer) restoreAlarms() error { - s.applyV3 = s.newApplierV3() - as, err := alarm.NewAlarmStore(s) - if err != nil { - return err - } - s.alarmStore = as - if len(as.Get(pb.AlarmType_NOSPACE)) > 0 { - s.applyV3 = newApplierV3Capped(s.applyV3) - } - if len(as.Get(pb.AlarmType_CORRUPT)) > 0 { - s.applyV3 = newApplierV3Corrupt(s.applyV3) - } - return nil -} - -func (s *EtcdServer) getAppliedIndex() uint64 { - return atomic.LoadUint64(&s.appliedIndex) -} - -func (s *EtcdServer) setAppliedIndex(v uint64) { - atomic.StoreUint64(&s.appliedIndex, v) -} - -func (s *EtcdServer) getCommittedIndex() uint64 { - return atomic.LoadUint64(&s.committedIndex) -} - -func (s *EtcdServer) setCommittedIndex(v uint64) { - atomic.StoreUint64(&s.committedIndex, v) -} - -// goAttach creates a goroutine on a given function and tracks it using -// the etcdserver waitgroup. -func (s *EtcdServer) goAttach(f func()) { - s.wgMu.RLock() // this blocks with ongoing close(s.stopping) - defer s.wgMu.RUnlock() - select { - case <-s.stopping: - plog.Warning("server has stopped (skipping goAttach)") - return - default: - } - - // now safe to add since waitgroup wait has not started yet - s.wg.Add(1) - go func() { - defer s.wg.Done() - f() - }() -} - -func (s *EtcdServer) Alarms() []*pb.AlarmMember { - return s.alarmStore.Get(pb.AlarmType_NONE) -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/snapshot_merge.go b/vendor/github.com/coreos/etcd/etcdserver/snapshot_merge.go deleted file mode 100644 index 928aa95b6b16..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/snapshot_merge.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "io" - - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/snap" -) - -// createMergedSnapshotMessage creates a snapshot message that contains: raft status (term, conf), -// a snapshot of v2 store inside raft.Snapshot as []byte, a snapshot of v3 KV in the top level message -// as ReadCloser. -func (s *EtcdServer) createMergedSnapshotMessage(m raftpb.Message, snapt, snapi uint64, confState raftpb.ConfState) snap.Message { - // get a snapshot of v2 store as []byte - clone := s.store.Clone() - d, err := clone.SaveNoCopy() - if err != nil { - plog.Panicf("store save should never fail: %v", err) - } - - // commit kv to write metadata(for example: consistent index). - s.KV().Commit() - dbsnap := s.be.Snapshot() - // get a snapshot of v3 KV as readCloser - rc := newSnapshotReaderCloser(dbsnap) - - // put the []byte snapshot of store into raft snapshot and return the merged snapshot with - // KV readCloser snapshot. - snapshot := raftpb.Snapshot{ - Metadata: raftpb.SnapshotMetadata{ - Index: snapi, - Term: snapt, - ConfState: confState, - }, - Data: d, - } - m.Snapshot = snapshot - - return *snap.NewMessage(m, rc, dbsnap.Size()) -} - -func newSnapshotReaderCloser(snapshot backend.Snapshot) io.ReadCloser { - pr, pw := io.Pipe() - go func() { - n, err := snapshot.WriteTo(pw) - if err == nil { - plog.Infof("wrote database snapshot out [total bytes: %d]", n) - } else { - plog.Warningf("failed to write database snapshot out [written bytes: %d]: %v", n, err) - } - pw.CloseWithError(err) - err = snapshot.Close() - if err != nil { - plog.Panicf("failed to close database snapshot: %v", err) - } - }() - return pr -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/stats/leader.go b/vendor/github.com/coreos/etcd/etcdserver/stats/leader.go deleted file mode 100644 index 8f6a54ff751a..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/stats/leader.go +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package stats - -import ( - "encoding/json" - "math" - "sync" - "time" -) - -// LeaderStats is used by the leader in an etcd cluster, and encapsulates -// statistics about communication with its followers -type LeaderStats struct { - leaderStats - sync.Mutex -} - -type leaderStats struct { - // Leader is the ID of the leader in the etcd cluster. - // TODO(jonboulle): clarify that these are IDs, not names - Leader string `json:"leader"` - Followers map[string]*FollowerStats `json:"followers"` -} - -// NewLeaderStats generates a new LeaderStats with the given id as leader -func NewLeaderStats(id string) *LeaderStats { - return &LeaderStats{ - leaderStats: leaderStats{ - Leader: id, - Followers: make(map[string]*FollowerStats), - }, - } -} - -func (ls *LeaderStats) JSON() []byte { - ls.Lock() - stats := ls.leaderStats - ls.Unlock() - b, err := json.Marshal(stats) - // TODO(jonboulle): appropriate error handling? - if err != nil { - plog.Errorf("error marshalling leader stats (%v)", err) - } - return b -} - -func (ls *LeaderStats) Follower(name string) *FollowerStats { - ls.Lock() - defer ls.Unlock() - fs, ok := ls.Followers[name] - if !ok { - fs = &FollowerStats{} - fs.Latency.Minimum = 1 << 63 - ls.Followers[name] = fs - } - return fs -} - -// FollowerStats encapsulates various statistics about a follower in an etcd cluster -type FollowerStats struct { - Latency LatencyStats `json:"latency"` - Counts CountsStats `json:"counts"` - - sync.Mutex -} - -// LatencyStats encapsulates latency statistics. -type LatencyStats struct { - Current float64 `json:"current"` - Average float64 `json:"average"` - averageSquare float64 - StandardDeviation float64 `json:"standardDeviation"` - Minimum float64 `json:"minimum"` - Maximum float64 `json:"maximum"` -} - -// CountsStats encapsulates raft statistics. -type CountsStats struct { - Fail uint64 `json:"fail"` - Success uint64 `json:"success"` -} - -// Succ updates the FollowerStats with a successful send -func (fs *FollowerStats) Succ(d time.Duration) { - fs.Lock() - defer fs.Unlock() - - total := float64(fs.Counts.Success) * fs.Latency.Average - totalSquare := float64(fs.Counts.Success) * fs.Latency.averageSquare - - fs.Counts.Success++ - - fs.Latency.Current = float64(d) / (1000000.0) - - if fs.Latency.Current > fs.Latency.Maximum { - fs.Latency.Maximum = fs.Latency.Current - } - - if fs.Latency.Current < fs.Latency.Minimum { - fs.Latency.Minimum = fs.Latency.Current - } - - fs.Latency.Average = (total + fs.Latency.Current) / float64(fs.Counts.Success) - fs.Latency.averageSquare = (totalSquare + fs.Latency.Current*fs.Latency.Current) / float64(fs.Counts.Success) - - // sdv = sqrt(avg(x^2) - avg(x)^2) - fs.Latency.StandardDeviation = math.Sqrt(fs.Latency.averageSquare - fs.Latency.Average*fs.Latency.Average) -} - -// Fail updates the FollowerStats with an unsuccessful send -func (fs *FollowerStats) Fail() { - fs.Lock() - defer fs.Unlock() - fs.Counts.Fail++ -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/stats/queue.go b/vendor/github.com/coreos/etcd/etcdserver/stats/queue.go deleted file mode 100644 index 635074c48983..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/stats/queue.go +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package stats - -import ( - "sync" - "time" -) - -const ( - queueCapacity = 200 -) - -// RequestStats represent the stats for a request. -// It encapsulates the sending time and the size of the request. -type RequestStats struct { - SendingTime time.Time - Size int -} - -type statsQueue struct { - items [queueCapacity]*RequestStats - size int - front int - back int - totalReqSize int - rwl sync.RWMutex -} - -func (q *statsQueue) Len() int { - return q.size -} - -func (q *statsQueue) ReqSize() int { - return q.totalReqSize -} - -// FrontAndBack gets the front and back elements in the queue -// We must grab front and back together with the protection of the lock -func (q *statsQueue) frontAndBack() (*RequestStats, *RequestStats) { - q.rwl.RLock() - defer q.rwl.RUnlock() - if q.size != 0 { - return q.items[q.front], q.items[q.back] - } - return nil, nil -} - -// Insert function insert a RequestStats into the queue and update the records -func (q *statsQueue) Insert(p *RequestStats) { - q.rwl.Lock() - defer q.rwl.Unlock() - - q.back = (q.back + 1) % queueCapacity - - if q.size == queueCapacity { //dequeue - q.totalReqSize -= q.items[q.front].Size - q.front = (q.back + 1) % queueCapacity - } else { - q.size++ - } - - q.items[q.back] = p - q.totalReqSize += q.items[q.back].Size - -} - -// Rate function returns the package rate and byte rate -func (q *statsQueue) Rate() (float64, float64) { - front, back := q.frontAndBack() - - if front == nil || back == nil { - return 0, 0 - } - - if time.Since(back.SendingTime) > time.Second { - q.Clear() - return 0, 0 - } - - sampleDuration := back.SendingTime.Sub(front.SendingTime) - - pr := float64(q.Len()) / float64(sampleDuration) * float64(time.Second) - - br := float64(q.ReqSize()) / float64(sampleDuration) * float64(time.Second) - - return pr, br -} - -// Clear function clear up the statsQueue -func (q *statsQueue) Clear() { - q.rwl.Lock() - defer q.rwl.Unlock() - q.back = -1 - q.front = 0 - q.size = 0 - q.totalReqSize = 0 -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/stats/server.go b/vendor/github.com/coreos/etcd/etcdserver/stats/server.go deleted file mode 100644 index b026e4480f65..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/stats/server.go +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package stats - -import ( - "encoding/json" - "log" - "sync" - "time" - - "github.com/coreos/etcd/raft" -) - -// ServerStats encapsulates various statistics about an EtcdServer and its -// communication with other members of the cluster -type ServerStats struct { - serverStats - sync.Mutex -} - -func NewServerStats(name, id string) *ServerStats { - ss := &ServerStats{ - serverStats: serverStats{ - Name: name, - ID: id, - }, - } - now := time.Now() - ss.StartTime = now - ss.LeaderInfo.StartTime = now - ss.sendRateQueue = &statsQueue{back: -1} - ss.recvRateQueue = &statsQueue{back: -1} - return ss -} - -type serverStats struct { - Name string `json:"name"` - // ID is the raft ID of the node. - // TODO(jonboulle): use ID instead of name? - ID string `json:"id"` - State raft.StateType `json:"state"` - StartTime time.Time `json:"startTime"` - - LeaderInfo struct { - Name string `json:"leader"` - Uptime string `json:"uptime"` - StartTime time.Time `json:"startTime"` - } `json:"leaderInfo"` - - RecvAppendRequestCnt uint64 `json:"recvAppendRequestCnt,"` - RecvingPkgRate float64 `json:"recvPkgRate,omitempty"` - RecvingBandwidthRate float64 `json:"recvBandwidthRate,omitempty"` - - SendAppendRequestCnt uint64 `json:"sendAppendRequestCnt"` - SendingPkgRate float64 `json:"sendPkgRate,omitempty"` - SendingBandwidthRate float64 `json:"sendBandwidthRate,omitempty"` - - sendRateQueue *statsQueue - recvRateQueue *statsQueue -} - -func (ss *ServerStats) JSON() []byte { - ss.Lock() - stats := ss.serverStats - stats.SendingPkgRate, stats.SendingBandwidthRate = stats.sendRateQueue.Rate() - stats.RecvingPkgRate, stats.RecvingBandwidthRate = stats.recvRateQueue.Rate() - stats.LeaderInfo.Uptime = time.Since(stats.LeaderInfo.StartTime).String() - ss.Unlock() - b, err := json.Marshal(stats) - // TODO(jonboulle): appropriate error handling? - if err != nil { - log.Printf("stats: error marshalling server stats: %v", err) - } - return b -} - -// RecvAppendReq updates the ServerStats in response to an AppendRequest -// from the given leader being received -func (ss *ServerStats) RecvAppendReq(leader string, reqSize int) { - ss.Lock() - defer ss.Unlock() - - now := time.Now() - - ss.State = raft.StateFollower - if leader != ss.LeaderInfo.Name { - ss.LeaderInfo.Name = leader - ss.LeaderInfo.StartTime = now - } - - ss.recvRateQueue.Insert( - &RequestStats{ - SendingTime: now, - Size: reqSize, - }, - ) - ss.RecvAppendRequestCnt++ -} - -// SendAppendReq updates the ServerStats in response to an AppendRequest -// being sent by this server -func (ss *ServerStats) SendAppendReq(reqSize int) { - ss.Lock() - defer ss.Unlock() - - ss.becomeLeader() - - ss.sendRateQueue.Insert( - &RequestStats{ - SendingTime: time.Now(), - Size: reqSize, - }, - ) - - ss.SendAppendRequestCnt++ -} - -func (ss *ServerStats) BecomeLeader() { - ss.Lock() - defer ss.Unlock() - ss.becomeLeader() -} - -func (ss *ServerStats) becomeLeader() { - if ss.State != raft.StateLeader { - ss.State = raft.StateLeader - ss.LeaderInfo.Name = ss.ID - ss.LeaderInfo.StartTime = time.Now() - } -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/stats/stats.go b/vendor/github.com/coreos/etcd/etcdserver/stats/stats.go deleted file mode 100644 index 2b5f7071aa76..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/stats/stats.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package stats defines a standard interface for etcd cluster statistics. -package stats - -import "github.com/coreos/pkg/capnslog" - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdserver/stats") -) - -type Stats interface { - // SelfStats returns the struct representing statistics of this server - SelfStats() []byte - // LeaderStats returns the statistics of all followers in the cluster - // if this server is leader. Otherwise, nil is returned. - LeaderStats() []byte - // StoreStats returns statistics of the store backing this EtcdServer - StoreStats() []byte -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/storage.go b/vendor/github.com/coreos/etcd/etcdserver/storage.go deleted file mode 100644 index 55c2dd4b6a41..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/storage.go +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "io" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/snap" - "github.com/coreos/etcd/wal" - "github.com/coreos/etcd/wal/walpb" -) - -type Storage interface { - // Save function saves ents and state to the underlying stable storage. - // Save MUST block until st and ents are on stable storage. - Save(st raftpb.HardState, ents []raftpb.Entry) error - // SaveSnap function saves snapshot to the underlying stable storage. - SaveSnap(snap raftpb.Snapshot) error - // Close closes the Storage and performs finalization. - Close() error -} - -type storage struct { - *wal.WAL - *snap.Snapshotter -} - -func NewStorage(w *wal.WAL, s *snap.Snapshotter) Storage { - return &storage{w, s} -} - -// SaveSnap saves the snapshot to disk and release the locked -// wal files since they will not be used. -func (st *storage) SaveSnap(snap raftpb.Snapshot) error { - walsnap := walpb.Snapshot{ - Index: snap.Metadata.Index, - Term: snap.Metadata.Term, - } - err := st.WAL.SaveSnapshot(walsnap) - if err != nil { - return err - } - err = st.Snapshotter.SaveSnap(snap) - if err != nil { - return err - } - return st.WAL.ReleaseLockTo(snap.Metadata.Index) -} - -func readWAL(waldir string, snap walpb.Snapshot) (w *wal.WAL, id, cid types.ID, st raftpb.HardState, ents []raftpb.Entry) { - var ( - err error - wmetadata []byte - ) - - repaired := false - for { - if w, err = wal.Open(waldir, snap); err != nil { - plog.Fatalf("open wal error: %v", err) - } - if wmetadata, st, ents, err = w.ReadAll(); err != nil { - w.Close() - // we can only repair ErrUnexpectedEOF and we never repair twice. - if repaired || err != io.ErrUnexpectedEOF { - plog.Fatalf("read wal error (%v) and cannot be repaired", err) - } - if !wal.Repair(waldir) { - plog.Fatalf("WAL error (%v) cannot be repaired", err) - } else { - plog.Infof("repaired WAL error (%v)", err) - repaired = true - } - continue - } - break - } - var metadata pb.Metadata - pbutil.MustUnmarshal(&metadata, wmetadata) - id = types.ID(metadata.NodeID) - cid = types.ID(metadata.ClusterID) - return w, id, cid, st, ents -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/util.go b/vendor/github.com/coreos/etcd/etcdserver/util.go deleted file mode 100644 index 79bb6b859ca8..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/util.go +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "fmt" - "reflect" - "strings" - "time" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/rafthttp" - "github.com/golang/protobuf/proto" -) - -// isConnectedToQuorumSince checks whether the local member is connected to the -// quorum of the cluster since the given time. -func isConnectedToQuorumSince(transport rafthttp.Transporter, since time.Time, self types.ID, members []*membership.Member) bool { - return numConnectedSince(transport, since, self, members) >= (len(members)/2)+1 -} - -// isConnectedSince checks whether the local member is connected to the -// remote member since the given time. -func isConnectedSince(transport rafthttp.Transporter, since time.Time, remote types.ID) bool { - t := transport.ActiveSince(remote) - return !t.IsZero() && t.Before(since) -} - -// isConnectedFullySince checks whether the local member is connected to all -// members in the cluster since the given time. -func isConnectedFullySince(transport rafthttp.Transporter, since time.Time, self types.ID, members []*membership.Member) bool { - return numConnectedSince(transport, since, self, members) == len(members) -} - -// numConnectedSince counts how many members are connected to the local member -// since the given time. -func numConnectedSince(transport rafthttp.Transporter, since time.Time, self types.ID, members []*membership.Member) int { - connectedNum := 0 - for _, m := range members { - if m.ID == self || isConnectedSince(transport, since, m.ID) { - connectedNum++ - } - } - return connectedNum -} - -// longestConnected chooses the member with longest active-since-time. -// It returns false, if nothing is active. -func longestConnected(tp rafthttp.Transporter, membs []types.ID) (types.ID, bool) { - var longest types.ID - var oldest time.Time - for _, id := range membs { - tm := tp.ActiveSince(id) - if tm.IsZero() { // inactive - continue - } - - if oldest.IsZero() { // first longest candidate - oldest = tm - longest = id - } - - if tm.Before(oldest) { - oldest = tm - longest = id - } - } - if uint64(longest) == 0 { - return longest, false - } - return longest, true -} - -type notifier struct { - c chan struct{} - err error -} - -func newNotifier() *notifier { - return ¬ifier{ - c: make(chan struct{}), - } -} - -func (nc *notifier) notify(err error) { - nc.err = err - close(nc.c) -} - -func warnOfExpensiveRequest(now time.Time, reqStringer fmt.Stringer, respMsg proto.Message, err error) { - var resp string - if !isNil(respMsg) { - resp = fmt.Sprintf("size:%d", proto.Size(respMsg)) - } - warnOfExpensiveGenericRequest(now, reqStringer, "", resp, err) -} - -func warnOfExpensiveReadOnlyTxnRequest(now time.Time, r *pb.TxnRequest, txnResponse *pb.TxnResponse, err error) { - reqStringer := pb.NewLoggableTxnRequest(r) - var resp string - if !isNil(txnResponse) { - var resps []string - for _, r := range txnResponse.Responses { - switch op := r.Response.(type) { - case *pb.ResponseOp_ResponseRange: - resps = append(resps, fmt.Sprintf("range_response_count:%d", len(op.ResponseRange.Kvs))) - default: - // only range responses should be in a read only txn request - } - } - resp = fmt.Sprintf("responses:<%s> size:%d", strings.Join(resps, " "), proto.Size(txnResponse)) - } - warnOfExpensiveGenericRequest(now, reqStringer, "read-only range ", resp, err) -} - -func warnOfExpensiveReadOnlyRangeRequest(now time.Time, reqStringer fmt.Stringer, rangeResponse *pb.RangeResponse, err error) { - var resp string - if !isNil(rangeResponse) { - resp = fmt.Sprintf("range_response_count:%d size:%d", len(rangeResponse.Kvs), proto.Size(rangeResponse)) - } - warnOfExpensiveGenericRequest(now, reqStringer, "read-only range ", resp, err) -} - -func warnOfExpensiveGenericRequest(now time.Time, reqStringer fmt.Stringer, prefix string, resp string, err error) { - // TODO: add metrics - d := time.Since(now) - if d > warnApplyDuration { - var result string - if err != nil { - result = fmt.Sprintf("error:%v", err) - } else { - result = resp - } - plog.Warningf("%srequest %q with result %q took too long (%v) to execute", prefix, reqStringer.String(), result, d) - slowApplies.Inc() - } -} - -func isNil(msg proto.Message) bool { - return msg == nil || reflect.ValueOf(msg).IsNil() -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/v2_server.go b/vendor/github.com/coreos/etcd/etcdserver/v2_server.go deleted file mode 100644 index b458350c10bf..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/v2_server.go +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "context" - "time" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/store" -) - -type RequestV2 pb.Request - -type RequestV2Handler interface { - Post(ctx context.Context, r *RequestV2) (Response, error) - Put(ctx context.Context, r *RequestV2) (Response, error) - Delete(ctx context.Context, r *RequestV2) (Response, error) - QGet(ctx context.Context, r *RequestV2) (Response, error) - Get(ctx context.Context, r *RequestV2) (Response, error) - Head(ctx context.Context, r *RequestV2) (Response, error) -} - -type reqV2HandlerEtcdServer struct { - reqV2HandlerStore - s *EtcdServer -} - -type reqV2HandlerStore struct { - store store.Store - applier ApplierV2 -} - -func NewStoreRequestV2Handler(s store.Store, applier ApplierV2) RequestV2Handler { - return &reqV2HandlerStore{s, applier} -} - -func (a *reqV2HandlerStore) Post(ctx context.Context, r *RequestV2) (Response, error) { - return a.applier.Post(r), nil -} - -func (a *reqV2HandlerStore) Put(ctx context.Context, r *RequestV2) (Response, error) { - return a.applier.Put(r), nil -} - -func (a *reqV2HandlerStore) Delete(ctx context.Context, r *RequestV2) (Response, error) { - return a.applier.Delete(r), nil -} - -func (a *reqV2HandlerStore) QGet(ctx context.Context, r *RequestV2) (Response, error) { - return a.applier.QGet(r), nil -} - -func (a *reqV2HandlerStore) Get(ctx context.Context, r *RequestV2) (Response, error) { - if r.Wait { - wc, err := a.store.Watch(r.Path, r.Recursive, r.Stream, r.Since) - return Response{Watcher: wc}, err - } - ev, err := a.store.Get(r.Path, r.Recursive, r.Sorted) - return Response{Event: ev}, err -} - -func (a *reqV2HandlerStore) Head(ctx context.Context, r *RequestV2) (Response, error) { - ev, err := a.store.Get(r.Path, r.Recursive, r.Sorted) - return Response{Event: ev}, err -} - -func (a *reqV2HandlerEtcdServer) Post(ctx context.Context, r *RequestV2) (Response, error) { - return a.processRaftRequest(ctx, r) -} - -func (a *reqV2HandlerEtcdServer) Put(ctx context.Context, r *RequestV2) (Response, error) { - return a.processRaftRequest(ctx, r) -} - -func (a *reqV2HandlerEtcdServer) Delete(ctx context.Context, r *RequestV2) (Response, error) { - return a.processRaftRequest(ctx, r) -} - -func (a *reqV2HandlerEtcdServer) QGet(ctx context.Context, r *RequestV2) (Response, error) { - return a.processRaftRequest(ctx, r) -} - -func (a *reqV2HandlerEtcdServer) processRaftRequest(ctx context.Context, r *RequestV2) (Response, error) { - data, err := ((*pb.Request)(r)).Marshal() - if err != nil { - return Response{}, err - } - ch := a.s.w.Register(r.ID) - - start := time.Now() - a.s.r.Propose(ctx, data) - proposalsPending.Inc() - defer proposalsPending.Dec() - - select { - case x := <-ch: - resp := x.(Response) - return resp, resp.Err - case <-ctx.Done(): - proposalsFailed.Inc() - a.s.w.Trigger(r.ID, nil) // GC wait - return Response{}, a.s.parseProposeCtxErr(ctx.Err(), start) - case <-a.s.stopping: - } - return Response{}, ErrStopped -} - -func (s *EtcdServer) Do(ctx context.Context, r pb.Request) (Response, error) { - r.ID = s.reqIDGen.Next() - h := &reqV2HandlerEtcdServer{ - reqV2HandlerStore: reqV2HandlerStore{ - store: s.store, - applier: s.applyV2, - }, - s: s, - } - rp := &r - resp, err := ((*RequestV2)(rp)).Handle(ctx, h) - resp.Term, resp.Index = s.Term(), s.Index() - return resp, err -} - -// Handle interprets r and performs an operation on s.store according to r.Method -// and other fields. If r.Method is "POST", "PUT", "DELETE", or a "GET" with -// Quorum == true, r will be sent through consensus before performing its -// respective operation. Do will block until an action is performed or there is -// an error. -func (r *RequestV2) Handle(ctx context.Context, v2api RequestV2Handler) (Response, error) { - if r.Method == "GET" && r.Quorum { - r.Method = "QGET" - } - switch r.Method { - case "POST": - return v2api.Post(ctx, r) - case "PUT": - return v2api.Put(ctx, r) - case "DELETE": - return v2api.Delete(ctx, r) - case "QGET": - return v2api.QGet(ctx, r) - case "GET": - return v2api.Get(ctx, r) - case "HEAD": - return v2api.Head(ctx, r) - } - return Response{}, ErrUnknownMethod -} - -func (r *RequestV2) String() string { - rpb := pb.Request(*r) - return rpb.String() -} diff --git a/vendor/github.com/coreos/etcd/etcdserver/v3_server.go b/vendor/github.com/coreos/etcd/etcdserver/v3_server.go deleted file mode 100644 index f214a1926bb9..000000000000 --- a/vendor/github.com/coreos/etcd/etcdserver/v3_server.go +++ /dev/null @@ -1,720 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "bytes" - "context" - "encoding/binary" - "time" - - "github.com/coreos/etcd/auth" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/lease/leasehttp" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/raft" - - "github.com/gogo/protobuf/proto" -) - -const ( - // In the health case, there might be a small gap (10s of entries) between - // the applied index and committed index. - // However, if the committed entries are very heavy to apply, the gap might grow. - // We should stop accepting new proposals if the gap growing to a certain point. - maxGapBetweenApplyAndCommitIndex = 5000 -) - -type RaftKV interface { - Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, error) - Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error) - DeleteRange(ctx context.Context, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) - Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error) - Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error) -} - -type Lessor interface { - // LeaseGrant sends LeaseGrant request to raft and apply it after committed. - LeaseGrant(ctx context.Context, r *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) - // LeaseRevoke sends LeaseRevoke request to raft and apply it after committed. - LeaseRevoke(ctx context.Context, r *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) - - // LeaseRenew renews the lease with given ID. The renewed TTL is returned. Or an error - // is returned. - LeaseRenew(ctx context.Context, id lease.LeaseID) (int64, error) - - // LeaseTimeToLive retrieves lease information. - LeaseTimeToLive(ctx context.Context, r *pb.LeaseTimeToLiveRequest) (*pb.LeaseTimeToLiveResponse, error) - - // LeaseLeases lists all leases. - LeaseLeases(ctx context.Context, r *pb.LeaseLeasesRequest) (*pb.LeaseLeasesResponse, error) -} - -type Authenticator interface { - AuthEnable(ctx context.Context, r *pb.AuthEnableRequest) (*pb.AuthEnableResponse, error) - AuthDisable(ctx context.Context, r *pb.AuthDisableRequest) (*pb.AuthDisableResponse, error) - Authenticate(ctx context.Context, r *pb.AuthenticateRequest) (*pb.AuthenticateResponse, error) - UserAdd(ctx context.Context, r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) - UserDelete(ctx context.Context, r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) - UserChangePassword(ctx context.Context, r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) - UserGrantRole(ctx context.Context, r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) - UserGet(ctx context.Context, r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) - UserRevokeRole(ctx context.Context, r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) - RoleAdd(ctx context.Context, r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) - RoleGrantPermission(ctx context.Context, r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) - RoleGet(ctx context.Context, r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) - RoleRevokePermission(ctx context.Context, r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) - RoleDelete(ctx context.Context, r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) - UserList(ctx context.Context, r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) - RoleList(ctx context.Context, r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) -} - -func (s *EtcdServer) Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, error) { - var resp *pb.RangeResponse - var err error - defer func(start time.Time) { - warnOfExpensiveReadOnlyRangeRequest(start, r, resp, err) - }(time.Now()) - - if !r.Serializable { - err = s.linearizableReadNotify(ctx) - if err != nil { - return nil, err - } - } - chk := func(ai *auth.AuthInfo) error { - return s.authStore.IsRangePermitted(ai, r.Key, r.RangeEnd) - } - - get := func() { resp, err = s.applyV3Base.Range(nil, r) } - if serr := s.doSerialize(ctx, chk, get); serr != nil { - err = serr - return nil, err - } - return resp, err -} - -func (s *EtcdServer) Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{Put: r}) - if err != nil { - return nil, err - } - return resp.(*pb.PutResponse), nil -} - -func (s *EtcdServer) DeleteRange(ctx context.Context, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{DeleteRange: r}) - if err != nil { - return nil, err - } - return resp.(*pb.DeleteRangeResponse), nil -} - -func (s *EtcdServer) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error) { - if isTxnReadonly(r) { - if !isTxnSerializable(r) { - err := s.linearizableReadNotify(ctx) - if err != nil { - return nil, err - } - } - var resp *pb.TxnResponse - var err error - chk := func(ai *auth.AuthInfo) error { - return checkTxnAuth(s.authStore, ai, r) - } - - defer func(start time.Time) { - warnOfExpensiveReadOnlyTxnRequest(start, r, resp, err) - }(time.Now()) - - get := func() { resp, err = s.applyV3Base.Txn(r) } - if serr := s.doSerialize(ctx, chk, get); serr != nil { - return nil, serr - } - return resp, err - } - - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{Txn: r}) - if err != nil { - return nil, err - } - return resp.(*pb.TxnResponse), nil -} - -func isTxnSerializable(r *pb.TxnRequest) bool { - for _, u := range r.Success { - if r := u.GetRequestRange(); r == nil || !r.Serializable { - return false - } - } - for _, u := range r.Failure { - if r := u.GetRequestRange(); r == nil || !r.Serializable { - return false - } - } - return true -} - -func isTxnReadonly(r *pb.TxnRequest) bool { - for _, u := range r.Success { - if r := u.GetRequestRange(); r == nil { - return false - } - } - for _, u := range r.Failure { - if r := u.GetRequestRange(); r == nil { - return false - } - } - return true -} - -func (s *EtcdServer) Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error) { - result, err := s.processInternalRaftRequestOnce(ctx, pb.InternalRaftRequest{Compaction: r}) - if r.Physical && result != nil && result.physc != nil { - <-result.physc - // The compaction is done deleting keys; the hash is now settled - // but the data is not necessarily committed. If there's a crash, - // the hash may revert to a hash prior to compaction completing - // if the compaction resumes. Force the finished compaction to - // commit so it won't resume following a crash. - s.be.ForceCommit() - } - if err != nil { - return nil, err - } - if result.err != nil { - return nil, result.err - } - resp := result.resp.(*pb.CompactionResponse) - if resp == nil { - resp = &pb.CompactionResponse{} - } - if resp.Header == nil { - resp.Header = &pb.ResponseHeader{} - } - resp.Header.Revision = s.kv.Rev() - return resp, nil -} - -func (s *EtcdServer) LeaseGrant(ctx context.Context, r *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - // no id given? choose one - for r.ID == int64(lease.NoLease) { - // only use positive int64 id's - r.ID = int64(s.reqIDGen.Next() & ((1 << 63) - 1)) - } - resp, err := s.raftRequestOnce(ctx, pb.InternalRaftRequest{LeaseGrant: r}) - if err != nil { - return nil, err - } - return resp.(*pb.LeaseGrantResponse), nil -} - -func (s *EtcdServer) LeaseRevoke(ctx context.Context, r *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) { - resp, err := s.raftRequestOnce(ctx, pb.InternalRaftRequest{LeaseRevoke: r}) - if err != nil { - return nil, err - } - return resp.(*pb.LeaseRevokeResponse), nil -} - -func (s *EtcdServer) LeaseRenew(ctx context.Context, id lease.LeaseID) (int64, error) { - ttl, err := s.lessor.Renew(id) - if err == nil { // already requested to primary lessor(leader) - return ttl, nil - } - if err != lease.ErrNotPrimary { - return -1, err - } - - cctx, cancel := context.WithTimeout(ctx, s.Cfg.ReqTimeout()) - defer cancel() - - // renewals don't go through raft; forward to leader manually - for cctx.Err() == nil && err != nil { - leader, lerr := s.waitLeader(cctx) - if lerr != nil { - return -1, lerr - } - for _, url := range leader.PeerURLs { - lurl := url + leasehttp.LeasePrefix - ttl, err = leasehttp.RenewHTTP(cctx, id, lurl, s.peerRt) - if err == nil || err == lease.ErrLeaseNotFound { - return ttl, err - } - } - } - return -1, ErrTimeout -} - -func (s *EtcdServer) LeaseTimeToLive(ctx context.Context, r *pb.LeaseTimeToLiveRequest) (*pb.LeaseTimeToLiveResponse, error) { - if s.Leader() == s.ID() { - // primary; timetolive directly from leader - le := s.lessor.Lookup(lease.LeaseID(r.ID)) - if le == nil { - return nil, lease.ErrLeaseNotFound - } - // TODO: fill out ResponseHeader - resp := &pb.LeaseTimeToLiveResponse{Header: &pb.ResponseHeader{}, ID: r.ID, TTL: int64(le.Remaining().Seconds()), GrantedTTL: le.TTL()} - if r.Keys { - ks := le.Keys() - kbs := make([][]byte, len(ks)) - for i := range ks { - kbs[i] = []byte(ks[i]) - } - resp.Keys = kbs - } - return resp, nil - } - - cctx, cancel := context.WithTimeout(ctx, s.Cfg.ReqTimeout()) - defer cancel() - - // forward to leader - for cctx.Err() == nil { - leader, err := s.waitLeader(cctx) - if err != nil { - return nil, err - } - for _, url := range leader.PeerURLs { - lurl := url + leasehttp.LeaseInternalPrefix - resp, err := leasehttp.TimeToLiveHTTP(cctx, lease.LeaseID(r.ID), r.Keys, lurl, s.peerRt) - if err == nil { - return resp.LeaseTimeToLiveResponse, nil - } - if err == lease.ErrLeaseNotFound { - return nil, err - } - } - } - return nil, ErrTimeout -} - -func (s *EtcdServer) LeaseLeases(ctx context.Context, r *pb.LeaseLeasesRequest) (*pb.LeaseLeasesResponse, error) { - ls := s.lessor.Leases() - lss := make([]*pb.LeaseStatus, len(ls)) - for i := range ls { - lss[i] = &pb.LeaseStatus{ID: int64(ls[i].ID)} - } - return &pb.LeaseLeasesResponse{Header: newHeader(s), Leases: lss}, nil -} - -func (s *EtcdServer) waitLeader(ctx context.Context) (*membership.Member, error) { - leader := s.cluster.Member(s.Leader()) - for leader == nil { - // wait an election - dur := time.Duration(s.Cfg.ElectionTicks) * time.Duration(s.Cfg.TickMs) * time.Millisecond - select { - case <-time.After(dur): - leader = s.cluster.Member(s.Leader()) - case <-s.stopping: - return nil, ErrStopped - case <-ctx.Done(): - return nil, ErrNoLeader - } - } - if leader == nil || len(leader.PeerURLs) == 0 { - return nil, ErrNoLeader - } - return leader, nil -} - -func (s *EtcdServer) Alarm(ctx context.Context, r *pb.AlarmRequest) (*pb.AlarmResponse, error) { - resp, err := s.raftRequestOnce(ctx, pb.InternalRaftRequest{Alarm: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AlarmResponse), nil -} - -func (s *EtcdServer) AuthEnable(ctx context.Context, r *pb.AuthEnableRequest) (*pb.AuthEnableResponse, error) { - resp, err := s.raftRequestOnce(ctx, pb.InternalRaftRequest{AuthEnable: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthEnableResponse), nil -} - -func (s *EtcdServer) AuthDisable(ctx context.Context, r *pb.AuthDisableRequest) (*pb.AuthDisableResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthDisable: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthDisableResponse), nil -} - -func (s *EtcdServer) Authenticate(ctx context.Context, r *pb.AuthenticateRequest) (*pb.AuthenticateResponse, error) { - if err := s.linearizableReadNotify(ctx); err != nil { - return nil, err - } - - var resp proto.Message - for { - checkedRevision, err := s.AuthStore().CheckPassword(r.Name, r.Password) - if err != nil { - if err != auth.ErrAuthNotEnabled { - plog.Errorf("invalid authentication request to user %s was issued", r.Name) - } - return nil, err - } - - st, err := s.AuthStore().GenTokenPrefix() - if err != nil { - return nil, err - } - - internalReq := &pb.InternalAuthenticateRequest{ - Name: r.Name, - Password: r.Password, - SimpleToken: st, - } - - resp, err = s.raftRequestOnce(ctx, pb.InternalRaftRequest{Authenticate: internalReq}) - if err != nil { - return nil, err - } - if checkedRevision == s.AuthStore().Revision() { - break - } - plog.Infof("revision when password checked is obsolete, retrying") - } - - return resp.(*pb.AuthenticateResponse), nil -} - -func (s *EtcdServer) UserAdd(ctx context.Context, r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserAdd: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserAddResponse), nil -} - -func (s *EtcdServer) UserDelete(ctx context.Context, r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserDelete: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserDeleteResponse), nil -} - -func (s *EtcdServer) UserChangePassword(ctx context.Context, r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserChangePassword: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserChangePasswordResponse), nil -} - -func (s *EtcdServer) UserGrantRole(ctx context.Context, r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserGrantRole: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserGrantRoleResponse), nil -} - -func (s *EtcdServer) UserGet(ctx context.Context, r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserGet: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserGetResponse), nil -} - -func (s *EtcdServer) UserList(ctx context.Context, r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserList: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserListResponse), nil -} - -func (s *EtcdServer) UserRevokeRole(ctx context.Context, r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserRevokeRole: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserRevokeRoleResponse), nil -} - -func (s *EtcdServer) RoleAdd(ctx context.Context, r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthRoleAdd: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthRoleAddResponse), nil -} - -func (s *EtcdServer) RoleGrantPermission(ctx context.Context, r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthRoleGrantPermission: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthRoleGrantPermissionResponse), nil -} - -func (s *EtcdServer) RoleGet(ctx context.Context, r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthRoleGet: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthRoleGetResponse), nil -} - -func (s *EtcdServer) RoleList(ctx context.Context, r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthRoleList: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthRoleListResponse), nil -} - -func (s *EtcdServer) RoleRevokePermission(ctx context.Context, r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthRoleRevokePermission: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthRoleRevokePermissionResponse), nil -} - -func (s *EtcdServer) RoleDelete(ctx context.Context, r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthRoleDelete: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthRoleDeleteResponse), nil -} - -func (s *EtcdServer) raftRequestOnce(ctx context.Context, r pb.InternalRaftRequest) (proto.Message, error) { - result, err := s.processInternalRaftRequestOnce(ctx, r) - if err != nil { - return nil, err - } - if result.err != nil { - return nil, result.err - } - return result.resp, nil -} - -func (s *EtcdServer) raftRequest(ctx context.Context, r pb.InternalRaftRequest) (proto.Message, error) { - for { - resp, err := s.raftRequestOnce(ctx, r) - if err != auth.ErrAuthOldRevision { - return resp, err - } - } -} - -// doSerialize handles the auth logic, with permissions checked by "chk", for a serialized request "get". Returns a non-nil error on authentication failure. -func (s *EtcdServer) doSerialize(ctx context.Context, chk func(*auth.AuthInfo) error, get func()) error { - for { - ai, err := s.AuthInfoFromCtx(ctx) - if err != nil { - return err - } - if ai == nil { - // chk expects non-nil AuthInfo; use empty credentials - ai = &auth.AuthInfo{} - } - if err = chk(ai); err != nil { - if err == auth.ErrAuthOldRevision { - continue - } - return err - } - // fetch response for serialized request - get() - // empty credentials or current auth info means no need to retry - if ai.Revision == 0 || ai.Revision == s.authStore.Revision() { - return nil - } - // avoid TOCTOU error, retry of the request is required. - } -} - -func (s *EtcdServer) processInternalRaftRequestOnce(ctx context.Context, r pb.InternalRaftRequest) (*applyResult, error) { - ai := s.getAppliedIndex() - ci := s.getCommittedIndex() - if ci > ai+maxGapBetweenApplyAndCommitIndex { - return nil, ErrTooManyRequests - } - - r.Header = &pb.RequestHeader{ - ID: s.reqIDGen.Next(), - } - - authInfo, err := s.AuthInfoFromCtx(ctx) - if err != nil { - return nil, err - } - if authInfo != nil { - r.Header.Username = authInfo.Username - r.Header.AuthRevision = authInfo.Revision - } - - data, err := r.Marshal() - if err != nil { - return nil, err - } - - if len(data) > int(s.Cfg.MaxRequestBytes) { - return nil, ErrRequestTooLarge - } - - id := r.ID - if id == 0 { - id = r.Header.ID - } - ch := s.w.Register(id) - - cctx, cancel := context.WithTimeout(ctx, s.Cfg.ReqTimeout()) - defer cancel() - - start := time.Now() - s.r.Propose(cctx, data) - proposalsPending.Inc() - defer proposalsPending.Dec() - - select { - case x := <-ch: - return x.(*applyResult), nil - case <-cctx.Done(): - proposalsFailed.Inc() - s.w.Trigger(id, nil) // GC wait - return nil, s.parseProposeCtxErr(cctx.Err(), start) - case <-s.done: - return nil, ErrStopped - } -} - -// Watchable returns a watchable interface attached to the etcdserver. -func (s *EtcdServer) Watchable() mvcc.WatchableKV { return s.KV() } - -func (s *EtcdServer) linearizableReadLoop() { - var rs raft.ReadState - - for { - ctxToSend := make([]byte, 8) - id1 := s.reqIDGen.Next() - binary.BigEndian.PutUint64(ctxToSend, id1) - - select { - case <-s.readwaitc: - case <-s.stopping: - return - } - - nextnr := newNotifier() - - s.readMu.Lock() - nr := s.readNotifier - s.readNotifier = nextnr - s.readMu.Unlock() - - cctx, cancel := context.WithTimeout(context.Background(), s.Cfg.ReqTimeout()) - if err := s.r.ReadIndex(cctx, ctxToSend); err != nil { - cancel() - if err == raft.ErrStopped { - return - } - plog.Errorf("failed to get read index from raft: %v", err) - readIndexFailed.Inc() - nr.notify(err) - continue - } - cancel() - - var ( - timeout bool - done bool - ) - for !timeout && !done { - select { - case rs = <-s.r.readStateC: - done = bytes.Equal(rs.RequestCtx, ctxToSend) - if !done { - // a previous request might time out. now we should ignore the response of it and - // continue waiting for the response of the current requests. - id2 := uint64(0) - if len(rs.RequestCtx) == 8 { - id2 = binary.BigEndian.Uint64(rs.RequestCtx) - } - plog.Warningf("ignored out-of-date read index response; local node read indexes queueing up and waiting to be in sync with leader (request ID want %d, got %d)", id1, id2) - slowReadIndex.Inc() - } - - case <-time.After(s.Cfg.ReqTimeout()): - plog.Warningf("timed out waiting for read index response (local node might have slow network)") - nr.notify(ErrTimeout) - timeout = true - slowReadIndex.Inc() - - case <-s.stopping: - return - } - } - if !done { - continue - } - - if ai := s.getAppliedIndex(); ai < rs.Index { - select { - case <-s.applyWait.Wait(rs.Index): - case <-s.stopping: - return - } - } - // unblock all l-reads requested at indices before rs.Index - nr.notify(nil) - } -} - -func (s *EtcdServer) linearizableReadNotify(ctx context.Context) error { - s.readMu.RLock() - nc := s.readNotifier - s.readMu.RUnlock() - - // signal linearizable loop for current notify if it hasn't been already - select { - case s.readwaitc <- struct{}{}: - default: - } - - // wait for read state notification - select { - case <-nc.c: - return nc.err - case <-ctx.Done(): - return ctx.Err() - case <-s.done: - return ErrStopped - } -} - -func (s *EtcdServer) AuthInfoFromCtx(ctx context.Context) (*auth.AuthInfo, error) { - authInfo, err := s.AuthStore().AuthInfoFromCtx(ctx) - if authInfo != nil || err != nil { - return authInfo, err - } - if !s.Cfg.ClientCertAuthEnabled { - return nil, nil - } - authInfo = s.AuthStore().AuthInfoFromTLS(ctx) - return authInfo, nil -} diff --git a/vendor/github.com/coreos/etcd/functional/rpcpb/etcd_config.go b/vendor/github.com/coreos/etcd/functional/rpcpb/etcd_config.go deleted file mode 100644 index 9d3d8c2350c1..000000000000 --- a/vendor/github.com/coreos/etcd/functional/rpcpb/etcd_config.go +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rpcpb - -import ( - "fmt" - "reflect" - "strings" -) - -var etcdFields = []string{ - "Name", - "DataDir", - "WALDir", - - "HeartbeatIntervalMs", - "ElectionTimeoutMs", - - "ListenClientURLs", - "AdvertiseClientURLs", - "ClientAutoTLS", - "ClientCertAuth", - "ClientCertFile", - "ClientKeyFile", - "ClientTrustedCAFile", - - "ListenPeerURLs", - "AdvertisePeerURLs", - "PeerAutoTLS", - "PeerClientCertAuth", - "PeerCertFile", - "PeerKeyFile", - "PeerTrustedCAFile", - - "InitialCluster", - "InitialClusterState", - "InitialClusterToken", - - "SnapshotCount", - "QuotaBackendBytes", - - // "PreVote", - // "InitialCorruptCheck", -} - -// Flags returns etcd flags in string slice. -func (cfg *Etcd) Flags() (fs []string) { - tp := reflect.TypeOf(*cfg) - vo := reflect.ValueOf(*cfg) - for _, name := range etcdFields { - field, ok := tp.FieldByName(name) - if !ok { - panic(fmt.Errorf("field %q not found", name)) - } - fv := reflect.Indirect(vo).FieldByName(name) - var sv string - switch fv.Type().Kind() { - case reflect.String: - sv = fv.String() - case reflect.Slice: - n := fv.Len() - sl := make([]string, n) - for i := 0; i < n; i++ { - sl[i] = fv.Index(i).String() - } - sv = strings.Join(sl, ",") - case reflect.Int64: - sv = fmt.Sprintf("%d", fv.Int()) - case reflect.Bool: - sv = fmt.Sprintf("%v", fv.Bool()) - default: - panic(fmt.Errorf("field %q (%v) cannot be parsed", name, fv.Type().Kind())) - } - - fname := field.Tag.Get("yaml") - - // not supported in old etcd - if fname == "pre-vote" || fname == "initial-corrupt-check" { - continue - } - - if sv != "" { - fs = append(fs, fmt.Sprintf("--%s=%s", fname, sv)) - } - } - return fs -} diff --git a/vendor/github.com/coreos/etcd/functional/rpcpb/member.go b/vendor/github.com/coreos/etcd/functional/rpcpb/member.go deleted file mode 100644 index 01f68411340a..000000000000 --- a/vendor/github.com/coreos/etcd/functional/rpcpb/member.go +++ /dev/null @@ -1,361 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rpcpb - -import ( - "context" - "crypto/tls" - "fmt" - "net/url" - "os" - "time" - - "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/pkg/transport" - "github.com/coreos/etcd/snapshot" - - "github.com/dustin/go-humanize" - "go.uber.org/zap" - grpc "google.golang.org/grpc" - "google.golang.org/grpc/credentials" -) - -// ElectionTimeout returns an election timeout duration. -func (m *Member) ElectionTimeout() time.Duration { - return time.Duration(m.Etcd.ElectionTimeoutMs) * time.Millisecond -} - -// DialEtcdGRPCServer creates a raw gRPC connection to an etcd member. -func (m *Member) DialEtcdGRPCServer(opts ...grpc.DialOption) (*grpc.ClientConn, error) { - dialOpts := []grpc.DialOption{ - grpc.WithTimeout(5 * time.Second), - grpc.WithBlock(), - } - - secure := false - for _, cu := range m.Etcd.AdvertiseClientURLs { - u, err := url.Parse(cu) - if err != nil { - return nil, err - } - if u.Scheme == "https" { // TODO: handle unix - secure = true - } - } - - if secure { - // assume save TLS assets are already stord on disk - tlsInfo := transport.TLSInfo{ - CertFile: m.ClientCertPath, - KeyFile: m.ClientKeyPath, - TrustedCAFile: m.ClientTrustedCAPath, - - // TODO: remove this with generated certs - // only need it for auto TLS - InsecureSkipVerify: true, - } - tlsConfig, err := tlsInfo.ClientConfig() - if err != nil { - return nil, err - } - creds := credentials.NewTLS(tlsConfig) - dialOpts = append(dialOpts, grpc.WithTransportCredentials(creds)) - } else { - dialOpts = append(dialOpts, grpc.WithInsecure()) - } - dialOpts = append(dialOpts, opts...) - return grpc.Dial(m.EtcdClientEndpoint, dialOpts...) -} - -// CreateEtcdClientConfig creates a client configuration from member. -func (m *Member) CreateEtcdClientConfig(opts ...grpc.DialOption) (cfg *clientv3.Config, err error) { - secure := false - for _, cu := range m.Etcd.AdvertiseClientURLs { - var u *url.URL - u, err = url.Parse(cu) - if err != nil { - return nil, err - } - if u.Scheme == "https" { // TODO: handle unix - secure = true - } - } - - cfg = &clientv3.Config{ - Endpoints: []string{m.EtcdClientEndpoint}, - DialTimeout: 10 * time.Second, - DialOptions: opts, - } - if secure { - // assume save TLS assets are already stord on disk - tlsInfo := transport.TLSInfo{ - CertFile: m.ClientCertPath, - KeyFile: m.ClientKeyPath, - TrustedCAFile: m.ClientTrustedCAPath, - - // TODO: remove this with generated certs - // only need it for auto TLS - InsecureSkipVerify: true, - } - var tlsConfig *tls.Config - tlsConfig, err = tlsInfo.ClientConfig() - if err != nil { - return nil, err - } - cfg.TLS = tlsConfig - } - return cfg, err -} - -// CreateEtcdClient creates a client from member. -func (m *Member) CreateEtcdClient(opts ...grpc.DialOption) (*clientv3.Client, error) { - cfg, err := m.CreateEtcdClientConfig(opts...) - if err != nil { - return nil, err - } - return clientv3.New(*cfg) -} - -// CheckCompact ensures that historical data before given revision has been compacted. -func (m *Member) CheckCompact(rev int64) error { - cli, err := m.CreateEtcdClient() - if err != nil { - return fmt.Errorf("%v (%q)", err, m.EtcdClientEndpoint) - } - defer cli.Close() - - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - wch := cli.Watch(ctx, "\x00", clientv3.WithFromKey(), clientv3.WithRev(rev-1)) - wr, ok := <-wch - cancel() - - if !ok { - return fmt.Errorf("watch channel terminated (endpoint %q)", m.EtcdClientEndpoint) - } - if wr.CompactRevision != rev { - return fmt.Errorf("got compact revision %v, wanted %v (endpoint %q)", wr.CompactRevision, rev, m.EtcdClientEndpoint) - } - - return nil -} - -// Defrag runs defragmentation on this member. -func (m *Member) Defrag() error { - cli, err := m.CreateEtcdClient() - if err != nil { - return fmt.Errorf("%v (%q)", err, m.EtcdClientEndpoint) - } - defer cli.Close() - - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) - _, err = cli.Defragment(ctx, m.EtcdClientEndpoint) - cancel() - return err -} - -// RevHash fetches current revision and hash on this member. -func (m *Member) RevHash() (int64, int64, error) { - conn, err := m.DialEtcdGRPCServer() - if err != nil { - return 0, 0, err - } - defer conn.Close() - - mt := pb.NewMaintenanceClient(conn) - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - resp, err := mt.Hash(ctx, &pb.HashRequest{}, grpc.FailFast(false)) - cancel() - - if err != nil { - return 0, 0, err - } - - return resp.Header.Revision, int64(resp.Hash), nil -} - -// Rev fetches current revision on this member. -func (m *Member) Rev(ctx context.Context) (int64, error) { - cli, err := m.CreateEtcdClient() - if err != nil { - return 0, fmt.Errorf("%v (%q)", err, m.EtcdClientEndpoint) - } - defer cli.Close() - - resp, err := cli.Status(ctx, m.EtcdClientEndpoint) - if err != nil { - return 0, err - } - return resp.Header.Revision, nil -} - -// Compact compacts member storage with given revision. -// It blocks until it's physically done. -func (m *Member) Compact(rev int64, timeout time.Duration) error { - cli, err := m.CreateEtcdClient() - if err != nil { - return fmt.Errorf("%v (%q)", err, m.EtcdClientEndpoint) - } - defer cli.Close() - - ctx, cancel := context.WithTimeout(context.Background(), timeout) - _, err = cli.Compact(ctx, rev, clientv3.WithCompactPhysical()) - cancel() - return err -} - -// IsLeader returns true if this member is the current cluster leader. -func (m *Member) IsLeader() (bool, error) { - cli, err := m.CreateEtcdClient() - if err != nil { - return false, fmt.Errorf("%v (%q)", err, m.EtcdClientEndpoint) - } - defer cli.Close() - - resp, err := cli.Status(context.Background(), m.EtcdClientEndpoint) - if err != nil { - return false, err - } - return resp.Header.MemberId == resp.Leader, nil -} - -// WriteHealthKey writes a health key to this member. -func (m *Member) WriteHealthKey() error { - cli, err := m.CreateEtcdClient() - if err != nil { - return fmt.Errorf("%v (%q)", err, m.EtcdClientEndpoint) - } - defer cli.Close() - - // give enough time-out in case expensive requests (range/delete) are pending - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - _, err = cli.Put(ctx, "health", "good") - cancel() - if err != nil { - return fmt.Errorf("%v (%q)", err, m.EtcdClientEndpoint) - } - return nil -} - -// SaveSnapshot downloads a snapshot file from this member, locally. -// It's meant to requested remotely, so that local member can store -// snapshot file on local disk. -func (m *Member) SaveSnapshot(lg *zap.Logger) (err error) { - // remove existing snapshot first - if err = os.RemoveAll(m.SnapshotPath); err != nil { - return err - } - - var ccfg *clientv3.Config - ccfg, err = m.CreateEtcdClientConfig() - if err != nil { - return fmt.Errorf("%v (%q)", err, m.EtcdClientEndpoint) - } - - lg.Info( - "snapshot save START", - zap.String("member-name", m.Etcd.Name), - zap.Strings("member-client-urls", m.Etcd.AdvertiseClientURLs), - zap.String("snapshot-path", m.SnapshotPath), - ) - now := time.Now() - mgr := snapshot.NewV3(lg) - if err = mgr.Save(context.Background(), *ccfg, m.SnapshotPath); err != nil { - return err - } - took := time.Since(now) - - var fi os.FileInfo - fi, err = os.Stat(m.SnapshotPath) - if err != nil { - return err - } - var st snapshot.Status - st, err = mgr.Status(m.SnapshotPath) - if err != nil { - return err - } - m.SnapshotInfo = &SnapshotInfo{ - MemberName: m.Etcd.Name, - MemberClientURLs: m.Etcd.AdvertiseClientURLs, - SnapshotPath: m.SnapshotPath, - SnapshotFileSize: humanize.Bytes(uint64(fi.Size())), - SnapshotTotalSize: humanize.Bytes(uint64(st.TotalSize)), - SnapshotTotalKey: int64(st.TotalKey), - SnapshotHash: int64(st.Hash), - SnapshotRevision: st.Revision, - Took: fmt.Sprintf("%v", took), - } - lg.Info( - "snapshot save END", - zap.String("member-name", m.SnapshotInfo.MemberName), - zap.Strings("member-client-urls", m.SnapshotInfo.MemberClientURLs), - zap.String("snapshot-path", m.SnapshotPath), - zap.String("snapshot-file-size", m.SnapshotInfo.SnapshotFileSize), - zap.String("snapshot-total-size", m.SnapshotInfo.SnapshotTotalSize), - zap.Int64("snapshot-total-key", m.SnapshotInfo.SnapshotTotalKey), - zap.Int64("snapshot-hash", m.SnapshotInfo.SnapshotHash), - zap.Int64("snapshot-revision", m.SnapshotInfo.SnapshotRevision), - zap.String("took", m.SnapshotInfo.Took), - ) - return nil -} - -// RestoreSnapshot restores a cluster from a given snapshot file on disk. -// It's meant to requested remotely, so that local member can load the -// snapshot file from local disk. -func (m *Member) RestoreSnapshot(lg *zap.Logger) (err error) { - if err = os.RemoveAll(m.EtcdOnSnapshotRestore.DataDir); err != nil { - return err - } - if err = os.RemoveAll(m.EtcdOnSnapshotRestore.WALDir); err != nil { - return err - } - - lg.Info( - "snapshot restore START", - zap.String("member-name", m.Etcd.Name), - zap.Strings("member-client-urls", m.Etcd.AdvertiseClientURLs), - zap.String("snapshot-path", m.SnapshotPath), - ) - now := time.Now() - mgr := snapshot.NewV3(lg) - err = mgr.Restore(snapshot.RestoreConfig{ - SnapshotPath: m.SnapshotInfo.SnapshotPath, - Name: m.EtcdOnSnapshotRestore.Name, - OutputDataDir: m.EtcdOnSnapshotRestore.DataDir, - OutputWALDir: m.EtcdOnSnapshotRestore.WALDir, - PeerURLs: m.EtcdOnSnapshotRestore.AdvertisePeerURLs, - InitialCluster: m.EtcdOnSnapshotRestore.InitialCluster, - InitialClusterToken: m.EtcdOnSnapshotRestore.InitialClusterToken, - SkipHashCheck: false, - // TODO: set SkipHashCheck it true, to recover from existing db file - }) - took := time.Since(now) - lg.Info( - "snapshot restore END", - zap.String("member-name", m.SnapshotInfo.MemberName), - zap.Strings("member-client-urls", m.SnapshotInfo.MemberClientURLs), - zap.String("snapshot-path", m.SnapshotPath), - zap.String("snapshot-file-size", m.SnapshotInfo.SnapshotFileSize), - zap.String("snapshot-total-size", m.SnapshotInfo.SnapshotTotalSize), - zap.Int64("snapshot-total-key", m.SnapshotInfo.SnapshotTotalKey), - zap.Int64("snapshot-hash", m.SnapshotInfo.SnapshotHash), - zap.Int64("snapshot-revision", m.SnapshotInfo.SnapshotRevision), - zap.String("took", took.String()), - zap.Error(err), - ) - return err -} diff --git a/vendor/github.com/coreos/etcd/functional/rpcpb/rpc.pb.go b/vendor/github.com/coreos/etcd/functional/rpcpb/rpc.pb.go deleted file mode 100644 index 1c488dc47336..000000000000 --- a/vendor/github.com/coreos/etcd/functional/rpcpb/rpc.pb.go +++ /dev/null @@ -1,5112 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: rpcpb/rpc.proto - -/* - Package rpcpb is a generated protocol buffer package. - - It is generated from these files: - rpcpb/rpc.proto - - It has these top-level messages: - Request - SnapshotInfo - Response - Member - Tester - Etcd -*/ -package rpcpb - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" -import _ "github.com/gogo/protobuf/gogoproto" - -import context "golang.org/x/net/context" -import grpc "google.golang.org/grpc" - -import io "io" - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type Operation int32 - -const ( - // NOT_STARTED is the agent status before etcd first start. - Operation_NOT_STARTED Operation = 0 - // INITIAL_START_ETCD is only called to start etcd, the very first time. - Operation_INITIAL_START_ETCD Operation = 10 - // RESTART_ETCD is sent to restart killed etcd. - Operation_RESTART_ETCD Operation = 11 - // SIGTERM_ETCD pauses etcd process while keeping data directories - // and previous etcd configurations. - Operation_SIGTERM_ETCD Operation = 20 - // SIGQUIT_ETCD_AND_REMOVE_DATA kills etcd process and removes all data - // directories to simulate destroying the whole machine. - Operation_SIGQUIT_ETCD_AND_REMOVE_DATA Operation = 21 - // SAVE_SNAPSHOT is sent to trigger local member to download its snapshot - // onto its local disk with the specified path from tester. - Operation_SAVE_SNAPSHOT Operation = 30 - // RESTORE_RESTART_FROM_SNAPSHOT is sent to trigger local member to - // restore a cluster from existing snapshot from disk, and restart - // an etcd instance from recovered data. - Operation_RESTORE_RESTART_FROM_SNAPSHOT Operation = 31 - // RESTART_FROM_SNAPSHOT is sent to trigger local member to restart - // and join an existing cluster that has been recovered from a snapshot. - // Local member joins this cluster with fresh data. - Operation_RESTART_FROM_SNAPSHOT Operation = 32 - // SIGQUIT_ETCD_AND_ARCHIVE_DATA is sent when consistency check failed, - // thus need to archive etcd data directories. - Operation_SIGQUIT_ETCD_AND_ARCHIVE_DATA Operation = 40 - // SIGQUIT_ETCD_AND_REMOVE_DATA_AND_STOP_AGENT destroys etcd process, - // etcd data, and agent server. - Operation_SIGQUIT_ETCD_AND_REMOVE_DATA_AND_STOP_AGENT Operation = 41 - // BLACKHOLE_PEER_PORT_TX_RX drops all outgoing/incoming packets from/to - // the peer port on target member's peer port. - Operation_BLACKHOLE_PEER_PORT_TX_RX Operation = 100 - // UNBLACKHOLE_PEER_PORT_TX_RX removes outgoing/incoming packet dropping. - Operation_UNBLACKHOLE_PEER_PORT_TX_RX Operation = 101 - // DELAY_PEER_PORT_TX_RX delays all outgoing/incoming packets from/to - // the peer port on target member's peer port. - Operation_DELAY_PEER_PORT_TX_RX Operation = 200 - // UNDELAY_PEER_PORT_TX_RX removes all outgoing/incoming delays. - Operation_UNDELAY_PEER_PORT_TX_RX Operation = 201 -) - -var Operation_name = map[int32]string{ - 0: "NOT_STARTED", - 10: "INITIAL_START_ETCD", - 11: "RESTART_ETCD", - 20: "SIGTERM_ETCD", - 21: "SIGQUIT_ETCD_AND_REMOVE_DATA", - 30: "SAVE_SNAPSHOT", - 31: "RESTORE_RESTART_FROM_SNAPSHOT", - 32: "RESTART_FROM_SNAPSHOT", - 40: "SIGQUIT_ETCD_AND_ARCHIVE_DATA", - 41: "SIGQUIT_ETCD_AND_REMOVE_DATA_AND_STOP_AGENT", - 100: "BLACKHOLE_PEER_PORT_TX_RX", - 101: "UNBLACKHOLE_PEER_PORT_TX_RX", - 200: "DELAY_PEER_PORT_TX_RX", - 201: "UNDELAY_PEER_PORT_TX_RX", -} -var Operation_value = map[string]int32{ - "NOT_STARTED": 0, - "INITIAL_START_ETCD": 10, - "RESTART_ETCD": 11, - "SIGTERM_ETCD": 20, - "SIGQUIT_ETCD_AND_REMOVE_DATA": 21, - "SAVE_SNAPSHOT": 30, - "RESTORE_RESTART_FROM_SNAPSHOT": 31, - "RESTART_FROM_SNAPSHOT": 32, - "SIGQUIT_ETCD_AND_ARCHIVE_DATA": 40, - "SIGQUIT_ETCD_AND_REMOVE_DATA_AND_STOP_AGENT": 41, - "BLACKHOLE_PEER_PORT_TX_RX": 100, - "UNBLACKHOLE_PEER_PORT_TX_RX": 101, - "DELAY_PEER_PORT_TX_RX": 200, - "UNDELAY_PEER_PORT_TX_RX": 201, -} - -func (x Operation) String() string { - return proto.EnumName(Operation_name, int32(x)) -} -func (Operation) EnumDescriptor() ([]byte, []int) { return fileDescriptorRpc, []int{0} } - -// Case defines various system faults or test case in distributed systems, -// in order to verify correct behavior of etcd servers and clients. -type Case int32 - -const ( - // SIGTERM_ONE_FOLLOWER stops a randomly chosen follower (non-leader) - // but does not delete its data directories on disk for next restart. - // It waits "delay-ms" before recovering this failure. - // The expected behavior is that the follower comes back online - // and rejoins the cluster, and then each member continues to process - // client requests ('Put' request that requires Raft consensus). - Case_SIGTERM_ONE_FOLLOWER Case = 0 - // SIGTERM_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT stops a randomly chosen - // follower but does not delete its data directories on disk for next - // restart. And waits until most up-to-date node (leader) applies the - // snapshot count of entries since the stop operation. - // The expected behavior is that the follower comes back online and - // rejoins the cluster, and then active leader sends snapshot - // to the follower to force it to follow the leader's log. - // As always, after recovery, each member must be able to process - // client requests. - Case_SIGTERM_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT Case = 1 - // SIGTERM_LEADER stops the active leader node but does not delete its - // data directories on disk for next restart. Then it waits "delay-ms" - // before recovering this failure, in order to trigger election timeouts. - // The expected behavior is that a new leader gets elected, and the - // old leader comes back online and rejoins the cluster as a follower. - // As always, after recovery, each member must be able to process - // client requests. - Case_SIGTERM_LEADER Case = 2 - // SIGTERM_LEADER_UNTIL_TRIGGER_SNAPSHOT stops the active leader node - // but does not delete its data directories on disk for next restart. - // And waits until most up-to-date node ("new" leader) applies the - // snapshot count of entries since the stop operation. - // The expected behavior is that cluster elects a new leader, and the - // old leader comes back online and rejoins the cluster as a follower. - // And it receives the snapshot from the new leader to overwrite its - // store. As always, after recovery, each member must be able to - // process client requests. - Case_SIGTERM_LEADER_UNTIL_TRIGGER_SNAPSHOT Case = 3 - // SIGTERM_QUORUM stops majority number of nodes to make the whole cluster - // inoperable but does not delete data directories on stopped nodes - // for next restart. And it waits "delay-ms" before recovering failure. - // The expected behavior is that nodes come back online, thus cluster - // comes back operative as well. As always, after recovery, each member - // must be able to process client requests. - Case_SIGTERM_QUORUM Case = 4 - // SIGTERM_ALL stops the whole cluster but does not delete data directories - // on disk for next restart. And it waits "delay-ms" before recovering - // this failure. - // The expected behavior is that nodes come back online, thus cluster - // comes back operative as well. As always, after recovery, each member - // must be able to process client requests. - Case_SIGTERM_ALL Case = 5 - // SIGQUIT_AND_REMOVE_ONE_FOLLOWER stops a randomly chosen follower - // (non-leader), deletes its data directories on disk, and removes - // this member from cluster (membership reconfiguration). On recovery, - // tester adds a new member, and this member joins the existing cluster - // with fresh data. It waits "delay-ms" before recovering this - // failure. This simulates destroying one follower machine, where operator - // needs to add a new member from a fresh machine. - // The expected behavior is that a new member joins the existing cluster, - // and then each member continues to process client requests. - Case_SIGQUIT_AND_REMOVE_ONE_FOLLOWER Case = 10 - // SIGQUIT_AND_REMOVE_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT stops a randomly - // chosen follower, deletes its data directories on disk, and removes - // this member from cluster (membership reconfiguration). On recovery, - // tester adds a new member, and this member joins the existing cluster - // restart. On member remove, cluster waits until most up-to-date node - // (leader) applies the snapshot count of entries since the stop operation. - // This simulates destroying a leader machine, where operator needs to add - // a new member from a fresh machine. - // The expected behavior is that a new member joins the existing cluster, - // and receives a snapshot from the active leader. As always, after - // recovery, each member must be able to process client requests. - Case_SIGQUIT_AND_REMOVE_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT Case = 11 - // SIGQUIT_AND_REMOVE_LEADER stops the active leader node, deletes its - // data directories on disk, and removes this member from cluster. - // On recovery, tester adds a new member, and this member joins the - // existing cluster with fresh data. It waits "delay-ms" before - // recovering this failure. This simulates destroying a leader machine, - // where operator needs to add a new member from a fresh machine. - // The expected behavior is that a new member joins the existing cluster, - // and then each member continues to process client requests. - Case_SIGQUIT_AND_REMOVE_LEADER Case = 12 - // SIGQUIT_AND_REMOVE_LEADER_UNTIL_TRIGGER_SNAPSHOT stops the active leader, - // deletes its data directories on disk, and removes this member from - // cluster (membership reconfiguration). On recovery, tester adds a new - // member, and this member joins the existing cluster restart. On member - // remove, cluster waits until most up-to-date node (new leader) applies - // the snapshot count of entries since the stop operation. This simulates - // destroying a leader machine, where operator needs to add a new member - // from a fresh machine. - // The expected behavior is that on member remove, cluster elects a new - // leader, and a new member joins the existing cluster and receives a - // snapshot from the newly elected leader. As always, after recovery, each - // member must be able to process client requests. - Case_SIGQUIT_AND_REMOVE_LEADER_UNTIL_TRIGGER_SNAPSHOT Case = 13 - // SIGQUIT_AND_REMOVE_QUORUM_AND_RESTORE_LEADER_SNAPSHOT_FROM_SCRATCH first - // stops majority number of nodes, deletes data directories on those quorum - // nodes, to make the whole cluster inoperable. Now that quorum and their - // data are totally destroyed, cluster cannot even remove unavailable nodes - // (e.g. 2 out of 3 are lost, so no leader can be elected). - // Let's assume 3-node cluster of node A, B, and C. One day, node A and B - // are destroyed and all their data are gone. The only viable solution is - // to recover from C's latest snapshot. - // - // To simulate: - // 1. Assume node C is the current leader with most up-to-date data. - // 2. Download snapshot from node C, before destroying node A and B. - // 3. Destroy node A and B, and make the whole cluster inoperable. - // 4. Now node C cannot operate either. - // 5. SIGTERM node C and remove its data directories. - // 6. Restore a new seed member from node C's latest snapshot file. - // 7. Add another member to establish 2-node cluster. - // 8. Add another member to establish 3-node cluster. - // 9. Add more if any. - // - // The expected behavior is that etcd successfully recovers from such - // disastrous situation as only 1-node survives out of 3-node cluster, - // new members joins the existing cluster, and previous data from snapshot - // are still preserved after recovery process. As always, after recovery, - // each member must be able to process client requests. - Case_SIGQUIT_AND_REMOVE_QUORUM_AND_RESTORE_LEADER_SNAPSHOT_FROM_SCRATCH Case = 14 - // BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER drops all outgoing/incoming - // packets from/to the peer port on a randomly chosen follower - // (non-leader), and waits for "delay-ms" until recovery. - // The expected behavior is that once dropping operation is undone, - // each member must be able to process client requests. - Case_BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER Case = 100 - // BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT drops - // all outgoing/incoming packets from/to the peer port on a randomly - // chosen follower (non-leader), and waits for most up-to-date node - // (leader) applies the snapshot count of entries since the blackhole - // operation. - // The expected behavior is that once packet drop operation is undone, - // the slow follower tries to catch up, possibly receiving the snapshot - // from the active leader. As always, after recovery, each member must - // be able to process client requests. - Case_BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT Case = 101 - // BLACKHOLE_PEER_PORT_TX_RX_LEADER drops all outgoing/incoming packets - // from/to the peer port on the active leader (isolated), and waits for - // "delay-ms" until recovery, in order to trigger election timeout. - // The expected behavior is that after election timeout, a new leader gets - // elected, and once dropping operation is undone, the old leader comes - // back and rejoins the cluster as a follower. As always, after recovery, - // each member must be able to process client requests. - Case_BLACKHOLE_PEER_PORT_TX_RX_LEADER Case = 102 - // BLACKHOLE_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT drops all - // outgoing/incoming packets from/to the peer port on the active leader, - // and waits for most up-to-date node (leader) applies the snapshot - // count of entries since the blackhole operation. - // The expected behavior is that cluster elects a new leader, and once - // dropping operation is undone, the old leader comes back and rejoins - // the cluster as a follower. The slow follower tries to catch up, likely - // receiving the snapshot from the new active leader. As always, after - // recovery, each member must be able to process client requests. - Case_BLACKHOLE_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT Case = 103 - // BLACKHOLE_PEER_PORT_TX_RX_QUORUM drops all outgoing/incoming packets - // from/to the peer ports on majority nodes of cluster, thus losing its - // leader and cluster being inoperable. And it waits for "delay-ms" - // until recovery. - // The expected behavior is that once packet drop operation is undone, - // nodes come back online, thus cluster comes back operative. As always, - // after recovery, each member must be able to process client requests. - Case_BLACKHOLE_PEER_PORT_TX_RX_QUORUM Case = 104 - // BLACKHOLE_PEER_PORT_TX_RX_ALL drops all outgoing/incoming packets - // from/to the peer ports on all nodes, thus making cluster totally - // inoperable. It waits for "delay-ms" until recovery. - // The expected behavior is that once packet drop operation is undone, - // nodes come back online, thus cluster comes back operative. As always, - // after recovery, each member must be able to process client requests. - Case_BLACKHOLE_PEER_PORT_TX_RX_ALL Case = 105 - // DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER delays outgoing/incoming packets - // from/to the peer port on a randomly chosen follower (non-leader). - // It waits for "delay-ms" until recovery. - // The expected behavior is that once packet delay operation is undone, - // the follower comes back and tries to catch up with latest changes from - // cluster. And as always, after recovery, each member must be able to - // process client requests. - Case_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER Case = 200 - // RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER delays outgoing/incoming - // packets from/to the peer port on a randomly chosen follower - // (non-leader) with a randomized time duration (thus isolated). It - // waits for "delay-ms" until recovery. - // The expected behavior is that once packet delay operation is undone, - // each member must be able to process client requests. - Case_RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER Case = 201 - // DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT delays - // outgoing/incoming packets from/to the peer port on a randomly chosen - // follower (non-leader), and waits for most up-to-date node (leader) - // applies the snapshot count of entries since the delay operation. - // The expected behavior is that the delayed follower gets isolated - // and behind the current active leader, and once delay operation is undone, - // the slow follower comes back and catches up possibly receiving snapshot - // from the active leader. As always, after recovery, each member must be - // able to process client requests. - Case_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT Case = 202 - // RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT delays - // outgoing/incoming packets from/to the peer port on a randomly chosen - // follower (non-leader) with a randomized time duration, and waits for - // most up-to-date node (leader) applies the snapshot count of entries - // since the delay operation. - // The expected behavior is that the delayed follower gets isolated - // and behind the current active leader, and once delay operation is undone, - // the slow follower comes back and catches up, possibly receiving a - // snapshot from the active leader. As always, after recovery, each member - // must be able to process client requests. - Case_RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT Case = 203 - // DELAY_PEER_PORT_TX_RX_LEADER delays outgoing/incoming packets from/to - // the peer port on the active leader. And waits for "delay-ms" until - // recovery. - // The expected behavior is that cluster may elect a new leader, and - // once packet delay operation is undone, the (old) leader comes back - // and tries to catch up with latest changes from cluster. As always, - // after recovery, each member must be able to process client requests. - Case_DELAY_PEER_PORT_TX_RX_LEADER Case = 204 - // RANDOM_DELAY_PEER_PORT_TX_RX_LEADER delays outgoing/incoming packets - // from/to the peer port on the active leader with a randomized time - // duration. And waits for "delay-ms" until recovery. - // The expected behavior is that cluster may elect a new leader, and - // once packet delay operation is undone, the (old) leader comes back - // and tries to catch up with latest changes from cluster. As always, - // after recovery, each member must be able to process client requests. - Case_RANDOM_DELAY_PEER_PORT_TX_RX_LEADER Case = 205 - // DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT delays - // outgoing/incoming packets from/to the peer port on the active leader, - // and waits for most up-to-date node (current or new leader) applies the - // snapshot count of entries since the delay operation. - // The expected behavior is that cluster may elect a new leader, and - // the old leader gets isolated and behind the current active leader, - // and once delay operation is undone, the slow follower comes back - // and catches up, likely receiving a snapshot from the active leader. - // As always, after recovery, each member must be able to process client - // requests. - Case_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT Case = 206 - // RANDOM_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT delays - // outgoing/incoming packets from/to the peer port on the active leader, - // with a randomized time duration. And it waits for most up-to-date node - // (current or new leader) applies the snapshot count of entries since the - // delay operation. - // The expected behavior is that cluster may elect a new leader, and - // the old leader gets isolated and behind the current active leader, - // and once delay operation is undone, the slow follower comes back - // and catches up, likely receiving a snapshot from the active leader. - // As always, after recovery, each member must be able to process client - // requests. - Case_RANDOM_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT Case = 207 - // DELAY_PEER_PORT_TX_RX_QUORUM delays outgoing/incoming packets from/to - // the peer ports on majority nodes of cluster. And it waits for - // "delay-ms" until recovery, likely to trigger election timeouts. - // The expected behavior is that cluster may elect a new leader, while - // quorum of nodes struggle with slow networks, and once delay operation - // is undone, nodes come back and cluster comes back operative. As always, - // after recovery, each member must be able to process client requests. - Case_DELAY_PEER_PORT_TX_RX_QUORUM Case = 208 - // RANDOM_DELAY_PEER_PORT_TX_RX_QUORUM delays outgoing/incoming packets - // from/to the peer ports on majority nodes of cluster, with randomized - // time durations. And it waits for "delay-ms" until recovery, likely - // to trigger election timeouts. - // The expected behavior is that cluster may elect a new leader, while - // quorum of nodes struggle with slow networks, and once delay operation - // is undone, nodes come back and cluster comes back operative. As always, - // after recovery, each member must be able to process client requests. - Case_RANDOM_DELAY_PEER_PORT_TX_RX_QUORUM Case = 209 - // DELAY_PEER_PORT_TX_RX_ALL delays outgoing/incoming packets from/to the - // peer ports on all nodes. And it waits for "delay-ms" until recovery, - // likely to trigger election timeouts. - // The expected behavior is that cluster may become totally inoperable, - // struggling with slow networks across the whole cluster. Once delay - // operation is undone, nodes come back and cluster comes back operative. - // As always, after recovery, each member must be able to process client - // requests. - Case_DELAY_PEER_PORT_TX_RX_ALL Case = 210 - // RANDOM_DELAY_PEER_PORT_TX_RX_ALL delays outgoing/incoming packets - // from/to the peer ports on all nodes, with randomized time durations. - // And it waits for "delay-ms" until recovery, likely to trigger - // election timeouts. - // The expected behavior is that cluster may become totally inoperable, - // struggling with slow networks across the whole cluster. Once delay - // operation is undone, nodes come back and cluster comes back operative. - // As always, after recovery, each member must be able to process client - // requests. - Case_RANDOM_DELAY_PEER_PORT_TX_RX_ALL Case = 211 - // NO_FAIL_WITH_STRESS stops injecting failures while testing the - // consistency and correctness under pressure loads, for the duration of - // "delay-ms". Goal is to ensure cluster be still making progress - // on recovery, and verify system does not deadlock following a sequence - // of failure injections. - // The expected behavior is that cluster remains fully operative in healthy - // condition. As always, after recovery, each member must be able to process - // client requests. - Case_NO_FAIL_WITH_STRESS Case = 300 - // NO_FAIL_WITH_NO_STRESS_FOR_LIVENESS neither injects failures nor - // sends stressig client requests to the cluster, for the duration of - // "delay-ms". Goal is to ensure cluster be still making progress - // on recovery, and verify system does not deadlock following a sequence - // of failure injections. - // The expected behavior is that cluster remains fully operative in healthy - // condition, and clients requests during liveness period succeed without - // errors. - // Note: this is how Google Chubby does failure injection testing - // https://static.googleusercontent.com/media/research.google.com/en//archive/paxos_made_live.pdf. - Case_NO_FAIL_WITH_NO_STRESS_FOR_LIVENESS Case = 301 - // FAILPOINTS injects failpoints to etcd server runtime, triggering panics - // in critical code paths. - Case_FAILPOINTS Case = 400 - // EXTERNAL runs external failure injection scripts. - Case_EXTERNAL Case = 500 -) - -var Case_name = map[int32]string{ - 0: "SIGTERM_ONE_FOLLOWER", - 1: "SIGTERM_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT", - 2: "SIGTERM_LEADER", - 3: "SIGTERM_LEADER_UNTIL_TRIGGER_SNAPSHOT", - 4: "SIGTERM_QUORUM", - 5: "SIGTERM_ALL", - 10: "SIGQUIT_AND_REMOVE_ONE_FOLLOWER", - 11: "SIGQUIT_AND_REMOVE_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT", - 12: "SIGQUIT_AND_REMOVE_LEADER", - 13: "SIGQUIT_AND_REMOVE_LEADER_UNTIL_TRIGGER_SNAPSHOT", - 14: "SIGQUIT_AND_REMOVE_QUORUM_AND_RESTORE_LEADER_SNAPSHOT_FROM_SCRATCH", - 100: "BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER", - 101: "BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT", - 102: "BLACKHOLE_PEER_PORT_TX_RX_LEADER", - 103: "BLACKHOLE_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT", - 104: "BLACKHOLE_PEER_PORT_TX_RX_QUORUM", - 105: "BLACKHOLE_PEER_PORT_TX_RX_ALL", - 200: "DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER", - 201: "RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER", - 202: "DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT", - 203: "RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT", - 204: "DELAY_PEER_PORT_TX_RX_LEADER", - 205: "RANDOM_DELAY_PEER_PORT_TX_RX_LEADER", - 206: "DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT", - 207: "RANDOM_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT", - 208: "DELAY_PEER_PORT_TX_RX_QUORUM", - 209: "RANDOM_DELAY_PEER_PORT_TX_RX_QUORUM", - 210: "DELAY_PEER_PORT_TX_RX_ALL", - 211: "RANDOM_DELAY_PEER_PORT_TX_RX_ALL", - 300: "NO_FAIL_WITH_STRESS", - 301: "NO_FAIL_WITH_NO_STRESS_FOR_LIVENESS", - 400: "FAILPOINTS", - 500: "EXTERNAL", -} -var Case_value = map[string]int32{ - "SIGTERM_ONE_FOLLOWER": 0, - "SIGTERM_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT": 1, - "SIGTERM_LEADER": 2, - "SIGTERM_LEADER_UNTIL_TRIGGER_SNAPSHOT": 3, - "SIGTERM_QUORUM": 4, - "SIGTERM_ALL": 5, - "SIGQUIT_AND_REMOVE_ONE_FOLLOWER": 10, - "SIGQUIT_AND_REMOVE_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT": 11, - "SIGQUIT_AND_REMOVE_LEADER": 12, - "SIGQUIT_AND_REMOVE_LEADER_UNTIL_TRIGGER_SNAPSHOT": 13, - "SIGQUIT_AND_REMOVE_QUORUM_AND_RESTORE_LEADER_SNAPSHOT_FROM_SCRATCH": 14, - "BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER": 100, - "BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT": 101, - "BLACKHOLE_PEER_PORT_TX_RX_LEADER": 102, - "BLACKHOLE_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT": 103, - "BLACKHOLE_PEER_PORT_TX_RX_QUORUM": 104, - "BLACKHOLE_PEER_PORT_TX_RX_ALL": 105, - "DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER": 200, - "RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER": 201, - "DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT": 202, - "RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT": 203, - "DELAY_PEER_PORT_TX_RX_LEADER": 204, - "RANDOM_DELAY_PEER_PORT_TX_RX_LEADER": 205, - "DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT": 206, - "RANDOM_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT": 207, - "DELAY_PEER_PORT_TX_RX_QUORUM": 208, - "RANDOM_DELAY_PEER_PORT_TX_RX_QUORUM": 209, - "DELAY_PEER_PORT_TX_RX_ALL": 210, - "RANDOM_DELAY_PEER_PORT_TX_RX_ALL": 211, - "NO_FAIL_WITH_STRESS": 300, - "NO_FAIL_WITH_NO_STRESS_FOR_LIVENESS": 301, - "FAILPOINTS": 400, - "EXTERNAL": 500, -} - -func (x Case) String() string { - return proto.EnumName(Case_name, int32(x)) -} -func (Case) EnumDescriptor() ([]byte, []int) { return fileDescriptorRpc, []int{1} } - -type Stresser int32 - -const ( - Stresser_KV Stresser = 0 - Stresser_LEASE Stresser = 1 - Stresser_ELECTION_RUNNER Stresser = 2 - Stresser_WATCH_RUNNER Stresser = 3 - Stresser_LOCK_RACER_RUNNER Stresser = 4 - Stresser_LEASE_RUNNER Stresser = 5 -) - -var Stresser_name = map[int32]string{ - 0: "KV", - 1: "LEASE", - 2: "ELECTION_RUNNER", - 3: "WATCH_RUNNER", - 4: "LOCK_RACER_RUNNER", - 5: "LEASE_RUNNER", -} -var Stresser_value = map[string]int32{ - "KV": 0, - "LEASE": 1, - "ELECTION_RUNNER": 2, - "WATCH_RUNNER": 3, - "LOCK_RACER_RUNNER": 4, - "LEASE_RUNNER": 5, -} - -func (x Stresser) String() string { - return proto.EnumName(Stresser_name, int32(x)) -} -func (Stresser) EnumDescriptor() ([]byte, []int) { return fileDescriptorRpc, []int{2} } - -type Checker int32 - -const ( - Checker_KV_HASH Checker = 0 - Checker_LEASE_EXPIRE Checker = 1 - Checker_RUNNER Checker = 2 - Checker_NO_CHECK Checker = 3 -) - -var Checker_name = map[int32]string{ - 0: "KV_HASH", - 1: "LEASE_EXPIRE", - 2: "RUNNER", - 3: "NO_CHECK", -} -var Checker_value = map[string]int32{ - "KV_HASH": 0, - "LEASE_EXPIRE": 1, - "RUNNER": 2, - "NO_CHECK": 3, -} - -func (x Checker) String() string { - return proto.EnumName(Checker_name, int32(x)) -} -func (Checker) EnumDescriptor() ([]byte, []int) { return fileDescriptorRpc, []int{3} } - -type Request struct { - Operation Operation `protobuf:"varint,1,opt,name=Operation,proto3,enum=rpcpb.Operation" json:"Operation,omitempty"` - // Member contains the same Member object from tester configuration. - Member *Member `protobuf:"bytes,2,opt,name=Member" json:"Member,omitempty"` - // Tester contains tester configuration. - Tester *Tester `protobuf:"bytes,3,opt,name=Tester" json:"Tester,omitempty"` -} - -func (m *Request) Reset() { *m = Request{} } -func (m *Request) String() string { return proto.CompactTextString(m) } -func (*Request) ProtoMessage() {} -func (*Request) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{0} } - -// SnapshotInfo contains SAVE_SNAPSHOT request results. -type SnapshotInfo struct { - MemberName string `protobuf:"bytes,1,opt,name=MemberName,proto3" json:"MemberName,omitempty"` - MemberClientURLs []string `protobuf:"bytes,2,rep,name=MemberClientURLs" json:"MemberClientURLs,omitempty"` - SnapshotPath string `protobuf:"bytes,3,opt,name=SnapshotPath,proto3" json:"SnapshotPath,omitempty"` - SnapshotFileSize string `protobuf:"bytes,4,opt,name=SnapshotFileSize,proto3" json:"SnapshotFileSize,omitempty"` - SnapshotTotalSize string `protobuf:"bytes,5,opt,name=SnapshotTotalSize,proto3" json:"SnapshotTotalSize,omitempty"` - SnapshotTotalKey int64 `protobuf:"varint,6,opt,name=SnapshotTotalKey,proto3" json:"SnapshotTotalKey,omitempty"` - SnapshotHash int64 `protobuf:"varint,7,opt,name=SnapshotHash,proto3" json:"SnapshotHash,omitempty"` - SnapshotRevision int64 `protobuf:"varint,8,opt,name=SnapshotRevision,proto3" json:"SnapshotRevision,omitempty"` - Took string `protobuf:"bytes,9,opt,name=Took,proto3" json:"Took,omitempty"` -} - -func (m *SnapshotInfo) Reset() { *m = SnapshotInfo{} } -func (m *SnapshotInfo) String() string { return proto.CompactTextString(m) } -func (*SnapshotInfo) ProtoMessage() {} -func (*SnapshotInfo) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{1} } - -type Response struct { - Success bool `protobuf:"varint,1,opt,name=Success,proto3" json:"Success,omitempty"` - Status string `protobuf:"bytes,2,opt,name=Status,proto3" json:"Status,omitempty"` - // Member contains the same Member object from tester request. - Member *Member `protobuf:"bytes,3,opt,name=Member" json:"Member,omitempty"` - // SnapshotInfo contains SAVE_SNAPSHOT request results. - SnapshotInfo *SnapshotInfo `protobuf:"bytes,4,opt,name=SnapshotInfo" json:"SnapshotInfo,omitempty"` -} - -func (m *Response) Reset() { *m = Response{} } -func (m *Response) String() string { return proto.CompactTextString(m) } -func (*Response) ProtoMessage() {} -func (*Response) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{2} } - -type Member struct { - // EtcdExecPath is the executable etcd binary path in agent server. - EtcdExecPath string `protobuf:"bytes,1,opt,name=EtcdExecPath,proto3" json:"EtcdExecPath,omitempty" yaml:"etcd-exec-path"` - // AgentAddr is the agent HTTP server address. - AgentAddr string `protobuf:"bytes,11,opt,name=AgentAddr,proto3" json:"AgentAddr,omitempty" yaml:"agent-addr"` - // FailpointHTTPAddr is the agent's failpoints HTTP server address. - FailpointHTTPAddr string `protobuf:"bytes,12,opt,name=FailpointHTTPAddr,proto3" json:"FailpointHTTPAddr,omitempty" yaml:"failpoint-http-addr"` - // BaseDir is the base directory where all logs and etcd data are stored. - BaseDir string `protobuf:"bytes,101,opt,name=BaseDir,proto3" json:"BaseDir,omitempty" yaml:"base-dir"` - // EtcdLogPath is the log file to store current etcd server logs. - EtcdLogPath string `protobuf:"bytes,102,opt,name=EtcdLogPath,proto3" json:"EtcdLogPath,omitempty" yaml:"etcd-log-path"` - // EtcdClientProxy is true when client traffic needs to be proxied. - // If true, listen client URL port must be different than advertise client URL port. - EtcdClientProxy bool `protobuf:"varint,201,opt,name=EtcdClientProxy,proto3" json:"EtcdClientProxy,omitempty" yaml:"etcd-client-proxy"` - // EtcdPeerProxy is true when peer traffic needs to be proxied. - // If true, listen peer URL port must be different than advertise peer URL port. - EtcdPeerProxy bool `protobuf:"varint,202,opt,name=EtcdPeerProxy,proto3" json:"EtcdPeerProxy,omitempty" yaml:"etcd-peer-proxy"` - // EtcdClientEndpoint is the etcd client endpoint. - EtcdClientEndpoint string `protobuf:"bytes,301,opt,name=EtcdClientEndpoint,proto3" json:"EtcdClientEndpoint,omitempty" yaml:"etcd-client-endpoint"` - // Etcd defines etcd binary configuration flags. - Etcd *Etcd `protobuf:"bytes,302,opt,name=Etcd" json:"Etcd,omitempty" yaml:"etcd"` - // EtcdOnSnapshotRestore defines one-time use configuration during etcd - // snapshot recovery process. - EtcdOnSnapshotRestore *Etcd `protobuf:"bytes,303,opt,name=EtcdOnSnapshotRestore" json:"EtcdOnSnapshotRestore,omitempty"` - // ClientCertData contains cert file contents from this member's etcd server. - ClientCertData string `protobuf:"bytes,401,opt,name=ClientCertData,proto3" json:"ClientCertData,omitempty" yaml:"client-cert-data"` - ClientCertPath string `protobuf:"bytes,402,opt,name=ClientCertPath,proto3" json:"ClientCertPath,omitempty" yaml:"client-cert-path"` - // ClientKeyData contains key file contents from this member's etcd server. - ClientKeyData string `protobuf:"bytes,403,opt,name=ClientKeyData,proto3" json:"ClientKeyData,omitempty" yaml:"client-key-data"` - ClientKeyPath string `protobuf:"bytes,404,opt,name=ClientKeyPath,proto3" json:"ClientKeyPath,omitempty" yaml:"client-key-path"` - // ClientTrustedCAData contains trusted CA file contents from this member's etcd server. - ClientTrustedCAData string `protobuf:"bytes,405,opt,name=ClientTrustedCAData,proto3" json:"ClientTrustedCAData,omitempty" yaml:"client-trusted-ca-data"` - ClientTrustedCAPath string `protobuf:"bytes,406,opt,name=ClientTrustedCAPath,proto3" json:"ClientTrustedCAPath,omitempty" yaml:"client-trusted-ca-path"` - // PeerCertData contains cert file contents from this member's etcd server. - PeerCertData string `protobuf:"bytes,501,opt,name=PeerCertData,proto3" json:"PeerCertData,omitempty" yaml:"peer-cert-data"` - PeerCertPath string `protobuf:"bytes,502,opt,name=PeerCertPath,proto3" json:"PeerCertPath,omitempty" yaml:"peer-cert-path"` - // PeerKeyData contains key file contents from this member's etcd server. - PeerKeyData string `protobuf:"bytes,503,opt,name=PeerKeyData,proto3" json:"PeerKeyData,omitempty" yaml:"peer-key-data"` - PeerKeyPath string `protobuf:"bytes,504,opt,name=PeerKeyPath,proto3" json:"PeerKeyPath,omitempty" yaml:"peer-key-path"` - // PeerTrustedCAData contains trusted CA file contents from this member's etcd server. - PeerTrustedCAData string `protobuf:"bytes,505,opt,name=PeerTrustedCAData,proto3" json:"PeerTrustedCAData,omitempty" yaml:"peer-trusted-ca-data"` - PeerTrustedCAPath string `protobuf:"bytes,506,opt,name=PeerTrustedCAPath,proto3" json:"PeerTrustedCAPath,omitempty" yaml:"peer-trusted-ca-path"` - // SnapshotPath is the snapshot file path to store or restore from. - SnapshotPath string `protobuf:"bytes,601,opt,name=SnapshotPath,proto3" json:"SnapshotPath,omitempty" yaml:"snapshot-path"` - // SnapshotInfo contains last SAVE_SNAPSHOT request results. - SnapshotInfo *SnapshotInfo `protobuf:"bytes,602,opt,name=SnapshotInfo" json:"SnapshotInfo,omitempty"` -} - -func (m *Member) Reset() { *m = Member{} } -func (m *Member) String() string { return proto.CompactTextString(m) } -func (*Member) ProtoMessage() {} -func (*Member) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{3} } - -type Tester struct { - DataDir string `protobuf:"bytes,1,opt,name=DataDir,proto3" json:"DataDir,omitempty" yaml:"data-dir"` - Network string `protobuf:"bytes,2,opt,name=Network,proto3" json:"Network,omitempty" yaml:"network"` - Addr string `protobuf:"bytes,3,opt,name=Addr,proto3" json:"Addr,omitempty" yaml:"addr"` - // DelayLatencyMsRv is the delay latency in milliseconds, - // to inject to simulated slow network. - DelayLatencyMs uint32 `protobuf:"varint,11,opt,name=DelayLatencyMs,proto3" json:"DelayLatencyMs,omitempty" yaml:"delay-latency-ms"` - // DelayLatencyMsRv is the delay latency random variable in milliseconds. - DelayLatencyMsRv uint32 `protobuf:"varint,12,opt,name=DelayLatencyMsRv,proto3" json:"DelayLatencyMsRv,omitempty" yaml:"delay-latency-ms-rv"` - // UpdatedDelayLatencyMs is the update delay latency in milliseconds, - // to inject to simulated slow network. It's the final latency to apply, - // in case the latency numbers are randomly generated from given delay latency field. - UpdatedDelayLatencyMs uint32 `protobuf:"varint,13,opt,name=UpdatedDelayLatencyMs,proto3" json:"UpdatedDelayLatencyMs,omitempty" yaml:"updated-delay-latency-ms"` - // RoundLimit is the limit of rounds to run failure set (-1 to run without limits). - RoundLimit int32 `protobuf:"varint,21,opt,name=RoundLimit,proto3" json:"RoundLimit,omitempty" yaml:"round-limit"` - // ExitOnCaseFail is true, then exit tester on first failure. - ExitOnCaseFail bool `protobuf:"varint,22,opt,name=ExitOnCaseFail,proto3" json:"ExitOnCaseFail,omitempty" yaml:"exit-on-failure"` - // EnablePprof is true to enable profiler. - EnablePprof bool `protobuf:"varint,23,opt,name=EnablePprof,proto3" json:"EnablePprof,omitempty" yaml:"enable-pprof"` - // CaseDelayMs is the delay duration after failure is injected. - // Useful when triggering snapshot or no-op failure cases. - CaseDelayMs uint32 `protobuf:"varint,31,opt,name=CaseDelayMs,proto3" json:"CaseDelayMs,omitempty" yaml:"case-delay-ms"` - // CaseShuffle is true to randomize failure injecting order. - CaseShuffle bool `protobuf:"varint,32,opt,name=CaseShuffle,proto3" json:"CaseShuffle,omitempty" yaml:"case-shuffle"` - // Cases is the selected test cases to schedule. - // If empty, run all failure cases. - Cases []string `protobuf:"bytes,33,rep,name=Cases" json:"Cases,omitempty" yaml:"cases"` - // FailpointCommands is the list of "gofail" commands - // (e.g. panic("etcd-tester"),1*sleep(1000). - FailpointCommands []string `protobuf:"bytes,34,rep,name=FailpointCommands" json:"FailpointCommands,omitempty" yaml:"failpoint-commands"` - // RunnerExecPath is a path of etcd-runner binary. - RunnerExecPath string `protobuf:"bytes,41,opt,name=RunnerExecPath,proto3" json:"RunnerExecPath,omitempty" yaml:"runner-exec-path"` - // ExternalExecPath is a path of script for enabling/disabling an external fault injector. - ExternalExecPath string `protobuf:"bytes,42,opt,name=ExternalExecPath,proto3" json:"ExternalExecPath,omitempty" yaml:"external-exec-path"` - // Stressers is the list of stresser types: - // KV, LEASE, ELECTION_RUNNER, WATCH_RUNNER, LOCK_RACER_RUNNER, LEASE_RUNNER. - Stressers []string `protobuf:"bytes,101,rep,name=Stressers" json:"Stressers,omitempty" yaml:"stressers"` - // Checkers is the list of consistency checker types: - // KV_HASH, LEASE_EXPIRE, NO_CHECK, RUNNER. - // Leave empty to skip consistency checks. - Checkers []string `protobuf:"bytes,102,rep,name=Checkers" json:"Checkers,omitempty" yaml:"checkers"` - // StressKeySize is the size of each small key written into etcd. - StressKeySize int32 `protobuf:"varint,201,opt,name=StressKeySize,proto3" json:"StressKeySize,omitempty" yaml:"stress-key-size"` - // StressKeySizeLarge is the size of each large key written into etcd. - StressKeySizeLarge int32 `protobuf:"varint,202,opt,name=StressKeySizeLarge,proto3" json:"StressKeySizeLarge,omitempty" yaml:"stress-key-size-large"` - // StressKeySuffixRange is the count of key range written into etcd. - // Stress keys are created with "fmt.Sprintf("foo%016x", rand.Intn(keySuffixRange)". - StressKeySuffixRange int32 `protobuf:"varint,203,opt,name=StressKeySuffixRange,proto3" json:"StressKeySuffixRange,omitempty" yaml:"stress-key-suffix-range"` - // StressKeySuffixRangeTxn is the count of key range written into etcd txn (max 100). - // Stress keys are created with "fmt.Sprintf("/k%03d", i)". - StressKeySuffixRangeTxn int32 `protobuf:"varint,204,opt,name=StressKeySuffixRangeTxn,proto3" json:"StressKeySuffixRangeTxn,omitempty" yaml:"stress-key-suffix-range-txn"` - // StressKeyTxnOps is the number of operations per a transaction (max 64). - StressKeyTxnOps int32 `protobuf:"varint,205,opt,name=StressKeyTxnOps,proto3" json:"StressKeyTxnOps,omitempty" yaml:"stress-key-txn-ops"` - // StressClients is the number of concurrent stressing clients - // with "one" shared TCP connection. - StressClients int32 `protobuf:"varint,301,opt,name=StressClients,proto3" json:"StressClients,omitempty" yaml:"stress-clients"` - // StressQPS is the maximum number of stresser requests per second. - StressQPS int32 `protobuf:"varint,302,opt,name=StressQPS,proto3" json:"StressQPS,omitempty" yaml:"stress-qps"` -} - -func (m *Tester) Reset() { *m = Tester{} } -func (m *Tester) String() string { return proto.CompactTextString(m) } -func (*Tester) ProtoMessage() {} -func (*Tester) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{4} } - -type Etcd struct { - Name string `protobuf:"bytes,1,opt,name=Name,proto3" json:"Name,omitempty" yaml:"name"` - DataDir string `protobuf:"bytes,2,opt,name=DataDir,proto3" json:"DataDir,omitempty" yaml:"data-dir"` - WALDir string `protobuf:"bytes,3,opt,name=WALDir,proto3" json:"WALDir,omitempty" yaml:"wal-dir"` - // HeartbeatIntervalMs is the time (in milliseconds) of a heartbeat interval. - // Default value is 100, which is 100ms. - HeartbeatIntervalMs int64 `protobuf:"varint,11,opt,name=HeartbeatIntervalMs,proto3" json:"HeartbeatIntervalMs,omitempty" yaml:"heartbeat-interval"` - // ElectionTimeoutMs is the time (in milliseconds) for an election to timeout. - // Default value is 1000, which is 1s. - ElectionTimeoutMs int64 `protobuf:"varint,12,opt,name=ElectionTimeoutMs,proto3" json:"ElectionTimeoutMs,omitempty" yaml:"election-timeout"` - ListenClientURLs []string `protobuf:"bytes,21,rep,name=ListenClientURLs" json:"ListenClientURLs,omitempty" yaml:"listen-client-urls"` - AdvertiseClientURLs []string `protobuf:"bytes,22,rep,name=AdvertiseClientURLs" json:"AdvertiseClientURLs,omitempty" yaml:"advertise-client-urls"` - ClientAutoTLS bool `protobuf:"varint,23,opt,name=ClientAutoTLS,proto3" json:"ClientAutoTLS,omitempty" yaml:"auto-tls"` - ClientCertAuth bool `protobuf:"varint,24,opt,name=ClientCertAuth,proto3" json:"ClientCertAuth,omitempty" yaml:"client-cert-auth"` - ClientCertFile string `protobuf:"bytes,25,opt,name=ClientCertFile,proto3" json:"ClientCertFile,omitempty" yaml:"cert-file"` - ClientKeyFile string `protobuf:"bytes,26,opt,name=ClientKeyFile,proto3" json:"ClientKeyFile,omitempty" yaml:"key-file"` - ClientTrustedCAFile string `protobuf:"bytes,27,opt,name=ClientTrustedCAFile,proto3" json:"ClientTrustedCAFile,omitempty" yaml:"trusted-ca-file"` - ListenPeerURLs []string `protobuf:"bytes,31,rep,name=ListenPeerURLs" json:"ListenPeerURLs,omitempty" yaml:"listen-peer-urls"` - AdvertisePeerURLs []string `protobuf:"bytes,32,rep,name=AdvertisePeerURLs" json:"AdvertisePeerURLs,omitempty" yaml:"initial-advertise-peer-urls"` - PeerAutoTLS bool `protobuf:"varint,33,opt,name=PeerAutoTLS,proto3" json:"PeerAutoTLS,omitempty" yaml:"peer-auto-tls"` - PeerClientCertAuth bool `protobuf:"varint,34,opt,name=PeerClientCertAuth,proto3" json:"PeerClientCertAuth,omitempty" yaml:"peer-client-cert-auth"` - PeerCertFile string `protobuf:"bytes,35,opt,name=PeerCertFile,proto3" json:"PeerCertFile,omitempty" yaml:"peer-cert-file"` - PeerKeyFile string `protobuf:"bytes,36,opt,name=PeerKeyFile,proto3" json:"PeerKeyFile,omitempty" yaml:"peer-key-file"` - PeerTrustedCAFile string `protobuf:"bytes,37,opt,name=PeerTrustedCAFile,proto3" json:"PeerTrustedCAFile,omitempty" yaml:"peer-trusted-ca-file"` - InitialCluster string `protobuf:"bytes,41,opt,name=InitialCluster,proto3" json:"InitialCluster,omitempty" yaml:"initial-cluster"` - InitialClusterState string `protobuf:"bytes,42,opt,name=InitialClusterState,proto3" json:"InitialClusterState,omitempty" yaml:"initial-cluster-state"` - InitialClusterToken string `protobuf:"bytes,43,opt,name=InitialClusterToken,proto3" json:"InitialClusterToken,omitempty" yaml:"initial-cluster-token"` - SnapshotCount int64 `protobuf:"varint,51,opt,name=SnapshotCount,proto3" json:"SnapshotCount,omitempty" yaml:"snapshot-count"` - QuotaBackendBytes int64 `protobuf:"varint,52,opt,name=QuotaBackendBytes,proto3" json:"QuotaBackendBytes,omitempty" yaml:"quota-backend-bytes"` - PreVote bool `protobuf:"varint,63,opt,name=PreVote,proto3" json:"PreVote,omitempty" yaml:"pre-vote"` - InitialCorruptCheck bool `protobuf:"varint,64,opt,name=InitialCorruptCheck,proto3" json:"InitialCorruptCheck,omitempty" yaml:"initial-corrupt-check"` -} - -func (m *Etcd) Reset() { *m = Etcd{} } -func (m *Etcd) String() string { return proto.CompactTextString(m) } -func (*Etcd) ProtoMessage() {} -func (*Etcd) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{5} } - -func init() { - proto.RegisterType((*Request)(nil), "rpcpb.Request") - proto.RegisterType((*SnapshotInfo)(nil), "rpcpb.SnapshotInfo") - proto.RegisterType((*Response)(nil), "rpcpb.Response") - proto.RegisterType((*Member)(nil), "rpcpb.Member") - proto.RegisterType((*Tester)(nil), "rpcpb.Tester") - proto.RegisterType((*Etcd)(nil), "rpcpb.Etcd") - proto.RegisterEnum("rpcpb.Operation", Operation_name, Operation_value) - proto.RegisterEnum("rpcpb.Case", Case_name, Case_value) - proto.RegisterEnum("rpcpb.Stresser", Stresser_name, Stresser_value) - proto.RegisterEnum("rpcpb.Checker", Checker_name, Checker_value) -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// Client API for Transport service - -type TransportClient interface { - Transport(ctx context.Context, opts ...grpc.CallOption) (Transport_TransportClient, error) -} - -type transportClient struct { - cc *grpc.ClientConn -} - -func NewTransportClient(cc *grpc.ClientConn) TransportClient { - return &transportClient{cc} -} - -func (c *transportClient) Transport(ctx context.Context, opts ...grpc.CallOption) (Transport_TransportClient, error) { - stream, err := grpc.NewClientStream(ctx, &_Transport_serviceDesc.Streams[0], c.cc, "/rpcpb.Transport/Transport", opts...) - if err != nil { - return nil, err - } - x := &transportTransportClient{stream} - return x, nil -} - -type Transport_TransportClient interface { - Send(*Request) error - Recv() (*Response, error) - grpc.ClientStream -} - -type transportTransportClient struct { - grpc.ClientStream -} - -func (x *transportTransportClient) Send(m *Request) error { - return x.ClientStream.SendMsg(m) -} - -func (x *transportTransportClient) Recv() (*Response, error) { - m := new(Response) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -// Server API for Transport service - -type TransportServer interface { - Transport(Transport_TransportServer) error -} - -func RegisterTransportServer(s *grpc.Server, srv TransportServer) { - s.RegisterService(&_Transport_serviceDesc, srv) -} - -func _Transport_Transport_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(TransportServer).Transport(&transportTransportServer{stream}) -} - -type Transport_TransportServer interface { - Send(*Response) error - Recv() (*Request, error) - grpc.ServerStream -} - -type transportTransportServer struct { - grpc.ServerStream -} - -func (x *transportTransportServer) Send(m *Response) error { - return x.ServerStream.SendMsg(m) -} - -func (x *transportTransportServer) Recv() (*Request, error) { - m := new(Request) - if err := x.ServerStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -var _Transport_serviceDesc = grpc.ServiceDesc{ - ServiceName: "rpcpb.Transport", - HandlerType: (*TransportServer)(nil), - Methods: []grpc.MethodDesc{}, - Streams: []grpc.StreamDesc{ - { - StreamName: "Transport", - Handler: _Transport_Transport_Handler, - ServerStreams: true, - ClientStreams: true, - }, - }, - Metadata: "rpcpb/rpc.proto", -} - -func (m *Request) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Request) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Operation != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Operation)) - } - if m.Member != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Member.Size())) - n1, err := m.Member.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - } - if m.Tester != nil { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Tester.Size())) - n2, err := m.Tester.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - } - return i, nil -} - -func (m *SnapshotInfo) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SnapshotInfo) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.MemberName) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.MemberName))) - i += copy(dAtA[i:], m.MemberName) - } - if len(m.MemberClientURLs) > 0 { - for _, s := range m.MemberClientURLs { - dAtA[i] = 0x12 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if len(m.SnapshotPath) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.SnapshotPath))) - i += copy(dAtA[i:], m.SnapshotPath) - } - if len(m.SnapshotFileSize) > 0 { - dAtA[i] = 0x22 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.SnapshotFileSize))) - i += copy(dAtA[i:], m.SnapshotFileSize) - } - if len(m.SnapshotTotalSize) > 0 { - dAtA[i] = 0x2a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.SnapshotTotalSize))) - i += copy(dAtA[i:], m.SnapshotTotalSize) - } - if m.SnapshotTotalKey != 0 { - dAtA[i] = 0x30 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.SnapshotTotalKey)) - } - if m.SnapshotHash != 0 { - dAtA[i] = 0x38 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.SnapshotHash)) - } - if m.SnapshotRevision != 0 { - dAtA[i] = 0x40 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.SnapshotRevision)) - } - if len(m.Took) > 0 { - dAtA[i] = 0x4a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Took))) - i += copy(dAtA[i:], m.Took) - } - return i, nil -} - -func (m *Response) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Response) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Success { - dAtA[i] = 0x8 - i++ - if m.Success { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if len(m.Status) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Status))) - i += copy(dAtA[i:], m.Status) - } - if m.Member != nil { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Member.Size())) - n3, err := m.Member.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n3 - } - if m.SnapshotInfo != nil { - dAtA[i] = 0x22 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.SnapshotInfo.Size())) - n4, err := m.SnapshotInfo.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n4 - } - return i, nil -} - -func (m *Member) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Member) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.EtcdExecPath) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.EtcdExecPath))) - i += copy(dAtA[i:], m.EtcdExecPath) - } - if len(m.AgentAddr) > 0 { - dAtA[i] = 0x5a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.AgentAddr))) - i += copy(dAtA[i:], m.AgentAddr) - } - if len(m.FailpointHTTPAddr) > 0 { - dAtA[i] = 0x62 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.FailpointHTTPAddr))) - i += copy(dAtA[i:], m.FailpointHTTPAddr) - } - if len(m.BaseDir) > 0 { - dAtA[i] = 0xaa - i++ - dAtA[i] = 0x6 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.BaseDir))) - i += copy(dAtA[i:], m.BaseDir) - } - if len(m.EtcdLogPath) > 0 { - dAtA[i] = 0xb2 - i++ - dAtA[i] = 0x6 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.EtcdLogPath))) - i += copy(dAtA[i:], m.EtcdLogPath) - } - if m.EtcdClientProxy { - dAtA[i] = 0xc8 - i++ - dAtA[i] = 0xc - i++ - if m.EtcdClientProxy { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.EtcdPeerProxy { - dAtA[i] = 0xd0 - i++ - dAtA[i] = 0xc - i++ - if m.EtcdPeerProxy { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if len(m.EtcdClientEndpoint) > 0 { - dAtA[i] = 0xea - i++ - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.EtcdClientEndpoint))) - i += copy(dAtA[i:], m.EtcdClientEndpoint) - } - if m.Etcd != nil { - dAtA[i] = 0xf2 - i++ - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Etcd.Size())) - n5, err := m.Etcd.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n5 - } - if m.EtcdOnSnapshotRestore != nil { - dAtA[i] = 0xfa - i++ - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.EtcdOnSnapshotRestore.Size())) - n6, err := m.EtcdOnSnapshotRestore.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n6 - } - if len(m.ClientCertData) > 0 { - dAtA[i] = 0x8a - i++ - dAtA[i] = 0x19 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ClientCertData))) - i += copy(dAtA[i:], m.ClientCertData) - } - if len(m.ClientCertPath) > 0 { - dAtA[i] = 0x92 - i++ - dAtA[i] = 0x19 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ClientCertPath))) - i += copy(dAtA[i:], m.ClientCertPath) - } - if len(m.ClientKeyData) > 0 { - dAtA[i] = 0x9a - i++ - dAtA[i] = 0x19 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ClientKeyData))) - i += copy(dAtA[i:], m.ClientKeyData) - } - if len(m.ClientKeyPath) > 0 { - dAtA[i] = 0xa2 - i++ - dAtA[i] = 0x19 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ClientKeyPath))) - i += copy(dAtA[i:], m.ClientKeyPath) - } - if len(m.ClientTrustedCAData) > 0 { - dAtA[i] = 0xaa - i++ - dAtA[i] = 0x19 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ClientTrustedCAData))) - i += copy(dAtA[i:], m.ClientTrustedCAData) - } - if len(m.ClientTrustedCAPath) > 0 { - dAtA[i] = 0xb2 - i++ - dAtA[i] = 0x19 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ClientTrustedCAPath))) - i += copy(dAtA[i:], m.ClientTrustedCAPath) - } - if len(m.PeerCertData) > 0 { - dAtA[i] = 0xaa - i++ - dAtA[i] = 0x1f - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.PeerCertData))) - i += copy(dAtA[i:], m.PeerCertData) - } - if len(m.PeerCertPath) > 0 { - dAtA[i] = 0xb2 - i++ - dAtA[i] = 0x1f - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.PeerCertPath))) - i += copy(dAtA[i:], m.PeerCertPath) - } - if len(m.PeerKeyData) > 0 { - dAtA[i] = 0xba - i++ - dAtA[i] = 0x1f - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.PeerKeyData))) - i += copy(dAtA[i:], m.PeerKeyData) - } - if len(m.PeerKeyPath) > 0 { - dAtA[i] = 0xc2 - i++ - dAtA[i] = 0x1f - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.PeerKeyPath))) - i += copy(dAtA[i:], m.PeerKeyPath) - } - if len(m.PeerTrustedCAData) > 0 { - dAtA[i] = 0xca - i++ - dAtA[i] = 0x1f - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.PeerTrustedCAData))) - i += copy(dAtA[i:], m.PeerTrustedCAData) - } - if len(m.PeerTrustedCAPath) > 0 { - dAtA[i] = 0xd2 - i++ - dAtA[i] = 0x1f - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.PeerTrustedCAPath))) - i += copy(dAtA[i:], m.PeerTrustedCAPath) - } - if len(m.SnapshotPath) > 0 { - dAtA[i] = 0xca - i++ - dAtA[i] = 0x25 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.SnapshotPath))) - i += copy(dAtA[i:], m.SnapshotPath) - } - if m.SnapshotInfo != nil { - dAtA[i] = 0xd2 - i++ - dAtA[i] = 0x25 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.SnapshotInfo.Size())) - n7, err := m.SnapshotInfo.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n7 - } - return i, nil -} - -func (m *Tester) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Tester) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.DataDir) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.DataDir))) - i += copy(dAtA[i:], m.DataDir) - } - if len(m.Network) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Network))) - i += copy(dAtA[i:], m.Network) - } - if len(m.Addr) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Addr))) - i += copy(dAtA[i:], m.Addr) - } - if m.DelayLatencyMs != 0 { - dAtA[i] = 0x58 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.DelayLatencyMs)) - } - if m.DelayLatencyMsRv != 0 { - dAtA[i] = 0x60 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.DelayLatencyMsRv)) - } - if m.UpdatedDelayLatencyMs != 0 { - dAtA[i] = 0x68 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.UpdatedDelayLatencyMs)) - } - if m.RoundLimit != 0 { - dAtA[i] = 0xa8 - i++ - dAtA[i] = 0x1 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.RoundLimit)) - } - if m.ExitOnCaseFail { - dAtA[i] = 0xb0 - i++ - dAtA[i] = 0x1 - i++ - if m.ExitOnCaseFail { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.EnablePprof { - dAtA[i] = 0xb8 - i++ - dAtA[i] = 0x1 - i++ - if m.EnablePprof { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.CaseDelayMs != 0 { - dAtA[i] = 0xf8 - i++ - dAtA[i] = 0x1 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.CaseDelayMs)) - } - if m.CaseShuffle { - dAtA[i] = 0x80 - i++ - dAtA[i] = 0x2 - i++ - if m.CaseShuffle { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if len(m.Cases) > 0 { - for _, s := range m.Cases { - dAtA[i] = 0x8a - i++ - dAtA[i] = 0x2 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if len(m.FailpointCommands) > 0 { - for _, s := range m.FailpointCommands { - dAtA[i] = 0x92 - i++ - dAtA[i] = 0x2 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if len(m.RunnerExecPath) > 0 { - dAtA[i] = 0xca - i++ - dAtA[i] = 0x2 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.RunnerExecPath))) - i += copy(dAtA[i:], m.RunnerExecPath) - } - if len(m.ExternalExecPath) > 0 { - dAtA[i] = 0xd2 - i++ - dAtA[i] = 0x2 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ExternalExecPath))) - i += copy(dAtA[i:], m.ExternalExecPath) - } - if len(m.Stressers) > 0 { - for _, s := range m.Stressers { - dAtA[i] = 0xaa - i++ - dAtA[i] = 0x6 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if len(m.Checkers) > 0 { - for _, s := range m.Checkers { - dAtA[i] = 0xb2 - i++ - dAtA[i] = 0x6 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if m.StressKeySize != 0 { - dAtA[i] = 0xc8 - i++ - dAtA[i] = 0xc - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.StressKeySize)) - } - if m.StressKeySizeLarge != 0 { - dAtA[i] = 0xd0 - i++ - dAtA[i] = 0xc - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.StressKeySizeLarge)) - } - if m.StressKeySuffixRange != 0 { - dAtA[i] = 0xd8 - i++ - dAtA[i] = 0xc - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.StressKeySuffixRange)) - } - if m.StressKeySuffixRangeTxn != 0 { - dAtA[i] = 0xe0 - i++ - dAtA[i] = 0xc - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.StressKeySuffixRangeTxn)) - } - if m.StressKeyTxnOps != 0 { - dAtA[i] = 0xe8 - i++ - dAtA[i] = 0xc - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.StressKeyTxnOps)) - } - if m.StressClients != 0 { - dAtA[i] = 0xe8 - i++ - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.StressClients)) - } - if m.StressQPS != 0 { - dAtA[i] = 0xf0 - i++ - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.StressQPS)) - } - return i, nil -} - -func (m *Etcd) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Etcd) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.DataDir) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.DataDir))) - i += copy(dAtA[i:], m.DataDir) - } - if len(m.WALDir) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.WALDir))) - i += copy(dAtA[i:], m.WALDir) - } - if m.HeartbeatIntervalMs != 0 { - dAtA[i] = 0x58 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.HeartbeatIntervalMs)) - } - if m.ElectionTimeoutMs != 0 { - dAtA[i] = 0x60 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ElectionTimeoutMs)) - } - if len(m.ListenClientURLs) > 0 { - for _, s := range m.ListenClientURLs { - dAtA[i] = 0xaa - i++ - dAtA[i] = 0x1 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if len(m.AdvertiseClientURLs) > 0 { - for _, s := range m.AdvertiseClientURLs { - dAtA[i] = 0xb2 - i++ - dAtA[i] = 0x1 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if m.ClientAutoTLS { - dAtA[i] = 0xb8 - i++ - dAtA[i] = 0x1 - i++ - if m.ClientAutoTLS { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.ClientCertAuth { - dAtA[i] = 0xc0 - i++ - dAtA[i] = 0x1 - i++ - if m.ClientCertAuth { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if len(m.ClientCertFile) > 0 { - dAtA[i] = 0xca - i++ - dAtA[i] = 0x1 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ClientCertFile))) - i += copy(dAtA[i:], m.ClientCertFile) - } - if len(m.ClientKeyFile) > 0 { - dAtA[i] = 0xd2 - i++ - dAtA[i] = 0x1 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ClientKeyFile))) - i += copy(dAtA[i:], m.ClientKeyFile) - } - if len(m.ClientTrustedCAFile) > 0 { - dAtA[i] = 0xda - i++ - dAtA[i] = 0x1 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ClientTrustedCAFile))) - i += copy(dAtA[i:], m.ClientTrustedCAFile) - } - if len(m.ListenPeerURLs) > 0 { - for _, s := range m.ListenPeerURLs { - dAtA[i] = 0xfa - i++ - dAtA[i] = 0x1 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if len(m.AdvertisePeerURLs) > 0 { - for _, s := range m.AdvertisePeerURLs { - dAtA[i] = 0x82 - i++ - dAtA[i] = 0x2 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if m.PeerAutoTLS { - dAtA[i] = 0x88 - i++ - dAtA[i] = 0x2 - i++ - if m.PeerAutoTLS { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.PeerClientCertAuth { - dAtA[i] = 0x90 - i++ - dAtA[i] = 0x2 - i++ - if m.PeerClientCertAuth { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if len(m.PeerCertFile) > 0 { - dAtA[i] = 0x9a - i++ - dAtA[i] = 0x2 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.PeerCertFile))) - i += copy(dAtA[i:], m.PeerCertFile) - } - if len(m.PeerKeyFile) > 0 { - dAtA[i] = 0xa2 - i++ - dAtA[i] = 0x2 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.PeerKeyFile))) - i += copy(dAtA[i:], m.PeerKeyFile) - } - if len(m.PeerTrustedCAFile) > 0 { - dAtA[i] = 0xaa - i++ - dAtA[i] = 0x2 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.PeerTrustedCAFile))) - i += copy(dAtA[i:], m.PeerTrustedCAFile) - } - if len(m.InitialCluster) > 0 { - dAtA[i] = 0xca - i++ - dAtA[i] = 0x2 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.InitialCluster))) - i += copy(dAtA[i:], m.InitialCluster) - } - if len(m.InitialClusterState) > 0 { - dAtA[i] = 0xd2 - i++ - dAtA[i] = 0x2 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.InitialClusterState))) - i += copy(dAtA[i:], m.InitialClusterState) - } - if len(m.InitialClusterToken) > 0 { - dAtA[i] = 0xda - i++ - dAtA[i] = 0x2 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.InitialClusterToken))) - i += copy(dAtA[i:], m.InitialClusterToken) - } - if m.SnapshotCount != 0 { - dAtA[i] = 0x98 - i++ - dAtA[i] = 0x3 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.SnapshotCount)) - } - if m.QuotaBackendBytes != 0 { - dAtA[i] = 0xa0 - i++ - dAtA[i] = 0x3 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.QuotaBackendBytes)) - } - if m.PreVote { - dAtA[i] = 0xf8 - i++ - dAtA[i] = 0x3 - i++ - if m.PreVote { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.InitialCorruptCheck { - dAtA[i] = 0x80 - i++ - dAtA[i] = 0x4 - i++ - if m.InitialCorruptCheck { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - return i, nil -} - -func encodeVarintRpc(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *Request) Size() (n int) { - var l int - _ = l - if m.Operation != 0 { - n += 1 + sovRpc(uint64(m.Operation)) - } - if m.Member != nil { - l = m.Member.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.Tester != nil { - l = m.Tester.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *SnapshotInfo) Size() (n int) { - var l int - _ = l - l = len(m.MemberName) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.MemberClientURLs) > 0 { - for _, s := range m.MemberClientURLs { - l = len(s) - n += 1 + l + sovRpc(uint64(l)) - } - } - l = len(m.SnapshotPath) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.SnapshotFileSize) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.SnapshotTotalSize) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.SnapshotTotalKey != 0 { - n += 1 + sovRpc(uint64(m.SnapshotTotalKey)) - } - if m.SnapshotHash != 0 { - n += 1 + sovRpc(uint64(m.SnapshotHash)) - } - if m.SnapshotRevision != 0 { - n += 1 + sovRpc(uint64(m.SnapshotRevision)) - } - l = len(m.Took) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *Response) Size() (n int) { - var l int - _ = l - if m.Success { - n += 2 - } - l = len(m.Status) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.Member != nil { - l = m.Member.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.SnapshotInfo != nil { - l = m.SnapshotInfo.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *Member) Size() (n int) { - var l int - _ = l - l = len(m.EtcdExecPath) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.AgentAddr) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.FailpointHTTPAddr) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.BaseDir) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.EtcdLogPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - if m.EtcdClientProxy { - n += 3 - } - if m.EtcdPeerProxy { - n += 3 - } - l = len(m.EtcdClientEndpoint) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - if m.Etcd != nil { - l = m.Etcd.Size() - n += 2 + l + sovRpc(uint64(l)) - } - if m.EtcdOnSnapshotRestore != nil { - l = m.EtcdOnSnapshotRestore.Size() - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.ClientCertData) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.ClientCertPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.ClientKeyData) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.ClientKeyPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.ClientTrustedCAData) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.ClientTrustedCAPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.PeerCertData) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.PeerCertPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.PeerKeyData) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.PeerKeyPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.PeerTrustedCAData) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.PeerTrustedCAPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.SnapshotPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - if m.SnapshotInfo != nil { - l = m.SnapshotInfo.Size() - n += 2 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *Tester) Size() (n int) { - var l int - _ = l - l = len(m.DataDir) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Network) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Addr) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.DelayLatencyMs != 0 { - n += 1 + sovRpc(uint64(m.DelayLatencyMs)) - } - if m.DelayLatencyMsRv != 0 { - n += 1 + sovRpc(uint64(m.DelayLatencyMsRv)) - } - if m.UpdatedDelayLatencyMs != 0 { - n += 1 + sovRpc(uint64(m.UpdatedDelayLatencyMs)) - } - if m.RoundLimit != 0 { - n += 2 + sovRpc(uint64(m.RoundLimit)) - } - if m.ExitOnCaseFail { - n += 3 - } - if m.EnablePprof { - n += 3 - } - if m.CaseDelayMs != 0 { - n += 2 + sovRpc(uint64(m.CaseDelayMs)) - } - if m.CaseShuffle { - n += 3 - } - if len(m.Cases) > 0 { - for _, s := range m.Cases { - l = len(s) - n += 2 + l + sovRpc(uint64(l)) - } - } - if len(m.FailpointCommands) > 0 { - for _, s := range m.FailpointCommands { - l = len(s) - n += 2 + l + sovRpc(uint64(l)) - } - } - l = len(m.RunnerExecPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.ExternalExecPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - if len(m.Stressers) > 0 { - for _, s := range m.Stressers { - l = len(s) - n += 2 + l + sovRpc(uint64(l)) - } - } - if len(m.Checkers) > 0 { - for _, s := range m.Checkers { - l = len(s) - n += 2 + l + sovRpc(uint64(l)) - } - } - if m.StressKeySize != 0 { - n += 2 + sovRpc(uint64(m.StressKeySize)) - } - if m.StressKeySizeLarge != 0 { - n += 2 + sovRpc(uint64(m.StressKeySizeLarge)) - } - if m.StressKeySuffixRange != 0 { - n += 2 + sovRpc(uint64(m.StressKeySuffixRange)) - } - if m.StressKeySuffixRangeTxn != 0 { - n += 2 + sovRpc(uint64(m.StressKeySuffixRangeTxn)) - } - if m.StressKeyTxnOps != 0 { - n += 2 + sovRpc(uint64(m.StressKeyTxnOps)) - } - if m.StressClients != 0 { - n += 2 + sovRpc(uint64(m.StressClients)) - } - if m.StressQPS != 0 { - n += 2 + sovRpc(uint64(m.StressQPS)) - } - return n -} - -func (m *Etcd) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.DataDir) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.WALDir) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.HeartbeatIntervalMs != 0 { - n += 1 + sovRpc(uint64(m.HeartbeatIntervalMs)) - } - if m.ElectionTimeoutMs != 0 { - n += 1 + sovRpc(uint64(m.ElectionTimeoutMs)) - } - if len(m.ListenClientURLs) > 0 { - for _, s := range m.ListenClientURLs { - l = len(s) - n += 2 + l + sovRpc(uint64(l)) - } - } - if len(m.AdvertiseClientURLs) > 0 { - for _, s := range m.AdvertiseClientURLs { - l = len(s) - n += 2 + l + sovRpc(uint64(l)) - } - } - if m.ClientAutoTLS { - n += 3 - } - if m.ClientCertAuth { - n += 3 - } - l = len(m.ClientCertFile) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.ClientKeyFile) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.ClientTrustedCAFile) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - if len(m.ListenPeerURLs) > 0 { - for _, s := range m.ListenPeerURLs { - l = len(s) - n += 2 + l + sovRpc(uint64(l)) - } - } - if len(m.AdvertisePeerURLs) > 0 { - for _, s := range m.AdvertisePeerURLs { - l = len(s) - n += 2 + l + sovRpc(uint64(l)) - } - } - if m.PeerAutoTLS { - n += 3 - } - if m.PeerClientCertAuth { - n += 3 - } - l = len(m.PeerCertFile) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.PeerKeyFile) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.PeerTrustedCAFile) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.InitialCluster) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.InitialClusterState) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.InitialClusterToken) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - if m.SnapshotCount != 0 { - n += 2 + sovRpc(uint64(m.SnapshotCount)) - } - if m.QuotaBackendBytes != 0 { - n += 2 + sovRpc(uint64(m.QuotaBackendBytes)) - } - if m.PreVote { - n += 3 - } - if m.InitialCorruptCheck { - n += 3 - } - return n -} - -func sovRpc(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozRpc(x uint64) (n int) { - return sovRpc(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Request) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Request: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Request: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Operation", wireType) - } - m.Operation = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Operation |= (Operation(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Member", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Member == nil { - m.Member = &Member{} - } - if err := m.Member.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Tester", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Tester == nil { - m.Tester = &Tester{} - } - if err := m.Tester.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *SnapshotInfo) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SnapshotInfo: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SnapshotInfo: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MemberName", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.MemberName = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MemberClientURLs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.MemberClientURLs = append(m.MemberClientURLs, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SnapshotPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotFileSize", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SnapshotFileSize = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotTotalSize", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SnapshotTotalSize = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotTotalKey", wireType) - } - m.SnapshotTotalKey = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.SnapshotTotalKey |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 7: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotHash", wireType) - } - m.SnapshotHash = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.SnapshotHash |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotRevision", wireType) - } - m.SnapshotRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.SnapshotRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 9: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Took", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Took = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Response) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Response: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Response: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Success", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Success = bool(v != 0) - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Status", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Status = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Member", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Member == nil { - m.Member = &Member{} - } - if err := m.Member.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotInfo", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.SnapshotInfo == nil { - m.SnapshotInfo = &SnapshotInfo{} - } - if err := m.SnapshotInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Member) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Member: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Member: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EtcdExecPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.EtcdExecPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 11: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AgentAddr", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.AgentAddr = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 12: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field FailpointHTTPAddr", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.FailpointHTTPAddr = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 101: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BaseDir", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.BaseDir = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 102: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EtcdLogPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.EtcdLogPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 201: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field EtcdClientProxy", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.EtcdClientProxy = bool(v != 0) - case 202: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field EtcdPeerProxy", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.EtcdPeerProxy = bool(v != 0) - case 301: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EtcdClientEndpoint", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.EtcdClientEndpoint = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 302: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Etcd", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Etcd == nil { - m.Etcd = &Etcd{} - } - if err := m.Etcd.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 303: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EtcdOnSnapshotRestore", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.EtcdOnSnapshotRestore == nil { - m.EtcdOnSnapshotRestore = &Etcd{} - } - if err := m.EtcdOnSnapshotRestore.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 401: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientCertData", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientCertData = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 402: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientCertPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientCertPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 403: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientKeyData", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientKeyData = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 404: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientKeyPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientKeyPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 405: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientTrustedCAData", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientTrustedCAData = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 406: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientTrustedCAPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientTrustedCAPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 501: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerCertData", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerCertData = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 502: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerCertPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerCertPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 503: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerKeyData", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerKeyData = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 504: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerKeyPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerKeyPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 505: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerTrustedCAData", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerTrustedCAData = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 506: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerTrustedCAPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerTrustedCAPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 601: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SnapshotPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 602: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotInfo", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.SnapshotInfo == nil { - m.SnapshotInfo = &SnapshotInfo{} - } - if err := m.SnapshotInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Tester) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Tester: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Tester: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field DataDir", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.DataDir = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Network", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Network = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Addr", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Addr = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 11: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field DelayLatencyMs", wireType) - } - m.DelayLatencyMs = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.DelayLatencyMs |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 12: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field DelayLatencyMsRv", wireType) - } - m.DelayLatencyMsRv = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.DelayLatencyMsRv |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 13: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field UpdatedDelayLatencyMs", wireType) - } - m.UpdatedDelayLatencyMs = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.UpdatedDelayLatencyMs |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 21: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RoundLimit", wireType) - } - m.RoundLimit = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RoundLimit |= (int32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 22: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ExitOnCaseFail", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.ExitOnCaseFail = bool(v != 0) - case 23: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field EnablePprof", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.EnablePprof = bool(v != 0) - case 31: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CaseDelayMs", wireType) - } - m.CaseDelayMs = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.CaseDelayMs |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 32: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CaseShuffle", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.CaseShuffle = bool(v != 0) - case 33: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Cases", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Cases = append(m.Cases, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 34: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field FailpointCommands", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.FailpointCommands = append(m.FailpointCommands, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 41: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RunnerExecPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RunnerExecPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 42: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ExternalExecPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ExternalExecPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 101: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Stressers", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Stressers = append(m.Stressers, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 102: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Checkers", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Checkers = append(m.Checkers, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 201: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StressKeySize", wireType) - } - m.StressKeySize = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StressKeySize |= (int32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 202: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StressKeySizeLarge", wireType) - } - m.StressKeySizeLarge = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StressKeySizeLarge |= (int32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 203: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StressKeySuffixRange", wireType) - } - m.StressKeySuffixRange = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StressKeySuffixRange |= (int32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 204: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StressKeySuffixRangeTxn", wireType) - } - m.StressKeySuffixRangeTxn = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StressKeySuffixRangeTxn |= (int32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 205: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StressKeyTxnOps", wireType) - } - m.StressKeyTxnOps = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StressKeyTxnOps |= (int32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 301: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StressClients", wireType) - } - m.StressClients = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StressClients |= (int32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 302: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StressQPS", wireType) - } - m.StressQPS = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StressQPS |= (int32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Etcd) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Etcd: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Etcd: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field DataDir", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.DataDir = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field WALDir", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.WALDir = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 11: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field HeartbeatIntervalMs", wireType) - } - m.HeartbeatIntervalMs = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.HeartbeatIntervalMs |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 12: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ElectionTimeoutMs", wireType) - } - m.ElectionTimeoutMs = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ElectionTimeoutMs |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 21: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ListenClientURLs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ListenClientURLs = append(m.ListenClientURLs, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 22: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AdvertiseClientURLs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.AdvertiseClientURLs = append(m.AdvertiseClientURLs, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 23: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientAutoTLS", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.ClientAutoTLS = bool(v != 0) - case 24: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientCertAuth", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.ClientCertAuth = bool(v != 0) - case 25: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientCertFile", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientCertFile = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 26: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientKeyFile", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientKeyFile = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 27: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientTrustedCAFile", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientTrustedCAFile = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 31: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ListenPeerURLs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ListenPeerURLs = append(m.ListenPeerURLs, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 32: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AdvertisePeerURLs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.AdvertisePeerURLs = append(m.AdvertisePeerURLs, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 33: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerAutoTLS", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.PeerAutoTLS = bool(v != 0) - case 34: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerClientCertAuth", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.PeerClientCertAuth = bool(v != 0) - case 35: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerCertFile", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerCertFile = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 36: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerKeyFile", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerKeyFile = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 37: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerTrustedCAFile", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerTrustedCAFile = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 41: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field InitialCluster", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.InitialCluster = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 42: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field InitialClusterState", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.InitialClusterState = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 43: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field InitialClusterToken", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.InitialClusterToken = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 51: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotCount", wireType) - } - m.SnapshotCount = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.SnapshotCount |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 52: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field QuotaBackendBytes", wireType) - } - m.QuotaBackendBytes = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.QuotaBackendBytes |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 63: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PreVote", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.PreVote = bool(v != 0) - case 64: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field InitialCorruptCheck", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.InitialCorruptCheck = bool(v != 0) - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipRpc(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthRpc - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipRpc(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthRpc = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowRpc = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("rpcpb/rpc.proto", fileDescriptorRpc) } - -var fileDescriptorRpc = []byte{ - // 2808 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x59, 0xdb, 0x73, 0xdb, 0xc6, - 0xf5, 0x16, 0x44, 0x5d, 0x57, 0x37, 0x68, 0x65, 0xd9, 0xf0, 0x4d, 0x90, 0xe1, 0x38, 0x3f, 0x59, - 0x09, 0xec, 0xfc, 0xec, 0x4c, 0x2e, 0x4e, 0x13, 0x07, 0xa4, 0x20, 0x8b, 0x15, 0x44, 0xd2, 0x4b, - 0xc8, 0x76, 0x9e, 0x38, 0x10, 0xb9, 0x92, 0x30, 0xa6, 0x00, 0x06, 0x58, 0x2a, 0x52, 0xfe, 0x81, - 0xbe, 0xf6, 0x3e, 0xed, 0x4c, 0x9f, 0xfa, 0xdc, 0xb4, 0xff, 0x86, 0x73, 0x6b, 0xd3, 0xf6, 0xa9, - 0xed, 0x0c, 0xa7, 0x4d, 0x5f, 0xfa, 0xd4, 0x07, 0x4e, 0x6f, 0xe9, 0x53, 0x67, 0x77, 0x01, 0x71, - 0x01, 0x90, 0x92, 0x9e, 0xa4, 0x3d, 0xe7, 0xfb, 0xbe, 0x3d, 0xbb, 0x67, 0xb1, 0xe7, 0x00, 0x04, - 0x73, 0x41, 0xab, 0xde, 0xda, 0xb9, 0x1b, 0xb4, 0xea, 0x77, 0x5a, 0x81, 0x4f, 0x7c, 0x38, 0xca, - 0x0c, 0x57, 0xf4, 0x3d, 0x97, 0xec, 0xb7, 0x77, 0xee, 0xd4, 0xfd, 0x83, 0xbb, 0x7b, 0xfe, 0x9e, - 0x7f, 0x97, 0x79, 0x77, 0xda, 0xbb, 0x6c, 0xc4, 0x06, 0xec, 0x3f, 0xce, 0xd2, 0xbe, 0x23, 0x81, - 0x71, 0x84, 0x3f, 0x6c, 0xe3, 0x90, 0xc0, 0x3b, 0x60, 0xb2, 0xdc, 0xc2, 0x81, 0x43, 0x5c, 0xdf, - 0x53, 0xa4, 0x65, 0x69, 0x65, 0xf6, 0x9e, 0x7c, 0x87, 0xa9, 0xde, 0x39, 0xb1, 0xa3, 0x1e, 0x04, - 0xde, 0x02, 0x63, 0x5b, 0xf8, 0x60, 0x07, 0x07, 0xca, 0xf0, 0xb2, 0xb4, 0x32, 0x75, 0x6f, 0x26, - 0x02, 0x73, 0x23, 0x8a, 0x9c, 0x14, 0x66, 0xe3, 0x90, 0xe0, 0x40, 0xc9, 0x25, 0x60, 0xdc, 0x88, - 0x22, 0xa7, 0xf6, 0xb7, 0x61, 0x30, 0x5d, 0xf5, 0x9c, 0x56, 0xb8, 0xef, 0x93, 0xa2, 0xb7, 0xeb, - 0xc3, 0x25, 0x00, 0xb8, 0x42, 0xc9, 0x39, 0xc0, 0x2c, 0x9e, 0x49, 0x24, 0x58, 0xe0, 0x2a, 0x90, - 0xf9, 0xa8, 0xd0, 0x74, 0xb1, 0x47, 0xb6, 0x91, 0x15, 0x2a, 0xc3, 0xcb, 0xb9, 0x95, 0x49, 0x94, - 0xb1, 0x43, 0xad, 0xa7, 0x5d, 0x71, 0xc8, 0x3e, 0x8b, 0x64, 0x12, 0x25, 0x6c, 0x54, 0x2f, 0x1e, - 0xaf, 0xbb, 0x4d, 0x5c, 0x75, 0x3f, 0xc6, 0xca, 0x08, 0xc3, 0x65, 0xec, 0xf0, 0x55, 0x30, 0x1f, - 0xdb, 0x6c, 0x9f, 0x38, 0x4d, 0x06, 0x1e, 0x65, 0xe0, 0xac, 0x43, 0x54, 0x66, 0xc6, 0x4d, 0x7c, - 0xac, 0x8c, 0x2d, 0x4b, 0x2b, 0x39, 0x94, 0xb1, 0x8b, 0x91, 0x6e, 0x38, 0xe1, 0xbe, 0x32, 0xce, - 0x70, 0x09, 0x9b, 0xa8, 0x87, 0xf0, 0xa1, 0x1b, 0xd2, 0x7c, 0x4d, 0x24, 0xf5, 0x62, 0x3b, 0x84, - 0x60, 0xc4, 0xf6, 0xfd, 0xe7, 0xca, 0x24, 0x0b, 0x8e, 0xfd, 0xaf, 0xfd, 0x4c, 0x02, 0x13, 0x08, - 0x87, 0x2d, 0xdf, 0x0b, 0x31, 0x54, 0xc0, 0x78, 0xb5, 0x5d, 0xaf, 0xe3, 0x30, 0x64, 0x7b, 0x3c, - 0x81, 0xe2, 0x21, 0xbc, 0x08, 0xc6, 0xaa, 0xc4, 0x21, 0xed, 0x90, 0xe5, 0x77, 0x12, 0x45, 0x23, - 0x21, 0xef, 0xb9, 0xd3, 0xf2, 0xfe, 0x66, 0x32, 0x9f, 0x6c, 0x2f, 0xa7, 0xee, 0x2d, 0x44, 0x60, - 0xd1, 0x85, 0x12, 0x40, 0xed, 0x4f, 0xd3, 0xf1, 0x04, 0xf0, 0x5d, 0x30, 0x6d, 0x92, 0x7a, 0xc3, - 0x3c, 0xc2, 0x75, 0x96, 0x37, 0x76, 0x0a, 0xf2, 0x97, 0xbb, 0x1d, 0x75, 0xf1, 0xd8, 0x39, 0x68, - 0x3e, 0xd0, 0x30, 0xa9, 0x37, 0x74, 0x7c, 0x84, 0xeb, 0x7a, 0xcb, 0x21, 0xfb, 0x1a, 0x4a, 0xc0, - 0xe1, 0x7d, 0x30, 0x69, 0xec, 0x61, 0x8f, 0x18, 0x8d, 0x46, 0xa0, 0x4c, 0x31, 0xee, 0x62, 0xb7, - 0xa3, 0xce, 0x73, 0xae, 0x43, 0x5d, 0xba, 0xd3, 0x68, 0x04, 0x1a, 0xea, 0xe1, 0xa0, 0x05, 0xe6, - 0xd7, 0x1d, 0xb7, 0xd9, 0xf2, 0x5d, 0x8f, 0x6c, 0xd8, 0x76, 0x85, 0x91, 0xa7, 0x19, 0x79, 0xa9, - 0xdb, 0x51, 0xaf, 0x70, 0xf2, 0x6e, 0x0c, 0xd1, 0xf7, 0x09, 0x69, 0x45, 0x2a, 0x59, 0x22, 0xd4, - 0xc1, 0x78, 0xde, 0x09, 0xf1, 0x9a, 0x1b, 0x28, 0x98, 0x69, 0x2c, 0x74, 0x3b, 0xea, 0x1c, 0xd7, - 0xd8, 0x71, 0x42, 0xac, 0x37, 0xdc, 0x40, 0x43, 0x31, 0x06, 0x3e, 0x00, 0x53, 0x74, 0x05, 0x96, - 0xbf, 0xc7, 0xd6, 0xbb, 0xcb, 0x28, 0x4a, 0xb7, 0xa3, 0x5e, 0x10, 0xd6, 0xdb, 0xf4, 0xf7, 0xa2, - 0xe5, 0x8a, 0x60, 0xf8, 0x08, 0xcc, 0xd1, 0x21, 0x3f, 0xf6, 0x95, 0xc0, 0x3f, 0x3a, 0x56, 0x3e, - 0x65, 0x29, 0xcd, 0x5f, 0xeb, 0x76, 0x54, 0x45, 0x10, 0xa8, 0x33, 0x88, 0xde, 0xa2, 0x18, 0x0d, - 0xa5, 0x59, 0xd0, 0x00, 0x33, 0xd4, 0x54, 0xc1, 0x38, 0xe0, 0x32, 0x9f, 0x71, 0x99, 0x2b, 0xdd, - 0x8e, 0x7a, 0x51, 0x90, 0x69, 0x61, 0x1c, 0xc4, 0x22, 0x49, 0x06, 0xac, 0x00, 0xd8, 0x53, 0x35, - 0xbd, 0x06, 0xdb, 0x14, 0xe5, 0x13, 0x76, 0x90, 0xf2, 0x6a, 0xb7, 0xa3, 0x5e, 0xcd, 0x86, 0x83, - 0x23, 0x98, 0x86, 0xfa, 0x70, 0xe1, 0xff, 0x83, 0x11, 0x6a, 0x55, 0x7e, 0xc9, 0x2f, 0x9b, 0xa9, - 0xe8, 0x1c, 0x51, 0x5b, 0x7e, 0xae, 0xdb, 0x51, 0xa7, 0x7a, 0x82, 0x1a, 0x62, 0x50, 0x98, 0x07, - 0x8b, 0xf4, 0x6f, 0xd9, 0xeb, 0x3d, 0x15, 0x21, 0xf1, 0x03, 0xac, 0xfc, 0x2a, 0xab, 0x81, 0xfa, - 0x43, 0xe1, 0x1a, 0x98, 0xe5, 0x81, 0x14, 0x70, 0x40, 0xd6, 0x1c, 0xe2, 0x28, 0xdf, 0x63, 0x97, - 0x47, 0xfe, 0x6a, 0xb7, 0xa3, 0x5e, 0xe2, 0x73, 0x46, 0xf1, 0xd7, 0x71, 0x40, 0xf4, 0x86, 0x43, - 0x1c, 0x0d, 0xa5, 0x38, 0x49, 0x15, 0x96, 0xd9, 0xef, 0x9f, 0xaa, 0xc2, 0xb3, 0x9b, 0xe2, 0xd0, - 0xbc, 0x70, 0xcb, 0x26, 0x3e, 0x66, 0xa1, 0xfc, 0x80, 0x8b, 0x08, 0x79, 0x89, 0x44, 0x9e, 0xe3, - 0xe3, 0x28, 0x92, 0x24, 0x23, 0x21, 0xc1, 0xe2, 0xf8, 0xe1, 0x69, 0x12, 0x3c, 0x8c, 0x24, 0x03, - 0xda, 0x60, 0x81, 0x1b, 0xec, 0xa0, 0x1d, 0x12, 0xdc, 0x28, 0x18, 0x2c, 0x96, 0x1f, 0x71, 0xa1, - 0x1b, 0xdd, 0x8e, 0x7a, 0x3d, 0x21, 0x44, 0x38, 0x4c, 0xaf, 0x3b, 0x51, 0x48, 0xfd, 0xe8, 0x7d, - 0x54, 0x59, 0x78, 0x3f, 0x3e, 0x87, 0x2a, 0x8f, 0xb2, 0x1f, 0x1d, 0xbe, 0x07, 0xa6, 0xe9, 0x99, - 0x3c, 0xc9, 0xdd, 0x3f, 0x73, 0xe9, 0x0b, 0x84, 0x9d, 0x61, 0x21, 0x73, 0x09, 0xbc, 0xc8, 0x67, - 0xe1, 0xfc, 0xeb, 0x14, 0x7e, 0x74, 0x01, 0x89, 0x78, 0xf8, 0x0e, 0x98, 0xa2, 0xe3, 0x38, 0x5f, - 0xff, 0xce, 0xa5, 0x9f, 0x67, 0x46, 0xef, 0x65, 0x4b, 0x44, 0x0b, 0x64, 0x36, 0xf7, 0x7f, 0x06, - 0x93, 0xa3, 0xcb, 0x40, 0x40, 0xc3, 0x12, 0x98, 0xa7, 0xc3, 0x64, 0x8e, 0xbe, 0xc9, 0xa5, 0x9f, - 0x3f, 0x26, 0x91, 0xc9, 0x50, 0x96, 0x9a, 0xd1, 0x63, 0x21, 0xfd, 0xf7, 0x4c, 0x3d, 0x1e, 0x59, - 0x96, 0x4a, 0x6f, 0xf6, 0x44, 0x45, 0xfe, 0xc3, 0x48, 0x7a, 0x75, 0x61, 0xe4, 0x8e, 0x37, 0x36, - 0x51, 0xac, 0xdf, 0x4a, 0x15, 0x97, 0x3f, 0x9e, 0xbb, 0xba, 0xfc, 0x7c, 0x3a, 0xee, 0x47, 0xe8, - 0xdd, 0x4c, 0xd7, 0x46, 0xef, 0x66, 0x29, 0x7d, 0x37, 0xd3, 0x8d, 0x88, 0xee, 0xe6, 0x08, 0x03, - 0x5f, 0x05, 0xe3, 0x25, 0x4c, 0x3e, 0xf2, 0x83, 0xe7, 0xbc, 0x20, 0xe6, 0x61, 0xb7, 0xa3, 0xce, - 0x72, 0xb8, 0xc7, 0x1d, 0x1a, 0x8a, 0x21, 0xf0, 0x26, 0x18, 0x61, 0x95, 0x83, 0x6f, 0x91, 0x70, - 0x43, 0xf1, 0x52, 0xc1, 0x9c, 0xb0, 0x00, 0x66, 0xd7, 0x70, 0xd3, 0x39, 0xb6, 0x1c, 0x82, 0xbd, - 0xfa, 0xf1, 0x56, 0xc8, 0xaa, 0xd4, 0x8c, 0x78, 0x2d, 0x34, 0xa8, 0x5f, 0x6f, 0x72, 0x80, 0x7e, - 0x10, 0x6a, 0x28, 0x45, 0x81, 0xdf, 0x06, 0x72, 0xd2, 0x82, 0x0e, 0x59, 0xbd, 0x9a, 0x11, 0xeb, - 0x55, 0x5a, 0x46, 0x0f, 0x0e, 0x35, 0x94, 0xe1, 0xc1, 0x0f, 0xc0, 0xe2, 0x76, 0xab, 0xe1, 0x10, - 0xdc, 0x48, 0xc5, 0x35, 0xc3, 0x04, 0x6f, 0x76, 0x3b, 0xaa, 0xca, 0x05, 0xdb, 0x1c, 0xa6, 0x67, - 0xe3, 0xeb, 0xaf, 0x00, 0xdf, 0x00, 0x00, 0xf9, 0x6d, 0xaf, 0x61, 0xb9, 0x07, 0x2e, 0x51, 0x16, - 0x97, 0xa5, 0x95, 0xd1, 0xfc, 0xc5, 0x6e, 0x47, 0x85, 0x5c, 0x2f, 0xa0, 0x3e, 0xbd, 0x49, 0x9d, - 0x1a, 0x12, 0x90, 0x30, 0x0f, 0x66, 0xcd, 0x23, 0x97, 0x94, 0xbd, 0x82, 0x13, 0x62, 0x5a, 0x60, - 0x95, 0x8b, 0x99, 0x6a, 0x74, 0xe4, 0x12, 0xdd, 0xf7, 0x74, 0x5a, 0x94, 0xdb, 0x01, 0xd6, 0x50, - 0x8a, 0x01, 0xdf, 0x06, 0x53, 0xa6, 0xe7, 0xec, 0x34, 0x71, 0xa5, 0x15, 0xf8, 0xbb, 0xca, 0x25, - 0x26, 0x70, 0xa9, 0xdb, 0x51, 0x17, 0x22, 0x01, 0xe6, 0xd4, 0x5b, 0xd4, 0x4b, 0xab, 0x6a, 0x0f, - 0x4b, 0x2b, 0x32, 0x95, 0x61, 0x8b, 0xd9, 0x0a, 0x15, 0x95, 0xed, 0x83, 0x70, 0x4c, 0xeb, 0xac, - 0x88, 0xb3, 0x4d, 0xa0, 0x8b, 0x17, 0xc1, 0x74, 0x5a, 0x3a, 0xac, 0xee, 0xb7, 0x77, 0x77, 0x9b, - 0x58, 0x59, 0x4e, 0x4f, 0xcb, 0xb8, 0x21, 0xf7, 0x46, 0xd4, 0x08, 0x0b, 0x5f, 0x06, 0xa3, 0x74, - 0x18, 0x2a, 0x37, 0x68, 0x4b, 0x9b, 0x97, 0xbb, 0x1d, 0x75, 0xba, 0x47, 0x0a, 0x35, 0xc4, 0xdd, - 0x70, 0x53, 0xe8, 0x56, 0x0a, 0xfe, 0xc1, 0x81, 0xe3, 0x35, 0x42, 0x45, 0x63, 0x9c, 0xeb, 0xdd, - 0x8e, 0x7a, 0x39, 0xdd, 0xad, 0xd4, 0x23, 0x8c, 0xd8, 0xac, 0xc4, 0x3c, 0x7a, 0x1c, 0x51, 0xdb, - 0xf3, 0x70, 0x70, 0xd2, 0x70, 0xdd, 0x4e, 0x57, 0xa9, 0x80, 0xf9, 0xc5, 0x96, 0x2b, 0x45, 0x81, - 0x45, 0x20, 0x9b, 0x47, 0x04, 0x07, 0x9e, 0xd3, 0x3c, 0x91, 0x59, 0x65, 0x32, 0x42, 0x40, 0x38, - 0x42, 0x88, 0x42, 0x19, 0x1a, 0xbc, 0x07, 0x26, 0xab, 0x24, 0xc0, 0x61, 0x88, 0x83, 0x50, 0xc1, - 0x6c, 0x51, 0x17, 0xba, 0x1d, 0x55, 0x8e, 0x2e, 0x88, 0xd8, 0xa5, 0xa1, 0x1e, 0x0c, 0xde, 0x05, - 0x13, 0x85, 0x7d, 0x5c, 0x7f, 0x4e, 0x29, 0xbb, 0x8c, 0x22, 0x3c, 0xd5, 0xf5, 0xc8, 0xa3, 0xa1, - 0x13, 0x10, 0x2d, 0x89, 0x9c, 0xbd, 0x89, 0x8f, 0x59, 0x1f, 0xcf, 0x9a, 0xa6, 0x51, 0xf1, 0x7c, - 0xf1, 0x99, 0xd8, 0x55, 0x1b, 0xba, 0x1f, 0x63, 0x0d, 0x25, 0x19, 0xf0, 0x31, 0x80, 0x09, 0x83, - 0xe5, 0x04, 0x7b, 0x98, 0x77, 0x4d, 0xa3, 0xf9, 0xe5, 0x6e, 0x47, 0xbd, 0xd6, 0x57, 0x47, 0x6f, - 0x52, 0x9c, 0x86, 0xfa, 0x90, 0xe1, 0x53, 0x70, 0xa1, 0x67, 0x6d, 0xef, 0xee, 0xba, 0x47, 0xc8, - 0xf1, 0xf6, 0xb0, 0xf2, 0x39, 0x17, 0xd5, 0xba, 0x1d, 0x75, 0x29, 0x2b, 0xca, 0x80, 0x7a, 0x40, - 0x91, 0x1a, 0xea, 0x2b, 0x00, 0x1d, 0x70, 0xa9, 0x9f, 0xdd, 0x3e, 0xf2, 0x94, 0x2f, 0xb8, 0xf6, - 0xcb, 0xdd, 0x8e, 0xaa, 0x9d, 0xaa, 0xad, 0x93, 0x23, 0x4f, 0x43, 0x83, 0x74, 0xe0, 0x06, 0x98, - 0x3b, 0x71, 0xd9, 0x47, 0x5e, 0xb9, 0x15, 0x2a, 0x5f, 0x72, 0x69, 0xe1, 0x04, 0x08, 0xd2, 0xe4, - 0xc8, 0xd3, 0xfd, 0x56, 0xa8, 0xa1, 0x34, 0x0d, 0xbe, 0x1f, 0xe7, 0x86, 0x17, 0xf7, 0x90, 0x77, - 0x90, 0xa3, 0x62, 0x01, 0x8e, 0x74, 0x78, 0x5b, 0x10, 0x9e, 0xa4, 0x26, 0x22, 0xc0, 0xd7, 0xe3, - 0x23, 0xf4, 0xb8, 0x52, 0xe5, 0xbd, 0xe3, 0xa8, 0xf8, 0x0e, 0x10, 0xb1, 0x3f, 0x6c, 0xf5, 0x0e, - 0xd1, 0xe3, 0x4a, 0x55, 0xfb, 0x66, 0x86, 0x77, 0x9b, 0xf4, 0x16, 0xef, 0xbd, 0x7e, 0x8a, 0xb7, - 0xb8, 0xe7, 0x1c, 0x60, 0x0d, 0x31, 0xa7, 0x58, 0x47, 0x86, 0xcf, 0x51, 0x47, 0x56, 0xc1, 0xd8, - 0x53, 0xc3, 0xa2, 0xe8, 0x5c, 0xba, 0x8c, 0x7c, 0xe4, 0x34, 0x39, 0x38, 0x42, 0xc0, 0x32, 0x58, - 0xd8, 0xc0, 0x4e, 0x40, 0x76, 0xb0, 0x43, 0x8a, 0x1e, 0xc1, 0xc1, 0xa1, 0xd3, 0x8c, 0xaa, 0x44, - 0x4e, 0xdc, 0xcd, 0xfd, 0x18, 0xa4, 0xbb, 0x11, 0x4a, 0x43, 0xfd, 0x98, 0xb0, 0x08, 0xe6, 0xcd, - 0x26, 0xae, 0xd3, 0x17, 0x78, 0xdb, 0x3d, 0xc0, 0x7e, 0x9b, 0x6c, 0x85, 0xac, 0x5a, 0xe4, 0xc4, - 0xa7, 0x1c, 0x47, 0x10, 0x9d, 0x70, 0x8c, 0x86, 0xb2, 0x2c, 0xfa, 0xa0, 0x5b, 0x6e, 0x48, 0xb0, - 0x27, 0xbc, 0x80, 0x2f, 0xa6, 0x6f, 0x9e, 0x26, 0x43, 0xc4, 0x2d, 0x7e, 0x3b, 0x68, 0x86, 0x1a, - 0xca, 0xd0, 0x20, 0x02, 0x0b, 0x46, 0xe3, 0x10, 0x07, 0xc4, 0x0d, 0xb1, 0xa0, 0x76, 0x91, 0xa9, - 0x09, 0x0f, 0x90, 0x13, 0x83, 0x92, 0x82, 0xfd, 0xc8, 0xf0, 0xed, 0xb8, 0xd5, 0x35, 0xda, 0xc4, - 0xb7, 0xad, 0x6a, 0x74, 0xeb, 0x0b, 0xb9, 0x71, 0xda, 0xc4, 0xd7, 0x09, 0x15, 0x48, 0x22, 0xe9, - 0x3d, 0xd8, 0x6b, 0xbd, 0x8d, 0x36, 0xd9, 0x57, 0x14, 0xc6, 0x1d, 0xd0, 0xad, 0x3b, 0xed, 0x54, - 0xb7, 0x4e, 0x29, 0xf0, 0x5b, 0xa2, 0xc8, 0xba, 0xdb, 0xc4, 0xca, 0x65, 0x96, 0x6e, 0xe1, 0x06, - 0x63, 0xec, 0x5d, 0x97, 0x5e, 0xfe, 0x29, 0x6c, 0x2f, 0xfa, 0x4d, 0x7c, 0xcc, 0xc8, 0x57, 0xd2, - 0x27, 0x8b, 0x3e, 0x39, 0x9c, 0x9b, 0x44, 0x42, 0x2b, 0xd3, 0x4a, 0x33, 0x81, 0xab, 0xe9, 0x46, - 0x5f, 0x68, 0xd3, 0xb8, 0x4e, 0x3f, 0x1a, 0xdd, 0x0b, 0x9e, 0x2e, 0xda, 0xc3, 0xb1, 0xac, 0xa8, - 0x2c, 0x2b, 0xc2, 0x5e, 0x44, 0x39, 0x66, 0xbd, 0x1f, 0x4f, 0x48, 0x8a, 0x02, 0x6d, 0x30, 0x7f, - 0x92, 0xa2, 0x13, 0x9d, 0x65, 0xa6, 0x23, 0xdc, 0x36, 0xae, 0xe7, 0x12, 0xd7, 0x69, 0xea, 0xbd, - 0x2c, 0x0b, 0x92, 0x59, 0x01, 0x5a, 0x9a, 0xe9, 0xff, 0x71, 0x7e, 0x6f, 0xb0, 0x1c, 0xa5, 0xfb, - 0xe3, 0x5e, 0x92, 0x45, 0x30, 0x7d, 0x41, 0x65, 0x9d, 0x7a, 0x32, 0xcd, 0x1a, 0x93, 0x10, 0x0e, - 0x1c, 0x6f, 0xef, 0x33, 0xb9, 0xee, 0xc3, 0xa5, 0x1d, 0x6d, 0xdc, 0xfb, 0xb3, 0xfd, 0xbe, 0x39, - 0xf8, 0x55, 0x81, 0x6f, 0x77, 0x02, 0x1e, 0x2f, 0x26, 0x4e, 0xf7, 0x4b, 0x03, 0x9b, 0x7d, 0x4e, - 0x16, 0xc1, 0x70, 0x2b, 0xd5, 0x9c, 0x33, 0x85, 0x5b, 0x67, 0xf5, 0xe6, 0x5c, 0x28, 0xcb, 0xa4, - 0x1d, 0x57, 0x91, 0xa7, 0xa2, 0xd0, 0x6c, 0xb3, 0x2f, 0x77, 0xb7, 0xd3, 0x67, 0x27, 0x4e, 0x55, - 0x9d, 0x03, 0x34, 0x94, 0x62, 0xd0, 0x27, 0x3a, 0x69, 0xa9, 0x12, 0x87, 0xe0, 0xa8, 0x11, 0x10, - 0x36, 0x38, 0x25, 0xa4, 0x87, 0x14, 0xa6, 0xa1, 0x7e, 0xe4, 0xac, 0xa6, 0xed, 0x3f, 0xc7, 0x9e, - 0xf2, 0xca, 0x59, 0x9a, 0x84, 0xc2, 0x32, 0x9a, 0x8c, 0x0c, 0x1f, 0x82, 0x99, 0xf8, 0xf5, 0xa0, - 0xe0, 0xb7, 0x3d, 0xa2, 0xdc, 0x67, 0x77, 0xa1, 0x58, 0x60, 0xe2, 0xf7, 0x90, 0x3a, 0xf5, 0xd3, - 0x02, 0x23, 0xe2, 0xa1, 0x05, 0xe6, 0x1f, 0xb7, 0x7d, 0xe2, 0xe4, 0x9d, 0xfa, 0x73, 0xec, 0x35, - 0xf2, 0xc7, 0x04, 0x87, 0xca, 0xeb, 0x4c, 0x44, 0x68, 0xbf, 0x3f, 0xa4, 0x10, 0x7d, 0x87, 0x63, - 0xf4, 0x1d, 0x0a, 0xd2, 0x50, 0x96, 0x48, 0x4b, 0x49, 0x25, 0xc0, 0x4f, 0x7c, 0x82, 0x95, 0x87, - 0xe9, 0xeb, 0xaa, 0x15, 0x60, 0xfd, 0xd0, 0xa7, 0xbb, 0x13, 0x63, 0xc4, 0x1d, 0xf1, 0x83, 0xa0, - 0xdd, 0x22, 0xac, 0xab, 0x51, 0xde, 0x4f, 0x1f, 0xe3, 0x93, 0x1d, 0xe1, 0x28, 0x9d, 0xf5, 0x41, - 0xc2, 0x8e, 0x08, 0xe4, 0xd5, 0x9f, 0xe6, 0x84, 0xef, 0xc0, 0x70, 0x0e, 0x4c, 0x95, 0xca, 0x76, - 0xad, 0x6a, 0x1b, 0xc8, 0x36, 0xd7, 0xe4, 0x21, 0x78, 0x11, 0xc0, 0x62, 0xa9, 0x68, 0x17, 0x0d, - 0x8b, 0x1b, 0x6b, 0xa6, 0x5d, 0x58, 0x93, 0x01, 0x94, 0xc1, 0x34, 0x32, 0x05, 0xcb, 0x14, 0xb5, - 0x54, 0x8b, 0x8f, 0x6c, 0x13, 0x6d, 0x71, 0xcb, 0x05, 0xb8, 0x0c, 0xae, 0x55, 0x8b, 0x8f, 0x1e, - 0x6f, 0x17, 0x39, 0xa6, 0x66, 0x94, 0xd6, 0x6a, 0xc8, 0xdc, 0x2a, 0x3f, 0x31, 0x6b, 0x6b, 0x86, - 0x6d, 0xc8, 0x8b, 0x70, 0x1e, 0xcc, 0x54, 0x8d, 0x27, 0x66, 0xad, 0x5a, 0x32, 0x2a, 0xd5, 0x8d, - 0xb2, 0x2d, 0x2f, 0xc1, 0x1b, 0xe0, 0x3a, 0x15, 0x2e, 0x23, 0xb3, 0x16, 0x4f, 0xb0, 0x8e, 0xca, - 0x5b, 0x3d, 0x88, 0x0a, 0x2f, 0x83, 0xc5, 0xfe, 0xae, 0x65, 0xca, 0xce, 0x4c, 0x69, 0xa0, 0xc2, - 0x46, 0x31, 0x9e, 0x73, 0x05, 0xde, 0x05, 0xaf, 0x9c, 0x16, 0x15, 0x1b, 0x57, 0xed, 0x72, 0xa5, - 0x66, 0x3c, 0x32, 0x4b, 0xb6, 0x7c, 0x1b, 0x5e, 0x07, 0x97, 0xf3, 0x96, 0x51, 0xd8, 0xdc, 0x28, - 0x5b, 0x66, 0xad, 0x62, 0x9a, 0xa8, 0x56, 0x29, 0x23, 0xbb, 0x66, 0x3f, 0xab, 0xa1, 0x67, 0x72, - 0x03, 0xaa, 0xe0, 0xea, 0x76, 0x69, 0x30, 0x00, 0xc3, 0x2b, 0x60, 0x71, 0xcd, 0xb4, 0x8c, 0x0f, - 0x32, 0xae, 0x17, 0x12, 0xbc, 0x06, 0x2e, 0x6d, 0x97, 0xfa, 0x7b, 0x3f, 0x95, 0x56, 0xff, 0x0e, - 0xc0, 0x08, 0xed, 0xfb, 0xa1, 0x02, 0x2e, 0xc4, 0x7b, 0x5b, 0x2e, 0x99, 0xb5, 0xf5, 0xb2, 0x65, - 0x95, 0x9f, 0x9a, 0x48, 0x1e, 0x8a, 0x56, 0x93, 0xf1, 0xd4, 0xb6, 0x4b, 0x76, 0xd1, 0xaa, 0xd9, - 0xa8, 0xf8, 0xe8, 0x91, 0x89, 0x7a, 0x3b, 0x24, 0x41, 0x08, 0x66, 0x63, 0x82, 0x65, 0x1a, 0x6b, - 0x26, 0x92, 0x87, 0xe1, 0x6d, 0x70, 0x2b, 0x69, 0x1b, 0x44, 0xcf, 0x89, 0xf4, 0xc7, 0xdb, 0x65, - 0xb4, 0xbd, 0x25, 0x8f, 0xd0, 0x43, 0x13, 0xdb, 0x0c, 0xcb, 0x92, 0x47, 0xe1, 0x4d, 0xa0, 0xc6, - 0x5b, 0x2c, 0xec, 0x6e, 0x22, 0x72, 0x00, 0x1f, 0x80, 0x37, 0xce, 0x00, 0x0d, 0x8a, 0x62, 0x8a, - 0xa6, 0xa4, 0x0f, 0x37, 0x5a, 0xcf, 0x34, 0x7c, 0x1d, 0xbc, 0x36, 0xd0, 0x3d, 0x48, 0x74, 0x06, - 0xae, 0x83, 0x7c, 0x1f, 0x16, 0x5f, 0x65, 0x64, 0xe1, 0xe7, 0x32, 0x12, 0x8a, 0xa9, 0xd1, 0x21, - 0x2c, 0x20, 0xc3, 0x2e, 0x6c, 0xc8, 0xb3, 0x70, 0x15, 0xbc, 0x3c, 0xf0, 0x38, 0x24, 0x37, 0xa1, - 0x01, 0x0d, 0xf0, 0xee, 0xf9, 0xb0, 0x83, 0xc2, 0xc6, 0xf0, 0x25, 0xb0, 0x3c, 0x58, 0x22, 0xda, - 0x92, 0x5d, 0xf8, 0x0e, 0x78, 0xf3, 0x2c, 0xd4, 0xa0, 0x29, 0xf6, 0x4e, 0x9f, 0x22, 0x3a, 0x06, - 0xfb, 0xf4, 0xd9, 0x1b, 0x8c, 0xa2, 0x07, 0xc3, 0x85, 0xff, 0x07, 0xb4, 0xbe, 0x87, 0x3d, 0xb9, - 0x2d, 0x2f, 0x24, 0x78, 0x07, 0xdc, 0x46, 0x46, 0x69, 0xad, 0xbc, 0x55, 0x3b, 0x07, 0xfe, 0x53, - 0x09, 0xbe, 0x07, 0xde, 0x3e, 0x1b, 0x38, 0x68, 0x81, 0x9f, 0x49, 0xd0, 0x04, 0xef, 0x9f, 0x7b, - 0xbe, 0x41, 0x32, 0x9f, 0x4b, 0xf0, 0x06, 0xb8, 0xd6, 0x9f, 0x1f, 0xe5, 0xe1, 0x0b, 0x09, 0xae, - 0x80, 0x9b, 0xa7, 0xce, 0x14, 0x21, 0xbf, 0x94, 0xe0, 0x5b, 0xe0, 0xfe, 0x69, 0x90, 0x41, 0x61, - 0xfc, 0x5a, 0x82, 0x0f, 0xc1, 0x83, 0x73, 0xcc, 0x31, 0x48, 0xe0, 0x37, 0xa7, 0xac, 0x23, 0x4a, - 0xf6, 0x57, 0x67, 0xaf, 0x23, 0x42, 0xfe, 0x56, 0x82, 0x4b, 0xe0, 0x72, 0x7f, 0x08, 0x3d, 0x13, - 0xbf, 0x93, 0xe0, 0x2d, 0xb0, 0x7c, 0xaa, 0x12, 0x85, 0xfd, 0x5e, 0x82, 0x0a, 0x58, 0x28, 0x95, - 0x6b, 0xeb, 0x46, 0xd1, 0xaa, 0x3d, 0x2d, 0xda, 0x1b, 0xb5, 0xaa, 0x8d, 0xcc, 0x6a, 0x55, 0xfe, - 0xc5, 0x30, 0x0d, 0x25, 0xe1, 0x29, 0x95, 0x23, 0x67, 0x6d, 0xbd, 0x8c, 0x6a, 0x56, 0xf1, 0x89, - 0x59, 0xa2, 0xc8, 0x4f, 0x86, 0xe1, 0x1c, 0x00, 0x14, 0x56, 0x29, 0x17, 0x4b, 0x76, 0x55, 0xfe, - 0x6e, 0x0e, 0xce, 0x80, 0x09, 0xf3, 0x99, 0x6d, 0xa2, 0x92, 0x61, 0xc9, 0xff, 0xc8, 0xad, 0x1e, - 0x80, 0x89, 0xf8, 0xd3, 0x02, 0x1c, 0x03, 0xc3, 0x9b, 0x4f, 0xe4, 0x21, 0x38, 0x09, 0x46, 0x2d, - 0xd3, 0xa8, 0x9a, 0xb2, 0x04, 0x17, 0xc0, 0x9c, 0x69, 0x99, 0x05, 0xbb, 0x58, 0x2e, 0xd5, 0xd0, - 0x76, 0xa9, 0xc4, 0x2e, 0x4f, 0x19, 0x4c, 0x3f, 0xa5, 0x4f, 0x7e, 0x6c, 0xc9, 0xc1, 0x45, 0x30, - 0x6f, 0x95, 0x0b, 0x9b, 0x35, 0x64, 0x14, 0x4c, 0x14, 0x9b, 0x47, 0x28, 0x90, 0x09, 0xc5, 0x96, - 0xd1, 0xd5, 0x3c, 0x18, 0x8f, 0xbe, 0x4b, 0xc0, 0x29, 0x30, 0xbe, 0xf9, 0xa4, 0xb6, 0x61, 0x54, - 0x37, 0xe4, 0xa1, 0x1e, 0xd2, 0x7c, 0x56, 0x29, 0x22, 0x3a, 0x33, 0x00, 0x63, 0x27, 0x13, 0x4e, - 0x83, 0x89, 0x52, 0xb9, 0x56, 0xd8, 0x30, 0x0b, 0x9b, 0x72, 0xee, 0xde, 0x43, 0x30, 0x69, 0x07, - 0x8e, 0x17, 0xb6, 0xfc, 0x80, 0xc0, 0x7b, 0xe2, 0x60, 0x36, 0xfa, 0x3a, 0x1a, 0xfd, 0xe0, 0x7b, - 0x65, 0xee, 0x64, 0xcc, 0x7f, 0x0b, 0xd4, 0x86, 0x56, 0xa4, 0xd7, 0xa4, 0xfc, 0x85, 0x17, 0x7f, - 0x59, 0x1a, 0x7a, 0xf1, 0xf5, 0x92, 0xf4, 0xd5, 0xd7, 0x4b, 0xd2, 0x9f, 0xbf, 0x5e, 0x92, 0x7e, - 0xf2, 0xd7, 0xa5, 0xa1, 0x9d, 0x31, 0xf6, 0x83, 0xf1, 0xfd, 0xff, 0x05, 0x00, 0x00, 0xff, 0xff, - 0x5c, 0x9f, 0x8c, 0x37, 0x79, 0x1e, 0x00, 0x00, -} diff --git a/vendor/github.com/coreos/etcd/lease/doc.go b/vendor/github.com/coreos/etcd/lease/doc.go deleted file mode 100644 index a74eaf76fc59..000000000000 --- a/vendor/github.com/coreos/etcd/lease/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package lease provides an interface and implementation for time-limited leases over arbitrary resources. -package lease diff --git a/vendor/github.com/coreos/etcd/lease/leasehttp/doc.go b/vendor/github.com/coreos/etcd/lease/leasehttp/doc.go deleted file mode 100644 index 8177a37b663d..000000000000 --- a/vendor/github.com/coreos/etcd/lease/leasehttp/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package leasehttp serves lease renewals made through HTTP requests. -package leasehttp diff --git a/vendor/github.com/coreos/etcd/lease/leasehttp/http.go b/vendor/github.com/coreos/etcd/lease/leasehttp/http.go deleted file mode 100644 index ac2e7880e8a2..000000000000 --- a/vendor/github.com/coreos/etcd/lease/leasehttp/http.go +++ /dev/null @@ -1,247 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package leasehttp - -import ( - "bytes" - "context" - "errors" - "fmt" - "io/ioutil" - "net/http" - "time" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/lease/leasepb" - "github.com/coreos/etcd/pkg/httputil" -) - -var ( - LeasePrefix = "/leases" - LeaseInternalPrefix = "/leases/internal" - applyTimeout = time.Second - ErrLeaseHTTPTimeout = errors.New("waiting for node to catch up its applied index has timed out") -) - -// NewHandler returns an http Handler for lease renewals -func NewHandler(l lease.Lessor, waitch func() <-chan struct{}) http.Handler { - return &leaseHandler{l, waitch} -} - -type leaseHandler struct { - l lease.Lessor - waitch func() <-chan struct{} -} - -func (h *leaseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if r.Method != "POST" { - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return - } - - b, err := ioutil.ReadAll(r.Body) - if err != nil { - http.Error(w, "error reading body", http.StatusBadRequest) - return - } - - var v []byte - switch r.URL.Path { - case LeasePrefix: - lreq := pb.LeaseKeepAliveRequest{} - if err := lreq.Unmarshal(b); err != nil { - http.Error(w, "error unmarshalling request", http.StatusBadRequest) - return - } - select { - case <-h.waitch(): - case <-time.After(applyTimeout): - http.Error(w, ErrLeaseHTTPTimeout.Error(), http.StatusRequestTimeout) - return - } - ttl, err := h.l.Renew(lease.LeaseID(lreq.ID)) - if err != nil { - if err == lease.ErrLeaseNotFound { - http.Error(w, err.Error(), http.StatusNotFound) - return - } - - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - // TODO: fill out ResponseHeader - resp := &pb.LeaseKeepAliveResponse{ID: lreq.ID, TTL: ttl} - v, err = resp.Marshal() - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - case LeaseInternalPrefix: - lreq := leasepb.LeaseInternalRequest{} - if err := lreq.Unmarshal(b); err != nil { - http.Error(w, "error unmarshalling request", http.StatusBadRequest) - return - } - select { - case <-h.waitch(): - case <-time.After(applyTimeout): - http.Error(w, ErrLeaseHTTPTimeout.Error(), http.StatusRequestTimeout) - return - } - l := h.l.Lookup(lease.LeaseID(lreq.LeaseTimeToLiveRequest.ID)) - if l == nil { - http.Error(w, lease.ErrLeaseNotFound.Error(), http.StatusNotFound) - return - } - // TODO: fill out ResponseHeader - resp := &leasepb.LeaseInternalResponse{ - LeaseTimeToLiveResponse: &pb.LeaseTimeToLiveResponse{ - Header: &pb.ResponseHeader{}, - ID: lreq.LeaseTimeToLiveRequest.ID, - TTL: int64(l.Remaining().Seconds()), - GrantedTTL: l.TTL(), - }, - } - if lreq.LeaseTimeToLiveRequest.Keys { - ks := l.Keys() - kbs := make([][]byte, len(ks)) - for i := range ks { - kbs[i] = []byte(ks[i]) - } - resp.LeaseTimeToLiveResponse.Keys = kbs - } - - v, err = resp.Marshal() - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - default: - http.Error(w, fmt.Sprintf("unknown request path %q", r.URL.Path), http.StatusBadRequest) - return - } - - w.Header().Set("Content-Type", "application/protobuf") - w.Write(v) -} - -// RenewHTTP renews a lease at a given primary server. -// TODO: Batch request in future? -func RenewHTTP(ctx context.Context, id lease.LeaseID, url string, rt http.RoundTripper) (int64, error) { - // will post lreq protobuf to leader - lreq, err := (&pb.LeaseKeepAliveRequest{ID: int64(id)}).Marshal() - if err != nil { - return -1, err - } - - cc := &http.Client{Transport: rt} - req, err := http.NewRequest("POST", url, bytes.NewReader(lreq)) - if err != nil { - return -1, err - } - req.Header.Set("Content-Type", "application/protobuf") - req.Cancel = ctx.Done() - - resp, err := cc.Do(req) - if err != nil { - return -1, err - } - b, err := readResponse(resp) - if err != nil { - return -1, err - } - - if resp.StatusCode == http.StatusRequestTimeout { - return -1, ErrLeaseHTTPTimeout - } - - if resp.StatusCode == http.StatusNotFound { - return -1, lease.ErrLeaseNotFound - } - - if resp.StatusCode != http.StatusOK { - return -1, fmt.Errorf("lease: unknown error(%s)", string(b)) - } - - lresp := &pb.LeaseKeepAliveResponse{} - if err := lresp.Unmarshal(b); err != nil { - return -1, fmt.Errorf(`lease: %v. data = "%s"`, err, string(b)) - } - if lresp.ID != int64(id) { - return -1, fmt.Errorf("lease: renew id mismatch") - } - return lresp.TTL, nil -} - -// TimeToLiveHTTP retrieves lease information of the given lease ID. -func TimeToLiveHTTP(ctx context.Context, id lease.LeaseID, keys bool, url string, rt http.RoundTripper) (*leasepb.LeaseInternalResponse, error) { - // will post lreq protobuf to leader - lreq, err := (&leasepb.LeaseInternalRequest{ - LeaseTimeToLiveRequest: &pb.LeaseTimeToLiveRequest{ - ID: int64(id), - Keys: keys, - }, - }).Marshal() - if err != nil { - return nil, err - } - - req, err := http.NewRequest("POST", url, bytes.NewReader(lreq)) - if err != nil { - return nil, err - } - req.Header.Set("Content-Type", "application/protobuf") - - req = req.WithContext(ctx) - - cc := &http.Client{Transport: rt} - var b []byte - // buffer errc channel so that errc don't block inside the go routinue - resp, err := cc.Do(req) - if err != nil { - return nil, err - } - b, err = readResponse(resp) - if err != nil { - return nil, err - } - if resp.StatusCode == http.StatusRequestTimeout { - return nil, ErrLeaseHTTPTimeout - } - if resp.StatusCode == http.StatusNotFound { - return nil, lease.ErrLeaseNotFound - } - if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("lease: unknown error(%s)", string(b)) - } - - lresp := &leasepb.LeaseInternalResponse{} - if err := lresp.Unmarshal(b); err != nil { - return nil, fmt.Errorf(`lease: %v. data = "%s"`, err, string(b)) - } - if lresp.LeaseTimeToLiveResponse.ID != int64(id) { - return nil, fmt.Errorf("lease: renew id mismatch") - } - return lresp, nil -} - -func readResponse(resp *http.Response) (b []byte, err error) { - b, err = ioutil.ReadAll(resp.Body) - httputil.GracefulClose(resp) - return -} diff --git a/vendor/github.com/coreos/etcd/lease/leasepb/lease.pb.go b/vendor/github.com/coreos/etcd/lease/leasepb/lease.pb.go deleted file mode 100644 index 4ab937672776..000000000000 --- a/vendor/github.com/coreos/etcd/lease/leasepb/lease.pb.go +++ /dev/null @@ -1,591 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: lease.proto - -/* - Package leasepb is a generated protocol buffer package. - - It is generated from these files: - lease.proto - - It has these top-level messages: - Lease - LeaseInternalRequest - LeaseInternalResponse -*/ -package leasepb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - etcdserverpb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type Lease struct { - ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` - TTL int64 `protobuf:"varint,2,opt,name=TTL,proto3" json:"TTL,omitempty"` -} - -func (m *Lease) Reset() { *m = Lease{} } -func (m *Lease) String() string { return proto.CompactTextString(m) } -func (*Lease) ProtoMessage() {} -func (*Lease) Descriptor() ([]byte, []int) { return fileDescriptorLease, []int{0} } - -type LeaseInternalRequest struct { - LeaseTimeToLiveRequest *etcdserverpb.LeaseTimeToLiveRequest `protobuf:"bytes,1,opt,name=LeaseTimeToLiveRequest" json:"LeaseTimeToLiveRequest,omitempty"` -} - -func (m *LeaseInternalRequest) Reset() { *m = LeaseInternalRequest{} } -func (m *LeaseInternalRequest) String() string { return proto.CompactTextString(m) } -func (*LeaseInternalRequest) ProtoMessage() {} -func (*LeaseInternalRequest) Descriptor() ([]byte, []int) { return fileDescriptorLease, []int{1} } - -type LeaseInternalResponse struct { - LeaseTimeToLiveResponse *etcdserverpb.LeaseTimeToLiveResponse `protobuf:"bytes,1,opt,name=LeaseTimeToLiveResponse" json:"LeaseTimeToLiveResponse,omitempty"` -} - -func (m *LeaseInternalResponse) Reset() { *m = LeaseInternalResponse{} } -func (m *LeaseInternalResponse) String() string { return proto.CompactTextString(m) } -func (*LeaseInternalResponse) ProtoMessage() {} -func (*LeaseInternalResponse) Descriptor() ([]byte, []int) { return fileDescriptorLease, []int{2} } - -func init() { - proto.RegisterType((*Lease)(nil), "leasepb.Lease") - proto.RegisterType((*LeaseInternalRequest)(nil), "leasepb.LeaseInternalRequest") - proto.RegisterType((*LeaseInternalResponse)(nil), "leasepb.LeaseInternalResponse") -} -func (m *Lease) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Lease) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintLease(dAtA, i, uint64(m.ID)) - } - if m.TTL != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintLease(dAtA, i, uint64(m.TTL)) - } - return i, nil -} - -func (m *LeaseInternalRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseInternalRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.LeaseTimeToLiveRequest != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintLease(dAtA, i, uint64(m.LeaseTimeToLiveRequest.Size())) - n1, err := m.LeaseTimeToLiveRequest.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - } - return i, nil -} - -func (m *LeaseInternalResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseInternalResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.LeaseTimeToLiveResponse != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintLease(dAtA, i, uint64(m.LeaseTimeToLiveResponse.Size())) - n2, err := m.LeaseTimeToLiveResponse.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - } - return i, nil -} - -func encodeVarintLease(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *Lease) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovLease(uint64(m.ID)) - } - if m.TTL != 0 { - n += 1 + sovLease(uint64(m.TTL)) - } - return n -} - -func (m *LeaseInternalRequest) Size() (n int) { - var l int - _ = l - if m.LeaseTimeToLiveRequest != nil { - l = m.LeaseTimeToLiveRequest.Size() - n += 1 + l + sovLease(uint64(l)) - } - return n -} - -func (m *LeaseInternalResponse) Size() (n int) { - var l int - _ = l - if m.LeaseTimeToLiveResponse != nil { - l = m.LeaseTimeToLiveResponse.Size() - n += 1 + l + sovLease(uint64(l)) - } - return n -} - -func sovLease(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozLease(x uint64) (n int) { - return sovLease(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Lease) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Lease: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Lease: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TTL", wireType) - } - m.TTL = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TTL |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipLease(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthLease - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseInternalRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseInternalRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseInternalRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field LeaseTimeToLiveRequest", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthLease - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.LeaseTimeToLiveRequest == nil { - m.LeaseTimeToLiveRequest = &etcdserverpb.LeaseTimeToLiveRequest{} - } - if err := m.LeaseTimeToLiveRequest.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipLease(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthLease - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseInternalResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseInternalResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseInternalResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field LeaseTimeToLiveResponse", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthLease - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.LeaseTimeToLiveResponse == nil { - m.LeaseTimeToLiveResponse = &etcdserverpb.LeaseTimeToLiveResponse{} - } - if err := m.LeaseTimeToLiveResponse.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipLease(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthLease - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipLease(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowLease - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowLease - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowLease - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthLease - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowLease - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipLease(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthLease = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowLease = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("lease.proto", fileDescriptorLease) } - -var fileDescriptorLease = []byte{ - // 233 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xce, 0x49, 0x4d, 0x2c, - 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x07, 0x73, 0x0a, 0x92, 0xa4, 0x44, 0xd2, - 0xf3, 0xd3, 0xf3, 0xc1, 0x62, 0xfa, 0x20, 0x16, 0x44, 0x5a, 0x4a, 0x2d, 0xb5, 0x24, 0x39, 0x45, - 0x1f, 0x44, 0x14, 0xa7, 0x16, 0x95, 0xa5, 0x16, 0x21, 0x31, 0x0b, 0x92, 0xf4, 0x8b, 0x0a, 0x92, - 0x21, 0xea, 0x94, 0x34, 0xb9, 0x58, 0x7d, 0x40, 0x06, 0x09, 0xf1, 0x71, 0x31, 0x79, 0xba, 0x48, - 0x30, 0x2a, 0x30, 0x6a, 0x30, 0x07, 0x31, 0x79, 0xba, 0x08, 0x09, 0x70, 0x31, 0x87, 0x84, 0xf8, - 0x48, 0x30, 0x81, 0x05, 0x40, 0x4c, 0xa5, 0x12, 0x2e, 0x11, 0xb0, 0x52, 0xcf, 0xbc, 0x92, 0xd4, - 0xa2, 0xbc, 0xc4, 0x9c, 0xa0, 0xd4, 0xc2, 0xd2, 0xd4, 0xe2, 0x12, 0xa1, 0x18, 0x2e, 0x31, 0xb0, - 0x78, 0x48, 0x66, 0x6e, 0x6a, 0x48, 0xbe, 0x4f, 0x66, 0x59, 0x2a, 0x54, 0x06, 0x6c, 0x1a, 0xb7, - 0x91, 0x8a, 0x1e, 0xb2, 0xdd, 0x7a, 0xd8, 0xd5, 0x06, 0xe1, 0x30, 0x43, 0xa9, 0x82, 0x4b, 0x14, - 0xcd, 0xd6, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, 0x54, 0xa1, 0x78, 0x2e, 0x71, 0x0c, 0x2d, 0x10, 0x29, - 0xa8, 0xbd, 0xaa, 0x04, 0xec, 0x85, 0x28, 0x0e, 0xc2, 0x65, 0x8a, 0x93, 0xc4, 0x89, 0x87, 0x72, - 0x0c, 0x17, 0x1e, 0xca, 0x31, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, - 0x72, 0x8c, 0x33, 0x1e, 0xcb, 0x31, 0x24, 0xb1, 0x81, 0xc3, 0xce, 0x18, 0x10, 0x00, 0x00, 0xff, - 0xff, 0x9f, 0xf2, 0x42, 0xe0, 0x91, 0x01, 0x00, 0x00, -} diff --git a/vendor/github.com/coreos/etcd/lease/lessor.go b/vendor/github.com/coreos/etcd/lease/lessor.go deleted file mode 100644 index 43f0503531fe..000000000000 --- a/vendor/github.com/coreos/etcd/lease/lessor.go +++ /dev/null @@ -1,680 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package lease - -import ( - "encoding/binary" - "errors" - "math" - "sort" - "sync" - "time" - - "github.com/coreos/etcd/lease/leasepb" - "github.com/coreos/etcd/mvcc/backend" -) - -// NoLease is a special LeaseID representing the absence of a lease. -const NoLease = LeaseID(0) - -// MaxLeaseTTL is the maximum lease TTL value -const MaxLeaseTTL = 9000000000 - -var ( - forever = time.Time{} - - leaseBucketName = []byte("lease") - - // maximum number of leases to revoke per second; configurable for tests - leaseRevokeRate = 1000 - - ErrNotPrimary = errors.New("not a primary lessor") - ErrLeaseNotFound = errors.New("lease not found") - ErrLeaseExists = errors.New("lease already exists") - ErrLeaseTTLTooLarge = errors.New("too large lease TTL") -) - -// TxnDelete is a TxnWrite that only permits deletes. Defined here -// to avoid circular dependency with mvcc. -type TxnDelete interface { - DeleteRange(key, end []byte) (n, rev int64) - End() -} - -// RangeDeleter is a TxnDelete constructor. -type RangeDeleter func() TxnDelete - -type LeaseID int64 - -// Lessor owns leases. It can grant, revoke, renew and modify leases for lessee. -type Lessor interface { - // SetRangeDeleter lets the lessor create TxnDeletes to the store. - // Lessor deletes the items in the revoked or expired lease by creating - // new TxnDeletes. - SetRangeDeleter(rd RangeDeleter) - - // Grant grants a lease that expires at least after TTL seconds. - Grant(id LeaseID, ttl int64) (*Lease, error) - // Revoke revokes a lease with given ID. The item attached to the - // given lease will be removed. If the ID does not exist, an error - // will be returned. - Revoke(id LeaseID) error - - // Attach attaches given leaseItem to the lease with given LeaseID. - // If the lease does not exist, an error will be returned. - Attach(id LeaseID, items []LeaseItem) error - - // GetLease returns LeaseID for given item. - // If no lease found, NoLease value will be returned. - GetLease(item LeaseItem) LeaseID - - // Detach detaches given leaseItem from the lease with given LeaseID. - // If the lease does not exist, an error will be returned. - Detach(id LeaseID, items []LeaseItem) error - - // Promote promotes the lessor to be the primary lessor. Primary lessor manages - // the expiration and renew of leases. - // Newly promoted lessor renew the TTL of all lease to extend + previous TTL. - Promote(extend time.Duration) - - // Demote demotes the lessor from being the primary lessor. - Demote() - - // Renew renews a lease with given ID. It returns the renewed TTL. If the ID does not exist, - // an error will be returned. - Renew(id LeaseID) (int64, error) - - // Lookup gives the lease at a given lease id, if any - Lookup(id LeaseID) *Lease - - // Leases lists all leases. - Leases() []*Lease - - // ExpiredLeasesC returns a chan that is used to receive expired leases. - ExpiredLeasesC() <-chan []*Lease - - // Recover recovers the lessor state from the given backend and RangeDeleter. - Recover(b backend.Backend, rd RangeDeleter) - - // Stop stops the lessor for managing leases. The behavior of calling Stop multiple - // times is undefined. - Stop() -} - -// lessor implements Lessor interface. -// TODO: use clockwork for testability. -type lessor struct { - mu sync.Mutex - - // demotec is set when the lessor is the primary. - // demotec will be closed if the lessor is demoted. - demotec chan struct{} - - // TODO: probably this should be a heap with a secondary - // id index. - // Now it is O(N) to loop over the leases to find expired ones. - // We want to make Grant, Revoke, and findExpiredLeases all O(logN) and - // Renew O(1). - // findExpiredLeases and Renew should be the most frequent operations. - leaseMap map[LeaseID]*Lease - - itemMap map[LeaseItem]LeaseID - - // When a lease expires, the lessor will delete the - // leased range (or key) by the RangeDeleter. - rd RangeDeleter - - // backend to persist leases. We only persist lease ID and expiry for now. - // The leased items can be recovered by iterating all the keys in kv. - b backend.Backend - - // minLeaseTTL is the minimum lease TTL that can be granted for a lease. Any - // requests for shorter TTLs are extended to the minimum TTL. - minLeaseTTL int64 - - expiredC chan []*Lease - // stopC is a channel whose closure indicates that the lessor should be stopped. - stopC chan struct{} - // doneC is a channel whose closure indicates that the lessor is stopped. - doneC chan struct{} -} - -func NewLessor(b backend.Backend, minLeaseTTL int64) Lessor { - return newLessor(b, minLeaseTTL) -} - -func newLessor(b backend.Backend, minLeaseTTL int64) *lessor { - l := &lessor{ - leaseMap: make(map[LeaseID]*Lease), - itemMap: make(map[LeaseItem]LeaseID), - b: b, - minLeaseTTL: minLeaseTTL, - // expiredC is a small buffered chan to avoid unnecessary blocking. - expiredC: make(chan []*Lease, 16), - stopC: make(chan struct{}), - doneC: make(chan struct{}), - } - l.initAndRecover() - - go l.runLoop() - - return l -} - -// isPrimary indicates if this lessor is the primary lessor. The primary -// lessor manages lease expiration and renew. -// -// in etcd, raft leader is the primary. Thus there might be two primary -// leaders at the same time (raft allows concurrent leader but with different term) -// for at most a leader election timeout. -// The old primary leader cannot affect the correctness since its proposal has a -// smaller term and will not be committed. -// -// TODO: raft follower do not forward lease management proposals. There might be a -// very small window (within second normally which depends on go scheduling) that -// a raft follow is the primary between the raft leader demotion and lessor demotion. -// Usually this should not be a problem. Lease should not be that sensitive to timing. -func (le *lessor) isPrimary() bool { - return le.demotec != nil -} - -func (le *lessor) SetRangeDeleter(rd RangeDeleter) { - le.mu.Lock() - defer le.mu.Unlock() - - le.rd = rd -} - -func (le *lessor) Grant(id LeaseID, ttl int64) (*Lease, error) { - if id == NoLease { - return nil, ErrLeaseNotFound - } - - if ttl > MaxLeaseTTL { - return nil, ErrLeaseTTLTooLarge - } - - // TODO: when lessor is under high load, it should give out lease - // with longer TTL to reduce renew load. - l := &Lease{ - ID: id, - ttl: ttl, - itemSet: make(map[LeaseItem]struct{}), - revokec: make(chan struct{}), - } - - le.mu.Lock() - defer le.mu.Unlock() - - if _, ok := le.leaseMap[id]; ok { - return nil, ErrLeaseExists - } - - if l.ttl < le.minLeaseTTL { - l.ttl = le.minLeaseTTL - } - - if le.isPrimary() { - l.refresh(0) - } else { - l.forever() - } - - le.leaseMap[id] = l - l.persistTo(le.b) - - return l, nil -} - -func (le *lessor) Revoke(id LeaseID) error { - le.mu.Lock() - - l := le.leaseMap[id] - if l == nil { - le.mu.Unlock() - return ErrLeaseNotFound - } - defer close(l.revokec) - // unlock before doing external work - le.mu.Unlock() - - if le.rd == nil { - return nil - } - - txn := le.rd() - - // sort keys so deletes are in same order among all members, - // otherwise the backened hashes will be different - keys := l.Keys() - sort.StringSlice(keys).Sort() - for _, key := range keys { - txn.DeleteRange([]byte(key), nil) - } - - le.mu.Lock() - defer le.mu.Unlock() - delete(le.leaseMap, l.ID) - // lease deletion needs to be in the same backend transaction with the - // kv deletion. Or we might end up with not executing the revoke or not - // deleting the keys if etcdserver fails in between. - le.b.BatchTx().UnsafeDelete(leaseBucketName, int64ToBytes(int64(l.ID))) - - txn.End() - return nil -} - -// Renew renews an existing lease. If the given lease does not exist or -// has expired, an error will be returned. -func (le *lessor) Renew(id LeaseID) (int64, error) { - le.mu.Lock() - - unlock := func() { le.mu.Unlock() } - defer func() { unlock() }() - - if !le.isPrimary() { - // forward renew request to primary instead of returning error. - return -1, ErrNotPrimary - } - - demotec := le.demotec - - l := le.leaseMap[id] - if l == nil { - return -1, ErrLeaseNotFound - } - - if l.expired() { - le.mu.Unlock() - unlock = func() {} - select { - // A expired lease might be pending for revoking or going through - // quorum to be revoked. To be accurate, renew request must wait for the - // deletion to complete. - case <-l.revokec: - return -1, ErrLeaseNotFound - // The expired lease might fail to be revoked if the primary changes. - // The caller will retry on ErrNotPrimary. - case <-demotec: - return -1, ErrNotPrimary - case <-le.stopC: - return -1, ErrNotPrimary - } - } - - l.refresh(0) - return l.ttl, nil -} - -func (le *lessor) Lookup(id LeaseID) *Lease { - le.mu.Lock() - defer le.mu.Unlock() - return le.leaseMap[id] -} - -func (le *lessor) unsafeLeases() []*Lease { - leases := make([]*Lease, 0, len(le.leaseMap)) - for _, l := range le.leaseMap { - leases = append(leases, l) - } - sort.Sort(leasesByExpiry(leases)) - return leases -} - -func (le *lessor) Leases() []*Lease { - le.mu.Lock() - ls := le.unsafeLeases() - le.mu.Unlock() - return ls -} - -func (le *lessor) Promote(extend time.Duration) { - le.mu.Lock() - defer le.mu.Unlock() - - le.demotec = make(chan struct{}) - - // refresh the expiries of all leases. - for _, l := range le.leaseMap { - l.refresh(extend) - } - - if len(le.leaseMap) < leaseRevokeRate { - // no possibility of lease pile-up - return - } - - // adjust expiries in case of overlap - leases := le.unsafeLeases() - - baseWindow := leases[0].Remaining() - nextWindow := baseWindow + time.Second - expires := 0 - // have fewer expires than the total revoke rate so piled up leases - // don't consume the entire revoke limit - targetExpiresPerSecond := (3 * leaseRevokeRate) / 4 - for _, l := range leases { - remaining := l.Remaining() - if remaining > nextWindow { - baseWindow = remaining - nextWindow = baseWindow + time.Second - expires = 1 - continue - } - expires++ - if expires <= targetExpiresPerSecond { - continue - } - rateDelay := float64(time.Second) * (float64(expires) / float64(targetExpiresPerSecond)) - // If leases are extended by n seconds, leases n seconds ahead of the - // base window should be extended by only one second. - rateDelay -= float64(remaining - baseWindow) - delay := time.Duration(rateDelay) - nextWindow = baseWindow + delay - l.refresh(delay + extend) - } -} - -type leasesByExpiry []*Lease - -func (le leasesByExpiry) Len() int { return len(le) } -func (le leasesByExpiry) Less(i, j int) bool { return le[i].Remaining() < le[j].Remaining() } -func (le leasesByExpiry) Swap(i, j int) { le[i], le[j] = le[j], le[i] } - -func (le *lessor) Demote() { - le.mu.Lock() - defer le.mu.Unlock() - - // set the expiries of all leases to forever - for _, l := range le.leaseMap { - l.forever() - } - - if le.demotec != nil { - close(le.demotec) - le.demotec = nil - } -} - -// Attach attaches items to the lease with given ID. When the lease -// expires, the attached items will be automatically removed. -// If the given lease does not exist, an error will be returned. -func (le *lessor) Attach(id LeaseID, items []LeaseItem) error { - le.mu.Lock() - defer le.mu.Unlock() - - l := le.leaseMap[id] - if l == nil { - return ErrLeaseNotFound - } - - l.mu.Lock() - for _, it := range items { - l.itemSet[it] = struct{}{} - le.itemMap[it] = id - } - l.mu.Unlock() - return nil -} - -func (le *lessor) GetLease(item LeaseItem) LeaseID { - le.mu.Lock() - id := le.itemMap[item] - le.mu.Unlock() - return id -} - -// Detach detaches items from the lease with given ID. -// If the given lease does not exist, an error will be returned. -func (le *lessor) Detach(id LeaseID, items []LeaseItem) error { - le.mu.Lock() - defer le.mu.Unlock() - - l := le.leaseMap[id] - if l == nil { - return ErrLeaseNotFound - } - - l.mu.Lock() - for _, it := range items { - delete(l.itemSet, it) - delete(le.itemMap, it) - } - l.mu.Unlock() - return nil -} - -func (le *lessor) Recover(b backend.Backend, rd RangeDeleter) { - le.mu.Lock() - defer le.mu.Unlock() - - le.b = b - le.rd = rd - le.leaseMap = make(map[LeaseID]*Lease) - le.itemMap = make(map[LeaseItem]LeaseID) - le.initAndRecover() -} - -func (le *lessor) ExpiredLeasesC() <-chan []*Lease { - return le.expiredC -} - -func (le *lessor) Stop() { - close(le.stopC) - <-le.doneC -} - -func (le *lessor) runLoop() { - defer close(le.doneC) - - for { - var ls []*Lease - - // rate limit - revokeLimit := leaseRevokeRate / 2 - - le.mu.Lock() - if le.isPrimary() { - ls = le.findExpiredLeases(revokeLimit) - } - le.mu.Unlock() - - if len(ls) != 0 { - select { - case <-le.stopC: - return - case le.expiredC <- ls: - default: - // the receiver of expiredC is probably busy handling - // other stuff - // let's try this next time after 500ms - } - } - - select { - case <-time.After(500 * time.Millisecond): - case <-le.stopC: - return - } - } -} - -// findExpiredLeases loops leases in the leaseMap until reaching expired limit -// and returns the expired leases that needed to be revoked. -func (le *lessor) findExpiredLeases(limit int) []*Lease { - leases := make([]*Lease, 0, 16) - - for _, l := range le.leaseMap { - // TODO: probably should change to <= 100-500 millisecond to - // make up committing latency. - if l.expired() { - leases = append(leases, l) - - // reach expired limit - if len(leases) == limit { - break - } - } - } - - return leases -} - -func (le *lessor) initAndRecover() { - tx := le.b.BatchTx() - tx.Lock() - - tx.UnsafeCreateBucket(leaseBucketName) - _, vs := tx.UnsafeRange(leaseBucketName, int64ToBytes(0), int64ToBytes(math.MaxInt64), 0) - // TODO: copy vs and do decoding outside tx lock if lock contention becomes an issue. - for i := range vs { - var lpb leasepb.Lease - err := lpb.Unmarshal(vs[i]) - if err != nil { - tx.Unlock() - panic("failed to unmarshal lease proto item") - } - ID := LeaseID(lpb.ID) - if lpb.TTL < le.minLeaseTTL { - lpb.TTL = le.minLeaseTTL - } - le.leaseMap[ID] = &Lease{ - ID: ID, - ttl: lpb.TTL, - // itemSet will be filled in when recover key-value pairs - // set expiry to forever, refresh when promoted - itemSet: make(map[LeaseItem]struct{}), - expiry: forever, - revokec: make(chan struct{}), - } - } - tx.Unlock() - - le.b.ForceCommit() -} - -type Lease struct { - ID LeaseID - ttl int64 // time to live in seconds - // expiryMu protects concurrent accesses to expiry - expiryMu sync.RWMutex - // expiry is time when lease should expire. no expiration when expiry.IsZero() is true - expiry time.Time - - // mu protects concurrent accesses to itemSet - mu sync.RWMutex - itemSet map[LeaseItem]struct{} - revokec chan struct{} -} - -func (l *Lease) expired() bool { - return l.Remaining() <= 0 -} - -func (l *Lease) persistTo(b backend.Backend) { - key := int64ToBytes(int64(l.ID)) - - lpb := leasepb.Lease{ID: int64(l.ID), TTL: int64(l.ttl)} - val, err := lpb.Marshal() - if err != nil { - panic("failed to marshal lease proto item") - } - - b.BatchTx().Lock() - b.BatchTx().UnsafePut(leaseBucketName, key, val) - b.BatchTx().Unlock() -} - -// TTL returns the TTL of the Lease. -func (l *Lease) TTL() int64 { - return l.ttl -} - -// refresh refreshes the expiry of the lease. -func (l *Lease) refresh(extend time.Duration) { - newExpiry := time.Now().Add(extend + time.Duration(l.ttl)*time.Second) - l.expiryMu.Lock() - defer l.expiryMu.Unlock() - l.expiry = newExpiry -} - -// forever sets the expiry of lease to be forever. -func (l *Lease) forever() { - l.expiryMu.Lock() - defer l.expiryMu.Unlock() - l.expiry = forever -} - -// Keys returns all the keys attached to the lease. -func (l *Lease) Keys() []string { - l.mu.RLock() - keys := make([]string, 0, len(l.itemSet)) - for k := range l.itemSet { - keys = append(keys, k.Key) - } - l.mu.RUnlock() - return keys -} - -// Remaining returns the remaining time of the lease. -func (l *Lease) Remaining() time.Duration { - l.expiryMu.RLock() - defer l.expiryMu.RUnlock() - if l.expiry.IsZero() { - return time.Duration(math.MaxInt64) - } - return time.Until(l.expiry) -} - -type LeaseItem struct { - Key string -} - -func int64ToBytes(n int64) []byte { - bytes := make([]byte, 8) - binary.BigEndian.PutUint64(bytes, uint64(n)) - return bytes -} - -// FakeLessor is a fake implementation of Lessor interface. -// Used for testing only. -type FakeLessor struct{} - -func (fl *FakeLessor) SetRangeDeleter(dr RangeDeleter) {} - -func (fl *FakeLessor) Grant(id LeaseID, ttl int64) (*Lease, error) { return nil, nil } - -func (fl *FakeLessor) Revoke(id LeaseID) error { return nil } - -func (fl *FakeLessor) Attach(id LeaseID, items []LeaseItem) error { return nil } - -func (fl *FakeLessor) GetLease(item LeaseItem) LeaseID { return 0 } -func (fl *FakeLessor) Detach(id LeaseID, items []LeaseItem) error { return nil } - -func (fl *FakeLessor) Promote(extend time.Duration) {} - -func (fl *FakeLessor) Demote() {} - -func (fl *FakeLessor) Renew(id LeaseID) (int64, error) { return 10, nil } - -func (fl *FakeLessor) Lookup(id LeaseID) *Lease { return nil } - -func (fl *FakeLessor) Leases() []*Lease { return nil } - -func (fl *FakeLessor) ExpiredLeasesC() <-chan []*Lease { return nil } - -func (fl *FakeLessor) Recover(b backend.Backend, rd RangeDeleter) {} - -func (fl *FakeLessor) Stop() {} diff --git a/vendor/github.com/coreos/etcd/mvcc/backend/backend.go b/vendor/github.com/coreos/etcd/mvcc/backend/backend.go deleted file mode 100644 index f7d9e60c2e7d..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/backend/backend.go +++ /dev/null @@ -1,464 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package backend - -import ( - "fmt" - "hash/crc32" - "io" - "io/ioutil" - "os" - "path/filepath" - "sync" - "sync/atomic" - "time" - - bolt "github.com/coreos/bbolt" - "github.com/coreos/pkg/capnslog" -) - -var ( - defaultBatchLimit = 10000 - defaultBatchInterval = 100 * time.Millisecond - - defragLimit = 10000 - - // initialMmapSize is the initial size of the mmapped region. Setting this larger than - // the potential max db size can prevent writer from blocking reader. - // This only works for linux. - initialMmapSize = uint64(10 * 1024 * 1024 * 1024) - - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "mvcc/backend") - - // minSnapshotWarningTimeout is the minimum threshold to trigger a long running snapshot warning. - minSnapshotWarningTimeout = time.Duration(30 * time.Second) -) - -type Backend interface { - ReadTx() ReadTx - BatchTx() BatchTx - - Snapshot() Snapshot - Hash(ignores map[IgnoreKey]struct{}) (uint32, error) - // Size returns the current size of the backend. - Size() int64 - // SizeInUse returns the current size of the backend logically in use. - // Since the backend can manage free space in a non-byte unit such as - // number of pages, the returned value can be not exactly accurate in bytes. - SizeInUse() int64 - Defrag() error - ForceCommit() - Close() error -} - -type Snapshot interface { - // Size gets the size of the snapshot. - Size() int64 - // WriteTo writes the snapshot into the given writer. - WriteTo(w io.Writer) (n int64, err error) - // Close closes the snapshot. - Close() error -} - -type backend struct { - // size and commits are used with atomic operations so they must be - // 64-bit aligned, otherwise 32-bit tests will crash - - // size is the number of bytes in the backend - size int64 - - // sizeInUse is the number of bytes actually used in the backend - sizeInUse int64 - - // commits counts number of commits since start - commits int64 - - mu sync.RWMutex - db *bolt.DB - - batchInterval time.Duration - batchLimit int - batchTx *batchTxBuffered - - readTx *readTx - - stopc chan struct{} - donec chan struct{} -} - -type BackendConfig struct { - // Path is the file path to the backend file. - Path string - // BatchInterval is the maximum time before flushing the BatchTx. - BatchInterval time.Duration - // BatchLimit is the maximum puts before flushing the BatchTx. - BatchLimit int - // MmapSize is the number of bytes to mmap for the backend. - MmapSize uint64 -} - -func DefaultBackendConfig() BackendConfig { - return BackendConfig{ - BatchInterval: defaultBatchInterval, - BatchLimit: defaultBatchLimit, - MmapSize: initialMmapSize, - } -} - -func New(bcfg BackendConfig) Backend { - return newBackend(bcfg) -} - -func NewDefaultBackend(path string) Backend { - bcfg := DefaultBackendConfig() - bcfg.Path = path - return newBackend(bcfg) -} - -func newBackend(bcfg BackendConfig) *backend { - bopts := &bolt.Options{} - if boltOpenOptions != nil { - *bopts = *boltOpenOptions - } - bopts.InitialMmapSize = bcfg.mmapSize() - - db, err := bolt.Open(bcfg.Path, 0600, bopts) - if err != nil { - plog.Panicf("cannot open database at %s (%v)", bcfg.Path, err) - } - - // In future, may want to make buffering optional for low-concurrency systems - // or dynamically swap between buffered/non-buffered depending on workload. - b := &backend{ - db: db, - - batchInterval: bcfg.BatchInterval, - batchLimit: bcfg.BatchLimit, - - readTx: &readTx{ - buf: txReadBuffer{ - txBuffer: txBuffer{make(map[string]*bucketBuffer)}, - }, - buckets: make(map[string]*bolt.Bucket), - }, - - stopc: make(chan struct{}), - donec: make(chan struct{}), - } - b.batchTx = newBatchTxBuffered(b) - go b.run() - return b -} - -// BatchTx returns the current batch tx in coalescer. The tx can be used for read and -// write operations. The write result can be retrieved within the same tx immediately. -// The write result is isolated with other txs until the current one get committed. -func (b *backend) BatchTx() BatchTx { - return b.batchTx -} - -func (b *backend) ReadTx() ReadTx { return b.readTx } - -// ForceCommit forces the current batching tx to commit. -func (b *backend) ForceCommit() { - b.batchTx.Commit() -} - -func (b *backend) Snapshot() Snapshot { - b.batchTx.Commit() - - b.mu.RLock() - defer b.mu.RUnlock() - tx, err := b.db.Begin(false) - if err != nil { - plog.Fatalf("cannot begin tx (%s)", err) - } - - stopc, donec := make(chan struct{}), make(chan struct{}) - dbBytes := tx.Size() - go func() { - defer close(donec) - // sendRateBytes is based on transferring snapshot data over a 1 gigabit/s connection - // assuming a min tcp throughput of 100MB/s. - var sendRateBytes int64 = 100 * 1024 * 1014 - warningTimeout := time.Duration(int64((float64(dbBytes) / float64(sendRateBytes)) * float64(time.Second))) - if warningTimeout < minSnapshotWarningTimeout { - warningTimeout = minSnapshotWarningTimeout - } - start := time.Now() - ticker := time.NewTicker(warningTimeout) - defer ticker.Stop() - for { - select { - case <-ticker.C: - plog.Warningf("snapshotting is taking more than %v seconds to finish transferring %v MB [started at %v]", time.Since(start).Seconds(), float64(dbBytes)/float64(1024*1014), start) - case <-stopc: - snapshotDurations.Observe(time.Since(start).Seconds()) - return - } - } - }() - - return &snapshot{tx, stopc, donec} -} - -type IgnoreKey struct { - Bucket string - Key string -} - -func (b *backend) Hash(ignores map[IgnoreKey]struct{}) (uint32, error) { - h := crc32.New(crc32.MakeTable(crc32.Castagnoli)) - - b.mu.RLock() - defer b.mu.RUnlock() - err := b.db.View(func(tx *bolt.Tx) error { - c := tx.Cursor() - for next, _ := c.First(); next != nil; next, _ = c.Next() { - b := tx.Bucket(next) - if b == nil { - return fmt.Errorf("cannot get hash of bucket %s", string(next)) - } - h.Write(next) - b.ForEach(func(k, v []byte) error { - bk := IgnoreKey{Bucket: string(next), Key: string(k)} - if _, ok := ignores[bk]; !ok { - h.Write(k) - h.Write(v) - } - return nil - }) - } - return nil - }) - - if err != nil { - return 0, err - } - - return h.Sum32(), nil -} - -func (b *backend) Size() int64 { - return atomic.LoadInt64(&b.size) -} - -func (b *backend) SizeInUse() int64 { - return atomic.LoadInt64(&b.sizeInUse) -} - -func (b *backend) run() { - defer close(b.donec) - t := time.NewTimer(b.batchInterval) - defer t.Stop() - for { - select { - case <-t.C: - case <-b.stopc: - b.batchTx.CommitAndStop() - return - } - b.batchTx.Commit() - t.Reset(b.batchInterval) - } -} - -func (b *backend) Close() error { - close(b.stopc) - <-b.donec - return b.db.Close() -} - -// Commits returns total number of commits since start -func (b *backend) Commits() int64 { - return atomic.LoadInt64(&b.commits) -} - -func (b *backend) Defrag() error { - return b.defrag() -} - -func (b *backend) defrag() error { - now := time.Now() - - // TODO: make this non-blocking? - // lock batchTx to ensure nobody is using previous tx, and then - // close previous ongoing tx. - b.batchTx.Lock() - defer b.batchTx.Unlock() - - // lock database after lock tx to avoid deadlock. - b.mu.Lock() - defer b.mu.Unlock() - - // block concurrent read requests while resetting tx - b.readTx.mu.Lock() - defer b.readTx.mu.Unlock() - - b.batchTx.unsafeCommit(true) - b.batchTx.tx = nil - - tmpdb, err := bolt.Open(b.db.Path()+".tmp", 0600, boltOpenOptions) - if err != nil { - return err - } - - err = defragdb(b.db, tmpdb, defragLimit) - - if err != nil { - tmpdb.Close() - os.RemoveAll(tmpdb.Path()) - return err - } - - dbp := b.db.Path() - tdbp := tmpdb.Path() - - err = b.db.Close() - if err != nil { - plog.Fatalf("cannot close database (%s)", err) - } - err = tmpdb.Close() - if err != nil { - plog.Fatalf("cannot close database (%s)", err) - } - err = os.Rename(tdbp, dbp) - if err != nil { - plog.Fatalf("cannot rename database (%s)", err) - } - - b.db, err = bolt.Open(dbp, 0600, boltOpenOptions) - if err != nil { - plog.Panicf("cannot open database at %s (%v)", dbp, err) - } - b.batchTx.tx, err = b.db.Begin(true) - if err != nil { - plog.Fatalf("cannot begin tx (%s)", err) - } - - b.readTx.reset() - b.readTx.tx = b.unsafeBegin(false) - - size := b.readTx.tx.Size() - db := b.db - atomic.StoreInt64(&b.size, size) - atomic.StoreInt64(&b.sizeInUse, size-(int64(db.Stats().FreePageN)*int64(db.Info().PageSize))) - - took := time.Since(now) - defragDurations.Observe(took.Seconds()) - - return nil -} - -func defragdb(odb, tmpdb *bolt.DB, limit int) error { - // open a tx on tmpdb for writes - tmptx, err := tmpdb.Begin(true) - if err != nil { - return err - } - - // open a tx on old db for read - tx, err := odb.Begin(false) - if err != nil { - return err - } - defer tx.Rollback() - - c := tx.Cursor() - - count := 0 - for next, _ := c.First(); next != nil; next, _ = c.Next() { - b := tx.Bucket(next) - if b == nil { - return fmt.Errorf("backend: cannot defrag bucket %s", string(next)) - } - - tmpb, berr := tmptx.CreateBucketIfNotExists(next) - if berr != nil { - return berr - } - tmpb.FillPercent = 0.9 // for seq write in for each - - b.ForEach(func(k, v []byte) error { - count++ - if count > limit { - err = tmptx.Commit() - if err != nil { - return err - } - tmptx, err = tmpdb.Begin(true) - if err != nil { - return err - } - tmpb = tmptx.Bucket(next) - tmpb.FillPercent = 0.9 // for seq write in for each - - count = 0 - } - return tmpb.Put(k, v) - }) - } - - return tmptx.Commit() -} - -func (b *backend) begin(write bool) *bolt.Tx { - b.mu.RLock() - tx := b.unsafeBegin(write) - b.mu.RUnlock() - - size := tx.Size() - db := tx.DB() - atomic.StoreInt64(&b.size, size) - atomic.StoreInt64(&b.sizeInUse, size-(int64(db.Stats().FreePageN)*int64(db.Info().PageSize))) - - return tx -} - -func (b *backend) unsafeBegin(write bool) *bolt.Tx { - tx, err := b.db.Begin(write) - if err != nil { - plog.Fatalf("cannot begin tx (%s)", err) - } - return tx -} - -// NewTmpBackend creates a backend implementation for testing. -func NewTmpBackend(batchInterval time.Duration, batchLimit int) (*backend, string) { - dir, err := ioutil.TempDir(os.TempDir(), "etcd_backend_test") - if err != nil { - plog.Fatal(err) - } - tmpPath := filepath.Join(dir, "database") - bcfg := DefaultBackendConfig() - bcfg.Path, bcfg.BatchInterval, bcfg.BatchLimit = tmpPath, batchInterval, batchLimit - return newBackend(bcfg), tmpPath -} - -func NewDefaultTmpBackend() (*backend, string) { - return NewTmpBackend(defaultBatchInterval, defaultBatchLimit) -} - -type snapshot struct { - *bolt.Tx - stopc chan struct{} - donec chan struct{} -} - -func (s *snapshot) Close() error { - close(s.stopc) - <-s.donec - return s.Tx.Rollback() -} diff --git a/vendor/github.com/coreos/etcd/mvcc/backend/batch_tx.go b/vendor/github.com/coreos/etcd/mvcc/backend/batch_tx.go deleted file mode 100644 index aed6893e41a1..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/backend/batch_tx.go +++ /dev/null @@ -1,254 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package backend - -import ( - "bytes" - "math" - "sync" - "sync/atomic" - "time" - - bolt "github.com/coreos/bbolt" -) - -type BatchTx interface { - ReadTx - UnsafeCreateBucket(name []byte) - UnsafePut(bucketName []byte, key []byte, value []byte) - UnsafeSeqPut(bucketName []byte, key []byte, value []byte) - UnsafeDelete(bucketName []byte, key []byte) - // Commit commits a previous tx and begins a new writable one. - Commit() - // CommitAndStop commits the previous tx and does not create a new one. - CommitAndStop() -} - -type batchTx struct { - sync.Mutex - tx *bolt.Tx - backend *backend - - pending int -} - -func (t *batchTx) UnsafeCreateBucket(name []byte) { - _, err := t.tx.CreateBucket(name) - if err != nil && err != bolt.ErrBucketExists { - plog.Fatalf("cannot create bucket %s (%v)", name, err) - } - t.pending++ -} - -// UnsafePut must be called holding the lock on the tx. -func (t *batchTx) UnsafePut(bucketName []byte, key []byte, value []byte) { - t.unsafePut(bucketName, key, value, false) -} - -// UnsafeSeqPut must be called holding the lock on the tx. -func (t *batchTx) UnsafeSeqPut(bucketName []byte, key []byte, value []byte) { - t.unsafePut(bucketName, key, value, true) -} - -func (t *batchTx) unsafePut(bucketName []byte, key []byte, value []byte, seq bool) { - bucket := t.tx.Bucket(bucketName) - if bucket == nil { - plog.Fatalf("bucket %s does not exist", bucketName) - } - if seq { - // it is useful to increase fill percent when the workloads are mostly append-only. - // this can delay the page split and reduce space usage. - bucket.FillPercent = 0.9 - } - if err := bucket.Put(key, value); err != nil { - plog.Fatalf("cannot put key into bucket (%v)", err) - } - t.pending++ -} - -// UnsafeRange must be called holding the lock on the tx. -func (t *batchTx) UnsafeRange(bucketName, key, endKey []byte, limit int64) ([][]byte, [][]byte) { - bucket := t.tx.Bucket(bucketName) - if bucket == nil { - plog.Fatalf("bucket %s does not exist", bucketName) - } - return unsafeRange(bucket.Cursor(), key, endKey, limit) -} - -func unsafeRange(c *bolt.Cursor, key, endKey []byte, limit int64) (keys [][]byte, vs [][]byte) { - if limit <= 0 { - limit = math.MaxInt64 - } - var isMatch func(b []byte) bool - if len(endKey) > 0 { - isMatch = func(b []byte) bool { return bytes.Compare(b, endKey) < 0 } - } else { - isMatch = func(b []byte) bool { return bytes.Equal(b, key) } - limit = 1 - } - for ck, cv := c.Seek(key); ck != nil && isMatch(ck); ck, cv = c.Next() { - vs = append(vs, cv) - keys = append(keys, ck) - if limit == int64(len(keys)) { - break - } - } - return keys, vs -} - -// UnsafeDelete must be called holding the lock on the tx. -func (t *batchTx) UnsafeDelete(bucketName []byte, key []byte) { - bucket := t.tx.Bucket(bucketName) - if bucket == nil { - plog.Fatalf("bucket %s does not exist", bucketName) - } - err := bucket.Delete(key) - if err != nil { - plog.Fatalf("cannot delete key from bucket (%v)", err) - } - t.pending++ -} - -// UnsafeForEach must be called holding the lock on the tx. -func (t *batchTx) UnsafeForEach(bucketName []byte, visitor func(k, v []byte) error) error { - return unsafeForEach(t.tx, bucketName, visitor) -} - -func unsafeForEach(tx *bolt.Tx, bucket []byte, visitor func(k, v []byte) error) error { - if b := tx.Bucket(bucket); b != nil { - return b.ForEach(visitor) - } - return nil -} - -// Commit commits a previous tx and begins a new writable one. -func (t *batchTx) Commit() { - t.Lock() - t.commit(false) - t.Unlock() -} - -// CommitAndStop commits the previous tx and does not create a new one. -func (t *batchTx) CommitAndStop() { - t.Lock() - t.commit(true) - t.Unlock() -} - -func (t *batchTx) Unlock() { - if t.pending >= t.backend.batchLimit { - t.commit(false) - } - t.Mutex.Unlock() -} - -func (t *batchTx) commit(stop bool) { - // commit the last tx - if t.tx != nil { - if t.pending == 0 && !stop { - return - } - - start := time.Now() - - // gofail: var beforeCommit struct{} - err := t.tx.Commit() - // gofail: var afterCommit struct{} - - commitDurations.Observe(time.Since(start).Seconds()) - atomic.AddInt64(&t.backend.commits, 1) - - t.pending = 0 - if err != nil { - plog.Fatalf("cannot commit tx (%s)", err) - } - } - if !stop { - t.tx = t.backend.begin(true) - } -} - -type batchTxBuffered struct { - batchTx - buf txWriteBuffer -} - -func newBatchTxBuffered(backend *backend) *batchTxBuffered { - tx := &batchTxBuffered{ - batchTx: batchTx{backend: backend}, - buf: txWriteBuffer{ - txBuffer: txBuffer{make(map[string]*bucketBuffer)}, - seq: true, - }, - } - tx.Commit() - return tx -} - -func (t *batchTxBuffered) Unlock() { - if t.pending != 0 { - t.backend.readTx.mu.Lock() - t.buf.writeback(&t.backend.readTx.buf) - t.backend.readTx.mu.Unlock() - if t.pending >= t.backend.batchLimit { - t.commit(false) - } - } - t.batchTx.Unlock() -} - -func (t *batchTxBuffered) Commit() { - t.Lock() - t.commit(false) - t.Unlock() -} - -func (t *batchTxBuffered) CommitAndStop() { - t.Lock() - t.commit(true) - t.Unlock() -} - -func (t *batchTxBuffered) commit(stop bool) { - // all read txs must be closed to acquire boltdb commit rwlock - t.backend.readTx.mu.Lock() - t.unsafeCommit(stop) - t.backend.readTx.mu.Unlock() -} - -func (t *batchTxBuffered) unsafeCommit(stop bool) { - if t.backend.readTx.tx != nil { - if err := t.backend.readTx.tx.Rollback(); err != nil { - plog.Fatalf("cannot rollback tx (%s)", err) - } - t.backend.readTx.reset() - } - - t.batchTx.commit(stop) - - if !stop { - t.backend.readTx.tx = t.backend.begin(false) - } -} - -func (t *batchTxBuffered) UnsafePut(bucketName []byte, key []byte, value []byte) { - t.batchTx.UnsafePut(bucketName, key, value) - t.buf.put(bucketName, key, value) -} - -func (t *batchTxBuffered) UnsafeSeqPut(bucketName []byte, key []byte, value []byte) { - t.batchTx.UnsafeSeqPut(bucketName, key, value) - t.buf.putSeq(bucketName, key, value) -} diff --git a/vendor/github.com/coreos/etcd/mvcc/backend/config_default.go b/vendor/github.com/coreos/etcd/mvcc/backend/config_default.go deleted file mode 100644 index edfed0025c6c..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/backend/config_default.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !linux,!windows - -package backend - -import bolt "github.com/coreos/bbolt" - -var boltOpenOptions *bolt.Options = nil - -func (bcfg *BackendConfig) mmapSize() int { return int(bcfg.MmapSize) } diff --git a/vendor/github.com/coreos/etcd/mvcc/backend/config_linux.go b/vendor/github.com/coreos/etcd/mvcc/backend/config_linux.go deleted file mode 100644 index b01785f3b339..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/backend/config_linux.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package backend - -import ( - "syscall" - - bolt "github.com/coreos/bbolt" -) - -// syscall.MAP_POPULATE on linux 2.6.23+ does sequential read-ahead -// which can speed up entire-database read with boltdb. We want to -// enable MAP_POPULATE for faster key-value store recovery in storage -// package. If your kernel version is lower than 2.6.23 -// (https://github.com/torvalds/linux/releases/tag/v2.6.23), mmap might -// silently ignore this flag. Please update your kernel to prevent this. -var boltOpenOptions = &bolt.Options{ - MmapFlags: syscall.MAP_POPULATE, - NoFreelistSync: true, -} - -func (bcfg *BackendConfig) mmapSize() int { return int(bcfg.MmapSize) } diff --git a/vendor/github.com/coreos/etcd/mvcc/backend/config_windows.go b/vendor/github.com/coreos/etcd/mvcc/backend/config_windows.go deleted file mode 100644 index 71d02700bcdc..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/backend/config_windows.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build windows - -package backend - -import bolt "github.com/coreos/bbolt" - -var boltOpenOptions *bolt.Options = nil - -// setting mmap size != 0 on windows will allocate the entire -// mmap size for the file, instead of growing it. So, force 0. - -func (bcfg *BackendConfig) mmapSize() int { return 0 } diff --git a/vendor/github.com/coreos/etcd/mvcc/backend/doc.go b/vendor/github.com/coreos/etcd/mvcc/backend/doc.go deleted file mode 100644 index 9cc42fa793cb..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/backend/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package backend defines a standard interface for etcd's backend MVCC storage. -package backend diff --git a/vendor/github.com/coreos/etcd/mvcc/backend/metrics.go b/vendor/github.com/coreos/etcd/mvcc/backend/metrics.go deleted file mode 100644 index 34157080499b..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/backend/metrics.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package backend - -import "github.com/prometheus/client_golang/prometheus" - -var ( - commitDurations = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "disk", - Name: "backend_commit_duration_seconds", - Help: "The latency distributions of commit called by backend.", - - // lowest bucket start of upper bound 0.001 sec (1 ms) with factor 2 - // highest bucket start of 0.001 sec * 2^13 == 8.192 sec - Buckets: prometheus.ExponentialBuckets(0.001, 2, 14), - }) - - defragDurations = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "disk", - Name: "backend_defrag_duration_seconds", - Help: "The latency distribution of backend defragmentation.", - - // 100 MB usually takes 1 sec, so start with 10 MB of 100 ms - // lowest bucket start of upper bound 0.1 sec (100 ms) with factor 2 - // highest bucket start of 0.1 sec * 2^12 == 409.6 sec - Buckets: prometheus.ExponentialBuckets(.1, 2, 13), - }) - - snapshotDurations = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "disk", - Name: "backend_snapshot_duration_seconds", - Help: "The latency distribution of backend snapshots.", - - // lowest bucket start of upper bound 0.01 sec (10 ms) with factor 2 - // highest bucket start of 0.01 sec * 2^16 == 655.36 sec - Buckets: prometheus.ExponentialBuckets(.01, 2, 17), - }) -) - -func init() { - prometheus.MustRegister(commitDurations) - prometheus.MustRegister(defragDurations) - prometheus.MustRegister(snapshotDurations) -} diff --git a/vendor/github.com/coreos/etcd/mvcc/backend/read_tx.go b/vendor/github.com/coreos/etcd/mvcc/backend/read_tx.go deleted file mode 100644 index 0536de70e2bf..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/backend/read_tx.go +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package backend - -import ( - "bytes" - "math" - "sync" - - bolt "github.com/coreos/bbolt" -) - -// safeRangeBucket is a hack to avoid inadvertently reading duplicate keys; -// overwrites on a bucket should only fetch with limit=1, but safeRangeBucket -// is known to never overwrite any key so range is safe. -var safeRangeBucket = []byte("key") - -type ReadTx interface { - Lock() - Unlock() - - UnsafeRange(bucketName []byte, key, endKey []byte, limit int64) (keys [][]byte, vals [][]byte) - UnsafeForEach(bucketName []byte, visitor func(k, v []byte) error) error -} - -type readTx struct { - // mu protects accesses to the txReadBuffer - mu sync.RWMutex - buf txReadBuffer - - // txmu protects accesses to buckets and tx on Range requests. - txmu sync.RWMutex - tx *bolt.Tx - buckets map[string]*bolt.Bucket -} - -func (rt *readTx) Lock() { rt.mu.RLock() } -func (rt *readTx) Unlock() { rt.mu.RUnlock() } - -func (rt *readTx) UnsafeRange(bucketName, key, endKey []byte, limit int64) ([][]byte, [][]byte) { - if endKey == nil { - // forbid duplicates for single keys - limit = 1 - } - if limit <= 0 { - limit = math.MaxInt64 - } - if limit > 1 && !bytes.Equal(bucketName, safeRangeBucket) { - panic("do not use unsafeRange on non-keys bucket") - } - keys, vals := rt.buf.Range(bucketName, key, endKey, limit) - if int64(len(keys)) == limit { - return keys, vals - } - - // find/cache bucket - bn := string(bucketName) - rt.txmu.RLock() - bucket, ok := rt.buckets[bn] - rt.txmu.RUnlock() - if !ok { - rt.txmu.Lock() - bucket = rt.tx.Bucket(bucketName) - rt.buckets[bn] = bucket - rt.txmu.Unlock() - } - - // ignore missing bucket since may have been created in this batch - if bucket == nil { - return keys, vals - } - rt.txmu.Lock() - c := bucket.Cursor() - rt.txmu.Unlock() - - k2, v2 := unsafeRange(c, key, endKey, limit-int64(len(keys))) - return append(k2, keys...), append(v2, vals...) -} - -func (rt *readTx) UnsafeForEach(bucketName []byte, visitor func(k, v []byte) error) error { - dups := make(map[string]struct{}) - getDups := func(k, v []byte) error { - dups[string(k)] = struct{}{} - return nil - } - visitNoDup := func(k, v []byte) error { - if _, ok := dups[string(k)]; ok { - return nil - } - return visitor(k, v) - } - if err := rt.buf.ForEach(bucketName, getDups); err != nil { - return err - } - rt.txmu.Lock() - err := unsafeForEach(rt.tx, bucketName, visitNoDup) - rt.txmu.Unlock() - if err != nil { - return err - } - return rt.buf.ForEach(bucketName, visitor) -} - -func (rt *readTx) reset() { - rt.buf.reset() - rt.buckets = make(map[string]*bolt.Bucket) - rt.tx = nil -} diff --git a/vendor/github.com/coreos/etcd/mvcc/backend/tx_buffer.go b/vendor/github.com/coreos/etcd/mvcc/backend/tx_buffer.go deleted file mode 100644 index 56e885dbfbc3..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/backend/tx_buffer.go +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package backend - -import ( - "bytes" - "sort" -) - -// txBuffer handles functionality shared between txWriteBuffer and txReadBuffer. -type txBuffer struct { - buckets map[string]*bucketBuffer -} - -func (txb *txBuffer) reset() { - for k, v := range txb.buckets { - if v.used == 0 { - // demote - delete(txb.buckets, k) - } - v.used = 0 - } -} - -// txWriteBuffer buffers writes of pending updates that have not yet committed. -type txWriteBuffer struct { - txBuffer - seq bool -} - -func (txw *txWriteBuffer) put(bucket, k, v []byte) { - txw.seq = false - txw.putSeq(bucket, k, v) -} - -func (txw *txWriteBuffer) putSeq(bucket, k, v []byte) { - b, ok := txw.buckets[string(bucket)] - if !ok { - b = newBucketBuffer() - txw.buckets[string(bucket)] = b - } - b.add(k, v) -} - -func (txw *txWriteBuffer) writeback(txr *txReadBuffer) { - for k, wb := range txw.buckets { - rb, ok := txr.buckets[k] - if !ok { - delete(txw.buckets, k) - txr.buckets[k] = wb - continue - } - if !txw.seq && wb.used > 1 { - // assume no duplicate keys - sort.Sort(wb) - } - rb.merge(wb) - } - txw.reset() -} - -// txReadBuffer accesses buffered updates. -type txReadBuffer struct{ txBuffer } - -func (txr *txReadBuffer) Range(bucketName, key, endKey []byte, limit int64) ([][]byte, [][]byte) { - if b := txr.buckets[string(bucketName)]; b != nil { - return b.Range(key, endKey, limit) - } - return nil, nil -} - -func (txr *txReadBuffer) ForEach(bucketName []byte, visitor func(k, v []byte) error) error { - if b := txr.buckets[string(bucketName)]; b != nil { - return b.ForEach(visitor) - } - return nil -} - -type kv struct { - key []byte - val []byte -} - -// bucketBuffer buffers key-value pairs that are pending commit. -type bucketBuffer struct { - buf []kv - // used tracks number of elements in use so buf can be reused without reallocation. - used int -} - -func newBucketBuffer() *bucketBuffer { - return &bucketBuffer{buf: make([]kv, 512), used: 0} -} - -func (bb *bucketBuffer) Range(key, endKey []byte, limit int64) (keys [][]byte, vals [][]byte) { - f := func(i int) bool { return bytes.Compare(bb.buf[i].key, key) >= 0 } - idx := sort.Search(bb.used, f) - if idx < 0 { - return nil, nil - } - if len(endKey) == 0 { - if bytes.Equal(key, bb.buf[idx].key) { - keys = append(keys, bb.buf[idx].key) - vals = append(vals, bb.buf[idx].val) - } - return keys, vals - } - if bytes.Compare(endKey, bb.buf[idx].key) <= 0 { - return nil, nil - } - for i := idx; i < bb.used && int64(len(keys)) < limit; i++ { - if bytes.Compare(endKey, bb.buf[i].key) <= 0 { - break - } - keys = append(keys, bb.buf[i].key) - vals = append(vals, bb.buf[i].val) - } - return keys, vals -} - -func (bb *bucketBuffer) ForEach(visitor func(k, v []byte) error) error { - for i := 0; i < bb.used; i++ { - if err := visitor(bb.buf[i].key, bb.buf[i].val); err != nil { - return err - } - } - return nil -} - -func (bb *bucketBuffer) add(k, v []byte) { - bb.buf[bb.used].key, bb.buf[bb.used].val = k, v - bb.used++ - if bb.used == len(bb.buf) { - buf := make([]kv, (3*len(bb.buf))/2) - copy(buf, bb.buf) - bb.buf = buf - } -} - -// merge merges data from bb into bbsrc. -func (bb *bucketBuffer) merge(bbsrc *bucketBuffer) { - for i := 0; i < bbsrc.used; i++ { - bb.add(bbsrc.buf[i].key, bbsrc.buf[i].val) - } - if bb.used == bbsrc.used { - return - } - if bytes.Compare(bb.buf[(bb.used-bbsrc.used)-1].key, bbsrc.buf[0].key) < 0 { - return - } - - sort.Stable(bb) - - // remove duplicates, using only newest update - widx := 0 - for ridx := 1; ridx < bb.used; ridx++ { - if !bytes.Equal(bb.buf[ridx].key, bb.buf[widx].key) { - widx++ - } - bb.buf[widx] = bb.buf[ridx] - } - bb.used = widx + 1 -} - -func (bb *bucketBuffer) Len() int { return bb.used } -func (bb *bucketBuffer) Less(i, j int) bool { - return bytes.Compare(bb.buf[i].key, bb.buf[j].key) < 0 -} -func (bb *bucketBuffer) Swap(i, j int) { bb.buf[i], bb.buf[j] = bb.buf[j], bb.buf[i] } diff --git a/vendor/github.com/coreos/etcd/mvcc/doc.go b/vendor/github.com/coreos/etcd/mvcc/doc.go deleted file mode 100644 index ad5be03086fb..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package mvcc defines etcd's stable MVCC storage. -package mvcc diff --git a/vendor/github.com/coreos/etcd/mvcc/index.go b/vendor/github.com/coreos/etcd/mvcc/index.go deleted file mode 100644 index b27a9e543395..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/index.go +++ /dev/null @@ -1,251 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "sort" - "sync" - - "github.com/google/btree" -) - -type index interface { - Get(key []byte, atRev int64) (rev, created revision, ver int64, err error) - Range(key, end []byte, atRev int64) ([][]byte, []revision) - Revisions(key, end []byte, atRev int64) []revision - Put(key []byte, rev revision) - Tombstone(key []byte, rev revision) error - RangeSince(key, end []byte, rev int64) []revision - Compact(rev int64) map[revision]struct{} - Keep(rev int64) map[revision]struct{} - Equal(b index) bool - - Insert(ki *keyIndex) - KeyIndex(ki *keyIndex) *keyIndex -} - -type treeIndex struct { - sync.RWMutex - tree *btree.BTree -} - -func newTreeIndex() index { - return &treeIndex{ - tree: btree.New(32), - } -} - -func (ti *treeIndex) Put(key []byte, rev revision) { - keyi := &keyIndex{key: key} - - ti.Lock() - defer ti.Unlock() - item := ti.tree.Get(keyi) - if item == nil { - keyi.put(rev.main, rev.sub) - ti.tree.ReplaceOrInsert(keyi) - return - } - okeyi := item.(*keyIndex) - okeyi.put(rev.main, rev.sub) -} - -func (ti *treeIndex) Get(key []byte, atRev int64) (modified, created revision, ver int64, err error) { - keyi := &keyIndex{key: key} - ti.RLock() - defer ti.RUnlock() - if keyi = ti.keyIndex(keyi); keyi == nil { - return revision{}, revision{}, 0, ErrRevisionNotFound - } - return keyi.get(atRev) -} - -func (ti *treeIndex) KeyIndex(keyi *keyIndex) *keyIndex { - ti.RLock() - defer ti.RUnlock() - return ti.keyIndex(keyi) -} - -func (ti *treeIndex) keyIndex(keyi *keyIndex) *keyIndex { - if item := ti.tree.Get(keyi); item != nil { - return item.(*keyIndex) - } - return nil -} - -func (ti *treeIndex) visit(key, end []byte, f func(ki *keyIndex)) { - keyi, endi := &keyIndex{key: key}, &keyIndex{key: end} - - ti.RLock() - defer ti.RUnlock() - - ti.tree.AscendGreaterOrEqual(keyi, func(item btree.Item) bool { - if len(endi.key) > 0 && !item.Less(endi) { - return false - } - f(item.(*keyIndex)) - return true - }) -} - -func (ti *treeIndex) Revisions(key, end []byte, atRev int64) (revs []revision) { - if end == nil { - rev, _, _, err := ti.Get(key, atRev) - if err != nil { - return nil - } - return []revision{rev} - } - ti.visit(key, end, func(ki *keyIndex) { - if rev, _, _, err := ki.get(atRev); err == nil { - revs = append(revs, rev) - } - }) - return revs -} - -func (ti *treeIndex) Range(key, end []byte, atRev int64) (keys [][]byte, revs []revision) { - if end == nil { - rev, _, _, err := ti.Get(key, atRev) - if err != nil { - return nil, nil - } - return [][]byte{key}, []revision{rev} - } - ti.visit(key, end, func(ki *keyIndex) { - if rev, _, _, err := ki.get(atRev); err == nil { - revs = append(revs, rev) - keys = append(keys, ki.key) - } - }) - return keys, revs -} - -func (ti *treeIndex) Tombstone(key []byte, rev revision) error { - keyi := &keyIndex{key: key} - - ti.Lock() - defer ti.Unlock() - item := ti.tree.Get(keyi) - if item == nil { - return ErrRevisionNotFound - } - - ki := item.(*keyIndex) - return ki.tombstone(rev.main, rev.sub) -} - -// RangeSince returns all revisions from key(including) to end(excluding) -// at or after the given rev. The returned slice is sorted in the order -// of revision. -func (ti *treeIndex) RangeSince(key, end []byte, rev int64) []revision { - keyi := &keyIndex{key: key} - - ti.RLock() - defer ti.RUnlock() - - if end == nil { - item := ti.tree.Get(keyi) - if item == nil { - return nil - } - keyi = item.(*keyIndex) - return keyi.since(rev) - } - - endi := &keyIndex{key: end} - var revs []revision - ti.tree.AscendGreaterOrEqual(keyi, func(item btree.Item) bool { - if len(endi.key) > 0 && !item.Less(endi) { - return false - } - curKeyi := item.(*keyIndex) - revs = append(revs, curKeyi.since(rev)...) - return true - }) - sort.Sort(revisions(revs)) - - return revs -} - -func (ti *treeIndex) Compact(rev int64) map[revision]struct{} { - available := make(map[revision]struct{}) - var emptyki []*keyIndex - plog.Printf("store.index: compact %d", rev) - // TODO: do not hold the lock for long time? - // This is probably OK. Compacting 10M keys takes O(10ms). - ti.Lock() - defer ti.Unlock() - ti.tree.Ascend(compactIndex(rev, available, &emptyki)) - for _, ki := range emptyki { - item := ti.tree.Delete(ki) - if item == nil { - plog.Panic("store.index: unexpected delete failure during compaction") - } - } - return available -} - -// Keep finds all revisions to be kept for a Compaction at the given rev. -func (ti *treeIndex) Keep(rev int64) map[revision]struct{} { - available := make(map[revision]struct{}) - ti.RLock() - defer ti.RUnlock() - ti.tree.Ascend(func(i btree.Item) bool { - keyi := i.(*keyIndex) - keyi.keep(rev, available) - return true - }) - return available -} - -func compactIndex(rev int64, available map[revision]struct{}, emptyki *[]*keyIndex) func(i btree.Item) bool { - return func(i btree.Item) bool { - keyi := i.(*keyIndex) - keyi.compact(rev, available) - if keyi.isEmpty() { - *emptyki = append(*emptyki, keyi) - } - return true - } -} - -func (ti *treeIndex) Equal(bi index) bool { - b := bi.(*treeIndex) - - if ti.tree.Len() != b.tree.Len() { - return false - } - - equal := true - - ti.tree.Ascend(func(item btree.Item) bool { - aki := item.(*keyIndex) - bki := b.tree.Get(item).(*keyIndex) - if !aki.equal(bki) { - equal = false - return false - } - return true - }) - - return equal -} - -func (ti *treeIndex) Insert(ki *keyIndex) { - ti.Lock() - defer ti.Unlock() - ti.tree.ReplaceOrInsert(ki) -} diff --git a/vendor/github.com/coreos/etcd/mvcc/key_index.go b/vendor/github.com/coreos/etcd/mvcc/key_index.go deleted file mode 100644 index 805922bfc9a3..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/key_index.go +++ /dev/null @@ -1,356 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "bytes" - "errors" - "fmt" - - "github.com/google/btree" -) - -var ( - ErrRevisionNotFound = errors.New("mvcc: revision not found") -) - -// keyIndex stores the revisions of a key in the backend. -// Each keyIndex has at least one key generation. -// Each generation might have several key versions. -// Tombstone on a key appends an tombstone version at the end -// of the current generation and creates a new empty generation. -// Each version of a key has an index pointing to the backend. -// -// For example: put(1.0);put(2.0);tombstone(3.0);put(4.0);tombstone(5.0) on key "foo" -// generate a keyIndex: -// key: "foo" -// rev: 5 -// generations: -// {empty} -// {4.0, 5.0(t)} -// {1.0, 2.0, 3.0(t)} -// -// Compact a keyIndex removes the versions with smaller or equal to -// rev except the largest one. If the generation becomes empty -// during compaction, it will be removed. if all the generations get -// removed, the keyIndex should be removed. -// -// For example: -// compact(2) on the previous example -// generations: -// {empty} -// {4.0, 5.0(t)} -// {2.0, 3.0(t)} -// -// compact(4) -// generations: -// {empty} -// {4.0, 5.0(t)} -// -// compact(5): -// generations: -// {empty} -> key SHOULD be removed. -// -// compact(6): -// generations: -// {empty} -> key SHOULD be removed. -type keyIndex struct { - key []byte - modified revision // the main rev of the last modification - generations []generation -} - -// put puts a revision to the keyIndex. -func (ki *keyIndex) put(main int64, sub int64) { - rev := revision{main: main, sub: sub} - - if !rev.GreaterThan(ki.modified) { - plog.Panicf("store.keyindex: put with unexpected smaller revision [%v / %v]", rev, ki.modified) - } - if len(ki.generations) == 0 { - ki.generations = append(ki.generations, generation{}) - } - g := &ki.generations[len(ki.generations)-1] - if len(g.revs) == 0 { // create a new key - keysGauge.Inc() - g.created = rev - } - g.revs = append(g.revs, rev) - g.ver++ - ki.modified = rev -} - -func (ki *keyIndex) restore(created, modified revision, ver int64) { - if len(ki.generations) != 0 { - plog.Panicf("store.keyindex: cannot restore non-empty keyIndex") - } - - ki.modified = modified - g := generation{created: created, ver: ver, revs: []revision{modified}} - ki.generations = append(ki.generations, g) - keysGauge.Inc() -} - -// tombstone puts a revision, pointing to a tombstone, to the keyIndex. -// It also creates a new empty generation in the keyIndex. -// It returns ErrRevisionNotFound when tombstone on an empty generation. -func (ki *keyIndex) tombstone(main int64, sub int64) error { - if ki.isEmpty() { - plog.Panicf("store.keyindex: unexpected tombstone on empty keyIndex %s", string(ki.key)) - } - if ki.generations[len(ki.generations)-1].isEmpty() { - return ErrRevisionNotFound - } - ki.put(main, sub) - ki.generations = append(ki.generations, generation{}) - keysGauge.Dec() - return nil -} - -// get gets the modified, created revision and version of the key that satisfies the given atRev. -// Rev must be higher than or equal to the given atRev. -func (ki *keyIndex) get(atRev int64) (modified, created revision, ver int64, err error) { - if ki.isEmpty() { - plog.Panicf("store.keyindex: unexpected get on empty keyIndex %s", string(ki.key)) - } - g := ki.findGeneration(atRev) - if g.isEmpty() { - return revision{}, revision{}, 0, ErrRevisionNotFound - } - - n := g.walk(func(rev revision) bool { return rev.main > atRev }) - if n != -1 { - return g.revs[n], g.created, g.ver - int64(len(g.revs)-n-1), nil - } - - return revision{}, revision{}, 0, ErrRevisionNotFound -} - -// since returns revisions since the given rev. Only the revision with the -// largest sub revision will be returned if multiple revisions have the same -// main revision. -func (ki *keyIndex) since(rev int64) []revision { - if ki.isEmpty() { - plog.Panicf("store.keyindex: unexpected get on empty keyIndex %s", string(ki.key)) - } - since := revision{rev, 0} - var gi int - // find the generations to start checking - for gi = len(ki.generations) - 1; gi > 0; gi-- { - g := ki.generations[gi] - if g.isEmpty() { - continue - } - if since.GreaterThan(g.created) { - break - } - } - - var revs []revision - var last int64 - for ; gi < len(ki.generations); gi++ { - for _, r := range ki.generations[gi].revs { - if since.GreaterThan(r) { - continue - } - if r.main == last { - // replace the revision with a new one that has higher sub value, - // because the original one should not be seen by external - revs[len(revs)-1] = r - continue - } - revs = append(revs, r) - last = r.main - } - } - return revs -} - -// compact compacts a keyIndex by removing the versions with smaller or equal -// revision than the given atRev except the largest one (If the largest one is -// a tombstone, it will not be kept). -// If a generation becomes empty during compaction, it will be removed. -func (ki *keyIndex) compact(atRev int64, available map[revision]struct{}) { - if ki.isEmpty() { - plog.Panicf("store.keyindex: unexpected compact on empty keyIndex %s", string(ki.key)) - } - - genIdx, revIndex := ki.doCompact(atRev, available) - - g := &ki.generations[genIdx] - if !g.isEmpty() { - // remove the previous contents. - if revIndex != -1 { - g.revs = g.revs[revIndex:] - } - // remove any tombstone - if len(g.revs) == 1 && genIdx != len(ki.generations)-1 { - delete(available, g.revs[0]) - genIdx++ - } - } - - // remove the previous generations. - ki.generations = ki.generations[genIdx:] -} - -// keep finds the revision to be kept if compact is called at given atRev. -func (ki *keyIndex) keep(atRev int64, available map[revision]struct{}) { - if ki.isEmpty() { - return - } - - genIdx, revIndex := ki.doCompact(atRev, available) - g := &ki.generations[genIdx] - if !g.isEmpty() { - // remove any tombstone - if revIndex == len(g.revs)-1 && genIdx != len(ki.generations)-1 { - delete(available, g.revs[revIndex]) - } - } -} - -func (ki *keyIndex) doCompact(atRev int64, available map[revision]struct{}) (genIdx int, revIndex int) { - // walk until reaching the first revision smaller or equal to "atRev", - // and add the revision to the available map - f := func(rev revision) bool { - if rev.main <= atRev { - available[rev] = struct{}{} - return false - } - return true - } - - genIdx, g := 0, &ki.generations[0] - // find first generation includes atRev or created after atRev - for genIdx < len(ki.generations)-1 { - if tomb := g.revs[len(g.revs)-1].main; tomb > atRev { - break - } - genIdx++ - g = &ki.generations[genIdx] - } - - revIndex = g.walk(f) - - return genIdx, revIndex -} - -func (ki *keyIndex) isEmpty() bool { - return len(ki.generations) == 1 && ki.generations[0].isEmpty() -} - -// findGeneration finds out the generation of the keyIndex that the -// given rev belongs to. If the given rev is at the gap of two generations, -// which means that the key does not exist at the given rev, it returns nil. -func (ki *keyIndex) findGeneration(rev int64) *generation { - lastg := len(ki.generations) - 1 - cg := lastg - - for cg >= 0 { - if len(ki.generations[cg].revs) == 0 { - cg-- - continue - } - g := ki.generations[cg] - if cg != lastg { - if tomb := g.revs[len(g.revs)-1].main; tomb <= rev { - return nil - } - } - if g.revs[0].main <= rev { - return &ki.generations[cg] - } - cg-- - } - return nil -} - -func (a *keyIndex) Less(b btree.Item) bool { - return bytes.Compare(a.key, b.(*keyIndex).key) == -1 -} - -func (a *keyIndex) equal(b *keyIndex) bool { - if !bytes.Equal(a.key, b.key) { - return false - } - if a.modified != b.modified { - return false - } - if len(a.generations) != len(b.generations) { - return false - } - for i := range a.generations { - ag, bg := a.generations[i], b.generations[i] - if !ag.equal(bg) { - return false - } - } - return true -} - -func (ki *keyIndex) String() string { - var s string - for _, g := range ki.generations { - s += g.String() - } - return s -} - -// generation contains multiple revisions of a key. -type generation struct { - ver int64 - created revision // when the generation is created (put in first revision). - revs []revision -} - -func (g *generation) isEmpty() bool { return g == nil || len(g.revs) == 0 } - -// walk walks through the revisions in the generation in descending order. -// It passes the revision to the given function. -// walk returns until: 1. it finishes walking all pairs 2. the function returns false. -// walk returns the position at where it stopped. If it stopped after -// finishing walking, -1 will be returned. -func (g *generation) walk(f func(rev revision) bool) int { - l := len(g.revs) - for i := range g.revs { - ok := f(g.revs[l-i-1]) - if !ok { - return l - i - 1 - } - } - return -1 -} - -func (g *generation) String() string { - return fmt.Sprintf("g: created[%d] ver[%d], revs %#v\n", g.created, g.ver, g.revs) -} - -func (a generation) equal(b generation) bool { - if a.ver != b.ver { - return false - } - if len(a.revs) != len(b.revs) { - return false - } - - for i := range a.revs { - ar, br := a.revs[i], b.revs[i] - if ar != br { - return false - } - } - return true -} diff --git a/vendor/github.com/coreos/etcd/mvcc/kv.go b/vendor/github.com/coreos/etcd/mvcc/kv.go deleted file mode 100644 index 2dad3ad8ef0a..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/kv.go +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -type RangeOptions struct { - Limit int64 - Rev int64 - Count bool -} - -type RangeResult struct { - KVs []mvccpb.KeyValue - Rev int64 - Count int -} - -type ReadView interface { - // FirstRev returns the first KV revision at the time of opening the txn. - // After a compaction, the first revision increases to the compaction - // revision. - FirstRev() int64 - - // Rev returns the revision of the KV at the time of opening the txn. - Rev() int64 - - // Range gets the keys in the range at rangeRev. - // The returned rev is the current revision of the KV when the operation is executed. - // If rangeRev <=0, range gets the keys at currentRev. - // If `end` is nil, the request returns the key. - // If `end` is not nil and not empty, it gets the keys in range [key, range_end). - // If `end` is not nil and empty, it gets the keys greater than or equal to key. - // Limit limits the number of keys returned. - // If the required rev is compacted, ErrCompacted will be returned. - Range(key, end []byte, ro RangeOptions) (r *RangeResult, err error) -} - -// TxnRead represents a read-only transaction with operations that will not -// block other read transactions. -type TxnRead interface { - ReadView - // End marks the transaction is complete and ready to commit. - End() -} - -type WriteView interface { - // DeleteRange deletes the given range from the store. - // A deleteRange increases the rev of the store if any key in the range exists. - // The number of key deleted will be returned. - // The returned rev is the current revision of the KV when the operation is executed. - // It also generates one event for each key delete in the event history. - // if the `end` is nil, deleteRange deletes the key. - // if the `end` is not nil, deleteRange deletes the keys in range [key, range_end). - DeleteRange(key, end []byte) (n, rev int64) - - // Put puts the given key, value into the store. Put also takes additional argument lease to - // attach a lease to a key-value pair as meta-data. KV implementation does not validate the lease - // id. - // A put also increases the rev of the store, and generates one event in the event history. - // The returned rev is the current revision of the KV when the operation is executed. - Put(key, value []byte, lease lease.LeaseID) (rev int64) -} - -// TxnWrite represents a transaction that can modify the store. -type TxnWrite interface { - TxnRead - WriteView - // Changes gets the changes made since opening the write txn. - Changes() []mvccpb.KeyValue -} - -// txnReadWrite coerces a read txn to a write, panicking on any write operation. -type txnReadWrite struct{ TxnRead } - -func (trw *txnReadWrite) DeleteRange(key, end []byte) (n, rev int64) { panic("unexpected DeleteRange") } -func (trw *txnReadWrite) Put(key, value []byte, lease lease.LeaseID) (rev int64) { - panic("unexpected Put") -} -func (trw *txnReadWrite) Changes() []mvccpb.KeyValue { return nil } - -func NewReadOnlyTxnWrite(txn TxnRead) TxnWrite { return &txnReadWrite{txn} } - -type KV interface { - ReadView - WriteView - - // Read creates a read transaction. - Read() TxnRead - - // Write creates a write transaction. - Write() TxnWrite - - // Hash computes the hash of the KV's backend. - Hash() (hash uint32, revision int64, err error) - - // HashByRev computes the hash of all MVCC revisions up to a given revision. - HashByRev(rev int64) (hash uint32, revision int64, compactRev int64, err error) - - // Compact frees all superseded keys with revisions less than rev. - Compact(rev int64) (<-chan struct{}, error) - - // Commit commits outstanding txns into the underlying backend. - Commit() - - // Restore restores the KV store from a backend. - Restore(b backend.Backend) error - Close() error -} - -// WatchableKV is a KV that can be watched. -type WatchableKV interface { - KV - Watchable -} - -// Watchable is the interface that wraps the NewWatchStream function. -type Watchable interface { - // NewWatchStream returns a WatchStream that can be used to - // watch events happened or happening on the KV. - NewWatchStream() WatchStream -} - -// ConsistentWatchableKV is a WatchableKV that understands the consistency -// algorithm and consistent index. -// If the consistent index of executing entry is not larger than the -// consistent index of ConsistentWatchableKV, all operations in -// this entry are skipped and return empty response. -type ConsistentWatchableKV interface { - WatchableKV - // ConsistentIndex returns the current consistent index of the KV. - ConsistentIndex() uint64 -} diff --git a/vendor/github.com/coreos/etcd/mvcc/kv_view.go b/vendor/github.com/coreos/etcd/mvcc/kv_view.go deleted file mode 100644 index f40ba8edc22b..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/kv_view.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "github.com/coreos/etcd/lease" -) - -type readView struct{ kv KV } - -func (rv *readView) FirstRev() int64 { - tr := rv.kv.Read() - defer tr.End() - return tr.FirstRev() -} - -func (rv *readView) Rev() int64 { - tr := rv.kv.Read() - defer tr.End() - return tr.Rev() -} - -func (rv *readView) Range(key, end []byte, ro RangeOptions) (r *RangeResult, err error) { - tr := rv.kv.Read() - defer tr.End() - return tr.Range(key, end, ro) -} - -type writeView struct{ kv KV } - -func (wv *writeView) DeleteRange(key, end []byte) (n, rev int64) { - tw := wv.kv.Write() - defer tw.End() - return tw.DeleteRange(key, end) -} - -func (wv *writeView) Put(key, value []byte, lease lease.LeaseID) (rev int64) { - tw := wv.kv.Write() - defer tw.End() - return tw.Put(key, value, lease) -} diff --git a/vendor/github.com/coreos/etcd/mvcc/kvstore.go b/vendor/github.com/coreos/etcd/mvcc/kvstore.go deleted file mode 100644 index dd9f04ae2113..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/kvstore.go +++ /dev/null @@ -1,510 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "context" - "encoding/binary" - "errors" - "hash/crc32" - "math" - "sync" - "sync/atomic" - "time" - - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/mvcc/mvccpb" - "github.com/coreos/etcd/pkg/schedule" - "github.com/coreos/pkg/capnslog" -) - -var ( - keyBucketName = []byte("key") - metaBucketName = []byte("meta") - - consistentIndexKeyName = []byte("consistent_index") - scheduledCompactKeyName = []byte("scheduledCompactRev") - finishedCompactKeyName = []byte("finishedCompactRev") - - ErrCompacted = errors.New("mvcc: required revision has been compacted") - ErrFutureRev = errors.New("mvcc: required revision is a future revision") - ErrCanceled = errors.New("mvcc: watcher is canceled") - ErrClosed = errors.New("mvcc: closed") - - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "mvcc") -) - -const ( - // markedRevBytesLen is the byte length of marked revision. - // The first `revBytesLen` bytes represents a normal revision. The last - // one byte is the mark. - markedRevBytesLen = revBytesLen + 1 - markBytePosition = markedRevBytesLen - 1 - markTombstone byte = 't' -) - -var restoreChunkKeys = 10000 // non-const for testing - -// ConsistentIndexGetter is an interface that wraps the Get method. -// Consistent index is the offset of an entry in a consistent replicated log. -type ConsistentIndexGetter interface { - // ConsistentIndex returns the consistent index of current executing entry. - ConsistentIndex() uint64 -} - -type store struct { - ReadView - WriteView - - // consistentIndex caches the "consistent_index" key's value. Accessed - // through atomics so must be 64-bit aligned. - consistentIndex uint64 - - // mu read locks for txns and write locks for non-txn store changes. - mu sync.RWMutex - - ig ConsistentIndexGetter - - b backend.Backend - kvindex index - - le lease.Lessor - - // revMuLock protects currentRev and compactMainRev. - // Locked at end of write txn and released after write txn unlock lock. - // Locked before locking read txn and released after locking. - revMu sync.RWMutex - // currentRev is the revision of the last completed transaction. - currentRev int64 - // compactMainRev is the main revision of the last compaction. - compactMainRev int64 - - // bytesBuf8 is a byte slice of length 8 - // to avoid a repetitive allocation in saveIndex. - bytesBuf8 []byte - - fifoSched schedule.Scheduler - - stopc chan struct{} -} - -// NewStore returns a new store. It is useful to create a store inside -// mvcc pkg. It should only be used for testing externally. -func NewStore(b backend.Backend, le lease.Lessor, ig ConsistentIndexGetter) *store { - s := &store{ - b: b, - ig: ig, - kvindex: newTreeIndex(), - - le: le, - - currentRev: 1, - compactMainRev: -1, - - bytesBuf8: make([]byte, 8), - fifoSched: schedule.NewFIFOScheduler(), - - stopc: make(chan struct{}), - } - s.ReadView = &readView{s} - s.WriteView = &writeView{s} - if s.le != nil { - s.le.SetRangeDeleter(func() lease.TxnDelete { return s.Write() }) - } - - tx := s.b.BatchTx() - tx.Lock() - tx.UnsafeCreateBucket(keyBucketName) - tx.UnsafeCreateBucket(metaBucketName) - tx.Unlock() - s.b.ForceCommit() - - if err := s.restore(); err != nil { - // TODO: return the error instead of panic here? - panic("failed to recover store from backend") - } - - return s -} - -func (s *store) compactBarrier(ctx context.Context, ch chan struct{}) { - if ctx == nil || ctx.Err() != nil { - s.mu.Lock() - select { - case <-s.stopc: - default: - f := func(ctx context.Context) { s.compactBarrier(ctx, ch) } - s.fifoSched.Schedule(f) - } - s.mu.Unlock() - return - } - close(ch) -} - -func (s *store) Hash() (hash uint32, revision int64, err error) { - start := time.Now() - - s.b.ForceCommit() - h, err := s.b.Hash(DefaultIgnores) - - hashDurations.Observe(time.Since(start).Seconds()) - return h, s.currentRev, err -} - -func (s *store) HashByRev(rev int64) (hash uint32, currentRev int64, compactRev int64, err error) { - start := time.Now() - - s.mu.RLock() - s.revMu.RLock() - compactRev, currentRev = s.compactMainRev, s.currentRev - s.revMu.RUnlock() - - if rev > 0 && rev <= compactRev { - s.mu.RUnlock() - return 0, 0, compactRev, ErrCompacted - } else if rev > 0 && rev > currentRev { - s.mu.RUnlock() - return 0, currentRev, 0, ErrFutureRev - } - - if rev == 0 { - rev = currentRev - } - keep := s.kvindex.Keep(rev) - - tx := s.b.ReadTx() - tx.Lock() - defer tx.Unlock() - s.mu.RUnlock() - - upper := revision{main: rev + 1} - lower := revision{main: compactRev + 1} - h := crc32.New(crc32.MakeTable(crc32.Castagnoli)) - - h.Write(keyBucketName) - err = tx.UnsafeForEach(keyBucketName, func(k, v []byte) error { - kr := bytesToRev(k) - if !upper.GreaterThan(kr) { - return nil - } - // skip revisions that are scheduled for deletion - // due to compacting; don't skip if there isn't one. - if lower.GreaterThan(kr) && len(keep) > 0 { - if _, ok := keep[kr]; !ok { - return nil - } - } - h.Write(k) - h.Write(v) - return nil - }) - hash = h.Sum32() - - hashRevDurations.Observe(time.Since(start).Seconds()) - return hash, currentRev, compactRev, err -} - -func (s *store) Compact(rev int64) (<-chan struct{}, error) { - s.mu.Lock() - defer s.mu.Unlock() - s.revMu.Lock() - defer s.revMu.Unlock() - - if rev <= s.compactMainRev { - ch := make(chan struct{}) - f := func(ctx context.Context) { s.compactBarrier(ctx, ch) } - s.fifoSched.Schedule(f) - return ch, ErrCompacted - } - if rev > s.currentRev { - return nil, ErrFutureRev - } - - start := time.Now() - - s.compactMainRev = rev - - rbytes := newRevBytes() - revToBytes(revision{main: rev}, rbytes) - - tx := s.b.BatchTx() - tx.Lock() - tx.UnsafePut(metaBucketName, scheduledCompactKeyName, rbytes) - tx.Unlock() - // ensure that desired compaction is persisted - s.b.ForceCommit() - - keep := s.kvindex.Compact(rev) - ch := make(chan struct{}) - var j = func(ctx context.Context) { - if ctx.Err() != nil { - s.compactBarrier(ctx, ch) - return - } - if !s.scheduleCompaction(rev, keep) { - s.compactBarrier(nil, ch) - return - } - close(ch) - } - - s.fifoSched.Schedule(j) - - indexCompactionPauseDurations.Observe(float64(time.Since(start) / time.Millisecond)) - return ch, nil -} - -// DefaultIgnores is a map of keys to ignore in hash checking. -var DefaultIgnores map[backend.IgnoreKey]struct{} - -func init() { - DefaultIgnores = map[backend.IgnoreKey]struct{}{ - // consistent index might be changed due to v2 internal sync, which - // is not controllable by the user. - {Bucket: string(metaBucketName), Key: string(consistentIndexKeyName)}: {}, - } -} - -func (s *store) Commit() { - s.mu.Lock() - defer s.mu.Unlock() - - tx := s.b.BatchTx() - tx.Lock() - s.saveIndex(tx) - tx.Unlock() - s.b.ForceCommit() -} - -func (s *store) Restore(b backend.Backend) error { - s.mu.Lock() - defer s.mu.Unlock() - - close(s.stopc) - s.fifoSched.Stop() - - atomic.StoreUint64(&s.consistentIndex, 0) - s.b = b - s.kvindex = newTreeIndex() - s.currentRev = 1 - s.compactMainRev = -1 - s.fifoSched = schedule.NewFIFOScheduler() - s.stopc = make(chan struct{}) - - return s.restore() -} - -func (s *store) restore() error { - b := s.b - - reportDbTotalSizeInBytesMu.Lock() - reportDbTotalSizeInBytes = func() float64 { return float64(b.Size()) } - reportDbTotalSizeInBytesMu.Unlock() - reportDbTotalSizeInUseInBytesMu.Lock() - reportDbTotalSizeInUseInBytes = func() float64 { return float64(b.SizeInUse()) } - reportDbTotalSizeInUseInBytesMu.Unlock() - - min, max := newRevBytes(), newRevBytes() - revToBytes(revision{main: 1}, min) - revToBytes(revision{main: math.MaxInt64, sub: math.MaxInt64}, max) - - keyToLease := make(map[string]lease.LeaseID) - - // restore index - tx := s.b.BatchTx() - tx.Lock() - - _, finishedCompactBytes := tx.UnsafeRange(metaBucketName, finishedCompactKeyName, nil, 0) - if len(finishedCompactBytes) != 0 { - s.compactMainRev = bytesToRev(finishedCompactBytes[0]).main - plog.Printf("restore compact to %d", s.compactMainRev) - } - _, scheduledCompactBytes := tx.UnsafeRange(metaBucketName, scheduledCompactKeyName, nil, 0) - scheduledCompact := int64(0) - if len(scheduledCompactBytes) != 0 { - scheduledCompact = bytesToRev(scheduledCompactBytes[0]).main - } - - // index keys concurrently as they're loaded in from tx - keysGauge.Set(0) - rkvc, revc := restoreIntoIndex(s.kvindex) - for { - keys, vals := tx.UnsafeRange(keyBucketName, min, max, int64(restoreChunkKeys)) - if len(keys) == 0 { - break - } - // rkvc blocks if the total pending keys exceeds the restore - // chunk size to keep keys from consuming too much memory. - restoreChunk(rkvc, keys, vals, keyToLease) - if len(keys) < restoreChunkKeys { - // partial set implies final set - break - } - // next set begins after where this one ended - newMin := bytesToRev(keys[len(keys)-1][:revBytesLen]) - newMin.sub++ - revToBytes(newMin, min) - } - close(rkvc) - s.currentRev = <-revc - - // keys in the range [compacted revision -N, compaction] might all be deleted due to compaction. - // the correct revision should be set to compaction revision in the case, not the largest revision - // we have seen. - if s.currentRev < s.compactMainRev { - s.currentRev = s.compactMainRev - } - if scheduledCompact <= s.compactMainRev { - scheduledCompact = 0 - } - - for key, lid := range keyToLease { - if s.le == nil { - panic("no lessor to attach lease") - } - err := s.le.Attach(lid, []lease.LeaseItem{{Key: key}}) - if err != nil { - plog.Errorf("unexpected Attach error: %v", err) - } - } - - tx.Unlock() - - if scheduledCompact != 0 { - s.Compact(scheduledCompact) - plog.Printf("resume scheduled compaction at %d", scheduledCompact) - } - - return nil -} - -type revKeyValue struct { - key []byte - kv mvccpb.KeyValue - kstr string -} - -func restoreIntoIndex(idx index) (chan<- revKeyValue, <-chan int64) { - rkvc, revc := make(chan revKeyValue, restoreChunkKeys), make(chan int64, 1) - go func() { - currentRev := int64(1) - defer func() { revc <- currentRev }() - // restore the tree index from streaming the unordered index. - kiCache := make(map[string]*keyIndex, restoreChunkKeys) - for rkv := range rkvc { - ki, ok := kiCache[rkv.kstr] - // purge kiCache if many keys but still missing in the cache - if !ok && len(kiCache) >= restoreChunkKeys { - i := 10 - for k := range kiCache { - delete(kiCache, k) - if i--; i == 0 { - break - } - } - } - // cache miss, fetch from tree index if there - if !ok { - ki = &keyIndex{key: rkv.kv.Key} - if idxKey := idx.KeyIndex(ki); idxKey != nil { - kiCache[rkv.kstr], ki = idxKey, idxKey - ok = true - } - } - rev := bytesToRev(rkv.key) - currentRev = rev.main - if ok { - if isTombstone(rkv.key) { - ki.tombstone(rev.main, rev.sub) - continue - } - ki.put(rev.main, rev.sub) - } else if !isTombstone(rkv.key) { - ki.restore(revision{rkv.kv.CreateRevision, 0}, rev, rkv.kv.Version) - idx.Insert(ki) - kiCache[rkv.kstr] = ki - } - } - }() - return rkvc, revc -} - -func restoreChunk(kvc chan<- revKeyValue, keys, vals [][]byte, keyToLease map[string]lease.LeaseID) { - for i, key := range keys { - rkv := revKeyValue{key: key} - if err := rkv.kv.Unmarshal(vals[i]); err != nil { - plog.Fatalf("cannot unmarshal event: %v", err) - } - rkv.kstr = string(rkv.kv.Key) - if isTombstone(key) { - delete(keyToLease, rkv.kstr) - } else if lid := lease.LeaseID(rkv.kv.Lease); lid != lease.NoLease { - keyToLease[rkv.kstr] = lid - } else { - delete(keyToLease, rkv.kstr) - } - kvc <- rkv - } -} - -func (s *store) Close() error { - close(s.stopc) - s.fifoSched.Stop() - return nil -} - -func (s *store) saveIndex(tx backend.BatchTx) { - if s.ig == nil { - return - } - bs := s.bytesBuf8 - ci := s.ig.ConsistentIndex() - binary.BigEndian.PutUint64(bs, ci) - // put the index into the underlying backend - // tx has been locked in TxnBegin, so there is no need to lock it again - tx.UnsafePut(metaBucketName, consistentIndexKeyName, bs) - atomic.StoreUint64(&s.consistentIndex, ci) -} - -func (s *store) ConsistentIndex() uint64 { - if ci := atomic.LoadUint64(&s.consistentIndex); ci > 0 { - return ci - } - tx := s.b.BatchTx() - tx.Lock() - defer tx.Unlock() - _, vs := tx.UnsafeRange(metaBucketName, consistentIndexKeyName, nil, 0) - if len(vs) == 0 { - return 0 - } - v := binary.BigEndian.Uint64(vs[0]) - atomic.StoreUint64(&s.consistentIndex, v) - return v -} - -// appendMarkTombstone appends tombstone mark to normal revision bytes. -func appendMarkTombstone(b []byte) []byte { - if len(b) != revBytesLen { - plog.Panicf("cannot append mark to non normal revision bytes") - } - return append(b, markTombstone) -} - -// isTombstone checks whether the revision bytes is a tombstone. -func isTombstone(b []byte) bool { - return len(b) == markedRevBytesLen && b[markBytePosition] == markTombstone -} diff --git a/vendor/github.com/coreos/etcd/mvcc/kvstore_compaction.go b/vendor/github.com/coreos/etcd/mvcc/kvstore_compaction.go deleted file mode 100644 index 082a33f0e5d0..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/kvstore_compaction.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "encoding/binary" - "time" -) - -func (s *store) scheduleCompaction(compactMainRev int64, keep map[revision]struct{}) bool { - totalStart := time.Now() - defer func() { dbCompactionTotalDurations.Observe(float64(time.Since(totalStart) / time.Millisecond)) }() - keyCompactions := 0 - defer func() { dbCompactionKeysCounter.Add(float64(keyCompactions)) }() - - end := make([]byte, 8) - binary.BigEndian.PutUint64(end, uint64(compactMainRev+1)) - - batchsize := int64(10000) - last := make([]byte, 8+1+8) - for { - var rev revision - - start := time.Now() - tx := s.b.BatchTx() - tx.Lock() - - keys, _ := tx.UnsafeRange(keyBucketName, last, end, batchsize) - for _, key := range keys { - rev = bytesToRev(key) - if _, ok := keep[rev]; !ok { - tx.UnsafeDelete(keyBucketName, key) - keyCompactions++ - } - } - - if len(keys) < int(batchsize) { - rbytes := make([]byte, 8+1+8) - revToBytes(revision{main: compactMainRev}, rbytes) - tx.UnsafePut(metaBucketName, finishedCompactKeyName, rbytes) - tx.Unlock() - plog.Printf("finished scheduled compaction at %d (took %v)", compactMainRev, time.Since(totalStart)) - return true - } - - // update last - revToBytes(revision{main: rev.main, sub: rev.sub + 1}, last) - tx.Unlock() - dbCompactionPauseDurations.Observe(float64(time.Since(start) / time.Millisecond)) - - select { - case <-time.After(100 * time.Millisecond): - case <-s.stopc: - return false - } - } -} diff --git a/vendor/github.com/coreos/etcd/mvcc/kvstore_txn.go b/vendor/github.com/coreos/etcd/mvcc/kvstore_txn.go deleted file mode 100644 index 8896fb86dbf2..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/kvstore_txn.go +++ /dev/null @@ -1,253 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -type storeTxnRead struct { - s *store - tx backend.ReadTx - - firstRev int64 - rev int64 -} - -func (s *store) Read() TxnRead { - s.mu.RLock() - tx := s.b.ReadTx() - s.revMu.RLock() - tx.Lock() - firstRev, rev := s.compactMainRev, s.currentRev - s.revMu.RUnlock() - return newMetricsTxnRead(&storeTxnRead{s, tx, firstRev, rev}) -} - -func (tr *storeTxnRead) FirstRev() int64 { return tr.firstRev } -func (tr *storeTxnRead) Rev() int64 { return tr.rev } - -func (tr *storeTxnRead) Range(key, end []byte, ro RangeOptions) (r *RangeResult, err error) { - return tr.rangeKeys(key, end, tr.Rev(), ro) -} - -func (tr *storeTxnRead) End() { - tr.tx.Unlock() - tr.s.mu.RUnlock() -} - -type storeTxnWrite struct { - storeTxnRead - tx backend.BatchTx - // beginRev is the revision where the txn begins; it will write to the next revision. - beginRev int64 - changes []mvccpb.KeyValue -} - -func (s *store) Write() TxnWrite { - s.mu.RLock() - tx := s.b.BatchTx() - tx.Lock() - tw := &storeTxnWrite{ - storeTxnRead: storeTxnRead{s, tx, 0, 0}, - tx: tx, - beginRev: s.currentRev, - changes: make([]mvccpb.KeyValue, 0, 4), - } - return newMetricsTxnWrite(tw) -} - -func (tw *storeTxnWrite) Rev() int64 { return tw.beginRev } - -func (tw *storeTxnWrite) Range(key, end []byte, ro RangeOptions) (r *RangeResult, err error) { - rev := tw.beginRev - if len(tw.changes) > 0 { - rev++ - } - return tw.rangeKeys(key, end, rev, ro) -} - -func (tw *storeTxnWrite) DeleteRange(key, end []byte) (int64, int64) { - if n := tw.deleteRange(key, end); n != 0 || len(tw.changes) > 0 { - return n, int64(tw.beginRev + 1) - } - return 0, int64(tw.beginRev) -} - -func (tw *storeTxnWrite) Put(key, value []byte, lease lease.LeaseID) int64 { - tw.put(key, value, lease) - return int64(tw.beginRev + 1) -} - -func (tw *storeTxnWrite) End() { - // only update index if the txn modifies the mvcc state. - if len(tw.changes) != 0 { - tw.s.saveIndex(tw.tx) - // hold revMu lock to prevent new read txns from opening until writeback. - tw.s.revMu.Lock() - tw.s.currentRev++ - } - tw.tx.Unlock() - if len(tw.changes) != 0 { - tw.s.revMu.Unlock() - } - tw.s.mu.RUnlock() -} - -func (tr *storeTxnRead) rangeKeys(key, end []byte, curRev int64, ro RangeOptions) (*RangeResult, error) { - rev := ro.Rev - if rev > curRev { - return &RangeResult{KVs: nil, Count: -1, Rev: curRev}, ErrFutureRev - } - if rev <= 0 { - rev = curRev - } - if rev < tr.s.compactMainRev { - return &RangeResult{KVs: nil, Count: -1, Rev: 0}, ErrCompacted - } - - revpairs := tr.s.kvindex.Revisions(key, end, int64(rev)) - if len(revpairs) == 0 { - return &RangeResult{KVs: nil, Count: 0, Rev: curRev}, nil - } - if ro.Count { - return &RangeResult{KVs: nil, Count: len(revpairs), Rev: curRev}, nil - } - - limit := int(ro.Limit) - if limit <= 0 || limit > len(revpairs) { - limit = len(revpairs) - } - - kvs := make([]mvccpb.KeyValue, limit) - revBytes := newRevBytes() - for i, revpair := range revpairs[:len(kvs)] { - revToBytes(revpair, revBytes) - _, vs := tr.tx.UnsafeRange(keyBucketName, revBytes, nil, 0) - if len(vs) != 1 { - plog.Fatalf("range cannot find rev (%d,%d)", revpair.main, revpair.sub) - } - if err := kvs[i].Unmarshal(vs[0]); err != nil { - plog.Fatalf("cannot unmarshal event: %v", err) - } - } - return &RangeResult{KVs: kvs, Count: len(revpairs), Rev: curRev}, nil -} - -func (tw *storeTxnWrite) put(key, value []byte, leaseID lease.LeaseID) { - rev := tw.beginRev + 1 - c := rev - oldLease := lease.NoLease - - // if the key exists before, use its previous created and - // get its previous leaseID - _, created, ver, err := tw.s.kvindex.Get(key, rev) - if err == nil { - c = created.main - oldLease = tw.s.le.GetLease(lease.LeaseItem{Key: string(key)}) - } - - ibytes := newRevBytes() - idxRev := revision{main: rev, sub: int64(len(tw.changes))} - revToBytes(idxRev, ibytes) - - ver = ver + 1 - kv := mvccpb.KeyValue{ - Key: key, - Value: value, - CreateRevision: c, - ModRevision: rev, - Version: ver, - Lease: int64(leaseID), - } - - d, err := kv.Marshal() - if err != nil { - plog.Fatalf("cannot marshal event: %v", err) - } - - tw.tx.UnsafeSeqPut(keyBucketName, ibytes, d) - tw.s.kvindex.Put(key, idxRev) - tw.changes = append(tw.changes, kv) - - if oldLease != lease.NoLease { - if tw.s.le == nil { - panic("no lessor to detach lease") - } - err = tw.s.le.Detach(oldLease, []lease.LeaseItem{{Key: string(key)}}) - if err != nil { - plog.Errorf("unexpected error from lease detach: %v", err) - } - } - if leaseID != lease.NoLease { - if tw.s.le == nil { - panic("no lessor to attach lease") - } - err = tw.s.le.Attach(leaseID, []lease.LeaseItem{{Key: string(key)}}) - if err != nil { - panic("unexpected error from lease Attach") - } - } -} - -func (tw *storeTxnWrite) deleteRange(key, end []byte) int64 { - rrev := tw.beginRev - if len(tw.changes) > 0 { - rrev += 1 - } - keys, revs := tw.s.kvindex.Range(key, end, rrev) - if len(keys) == 0 { - return 0 - } - for i, key := range keys { - tw.delete(key, revs[i]) - } - return int64(len(keys)) -} - -func (tw *storeTxnWrite) delete(key []byte, rev revision) { - ibytes := newRevBytes() - idxRev := revision{main: tw.beginRev + 1, sub: int64(len(tw.changes))} - revToBytes(idxRev, ibytes) - ibytes = appendMarkTombstone(ibytes) - - kv := mvccpb.KeyValue{Key: key} - - d, err := kv.Marshal() - if err != nil { - plog.Fatalf("cannot marshal event: %v", err) - } - - tw.tx.UnsafeSeqPut(keyBucketName, ibytes, d) - err = tw.s.kvindex.Tombstone(key, idxRev) - if err != nil { - plog.Fatalf("cannot tombstone an existing key (%s): %v", string(key), err) - } - tw.changes = append(tw.changes, kv) - - item := lease.LeaseItem{Key: string(key)} - leaseID := tw.s.le.GetLease(item) - - if leaseID != lease.NoLease { - err = tw.s.le.Detach(leaseID, []lease.LeaseItem{item}) - if err != nil { - plog.Errorf("cannot detach %v", err) - } - } -} - -func (tw *storeTxnWrite) Changes() []mvccpb.KeyValue { return tw.changes } diff --git a/vendor/github.com/coreos/etcd/mvcc/metrics.go b/vendor/github.com/coreos/etcd/mvcc/metrics.go deleted file mode 100644 index b753310cff03..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/metrics.go +++ /dev/null @@ -1,239 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "sync" - - "github.com/prometheus/client_golang/prometheus" -) - -var ( - rangeCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "range_total", - Help: "Total number of ranges seen by this member.", - }) - - putCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "put_total", - Help: "Total number of puts seen by this member.", - }) - - deleteCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "delete_total", - Help: "Total number of deletes seen by this member.", - }) - - txnCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "txn_total", - Help: "Total number of txns seen by this member.", - }) - - keysGauge = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "keys_total", - Help: "Total number of keys.", - }) - - watchStreamGauge = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "watch_stream_total", - Help: "Total number of watch streams.", - }) - - watcherGauge = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "watcher_total", - Help: "Total number of watchers.", - }) - - slowWatcherGauge = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "slow_watcher_total", - Help: "Total number of unsynced slow watchers.", - }) - - totalEventsCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "events_total", - Help: "Total number of events sent by this member.", - }) - - pendingEventsGauge = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "pending_events_total", - Help: "Total number of pending events to be sent.", - }) - - indexCompactionPauseDurations = prometheus.NewHistogram( - prometheus.HistogramOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "index_compaction_pause_duration_milliseconds", - Help: "Bucketed histogram of index compaction pause duration.", - // 0.5ms -> 1second - Buckets: prometheus.ExponentialBuckets(0.5, 2, 12), - }) - - dbCompactionPauseDurations = prometheus.NewHistogram( - prometheus.HistogramOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "db_compaction_pause_duration_milliseconds", - Help: "Bucketed histogram of db compaction pause duration.", - // 1ms -> 4second - Buckets: prometheus.ExponentialBuckets(1, 2, 13), - }) - - dbCompactionTotalDurations = prometheus.NewHistogram( - prometheus.HistogramOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "db_compaction_total_duration_milliseconds", - Help: "Bucketed histogram of db compaction total duration.", - // 100ms -> 800second - Buckets: prometheus.ExponentialBuckets(100, 2, 14), - }) - - dbCompactionKeysCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "db_compaction_keys_total", - Help: "Total number of db keys compacted.", - }) - - dbTotalSizeDebugging = prometheus.NewGaugeFunc(prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "db_total_size_in_bytes", - Help: "Total size of the underlying database physically allocated in bytes. Use etcd_mvcc_db_total_size_in_bytes", - }, - func() float64 { - reportDbTotalSizeInBytesMu.RLock() - defer reportDbTotalSizeInBytesMu.RUnlock() - return reportDbTotalSizeInBytes() - }, - ) - dbTotalSize = prometheus.NewGaugeFunc(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "mvcc", - Name: "db_total_size_in_bytes", - Help: "Total size of the underlying database physically allocated in bytes.", - }, - func() float64 { - reportDbTotalSizeInBytesMu.RLock() - defer reportDbTotalSizeInBytesMu.RUnlock() - return reportDbTotalSizeInBytes() - }, - ) - // overridden by mvcc initialization - reportDbTotalSizeInBytesMu sync.RWMutex - reportDbTotalSizeInBytes = func() float64 { return 0 } - - dbTotalSizeInUse = prometheus.NewGaugeFunc(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "mvcc", - Name: "db_total_size_in_use_in_bytes", - Help: "Total size of the underlying database logically in use in bytes.", - }, - func() float64 { - reportDbTotalSizeInUseInBytesMu.RLock() - defer reportDbTotalSizeInUseInBytesMu.RUnlock() - return reportDbTotalSizeInUseInBytes() - }, - ) - // overridden by mvcc initialization - reportDbTotalSizeInUseInBytesMu sync.RWMutex - reportDbTotalSizeInUseInBytes func() float64 = func() float64 { return 0 } - - hashDurations = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "mvcc", - Name: "hash_duration_seconds", - Help: "The latency distribution of storage hash operation.", - - // 100 MB usually takes 100 ms, so start with 10 MB of 10 ms - // lowest bucket start of upper bound 0.01 sec (10 ms) with factor 2 - // highest bucket start of 0.01 sec * 2^14 == 163.84 sec - Buckets: prometheus.ExponentialBuckets(.01, 2, 15), - }) - - hashRevDurations = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "mvcc", - Name: "hash_rev_duration_seconds", - Help: "The latency distribution of storage hash by revision operation.", - - // 100 MB usually takes 100 ms, so start with 10 MB of 10 ms - // lowest bucket start of upper bound 0.01 sec (10 ms) with factor 2 - // highest bucket start of 0.01 sec * 2^14 == 163.84 sec - Buckets: prometheus.ExponentialBuckets(.01, 2, 15), - }) -) - -func init() { - prometheus.MustRegister(rangeCounter) - prometheus.MustRegister(putCounter) - prometheus.MustRegister(deleteCounter) - prometheus.MustRegister(txnCounter) - prometheus.MustRegister(keysGauge) - prometheus.MustRegister(watchStreamGauge) - prometheus.MustRegister(watcherGauge) - prometheus.MustRegister(slowWatcherGauge) - prometheus.MustRegister(totalEventsCounter) - prometheus.MustRegister(pendingEventsGauge) - prometheus.MustRegister(indexCompactionPauseDurations) - prometheus.MustRegister(dbCompactionPauseDurations) - prometheus.MustRegister(dbCompactionTotalDurations) - prometheus.MustRegister(dbCompactionKeysCounter) - prometheus.MustRegister(dbTotalSizeDebugging) - prometheus.MustRegister(dbTotalSize) - prometheus.MustRegister(dbTotalSizeInUse) - prometheus.MustRegister(hashDurations) - prometheus.MustRegister(hashRevDurations) -} - -// ReportEventReceived reports that an event is received. -// This function should be called when the external systems received an -// event from mvcc.Watcher. -func ReportEventReceived(n int) { - pendingEventsGauge.Sub(float64(n)) - totalEventsCounter.Add(float64(n)) -} diff --git a/vendor/github.com/coreos/etcd/mvcc/metrics_txn.go b/vendor/github.com/coreos/etcd/mvcc/metrics_txn.go deleted file mode 100644 index 911d64875d78..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/metrics_txn.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "github.com/coreos/etcd/lease" -) - -type metricsTxnWrite struct { - TxnWrite - ranges uint - puts uint - deletes uint -} - -func newMetricsTxnRead(tr TxnRead) TxnRead { - return &metricsTxnWrite{&txnReadWrite{tr}, 0, 0, 0} -} - -func newMetricsTxnWrite(tw TxnWrite) TxnWrite { - return &metricsTxnWrite{tw, 0, 0, 0} -} - -func (tw *metricsTxnWrite) Range(key, end []byte, ro RangeOptions) (*RangeResult, error) { - tw.ranges++ - return tw.TxnWrite.Range(key, end, ro) -} - -func (tw *metricsTxnWrite) DeleteRange(key, end []byte) (n, rev int64) { - tw.deletes++ - return tw.TxnWrite.DeleteRange(key, end) -} - -func (tw *metricsTxnWrite) Put(key, value []byte, lease lease.LeaseID) (rev int64) { - tw.puts++ - return tw.TxnWrite.Put(key, value, lease) -} - -func (tw *metricsTxnWrite) End() { - defer tw.TxnWrite.End() - if sum := tw.ranges + tw.puts + tw.deletes; sum > 1 { - txnCounter.Inc() - } - rangeCounter.Add(float64(tw.ranges)) - putCounter.Add(float64(tw.puts)) - deleteCounter.Add(float64(tw.deletes)) -} diff --git a/vendor/github.com/coreos/etcd/mvcc/mvccpb/kv.pb.go b/vendor/github.com/coreos/etcd/mvcc/mvccpb/kv.pb.go deleted file mode 100644 index 23fe337a59bf..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/mvccpb/kv.pb.go +++ /dev/null @@ -1,718 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: kv.proto - -/* - Package mvccpb is a generated protocol buffer package. - - It is generated from these files: - kv.proto - - It has these top-level messages: - KeyValue - Event -*/ -package mvccpb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type Event_EventType int32 - -const ( - PUT Event_EventType = 0 - DELETE Event_EventType = 1 -) - -var Event_EventType_name = map[int32]string{ - 0: "PUT", - 1: "DELETE", -} -var Event_EventType_value = map[string]int32{ - "PUT": 0, - "DELETE": 1, -} - -func (x Event_EventType) String() string { - return proto.EnumName(Event_EventType_name, int32(x)) -} -func (Event_EventType) EnumDescriptor() ([]byte, []int) { return fileDescriptorKv, []int{1, 0} } - -type KeyValue struct { - // key is the key in bytes. An empty key is not allowed. - Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - // create_revision is the revision of last creation on this key. - CreateRevision int64 `protobuf:"varint,2,opt,name=create_revision,json=createRevision,proto3" json:"create_revision,omitempty"` - // mod_revision is the revision of last modification on this key. - ModRevision int64 `protobuf:"varint,3,opt,name=mod_revision,json=modRevision,proto3" json:"mod_revision,omitempty"` - // version is the version of the key. A deletion resets - // the version to zero and any modification of the key - // increases its version. - Version int64 `protobuf:"varint,4,opt,name=version,proto3" json:"version,omitempty"` - // value is the value held by the key, in bytes. - Value []byte `protobuf:"bytes,5,opt,name=value,proto3" json:"value,omitempty"` - // lease is the ID of the lease that attached to key. - // When the attached lease expires, the key will be deleted. - // If lease is 0, then no lease is attached to the key. - Lease int64 `protobuf:"varint,6,opt,name=lease,proto3" json:"lease,omitempty"` -} - -func (m *KeyValue) Reset() { *m = KeyValue{} } -func (m *KeyValue) String() string { return proto.CompactTextString(m) } -func (*KeyValue) ProtoMessage() {} -func (*KeyValue) Descriptor() ([]byte, []int) { return fileDescriptorKv, []int{0} } - -type Event struct { - // type is the kind of event. If type is a PUT, it indicates - // new data has been stored to the key. If type is a DELETE, - // it indicates the key was deleted. - Type Event_EventType `protobuf:"varint,1,opt,name=type,proto3,enum=mvccpb.Event_EventType" json:"type,omitempty"` - // kv holds the KeyValue for the event. - // A PUT event contains current kv pair. - // A PUT event with kv.Version=1 indicates the creation of a key. - // A DELETE/EXPIRE event contains the deleted key with - // its modification revision set to the revision of deletion. - Kv *KeyValue `protobuf:"bytes,2,opt,name=kv" json:"kv,omitempty"` - // prev_kv holds the key-value pair before the event happens. - PrevKv *KeyValue `protobuf:"bytes,3,opt,name=prev_kv,json=prevKv" json:"prev_kv,omitempty"` -} - -func (m *Event) Reset() { *m = Event{} } -func (m *Event) String() string { return proto.CompactTextString(m) } -func (*Event) ProtoMessage() {} -func (*Event) Descriptor() ([]byte, []int) { return fileDescriptorKv, []int{1} } - -func init() { - proto.RegisterType((*KeyValue)(nil), "mvccpb.KeyValue") - proto.RegisterType((*Event)(nil), "mvccpb.Event") - proto.RegisterEnum("mvccpb.Event_EventType", Event_EventType_name, Event_EventType_value) -} -func (m *KeyValue) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *KeyValue) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Key) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintKv(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - if m.CreateRevision != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintKv(dAtA, i, uint64(m.CreateRevision)) - } - if m.ModRevision != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintKv(dAtA, i, uint64(m.ModRevision)) - } - if m.Version != 0 { - dAtA[i] = 0x20 - i++ - i = encodeVarintKv(dAtA, i, uint64(m.Version)) - } - if len(m.Value) > 0 { - dAtA[i] = 0x2a - i++ - i = encodeVarintKv(dAtA, i, uint64(len(m.Value))) - i += copy(dAtA[i:], m.Value) - } - if m.Lease != 0 { - dAtA[i] = 0x30 - i++ - i = encodeVarintKv(dAtA, i, uint64(m.Lease)) - } - return i, nil -} - -func (m *Event) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Event) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Type != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintKv(dAtA, i, uint64(m.Type)) - } - if m.Kv != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintKv(dAtA, i, uint64(m.Kv.Size())) - n1, err := m.Kv.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - } - if m.PrevKv != nil { - dAtA[i] = 0x1a - i++ - i = encodeVarintKv(dAtA, i, uint64(m.PrevKv.Size())) - n2, err := m.PrevKv.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - } - return i, nil -} - -func encodeVarintKv(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *KeyValue) Size() (n int) { - var l int - _ = l - l = len(m.Key) - if l > 0 { - n += 1 + l + sovKv(uint64(l)) - } - if m.CreateRevision != 0 { - n += 1 + sovKv(uint64(m.CreateRevision)) - } - if m.ModRevision != 0 { - n += 1 + sovKv(uint64(m.ModRevision)) - } - if m.Version != 0 { - n += 1 + sovKv(uint64(m.Version)) - } - l = len(m.Value) - if l > 0 { - n += 1 + l + sovKv(uint64(l)) - } - if m.Lease != 0 { - n += 1 + sovKv(uint64(m.Lease)) - } - return n -} - -func (m *Event) Size() (n int) { - var l int - _ = l - if m.Type != 0 { - n += 1 + sovKv(uint64(m.Type)) - } - if m.Kv != nil { - l = m.Kv.Size() - n += 1 + l + sovKv(uint64(l)) - } - if m.PrevKv != nil { - l = m.PrevKv.Size() - n += 1 + l + sovKv(uint64(l)) - } - return n -} - -func sovKv(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozKv(x uint64) (n int) { - return sovKv(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *KeyValue) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: KeyValue: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: KeyValue: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthKv - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CreateRevision", wireType) - } - m.CreateRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.CreateRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ModRevision", wireType) - } - m.ModRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ModRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) - } - m.Version = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Version |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthKv - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...) - if m.Value == nil { - m.Value = []byte{} - } - iNdEx = postIndex - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Lease", wireType) - } - m.Lease = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Lease |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipKv(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthKv - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Event) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Event: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Event: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= (Event_EventType(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Kv", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthKv - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Kv == nil { - m.Kv = &KeyValue{} - } - if err := m.Kv.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PrevKv", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthKv - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.PrevKv == nil { - m.PrevKv = &KeyValue{} - } - if err := m.PrevKv.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipKv(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthKv - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipKv(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowKv - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowKv - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowKv - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthKv - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowKv - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipKv(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthKv = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowKv = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("kv.proto", fileDescriptorKv) } - -var fileDescriptorKv = []byte{ - // 303 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0x41, 0x4e, 0xc2, 0x40, - 0x14, 0x86, 0x3b, 0x14, 0x0a, 0x3e, 0x08, 0x36, 0x13, 0x12, 0x27, 0x2e, 0x26, 0x95, 0x8d, 0x18, - 0x13, 0x4c, 0xf0, 0x06, 0xc6, 0xae, 0x70, 0x61, 0x1a, 0x74, 0x4b, 0x4a, 0x79, 0x21, 0xa4, 0x94, - 0x69, 0x4a, 0x9d, 0xa4, 0x37, 0x71, 0xef, 0xde, 0x73, 0xb0, 0xe4, 0x08, 0x52, 0x2f, 0x62, 0xfa, - 0xc6, 0xe2, 0xc6, 0xcd, 0xe4, 0xfd, 0xff, 0xff, 0x65, 0xe6, 0x7f, 0x03, 0x9d, 0x58, 0x8f, 0xd3, - 0x4c, 0xe5, 0x8a, 0x3b, 0x89, 0x8e, 0xa2, 0x74, 0x71, 0x39, 0x58, 0xa9, 0x95, 0x22, 0xeb, 0xae, - 0x9a, 0x4c, 0x3a, 0xfc, 0x64, 0xd0, 0x99, 0x62, 0xf1, 0x1a, 0x6e, 0xde, 0x90, 0xbb, 0x60, 0xc7, - 0x58, 0x08, 0xe6, 0xb1, 0x51, 0x2f, 0xa8, 0x46, 0x7e, 0x0d, 0xe7, 0x51, 0x86, 0x61, 0x8e, 0xf3, - 0x0c, 0xf5, 0x7a, 0xb7, 0x56, 0x5b, 0xd1, 0xf0, 0xd8, 0xc8, 0x0e, 0xfa, 0xc6, 0x0e, 0x7e, 0x5d, - 0x7e, 0x05, 0xbd, 0x44, 0x2d, 0xff, 0x28, 0x9b, 0xa8, 0x6e, 0xa2, 0x96, 0x27, 0x44, 0x40, 0x5b, - 0x63, 0x46, 0x69, 0x93, 0xd2, 0x5a, 0xf2, 0x01, 0xb4, 0x74, 0x55, 0x40, 0xb4, 0xe8, 0x65, 0x23, - 0x2a, 0x77, 0x83, 0xe1, 0x0e, 0x85, 0x43, 0xb4, 0x11, 0xc3, 0x0f, 0x06, 0x2d, 0x5f, 0xe3, 0x36, - 0xe7, 0xb7, 0xd0, 0xcc, 0x8b, 0x14, 0xa9, 0x6e, 0x7f, 0x72, 0x31, 0x36, 0x7b, 0x8e, 0x29, 0x34, - 0xe7, 0xac, 0x48, 0x31, 0x20, 0x88, 0x7b, 0xd0, 0x88, 0x35, 0x75, 0xef, 0x4e, 0xdc, 0x1a, 0xad, - 0x17, 0x0f, 0x1a, 0xb1, 0xe6, 0x37, 0xd0, 0x4e, 0x33, 0xd4, 0xf3, 0x58, 0x53, 0xf9, 0xff, 0x30, - 0xa7, 0x02, 0xa6, 0x7a, 0xe8, 0xc1, 0xd9, 0xe9, 0x7e, 0xde, 0x06, 0xfb, 0xf9, 0x65, 0xe6, 0x5a, - 0x1c, 0xc0, 0x79, 0xf4, 0x9f, 0xfc, 0x99, 0xef, 0xb2, 0x07, 0xb1, 0x3f, 0x4a, 0xeb, 0x70, 0x94, - 0xd6, 0xbe, 0x94, 0xec, 0x50, 0x4a, 0xf6, 0x55, 0x4a, 0xf6, 0xfe, 0x2d, 0xad, 0x85, 0x43, 0xff, - 0x7e, 0xff, 0x13, 0x00, 0x00, 0xff, 0xff, 0xb5, 0x45, 0x92, 0x5d, 0xa1, 0x01, 0x00, 0x00, -} diff --git a/vendor/github.com/coreos/etcd/mvcc/revision.go b/vendor/github.com/coreos/etcd/mvcc/revision.go deleted file mode 100644 index 5fa35a1c2a26..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/revision.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import "encoding/binary" - -// revBytesLen is the byte length of a normal revision. -// First 8 bytes is the revision.main in big-endian format. The 9th byte -// is a '_'. The last 8 bytes is the revision.sub in big-endian format. -const revBytesLen = 8 + 1 + 8 - -// A revision indicates modification of the key-value space. -// The set of changes that share same main revision changes the key-value space atomically. -type revision struct { - // main is the main revision of a set of changes that happen atomically. - main int64 - - // sub is the the sub revision of a change in a set of changes that happen - // atomically. Each change has different increasing sub revision in that - // set. - sub int64 -} - -func (a revision) GreaterThan(b revision) bool { - if a.main > b.main { - return true - } - if a.main < b.main { - return false - } - return a.sub > b.sub -} - -func newRevBytes() []byte { - return make([]byte, revBytesLen, markedRevBytesLen) -} - -func revToBytes(rev revision, bytes []byte) { - binary.BigEndian.PutUint64(bytes, uint64(rev.main)) - bytes[8] = '_' - binary.BigEndian.PutUint64(bytes[9:], uint64(rev.sub)) -} - -func bytesToRev(bytes []byte) revision { - return revision{ - main: int64(binary.BigEndian.Uint64(bytes[0:8])), - sub: int64(binary.BigEndian.Uint64(bytes[9:])), - } -} - -type revisions []revision - -func (a revisions) Len() int { return len(a) } -func (a revisions) Less(i, j int) bool { return a[j].GreaterThan(a[i]) } -func (a revisions) Swap(i, j int) { a[i], a[j] = a[j], a[i] } diff --git a/vendor/github.com/coreos/etcd/mvcc/util.go b/vendor/github.com/coreos/etcd/mvcc/util.go deleted file mode 100644 index 8a0df0bfcc37..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/util.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "encoding/binary" - - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -func UpdateConsistentIndex(be backend.Backend, index uint64) { - tx := be.BatchTx() - tx.Lock() - defer tx.Unlock() - - var oldi uint64 - _, vs := tx.UnsafeRange(metaBucketName, consistentIndexKeyName, nil, 0) - if len(vs) != 0 { - oldi = binary.BigEndian.Uint64(vs[0]) - } - - if index <= oldi { - return - } - - bs := make([]byte, 8) - binary.BigEndian.PutUint64(bs, index) - tx.UnsafePut(metaBucketName, consistentIndexKeyName, bs) -} - -func WriteKV(be backend.Backend, kv mvccpb.KeyValue) { - ibytes := newRevBytes() - revToBytes(revision{main: kv.ModRevision}, ibytes) - - d, err := kv.Marshal() - if err != nil { - plog.Fatalf("cannot marshal event: %v", err) - } - - be.BatchTx().Lock() - be.BatchTx().UnsafePut(keyBucketName, ibytes, d) - be.BatchTx().Unlock() -} diff --git a/vendor/github.com/coreos/etcd/mvcc/watchable_store.go b/vendor/github.com/coreos/etcd/mvcc/watchable_store.go deleted file mode 100644 index 78df19326b95..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/watchable_store.go +++ /dev/null @@ -1,534 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "sync" - "time" - - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -// non-const so modifiable by tests -var ( - // chanBufLen is the length of the buffered chan - // for sending out watched events. - // TODO: find a good buf value. 1024 is just a random one that - // seems to be reasonable. - chanBufLen = 1024 - - // maxWatchersPerSync is the number of watchers to sync in a single batch - maxWatchersPerSync = 512 -) - -type watchable interface { - watch(key, end []byte, startRev int64, id WatchID, ch chan<- WatchResponse, fcs ...FilterFunc) (*watcher, cancelFunc) - progress(w *watcher) - rev() int64 -} - -type watchableStore struct { - *store - - // mu protects watcher groups and batches. It should never be locked - // before locking store.mu to avoid deadlock. - mu sync.RWMutex - - // victims are watcher batches that were blocked on the watch channel - victims []watcherBatch - victimc chan struct{} - - // contains all unsynced watchers that needs to sync with events that have happened - unsynced watcherGroup - - // contains all synced watchers that are in sync with the progress of the store. - // The key of the map is the key that the watcher watches on. - synced watcherGroup - - stopc chan struct{} - wg sync.WaitGroup -} - -// cancelFunc updates unsynced and synced maps when running -// cancel operations. -type cancelFunc func() - -func New(b backend.Backend, le lease.Lessor, ig ConsistentIndexGetter) ConsistentWatchableKV { - return newWatchableStore(b, le, ig) -} - -func newWatchableStore(b backend.Backend, le lease.Lessor, ig ConsistentIndexGetter) *watchableStore { - s := &watchableStore{ - store: NewStore(b, le, ig), - victimc: make(chan struct{}, 1), - unsynced: newWatcherGroup(), - synced: newWatcherGroup(), - stopc: make(chan struct{}), - } - s.store.ReadView = &readView{s} - s.store.WriteView = &writeView{s} - if s.le != nil { - // use this store as the deleter so revokes trigger watch events - s.le.SetRangeDeleter(func() lease.TxnDelete { return s.Write() }) - } - s.wg.Add(2) - go s.syncWatchersLoop() - go s.syncVictimsLoop() - return s -} - -func (s *watchableStore) Close() error { - close(s.stopc) - s.wg.Wait() - return s.store.Close() -} - -func (s *watchableStore) NewWatchStream() WatchStream { - watchStreamGauge.Inc() - return &watchStream{ - watchable: s, - ch: make(chan WatchResponse, chanBufLen), - cancels: make(map[WatchID]cancelFunc), - watchers: make(map[WatchID]*watcher), - } -} - -func (s *watchableStore) watch(key, end []byte, startRev int64, id WatchID, ch chan<- WatchResponse, fcs ...FilterFunc) (*watcher, cancelFunc) { - wa := &watcher{ - key: key, - end: end, - minRev: startRev, - id: id, - ch: ch, - fcs: fcs, - } - - s.mu.Lock() - s.revMu.RLock() - synced := startRev > s.store.currentRev || startRev == 0 - if synced { - wa.minRev = s.store.currentRev + 1 - if startRev > wa.minRev { - wa.minRev = startRev - } - } - if synced { - s.synced.add(wa) - } else { - slowWatcherGauge.Inc() - s.unsynced.add(wa) - } - s.revMu.RUnlock() - s.mu.Unlock() - - watcherGauge.Inc() - - return wa, func() { s.cancelWatcher(wa) } -} - -// cancelWatcher removes references of the watcher from the watchableStore -func (s *watchableStore) cancelWatcher(wa *watcher) { - for { - s.mu.Lock() - if s.unsynced.delete(wa) { - slowWatcherGauge.Dec() - break - } else if s.synced.delete(wa) { - break - } else if wa.compacted { - break - } else if wa.ch == nil { - // already canceled (e.g., cancel/close race) - break - } - - if !wa.victim { - panic("watcher not victim but not in watch groups") - } - - var victimBatch watcherBatch - for _, wb := range s.victims { - if wb[wa] != nil { - victimBatch = wb - break - } - } - if victimBatch != nil { - slowWatcherGauge.Dec() - delete(victimBatch, wa) - break - } - - // victim being processed so not accessible; retry - s.mu.Unlock() - time.Sleep(time.Millisecond) - } - - watcherGauge.Dec() - wa.ch = nil - s.mu.Unlock() -} - -func (s *watchableStore) Restore(b backend.Backend) error { - s.mu.Lock() - defer s.mu.Unlock() - err := s.store.Restore(b) - if err != nil { - return err - } - - for wa := range s.synced.watchers { - wa.restore = true - s.unsynced.add(wa) - } - s.synced = newWatcherGroup() - return nil -} - -// syncWatchersLoop syncs the watcher in the unsynced map every 100ms. -func (s *watchableStore) syncWatchersLoop() { - defer s.wg.Done() - - for { - s.mu.RLock() - st := time.Now() - lastUnsyncedWatchers := s.unsynced.size() - s.mu.RUnlock() - - unsyncedWatchers := 0 - if lastUnsyncedWatchers > 0 { - unsyncedWatchers = s.syncWatchers() - } - syncDuration := time.Since(st) - - waitDuration := 100 * time.Millisecond - // more work pending? - if unsyncedWatchers != 0 && lastUnsyncedWatchers > unsyncedWatchers { - // be fair to other store operations by yielding time taken - waitDuration = syncDuration - } - - select { - case <-time.After(waitDuration): - case <-s.stopc: - return - } - } -} - -// syncVictimsLoop tries to write precomputed watcher responses to -// watchers that had a blocked watcher channel -func (s *watchableStore) syncVictimsLoop() { - defer s.wg.Done() - - for { - for s.moveVictims() != 0 { - // try to update all victim watchers - } - s.mu.RLock() - isEmpty := len(s.victims) == 0 - s.mu.RUnlock() - - var tickc <-chan time.Time - if !isEmpty { - tickc = time.After(10 * time.Millisecond) - } - - select { - case <-tickc: - case <-s.victimc: - case <-s.stopc: - return - } - } -} - -// moveVictims tries to update watches with already pending event data -func (s *watchableStore) moveVictims() (moved int) { - s.mu.Lock() - victims := s.victims - s.victims = nil - s.mu.Unlock() - - var newVictim watcherBatch - for _, wb := range victims { - // try to send responses again - for w, eb := range wb { - // watcher has observed the store up to, but not including, w.minRev - rev := w.minRev - 1 - if w.send(WatchResponse{WatchID: w.id, Events: eb.evs, Revision: rev}) { - pendingEventsGauge.Add(float64(len(eb.evs))) - } else { - if newVictim == nil { - newVictim = make(watcherBatch) - } - newVictim[w] = eb - continue - } - moved++ - } - - // assign completed victim watchers to unsync/sync - s.mu.Lock() - s.store.revMu.RLock() - curRev := s.store.currentRev - for w, eb := range wb { - if newVictim != nil && newVictim[w] != nil { - // couldn't send watch response; stays victim - continue - } - w.victim = false - if eb.moreRev != 0 { - w.minRev = eb.moreRev - } - if w.minRev <= curRev { - s.unsynced.add(w) - } else { - slowWatcherGauge.Dec() - s.synced.add(w) - } - } - s.store.revMu.RUnlock() - s.mu.Unlock() - } - - if len(newVictim) > 0 { - s.mu.Lock() - s.victims = append(s.victims, newVictim) - s.mu.Unlock() - } - - return moved -} - -// syncWatchers syncs unsynced watchers by: -// 1. choose a set of watchers from the unsynced watcher group -// 2. iterate over the set to get the minimum revision and remove compacted watchers -// 3. use minimum revision to get all key-value pairs and send those events to watchers -// 4. remove synced watchers in set from unsynced group and move to synced group -func (s *watchableStore) syncWatchers() int { - s.mu.Lock() - defer s.mu.Unlock() - - if s.unsynced.size() == 0 { - return 0 - } - - s.store.revMu.RLock() - defer s.store.revMu.RUnlock() - - // in order to find key-value pairs from unsynced watchers, we need to - // find min revision index, and these revisions can be used to - // query the backend store of key-value pairs - curRev := s.store.currentRev - compactionRev := s.store.compactMainRev - - wg, minRev := s.unsynced.choose(maxWatchersPerSync, curRev, compactionRev) - minBytes, maxBytes := newRevBytes(), newRevBytes() - revToBytes(revision{main: minRev}, minBytes) - revToBytes(revision{main: curRev + 1}, maxBytes) - - // UnsafeRange returns keys and values. And in boltdb, keys are revisions. - // values are actual key-value pairs in backend. - tx := s.store.b.ReadTx() - tx.Lock() - revs, vs := tx.UnsafeRange(keyBucketName, minBytes, maxBytes, 0) - evs := kvsToEvents(wg, revs, vs) - tx.Unlock() - - var victims watcherBatch - wb := newWatcherBatch(wg, evs) - for w := range wg.watchers { - w.minRev = curRev + 1 - - eb, ok := wb[w] - if !ok { - // bring un-notified watcher to synced - s.synced.add(w) - s.unsynced.delete(w) - continue - } - - if eb.moreRev != 0 { - w.minRev = eb.moreRev - } - - if w.send(WatchResponse{WatchID: w.id, Events: eb.evs, Revision: curRev}) { - pendingEventsGauge.Add(float64(len(eb.evs))) - } else { - if victims == nil { - victims = make(watcherBatch) - } - w.victim = true - } - - if w.victim { - victims[w] = eb - } else { - if eb.moreRev != 0 { - // stay unsynced; more to read - continue - } - s.synced.add(w) - } - s.unsynced.delete(w) - } - s.addVictim(victims) - - vsz := 0 - for _, v := range s.victims { - vsz += len(v) - } - slowWatcherGauge.Set(float64(s.unsynced.size() + vsz)) - - return s.unsynced.size() -} - -// kvsToEvents gets all events for the watchers from all key-value pairs -func kvsToEvents(wg *watcherGroup, revs, vals [][]byte) (evs []mvccpb.Event) { - for i, v := range vals { - var kv mvccpb.KeyValue - if err := kv.Unmarshal(v); err != nil { - plog.Panicf("cannot unmarshal event: %v", err) - } - - if !wg.contains(string(kv.Key)) { - continue - } - - ty := mvccpb.PUT - if isTombstone(revs[i]) { - ty = mvccpb.DELETE - // patch in mod revision so watchers won't skip - kv.ModRevision = bytesToRev(revs[i]).main - } - evs = append(evs, mvccpb.Event{Kv: &kv, Type: ty}) - } - return evs -} - -// notify notifies the fact that given event at the given rev just happened to -// watchers that watch on the key of the event. -func (s *watchableStore) notify(rev int64, evs []mvccpb.Event) { - var victim watcherBatch - for w, eb := range newWatcherBatch(&s.synced, evs) { - if eb.revs != 1 { - plog.Panicf("unexpected multiple revisions in notification") - } - if w.send(WatchResponse{WatchID: w.id, Events: eb.evs, Revision: rev}) { - pendingEventsGauge.Add(float64(len(eb.evs))) - } else { - // move slow watcher to victims - w.minRev = rev + 1 - if victim == nil { - victim = make(watcherBatch) - } - w.victim = true - victim[w] = eb - s.synced.delete(w) - slowWatcherGauge.Inc() - } - } - s.addVictim(victim) -} - -func (s *watchableStore) addVictim(victim watcherBatch) { - if victim == nil { - return - } - s.victims = append(s.victims, victim) - select { - case s.victimc <- struct{}{}: - default: - } -} - -func (s *watchableStore) rev() int64 { return s.store.Rev() } - -func (s *watchableStore) progress(w *watcher) { - s.mu.RLock() - defer s.mu.RUnlock() - - if _, ok := s.synced.watchers[w]; ok { - w.send(WatchResponse{WatchID: w.id, Revision: s.rev()}) - // If the ch is full, this watcher is receiving events. - // We do not need to send progress at all. - } -} - -type watcher struct { - // the watcher key - key []byte - // end indicates the end of the range to watch. - // If end is set, the watcher is on a range. - end []byte - - // victim is set when ch is blocked and undergoing victim processing - victim bool - - // compacted is set when the watcher is removed because of compaction - compacted bool - - // restore is true when the watcher is being restored from leader snapshot - // which means that this watcher has just been moved from "synced" to "unsynced" - // watcher group, possibly with a future revision when it was first added - // to the synced watcher - // "unsynced" watcher revision must always be <= current revision, - // except when the watcher were to be moved from "synced" watcher group - restore bool - - // minRev is the minimum revision update the watcher will accept - minRev int64 - id WatchID - - fcs []FilterFunc - // a chan to send out the watch response. - // The chan might be shared with other watchers. - ch chan<- WatchResponse -} - -func (w *watcher) send(wr WatchResponse) bool { - progressEvent := len(wr.Events) == 0 - - if len(w.fcs) != 0 { - ne := make([]mvccpb.Event, 0, len(wr.Events)) - for i := range wr.Events { - filtered := false - for _, filter := range w.fcs { - if filter(wr.Events[i]) { - filtered = true - break - } - } - if !filtered { - ne = append(ne, wr.Events[i]) - } - } - wr.Events = ne - } - - // if all events are filtered out, we should send nothing. - if !progressEvent && len(wr.Events) == 0 { - return true - } - select { - case w.ch <- wr: - return true - default: - return false - } -} diff --git a/vendor/github.com/coreos/etcd/mvcc/watchable_store_txn.go b/vendor/github.com/coreos/etcd/mvcc/watchable_store_txn.go deleted file mode 100644 index 5c5bfda13413..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/watchable_store_txn.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "github.com/coreos/etcd/mvcc/mvccpb" -) - -func (tw *watchableStoreTxnWrite) End() { - changes := tw.Changes() - if len(changes) == 0 { - tw.TxnWrite.End() - return - } - - rev := tw.Rev() + 1 - evs := make([]mvccpb.Event, len(changes)) - for i, change := range changes { - evs[i].Kv = &changes[i] - if change.CreateRevision == 0 { - evs[i].Type = mvccpb.DELETE - evs[i].Kv.ModRevision = rev - } else { - evs[i].Type = mvccpb.PUT - } - } - - // end write txn under watchable store lock so the updates are visible - // when asynchronous event posting checks the current store revision - tw.s.mu.Lock() - tw.s.notify(rev, evs) - tw.TxnWrite.End() - tw.s.mu.Unlock() -} - -type watchableStoreTxnWrite struct { - TxnWrite - s *watchableStore -} - -func (s *watchableStore) Write() TxnWrite { return &watchableStoreTxnWrite{s.store.Write(), s} } diff --git a/vendor/github.com/coreos/etcd/mvcc/watcher.go b/vendor/github.com/coreos/etcd/mvcc/watcher.go deleted file mode 100644 index bc0c6322fd1f..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/watcher.go +++ /dev/null @@ -1,180 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "bytes" - "errors" - "sync" - - "github.com/coreos/etcd/mvcc/mvccpb" -) - -var ( - ErrWatcherNotExist = errors.New("mvcc: watcher does not exist") -) - -type WatchID int64 - -// FilterFunc returns true if the given event should be filtered out. -type FilterFunc func(e mvccpb.Event) bool - -type WatchStream interface { - // Watch creates a watcher. The watcher watches the events happening or - // happened on the given key or range [key, end) from the given startRev. - // - // The whole event history can be watched unless compacted. - // If `startRev` <=0, watch observes events after currentRev. - // - // The returned `id` is the ID of this watcher. It appears as WatchID - // in events that are sent to the created watcher through stream channel. - // - Watch(key, end []byte, startRev int64, fcs ...FilterFunc) WatchID - - // Chan returns a chan. All watch response will be sent to the returned chan. - Chan() <-chan WatchResponse - - // RequestProgress requests the progress of the watcher with given ID. The response - // will only be sent if the watcher is currently synced. - // The responses will be sent through the WatchRespone Chan attached - // with this stream to ensure correct ordering. - // The responses contains no events. The revision in the response is the progress - // of the watchers since the watcher is currently synced. - RequestProgress(id WatchID) - - // Cancel cancels a watcher by giving its ID. If watcher does not exist, an error will be - // returned. - Cancel(id WatchID) error - - // Close closes Chan and release all related resources. - Close() - - // Rev returns the current revision of the KV the stream watches on. - Rev() int64 -} - -type WatchResponse struct { - // WatchID is the WatchID of the watcher this response sent to. - WatchID WatchID - - // Events contains all the events that needs to send. - Events []mvccpb.Event - - // Revision is the revision of the KV when the watchResponse is created. - // For a normal response, the revision should be the same as the last - // modified revision inside Events. For a delayed response to a unsynced - // watcher, the revision is greater than the last modified revision - // inside Events. - Revision int64 - - // CompactRevision is set when the watcher is cancelled due to compaction. - CompactRevision int64 -} - -// watchStream contains a collection of watchers that share -// one streaming chan to send out watched events and other control events. -type watchStream struct { - watchable watchable - ch chan WatchResponse - - mu sync.Mutex // guards fields below it - // nextID is the ID pre-allocated for next new watcher in this stream - nextID WatchID - closed bool - cancels map[WatchID]cancelFunc - watchers map[WatchID]*watcher -} - -// Watch creates a new watcher in the stream and returns its WatchID. -// TODO: return error if ws is closed? -func (ws *watchStream) Watch(key, end []byte, startRev int64, fcs ...FilterFunc) WatchID { - // prevent wrong range where key >= end lexicographically - // watch request with 'WithFromKey' has empty-byte range end - if len(end) != 0 && bytes.Compare(key, end) != -1 { - return -1 - } - - ws.mu.Lock() - defer ws.mu.Unlock() - if ws.closed { - return -1 - } - - id := ws.nextID - ws.nextID++ - - w, c := ws.watchable.watch(key, end, startRev, id, ws.ch, fcs...) - - ws.cancels[id] = c - ws.watchers[id] = w - return id -} - -func (ws *watchStream) Chan() <-chan WatchResponse { - return ws.ch -} - -func (ws *watchStream) Cancel(id WatchID) error { - ws.mu.Lock() - cancel, ok := ws.cancels[id] - w := ws.watchers[id] - ok = ok && !ws.closed - ws.mu.Unlock() - - if !ok { - return ErrWatcherNotExist - } - cancel() - - ws.mu.Lock() - // The watch isn't removed until cancel so that if Close() is called, - // it will wait for the cancel. Otherwise, Close() could close the - // watch channel while the store is still posting events. - if ww := ws.watchers[id]; ww == w { - delete(ws.cancels, id) - delete(ws.watchers, id) - } - ws.mu.Unlock() - - return nil -} - -func (ws *watchStream) Close() { - ws.mu.Lock() - defer ws.mu.Unlock() - - for _, cancel := range ws.cancels { - cancel() - } - ws.closed = true - close(ws.ch) - watchStreamGauge.Dec() -} - -func (ws *watchStream) Rev() int64 { - ws.mu.Lock() - defer ws.mu.Unlock() - return ws.watchable.rev() -} - -func (ws *watchStream) RequestProgress(id WatchID) { - ws.mu.Lock() - w, ok := ws.watchers[id] - ws.mu.Unlock() - if !ok { - return - } - ws.watchable.progress(w) -} diff --git a/vendor/github.com/coreos/etcd/mvcc/watcher_group.go b/vendor/github.com/coreos/etcd/mvcc/watcher_group.go deleted file mode 100644 index b65c7bc5eb7e..000000000000 --- a/vendor/github.com/coreos/etcd/mvcc/watcher_group.go +++ /dev/null @@ -1,292 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "fmt" - "math" - - "github.com/coreos/etcd/mvcc/mvccpb" - "github.com/coreos/etcd/pkg/adt" -) - -var ( - // watchBatchMaxRevs is the maximum distinct revisions that - // may be sent to an unsynced watcher at a time. Declared as - // var instead of const for testing purposes. - watchBatchMaxRevs = 1000 -) - -type eventBatch struct { - // evs is a batch of revision-ordered events - evs []mvccpb.Event - // revs is the minimum unique revisions observed for this batch - revs int - // moreRev is first revision with more events following this batch - moreRev int64 -} - -func (eb *eventBatch) add(ev mvccpb.Event) { - if eb.revs > watchBatchMaxRevs { - // maxed out batch size - return - } - - if len(eb.evs) == 0 { - // base case - eb.revs = 1 - eb.evs = append(eb.evs, ev) - return - } - - // revision accounting - ebRev := eb.evs[len(eb.evs)-1].Kv.ModRevision - evRev := ev.Kv.ModRevision - if evRev > ebRev { - eb.revs++ - if eb.revs > watchBatchMaxRevs { - eb.moreRev = evRev - return - } - } - - eb.evs = append(eb.evs, ev) -} - -type watcherBatch map[*watcher]*eventBatch - -func (wb watcherBatch) add(w *watcher, ev mvccpb.Event) { - eb := wb[w] - if eb == nil { - eb = &eventBatch{} - wb[w] = eb - } - eb.add(ev) -} - -// newWatcherBatch maps watchers to their matched events. It enables quick -// events look up by watcher. -func newWatcherBatch(wg *watcherGroup, evs []mvccpb.Event) watcherBatch { - if len(wg.watchers) == 0 { - return nil - } - - wb := make(watcherBatch) - for _, ev := range evs { - for w := range wg.watcherSetByKey(string(ev.Kv.Key)) { - if ev.Kv.ModRevision >= w.minRev { - // don't double notify - wb.add(w, ev) - } - } - } - return wb -} - -type watcherSet map[*watcher]struct{} - -func (w watcherSet) add(wa *watcher) { - if _, ok := w[wa]; ok { - panic("add watcher twice!") - } - w[wa] = struct{}{} -} - -func (w watcherSet) union(ws watcherSet) { - for wa := range ws { - w.add(wa) - } -} - -func (w watcherSet) delete(wa *watcher) { - if _, ok := w[wa]; !ok { - panic("removing missing watcher!") - } - delete(w, wa) -} - -type watcherSetByKey map[string]watcherSet - -func (w watcherSetByKey) add(wa *watcher) { - set := w[string(wa.key)] - if set == nil { - set = make(watcherSet) - w[string(wa.key)] = set - } - set.add(wa) -} - -func (w watcherSetByKey) delete(wa *watcher) bool { - k := string(wa.key) - if v, ok := w[k]; ok { - if _, ok := v[wa]; ok { - delete(v, wa) - if len(v) == 0 { - // remove the set; nothing left - delete(w, k) - } - return true - } - } - return false -} - -// watcherGroup is a collection of watchers organized by their ranges -type watcherGroup struct { - // keyWatchers has the watchers that watch on a single key - keyWatchers watcherSetByKey - // ranges has the watchers that watch a range; it is sorted by interval - ranges adt.IntervalTree - // watchers is the set of all watchers - watchers watcherSet -} - -func newWatcherGroup() watcherGroup { - return watcherGroup{ - keyWatchers: make(watcherSetByKey), - watchers: make(watcherSet), - } -} - -// add puts a watcher in the group. -func (wg *watcherGroup) add(wa *watcher) { - wg.watchers.add(wa) - if wa.end == nil { - wg.keyWatchers.add(wa) - return - } - - // interval already registered? - ivl := adt.NewStringAffineInterval(string(wa.key), string(wa.end)) - if iv := wg.ranges.Find(ivl); iv != nil { - iv.Val.(watcherSet).add(wa) - return - } - - // not registered, put in interval tree - ws := make(watcherSet) - ws.add(wa) - wg.ranges.Insert(ivl, ws) -} - -// contains is whether the given key has a watcher in the group. -func (wg *watcherGroup) contains(key string) bool { - _, ok := wg.keyWatchers[key] - return ok || wg.ranges.Intersects(adt.NewStringAffinePoint(key)) -} - -// size gives the number of unique watchers in the group. -func (wg *watcherGroup) size() int { return len(wg.watchers) } - -// delete removes a watcher from the group. -func (wg *watcherGroup) delete(wa *watcher) bool { - if _, ok := wg.watchers[wa]; !ok { - return false - } - wg.watchers.delete(wa) - if wa.end == nil { - wg.keyWatchers.delete(wa) - return true - } - - ivl := adt.NewStringAffineInterval(string(wa.key), string(wa.end)) - iv := wg.ranges.Find(ivl) - if iv == nil { - return false - } - - ws := iv.Val.(watcherSet) - delete(ws, wa) - if len(ws) == 0 { - // remove interval missing watchers - if ok := wg.ranges.Delete(ivl); !ok { - panic("could not remove watcher from interval tree") - } - } - - return true -} - -// choose selects watchers from the watcher group to update -func (wg *watcherGroup) choose(maxWatchers int, curRev, compactRev int64) (*watcherGroup, int64) { - if len(wg.watchers) < maxWatchers { - return wg, wg.chooseAll(curRev, compactRev) - } - ret := newWatcherGroup() - for w := range wg.watchers { - if maxWatchers <= 0 { - break - } - maxWatchers-- - ret.add(w) - } - return &ret, ret.chooseAll(curRev, compactRev) -} - -func (wg *watcherGroup) chooseAll(curRev, compactRev int64) int64 { - minRev := int64(math.MaxInt64) - for w := range wg.watchers { - if w.minRev > curRev { - // after network partition, possibly choosing future revision watcher from restore operation - // with watch key "proxy-namespace__lostleader" and revision "math.MaxInt64 - 2" - // do not panic when such watcher had been moved from "synced" watcher during restore operation - if !w.restore { - panic(fmt.Errorf("watcher minimum revision %d should not exceed current revision %d", w.minRev, curRev)) - } - - // mark 'restore' done, since it's chosen - w.restore = false - } - if w.minRev < compactRev { - select { - case w.ch <- WatchResponse{WatchID: w.id, CompactRevision: compactRev}: - w.compacted = true - wg.delete(w) - default: - // retry next time - } - continue - } - if minRev > w.minRev { - minRev = w.minRev - } - } - return minRev -} - -// watcherSetByKey gets the set of watchers that receive events on the given key. -func (wg *watcherGroup) watcherSetByKey(key string) watcherSet { - wkeys := wg.keyWatchers[key] - wranges := wg.ranges.Stab(adt.NewStringAffinePoint(key)) - - // zero-copy cases - switch { - case len(wranges) == 0: - // no need to merge ranges or copy; reuse single-key set - return wkeys - case len(wranges) == 0 && len(wkeys) == 0: - return nil - case len(wranges) == 1 && len(wkeys) == 0: - return wranges[0].Val.(watcherSet) - } - - // copy case - ret := make(watcherSet) - ret.union(wg.keyWatchers[key]) - for _, item := range wranges { - ret.union(item.Val.(watcherSet)) - } - return ret -} diff --git a/vendor/github.com/coreos/etcd/pkg/adt/doc.go b/vendor/github.com/coreos/etcd/pkg/adt/doc.go deleted file mode 100644 index 1a9559145b31..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/adt/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package adt implements useful abstract data types. -package adt diff --git a/vendor/github.com/coreos/etcd/pkg/adt/interval_tree.go b/vendor/github.com/coreos/etcd/pkg/adt/interval_tree.go deleted file mode 100644 index ec302e4a7a96..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/adt/interval_tree.go +++ /dev/null @@ -1,599 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adt - -import ( - "bytes" - "math" -) - -// Comparable is an interface for trichotomic comparisons. -type Comparable interface { - // Compare gives the result of a 3-way comparison - // a.Compare(b) = 1 => a > b - // a.Compare(b) = 0 => a == b - // a.Compare(b) = -1 => a < b - Compare(c Comparable) int -} - -type rbcolor int - -const ( - black rbcolor = iota - red -) - -// Interval implements a Comparable interval [begin, end) -// TODO: support different sorts of intervals: (a,b), [a,b], (a, b] -type Interval struct { - Begin Comparable - End Comparable -} - -// Compare on an interval gives == if the interval overlaps. -func (ivl *Interval) Compare(c Comparable) int { - ivl2 := c.(*Interval) - ivbCmpBegin := ivl.Begin.Compare(ivl2.Begin) - ivbCmpEnd := ivl.Begin.Compare(ivl2.End) - iveCmpBegin := ivl.End.Compare(ivl2.Begin) - - // ivl is left of ivl2 - if ivbCmpBegin < 0 && iveCmpBegin <= 0 { - return -1 - } - - // iv is right of iv2 - if ivbCmpEnd >= 0 { - return 1 - } - - return 0 -} - -type intervalNode struct { - // iv is the interval-value pair entry. - iv IntervalValue - // max endpoint of all descendent nodes. - max Comparable - // left and right are sorted by low endpoint of key interval - left, right *intervalNode - // parent is the direct ancestor of the node - parent *intervalNode - c rbcolor -} - -func (x *intervalNode) color() rbcolor { - if x == nil { - return black - } - return x.c -} - -func (n *intervalNode) height() int { - if n == nil { - return 0 - } - ld := n.left.height() - rd := n.right.height() - if ld < rd { - return rd + 1 - } - return ld + 1 -} - -func (x *intervalNode) min() *intervalNode { - for x.left != nil { - x = x.left - } - return x -} - -// successor is the next in-order node in the tree -func (x *intervalNode) successor() *intervalNode { - if x.right != nil { - return x.right.min() - } - y := x.parent - for y != nil && x == y.right { - x = y - y = y.parent - } - return y -} - -// updateMax updates the maximum values for a node and its ancestors -func (x *intervalNode) updateMax() { - for x != nil { - oldmax := x.max - max := x.iv.Ivl.End - if x.left != nil && x.left.max.Compare(max) > 0 { - max = x.left.max - } - if x.right != nil && x.right.max.Compare(max) > 0 { - max = x.right.max - } - if oldmax.Compare(max) == 0 { - break - } - x.max = max - x = x.parent - } -} - -type nodeVisitor func(n *intervalNode) bool - -// visit will call a node visitor on each node that overlaps the given interval -func (x *intervalNode) visit(iv *Interval, nv nodeVisitor) bool { - if x == nil { - return true - } - v := iv.Compare(&x.iv.Ivl) - switch { - case v < 0: - if !x.left.visit(iv, nv) { - return false - } - case v > 0: - maxiv := Interval{x.iv.Ivl.Begin, x.max} - if maxiv.Compare(iv) == 0 { - if !x.left.visit(iv, nv) || !x.right.visit(iv, nv) { - return false - } - } - default: - if !x.left.visit(iv, nv) || !nv(x) || !x.right.visit(iv, nv) { - return false - } - } - return true -} - -type IntervalValue struct { - Ivl Interval - Val interface{} -} - -// IntervalTree represents a (mostly) textbook implementation of the -// "Introduction to Algorithms" (Cormen et al, 2nd ed.) chapter 13 red-black tree -// and chapter 14.3 interval tree with search supporting "stabbing queries". -type IntervalTree struct { - root *intervalNode - count int -} - -// Delete removes the node with the given interval from the tree, returning -// true if a node is in fact removed. -func (ivt *IntervalTree) Delete(ivl Interval) bool { - z := ivt.find(ivl) - if z == nil { - return false - } - - y := z - if z.left != nil && z.right != nil { - y = z.successor() - } - - x := y.left - if x == nil { - x = y.right - } - if x != nil { - x.parent = y.parent - } - - if y.parent == nil { - ivt.root = x - } else { - if y == y.parent.left { - y.parent.left = x - } else { - y.parent.right = x - } - y.parent.updateMax() - } - if y != z { - z.iv = y.iv - z.updateMax() - } - - if y.color() == black && x != nil { - ivt.deleteFixup(x) - } - - ivt.count-- - return true -} - -func (ivt *IntervalTree) deleteFixup(x *intervalNode) { - for x != ivt.root && x.color() == black && x.parent != nil { - if x == x.parent.left { - w := x.parent.right - if w.color() == red { - w.c = black - x.parent.c = red - ivt.rotateLeft(x.parent) - w = x.parent.right - } - if w == nil { - break - } - if w.left.color() == black && w.right.color() == black { - w.c = red - x = x.parent - } else { - if w.right.color() == black { - w.left.c = black - w.c = red - ivt.rotateRight(w) - w = x.parent.right - } - w.c = x.parent.color() - x.parent.c = black - w.right.c = black - ivt.rotateLeft(x.parent) - x = ivt.root - } - } else { - // same as above but with left and right exchanged - w := x.parent.left - if w.color() == red { - w.c = black - x.parent.c = red - ivt.rotateRight(x.parent) - w = x.parent.left - } - if w == nil { - break - } - if w.left.color() == black && w.right.color() == black { - w.c = red - x = x.parent - } else { - if w.left.color() == black { - w.right.c = black - w.c = red - ivt.rotateLeft(w) - w = x.parent.left - } - w.c = x.parent.color() - x.parent.c = black - w.left.c = black - ivt.rotateRight(x.parent) - x = ivt.root - } - } - } - if x != nil { - x.c = black - } -} - -// Insert adds a node with the given interval into the tree. -func (ivt *IntervalTree) Insert(ivl Interval, val interface{}) { - var y *intervalNode - z := &intervalNode{iv: IntervalValue{ivl, val}, max: ivl.End, c: red} - x := ivt.root - for x != nil { - y = x - if z.iv.Ivl.Begin.Compare(x.iv.Ivl.Begin) < 0 { - x = x.left - } else { - x = x.right - } - } - - z.parent = y - if y == nil { - ivt.root = z - } else { - if z.iv.Ivl.Begin.Compare(y.iv.Ivl.Begin) < 0 { - y.left = z - } else { - y.right = z - } - y.updateMax() - } - z.c = red - ivt.insertFixup(z) - ivt.count++ -} - -func (ivt *IntervalTree) insertFixup(z *intervalNode) { - for z.parent != nil && z.parent.parent != nil && z.parent.color() == red { - if z.parent == z.parent.parent.left { - y := z.parent.parent.right - if y.color() == red { - y.c = black - z.parent.c = black - z.parent.parent.c = red - z = z.parent.parent - } else { - if z == z.parent.right { - z = z.parent - ivt.rotateLeft(z) - } - z.parent.c = black - z.parent.parent.c = red - ivt.rotateRight(z.parent.parent) - } - } else { - // same as then with left/right exchanged - y := z.parent.parent.left - if y.color() == red { - y.c = black - z.parent.c = black - z.parent.parent.c = red - z = z.parent.parent - } else { - if z == z.parent.left { - z = z.parent - ivt.rotateRight(z) - } - z.parent.c = black - z.parent.parent.c = red - ivt.rotateLeft(z.parent.parent) - } - } - } - ivt.root.c = black -} - -// rotateLeft moves x so it is left of its right child -func (ivt *IntervalTree) rotateLeft(x *intervalNode) { - y := x.right - x.right = y.left - if y.left != nil { - y.left.parent = x - } - x.updateMax() - ivt.replaceParent(x, y) - y.left = x - y.updateMax() -} - -// rotateLeft moves x so it is right of its left child -func (ivt *IntervalTree) rotateRight(x *intervalNode) { - if x == nil { - return - } - y := x.left - x.left = y.right - if y.right != nil { - y.right.parent = x - } - x.updateMax() - ivt.replaceParent(x, y) - y.right = x - y.updateMax() -} - -// replaceParent replaces x's parent with y -func (ivt *IntervalTree) replaceParent(x *intervalNode, y *intervalNode) { - y.parent = x.parent - if x.parent == nil { - ivt.root = y - } else { - if x == x.parent.left { - x.parent.left = y - } else { - x.parent.right = y - } - x.parent.updateMax() - } - x.parent = y -} - -// Len gives the number of elements in the tree -func (ivt *IntervalTree) Len() int { return ivt.count } - -// Height is the number of levels in the tree; one node has height 1. -func (ivt *IntervalTree) Height() int { return ivt.root.height() } - -// MaxHeight is the expected maximum tree height given the number of nodes -func (ivt *IntervalTree) MaxHeight() int { - return int((2 * math.Log2(float64(ivt.Len()+1))) + 0.5) -} - -// IntervalVisitor is used on tree searches; return false to stop searching. -type IntervalVisitor func(n *IntervalValue) bool - -// Visit calls a visitor function on every tree node intersecting the given interval. -// It will visit each interval [x, y) in ascending order sorted on x. -func (ivt *IntervalTree) Visit(ivl Interval, ivv IntervalVisitor) { - ivt.root.visit(&ivl, func(n *intervalNode) bool { return ivv(&n.iv) }) -} - -// find the exact node for a given interval -func (ivt *IntervalTree) find(ivl Interval) (ret *intervalNode) { - f := func(n *intervalNode) bool { - if n.iv.Ivl != ivl { - return true - } - ret = n - return false - } - ivt.root.visit(&ivl, f) - return ret -} - -// Find gets the IntervalValue for the node matching the given interval -func (ivt *IntervalTree) Find(ivl Interval) (ret *IntervalValue) { - n := ivt.find(ivl) - if n == nil { - return nil - } - return &n.iv -} - -// Intersects returns true if there is some tree node intersecting the given interval. -func (ivt *IntervalTree) Intersects(iv Interval) bool { - x := ivt.root - for x != nil && iv.Compare(&x.iv.Ivl) != 0 { - if x.left != nil && x.left.max.Compare(iv.Begin) > 0 { - x = x.left - } else { - x = x.right - } - } - return x != nil -} - -// Contains returns true if the interval tree's keys cover the entire given interval. -func (ivt *IntervalTree) Contains(ivl Interval) bool { - var maxEnd, minBegin Comparable - - isContiguous := true - ivt.Visit(ivl, func(n *IntervalValue) bool { - if minBegin == nil { - minBegin = n.Ivl.Begin - maxEnd = n.Ivl.End - return true - } - if maxEnd.Compare(n.Ivl.Begin) < 0 { - isContiguous = false - return false - } - if n.Ivl.End.Compare(maxEnd) > 0 { - maxEnd = n.Ivl.End - } - return true - }) - - return isContiguous && minBegin != nil && maxEnd.Compare(ivl.End) >= 0 && minBegin.Compare(ivl.Begin) <= 0 -} - -// Stab returns a slice with all elements in the tree intersecting the interval. -func (ivt *IntervalTree) Stab(iv Interval) (ivs []*IntervalValue) { - if ivt.count == 0 { - return nil - } - f := func(n *IntervalValue) bool { ivs = append(ivs, n); return true } - ivt.Visit(iv, f) - return ivs -} - -// Union merges a given interval tree into the receiver. -func (ivt *IntervalTree) Union(inIvt IntervalTree, ivl Interval) { - f := func(n *IntervalValue) bool { - ivt.Insert(n.Ivl, n.Val) - return true - } - inIvt.Visit(ivl, f) -} - -type StringComparable string - -func (s StringComparable) Compare(c Comparable) int { - sc := c.(StringComparable) - if s < sc { - return -1 - } - if s > sc { - return 1 - } - return 0 -} - -func NewStringInterval(begin, end string) Interval { - return Interval{StringComparable(begin), StringComparable(end)} -} - -func NewStringPoint(s string) Interval { - return Interval{StringComparable(s), StringComparable(s + "\x00")} -} - -// StringAffineComparable treats "" as > all other strings -type StringAffineComparable string - -func (s StringAffineComparable) Compare(c Comparable) int { - sc := c.(StringAffineComparable) - - if len(s) == 0 { - if len(sc) == 0 { - return 0 - } - return 1 - } - if len(sc) == 0 { - return -1 - } - - if s < sc { - return -1 - } - if s > sc { - return 1 - } - return 0 -} - -func NewStringAffineInterval(begin, end string) Interval { - return Interval{StringAffineComparable(begin), StringAffineComparable(end)} -} -func NewStringAffinePoint(s string) Interval { - return NewStringAffineInterval(s, s+"\x00") -} - -func NewInt64Interval(a int64, b int64) Interval { - return Interval{Int64Comparable(a), Int64Comparable(b)} -} - -func NewInt64Point(a int64) Interval { - return Interval{Int64Comparable(a), Int64Comparable(a + 1)} -} - -type Int64Comparable int64 - -func (v Int64Comparable) Compare(c Comparable) int { - vc := c.(Int64Comparable) - cmp := v - vc - if cmp < 0 { - return -1 - } - if cmp > 0 { - return 1 - } - return 0 -} - -// BytesAffineComparable treats empty byte arrays as > all other byte arrays -type BytesAffineComparable []byte - -func (b BytesAffineComparable) Compare(c Comparable) int { - bc := c.(BytesAffineComparable) - - if len(b) == 0 { - if len(bc) == 0 { - return 0 - } - return 1 - } - if len(bc) == 0 { - return -1 - } - - return bytes.Compare(b, bc) -} - -func NewBytesAffineInterval(begin, end []byte) Interval { - return Interval{BytesAffineComparable(begin), BytesAffineComparable(end)} -} -func NewBytesAffinePoint(b []byte) Interval { - be := make([]byte, len(b)+1) - copy(be, b) - be[len(b)] = 0 - return NewBytesAffineInterval(b, be) -} diff --git a/vendor/github.com/coreos/etcd/pkg/contention/contention.go b/vendor/github.com/coreos/etcd/pkg/contention/contention.go deleted file mode 100644 index 26ce9a2f3473..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/contention/contention.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package contention - -import ( - "sync" - "time" -) - -// TimeoutDetector detects routine starvations by -// observing the actual time duration to finish an action -// or between two events that should happen in a fixed -// interval. If the observed duration is longer than -// the expectation, the detector will report the result. -type TimeoutDetector struct { - mu sync.Mutex // protects all - maxDuration time.Duration - // map from event to time - // time is the last seen time of the event. - records map[uint64]time.Time -} - -// NewTimeoutDetector creates the TimeoutDetector. -func NewTimeoutDetector(maxDuration time.Duration) *TimeoutDetector { - return &TimeoutDetector{ - maxDuration: maxDuration, - records: make(map[uint64]time.Time), - } -} - -// Reset resets the NewTimeoutDetector. -func (td *TimeoutDetector) Reset() { - td.mu.Lock() - defer td.mu.Unlock() - - td.records = make(map[uint64]time.Time) -} - -// Observe observes an event for given id. It returns false and exceeded duration -// if the interval is longer than the expectation. -func (td *TimeoutDetector) Observe(which uint64) (bool, time.Duration) { - td.mu.Lock() - defer td.mu.Unlock() - - ok := true - now := time.Now() - exceed := time.Duration(0) - - if pt, found := td.records[which]; found { - exceed = now.Sub(pt) - td.maxDuration - if exceed > 0 { - ok = false - } - } - td.records[which] = now - return ok, exceed -} diff --git a/vendor/github.com/coreos/etcd/pkg/contention/doc.go b/vendor/github.com/coreos/etcd/pkg/contention/doc.go deleted file mode 100644 index daf452219e07..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/contention/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package contention provides facilities for detecting system contention. -package contention diff --git a/vendor/github.com/coreos/etcd/pkg/cors/cors.go b/vendor/github.com/coreos/etcd/pkg/cors/cors.go deleted file mode 100644 index 0c64f16a3905..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/cors/cors.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package cors handles cross-origin HTTP requests (CORS). -package cors - -import ( - "fmt" - "net/http" - "net/url" - "sort" - "strings" -) - -type CORSInfo map[string]bool - -// Set implements the flag.Value interface to allow users to define a list of CORS origins -func (ci *CORSInfo) Set(s string) error { - m := make(map[string]bool) - for _, v := range strings.Split(s, ",") { - v = strings.TrimSpace(v) - if v == "" { - continue - } - if v != "*" { - if _, err := url.Parse(v); err != nil { - return fmt.Errorf("Invalid CORS origin: %s", err) - } - } - m[v] = true - - } - *ci = CORSInfo(m) - return nil -} - -func (ci *CORSInfo) String() string { - o := make([]string, 0) - for k := range *ci { - o = append(o, k) - } - sort.StringSlice(o).Sort() - return strings.Join(o, ",") -} - -// OriginAllowed determines whether the server will allow a given CORS origin. -func (c CORSInfo) OriginAllowed(origin string) bool { - return c["*"] || c[origin] -} - -type CORSHandler struct { - Handler http.Handler - Info *CORSInfo -} - -// addHeader adds the correct cors headers given an origin -func (h *CORSHandler) addHeader(w http.ResponseWriter, origin string) { - w.Header().Add("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") - w.Header().Add("Access-Control-Allow-Origin", origin) - w.Header().Add("Access-Control-Allow-Headers", "accept, content-type, authorization") -} - -// ServeHTTP adds the correct CORS headers based on the origin and returns immediately -// with a 200 OK if the method is OPTIONS. -func (h *CORSHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { - // Write CORS header. - if h.Info.OriginAllowed("*") { - h.addHeader(w, "*") - } else if origin := req.Header.Get("Origin"); h.Info.OriginAllowed(origin) { - h.addHeader(w, origin) - } - - if req.Method == "OPTIONS" { - w.WriteHeader(http.StatusOK) - return - } - - h.Handler.ServeHTTP(w, req) -} diff --git a/vendor/github.com/coreos/etcd/pkg/cpuutil/doc.go b/vendor/github.com/coreos/etcd/pkg/cpuutil/doc.go deleted file mode 100644 index 0323b2d34c64..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/cpuutil/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package cpuutil provides facilities for detecting cpu-specific features. -package cpuutil diff --git a/vendor/github.com/coreos/etcd/pkg/cpuutil/endian.go b/vendor/github.com/coreos/etcd/pkg/cpuutil/endian.go deleted file mode 100644 index 6ab898d4b596..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/cpuutil/endian.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package cpuutil - -import ( - "encoding/binary" - "unsafe" -) - -const intWidth int = int(unsafe.Sizeof(0)) - -var byteOrder binary.ByteOrder - -// ByteOrder returns the byte order for the CPU's native endianness. -func ByteOrder() binary.ByteOrder { return byteOrder } - -func init() { - var i int = 0x1 - if v := (*[intWidth]byte)(unsafe.Pointer(&i)); v[0] == 0 { - byteOrder = binary.BigEndian - } else { - byteOrder = binary.LittleEndian - } -} diff --git a/vendor/github.com/coreos/etcd/pkg/crc/crc.go b/vendor/github.com/coreos/etcd/pkg/crc/crc.go deleted file mode 100644 index 4b998a48455f..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/crc/crc.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package crc provides utility function for cyclic redundancy check -// algorithms. -package crc - -import ( - "hash" - "hash/crc32" -) - -// The size of a CRC-32 checksum in bytes. -const Size = 4 - -type digest struct { - crc uint32 - tab *crc32.Table -} - -// New creates a new hash.Hash32 computing the CRC-32 checksum -// using the polynomial represented by the Table. -// Modified by xiangli to take a prevcrc. -func New(prev uint32, tab *crc32.Table) hash.Hash32 { return &digest{prev, tab} } - -func (d *digest) Size() int { return Size } - -func (d *digest) BlockSize() int { return 1 } - -func (d *digest) Reset() { d.crc = 0 } - -func (d *digest) Write(p []byte) (n int, err error) { - d.crc = crc32.Update(d.crc, d.tab, p) - return len(p), nil -} - -func (d *digest) Sum32() uint32 { return d.crc } - -func (d *digest) Sum(in []byte) []byte { - s := d.Sum32() - return append(in, byte(s>>24), byte(s>>16), byte(s>>8), byte(s)) -} diff --git a/vendor/github.com/coreos/etcd/pkg/debugutil/doc.go b/vendor/github.com/coreos/etcd/pkg/debugutil/doc.go deleted file mode 100644 index 74499eb2737e..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/debugutil/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package debugutil includes utility functions for debugging. -package debugutil diff --git a/vendor/github.com/coreos/etcd/pkg/debugutil/pprof.go b/vendor/github.com/coreos/etcd/pkg/debugutil/pprof.go deleted file mode 100644 index 8d5544a3dcac..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/debugutil/pprof.go +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package debugutil - -import ( - "net/http" - "net/http/pprof" - "runtime" -) - -const HTTPPrefixPProf = "/debug/pprof" - -// PProfHandlers returns a map of pprof handlers keyed by the HTTP path. -func PProfHandlers() map[string]http.Handler { - // set only when there's no existing setting - if runtime.SetMutexProfileFraction(-1) == 0 { - // 1 out of 5 mutex events are reported, on average - runtime.SetMutexProfileFraction(5) - } - - m := make(map[string]http.Handler) - - m[HTTPPrefixPProf+"/"] = http.HandlerFunc(pprof.Index) - m[HTTPPrefixPProf+"/profile"] = http.HandlerFunc(pprof.Profile) - m[HTTPPrefixPProf+"/symbol"] = http.HandlerFunc(pprof.Symbol) - m[HTTPPrefixPProf+"/cmdline"] = http.HandlerFunc(pprof.Cmdline) - m[HTTPPrefixPProf+"/trace "] = http.HandlerFunc(pprof.Trace) - m[HTTPPrefixPProf+"/heap"] = pprof.Handler("heap") - m[HTTPPrefixPProf+"/goroutine"] = pprof.Handler("goroutine") - m[HTTPPrefixPProf+"/threadcreate"] = pprof.Handler("threadcreate") - m[HTTPPrefixPProf+"/block"] = pprof.Handler("block") - m[HTTPPrefixPProf+"/mutex"] = pprof.Handler("mutex") - - return m -} diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/dir_unix.go b/vendor/github.com/coreos/etcd/pkg/fileutil/dir_unix.go deleted file mode 100644 index 58a77dfc1a99..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/dir_unix.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !windows - -package fileutil - -import "os" - -// OpenDir opens a directory for syncing. -func OpenDir(path string) (*os.File, error) { return os.Open(path) } diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/dir_windows.go b/vendor/github.com/coreos/etcd/pkg/fileutil/dir_windows.go deleted file mode 100644 index c123395c0040..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/dir_windows.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build windows - -package fileutil - -import ( - "os" - "syscall" -) - -// OpenDir opens a directory in windows with write access for syncing. -func OpenDir(path string) (*os.File, error) { - fd, err := openDir(path) - if err != nil { - return nil, err - } - return os.NewFile(uintptr(fd), path), nil -} - -func openDir(path string) (fd syscall.Handle, err error) { - if len(path) == 0 { - return syscall.InvalidHandle, syscall.ERROR_FILE_NOT_FOUND - } - pathp, err := syscall.UTF16PtrFromString(path) - if err != nil { - return syscall.InvalidHandle, err - } - access := uint32(syscall.GENERIC_READ | syscall.GENERIC_WRITE) - sharemode := uint32(syscall.FILE_SHARE_READ | syscall.FILE_SHARE_WRITE) - createmode := uint32(syscall.OPEN_EXISTING) - fl := uint32(syscall.FILE_FLAG_BACKUP_SEMANTICS) - return syscall.CreateFile(pathp, access, sharemode, nil, createmode, fl, 0) -} diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/fileutil.go b/vendor/github.com/coreos/etcd/pkg/fileutil/fileutil.go deleted file mode 100644 index fce5126c6956..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/fileutil.go +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package fileutil implements utility functions related to files and paths. -package fileutil - -import ( - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "sort" - - "github.com/coreos/pkg/capnslog" -) - -const ( - // PrivateFileMode grants owner to read/write a file. - PrivateFileMode = 0600 - // PrivateDirMode grants owner to make/remove files inside the directory. - PrivateDirMode = 0700 -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "pkg/fileutil") -) - -// IsDirWriteable checks if dir is writable by writing and removing a file -// to dir. It returns nil if dir is writable. -func IsDirWriteable(dir string) error { - f := filepath.Join(dir, ".touch") - if err := ioutil.WriteFile(f, []byte(""), PrivateFileMode); err != nil { - return err - } - return os.Remove(f) -} - -// ReadDir returns the filenames in the given directory in sorted order. -func ReadDir(dirpath string) ([]string, error) { - dir, err := os.Open(dirpath) - if err != nil { - return nil, err - } - defer dir.Close() - names, err := dir.Readdirnames(-1) - if err != nil { - return nil, err - } - sort.Strings(names) - return names, nil -} - -// TouchDirAll is similar to os.MkdirAll. It creates directories with 0700 permission if any directory -// does not exists. TouchDirAll also ensures the given directory is writable. -func TouchDirAll(dir string) error { - // If path is already a directory, MkdirAll does nothing - // and returns nil. - err := os.MkdirAll(dir, PrivateDirMode) - if err != nil { - // if mkdirAll("a/text") and "text" is not - // a directory, this will return syscall.ENOTDIR - return err - } - return IsDirWriteable(dir) -} - -// CreateDirAll is similar to TouchDirAll but returns error -// if the deepest directory was not empty. -func CreateDirAll(dir string) error { - err := TouchDirAll(dir) - if err == nil { - var ns []string - ns, err = ReadDir(dir) - if err != nil { - return err - } - if len(ns) != 0 { - err = fmt.Errorf("expected %q to be empty, got %q", dir, ns) - } - } - return err -} - -func Exist(name string) bool { - _, err := os.Stat(name) - return err == nil -} - -// ZeroToEnd zeros a file starting from SEEK_CUR to its SEEK_END. May temporarily -// shorten the length of the file. -func ZeroToEnd(f *os.File) error { - // TODO: support FALLOC_FL_ZERO_RANGE - off, err := f.Seek(0, io.SeekCurrent) - if err != nil { - return err - } - lenf, lerr := f.Seek(0, io.SeekEnd) - if lerr != nil { - return lerr - } - if err = f.Truncate(off); err != nil { - return err - } - // make sure blocks remain allocated - if err = Preallocate(f, lenf, true); err != nil { - return err - } - _, err = f.Seek(off, io.SeekStart) - return err -} diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/lock.go b/vendor/github.com/coreos/etcd/pkg/fileutil/lock.go deleted file mode 100644 index 338627f43c88..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/lock.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fileutil - -import ( - "errors" - "os" -) - -var ( - ErrLocked = errors.New("fileutil: file already locked") -) - -type LockedFile struct{ *os.File } diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/lock_flock.go b/vendor/github.com/coreos/etcd/pkg/fileutil/lock_flock.go deleted file mode 100644 index 542550bc8a96..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/lock_flock.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !windows,!plan9,!solaris - -package fileutil - -import ( - "os" - "syscall" -) - -func flockTryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - f, err := os.OpenFile(path, flag, perm) - if err != nil { - return nil, err - } - if err = syscall.Flock(int(f.Fd()), syscall.LOCK_EX|syscall.LOCK_NB); err != nil { - f.Close() - if err == syscall.EWOULDBLOCK { - err = ErrLocked - } - return nil, err - } - return &LockedFile{f}, nil -} - -func flockLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - f, err := os.OpenFile(path, flag, perm) - if err != nil { - return nil, err - } - if err = syscall.Flock(int(f.Fd()), syscall.LOCK_EX); err != nil { - f.Close() - return nil, err - } - return &LockedFile{f}, err -} diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/lock_linux.go b/vendor/github.com/coreos/etcd/pkg/fileutil/lock_linux.go deleted file mode 100644 index 939fea623818..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/lock_linux.go +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build linux - -package fileutil - -import ( - "io" - "os" - "syscall" -) - -// This used to call syscall.Flock() but that call fails with EBADF on NFS. -// An alternative is lockf() which works on NFS but that call lets a process lock -// the same file twice. Instead, use Linux's non-standard open file descriptor -// locks which will block if the process already holds the file lock. -// -// constants from /usr/include/bits/fcntl-linux.h -const ( - F_OFD_GETLK = 37 - F_OFD_SETLK = 37 - F_OFD_SETLKW = 38 -) - -var ( - wrlck = syscall.Flock_t{ - Type: syscall.F_WRLCK, - Whence: int16(io.SeekStart), - Start: 0, - Len: 0, - } - - linuxTryLockFile = flockTryLockFile - linuxLockFile = flockLockFile -) - -func init() { - // use open file descriptor locks if the system supports it - getlk := syscall.Flock_t{Type: syscall.F_RDLCK} - if err := syscall.FcntlFlock(0, F_OFD_GETLK, &getlk); err == nil { - linuxTryLockFile = ofdTryLockFile - linuxLockFile = ofdLockFile - } -} - -func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - return linuxTryLockFile(path, flag, perm) -} - -func ofdTryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - f, err := os.OpenFile(path, flag, perm) - if err != nil { - return nil, err - } - - flock := wrlck - if err = syscall.FcntlFlock(f.Fd(), F_OFD_SETLK, &flock); err != nil { - f.Close() - if err == syscall.EWOULDBLOCK { - err = ErrLocked - } - return nil, err - } - return &LockedFile{f}, nil -} - -func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - return linuxLockFile(path, flag, perm) -} - -func ofdLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - f, err := os.OpenFile(path, flag, perm) - if err != nil { - return nil, err - } - - flock := wrlck - err = syscall.FcntlFlock(f.Fd(), F_OFD_SETLKW, &flock) - - if err != nil { - f.Close() - return nil, err - } - return &LockedFile{f}, err -} diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/lock_plan9.go b/vendor/github.com/coreos/etcd/pkg/fileutil/lock_plan9.go deleted file mode 100644 index fee6a7c8f466..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/lock_plan9.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fileutil - -import ( - "os" - "syscall" - "time" -) - -func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - if err := os.Chmod(path, syscall.DMEXCL|PrivateFileMode); err != nil { - return nil, err - } - f, err := os.Open(path, flag, perm) - if err != nil { - return nil, ErrLocked - } - return &LockedFile{f}, nil -} - -func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - if err := os.Chmod(path, syscall.DMEXCL|PrivateFileMode); err != nil { - return nil, err - } - for { - f, err := os.OpenFile(path, flag, perm) - if err == nil { - return &LockedFile{f}, nil - } - time.Sleep(10 * time.Millisecond) - } -} diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/lock_solaris.go b/vendor/github.com/coreos/etcd/pkg/fileutil/lock_solaris.go deleted file mode 100644 index 352ca5590d13..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/lock_solaris.go +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build solaris - -package fileutil - -import ( - "os" - "syscall" -) - -func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - var lock syscall.Flock_t - lock.Start = 0 - lock.Len = 0 - lock.Pid = 0 - lock.Type = syscall.F_WRLCK - lock.Whence = 0 - lock.Pid = 0 - f, err := os.OpenFile(path, flag, perm) - if err != nil { - return nil, err - } - if err := syscall.FcntlFlock(f.Fd(), syscall.F_SETLK, &lock); err != nil { - f.Close() - if err == syscall.EAGAIN { - err = ErrLocked - } - return nil, err - } - return &LockedFile{f}, nil -} - -func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - var lock syscall.Flock_t - lock.Start = 0 - lock.Len = 0 - lock.Pid = 0 - lock.Type = syscall.F_WRLCK - lock.Whence = 0 - f, err := os.OpenFile(path, flag, perm) - if err != nil { - return nil, err - } - if err = syscall.FcntlFlock(f.Fd(), syscall.F_SETLKW, &lock); err != nil { - f.Close() - return nil, err - } - return &LockedFile{f}, nil -} diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/lock_unix.go b/vendor/github.com/coreos/etcd/pkg/fileutil/lock_unix.go deleted file mode 100644 index ed01164de6e4..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/lock_unix.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !windows,!plan9,!solaris,!linux - -package fileutil - -import ( - "os" -) - -func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - return flockTryLockFile(path, flag, perm) -} - -func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - return flockLockFile(path, flag, perm) -} diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/lock_windows.go b/vendor/github.com/coreos/etcd/pkg/fileutil/lock_windows.go deleted file mode 100644 index b1817230a3cf..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/lock_windows.go +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build windows - -package fileutil - -import ( - "errors" - "fmt" - "os" - "syscall" - "unsafe" -) - -var ( - modkernel32 = syscall.NewLazyDLL("kernel32.dll") - procLockFileEx = modkernel32.NewProc("LockFileEx") - - errLocked = errors.New("The process cannot access the file because another process has locked a portion of the file.") -) - -const ( - // https://msdn.microsoft.com/en-us/library/windows/desktop/aa365203(v=vs.85).aspx - LOCKFILE_EXCLUSIVE_LOCK = 2 - LOCKFILE_FAIL_IMMEDIATELY = 1 - - // see https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx - errLockViolation syscall.Errno = 0x21 -) - -func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - f, err := open(path, flag, perm) - if err != nil { - return nil, err - } - if err := lockFile(syscall.Handle(f.Fd()), LOCKFILE_FAIL_IMMEDIATELY); err != nil { - f.Close() - return nil, err - } - return &LockedFile{f}, nil -} - -func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - f, err := open(path, flag, perm) - if err != nil { - return nil, err - } - if err := lockFile(syscall.Handle(f.Fd()), 0); err != nil { - f.Close() - return nil, err - } - return &LockedFile{f}, nil -} - -func open(path string, flag int, perm os.FileMode) (*os.File, error) { - if path == "" { - return nil, fmt.Errorf("cannot open empty filename") - } - var access uint32 - switch flag { - case syscall.O_RDONLY: - access = syscall.GENERIC_READ - case syscall.O_WRONLY: - access = syscall.GENERIC_WRITE - case syscall.O_RDWR: - access = syscall.GENERIC_READ | syscall.GENERIC_WRITE - case syscall.O_WRONLY | syscall.O_CREAT: - access = syscall.GENERIC_ALL - default: - panic(fmt.Errorf("flag %v is not supported", flag)) - } - fd, err := syscall.CreateFile(&(syscall.StringToUTF16(path)[0]), - access, - syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE, - nil, - syscall.OPEN_ALWAYS, - syscall.FILE_ATTRIBUTE_NORMAL, - 0) - if err != nil { - return nil, err - } - return os.NewFile(uintptr(fd), path), nil -} - -func lockFile(fd syscall.Handle, flags uint32) error { - var flag uint32 = LOCKFILE_EXCLUSIVE_LOCK - flag |= flags - if fd == syscall.InvalidHandle { - return nil - } - err := lockFileEx(fd, flag, 1, 0, &syscall.Overlapped{}) - if err == nil { - return nil - } else if err.Error() == errLocked.Error() { - return ErrLocked - } else if err != errLockViolation { - return err - } - return nil -} - -func lockFileEx(h syscall.Handle, flags, locklow, lockhigh uint32, ol *syscall.Overlapped) (err error) { - var reserved uint32 = 0 - r1, _, e1 := syscall.Syscall6(procLockFileEx.Addr(), 6, uintptr(h), uintptr(flags), uintptr(reserved), uintptr(locklow), uintptr(lockhigh), uintptr(unsafe.Pointer(ol))) - if r1 == 0 { - if e1 != 0 { - err = error(e1) - } else { - err = syscall.EINVAL - } - } - return err -} diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/preallocate.go b/vendor/github.com/coreos/etcd/pkg/fileutil/preallocate.go deleted file mode 100644 index c747b7cf81f9..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/preallocate.go +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fileutil - -import ( - "io" - "os" -) - -// Preallocate tries to allocate the space for given -// file. This operation is only supported on linux by a -// few filesystems (btrfs, ext4, etc.). -// If the operation is unsupported, no error will be returned. -// Otherwise, the error encountered will be returned. -func Preallocate(f *os.File, sizeInBytes int64, extendFile bool) error { - if sizeInBytes == 0 { - // fallocate will return EINVAL if length is 0; skip - return nil - } - if extendFile { - return preallocExtend(f, sizeInBytes) - } - return preallocFixed(f, sizeInBytes) -} - -func preallocExtendTrunc(f *os.File, sizeInBytes int64) error { - curOff, err := f.Seek(0, io.SeekCurrent) - if err != nil { - return err - } - size, err := f.Seek(sizeInBytes, io.SeekEnd) - if err != nil { - return err - } - if _, err = f.Seek(curOff, io.SeekStart); err != nil { - return err - } - if sizeInBytes > size { - return nil - } - return f.Truncate(sizeInBytes) -} diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/preallocate_darwin.go b/vendor/github.com/coreos/etcd/pkg/fileutil/preallocate_darwin.go deleted file mode 100644 index 5a6dccfa796f..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/preallocate_darwin.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build darwin - -package fileutil - -import ( - "os" - "syscall" - "unsafe" -) - -func preallocExtend(f *os.File, sizeInBytes int64) error { - if err := preallocFixed(f, sizeInBytes); err != nil { - return err - } - return preallocExtendTrunc(f, sizeInBytes) -} - -func preallocFixed(f *os.File, sizeInBytes int64) error { - // allocate all requested space or no space at all - // TODO: allocate contiguous space on disk with F_ALLOCATECONTIG flag - fstore := &syscall.Fstore_t{ - Flags: syscall.F_ALLOCATEALL, - Posmode: syscall.F_PEOFPOSMODE, - Length: sizeInBytes} - p := unsafe.Pointer(fstore) - _, _, errno := syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), uintptr(syscall.F_PREALLOCATE), uintptr(p)) - if errno == 0 || errno == syscall.ENOTSUP { - return nil - } - - // wrong argument to fallocate syscall - if errno == syscall.EINVAL { - // filesystem "st_blocks" are allocated in the units of - // "Allocation Block Size" (run "diskutil info /" command) - var stat syscall.Stat_t - syscall.Fstat(int(f.Fd()), &stat) - - // syscall.Statfs_t.Bsize is "optimal transfer block size" - // and contains matching 4096 value when latest OS X kernel - // supports 4,096 KB filesystem block size - var statfs syscall.Statfs_t - syscall.Fstatfs(int(f.Fd()), &statfs) - blockSize := int64(statfs.Bsize) - - if stat.Blocks*blockSize >= sizeInBytes { - // enough blocks are already allocated - return nil - } - } - return errno -} diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/preallocate_unix.go b/vendor/github.com/coreos/etcd/pkg/fileutil/preallocate_unix.go deleted file mode 100644 index 50bd84f02ada..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/preallocate_unix.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build linux - -package fileutil - -import ( - "os" - "syscall" -) - -func preallocExtend(f *os.File, sizeInBytes int64) error { - // use mode = 0 to change size - err := syscall.Fallocate(int(f.Fd()), 0, 0, sizeInBytes) - if err != nil { - errno, ok := err.(syscall.Errno) - // not supported; fallback - // fallocate EINTRs frequently in some environments; fallback - if ok && (errno == syscall.ENOTSUP || errno == syscall.EINTR) { - return preallocExtendTrunc(f, sizeInBytes) - } - } - return err -} - -func preallocFixed(f *os.File, sizeInBytes int64) error { - // use mode = 1 to keep size; see FALLOC_FL_KEEP_SIZE - err := syscall.Fallocate(int(f.Fd()), 1, 0, sizeInBytes) - if err != nil { - errno, ok := err.(syscall.Errno) - // treat not supported as nil error - if ok && errno == syscall.ENOTSUP { - return nil - } - } - return err -} diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/preallocate_unsupported.go b/vendor/github.com/coreos/etcd/pkg/fileutil/preallocate_unsupported.go deleted file mode 100644 index 162fbc5f7826..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/preallocate_unsupported.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !linux,!darwin - -package fileutil - -import "os" - -func preallocExtend(f *os.File, sizeInBytes int64) error { - return preallocExtendTrunc(f, sizeInBytes) -} - -func preallocFixed(f *os.File, sizeInBytes int64) error { return nil } diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/purge.go b/vendor/github.com/coreos/etcd/pkg/fileutil/purge.go deleted file mode 100644 index 92fceab017f3..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/purge.go +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fileutil - -import ( - "os" - "path/filepath" - "sort" - "strings" - "time" -) - -func PurgeFile(dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) <-chan error { - return purgeFile(dirname, suffix, max, interval, stop, nil) -} - -// purgeFile is the internal implementation for PurgeFile which can post purged files to purgec if non-nil. -func purgeFile(dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}, purgec chan<- string) <-chan error { - errC := make(chan error, 1) - go func() { - for { - fnames, err := ReadDir(dirname) - if err != nil { - errC <- err - return - } - newfnames := make([]string, 0) - for _, fname := range fnames { - if strings.HasSuffix(fname, suffix) { - newfnames = append(newfnames, fname) - } - } - sort.Strings(newfnames) - fnames = newfnames - for len(newfnames) > int(max) { - f := filepath.Join(dirname, newfnames[0]) - l, err := TryLockFile(f, os.O_WRONLY, PrivateFileMode) - if err != nil { - break - } - if err = os.Remove(f); err != nil { - errC <- err - return - } - if err = l.Close(); err != nil { - plog.Errorf("error unlocking %s when purging file (%v)", l.Name(), err) - errC <- err - return - } - plog.Infof("purged file %s successfully", f) - newfnames = newfnames[1:] - } - if purgec != nil { - for i := 0; i < len(fnames)-len(newfnames); i++ { - purgec <- fnames[i] - } - } - select { - case <-time.After(interval): - case <-stop: - return - } - } - }() - return errC -} diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/sync.go b/vendor/github.com/coreos/etcd/pkg/fileutil/sync.go deleted file mode 100644 index 54dd41f4f351..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/sync.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !linux,!darwin - -package fileutil - -import "os" - -// Fsync is a wrapper around file.Sync(). Special handling is needed on darwin platform. -func Fsync(f *os.File) error { - return f.Sync() -} - -// Fdatasync is a wrapper around file.Sync(). Special handling is needed on linux platform. -func Fdatasync(f *os.File) error { - return f.Sync() -} diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/sync_darwin.go b/vendor/github.com/coreos/etcd/pkg/fileutil/sync_darwin.go deleted file mode 100644 index c2f39bf204d2..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/sync_darwin.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build darwin - -package fileutil - -import ( - "os" - "syscall" -) - -// Fsync on HFS/OSX flushes the data on to the physical drive but the drive -// may not write it to the persistent media for quite sometime and it may be -// written in out-of-order sequence. Using F_FULLFSYNC ensures that the -// physical drive's buffer will also get flushed to the media. -func Fsync(f *os.File) error { - _, _, errno := syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), uintptr(syscall.F_FULLFSYNC), uintptr(0)) - if errno == 0 { - return nil - } - return errno -} - -// Fdatasync on darwin platform invokes fcntl(F_FULLFSYNC) for actual persistence -// on physical drive media. -func Fdatasync(f *os.File) error { - return Fsync(f) -} diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/sync_linux.go b/vendor/github.com/coreos/etcd/pkg/fileutil/sync_linux.go deleted file mode 100644 index 1bbced915e9b..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/sync_linux.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build linux - -package fileutil - -import ( - "os" - "syscall" -) - -// Fsync is a wrapper around file.Sync(). Special handling is needed on darwin platform. -func Fsync(f *os.File) error { - return f.Sync() -} - -// Fdatasync is similar to fsync(), but does not flush modified metadata -// unless that metadata is needed in order to allow a subsequent data retrieval -// to be correctly handled. -func Fdatasync(f *os.File) error { - return syscall.Fdatasync(int(f.Fd())) -} diff --git a/vendor/github.com/coreos/etcd/pkg/flags/flag.go b/vendor/github.com/coreos/etcd/pkg/flags/flag.go deleted file mode 100644 index 69c464118548..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/flags/flag.go +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package flags implements command-line flag parsing. -package flags - -import ( - "flag" - "fmt" - "net/url" - "os" - "strings" - - "github.com/coreos/pkg/capnslog" - "github.com/spf13/pflag" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "pkg/flags") -) - -// DeprecatedFlag encapsulates a flag that may have been previously valid but -// is now deprecated. If a DeprecatedFlag is set, an error occurs. -type DeprecatedFlag struct { - Name string -} - -func (f *DeprecatedFlag) Set(_ string) error { - return fmt.Errorf(`flag "-%s" is no longer supported.`, f.Name) -} - -func (f *DeprecatedFlag) String() string { - return "" -} - -// IgnoredFlag encapsulates a flag that may have been previously valid but is -// now ignored. If an IgnoredFlag is set, a warning is printed and -// operation continues. -type IgnoredFlag struct { - Name string -} - -// IsBoolFlag is defined to allow the flag to be defined without an argument -func (f *IgnoredFlag) IsBoolFlag() bool { - return true -} - -func (f *IgnoredFlag) Set(s string) error { - plog.Warningf(`flag "-%s" is no longer supported - ignoring.`, f.Name) - return nil -} - -func (f *IgnoredFlag) String() string { - return "" -} - -// SetFlagsFromEnv parses all registered flags in the given flagset, -// and if they are not already set it attempts to set their values from -// environment variables. Environment variables take the name of the flag but -// are UPPERCASE, have the given prefix and any dashes are replaced by -// underscores - for example: some-flag => ETCD_SOME_FLAG -func SetFlagsFromEnv(prefix string, fs *flag.FlagSet) error { - var err error - alreadySet := make(map[string]bool) - fs.Visit(func(f *flag.Flag) { - alreadySet[FlagToEnv(prefix, f.Name)] = true - }) - usedEnvKey := make(map[string]bool) - fs.VisitAll(func(f *flag.Flag) { - if serr := setFlagFromEnv(fs, prefix, f.Name, usedEnvKey, alreadySet, true); serr != nil { - err = serr - } - }) - verifyEnv(prefix, usedEnvKey, alreadySet) - return err -} - -// SetPflagsFromEnv is similar to SetFlagsFromEnv. However, the accepted flagset type is pflag.FlagSet -// and it does not do any logging. -func SetPflagsFromEnv(prefix string, fs *pflag.FlagSet) error { - var err error - alreadySet := make(map[string]bool) - usedEnvKey := make(map[string]bool) - fs.VisitAll(func(f *pflag.Flag) { - if f.Changed { - alreadySet[FlagToEnv(prefix, f.Name)] = true - } - if serr := setFlagFromEnv(fs, prefix, f.Name, usedEnvKey, alreadySet, false); serr != nil { - err = serr - } - }) - verifyEnv(prefix, usedEnvKey, alreadySet) - return err -} - -// FlagToEnv converts flag string to upper-case environment variable key string. -func FlagToEnv(prefix, name string) string { - return prefix + "_" + strings.ToUpper(strings.Replace(name, "-", "_", -1)) -} - -func verifyEnv(prefix string, usedEnvKey, alreadySet map[string]bool) { - for _, env := range os.Environ() { - kv := strings.SplitN(env, "=", 2) - if len(kv) != 2 { - plog.Warningf("found invalid env %s", env) - } - if usedEnvKey[kv[0]] { - continue - } - if alreadySet[kv[0]] { - // TODO: exit with error in v3.4 - plog.Warningf("recognized environment variable %s, but unused: shadowed by corresponding flag", kv[0]) - continue - } - if strings.HasPrefix(env, prefix+"_") { - plog.Warningf("unrecognized environment variable %s", env) - } - } -} - -type flagSetter interface { - Set(fk string, fv string) error -} - -func setFlagFromEnv(fs flagSetter, prefix, fname string, usedEnvKey, alreadySet map[string]bool, log bool) error { - key := FlagToEnv(prefix, fname) - if !alreadySet[key] { - val := os.Getenv(key) - if val != "" { - usedEnvKey[key] = true - if serr := fs.Set(fname, val); serr != nil { - return fmt.Errorf("invalid value %q for %s: %v", val, key, serr) - } - if log { - plog.Infof("recognized and used environment variable %s=%s", key, val) - } - } - } - return nil -} - -// URLsFromFlag returns a slices from url got from the flag. -func URLsFromFlag(fs *flag.FlagSet, urlsFlagName string) []url.URL { - return []url.URL(*fs.Lookup(urlsFlagName).Value.(*URLsValue)) -} - -func IsSet(fs *flag.FlagSet, name string) bool { - set := false - fs.Visit(func(f *flag.Flag) { - if f.Name == name { - set = true - } - }) - return set -} diff --git a/vendor/github.com/coreos/etcd/pkg/flags/strings.go b/vendor/github.com/coreos/etcd/pkg/flags/strings.go deleted file mode 100644 index 89bdf950661a..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/flags/strings.go +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package flags - -import ( - "errors" - "flag" - "sort" - "strings" -) - -// NewStringsFlag creates a new string flag for which any one of the given -// strings is a valid value, and any other value is an error. -// -// valids[0] will be default value. Caller must be sure len(valids)!=0 or -// it will panic. -func NewStringsFlag(valids ...string) *StringsFlag { - return &StringsFlag{Values: valids, val: valids[0]} -} - -// StringsFlag implements the flag.Value interface. -type StringsFlag struct { - Values []string - val string -} - -// Set verifies the argument to be a valid member of the allowed values -// before setting the underlying flag value. -func (ss *StringsFlag) Set(s string) error { - for _, v := range ss.Values { - if s == v { - ss.val = s - return nil - } - } - return errors.New("invalid value") -} - -// String returns the set value (if any) of the StringsFlag -func (ss *StringsFlag) String() string { - return ss.val -} - -// StringsValueV2 wraps "sort.StringSlice". -type StringsValueV2 sort.StringSlice - -// Set parses a command line set of strings, separated by comma. -// Implements "flag.Value" interface. -func (ss *StringsValueV2) Set(s string) error { - *ss = strings.Split(s, ",") - return nil -} - -// String implements "flag.Value" interface. -func (ss *StringsValueV2) String() string { return strings.Join(*ss, ",") } - -// NewStringsValueV2 implements string slice as "flag.Value" interface. -// Given value is to be separated by comma. -func NewStringsValueV2(s string) (ss *StringsValueV2) { - if s == "" { - return &StringsValueV2{} - } - ss = new(StringsValueV2) - if err := ss.Set(s); err != nil { - plog.Panicf("new StringsValueV2 should never fail: %v", err) - } - return ss -} - -// StringsFromFlagV2 returns a string slice from the flag. -func StringsFromFlagV2(fs *flag.FlagSet, flagName string) []string { - return []string(*fs.Lookup(flagName).Value.(*StringsValueV2)) -} diff --git a/vendor/github.com/coreos/etcd/pkg/flags/urls.go b/vendor/github.com/coreos/etcd/pkg/flags/urls.go deleted file mode 100644 index 6383d7e92574..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/flags/urls.go +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package flags - -import ( - "strings" - - "github.com/coreos/etcd/pkg/types" -) - -type URLsValue types.URLs - -// Set parses a command line set of URLs formatted like: -// http://127.0.0.1:2380,http://10.1.1.2:80 -func (us *URLsValue) Set(s string) error { - strs := strings.Split(s, ",") - nus, err := types.NewURLs(strs) - if err != nil { - return err - } - - *us = URLsValue(nus) - return nil -} - -func (us *URLsValue) String() string { - all := make([]string, len(*us)) - for i, u := range *us { - all[i] = u.String() - } - return strings.Join(all, ",") -} - -func NewURLsValue(init string) *URLsValue { - v := &URLsValue{} - if err := v.Set(init); err != nil { - plog.Panicf("new URLsValue should never fail: %v", err) - } - return v -} diff --git a/vendor/github.com/coreos/etcd/pkg/httputil/httputil.go b/vendor/github.com/coreos/etcd/pkg/httputil/httputil.go deleted file mode 100644 index 09f44e7c71d9..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/httputil/httputil.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// borrowed from golang/net/context/ctxhttp/cancelreq.go - -// Package httputil provides HTTP utility functions. -package httputil - -import ( - "io" - "io/ioutil" - "net/http" -) - -// GracefulClose drains http.Response.Body until it hits EOF -// and closes it. This prevents TCP/TLS connections from closing, -// therefore available for reuse. -func GracefulClose(resp *http.Response) { - io.Copy(ioutil.Discard, resp.Body) - resp.Body.Close() -} diff --git a/vendor/github.com/coreos/etcd/pkg/idutil/id.go b/vendor/github.com/coreos/etcd/pkg/idutil/id.go deleted file mode 100644 index 2da210626571..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/idutil/id.go +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package idutil implements utility functions for generating unique, -// randomized ids. -package idutil - -import ( - "math" - "sync" - "time" -) - -const ( - tsLen = 5 * 8 - cntLen = 8 - suffixLen = tsLen + cntLen -) - -// Generator generates unique identifiers based on counters, timestamps, and -// a node member ID. -// -// The initial id is in this format: -// High order 2 bytes are from memberID, next 5 bytes are from timestamp, -// and low order one byte is a counter. -// | prefix | suffix | -// | 2 bytes | 5 bytes | 1 byte | -// | memberID | timestamp | cnt | -// -// The timestamp 5 bytes is different when the machine is restart -// after 1 ms and before 35 years. -// -// It increases suffix to generate the next id. -// The count field may overflow to timestamp field, which is intentional. -// It helps to extend the event window to 2^56. This doesn't break that -// id generated after restart is unique because etcd throughput is << -// 256req/ms(250k reqs/second). -type Generator struct { - mu sync.Mutex - // high order 2 bytes - prefix uint64 - // low order 6 bytes - suffix uint64 -} - -func NewGenerator(memberID uint16, now time.Time) *Generator { - prefix := uint64(memberID) << suffixLen - unixMilli := uint64(now.UnixNano()) / uint64(time.Millisecond/time.Nanosecond) - suffix := lowbit(unixMilli, tsLen) << cntLen - return &Generator{ - prefix: prefix, - suffix: suffix, - } -} - -// Next generates a id that is unique. -func (g *Generator) Next() uint64 { - g.mu.Lock() - defer g.mu.Unlock() - g.suffix++ - id := g.prefix | lowbit(g.suffix, suffixLen) - return id -} - -func lowbit(x uint64, n uint) uint64 { - return x & (math.MaxUint64 >> (64 - n)) -} diff --git a/vendor/github.com/coreos/etcd/pkg/ioutil/pagewriter.go b/vendor/github.com/coreos/etcd/pkg/ioutil/pagewriter.go deleted file mode 100644 index 72de1593d3ad..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/ioutil/pagewriter.go +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ioutil - -import ( - "io" -) - -var defaultBufferBytes = 128 * 1024 - -// PageWriter implements the io.Writer interface so that writes will -// either be in page chunks or from flushing. -type PageWriter struct { - w io.Writer - // pageOffset tracks the page offset of the base of the buffer - pageOffset int - // pageBytes is the number of bytes per page - pageBytes int - // bufferedBytes counts the number of bytes pending for write in the buffer - bufferedBytes int - // buf holds the write buffer - buf []byte - // bufWatermarkBytes is the number of bytes the buffer can hold before it needs - // to be flushed. It is less than len(buf) so there is space for slack writes - // to bring the writer to page alignment. - bufWatermarkBytes int -} - -// NewPageWriter creates a new PageWriter. pageBytes is the number of bytes -// to write per page. pageOffset is the starting offset of io.Writer. -func NewPageWriter(w io.Writer, pageBytes, pageOffset int) *PageWriter { - return &PageWriter{ - w: w, - pageOffset: pageOffset, - pageBytes: pageBytes, - buf: make([]byte, defaultBufferBytes+pageBytes), - bufWatermarkBytes: defaultBufferBytes, - } -} - -func (pw *PageWriter) Write(p []byte) (n int, err error) { - if len(p)+pw.bufferedBytes <= pw.bufWatermarkBytes { - // no overflow - copy(pw.buf[pw.bufferedBytes:], p) - pw.bufferedBytes += len(p) - return len(p), nil - } - // complete the slack page in the buffer if unaligned - slack := pw.pageBytes - ((pw.pageOffset + pw.bufferedBytes) % pw.pageBytes) - if slack != pw.pageBytes { - partial := slack > len(p) - if partial { - // not enough data to complete the slack page - slack = len(p) - } - // special case: writing to slack page in buffer - copy(pw.buf[pw.bufferedBytes:], p[:slack]) - pw.bufferedBytes += slack - n = slack - p = p[slack:] - if partial { - // avoid forcing an unaligned flush - return n, nil - } - } - // buffer contents are now page-aligned; clear out - if err = pw.Flush(); err != nil { - return n, err - } - // directly write all complete pages without copying - if len(p) > pw.pageBytes { - pages := len(p) / pw.pageBytes - c, werr := pw.w.Write(p[:pages*pw.pageBytes]) - n += c - if werr != nil { - return n, werr - } - p = p[pages*pw.pageBytes:] - } - // write remaining tail to buffer - c, werr := pw.Write(p) - n += c - return n, werr -} - -func (pw *PageWriter) Flush() error { - if pw.bufferedBytes == 0 { - return nil - } - _, err := pw.w.Write(pw.buf[:pw.bufferedBytes]) - pw.pageOffset = (pw.pageOffset + pw.bufferedBytes) % pw.pageBytes - pw.bufferedBytes = 0 - return err -} diff --git a/vendor/github.com/coreos/etcd/pkg/ioutil/readcloser.go b/vendor/github.com/coreos/etcd/pkg/ioutil/readcloser.go deleted file mode 100644 index d3efcfe3d5a6..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/ioutil/readcloser.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ioutil - -import ( - "fmt" - "io" -) - -// ReaderAndCloser implements io.ReadCloser interface by combining -// reader and closer together. -type ReaderAndCloser struct { - io.Reader - io.Closer -} - -var ( - ErrShortRead = fmt.Errorf("ioutil: short read") - ErrExpectEOF = fmt.Errorf("ioutil: expect EOF") -) - -// NewExactReadCloser returns a ReadCloser that returns errors if the underlying -// reader does not read back exactly the requested number of bytes. -func NewExactReadCloser(rc io.ReadCloser, totalBytes int64) io.ReadCloser { - return &exactReadCloser{rc: rc, totalBytes: totalBytes} -} - -type exactReadCloser struct { - rc io.ReadCloser - br int64 - totalBytes int64 -} - -func (e *exactReadCloser) Read(p []byte) (int, error) { - n, err := e.rc.Read(p) - e.br += int64(n) - if e.br > e.totalBytes { - return 0, ErrExpectEOF - } - if e.br < e.totalBytes && n == 0 { - return 0, ErrShortRead - } - return n, err -} - -func (e *exactReadCloser) Close() error { - if err := e.rc.Close(); err != nil { - return err - } - if e.br < e.totalBytes { - return ErrShortRead - } - return nil -} diff --git a/vendor/github.com/coreos/etcd/pkg/ioutil/reader.go b/vendor/github.com/coreos/etcd/pkg/ioutil/reader.go deleted file mode 100644 index 0703ed476d80..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/ioutil/reader.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package ioutil implements I/O utility functions. -package ioutil - -import "io" - -// NewLimitedBufferReader returns a reader that reads from the given reader -// but limits the amount of data returned to at most n bytes. -func NewLimitedBufferReader(r io.Reader, n int) io.Reader { - return &limitedBufferReader{ - r: r, - n: n, - } -} - -type limitedBufferReader struct { - r io.Reader - n int -} - -func (r *limitedBufferReader) Read(p []byte) (n int, err error) { - np := p - if len(np) > r.n { - np = np[:r.n] - } - return r.r.Read(np) -} diff --git a/vendor/github.com/coreos/etcd/pkg/ioutil/util.go b/vendor/github.com/coreos/etcd/pkg/ioutil/util.go deleted file mode 100644 index 192ad888c241..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/ioutil/util.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ioutil - -import ( - "io" - "os" - - "github.com/coreos/etcd/pkg/fileutil" -) - -// WriteAndSyncFile behaves just like ioutil.WriteFile in the standard library, -// but calls Sync before closing the file. WriteAndSyncFile guarantees the data -// is synced if there is no error returned. -func WriteAndSyncFile(filename string, data []byte, perm os.FileMode) error { - f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm) - if err != nil { - return err - } - n, err := f.Write(data) - if err == nil && n < len(data) { - err = io.ErrShortWrite - } - if err == nil { - err = fileutil.Fsync(f) - } - if err1 := f.Close(); err == nil { - err = err1 - } - return err -} diff --git a/vendor/github.com/coreos/etcd/pkg/logutil/merge_logger.go b/vendor/github.com/coreos/etcd/pkg/logutil/merge_logger.go deleted file mode 100644 index cc750f4d3d63..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/logutil/merge_logger.go +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package logutil includes utilities to facilitate logging. -package logutil - -import ( - "fmt" - "sync" - "time" - - "github.com/coreos/pkg/capnslog" -) - -var ( - defaultMergePeriod = time.Second - defaultTimeOutputScale = 10 * time.Millisecond - - outputInterval = time.Second -) - -// line represents a log line that can be printed out -// through capnslog.PackageLogger. -type line struct { - level capnslog.LogLevel - str string -} - -func (l line) append(s string) line { - return line{ - level: l.level, - str: l.str + " " + s, - } -} - -// status represents the merge status of a line. -type status struct { - period time.Duration - - start time.Time // start time of latest merge period - count int // number of merged lines from starting -} - -func (s *status) isInMergePeriod(now time.Time) bool { - return s.period == 0 || s.start.Add(s.period).After(now) -} - -func (s *status) isEmpty() bool { return s.count == 0 } - -func (s *status) summary(now time.Time) string { - ts := s.start.Round(defaultTimeOutputScale) - took := now.Round(defaultTimeOutputScale).Sub(ts) - return fmt.Sprintf("[merged %d repeated lines in %s]", s.count, took) -} - -func (s *status) reset(now time.Time) { - s.start = now - s.count = 0 -} - -// MergeLogger supports merge logging, which merges repeated log lines -// and prints summary log lines instead. -// -// For merge logging, MergeLogger prints out the line when the line appears -// at the first time. MergeLogger holds the same log line printed within -// defaultMergePeriod, and prints out summary log line at the end of defaultMergePeriod. -// It stops merging when the line doesn't appear within the -// defaultMergePeriod. -type MergeLogger struct { - *capnslog.PackageLogger - - mu sync.Mutex // protect statusm - statusm map[line]*status -} - -func NewMergeLogger(logger *capnslog.PackageLogger) *MergeLogger { - l := &MergeLogger{ - PackageLogger: logger, - statusm: make(map[line]*status), - } - go l.outputLoop() - return l -} - -func (l *MergeLogger) MergeInfo(entries ...interface{}) { - l.merge(line{ - level: capnslog.INFO, - str: fmt.Sprint(entries...), - }) -} - -func (l *MergeLogger) MergeInfof(format string, args ...interface{}) { - l.merge(line{ - level: capnslog.INFO, - str: fmt.Sprintf(format, args...), - }) -} - -func (l *MergeLogger) MergeNotice(entries ...interface{}) { - l.merge(line{ - level: capnslog.NOTICE, - str: fmt.Sprint(entries...), - }) -} - -func (l *MergeLogger) MergeNoticef(format string, args ...interface{}) { - l.merge(line{ - level: capnslog.NOTICE, - str: fmt.Sprintf(format, args...), - }) -} - -func (l *MergeLogger) MergeWarning(entries ...interface{}) { - l.merge(line{ - level: capnslog.WARNING, - str: fmt.Sprint(entries...), - }) -} - -func (l *MergeLogger) MergeWarningf(format string, args ...interface{}) { - l.merge(line{ - level: capnslog.WARNING, - str: fmt.Sprintf(format, args...), - }) -} - -func (l *MergeLogger) MergeError(entries ...interface{}) { - l.merge(line{ - level: capnslog.ERROR, - str: fmt.Sprint(entries...), - }) -} - -func (l *MergeLogger) MergeErrorf(format string, args ...interface{}) { - l.merge(line{ - level: capnslog.ERROR, - str: fmt.Sprintf(format, args...), - }) -} - -func (l *MergeLogger) merge(ln line) { - l.mu.Lock() - - // increase count if the logger is merging the line - if status, ok := l.statusm[ln]; ok { - status.count++ - l.mu.Unlock() - return - } - - // initialize status of the line - l.statusm[ln] = &status{ - period: defaultMergePeriod, - start: time.Now(), - } - // release the lock before IO operation - l.mu.Unlock() - // print out the line at its first time - l.PackageLogger.Logf(ln.level, ln.str) -} - -func (l *MergeLogger) outputLoop() { - for now := range time.Tick(outputInterval) { - var outputs []line - - l.mu.Lock() - for ln, status := range l.statusm { - if status.isInMergePeriod(now) { - continue - } - if status.isEmpty() { - delete(l.statusm, ln) - continue - } - outputs = append(outputs, ln.append(status.summary(now))) - status.reset(now) - } - l.mu.Unlock() - - for _, o := range outputs { - l.PackageLogger.Logf(o.level, o.str) - } - } -} diff --git a/vendor/github.com/coreos/etcd/pkg/netutil/isolate_linux.go b/vendor/github.com/coreos/etcd/pkg/netutil/isolate_linux.go deleted file mode 100644 index 418580ac48de..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/netutil/isolate_linux.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package netutil - -import ( - "fmt" - "os/exec" -) - -// DropPort drops all tcp packets that are received from the given port and sent to the given port. -func DropPort(port int) error { - cmdStr := fmt.Sprintf("sudo iptables -A OUTPUT -p tcp --destination-port %d -j DROP", port) - if _, err := exec.Command("/bin/sh", "-c", cmdStr).Output(); err != nil { - return err - } - cmdStr = fmt.Sprintf("sudo iptables -A INPUT -p tcp --destination-port %d -j DROP", port) - _, err := exec.Command("/bin/sh", "-c", cmdStr).Output() - return err -} - -// RecoverPort stops dropping tcp packets at given port. -func RecoverPort(port int) error { - cmdStr := fmt.Sprintf("sudo iptables -D OUTPUT -p tcp --destination-port %d -j DROP", port) - if _, err := exec.Command("/bin/sh", "-c", cmdStr).Output(); err != nil { - return err - } - cmdStr = fmt.Sprintf("sudo iptables -D INPUT -p tcp --destination-port %d -j DROP", port) - _, err := exec.Command("/bin/sh", "-c", cmdStr).Output() - return err -} - -// SetLatency adds latency in millisecond scale with random variations. -func SetLatency(ms, rv int) error { - ifces, err := GetDefaultInterfaces() - if err != nil { - return err - } - - if rv > ms { - rv = 1 - } - for ifce := range ifces { - cmdStr := fmt.Sprintf("sudo tc qdisc add dev %s root netem delay %dms %dms distribution normal", ifce, ms, rv) - _, err = exec.Command("/bin/sh", "-c", cmdStr).Output() - if err != nil { - // the rule has already been added. Overwrite it. - cmdStr = fmt.Sprintf("sudo tc qdisc change dev %s root netem delay %dms %dms distribution normal", ifce, ms, rv) - _, err = exec.Command("/bin/sh", "-c", cmdStr).Output() - if err != nil { - return err - } - } - } - return nil -} - -// RemoveLatency resets latency configurations. -func RemoveLatency() error { - ifces, err := GetDefaultInterfaces() - if err != nil { - return err - } - for ifce := range ifces { - _, err = exec.Command("/bin/sh", "-c", fmt.Sprintf("sudo tc qdisc del dev %s root netem", ifce)).Output() - if err != nil { - return err - } - } - return nil -} diff --git a/vendor/github.com/coreos/etcd/pkg/netutil/isolate_stub.go b/vendor/github.com/coreos/etcd/pkg/netutil/isolate_stub.go deleted file mode 100644 index 7f4c3e67c2ad..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/netutil/isolate_stub.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !linux - -package netutil - -func DropPort(port int) error { return nil } - -func RecoverPort(port int) error { return nil } - -func SetLatency(ms, rv int) error { return nil } - -func RemoveLatency() error { return nil } diff --git a/vendor/github.com/coreos/etcd/pkg/netutil/netutil.go b/vendor/github.com/coreos/etcd/pkg/netutil/netutil.go deleted file mode 100644 index e3db8c50a0df..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/netutil/netutil.go +++ /dev/null @@ -1,187 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package netutil implements network-related utility functions. -package netutil - -import ( - "context" - "fmt" - "net" - "net/url" - "reflect" - "sort" - "time" - - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/pkg/capnslog" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "pkg/netutil") - - // indirection for testing - resolveTCPAddr = resolveTCPAddrDefault -) - -const retryInterval = time.Second - -// taken from go's ResolveTCP code but uses configurable ctx -func resolveTCPAddrDefault(ctx context.Context, addr string) (*net.TCPAddr, error) { - host, port, serr := net.SplitHostPort(addr) - if serr != nil { - return nil, serr - } - portnum, perr := net.DefaultResolver.LookupPort(ctx, "tcp", port) - if perr != nil { - return nil, perr - } - - var ips []net.IPAddr - if ip := net.ParseIP(host); ip != nil { - ips = []net.IPAddr{{IP: ip}} - } else { - // Try as a DNS name. - ipss, err := net.DefaultResolver.LookupIPAddr(ctx, host) - if err != nil { - return nil, err - } - ips = ipss - } - // randomize? - ip := ips[0] - return &net.TCPAddr{IP: ip.IP, Port: portnum, Zone: ip.Zone}, nil -} - -// resolveTCPAddrs is a convenience wrapper for net.ResolveTCPAddr. -// resolveTCPAddrs return a new set of url.URLs, in which all DNS hostnames -// are resolved. -func resolveTCPAddrs(ctx context.Context, urls [][]url.URL) ([][]url.URL, error) { - newurls := make([][]url.URL, 0) - for _, us := range urls { - nus := make([]url.URL, len(us)) - for i, u := range us { - nu, err := url.Parse(u.String()) - if err != nil { - return nil, fmt.Errorf("failed to parse %q (%v)", u.String(), err) - } - nus[i] = *nu - } - for i, u := range nus { - h, err := resolveURL(ctx, u) - if err != nil { - return nil, fmt.Errorf("failed to resolve %q (%v)", u.String(), err) - } - if h != "" { - nus[i].Host = h - } - } - newurls = append(newurls, nus) - } - return newurls, nil -} - -func resolveURL(ctx context.Context, u url.URL) (string, error) { - if u.Scheme == "unix" || u.Scheme == "unixs" { - // unix sockets don't resolve over TCP - return "", nil - } - host, _, err := net.SplitHostPort(u.Host) - if err != nil { - plog.Errorf("could not parse url %s during tcp resolving", u.Host) - return "", err - } - if host == "localhost" || net.ParseIP(host) != nil { - return "", nil - } - for ctx.Err() == nil { - tcpAddr, err := resolveTCPAddr(ctx, u.Host) - if err == nil { - plog.Infof("resolving %s to %s", u.Host, tcpAddr.String()) - return tcpAddr.String(), nil - } - plog.Warningf("failed resolving host %s (%v); retrying in %v", u.Host, err, retryInterval) - select { - case <-ctx.Done(): - plog.Errorf("could not resolve host %s", u.Host) - return "", err - case <-time.After(retryInterval): - } - } - return "", ctx.Err() -} - -// urlsEqual checks equality of url.URLS between two arrays. -// This check pass even if an URL is in hostname and opposite is in IP address. -func urlsEqual(ctx context.Context, a []url.URL, b []url.URL) (bool, error) { - if len(a) != len(b) { - return false, fmt.Errorf("len(%q) != len(%q)", urlsToStrings(a), urlsToStrings(b)) - } - urls, err := resolveTCPAddrs(ctx, [][]url.URL{a, b}) - if err != nil { - return false, err - } - preva, prevb := a, b - a, b = urls[0], urls[1] - sort.Sort(types.URLs(a)) - sort.Sort(types.URLs(b)) - for i := range a { - if !reflect.DeepEqual(a[i], b[i]) { - return false, fmt.Errorf("%q(resolved from %q) != %q(resolved from %q)", - a[i].String(), preva[i].String(), - b[i].String(), prevb[i].String(), - ) - } - } - return true, nil -} - -// URLStringsEqual returns "true" if given URLs are valid -// and resolved to same IP addresses. Otherwise, return "false" -// and error, if any. -func URLStringsEqual(ctx context.Context, a []string, b []string) (bool, error) { - if len(a) != len(b) { - return false, fmt.Errorf("len(%q) != len(%q)", a, b) - } - urlsA := make([]url.URL, 0) - for _, str := range a { - u, err := url.Parse(str) - if err != nil { - return false, fmt.Errorf("failed to parse %q", str) - } - urlsA = append(urlsA, *u) - } - urlsB := make([]url.URL, 0) - for _, str := range b { - u, err := url.Parse(str) - if err != nil { - return false, fmt.Errorf("failed to parse %q", str) - } - urlsB = append(urlsB, *u) - } - return urlsEqual(ctx, urlsA, urlsB) -} - -func urlsToStrings(us []url.URL) []string { - rs := make([]string, len(us)) - for i := range us { - rs[i] = us[i].String() - } - return rs -} - -func IsNetworkTimeoutError(err error) bool { - nerr, ok := err.(net.Error) - return ok && nerr.Timeout() -} diff --git a/vendor/github.com/coreos/etcd/pkg/netutil/routes.go b/vendor/github.com/coreos/etcd/pkg/netutil/routes.go deleted file mode 100644 index 3eb6a19ec844..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/netutil/routes.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !linux - -package netutil - -import ( - "fmt" - "runtime" -) - -// GetDefaultHost fetches the a resolvable name that corresponds -// to the machine's default routable interface -func GetDefaultHost() (string, error) { - return "", fmt.Errorf("default host not supported on %s_%s", runtime.GOOS, runtime.GOARCH) -} - -// GetDefaultInterfaces fetches the device name of default routable interface. -func GetDefaultInterfaces() (map[string]uint8, error) { - return nil, fmt.Errorf("default host not supported on %s_%s", runtime.GOOS, runtime.GOARCH) -} diff --git a/vendor/github.com/coreos/etcd/pkg/netutil/routes_linux.go b/vendor/github.com/coreos/etcd/pkg/netutil/routes_linux.go deleted file mode 100644 index 797baeb482ae..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/netutil/routes_linux.go +++ /dev/null @@ -1,250 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build linux - -package netutil - -import ( - "bytes" - "encoding/binary" - "fmt" - "net" - "sort" - "syscall" - - "github.com/coreos/etcd/pkg/cpuutil" -) - -var errNoDefaultRoute = fmt.Errorf("could not find default route") -var errNoDefaultHost = fmt.Errorf("could not find default host") -var errNoDefaultInterface = fmt.Errorf("could not find default interface") - -// GetDefaultHost obtains the first IP address of machine from the routing table and returns the IP address as string. -// An IPv4 address is preferred to an IPv6 address for backward compatibility. -func GetDefaultHost() (string, error) { - rmsgs, rerr := getDefaultRoutes() - if rerr != nil { - return "", rerr - } - - // prioritize IPv4 - if rmsg, ok := rmsgs[syscall.AF_INET]; ok { - if host, err := chooseHost(syscall.AF_INET, rmsg); host != "" || err != nil { - return host, err - } - delete(rmsgs, syscall.AF_INET) - } - - // sort so choice is deterministic - var families []int - for family := range rmsgs { - families = append(families, int(family)) - } - sort.Ints(families) - - for _, f := range families { - family := uint8(f) - if host, err := chooseHost(family, rmsgs[family]); host != "" || err != nil { - return host, err - } - } - - return "", errNoDefaultHost -} - -func chooseHost(family uint8, rmsg *syscall.NetlinkMessage) (string, error) { - host, oif, err := parsePREFSRC(rmsg) - if host != "" || err != nil { - return host, err - } - - // prefsrc not detected, fall back to getting address from iface - ifmsg, ierr := getIfaceAddr(oif, family) - if ierr != nil { - return "", ierr - } - - attrs, aerr := syscall.ParseNetlinkRouteAttr(ifmsg) - if aerr != nil { - return "", aerr - } - - for _, attr := range attrs { - // search for RTA_DST because ipv6 doesn't have RTA_SRC - if attr.Attr.Type == syscall.RTA_DST { - return net.IP(attr.Value).String(), nil - } - } - - return "", nil -} - -func getDefaultRoutes() (map[uint8]*syscall.NetlinkMessage, error) { - dat, err := syscall.NetlinkRIB(syscall.RTM_GETROUTE, syscall.AF_UNSPEC) - if err != nil { - return nil, err - } - - msgs, msgErr := syscall.ParseNetlinkMessage(dat) - if msgErr != nil { - return nil, msgErr - } - - routes := make(map[uint8]*syscall.NetlinkMessage) - rtmsg := syscall.RtMsg{} - for _, m := range msgs { - if m.Header.Type != syscall.RTM_NEWROUTE { - continue - } - buf := bytes.NewBuffer(m.Data[:syscall.SizeofRtMsg]) - if rerr := binary.Read(buf, cpuutil.ByteOrder(), &rtmsg); rerr != nil { - continue - } - if rtmsg.Dst_len == 0 && rtmsg.Table == syscall.RT_TABLE_MAIN { - // zero-length Dst_len implies default route - msg := m - routes[rtmsg.Family] = &msg - } - } - - if len(routes) > 0 { - return routes, nil - } - - return nil, errNoDefaultRoute -} - -// Used to get an address of interface. -func getIfaceAddr(idx uint32, family uint8) (*syscall.NetlinkMessage, error) { - dat, err := syscall.NetlinkRIB(syscall.RTM_GETADDR, int(family)) - if err != nil { - return nil, err - } - - msgs, msgErr := syscall.ParseNetlinkMessage(dat) - if msgErr != nil { - return nil, msgErr - } - - ifaddrmsg := syscall.IfAddrmsg{} - for _, m := range msgs { - if m.Header.Type != syscall.RTM_NEWADDR { - continue - } - buf := bytes.NewBuffer(m.Data[:syscall.SizeofIfAddrmsg]) - if rerr := binary.Read(buf, cpuutil.ByteOrder(), &ifaddrmsg); rerr != nil { - continue - } - if ifaddrmsg.Index == idx { - return &m, nil - } - } - - return nil, fmt.Errorf("could not find address for interface index %v", idx) - -} - -// Used to get a name of interface. -func getIfaceLink(idx uint32) (*syscall.NetlinkMessage, error) { - dat, err := syscall.NetlinkRIB(syscall.RTM_GETLINK, syscall.AF_UNSPEC) - if err != nil { - return nil, err - } - - msgs, msgErr := syscall.ParseNetlinkMessage(dat) - if msgErr != nil { - return nil, msgErr - } - - ifinfomsg := syscall.IfInfomsg{} - for _, m := range msgs { - if m.Header.Type != syscall.RTM_NEWLINK { - continue - } - buf := bytes.NewBuffer(m.Data[:syscall.SizeofIfInfomsg]) - if rerr := binary.Read(buf, cpuutil.ByteOrder(), &ifinfomsg); rerr != nil { - continue - } - if ifinfomsg.Index == int32(idx) { - return &m, nil - } - } - - return nil, fmt.Errorf("could not find link for interface index %v", idx) -} - -// GetDefaultInterfaces gets names of interfaces and returns a map[interface]families. -func GetDefaultInterfaces() (map[string]uint8, error) { - interfaces := make(map[string]uint8) - rmsgs, rerr := getDefaultRoutes() - if rerr != nil { - return interfaces, rerr - } - - for family, rmsg := range rmsgs { - _, oif, err := parsePREFSRC(rmsg) - if err != nil { - return interfaces, err - } - - ifmsg, ierr := getIfaceLink(oif) - if ierr != nil { - return interfaces, ierr - } - - attrs, aerr := syscall.ParseNetlinkRouteAttr(ifmsg) - if aerr != nil { - return interfaces, aerr - } - - for _, attr := range attrs { - if attr.Attr.Type == syscall.IFLA_IFNAME { - // key is an interface name - // possible values: 2 - AF_INET, 10 - AF_INET6, 12 - dualstack - interfaces[string(attr.Value[:len(attr.Value)-1])] += family - } - } - } - if len(interfaces) > 0 { - return interfaces, nil - } - return interfaces, errNoDefaultInterface -} - -// parsePREFSRC returns preferred source address and output interface index (RTA_OIF). -func parsePREFSRC(m *syscall.NetlinkMessage) (host string, oif uint32, err error) { - var attrs []syscall.NetlinkRouteAttr - attrs, err = syscall.ParseNetlinkRouteAttr(m) - if err != nil { - return "", 0, err - } - - for _, attr := range attrs { - if attr.Attr.Type == syscall.RTA_PREFSRC { - host = net.IP(attr.Value).String() - } - if attr.Attr.Type == syscall.RTA_OIF { - oif = cpuutil.ByteOrder().Uint32(attr.Value) - } - if host != "" && oif != uint32(0) { - break - } - } - - if oif == 0 { - err = errNoDefaultRoute - } - return host, oif, err -} diff --git a/vendor/github.com/coreos/etcd/pkg/osutil/interrupt_unix.go b/vendor/github.com/coreos/etcd/pkg/osutil/interrupt_unix.go deleted file mode 100644 index b9feaffc952e..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/osutil/interrupt_unix.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !windows,!plan9 - -package osutil - -import ( - "os" - "os/signal" - "sync" - "syscall" -) - -// InterruptHandler is a function that is called on receiving a -// SIGTERM or SIGINT signal. -type InterruptHandler func() - -var ( - interruptRegisterMu, interruptExitMu sync.Mutex - // interruptHandlers holds all registered InterruptHandlers in order - // they will be executed. - interruptHandlers = []InterruptHandler{} -) - -// RegisterInterruptHandler registers a new InterruptHandler. Handlers registered -// after interrupt handing was initiated will not be executed. -func RegisterInterruptHandler(h InterruptHandler) { - interruptRegisterMu.Lock() - defer interruptRegisterMu.Unlock() - interruptHandlers = append(interruptHandlers, h) -} - -// HandleInterrupts calls the handler functions on receiving a SIGINT or SIGTERM. -func HandleInterrupts() { - notifier := make(chan os.Signal, 1) - signal.Notify(notifier, syscall.SIGINT, syscall.SIGTERM) - - go func() { - sig := <-notifier - - interruptRegisterMu.Lock() - ihs := make([]InterruptHandler, len(interruptHandlers)) - copy(ihs, interruptHandlers) - interruptRegisterMu.Unlock() - - interruptExitMu.Lock() - - plog.Noticef("received %v signal, shutting down...", sig) - - for _, h := range ihs { - h() - } - signal.Stop(notifier) - pid := syscall.Getpid() - // exit directly if it is the "init" process, since the kernel will not help to kill pid 1. - if pid == 1 { - os.Exit(0) - } - setDflSignal(sig.(syscall.Signal)) - syscall.Kill(pid, sig.(syscall.Signal)) - }() -} - -// Exit relays to os.Exit if no interrupt handlers are running, blocks otherwise. -func Exit(code int) { - interruptExitMu.Lock() - os.Exit(code) -} diff --git a/vendor/github.com/coreos/etcd/pkg/osutil/interrupt_windows.go b/vendor/github.com/coreos/etcd/pkg/osutil/interrupt_windows.go deleted file mode 100644 index 013ae88e1a7f..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/osutil/interrupt_windows.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build windows - -package osutil - -import "os" - -type InterruptHandler func() - -// RegisterInterruptHandler is a no-op on windows -func RegisterInterruptHandler(h InterruptHandler) {} - -// HandleInterrupts is a no-op on windows -func HandleInterrupts() {} - -// Exit calls os.Exit -func Exit(code int) { - os.Exit(code) -} diff --git a/vendor/github.com/coreos/etcd/pkg/osutil/osutil.go b/vendor/github.com/coreos/etcd/pkg/osutil/osutil.go deleted file mode 100644 index ef38280e7139..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/osutil/osutil.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package osutil implements operating system-related utility functions. -package osutil - -import ( - "os" - "strings" - - "github.com/coreos/pkg/capnslog" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "pkg/osutil") - - // support to override setting SIG_DFL so tests don't terminate early - setDflSignal = dflSignal -) - -func Unsetenv(key string) error { - envs := os.Environ() - os.Clearenv() - for _, e := range envs { - strs := strings.SplitN(e, "=", 2) - if strs[0] == key { - continue - } - if err := os.Setenv(strs[0], strs[1]); err != nil { - return err - } - } - return nil -} diff --git a/vendor/github.com/coreos/etcd/pkg/osutil/signal.go b/vendor/github.com/coreos/etcd/pkg/osutil/signal.go deleted file mode 100644 index 687397fdd5b8..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/osutil/signal.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !linux cov - -package osutil - -import "syscall" - -func dflSignal(sig syscall.Signal) { /* nop */ } diff --git a/vendor/github.com/coreos/etcd/pkg/osutil/signal_linux.go b/vendor/github.com/coreos/etcd/pkg/osutil/signal_linux.go deleted file mode 100644 index b94d80c58bd4..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/osutil/signal_linux.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build linux,!cov - -package osutil - -import ( - "syscall" - "unsafe" -) - -// dflSignal sets the given signal to SIG_DFL -func dflSignal(sig syscall.Signal) { - // clearing out the sigact sets the signal to SIG_DFL - var sigactBuf [32]uint64 - ptr := unsafe.Pointer(&sigactBuf) - syscall.Syscall6(uintptr(syscall.SYS_RT_SIGACTION), uintptr(sig), uintptr(ptr), 0, 8, 0, 0) -} diff --git a/vendor/github.com/coreos/etcd/pkg/pathutil/path.go b/vendor/github.com/coreos/etcd/pkg/pathutil/path.go deleted file mode 100644 index f26254ba933e..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/pathutil/path.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package pathutil implements utility functions for handling slash-separated -// paths. -package pathutil - -import "path" - -// CanonicalURLPath returns the canonical url path for p, which follows the rules: -// 1. the path always starts with "/" -// 2. replace multiple slashes with a single slash -// 3. replace each '.' '..' path name element with equivalent one -// 4. keep the trailing slash -// The function is borrowed from stdlib http.cleanPath in server.go. -func CanonicalURLPath(p string) string { - if p == "" { - return "/" - } - if p[0] != '/' { - p = "/" + p - } - np := path.Clean(p) - // path.Clean removes trailing slash except for root, - // put the trailing slash back if necessary. - if p[len(p)-1] == '/' && np != "/" { - np += "/" - } - return np -} diff --git a/vendor/github.com/coreos/etcd/pkg/pbutil/pbutil.go b/vendor/github.com/coreos/etcd/pkg/pbutil/pbutil.go deleted file mode 100644 index d70f98dd82fe..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/pbutil/pbutil.go +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package pbutil defines interfaces for handling Protocol Buffer objects. -package pbutil - -import "github.com/coreos/pkg/capnslog" - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "pkg/pbutil") -) - -type Marshaler interface { - Marshal() (data []byte, err error) -} - -type Unmarshaler interface { - Unmarshal(data []byte) error -} - -func MustMarshal(m Marshaler) []byte { - d, err := m.Marshal() - if err != nil { - plog.Panicf("marshal should never fail (%v)", err) - } - return d -} - -func MustUnmarshal(um Unmarshaler, data []byte) { - if err := um.Unmarshal(data); err != nil { - plog.Panicf("unmarshal should never fail (%v)", err) - } -} - -func MaybeUnmarshal(um Unmarshaler, data []byte) bool { - if err := um.Unmarshal(data); err != nil { - return false - } - return true -} - -func GetBool(v *bool) (vv bool, set bool) { - if v == nil { - return false, false - } - return *v, true -} - -func Boolp(b bool) *bool { return &b } diff --git a/vendor/github.com/coreos/etcd/pkg/proxy/doc.go b/vendor/github.com/coreos/etcd/pkg/proxy/doc.go deleted file mode 100644 index fc81aa20b7a1..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/proxy/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package proxy implements proxy servers for network fault testing. -package proxy diff --git a/vendor/github.com/coreos/etcd/pkg/proxy/server.go b/vendor/github.com/coreos/etcd/pkg/proxy/server.go deleted file mode 100644 index 311af966f220..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/proxy/server.go +++ /dev/null @@ -1,949 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package proxy - -import ( - "fmt" - "io" - mrand "math/rand" - "net" - "net/http" - "net/url" - "strings" - "sync" - "time" - - "github.com/coreos/etcd/pkg/transport" - - humanize "github.com/dustin/go-humanize" - "go.uber.org/zap" -) - -// Server defines proxy server layer that simulates common network faults, -// such as latency spikes, packet drop/corruption, etc.. -type Server interface { - // From returns proxy source address in "scheme://host:port" format. - From() string - // To returns proxy destination address in "scheme://host:port" format. - To() string - - // Ready returns when proxy is ready to serve. - Ready() <-chan struct{} - // Done returns when proxy has been closed. - Done() <-chan struct{} - // Error sends errors while serving proxy. - Error() <-chan error - // Close closes listener and transport. - Close() error - - // DelayAccept adds latency ± random variable to accepting new incoming connections. - DelayAccept(latency, rv time.Duration) - // UndelayAccept removes sending latencies. - UndelayAccept() - // LatencyAccept returns current latency on accepting new incoming connections. - LatencyAccept() time.Duration - // DelayTx adds latency ± random variable to "sending" layer. - DelayTx(latency, rv time.Duration) - // UndelayTx removes sending latencies. - UndelayTx() - // LatencyTx returns current send latency. - LatencyTx() time.Duration - // DelayRx adds latency ± random variable to "receiving" layer. - DelayRx(latency, rv time.Duration) - // UndelayRx removes "receiving" latencies. - UndelayRx() - // LatencyRx returns current receive latency. - LatencyRx() time.Duration - - // PauseAccept stops accepting new connections. - PauseAccept() - // UnpauseAccept removes pause operation on accepting new connections. - UnpauseAccept() - // PauseTx stops "forwarding" packets. - PauseTx() - // UnpauseTx removes "forwarding" pause operation. - UnpauseTx() - // PauseRx stops "receiving" packets to client. - PauseRx() - // UnpauseRx removes "receiving" pause operation. - UnpauseRx() - - // BlackholeTx drops all incoming packets before "forwarding". - BlackholeTx() - // UnblackholeTx removes blackhole operation on "sending". - UnblackholeTx() - // BlackholeRx drops all incoming packets to client. - BlackholeRx() - // UnblackholeRx removes blackhole operation on "receiving". - UnblackholeRx() - - // CorruptTx corrupts incoming packets from the listener. - CorruptTx(f func(data []byte) []byte) - // UncorruptTx removes corrupt operation on "forwarding". - UncorruptTx() - // CorruptRx corrupts incoming packets to client. - CorruptRx(f func(data []byte) []byte) - // UncorruptRx removes corrupt operation on "receiving". - UncorruptRx() - - // ResetListener closes and restarts listener. - ResetListener() error -} - -type proxyServer struct { - lg *zap.Logger - - from, to url.URL - tlsInfo transport.TLSInfo - dialTimeout time.Duration - bufferSize int - retryInterval time.Duration - - readyc chan struct{} - donec chan struct{} - errc chan error - - closeOnce sync.Once - closeWg sync.WaitGroup - - listenerMu sync.RWMutex - listener net.Listener - - latencyAcceptMu sync.RWMutex - latencyAccept time.Duration - latencyTxMu sync.RWMutex - latencyTx time.Duration - latencyRxMu sync.RWMutex - latencyRx time.Duration - - corruptTxMu sync.RWMutex - corruptTx func(data []byte) []byte - corruptRxMu sync.RWMutex - corruptRx func(data []byte) []byte - - acceptMu sync.Mutex - pauseAcceptc chan struct{} - txMu sync.Mutex - pauseTxc chan struct{} - blackholeTxc chan struct{} - rxMu sync.Mutex - pauseRxc chan struct{} - blackholeRxc chan struct{} -} - -// ServerConfig defines proxy server configuration. -type ServerConfig struct { - Logger *zap.Logger - From url.URL - To url.URL - TLSInfo transport.TLSInfo - DialTimeout time.Duration - BufferSize int - RetryInterval time.Duration -} - -var ( - defaultDialTimeout = 3 * time.Second - defaultBufferSize = 48 * 1024 - defaultRetryInterval = 10 * time.Millisecond - defaultLogger *zap.Logger -) - -func init() { - var err error - defaultLogger, err = zap.NewProduction() - if err != nil { - panic(err) - } -} - -// NewServer returns a proxy implementation with no iptables/tc dependencies. -// The proxy layer overhead is <1ms. -func NewServer(cfg ServerConfig) Server { - p := &proxyServer{ - lg: cfg.Logger, - - from: cfg.From, - to: cfg.To, - tlsInfo: cfg.TLSInfo, - dialTimeout: cfg.DialTimeout, - bufferSize: cfg.BufferSize, - retryInterval: cfg.RetryInterval, - - readyc: make(chan struct{}), - donec: make(chan struct{}), - errc: make(chan error, 16), - - pauseAcceptc: make(chan struct{}), - pauseTxc: make(chan struct{}), - blackholeTxc: make(chan struct{}), - pauseRxc: make(chan struct{}), - blackholeRxc: make(chan struct{}), - } - if p.dialTimeout == 0 { - p.dialTimeout = defaultDialTimeout - } - if p.bufferSize == 0 { - p.bufferSize = defaultBufferSize - } - if p.retryInterval == 0 { - p.retryInterval = defaultRetryInterval - } - if p.lg == nil { - p.lg = defaultLogger - } - close(p.pauseAcceptc) - close(p.pauseTxc) - close(p.pauseRxc) - - if strings.HasPrefix(p.from.Scheme, "http") { - p.from.Scheme = "tcp" - } - if strings.HasPrefix(p.to.Scheme, "http") { - p.to.Scheme = "tcp" - } - - var ln net.Listener - var err error - if !p.tlsInfo.Empty() { - ln, err = transport.NewListener(p.from.Host, p.from.Scheme, &p.tlsInfo) - } else { - ln, err = net.Listen(p.from.Scheme, p.from.Host) - } - if err != nil { - p.errc <- err - p.Close() - return p - } - p.listener = ln - - p.closeWg.Add(1) - go p.listenAndServe() - - p.lg.Info("started proxying", zap.String("from", p.From()), zap.String("to", p.To())) - return p -} - -func (p *proxyServer) From() string { - return fmt.Sprintf("%s://%s", p.from.Scheme, p.from.Host) -} - -func (p *proxyServer) To() string { - return fmt.Sprintf("%s://%s", p.to.Scheme, p.to.Host) -} - -// TODO: implement packet reordering from multiple TCP connections -// buffer packets per connection for awhile, reorder before transmit -// - https://github.com/coreos/etcd/issues/5614 -// - https://github.com/coreos/etcd/pull/6918#issuecomment-264093034 - -func (p *proxyServer) listenAndServe() { - defer p.closeWg.Done() - - p.lg.Info("proxy is listening on", zap.String("from", p.From())) - close(p.readyc) - - for { - p.acceptMu.Lock() - pausec := p.pauseAcceptc - p.acceptMu.Unlock() - select { - case <-pausec: - case <-p.donec: - return - } - - p.latencyAcceptMu.RLock() - lat := p.latencyAccept - p.latencyAcceptMu.RUnlock() - if lat > 0 { - select { - case <-time.After(lat): - case <-p.donec: - return - } - } - - p.listenerMu.RLock() - ln := p.listener - p.listenerMu.RUnlock() - - in, err := ln.Accept() - if err != nil { - select { - case p.errc <- err: - select { - case <-p.donec: - return - default: - } - case <-p.donec: - return - } - p.lg.Debug("listener accept error", zap.Error(err)) - - if strings.HasSuffix(err.Error(), "use of closed network connection") { - select { - case <-time.After(p.retryInterval): - case <-p.donec: - return - } - p.lg.Debug("listener is closed; retry listening on", zap.String("from", p.From())) - - if err = p.ResetListener(); err != nil { - select { - case p.errc <- err: - select { - case <-p.donec: - return - default: - } - case <-p.donec: - return - } - p.lg.Warn("failed to reset listener", zap.Error(err)) - } - } - - continue - } - - var out net.Conn - if !p.tlsInfo.Empty() { - var tp *http.Transport - tp, err = transport.NewTransport(p.tlsInfo, p.dialTimeout) - if err != nil { - select { - case p.errc <- err: - select { - case <-p.donec: - return - default: - } - case <-p.donec: - return - } - continue - } - out, err = tp.Dial(p.to.Scheme, p.to.Host) - } else { - out, err = net.Dial(p.to.Scheme, p.to.Host) - } - if err != nil { - select { - case p.errc <- err: - select { - case <-p.donec: - return - default: - } - case <-p.donec: - return - } - p.lg.Debug("failed to dial", zap.Error(err)) - continue - } - - go func() { - // read incoming bytes from listener, dispatch to outgoing connection - p.transmit(out, in) - out.Close() - in.Close() - }() - go func() { - // read response from outgoing connection, write back to listener - p.receive(in, out) - in.Close() - out.Close() - }() - } -} - -func (p *proxyServer) transmit(dst io.Writer, src io.Reader) { p.ioCopy(dst, src, true) } -func (p *proxyServer) receive(dst io.Writer, src io.Reader) { p.ioCopy(dst, src, false) } -func (p *proxyServer) ioCopy(dst io.Writer, src io.Reader, proxySend bool) { - buf := make([]byte, p.bufferSize) - for { - nr, err := src.Read(buf) - if err != nil { - if err == io.EOF { - return - } - // connection already closed - if strings.HasSuffix(err.Error(), "read: connection reset by peer") { - return - } - if strings.HasSuffix(err.Error(), "use of closed network connection") { - return - } - select { - case p.errc <- err: - select { - case <-p.donec: - return - default: - } - case <-p.donec: - return - } - p.lg.Debug("failed to read", zap.Error(err)) - return - } - if nr == 0 { - return - } - data := buf[:nr] - - var pausec chan struct{} - var blackholec chan struct{} - if proxySend { - p.txMu.Lock() - pausec = p.pauseTxc - blackholec = p.blackholeTxc - p.txMu.Unlock() - } else { - p.rxMu.Lock() - pausec = p.pauseRxc - blackholec = p.blackholeRxc - p.rxMu.Unlock() - } - select { - case <-pausec: - case <-p.donec: - return - } - blackholed := false - select { - case <-blackholec: - blackholed = true - case <-p.donec: - return - default: - } - if blackholed { - if proxySend { - p.lg.Debug( - "dropped", - zap.String("data-size", humanize.Bytes(uint64(nr))), - zap.String("from", p.From()), - zap.String("to", p.To()), - ) - } else { - p.lg.Debug( - "dropped", - zap.String("data-size", humanize.Bytes(uint64(nr))), - zap.String("from", p.To()), - zap.String("to", p.From()), - ) - } - continue - } - - var lat time.Duration - if proxySend { - p.latencyTxMu.RLock() - lat = p.latencyTx - p.latencyTxMu.RUnlock() - } else { - p.latencyRxMu.RLock() - lat = p.latencyRx - p.latencyRxMu.RUnlock() - } - if lat > 0 { - select { - case <-time.After(lat): - case <-p.donec: - return - } - } - - if proxySend { - p.corruptTxMu.RLock() - if p.corruptTx != nil { - data = p.corruptTx(data) - } - p.corruptTxMu.RUnlock() - } else { - p.corruptRxMu.RLock() - if p.corruptRx != nil { - data = p.corruptRx(data) - } - p.corruptRxMu.RUnlock() - } - - var nw int - nw, err = dst.Write(data) - if err != nil { - if err == io.EOF { - return - } - select { - case p.errc <- err: - select { - case <-p.donec: - return - default: - } - case <-p.donec: - return - } - if proxySend { - p.lg.Debug("failed to write while sending", zap.Error(err)) - } else { - p.lg.Debug("failed to write while receiving", zap.Error(err)) - } - return - } - - if nr != nw { - select { - case p.errc <- io.ErrShortWrite: - select { - case <-p.donec: - return - default: - } - case <-p.donec: - return - } - if proxySend { - p.lg.Debug( - "failed to write while sending; read/write bytes are different", - zap.Int("read-bytes", nr), - zap.Int("write-bytes", nw), - zap.Error(io.ErrShortWrite), - ) - } else { - p.lg.Debug( - "failed to write while receiving; read/write bytes are different", - zap.Int("read-bytes", nr), - zap.Int("write-bytes", nw), - zap.Error(io.ErrShortWrite), - ) - } - return - } - - if proxySend { - p.lg.Debug( - "transmitted", - zap.String("data-size", humanize.Bytes(uint64(nr))), - zap.String("from", p.From()), - zap.String("to", p.To()), - ) - } else { - p.lg.Debug( - "received", - zap.String("data-size", humanize.Bytes(uint64(nr))), - zap.String("from", p.To()), - zap.String("to", p.From()), - ) - } - - } -} - -func (p *proxyServer) Ready() <-chan struct{} { return p.readyc } -func (p *proxyServer) Done() <-chan struct{} { return p.donec } -func (p *proxyServer) Error() <-chan error { return p.errc } -func (p *proxyServer) Close() (err error) { - p.closeOnce.Do(func() { - close(p.donec) - p.listenerMu.Lock() - if p.listener != nil { - err = p.listener.Close() - p.lg.Info( - "closed proxy listener", - zap.String("from", p.From()), - zap.String("to", p.To()), - ) - } - p.lg.Sync() - p.listenerMu.Unlock() - }) - p.closeWg.Wait() - return err -} - -func (p *proxyServer) DelayAccept(latency, rv time.Duration) { - if latency <= 0 { - return - } - d := computeLatency(latency, rv) - p.latencyAcceptMu.Lock() - p.latencyAccept = d - p.latencyAcceptMu.Unlock() - - p.lg.Info( - "set accept latency", - zap.Duration("latency", d), - zap.Duration("given-latency", latency), - zap.Duration("given-latency-random-variable", rv), - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) UndelayAccept() { - p.latencyAcceptMu.Lock() - d := p.latencyAccept - p.latencyAccept = 0 - p.latencyAcceptMu.Unlock() - - p.lg.Info( - "removed accept latency", - zap.Duration("latency", d), - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) LatencyAccept() time.Duration { - p.latencyAcceptMu.RLock() - d := p.latencyAccept - p.latencyAcceptMu.RUnlock() - return d -} - -func (p *proxyServer) DelayTx(latency, rv time.Duration) { - if latency <= 0 { - return - } - d := computeLatency(latency, rv) - p.latencyTxMu.Lock() - p.latencyTx = d - p.latencyTxMu.Unlock() - - p.lg.Info( - "set transmit latency", - zap.Duration("latency", d), - zap.Duration("given-latency", latency), - zap.Duration("given-latency-random-variable", rv), - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) UndelayTx() { - p.latencyTxMu.Lock() - d := p.latencyTx - p.latencyTx = 0 - p.latencyTxMu.Unlock() - - p.lg.Info( - "removed transmit latency", - zap.Duration("latency", d), - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) LatencyTx() time.Duration { - p.latencyTxMu.RLock() - d := p.latencyTx - p.latencyTxMu.RUnlock() - return d -} - -func (p *proxyServer) DelayRx(latency, rv time.Duration) { - if latency <= 0 { - return - } - d := computeLatency(latency, rv) - p.latencyRxMu.Lock() - p.latencyRx = d - p.latencyRxMu.Unlock() - - p.lg.Info( - "set receive latency", - zap.Duration("latency", d), - zap.Duration("given-latency", latency), - zap.Duration("given-latency-random-variable", rv), - zap.String("from", p.To()), - zap.String("to", p.From()), - ) -} - -func (p *proxyServer) UndelayRx() { - p.latencyRxMu.Lock() - d := p.latencyRx - p.latencyRx = 0 - p.latencyRxMu.Unlock() - - p.lg.Info( - "removed receive latency", - zap.Duration("latency", d), - zap.String("from", p.To()), - zap.String("to", p.From()), - ) -} - -func (p *proxyServer) LatencyRx() time.Duration { - p.latencyRxMu.RLock() - d := p.latencyRx - p.latencyRxMu.RUnlock() - return d -} - -func computeLatency(lat, rv time.Duration) time.Duration { - if rv == 0 { - return lat - } - if rv < 0 { - rv *= -1 - } - if rv > lat { - rv = lat / 10 - } - now := time.Now() - mrand.Seed(int64(now.Nanosecond())) - sign := 1 - if now.Second()%2 == 0 { - sign = -1 - } - return lat + time.Duration(int64(sign)*mrand.Int63n(rv.Nanoseconds())) -} - -func (p *proxyServer) PauseAccept() { - p.acceptMu.Lock() - p.pauseAcceptc = make(chan struct{}) - p.acceptMu.Unlock() - - p.lg.Info( - "paused accepting new connections", - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) UnpauseAccept() { - p.acceptMu.Lock() - select { - case <-p.pauseAcceptc: // already unpaused - case <-p.donec: - p.acceptMu.Unlock() - return - default: - close(p.pauseAcceptc) - } - p.acceptMu.Unlock() - - p.lg.Info( - "unpaused accepting new connections", - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) PauseTx() { - p.txMu.Lock() - p.pauseTxc = make(chan struct{}) - p.txMu.Unlock() - - p.lg.Info( - "paused transmit listen", - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) UnpauseTx() { - p.txMu.Lock() - select { - case <-p.pauseTxc: // already unpaused - case <-p.donec: - p.txMu.Unlock() - return - default: - close(p.pauseTxc) - } - p.txMu.Unlock() - - p.lg.Info( - "unpaused transmit listen", - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) PauseRx() { - p.rxMu.Lock() - p.pauseRxc = make(chan struct{}) - p.rxMu.Unlock() - - p.lg.Info( - "paused receive listen", - zap.String("from", p.To()), - zap.String("to", p.From()), - ) -} - -func (p *proxyServer) UnpauseRx() { - p.rxMu.Lock() - select { - case <-p.pauseRxc: // already unpaused - case <-p.donec: - p.rxMu.Unlock() - return - default: - close(p.pauseRxc) - } - p.rxMu.Unlock() - - p.lg.Info( - "unpaused receive listen", - zap.String("from", p.To()), - zap.String("to", p.From()), - ) -} - -func (p *proxyServer) BlackholeTx() { - p.txMu.Lock() - select { - case <-p.blackholeTxc: // already blackholed - case <-p.donec: - p.txMu.Unlock() - return - default: - close(p.blackholeTxc) - } - p.txMu.Unlock() - - p.lg.Info( - "blackholed transmit", - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) UnblackholeTx() { - p.txMu.Lock() - p.blackholeTxc = make(chan struct{}) - p.txMu.Unlock() - - p.lg.Info( - "unblackholed transmit", - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) BlackholeRx() { - p.rxMu.Lock() - select { - case <-p.blackholeRxc: // already blackholed - case <-p.donec: - p.rxMu.Unlock() - return - default: - close(p.blackholeRxc) - } - p.rxMu.Unlock() - - p.lg.Info( - "blackholed receive", - zap.String("from", p.To()), - zap.String("to", p.From()), - ) -} - -func (p *proxyServer) UnblackholeRx() { - p.rxMu.Lock() - p.blackholeRxc = make(chan struct{}) - p.rxMu.Unlock() - - p.lg.Info( - "unblackholed receive", - zap.String("from", p.To()), - zap.String("to", p.From()), - ) -} - -func (p *proxyServer) CorruptTx(f func([]byte) []byte) { - p.corruptTxMu.Lock() - p.corruptTx = f - p.corruptTxMu.Unlock() - - p.lg.Info( - "corrupting transmit", - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) UncorruptTx() { - p.corruptTxMu.Lock() - p.corruptTx = nil - p.corruptTxMu.Unlock() - - p.lg.Info( - "stopped corrupting transmit", - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) CorruptRx(f func([]byte) []byte) { - p.corruptRxMu.Lock() - p.corruptRx = f - p.corruptRxMu.Unlock() - p.lg.Info( - "corrupting receive", - zap.String("from", p.To()), - zap.String("to", p.From()), - ) -} - -func (p *proxyServer) UncorruptRx() { - p.corruptRxMu.Lock() - p.corruptRx = nil - p.corruptRxMu.Unlock() - - p.lg.Info( - "stopped corrupting receive", - zap.String("from", p.To()), - zap.String("to", p.From()), - ) -} - -func (p *proxyServer) ResetListener() error { - p.listenerMu.Lock() - defer p.listenerMu.Unlock() - - if err := p.listener.Close(); err != nil { - // already closed - if !strings.HasSuffix(err.Error(), "use of closed network connection") { - return err - } - } - - var ln net.Listener - var err error - if !p.tlsInfo.Empty() { - ln, err = transport.NewListener(p.from.Host, p.from.Scheme, &p.tlsInfo) - } else { - ln, err = net.Listen(p.from.Scheme, p.from.Host) - } - if err != nil { - return err - } - p.listener = ln - - p.lg.Info( - "reset listener on", - zap.String("from", p.From()), - ) - return nil -} diff --git a/vendor/github.com/coreos/etcd/pkg/report/doc.go b/vendor/github.com/coreos/etcd/pkg/report/doc.go deleted file mode 100644 index 1ebd119f5d53..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/report/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package report generates human-readable benchmark reports. -package report diff --git a/vendor/github.com/coreos/etcd/pkg/report/report.go b/vendor/github.com/coreos/etcd/pkg/report/report.go deleted file mode 100644 index 36d09b9d5087..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/report/report.go +++ /dev/null @@ -1,278 +0,0 @@ -// Copyright 2014 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// the file is borrowed from github.com/rakyll/boom/boomer/print.go - -package report - -import ( - "fmt" - "math" - "sort" - "strings" - "time" -) - -const ( - barChar = "∎" -) - -// Result describes the timings for an operation. -type Result struct { - Start time.Time - End time.Time - Err error - Weight float64 -} - -func (res *Result) Duration() time.Duration { return res.End.Sub(res.Start) } - -type report struct { - results chan Result - precision string - - stats Stats - sps *secondPoints -} - -// Stats exposes results raw data. -type Stats struct { - AvgTotal float64 - Fastest float64 - Slowest float64 - Average float64 - Stddev float64 - RPS float64 - Total time.Duration - ErrorDist map[string]int - Lats []float64 - TimeSeries TimeSeries -} - -func (s *Stats) copy() Stats { - ss := *s - ss.ErrorDist = copyMap(ss.ErrorDist) - ss.Lats = copyFloats(ss.Lats) - return ss -} - -// Report processes a result stream until it is closed, then produces a -// string with information about the consumed result data. -type Report interface { - Results() chan<- Result - - // Run returns results in print-friendly format. - Run() <-chan string - - // Stats returns results in raw data. - Stats() <-chan Stats -} - -func NewReport(precision string) Report { return newReport(precision) } - -func newReport(precision string) *report { - r := &report{ - results: make(chan Result, 16), - precision: precision, - } - r.stats.ErrorDist = make(map[string]int) - return r -} - -func NewReportSample(precision string) Report { - r := NewReport(precision).(*report) - r.sps = newSecondPoints() - return r -} - -func (r *report) Results() chan<- Result { return r.results } - -func (r *report) Run() <-chan string { - donec := make(chan string, 1) - go func() { - defer close(donec) - r.processResults() - donec <- r.String() - }() - return donec -} - -func (r *report) Stats() <-chan Stats { - donec := make(chan Stats, 1) - go func() { - defer close(donec) - r.processResults() - s := r.stats.copy() - if r.sps != nil { - s.TimeSeries = r.sps.getTimeSeries() - } - donec <- s - }() - return donec -} - -func copyMap(m map[string]int) (c map[string]int) { - c = make(map[string]int, len(m)) - for k, v := range m { - c[k] = v - } - return c -} - -func copyFloats(s []float64) (c []float64) { - c = make([]float64, len(s)) - copy(c, s) - return c -} - -func (r *report) String() (s string) { - if len(r.stats.Lats) > 0 { - s += fmt.Sprintf("\nSummary:\n") - s += fmt.Sprintf(" Total:\t%s.\n", r.sec2str(r.stats.Total.Seconds())) - s += fmt.Sprintf(" Slowest:\t%s.\n", r.sec2str(r.stats.Slowest)) - s += fmt.Sprintf(" Fastest:\t%s.\n", r.sec2str(r.stats.Fastest)) - s += fmt.Sprintf(" Average:\t%s.\n", r.sec2str(r.stats.Average)) - s += fmt.Sprintf(" Stddev:\t%s.\n", r.sec2str(r.stats.Stddev)) - s += fmt.Sprintf(" Requests/sec:\t"+r.precision+"\n", r.stats.RPS) - s += r.histogram() - s += r.sprintLatencies() - if r.sps != nil { - s += fmt.Sprintf("%v\n", r.sps.getTimeSeries()) - } - } - if len(r.stats.ErrorDist) > 0 { - s += r.errors() - } - return s -} - -func (r *report) sec2str(sec float64) string { return fmt.Sprintf(r.precision+" secs", sec) } - -type reportRate struct{ *report } - -func NewReportRate(precision string) Report { - return &reportRate{NewReport(precision).(*report)} -} - -func (r *reportRate) String() string { - return fmt.Sprintf(" Requests/sec:\t"+r.precision+"\n", r.stats.RPS) -} - -func (r *report) processResult(res *Result) { - if res.Err != nil { - r.stats.ErrorDist[res.Err.Error()]++ - return - } - dur := res.Duration() - r.stats.Lats = append(r.stats.Lats, dur.Seconds()) - r.stats.AvgTotal += dur.Seconds() - if r.sps != nil { - r.sps.Add(res.Start, dur) - } -} - -func (r *report) processResults() { - st := time.Now() - for res := range r.results { - r.processResult(&res) - } - r.stats.Total = time.Since(st) - - r.stats.RPS = float64(len(r.stats.Lats)) / r.stats.Total.Seconds() - r.stats.Average = r.stats.AvgTotal / float64(len(r.stats.Lats)) - for i := range r.stats.Lats { - dev := r.stats.Lats[i] - r.stats.Average - r.stats.Stddev += dev * dev - } - r.stats.Stddev = math.Sqrt(r.stats.Stddev / float64(len(r.stats.Lats))) - sort.Float64s(r.stats.Lats) - if len(r.stats.Lats) > 0 { - r.stats.Fastest = r.stats.Lats[0] - r.stats.Slowest = r.stats.Lats[len(r.stats.Lats)-1] - } -} - -var pctls = []float64{10, 25, 50, 75, 90, 95, 99, 99.9} - -// Percentiles returns percentile distribution of float64 slice. -func Percentiles(nums []float64) (pcs []float64, data []float64) { - return pctls, percentiles(nums) -} - -func percentiles(nums []float64) (data []float64) { - data = make([]float64, len(pctls)) - j := 0 - n := len(nums) - for i := 0; i < n && j < len(pctls); i++ { - current := float64(i) * 100.0 / float64(n) - if current >= pctls[j] { - data[j] = nums[i] - j++ - } - } - return data -} - -func (r *report) sprintLatencies() string { - data := percentiles(r.stats.Lats) - s := fmt.Sprintf("\nLatency distribution:\n") - for i := 0; i < len(pctls); i++ { - if data[i] > 0 { - s += fmt.Sprintf(" %v%% in %s.\n", pctls[i], r.sec2str(data[i])) - } - } - return s -} - -func (r *report) histogram() string { - bc := 10 - buckets := make([]float64, bc+1) - counts := make([]int, bc+1) - bs := (r.stats.Slowest - r.stats.Fastest) / float64(bc) - for i := 0; i < bc; i++ { - buckets[i] = r.stats.Fastest + bs*float64(i) - } - buckets[bc] = r.stats.Slowest - var bi int - var max int - for i := 0; i < len(r.stats.Lats); { - if r.stats.Lats[i] <= buckets[bi] { - i++ - counts[bi]++ - if max < counts[bi] { - max = counts[bi] - } - } else if bi < len(buckets)-1 { - bi++ - } - } - s := fmt.Sprintf("\nResponse time histogram:\n") - for i := 0; i < len(buckets); i++ { - // Normalize bar lengths. - var barLen int - if max > 0 { - barLen = counts[i] * 40 / max - } - s += fmt.Sprintf(" "+r.precision+" [%v]\t|%v\n", buckets[i], counts[i], strings.Repeat(barChar, barLen)) - } - return s -} - -func (r *report) errors() string { - s := fmt.Sprintf("\nError distribution:\n") - for err, num := range r.stats.ErrorDist { - s += fmt.Sprintf(" [%d]\t%s\n", num, err) - } - return s -} diff --git a/vendor/github.com/coreos/etcd/pkg/report/timeseries.go b/vendor/github.com/coreos/etcd/pkg/report/timeseries.go deleted file mode 100644 index bc1493b2c27a..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/report/timeseries.go +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package report - -import ( - "bytes" - "encoding/csv" - "fmt" - "log" - "math" - "sort" - "sync" - "time" -) - -type DataPoint struct { - Timestamp int64 - MinLatency time.Duration - AvgLatency time.Duration - MaxLatency time.Duration - ThroughPut int64 -} - -type TimeSeries []DataPoint - -func (t TimeSeries) Swap(i, j int) { t[i], t[j] = t[j], t[i] } -func (t TimeSeries) Len() int { return len(t) } -func (t TimeSeries) Less(i, j int) bool { return t[i].Timestamp < t[j].Timestamp } - -type secondPoint struct { - minLatency time.Duration - maxLatency time.Duration - totalLatency time.Duration - count int64 -} - -type secondPoints struct { - mu sync.Mutex - tm map[int64]secondPoint -} - -func newSecondPoints() *secondPoints { - return &secondPoints{tm: make(map[int64]secondPoint)} -} - -func (sp *secondPoints) Add(ts time.Time, lat time.Duration) { - sp.mu.Lock() - defer sp.mu.Unlock() - - tk := ts.Unix() - if v, ok := sp.tm[tk]; !ok { - sp.tm[tk] = secondPoint{minLatency: lat, maxLatency: lat, totalLatency: lat, count: 1} - } else { - if lat != time.Duration(0) { - v.minLatency = minDuration(v.minLatency, lat) - } - v.maxLatency = maxDuration(v.maxLatency, lat) - v.totalLatency += lat - v.count++ - sp.tm[tk] = v - } -} - -func (sp *secondPoints) getTimeSeries() TimeSeries { - sp.mu.Lock() - defer sp.mu.Unlock() - - var ( - minTs int64 = math.MaxInt64 - maxTs int64 = -1 - ) - for k := range sp.tm { - if minTs > k { - minTs = k - } - if maxTs < k { - maxTs = k - } - } - for ti := minTs; ti < maxTs; ti++ { - if _, ok := sp.tm[ti]; !ok { // fill-in empties - sp.tm[ti] = secondPoint{totalLatency: 0, count: 0} - } - } - - var ( - tslice = make(TimeSeries, len(sp.tm)) - i int - ) - for k, v := range sp.tm { - var lat time.Duration - if v.count > 0 { - lat = time.Duration(v.totalLatency) / time.Duration(v.count) - } - tslice[i] = DataPoint{ - Timestamp: k, - MinLatency: v.minLatency, - AvgLatency: lat, - MaxLatency: v.maxLatency, - ThroughPut: v.count, - } - i++ - } - - sort.Sort(tslice) - return tslice -} - -func (t TimeSeries) String() string { - buf := new(bytes.Buffer) - wr := csv.NewWriter(buf) - if err := wr.Write([]string{"UNIX-SECOND", "MIN-LATENCY-MS", "AVG-LATENCY-MS", "MAX-LATENCY-MS", "AVG-THROUGHPUT"}); err != nil { - log.Fatal(err) - } - rows := [][]string{} - for i := range t { - row := []string{ - fmt.Sprintf("%d", t[i].Timestamp), - t[i].MinLatency.String(), - t[i].AvgLatency.String(), - t[i].MaxLatency.String(), - fmt.Sprintf("%d", t[i].ThroughPut), - } - rows = append(rows, row) - } - if err := wr.WriteAll(rows); err != nil { - log.Fatal(err) - } - wr.Flush() - if err := wr.Error(); err != nil { - log.Fatal(err) - } - return fmt.Sprintf("\nSample in one second (unix latency throughput):\n%s", buf.String()) -} - -func minDuration(a, b time.Duration) time.Duration { - if a < b { - return a - } - return b -} - -func maxDuration(a, b time.Duration) time.Duration { - if a > b { - return a - } - return b -} diff --git a/vendor/github.com/coreos/etcd/pkg/report/weighted.go b/vendor/github.com/coreos/etcd/pkg/report/weighted.go deleted file mode 100644 index 411214f6d165..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/report/weighted.go +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// the file is borrowed from github.com/rakyll/boom/boomer/print.go - -package report - -import ( - "time" -) - -type weightedReport struct { - baseReport Report - - report *report - results chan Result - weightTotal float64 -} - -// NewWeightedReport returns a report that includes -// both weighted and unweighted statistics. -func NewWeightedReport(r Report, precision string) Report { - return &weightedReport{ - baseReport: r, - report: newReport(precision), - results: make(chan Result, 16), - } -} - -func (wr *weightedReport) Results() chan<- Result { return wr.results } - -func (wr *weightedReport) Run() <-chan string { - donec := make(chan string, 2) - go func() { - defer close(donec) - basec, rc := make(chan string, 1), make(chan Stats, 1) - go func() { basec <- (<-wr.baseReport.Run()) }() - go func() { rc <- (<-wr.report.Stats()) }() - go wr.processResults() - wr.report.stats = wr.reweighStat(<-rc) - donec <- wr.report.String() - donec <- (<-basec) - }() - return donec -} - -func (wr *weightedReport) Stats() <-chan Stats { - donec := make(chan Stats, 2) - go func() { - defer close(donec) - basec, rc := make(chan Stats, 1), make(chan Stats, 1) - go func() { basec <- (<-wr.baseReport.Stats()) }() - go func() { rc <- (<-wr.report.Stats()) }() - go wr.processResults() - donec <- wr.reweighStat(<-rc) - donec <- (<-basec) - }() - return donec -} - -func (wr *weightedReport) processResults() { - defer close(wr.report.results) - defer close(wr.baseReport.Results()) - for res := range wr.results { - wr.processResult(res) - wr.baseReport.Results() <- res - } -} - -func (wr *weightedReport) processResult(res Result) { - if res.Err != nil { - wr.report.results <- res - return - } - if res.Weight == 0 { - res.Weight = 1.0 - } - wr.weightTotal += res.Weight - res.End = res.Start.Add(time.Duration(float64(res.End.Sub(res.Start)) / res.Weight)) - res.Weight = 1.0 - wr.report.results <- res -} - -func (wr *weightedReport) reweighStat(s Stats) Stats { - weightCoef := wr.weightTotal / float64(len(s.Lats)) - // weight > 1 => processing more than one request - s.RPS *= weightCoef - s.AvgTotal *= weightCoef * weightCoef - return s -} diff --git a/vendor/github.com/coreos/etcd/pkg/runtime/fds_linux.go b/vendor/github.com/coreos/etcd/pkg/runtime/fds_linux.go deleted file mode 100644 index 8e9359db28ca..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/runtime/fds_linux.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package runtime implements utility functions for runtime systems. -package runtime - -import ( - "io/ioutil" - "syscall" -) - -func FDLimit() (uint64, error) { - var rlimit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit); err != nil { - return 0, err - } - return rlimit.Cur, nil -} - -func FDUsage() (uint64, error) { - fds, err := ioutil.ReadDir("/proc/self/fd") - if err != nil { - return 0, err - } - return uint64(len(fds)), nil -} diff --git a/vendor/github.com/coreos/etcd/pkg/runtime/fds_other.go b/vendor/github.com/coreos/etcd/pkg/runtime/fds_other.go deleted file mode 100644 index 0cbdb88c7a60..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/runtime/fds_other.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !linux - -package runtime - -import ( - "fmt" - "runtime" -) - -func FDLimit() (uint64, error) { - return 0, fmt.Errorf("cannot get FDLimit on %s", runtime.GOOS) -} - -func FDUsage() (uint64, error) { - return 0, fmt.Errorf("cannot get FDUsage on %s", runtime.GOOS) -} diff --git a/vendor/github.com/coreos/etcd/pkg/schedule/doc.go b/vendor/github.com/coreos/etcd/pkg/schedule/doc.go deleted file mode 100644 index cca2c75fb6a9..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/schedule/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package schedule provides mechanisms and policies for scheduling units of work. -package schedule diff --git a/vendor/github.com/coreos/etcd/pkg/schedule/schedule.go b/vendor/github.com/coreos/etcd/pkg/schedule/schedule.go deleted file mode 100644 index 234d01989dfb..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/schedule/schedule.go +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package schedule - -import ( - "context" - "sync" -) - -type Job func(context.Context) - -// Scheduler can schedule jobs. -type Scheduler interface { - // Schedule asks the scheduler to schedule a job defined by the given func. - // Schedule to a stopped scheduler might panic. - Schedule(j Job) - - // Pending returns number of pending jobs - Pending() int - - // Scheduled returns the number of scheduled jobs (excluding pending jobs) - Scheduled() int - - // Finished returns the number of finished jobs - Finished() int - - // WaitFinish waits until at least n job are finished and all pending jobs are finished. - WaitFinish(n int) - - // Stop stops the scheduler. - Stop() -} - -type fifo struct { - mu sync.Mutex - - resume chan struct{} - scheduled int - finished int - pendings []Job - - ctx context.Context - cancel context.CancelFunc - - finishCond *sync.Cond - donec chan struct{} -} - -// NewFIFOScheduler returns a Scheduler that schedules jobs in FIFO -// order sequentially -func NewFIFOScheduler() Scheduler { - f := &fifo{ - resume: make(chan struct{}, 1), - donec: make(chan struct{}, 1), - } - f.finishCond = sync.NewCond(&f.mu) - f.ctx, f.cancel = context.WithCancel(context.Background()) - go f.run() - return f -} - -// Schedule schedules a job that will be ran in FIFO order sequentially. -func (f *fifo) Schedule(j Job) { - f.mu.Lock() - defer f.mu.Unlock() - - if f.cancel == nil { - panic("schedule: schedule to stopped scheduler") - } - - if len(f.pendings) == 0 { - select { - case f.resume <- struct{}{}: - default: - } - } - f.pendings = append(f.pendings, j) -} - -func (f *fifo) Pending() int { - f.mu.Lock() - defer f.mu.Unlock() - return len(f.pendings) -} - -func (f *fifo) Scheduled() int { - f.mu.Lock() - defer f.mu.Unlock() - return f.scheduled -} - -func (f *fifo) Finished() int { - f.finishCond.L.Lock() - defer f.finishCond.L.Unlock() - return f.finished -} - -func (f *fifo) WaitFinish(n int) { - f.finishCond.L.Lock() - for f.finished < n || len(f.pendings) != 0 { - f.finishCond.Wait() - } - f.finishCond.L.Unlock() -} - -// Stop stops the scheduler and cancels all pending jobs. -func (f *fifo) Stop() { - f.mu.Lock() - f.cancel() - f.cancel = nil - f.mu.Unlock() - <-f.donec -} - -func (f *fifo) run() { - // TODO: recover from job panic? - defer func() { - close(f.donec) - close(f.resume) - }() - - for { - var todo Job - f.mu.Lock() - if len(f.pendings) != 0 { - f.scheduled++ - todo = f.pendings[0] - } - f.mu.Unlock() - if todo == nil { - select { - case <-f.resume: - case <-f.ctx.Done(): - f.mu.Lock() - pendings := f.pendings - f.pendings = nil - f.mu.Unlock() - // clean up pending jobs - for _, todo := range pendings { - todo(f.ctx) - } - return - } - } else { - todo(f.ctx) - f.finishCond.L.Lock() - f.finished++ - f.pendings = f.pendings[1:] - f.finishCond.Broadcast() - f.finishCond.L.Unlock() - } - } -} diff --git a/vendor/github.com/coreos/etcd/pkg/srv/srv.go b/vendor/github.com/coreos/etcd/pkg/srv/srv.go deleted file mode 100644 index 600061ce8ea8..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/srv/srv.go +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package srv looks up DNS SRV records. -package srv - -import ( - "fmt" - "net" - "net/url" - "strings" - - "github.com/coreos/etcd/pkg/types" -) - -var ( - // indirection for testing - lookupSRV = net.LookupSRV // net.DefaultResolver.LookupSRV when ctxs don't conflict - resolveTCPAddr = net.ResolveTCPAddr -) - -// GetCluster gets the cluster information via DNS discovery. -// Also sees each entry as a separate instance. -func GetCluster(service, name, dns string, apurls types.URLs) ([]string, error) { - tempName := int(0) - tcp2ap := make(map[string]url.URL) - - // First, resolve the apurls - for _, url := range apurls { - tcpAddr, err := resolveTCPAddr("tcp", url.Host) - if err != nil { - return nil, err - } - tcp2ap[tcpAddr.String()] = url - } - - stringParts := []string{} - updateNodeMap := func(service, scheme string) error { - _, addrs, err := lookupSRV(service, "tcp", dns) - if err != nil { - return err - } - for _, srv := range addrs { - port := fmt.Sprintf("%d", srv.Port) - host := net.JoinHostPort(srv.Target, port) - tcpAddr, terr := resolveTCPAddr("tcp", host) - if terr != nil { - err = terr - continue - } - n := "" - url, ok := tcp2ap[tcpAddr.String()] - if ok { - n = name - } - if n == "" { - n = fmt.Sprintf("%d", tempName) - tempName++ - } - // SRV records have a trailing dot but URL shouldn't. - shortHost := strings.TrimSuffix(srv.Target, ".") - urlHost := net.JoinHostPort(shortHost, port) - if ok && url.Scheme != scheme { - err = fmt.Errorf("bootstrap at %s from DNS for %s has scheme mismatch with expected peer %s", scheme+"://"+urlHost, service, url.String()) - } else { - stringParts = append(stringParts, fmt.Sprintf("%s=%s://%s", n, scheme, urlHost)) - } - } - if len(stringParts) == 0 { - return err - } - return nil - } - - failCount := 0 - err := updateNodeMap(service+"-ssl", "https") - srvErr := make([]string, 2) - if err != nil { - srvErr[0] = fmt.Sprintf("error querying DNS SRV records for _%s-ssl %s", service, err) - failCount++ - } - err = updateNodeMap(service, "http") - if err != nil { - srvErr[1] = fmt.Sprintf("error querying DNS SRV records for _%s %s", service, err) - failCount++ - } - if failCount == 2 { - return nil, fmt.Errorf("srv: too many errors querying DNS SRV records (%q, %q)", srvErr[0], srvErr[1]) - } - return stringParts, nil -} - -type SRVClients struct { - Endpoints []string - SRVs []*net.SRV -} - -// GetClient looks up the client endpoints for a service and domain. -func GetClient(service, domain string) (*SRVClients, error) { - var urls []*url.URL - var srvs []*net.SRV - - updateURLs := func(service, scheme string) error { - _, addrs, err := lookupSRV(service, "tcp", domain) - if err != nil { - return err - } - for _, srv := range addrs { - urls = append(urls, &url.URL{ - Scheme: scheme, - Host: net.JoinHostPort(srv.Target, fmt.Sprintf("%d", srv.Port)), - }) - } - srvs = append(srvs, addrs...) - return nil - } - - errHTTPS := updateURLs(service+"-ssl", "https") - errHTTP := updateURLs(service, "http") - - if errHTTPS != nil && errHTTP != nil { - return nil, fmt.Errorf("dns lookup errors: %s and %s", errHTTPS, errHTTP) - } - - endpoints := make([]string, len(urls)) - for i := range urls { - endpoints[i] = urls[i].String() - } - return &SRVClients{Endpoints: endpoints, SRVs: srvs}, nil -} diff --git a/vendor/github.com/coreos/etcd/pkg/stringutil/stringutil.go b/vendor/github.com/coreos/etcd/pkg/stringutil/stringutil.go deleted file mode 100644 index 44d637c20a32..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/stringutil/stringutil.go +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package stringutil exports string utility functions. -package stringutil - -import "math/rand" - -const ( - chars = "abcdefghijklmnopqrstuvwxyz0123456789" -) - -// UniqueStrings returns a slice of randomly generated unique strings. -func UniqueStrings(maxlen uint, n int) []string { - exist := make(map[string]bool) - ss := make([]string, 0) - - for len(ss) < n { - s := randomString(maxlen) - if !exist[s] { - exist[s] = true - ss = append(ss, s) - } - } - - return ss -} - -// RandomStrings returns a slice of randomly generated strings. -func RandomStrings(maxlen uint, n int) []string { - ss := make([]string, 0) - for i := 0; i < n; i++ { - ss = append(ss, randomString(maxlen)) - } - return ss -} - -func randomString(l uint) string { - s := make([]byte, l) - for i := 0; i < int(l); i++ { - s[i] = chars[rand.Intn(len(chars))] - } - return string(s) -} diff --git a/vendor/github.com/coreos/etcd/pkg/testutil/assert.go b/vendor/github.com/coreos/etcd/pkg/testutil/assert.go deleted file mode 100644 index 9cf03457d52f..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/testutil/assert.go +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package testutil - -import ( - "fmt" - "reflect" - "testing" -) - -func AssertEqual(t *testing.T, e, a interface{}, msg ...string) { - if (e == nil || a == nil) && (isNil(e) && isNil(a)) { - return - } - if reflect.DeepEqual(e, a) { - return - } - s := "" - if len(msg) > 1 { - s = msg[0] + ": " - } - s = fmt.Sprintf("%sexpected %+v, got %+v", s, e, a) - FatalStack(t, s) -} - -func AssertNil(t *testing.T, v interface{}) { - AssertEqual(t, nil, v) -} - -func AssertNotNil(t *testing.T, v interface{}) { - if v == nil { - t.Fatalf("expected non-nil, got %+v", v) - } -} - -func AssertTrue(t *testing.T, v bool, msg ...string) { - AssertEqual(t, true, v, msg...) -} - -func AssertFalse(t *testing.T, v bool, msg ...string) { - AssertEqual(t, false, v, msg...) -} - -func isNil(v interface{}) bool { - if v == nil { - return true - } - rv := reflect.ValueOf(v) - return rv.Kind() != reflect.Struct && rv.IsNil() -} diff --git a/vendor/github.com/coreos/etcd/pkg/testutil/leak.go b/vendor/github.com/coreos/etcd/pkg/testutil/leak.go deleted file mode 100644 index 2ebae1e6e887..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/testutil/leak.go +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package testutil - -import ( - "fmt" - "net/http" - "os" - "regexp" - "runtime" - "sort" - "strings" - "testing" - "time" -) - -/* -CheckLeakedGoroutine verifies tests do not leave any leaky -goroutines. It returns true when there are goroutines still -running(leaking) after all tests. - - import "github.com/coreos/etcd/pkg/testutil" - - func TestMain(m *testing.M) { - v := m.Run() - if v == 0 && testutil.CheckLeakedGoroutine() { - os.Exit(1) - } - os.Exit(v) - } - - func TestSample(t *testing.T) { - defer testutil.AfterTest(t) - ... - } - -*/ -func CheckLeakedGoroutine() bool { - if testing.Short() { - // not counting goroutines for leakage in -short mode - return false - } - gs := interestingGoroutines() - if len(gs) == 0 { - return false - } - - stackCount := make(map[string]int) - re := regexp.MustCompile(`\(0[0-9a-fx, ]*\)`) - for _, g := range gs { - // strip out pointer arguments in first function of stack dump - normalized := string(re.ReplaceAll([]byte(g), []byte("(...)"))) - stackCount[normalized]++ - } - - fmt.Fprintf(os.Stderr, "Too many goroutines running after all test(s).\n") - for stack, count := range stackCount { - fmt.Fprintf(os.Stderr, "%d instances of:\n%s\n", count, stack) - } - return true -} - -// CheckAfterTest returns an error if AfterTest would fail with an error. -func CheckAfterTest(d time.Duration) error { - http.DefaultTransport.(*http.Transport).CloseIdleConnections() - if testing.Short() { - return nil - } - var bad string - badSubstring := map[string]string{ - ").writeLoop(": "a Transport", - "created by net/http/httptest.(*Server).Start": "an httptest.Server", - "timeoutHandler": "a TimeoutHandler", - "net.(*netFD).connect(": "a timing out dial", - ").noteClientGone(": "a closenotifier sender", - ").readLoop(": "a Transport", - ".grpc": "a gRPC resource", - } - - var stacks string - begin := time.Now() - for time.Since(begin) < d { - bad = "" - stacks = strings.Join(interestingGoroutines(), "\n\n") - for substr, what := range badSubstring { - if strings.Contains(stacks, substr) { - bad = what - } - } - if bad == "" { - return nil - } - // Bad stuff found, but goroutines might just still be - // shutting down, so give it some time. - time.Sleep(50 * time.Millisecond) - } - return fmt.Errorf("appears to have leaked %s:\n%s", bad, stacks) -} - -// AfterTest is meant to run in a defer that executes after a test completes. -// It will detect common goroutine leaks, retrying in case there are goroutines -// not synchronously torn down, and fail the test if any goroutines are stuck. -func AfterTest(t *testing.T) { - if err := CheckAfterTest(300 * time.Millisecond); err != nil { - t.Errorf("Test %v", err) - } -} - -func interestingGoroutines() (gs []string) { - buf := make([]byte, 2<<20) - buf = buf[:runtime.Stack(buf, true)] - for _, g := range strings.Split(string(buf), "\n\n") { - sl := strings.SplitN(g, "\n", 2) - if len(sl) != 2 { - continue - } - stack := strings.TrimSpace(sl[1]) - if stack == "" || - strings.Contains(stack, "sync.(*WaitGroup).Done") || - strings.Contains(stack, "os.(*file).close") || - strings.Contains(stack, "created by os/signal.init") || - strings.Contains(stack, "runtime/panic.go") || - strings.Contains(stack, "created by testing.RunTests") || - strings.Contains(stack, "testing.Main(") || - strings.Contains(stack, "runtime.goexit") || - strings.Contains(stack, "github.com/coreos/etcd/pkg/testutil.interestingGoroutines") || - strings.Contains(stack, "github.com/coreos/etcd/pkg/logutil.(*MergeLogger).outputLoop") || - strings.Contains(stack, "github.com/golang/glog.(*loggingT).flushDaemon") || - strings.Contains(stack, "created by runtime.gc") || - strings.Contains(stack, "runtime.MHeap_Scavenger") { - continue - } - gs = append(gs, stack) - } - sort.Strings(gs) - return gs -} diff --git a/vendor/github.com/coreos/etcd/pkg/testutil/pauseable_handler.go b/vendor/github.com/coreos/etcd/pkg/testutil/pauseable_handler.go deleted file mode 100644 index e0d6aca26df7..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/testutil/pauseable_handler.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package testutil - -import ( - "net/http" - "sync" -) - -type PauseableHandler struct { - Next http.Handler - mu sync.Mutex - paused bool -} - -func (ph *PauseableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - ph.mu.Lock() - paused := ph.paused - ph.mu.Unlock() - if !paused { - ph.Next.ServeHTTP(w, r) - } else { - hj, ok := w.(http.Hijacker) - if !ok { - panic("webserver doesn't support hijacking") - } - conn, _, err := hj.Hijack() - if err != nil { - panic(err.Error()) - } - conn.Close() - } -} - -func (ph *PauseableHandler) Pause() { - ph.mu.Lock() - defer ph.mu.Unlock() - ph.paused = true -} - -func (ph *PauseableHandler) Resume() { - ph.mu.Lock() - defer ph.mu.Unlock() - ph.paused = false -} diff --git a/vendor/github.com/coreos/etcd/pkg/testutil/recorder.go b/vendor/github.com/coreos/etcd/pkg/testutil/recorder.go deleted file mode 100644 index bdbbd8cc5d52..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/testutil/recorder.go +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package testutil - -import ( - "errors" - "fmt" - "sync" - "time" -) - -type Action struct { - Name string - Params []interface{} -} - -type Recorder interface { - // Record publishes an Action (e.g., function call) which will - // be reflected by Wait() or Chan() - Record(a Action) - // Wait waits until at least n Actions are available or returns with error - Wait(n int) ([]Action, error) - // Action returns immediately available Actions - Action() []Action - // Chan returns the channel for actions published by Record - Chan() <-chan Action -} - -// RecorderBuffered appends all Actions to a slice -type RecorderBuffered struct { - sync.Mutex - actions []Action -} - -func (r *RecorderBuffered) Record(a Action) { - r.Lock() - r.actions = append(r.actions, a) - r.Unlock() -} -func (r *RecorderBuffered) Action() []Action { - r.Lock() - cpy := make([]Action, len(r.actions)) - copy(cpy, r.actions) - r.Unlock() - return cpy -} -func (r *RecorderBuffered) Wait(n int) (acts []Action, err error) { - // legacy racey behavior - WaitSchedule() - acts = r.Action() - if len(acts) < n { - err = newLenErr(n, len(acts)) - } - return acts, err -} - -func (r *RecorderBuffered) Chan() <-chan Action { - ch := make(chan Action) - go func() { - acts := r.Action() - for i := range acts { - ch <- acts[i] - } - close(ch) - }() - return ch -} - -// RecorderStream writes all Actions to an unbuffered channel -type recorderStream struct { - ch chan Action -} - -func NewRecorderStream() Recorder { - return &recorderStream{ch: make(chan Action)} -} - -func (r *recorderStream) Record(a Action) { - r.ch <- a -} - -func (r *recorderStream) Action() (acts []Action) { - for { - select { - case act := <-r.ch: - acts = append(acts, act) - default: - return acts - } - } -} - -func (r *recorderStream) Chan() <-chan Action { - return r.ch -} - -func (r *recorderStream) Wait(n int) ([]Action, error) { - acts := make([]Action, n) - timeoutC := time.After(5 * time.Second) - for i := 0; i < n; i++ { - select { - case acts[i] = <-r.ch: - case <-timeoutC: - acts = acts[:i] - return acts, newLenErr(n, i) - } - } - // extra wait to catch any Action spew - select { - case act := <-r.ch: - acts = append(acts, act) - case <-time.After(10 * time.Millisecond): - } - return acts, nil -} - -func newLenErr(expected int, actual int) error { - s := fmt.Sprintf("len(actions) = %d, expected >= %d", actual, expected) - return errors.New(s) -} diff --git a/vendor/github.com/coreos/etcd/pkg/testutil/testutil.go b/vendor/github.com/coreos/etcd/pkg/testutil/testutil.go deleted file mode 100644 index 0e02ddc0db73..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/testutil/testutil.go +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package testutil provides test utility functions. -package testutil - -import ( - "net/url" - "runtime" - "testing" - "time" -) - -// WaitSchedule briefly sleeps in order to invoke the go scheduler. -// TODO: improve this when we are able to know the schedule or status of target go-routine. -func WaitSchedule() { - time.Sleep(10 * time.Millisecond) -} - -func MustNewURLs(t *testing.T, urls []string) []url.URL { - if urls == nil { - return nil - } - var us []url.URL - for _, url := range urls { - u := MustNewURL(t, url) - us = append(us, *u) - } - return us -} - -func MustNewURL(t *testing.T, s string) *url.URL { - u, err := url.Parse(s) - if err != nil { - t.Fatalf("parse %v error: %v", s, err) - } - return u -} - -// FatalStack helps to fatal the test and print out the stacks of all running goroutines. -func FatalStack(t *testing.T, s string) { - stackTrace := make([]byte, 1024*1024) - n := runtime.Stack(stackTrace, true) - t.Error(string(stackTrace[:n])) - t.Fatalf(s) -} - -// ConditionFunc returns true when a condition is met. -type ConditionFunc func() (bool, error) - -// Poll calls a condition function repeatedly on a polling interval until it returns true, returns an error -// or the timeout is reached. If the condition function returns true or an error before the timeout, Poll -// immediately returns with the true value or the error. If the timeout is exceeded, Poll returns false. -func Poll(interval time.Duration, timeout time.Duration, condition ConditionFunc) (bool, error) { - timeoutCh := time.After(timeout) - ticker := time.NewTicker(interval) - defer ticker.Stop() - - for { - select { - case <-timeoutCh: - return false, nil - case <-ticker.C: - success, err := condition() - if err != nil { - return false, err - } - if success { - return true, nil - } - } - } -} diff --git a/vendor/github.com/coreos/etcd/pkg/tlsutil/cipher_suites.go b/vendor/github.com/coreos/etcd/pkg/tlsutil/cipher_suites.go deleted file mode 100644 index b5916bb54dce..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/tlsutil/cipher_suites.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tlsutil - -import "crypto/tls" - -// cipher suites implemented by Go -// https://github.com/golang/go/blob/dev.boringcrypto.go1.10/src/crypto/tls/cipher_suites.go -var cipherSuites = map[string]uint16{ - "TLS_RSA_WITH_RC4_128_SHA": tls.TLS_RSA_WITH_RC4_128_SHA, - "TLS_RSA_WITH_3DES_EDE_CBC_SHA": tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA, - "TLS_RSA_WITH_AES_128_CBC_SHA": tls.TLS_RSA_WITH_AES_128_CBC_SHA, - "TLS_RSA_WITH_AES_256_CBC_SHA": tls.TLS_RSA_WITH_AES_256_CBC_SHA, - "TLS_RSA_WITH_AES_128_CBC_SHA256": tls.TLS_RSA_WITH_AES_128_CBC_SHA256, - "TLS_RSA_WITH_AES_128_GCM_SHA256": tls.TLS_RSA_WITH_AES_128_GCM_SHA256, - "TLS_RSA_WITH_AES_256_GCM_SHA384": tls.TLS_RSA_WITH_AES_256_GCM_SHA384, - "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA": tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, - "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA": tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, - "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA": tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, - "TLS_ECDHE_RSA_WITH_RC4_128_SHA": tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA, - "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, - "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, - "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, - "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256": tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, - "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256": tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, - "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256": tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, - "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256": tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, - "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384": tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, - "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384": tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, - "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305": tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, - "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305": tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, -} - -// GetCipherSuite returns the corresponding cipher suite, -// and boolean value if it is supported. -func GetCipherSuite(s string) (uint16, bool) { - v, ok := cipherSuites[s] - return v, ok -} diff --git a/vendor/github.com/coreos/etcd/pkg/tlsutil/doc.go b/vendor/github.com/coreos/etcd/pkg/tlsutil/doc.go deleted file mode 100644 index 3b6aa670bafe..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/tlsutil/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package tlsutil provides utility functions for handling TLS. -package tlsutil diff --git a/vendor/github.com/coreos/etcd/pkg/tlsutil/tlsutil.go b/vendor/github.com/coreos/etcd/pkg/tlsutil/tlsutil.go deleted file mode 100644 index 79b1f632ed51..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/tlsutil/tlsutil.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tlsutil - -import ( - "crypto/tls" - "crypto/x509" - "encoding/pem" - "io/ioutil" -) - -// NewCertPool creates x509 certPool with provided CA files. -func NewCertPool(CAFiles []string) (*x509.CertPool, error) { - certPool := x509.NewCertPool() - - for _, CAFile := range CAFiles { - pemByte, err := ioutil.ReadFile(CAFile) - if err != nil { - return nil, err - } - - for { - var block *pem.Block - block, pemByte = pem.Decode(pemByte) - if block == nil { - break - } - cert, err := x509.ParseCertificate(block.Bytes) - if err != nil { - return nil, err - } - certPool.AddCert(cert) - } - } - - return certPool, nil -} - -// NewCert generates TLS cert by using the given cert,key and parse function. -func NewCert(certfile, keyfile string, parseFunc func([]byte, []byte) (tls.Certificate, error)) (*tls.Certificate, error) { - cert, err := ioutil.ReadFile(certfile) - if err != nil { - return nil, err - } - - key, err := ioutil.ReadFile(keyfile) - if err != nil { - return nil, err - } - - if parseFunc == nil { - parseFunc = tls.X509KeyPair - } - - tlsCert, err := parseFunc(cert, key) - if err != nil { - return nil, err - } - return &tlsCert, nil -} diff --git a/vendor/github.com/coreos/etcd/pkg/transport/doc.go b/vendor/github.com/coreos/etcd/pkg/transport/doc.go deleted file mode 100644 index 37658ce591a4..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/transport/doc.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package transport implements various HTTP transport utilities based on Go -// net package. -package transport diff --git a/vendor/github.com/coreos/etcd/pkg/transport/keepalive_listener.go b/vendor/github.com/coreos/etcd/pkg/transport/keepalive_listener.go deleted file mode 100644 index 4ff8e7f0010c..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/transport/keepalive_listener.go +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "crypto/tls" - "fmt" - "net" - "time" -) - -type keepAliveConn interface { - SetKeepAlive(bool) error - SetKeepAlivePeriod(d time.Duration) error -} - -// NewKeepAliveListener returns a listener that listens on the given address. -// Be careful when wrap around KeepAliveListener with another Listener if TLSInfo is not nil. -// Some pkgs (like go/http) might expect Listener to return TLSConn type to start TLS handshake. -// http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html -func NewKeepAliveListener(l net.Listener, scheme string, tlscfg *tls.Config) (net.Listener, error) { - if scheme == "https" { - if tlscfg == nil { - return nil, fmt.Errorf("cannot listen on TLS for given listener: KeyFile and CertFile are not presented") - } - return newTLSKeepaliveListener(l, tlscfg), nil - } - - return &keepaliveListener{ - Listener: l, - }, nil -} - -type keepaliveListener struct{ net.Listener } - -func (kln *keepaliveListener) Accept() (net.Conn, error) { - c, err := kln.Listener.Accept() - if err != nil { - return nil, err - } - kac := c.(keepAliveConn) - // detection time: tcp_keepalive_time + tcp_keepalive_probes + tcp_keepalive_intvl - // default on linux: 30 + 8 * 30 - // default on osx: 30 + 8 * 75 - kac.SetKeepAlive(true) - kac.SetKeepAlivePeriod(30 * time.Second) - return c, nil -} - -// A tlsKeepaliveListener implements a network listener (net.Listener) for TLS connections. -type tlsKeepaliveListener struct { - net.Listener - config *tls.Config -} - -// Accept waits for and returns the next incoming TLS connection. -// The returned connection c is a *tls.Conn. -func (l *tlsKeepaliveListener) Accept() (c net.Conn, err error) { - c, err = l.Listener.Accept() - if err != nil { - return - } - kac := c.(keepAliveConn) - // detection time: tcp_keepalive_time + tcp_keepalive_probes + tcp_keepalive_intvl - // default on linux: 30 + 8 * 30 - // default on osx: 30 + 8 * 75 - kac.SetKeepAlive(true) - kac.SetKeepAlivePeriod(30 * time.Second) - c = tls.Server(c, l.config) - return c, nil -} - -// NewListener creates a Listener which accepts connections from an inner -// Listener and wraps each connection with Server. -// The configuration config must be non-nil and must have -// at least one certificate. -func newTLSKeepaliveListener(inner net.Listener, config *tls.Config) net.Listener { - l := &tlsKeepaliveListener{} - l.Listener = inner - l.config = config - return l -} diff --git a/vendor/github.com/coreos/etcd/pkg/transport/limit_listen.go b/vendor/github.com/coreos/etcd/pkg/transport/limit_listen.go deleted file mode 100644 index 930c542066f8..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/transport/limit_listen.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2013 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package transport provides network utility functions, complementing the more -// common ones in the net package. -package transport - -import ( - "errors" - "net" - "sync" - "time" -) - -var ( - ErrNotTCP = errors.New("only tcp connections have keepalive") -) - -// LimitListener returns a Listener that accepts at most n simultaneous -// connections from the provided Listener. -func LimitListener(l net.Listener, n int) net.Listener { - return &limitListener{l, make(chan struct{}, n)} -} - -type limitListener struct { - net.Listener - sem chan struct{} -} - -func (l *limitListener) acquire() { l.sem <- struct{}{} } -func (l *limitListener) release() { <-l.sem } - -func (l *limitListener) Accept() (net.Conn, error) { - l.acquire() - c, err := l.Listener.Accept() - if err != nil { - l.release() - return nil, err - } - return &limitListenerConn{Conn: c, release: l.release}, nil -} - -type limitListenerConn struct { - net.Conn - releaseOnce sync.Once - release func() -} - -func (l *limitListenerConn) Close() error { - err := l.Conn.Close() - l.releaseOnce.Do(l.release) - return err -} - -func (l *limitListenerConn) SetKeepAlive(doKeepAlive bool) error { - tcpc, ok := l.Conn.(*net.TCPConn) - if !ok { - return ErrNotTCP - } - return tcpc.SetKeepAlive(doKeepAlive) -} - -func (l *limitListenerConn) SetKeepAlivePeriod(d time.Duration) error { - tcpc, ok := l.Conn.(*net.TCPConn) - if !ok { - return ErrNotTCP - } - return tcpc.SetKeepAlivePeriod(d) -} diff --git a/vendor/github.com/coreos/etcd/pkg/transport/listener.go b/vendor/github.com/coreos/etcd/pkg/transport/listener.go deleted file mode 100644 index 48655063f6f2..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/transport/listener.go +++ /dev/null @@ -1,289 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "crypto/ecdsa" - "crypto/elliptic" - "crypto/rand" - "crypto/tls" - "crypto/x509" - "crypto/x509/pkix" - "encoding/pem" - "errors" - "fmt" - "math/big" - "net" - "os" - "path/filepath" - "strings" - "time" - - "github.com/coreos/etcd/pkg/tlsutil" -) - -func NewListener(addr, scheme string, tlsinfo *TLSInfo) (l net.Listener, err error) { - if l, err = newListener(addr, scheme); err != nil { - return nil, err - } - return wrapTLS(addr, scheme, tlsinfo, l) -} - -func newListener(addr string, scheme string) (net.Listener, error) { - if scheme == "unix" || scheme == "unixs" { - // unix sockets via unix://laddr - return NewUnixListener(addr) - } - return net.Listen("tcp", addr) -} - -func wrapTLS(addr, scheme string, tlsinfo *TLSInfo, l net.Listener) (net.Listener, error) { - if scheme != "https" && scheme != "unixs" { - return l, nil - } - return newTLSListener(l, tlsinfo, checkSAN) -} - -type TLSInfo struct { - CertFile string - KeyFile string - CAFile string // TODO: deprecate this in v4 - TrustedCAFile string - ClientCertAuth bool - CRLFile string - InsecureSkipVerify bool - - // ServerName ensures the cert matches the given host in case of discovery / virtual hosting - ServerName string - - // HandshakeFailure is optionally called when a connection fails to handshake. The - // connection will be closed immediately afterwards. - HandshakeFailure func(*tls.Conn, error) - - // CipherSuites is a list of supported cipher suites. - // If empty, Go auto-populates it by default. - // Note that cipher suites are prioritized in the given order. - CipherSuites []uint16 - - selfCert bool - - // parseFunc exists to simplify testing. Typically, parseFunc - // should be left nil. In that case, tls.X509KeyPair will be used. - parseFunc func([]byte, []byte) (tls.Certificate, error) - - // AllowedCN is a CN which must be provided by a client. - AllowedCN string -} - -func (info TLSInfo) String() string { - return fmt.Sprintf("cert = %s, key = %s, ca = %s, trusted-ca = %s, client-cert-auth = %v, crl-file = %s", info.CertFile, info.KeyFile, info.CAFile, info.TrustedCAFile, info.ClientCertAuth, info.CRLFile) -} - -func (info TLSInfo) Empty() bool { - return info.CertFile == "" && info.KeyFile == "" -} - -func SelfCert(dirpath string, hosts []string) (info TLSInfo, err error) { - if err = os.MkdirAll(dirpath, 0700); err != nil { - return - } - - certPath := filepath.Join(dirpath, "cert.pem") - keyPath := filepath.Join(dirpath, "key.pem") - _, errcert := os.Stat(certPath) - _, errkey := os.Stat(keyPath) - if errcert == nil && errkey == nil { - info.CertFile = certPath - info.KeyFile = keyPath - info.selfCert = true - return - } - - serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) - serialNumber, err := rand.Int(rand.Reader, serialNumberLimit) - if err != nil { - return - } - - tmpl := x509.Certificate{ - SerialNumber: serialNumber, - Subject: pkix.Name{Organization: []string{"etcd"}}, - NotBefore: time.Now(), - NotAfter: time.Now().Add(365 * (24 * time.Hour)), - - KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, - ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, - BasicConstraintsValid: true, - } - - for _, host := range hosts { - h, _, _ := net.SplitHostPort(host) - if ip := net.ParseIP(h); ip != nil { - tmpl.IPAddresses = append(tmpl.IPAddresses, ip) - } else { - tmpl.DNSNames = append(tmpl.DNSNames, h) - } - } - - priv, err := ecdsa.GenerateKey(elliptic.P521(), rand.Reader) - if err != nil { - return - } - - derBytes, err := x509.CreateCertificate(rand.Reader, &tmpl, &tmpl, &priv.PublicKey, priv) - if err != nil { - return - } - - certOut, err := os.Create(certPath) - if err != nil { - return - } - pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}) - certOut.Close() - - b, err := x509.MarshalECPrivateKey(priv) - if err != nil { - return - } - keyOut, err := os.OpenFile(keyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) - if err != nil { - return - } - pem.Encode(keyOut, &pem.Block{Type: "EC PRIVATE KEY", Bytes: b}) - keyOut.Close() - - return SelfCert(dirpath, hosts) -} - -func (info TLSInfo) baseConfig() (*tls.Config, error) { - if info.KeyFile == "" || info.CertFile == "" { - return nil, fmt.Errorf("KeyFile and CertFile must both be present[key: %v, cert: %v]", info.KeyFile, info.CertFile) - } - - _, err := tlsutil.NewCert(info.CertFile, info.KeyFile, info.parseFunc) - if err != nil { - return nil, err - } - - cfg := &tls.Config{ - MinVersion: tls.VersionTLS12, - ServerName: info.ServerName, - } - - if len(info.CipherSuites) > 0 { - cfg.CipherSuites = info.CipherSuites - } - - if info.AllowedCN != "" { - cfg.VerifyPeerCertificate = func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error { - for _, chains := range verifiedChains { - if len(chains) != 0 { - if info.AllowedCN == chains[0].Subject.CommonName { - return nil - } - } - } - return errors.New("CommonName authentication failed") - } - } - - // this only reloads certs when there's a client request - // TODO: support server-side refresh (e.g. inotify, SIGHUP), caching - cfg.GetCertificate = func(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error) { - return tlsutil.NewCert(info.CertFile, info.KeyFile, info.parseFunc) - } - cfg.GetClientCertificate = func(unused *tls.CertificateRequestInfo) (*tls.Certificate, error) { - return tlsutil.NewCert(info.CertFile, info.KeyFile, info.parseFunc) - } - return cfg, nil -} - -// cafiles returns a list of CA file paths. -func (info TLSInfo) cafiles() []string { - cs := make([]string, 0) - if info.CAFile != "" { - cs = append(cs, info.CAFile) - } - if info.TrustedCAFile != "" { - cs = append(cs, info.TrustedCAFile) - } - return cs -} - -// ServerConfig generates a tls.Config object for use by an HTTP server. -func (info TLSInfo) ServerConfig() (*tls.Config, error) { - cfg, err := info.baseConfig() - if err != nil { - return nil, err - } - - cfg.ClientAuth = tls.NoClientCert - if info.CAFile != "" || info.ClientCertAuth { - cfg.ClientAuth = tls.RequireAndVerifyClientCert - } - - CAFiles := info.cafiles() - if len(CAFiles) > 0 { - cp, err := tlsutil.NewCertPool(CAFiles) - if err != nil { - return nil, err - } - cfg.ClientCAs = cp - } - - // "h2" NextProtos is necessary for enabling HTTP2 for go's HTTP server - cfg.NextProtos = []string{"h2"} - - return cfg, nil -} - -// ClientConfig generates a tls.Config object for use by an HTTP client. -func (info TLSInfo) ClientConfig() (*tls.Config, error) { - var cfg *tls.Config - var err error - - if !info.Empty() { - cfg, err = info.baseConfig() - if err != nil { - return nil, err - } - } else { - cfg = &tls.Config{ServerName: info.ServerName} - } - cfg.InsecureSkipVerify = info.InsecureSkipVerify - - CAFiles := info.cafiles() - if len(CAFiles) > 0 { - cfg.RootCAs, err = tlsutil.NewCertPool(CAFiles) - if err != nil { - return nil, err - } - } - - if info.selfCert { - cfg.InsecureSkipVerify = true - } - return cfg, nil -} - -// IsClosedConnError returns true if the error is from closing listener, cmux. -// copied from golang.org/x/net/http2/http2.go -func IsClosedConnError(err error) bool { - // 'use of closed network connection' (Go <=1.8) - // 'use of closed file or network connection' (Go >1.8, internal/poll.ErrClosing) - // 'mux: listener closed' (cmux.ErrListenerClosed) - return err != nil && strings.Contains(err.Error(), "closed") -} diff --git a/vendor/github.com/coreos/etcd/pkg/transport/listener_tls.go b/vendor/github.com/coreos/etcd/pkg/transport/listener_tls.go deleted file mode 100644 index 6f1600945cc6..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/transport/listener_tls.go +++ /dev/null @@ -1,272 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "context" - "crypto/tls" - "crypto/x509" - "fmt" - "io/ioutil" - "net" - "strings" - "sync" -) - -// tlsListener overrides a TLS listener so it will reject client -// certificates with insufficient SAN credentials or CRL revoked -// certificates. -type tlsListener struct { - net.Listener - connc chan net.Conn - donec chan struct{} - err error - handshakeFailure func(*tls.Conn, error) - check tlsCheckFunc -} - -type tlsCheckFunc func(context.Context, *tls.Conn) error - -// NewTLSListener handshakes TLS connections and performs optional CRL checking. -func NewTLSListener(l net.Listener, tlsinfo *TLSInfo) (net.Listener, error) { - check := func(context.Context, *tls.Conn) error { return nil } - return newTLSListener(l, tlsinfo, check) -} - -func newTLSListener(l net.Listener, tlsinfo *TLSInfo, check tlsCheckFunc) (net.Listener, error) { - if tlsinfo == nil || tlsinfo.Empty() { - l.Close() - return nil, fmt.Errorf("cannot listen on TLS for %s: KeyFile and CertFile are not presented", l.Addr().String()) - } - tlscfg, err := tlsinfo.ServerConfig() - if err != nil { - return nil, err - } - - hf := tlsinfo.HandshakeFailure - if hf == nil { - hf = func(*tls.Conn, error) {} - } - - if len(tlsinfo.CRLFile) > 0 { - prevCheck := check - check = func(ctx context.Context, tlsConn *tls.Conn) error { - if err := prevCheck(ctx, tlsConn); err != nil { - return err - } - st := tlsConn.ConnectionState() - if certs := st.PeerCertificates; len(certs) > 0 { - return checkCRL(tlsinfo.CRLFile, certs) - } - return nil - } - } - - tlsl := &tlsListener{ - Listener: tls.NewListener(l, tlscfg), - connc: make(chan net.Conn), - donec: make(chan struct{}), - handshakeFailure: hf, - check: check, - } - go tlsl.acceptLoop() - return tlsl, nil -} - -func (l *tlsListener) Accept() (net.Conn, error) { - select { - case conn := <-l.connc: - return conn, nil - case <-l.donec: - return nil, l.err - } -} - -func checkSAN(ctx context.Context, tlsConn *tls.Conn) error { - st := tlsConn.ConnectionState() - if certs := st.PeerCertificates; len(certs) > 0 { - addr := tlsConn.RemoteAddr().String() - return checkCertSAN(ctx, certs[0], addr) - } - return nil -} - -// acceptLoop launches each TLS handshake in a separate goroutine -// to prevent a hanging TLS connection from blocking other connections. -func (l *tlsListener) acceptLoop() { - var wg sync.WaitGroup - var pendingMu sync.Mutex - - pending := make(map[net.Conn]struct{}) - ctx, cancel := context.WithCancel(context.Background()) - defer func() { - cancel() - pendingMu.Lock() - for c := range pending { - c.Close() - } - pendingMu.Unlock() - wg.Wait() - close(l.donec) - }() - - for { - conn, err := l.Listener.Accept() - if err != nil { - l.err = err - return - } - - pendingMu.Lock() - pending[conn] = struct{}{} - pendingMu.Unlock() - - wg.Add(1) - go func() { - defer func() { - if conn != nil { - conn.Close() - } - wg.Done() - }() - - tlsConn := conn.(*tls.Conn) - herr := tlsConn.Handshake() - pendingMu.Lock() - delete(pending, conn) - pendingMu.Unlock() - - if herr != nil { - l.handshakeFailure(tlsConn, herr) - return - } - if err := l.check(ctx, tlsConn); err != nil { - l.handshakeFailure(tlsConn, err) - return - } - - select { - case l.connc <- tlsConn: - conn = nil - case <-ctx.Done(): - } - }() - } -} - -func checkCRL(crlPath string, cert []*x509.Certificate) error { - // TODO: cache - crlBytes, err := ioutil.ReadFile(crlPath) - if err != nil { - return err - } - certList, err := x509.ParseCRL(crlBytes) - if err != nil { - return err - } - revokedSerials := make(map[string]struct{}) - for _, rc := range certList.TBSCertList.RevokedCertificates { - revokedSerials[string(rc.SerialNumber.Bytes())] = struct{}{} - } - for _, c := range cert { - serial := string(c.SerialNumber.Bytes()) - if _, ok := revokedSerials[serial]; ok { - return fmt.Errorf("transport: certificate serial %x revoked", serial) - } - } - return nil -} - -func checkCertSAN(ctx context.Context, cert *x509.Certificate, remoteAddr string) error { - if len(cert.IPAddresses) == 0 && len(cert.DNSNames) == 0 { - return nil - } - h, _, herr := net.SplitHostPort(remoteAddr) - if herr != nil { - return herr - } - if len(cert.IPAddresses) > 0 { - cerr := cert.VerifyHostname(h) - if cerr == nil { - return nil - } - if len(cert.DNSNames) == 0 { - return cerr - } - } - if len(cert.DNSNames) > 0 { - ok, err := isHostInDNS(ctx, h, cert.DNSNames) - if ok { - return nil - } - errStr := "" - if err != nil { - errStr = " (" + err.Error() + ")" - } - return fmt.Errorf("tls: %q does not match any of DNSNames %q"+errStr, h, cert.DNSNames) - } - return nil -} - -func isHostInDNS(ctx context.Context, host string, dnsNames []string) (ok bool, err error) { - // reverse lookup - wildcards, names := []string{}, []string{} - for _, dns := range dnsNames { - if strings.HasPrefix(dns, "*.") { - wildcards = append(wildcards, dns[1:]) - } else { - names = append(names, dns) - } - } - lnames, lerr := net.DefaultResolver.LookupAddr(ctx, host) - for _, name := range lnames { - // strip trailing '.' from PTR record - if name[len(name)-1] == '.' { - name = name[:len(name)-1] - } - for _, wc := range wildcards { - if strings.HasSuffix(name, wc) { - return true, nil - } - } - for _, n := range names { - if n == name { - return true, nil - } - } - } - err = lerr - - // forward lookup - for _, dns := range names { - addrs, lerr := net.DefaultResolver.LookupHost(ctx, dns) - if lerr != nil { - err = lerr - continue - } - for _, addr := range addrs { - if addr == host { - return true, nil - } - } - } - return false, err -} - -func (l *tlsListener) Close() error { - err := l.Listener.Close() - <-l.donec - return err -} diff --git a/vendor/github.com/coreos/etcd/pkg/transport/timeout_conn.go b/vendor/github.com/coreos/etcd/pkg/transport/timeout_conn.go deleted file mode 100644 index 7e8c02030fed..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/transport/timeout_conn.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "net" - "time" -) - -type timeoutConn struct { - net.Conn - wtimeoutd time.Duration - rdtimeoutd time.Duration -} - -func (c timeoutConn) Write(b []byte) (n int, err error) { - if c.wtimeoutd > 0 { - if err := c.SetWriteDeadline(time.Now().Add(c.wtimeoutd)); err != nil { - return 0, err - } - } - return c.Conn.Write(b) -} - -func (c timeoutConn) Read(b []byte) (n int, err error) { - if c.rdtimeoutd > 0 { - if err := c.SetReadDeadline(time.Now().Add(c.rdtimeoutd)); err != nil { - return 0, err - } - } - return c.Conn.Read(b) -} diff --git a/vendor/github.com/coreos/etcd/pkg/transport/timeout_dialer.go b/vendor/github.com/coreos/etcd/pkg/transport/timeout_dialer.go deleted file mode 100644 index 6ae39ecfc9b3..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/transport/timeout_dialer.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "net" - "time" -) - -type rwTimeoutDialer struct { - wtimeoutd time.Duration - rdtimeoutd time.Duration - net.Dialer -} - -func (d *rwTimeoutDialer) Dial(network, address string) (net.Conn, error) { - conn, err := d.Dialer.Dial(network, address) - tconn := &timeoutConn{ - rdtimeoutd: d.rdtimeoutd, - wtimeoutd: d.wtimeoutd, - Conn: conn, - } - return tconn, err -} diff --git a/vendor/github.com/coreos/etcd/pkg/transport/timeout_listener.go b/vendor/github.com/coreos/etcd/pkg/transport/timeout_listener.go deleted file mode 100644 index b35e04955bb0..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/transport/timeout_listener.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "net" - "time" -) - -// NewTimeoutListener returns a listener that listens on the given address. -// If read/write on the accepted connection blocks longer than its time limit, -// it will return timeout error. -func NewTimeoutListener(addr string, scheme string, tlsinfo *TLSInfo, rdtimeoutd, wtimeoutd time.Duration) (net.Listener, error) { - ln, err := newListener(addr, scheme) - if err != nil { - return nil, err - } - ln = &rwTimeoutListener{ - Listener: ln, - rdtimeoutd: rdtimeoutd, - wtimeoutd: wtimeoutd, - } - if ln, err = wrapTLS(addr, scheme, tlsinfo, ln); err != nil { - return nil, err - } - return ln, nil -} - -type rwTimeoutListener struct { - net.Listener - wtimeoutd time.Duration - rdtimeoutd time.Duration -} - -func (rwln *rwTimeoutListener) Accept() (net.Conn, error) { - c, err := rwln.Listener.Accept() - if err != nil { - return nil, err - } - return timeoutConn{ - Conn: c, - wtimeoutd: rwln.wtimeoutd, - rdtimeoutd: rwln.rdtimeoutd, - }, nil -} diff --git a/vendor/github.com/coreos/etcd/pkg/transport/timeout_transport.go b/vendor/github.com/coreos/etcd/pkg/transport/timeout_transport.go deleted file mode 100644 index ea16b4c0f869..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/transport/timeout_transport.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "net" - "net/http" - "time" -) - -// NewTimeoutTransport returns a transport created using the given TLS info. -// If read/write on the created connection blocks longer than its time limit, -// it will return timeout error. -// If read/write timeout is set, transport will not be able to reuse connection. -func NewTimeoutTransport(info TLSInfo, dialtimeoutd, rdtimeoutd, wtimeoutd time.Duration) (*http.Transport, error) { - tr, err := NewTransport(info, dialtimeoutd) - if err != nil { - return nil, err - } - - if rdtimeoutd != 0 || wtimeoutd != 0 { - // the timed out connection will timeout soon after it is idle. - // it should not be put back to http transport as an idle connection for future usage. - tr.MaxIdleConnsPerHost = -1 - } else { - // allow more idle connections between peers to avoid unnecessary port allocation. - tr.MaxIdleConnsPerHost = 1024 - } - - tr.Dial = (&rwTimeoutDialer{ - Dialer: net.Dialer{ - Timeout: dialtimeoutd, - KeepAlive: 30 * time.Second, - }, - rdtimeoutd: rdtimeoutd, - wtimeoutd: wtimeoutd, - }).Dial - return tr, nil -} diff --git a/vendor/github.com/coreos/etcd/pkg/transport/tls.go b/vendor/github.com/coreos/etcd/pkg/transport/tls.go deleted file mode 100644 index 62fe0d385195..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/transport/tls.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "fmt" - "strings" - "time" -) - -// ValidateSecureEndpoints scans the given endpoints against tls info, returning only those -// endpoints that could be validated as secure. -func ValidateSecureEndpoints(tlsInfo TLSInfo, eps []string) ([]string, error) { - t, err := NewTransport(tlsInfo, 5*time.Second) - if err != nil { - return nil, err - } - var errs []string - var endpoints []string - for _, ep := range eps { - if !strings.HasPrefix(ep, "https://") { - errs = append(errs, fmt.Sprintf("%q is insecure", ep)) - continue - } - conn, cerr := t.Dial("tcp", ep[len("https://"):]) - if cerr != nil { - errs = append(errs, fmt.Sprintf("%q failed to dial (%v)", ep, cerr)) - continue - } - conn.Close() - endpoints = append(endpoints, ep) - } - if len(errs) != 0 { - err = fmt.Errorf("%s", strings.Join(errs, ",")) - } - return endpoints, err -} diff --git a/vendor/github.com/coreos/etcd/pkg/transport/transport.go b/vendor/github.com/coreos/etcd/pkg/transport/transport.go deleted file mode 100644 index 4a7fe69d2e19..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/transport/transport.go +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "net" - "net/http" - "strings" - "time" -) - -type unixTransport struct{ *http.Transport } - -func NewTransport(info TLSInfo, dialtimeoutd time.Duration) (*http.Transport, error) { - cfg, err := info.ClientConfig() - if err != nil { - return nil, err - } - - t := &http.Transport{ - Proxy: http.ProxyFromEnvironment, - Dial: (&net.Dialer{ - Timeout: dialtimeoutd, - // value taken from http.DefaultTransport - KeepAlive: 30 * time.Second, - }).Dial, - // value taken from http.DefaultTransport - TLSHandshakeTimeout: 10 * time.Second, - TLSClientConfig: cfg, - } - - dialer := (&net.Dialer{ - Timeout: dialtimeoutd, - KeepAlive: 30 * time.Second, - }) - dial := func(net, addr string) (net.Conn, error) { - return dialer.Dial("unix", addr) - } - - tu := &http.Transport{ - Proxy: http.ProxyFromEnvironment, - Dial: dial, - TLSHandshakeTimeout: 10 * time.Second, - TLSClientConfig: cfg, - } - ut := &unixTransport{tu} - - t.RegisterProtocol("unix", ut) - t.RegisterProtocol("unixs", ut) - - return t, nil -} - -func (urt *unixTransport) RoundTrip(req *http.Request) (*http.Response, error) { - url := *req.URL - req.URL = &url - req.URL.Scheme = strings.Replace(req.URL.Scheme, "unix", "http", 1) - return urt.Transport.RoundTrip(req) -} diff --git a/vendor/github.com/coreos/etcd/pkg/transport/unix_listener.go b/vendor/github.com/coreos/etcd/pkg/transport/unix_listener.go deleted file mode 100644 index 123e2036f0f0..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/transport/unix_listener.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "net" - "os" -) - -type unixListener struct{ net.Listener } - -func NewUnixListener(addr string) (net.Listener, error) { - if err := os.Remove(addr); err != nil && !os.IsNotExist(err) { - return nil, err - } - l, err := net.Listen("unix", addr) - if err != nil { - return nil, err - } - return &unixListener{l}, nil -} - -func (ul *unixListener) Close() error { - if err := os.Remove(ul.Addr().String()); err != nil && !os.IsNotExist(err) { - return err - } - return ul.Listener.Close() -} diff --git a/vendor/github.com/coreos/etcd/pkg/types/doc.go b/vendor/github.com/coreos/etcd/pkg/types/doc.go deleted file mode 100644 index de8ef0bd7126..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/types/doc.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package types declares various data types and implements type-checking -// functions. -package types diff --git a/vendor/github.com/coreos/etcd/pkg/types/id.go b/vendor/github.com/coreos/etcd/pkg/types/id.go deleted file mode 100644 index 1b042d9ce652..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/types/id.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package types - -import ( - "strconv" -) - -// ID represents a generic identifier which is canonically -// stored as a uint64 but is typically represented as a -// base-16 string for input/output -type ID uint64 - -func (i ID) String() string { - return strconv.FormatUint(uint64(i), 16) -} - -// IDFromString attempts to create an ID from a base-16 string. -func IDFromString(s string) (ID, error) { - i, err := strconv.ParseUint(s, 16, 64) - return ID(i), err -} - -// IDSlice implements the sort interface -type IDSlice []ID - -func (p IDSlice) Len() int { return len(p) } -func (p IDSlice) Less(i, j int) bool { return uint64(p[i]) < uint64(p[j]) } -func (p IDSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } diff --git a/vendor/github.com/coreos/etcd/pkg/types/set.go b/vendor/github.com/coreos/etcd/pkg/types/set.go deleted file mode 100644 index c111b0c0c0bb..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/types/set.go +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package types - -import ( - "reflect" - "sort" - "sync" -) - -type Set interface { - Add(string) - Remove(string) - Contains(string) bool - Equals(Set) bool - Length() int - Values() []string - Copy() Set - Sub(Set) Set -} - -func NewUnsafeSet(values ...string) *unsafeSet { - set := &unsafeSet{make(map[string]struct{})} - for _, v := range values { - set.Add(v) - } - return set -} - -func NewThreadsafeSet(values ...string) *tsafeSet { - us := NewUnsafeSet(values...) - return &tsafeSet{us, sync.RWMutex{}} -} - -type unsafeSet struct { - d map[string]struct{} -} - -// Add adds a new value to the set (no-op if the value is already present) -func (us *unsafeSet) Add(value string) { - us.d[value] = struct{}{} -} - -// Remove removes the given value from the set -func (us *unsafeSet) Remove(value string) { - delete(us.d, value) -} - -// Contains returns whether the set contains the given value -func (us *unsafeSet) Contains(value string) (exists bool) { - _, exists = us.d[value] - return exists -} - -// ContainsAll returns whether the set contains all given values -func (us *unsafeSet) ContainsAll(values []string) bool { - for _, s := range values { - if !us.Contains(s) { - return false - } - } - return true -} - -// Equals returns whether the contents of two sets are identical -func (us *unsafeSet) Equals(other Set) bool { - v1 := sort.StringSlice(us.Values()) - v2 := sort.StringSlice(other.Values()) - v1.Sort() - v2.Sort() - return reflect.DeepEqual(v1, v2) -} - -// Length returns the number of elements in the set -func (us *unsafeSet) Length() int { - return len(us.d) -} - -// Values returns the values of the Set in an unspecified order. -func (us *unsafeSet) Values() (values []string) { - values = make([]string, 0) - for val := range us.d { - values = append(values, val) - } - return values -} - -// Copy creates a new Set containing the values of the first -func (us *unsafeSet) Copy() Set { - cp := NewUnsafeSet() - for val := range us.d { - cp.Add(val) - } - - return cp -} - -// Sub removes all elements in other from the set -func (us *unsafeSet) Sub(other Set) Set { - oValues := other.Values() - result := us.Copy().(*unsafeSet) - - for _, val := range oValues { - if _, ok := result.d[val]; !ok { - continue - } - delete(result.d, val) - } - - return result -} - -type tsafeSet struct { - us *unsafeSet - m sync.RWMutex -} - -func (ts *tsafeSet) Add(value string) { - ts.m.Lock() - defer ts.m.Unlock() - ts.us.Add(value) -} - -func (ts *tsafeSet) Remove(value string) { - ts.m.Lock() - defer ts.m.Unlock() - ts.us.Remove(value) -} - -func (ts *tsafeSet) Contains(value string) (exists bool) { - ts.m.RLock() - defer ts.m.RUnlock() - return ts.us.Contains(value) -} - -func (ts *tsafeSet) Equals(other Set) bool { - ts.m.RLock() - defer ts.m.RUnlock() - return ts.us.Equals(other) -} - -func (ts *tsafeSet) Length() int { - ts.m.RLock() - defer ts.m.RUnlock() - return ts.us.Length() -} - -func (ts *tsafeSet) Values() (values []string) { - ts.m.RLock() - defer ts.m.RUnlock() - return ts.us.Values() -} - -func (ts *tsafeSet) Copy() Set { - ts.m.RLock() - defer ts.m.RUnlock() - usResult := ts.us.Copy().(*unsafeSet) - return &tsafeSet{usResult, sync.RWMutex{}} -} - -func (ts *tsafeSet) Sub(other Set) Set { - ts.m.RLock() - defer ts.m.RUnlock() - usResult := ts.us.Sub(other).(*unsafeSet) - return &tsafeSet{usResult, sync.RWMutex{}} -} diff --git a/vendor/github.com/coreos/etcd/pkg/types/slice.go b/vendor/github.com/coreos/etcd/pkg/types/slice.go deleted file mode 100644 index 0dd9ca798ae4..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/types/slice.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package types - -// Uint64Slice implements sort interface -type Uint64Slice []uint64 - -func (p Uint64Slice) Len() int { return len(p) } -func (p Uint64Slice) Less(i, j int) bool { return p[i] < p[j] } -func (p Uint64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } diff --git a/vendor/github.com/coreos/etcd/pkg/types/urls.go b/vendor/github.com/coreos/etcd/pkg/types/urls.go deleted file mode 100644 index 9e5d03ff6457..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/types/urls.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package types - -import ( - "errors" - "fmt" - "net" - "net/url" - "sort" - "strings" -) - -type URLs []url.URL - -func NewURLs(strs []string) (URLs, error) { - all := make([]url.URL, len(strs)) - if len(all) == 0 { - return nil, errors.New("no valid URLs given") - } - for i, in := range strs { - in = strings.TrimSpace(in) - u, err := url.Parse(in) - if err != nil { - return nil, err - } - if u.Scheme != "http" && u.Scheme != "https" && u.Scheme != "unix" && u.Scheme != "unixs" { - return nil, fmt.Errorf("URL scheme must be http, https, unix, or unixs: %s", in) - } - if _, _, err := net.SplitHostPort(u.Host); err != nil { - return nil, fmt.Errorf(`URL address does not have the form "host:port": %s`, in) - } - if u.Path != "" { - return nil, fmt.Errorf("URL must not contain a path: %s", in) - } - all[i] = *u - } - us := URLs(all) - us.Sort() - - return us, nil -} - -func MustNewURLs(strs []string) URLs { - urls, err := NewURLs(strs) - if err != nil { - panic(err) - } - return urls -} - -func (us URLs) String() string { - return strings.Join(us.StringSlice(), ",") -} - -func (us *URLs) Sort() { - sort.Sort(us) -} -func (us URLs) Len() int { return len(us) } -func (us URLs) Less(i, j int) bool { return us[i].String() < us[j].String() } -func (us URLs) Swap(i, j int) { us[i], us[j] = us[j], us[i] } - -func (us URLs) StringSlice() []string { - out := make([]string, len(us)) - for i := range us { - out[i] = us[i].String() - } - - return out -} diff --git a/vendor/github.com/coreos/etcd/pkg/types/urlsmap.go b/vendor/github.com/coreos/etcd/pkg/types/urlsmap.go deleted file mode 100644 index 47690cc381a3..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/types/urlsmap.go +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package types - -import ( - "fmt" - "sort" - "strings" -) - -// URLsMap is a map from a name to its URLs. -type URLsMap map[string]URLs - -// NewURLsMap returns a URLsMap instantiated from the given string, -// which consists of discovery-formatted names-to-URLs, like: -// mach0=http://1.1.1.1:2380,mach0=http://2.2.2.2::2380,mach1=http://3.3.3.3:2380,mach2=http://4.4.4.4:2380 -func NewURLsMap(s string) (URLsMap, error) { - m := parse(s) - - cl := URLsMap{} - for name, urls := range m { - us, err := NewURLs(urls) - if err != nil { - return nil, err - } - cl[name] = us - } - return cl, nil -} - -// NewURLsMapFromStringMap takes a map of strings and returns a URLsMap. The -// string values in the map can be multiple values separated by the sep string. -func NewURLsMapFromStringMap(m map[string]string, sep string) (URLsMap, error) { - var err error - um := URLsMap{} - for k, v := range m { - um[k], err = NewURLs(strings.Split(v, sep)) - if err != nil { - return nil, err - } - } - return um, nil -} - -// String turns URLsMap into discovery-formatted name-to-URLs sorted by name. -func (c URLsMap) String() string { - var pairs []string - for name, urls := range c { - for _, url := range urls { - pairs = append(pairs, fmt.Sprintf("%s=%s", name, url.String())) - } - } - sort.Strings(pairs) - return strings.Join(pairs, ",") -} - -// URLs returns a list of all URLs. -// The returned list is sorted in ascending lexicographical order. -func (c URLsMap) URLs() []string { - var urls []string - for _, us := range c { - for _, u := range us { - urls = append(urls, u.String()) - } - } - sort.Strings(urls) - return urls -} - -// Len returns the size of URLsMap. -func (c URLsMap) Len() int { - return len(c) -} - -// parse parses the given string and returns a map listing the values specified for each key. -func parse(s string) map[string][]string { - m := make(map[string][]string) - for s != "" { - key := s - if i := strings.IndexAny(key, ","); i >= 0 { - key, s = key[:i], key[i+1:] - } else { - s = "" - } - if key == "" { - continue - } - value := "" - if i := strings.Index(key, "="); i >= 0 { - key, value = key[:i], key[i+1:] - } - m[key] = append(m[key], value) - } - return m -} diff --git a/vendor/github.com/coreos/etcd/pkg/wait/wait.go b/vendor/github.com/coreos/etcd/pkg/wait/wait.go deleted file mode 100644 index 9b1df419e292..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/wait/wait.go +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package wait provides utility functions for polling, listening using Go -// channel. -package wait - -import ( - "log" - "sync" -) - -// Wait is an interface that provides the ability to wait and trigger events that -// are associated with IDs. -type Wait interface { - // Register waits returns a chan that waits on the given ID. - // The chan will be triggered when Trigger is called with - // the same ID. - Register(id uint64) <-chan interface{} - // Trigger triggers the waiting chans with the given ID. - Trigger(id uint64, x interface{}) - IsRegistered(id uint64) bool -} - -type list struct { - l sync.RWMutex - m map[uint64]chan interface{} -} - -// New creates a Wait. -func New() Wait { - return &list{m: make(map[uint64]chan interface{})} -} - -func (w *list) Register(id uint64) <-chan interface{} { - w.l.Lock() - defer w.l.Unlock() - ch := w.m[id] - if ch == nil { - ch = make(chan interface{}, 1) - w.m[id] = ch - } else { - log.Panicf("dup id %x", id) - } - return ch -} - -func (w *list) Trigger(id uint64, x interface{}) { - w.l.Lock() - ch := w.m[id] - delete(w.m, id) - w.l.Unlock() - if ch != nil { - ch <- x - close(ch) - } -} - -func (w *list) IsRegistered(id uint64) bool { - w.l.RLock() - defer w.l.RUnlock() - _, ok := w.m[id] - return ok -} - -type waitWithResponse struct { - ch <-chan interface{} -} - -func NewWithResponse(ch <-chan interface{}) Wait { - return &waitWithResponse{ch: ch} -} - -func (w *waitWithResponse) Register(id uint64) <-chan interface{} { - return w.ch -} -func (w *waitWithResponse) Trigger(id uint64, x interface{}) {} -func (w *waitWithResponse) IsRegistered(id uint64) bool { - panic("waitWithResponse.IsRegistered() shouldn't be called") -} diff --git a/vendor/github.com/coreos/etcd/pkg/wait/wait_time.go b/vendor/github.com/coreos/etcd/pkg/wait/wait_time.go deleted file mode 100644 index 297e48a47d76..000000000000 --- a/vendor/github.com/coreos/etcd/pkg/wait/wait_time.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wait - -import "sync" - -type WaitTime interface { - // Wait returns a chan that waits on the given logical deadline. - // The chan will be triggered when Trigger is called with a - // deadline that is later than the one it is waiting for. - Wait(deadline uint64) <-chan struct{} - // Trigger triggers all the waiting chans with an earlier logical deadline. - Trigger(deadline uint64) -} - -var closec chan struct{} - -func init() { closec = make(chan struct{}); close(closec) } - -type timeList struct { - l sync.Mutex - lastTriggerDeadline uint64 - m map[uint64]chan struct{} -} - -func NewTimeList() *timeList { - return &timeList{m: make(map[uint64]chan struct{})} -} - -func (tl *timeList) Wait(deadline uint64) <-chan struct{} { - tl.l.Lock() - defer tl.l.Unlock() - if tl.lastTriggerDeadline >= deadline { - return closec - } - ch := tl.m[deadline] - if ch == nil { - ch = make(chan struct{}) - tl.m[deadline] = ch - } - return ch -} - -func (tl *timeList) Trigger(deadline uint64) { - tl.l.Lock() - defer tl.l.Unlock() - tl.lastTriggerDeadline = deadline - for t, ch := range tl.m { - if t <= deadline { - delete(tl.m, t) - close(ch) - } - } -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/auth_client_adapter.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/auth_client_adapter.go deleted file mode 100644 index 33dc91f013f9..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/auth_client_adapter.go +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - grpc "google.golang.org/grpc" -) - -type as2ac struct{ as pb.AuthServer } - -func AuthServerToAuthClient(as pb.AuthServer) pb.AuthClient { - return &as2ac{as} -} - -func (s *as2ac) AuthEnable(ctx context.Context, in *pb.AuthEnableRequest, opts ...grpc.CallOption) (*pb.AuthEnableResponse, error) { - return s.as.AuthEnable(ctx, in) -} - -func (s *as2ac) AuthDisable(ctx context.Context, in *pb.AuthDisableRequest, opts ...grpc.CallOption) (*pb.AuthDisableResponse, error) { - return s.as.AuthDisable(ctx, in) -} - -func (s *as2ac) Authenticate(ctx context.Context, in *pb.AuthenticateRequest, opts ...grpc.CallOption) (*pb.AuthenticateResponse, error) { - return s.as.Authenticate(ctx, in) -} - -func (s *as2ac) RoleAdd(ctx context.Context, in *pb.AuthRoleAddRequest, opts ...grpc.CallOption) (*pb.AuthRoleAddResponse, error) { - return s.as.RoleAdd(ctx, in) -} - -func (s *as2ac) RoleDelete(ctx context.Context, in *pb.AuthRoleDeleteRequest, opts ...grpc.CallOption) (*pb.AuthRoleDeleteResponse, error) { - return s.as.RoleDelete(ctx, in) -} - -func (s *as2ac) RoleGet(ctx context.Context, in *pb.AuthRoleGetRequest, opts ...grpc.CallOption) (*pb.AuthRoleGetResponse, error) { - return s.as.RoleGet(ctx, in) -} - -func (s *as2ac) RoleList(ctx context.Context, in *pb.AuthRoleListRequest, opts ...grpc.CallOption) (*pb.AuthRoleListResponse, error) { - return s.as.RoleList(ctx, in) -} - -func (s *as2ac) RoleRevokePermission(ctx context.Context, in *pb.AuthRoleRevokePermissionRequest, opts ...grpc.CallOption) (*pb.AuthRoleRevokePermissionResponse, error) { - return s.as.RoleRevokePermission(ctx, in) -} - -func (s *as2ac) RoleGrantPermission(ctx context.Context, in *pb.AuthRoleGrantPermissionRequest, opts ...grpc.CallOption) (*pb.AuthRoleGrantPermissionResponse, error) { - return s.as.RoleGrantPermission(ctx, in) -} - -func (s *as2ac) UserDelete(ctx context.Context, in *pb.AuthUserDeleteRequest, opts ...grpc.CallOption) (*pb.AuthUserDeleteResponse, error) { - return s.as.UserDelete(ctx, in) -} - -func (s *as2ac) UserAdd(ctx context.Context, in *pb.AuthUserAddRequest, opts ...grpc.CallOption) (*pb.AuthUserAddResponse, error) { - return s.as.UserAdd(ctx, in) -} - -func (s *as2ac) UserGet(ctx context.Context, in *pb.AuthUserGetRequest, opts ...grpc.CallOption) (*pb.AuthUserGetResponse, error) { - return s.as.UserGet(ctx, in) -} - -func (s *as2ac) UserList(ctx context.Context, in *pb.AuthUserListRequest, opts ...grpc.CallOption) (*pb.AuthUserListResponse, error) { - return s.as.UserList(ctx, in) -} - -func (s *as2ac) UserGrantRole(ctx context.Context, in *pb.AuthUserGrantRoleRequest, opts ...grpc.CallOption) (*pb.AuthUserGrantRoleResponse, error) { - return s.as.UserGrantRole(ctx, in) -} - -func (s *as2ac) UserRevokeRole(ctx context.Context, in *pb.AuthUserRevokeRoleRequest, opts ...grpc.CallOption) (*pb.AuthUserRevokeRoleResponse, error) { - return s.as.UserRevokeRole(ctx, in) -} - -func (s *as2ac) UserChangePassword(ctx context.Context, in *pb.AuthUserChangePasswordRequest, opts ...grpc.CallOption) (*pb.AuthUserChangePasswordResponse, error) { - return s.as.UserChangePassword(ctx, in) -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/chan_stream.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/chan_stream.go deleted file mode 100644 index 82e34119311f..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/chan_stream.go +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - "google.golang.org/grpc" - "google.golang.org/grpc/metadata" -) - -// chanServerStream implements grpc.ServerStream with a chanStream -type chanServerStream struct { - headerc chan<- metadata.MD - trailerc chan<- metadata.MD - grpc.Stream - - headers []metadata.MD -} - -func (ss *chanServerStream) SendHeader(md metadata.MD) error { - if ss.headerc == nil { - return errAlreadySentHeader - } - outmd := make(map[string][]string) - for _, h := range append(ss.headers, md) { - for k, v := range h { - outmd[k] = v - } - } - select { - case ss.headerc <- outmd: - ss.headerc = nil - ss.headers = nil - return nil - case <-ss.Context().Done(): - } - return ss.Context().Err() -} - -func (ss *chanServerStream) SetHeader(md metadata.MD) error { - if ss.headerc == nil { - return errAlreadySentHeader - } - ss.headers = append(ss.headers, md) - return nil -} - -func (ss *chanServerStream) SetTrailer(md metadata.MD) { - ss.trailerc <- md -} - -// chanClientStream implements grpc.ClientStream with a chanStream -type chanClientStream struct { - headerc <-chan metadata.MD - trailerc <-chan metadata.MD - *chanStream -} - -func (cs *chanClientStream) Header() (metadata.MD, error) { - select { - case md := <-cs.headerc: - return md, nil - case <-cs.Context().Done(): - } - return nil, cs.Context().Err() -} - -func (cs *chanClientStream) Trailer() metadata.MD { - select { - case md := <-cs.trailerc: - return md - case <-cs.Context().Done(): - return nil - } -} - -func (cs *chanClientStream) CloseSend() error { - close(cs.chanStream.sendc) - return nil -} - -// chanStream implements grpc.Stream using channels -type chanStream struct { - recvc <-chan interface{} - sendc chan<- interface{} - ctx context.Context - cancel context.CancelFunc -} - -func (s *chanStream) Context() context.Context { return s.ctx } - -func (s *chanStream) SendMsg(m interface{}) error { - select { - case s.sendc <- m: - if err, ok := m.(error); ok { - return err - } - return nil - case <-s.ctx.Done(): - } - return s.ctx.Err() -} - -func (s *chanStream) RecvMsg(m interface{}) error { - v := m.(*interface{}) - for { - select { - case msg, ok := <-s.recvc: - if !ok { - return grpc.ErrClientConnClosing - } - if err, ok := msg.(error); ok { - return err - } - *v = msg - return nil - case <-s.ctx.Done(): - } - if len(s.recvc) == 0 { - // prioritize any pending recv messages over canceled context - break - } - } - return s.ctx.Err() -} - -func newPipeStream(ctx context.Context, ssHandler func(chanServerStream) error) chanClientStream { - // ch1 is buffered so server can send error on close - ch1, ch2 := make(chan interface{}, 1), make(chan interface{}) - headerc, trailerc := make(chan metadata.MD, 1), make(chan metadata.MD, 1) - - cctx, ccancel := context.WithCancel(ctx) - cli := &chanStream{recvc: ch1, sendc: ch2, ctx: cctx, cancel: ccancel} - cs := chanClientStream{headerc, trailerc, cli} - - sctx, scancel := context.WithCancel(ctx) - srv := &chanStream{recvc: ch2, sendc: ch1, ctx: sctx, cancel: scancel} - ss := chanServerStream{headerc, trailerc, srv, nil} - - go func() { - if err := ssHandler(ss); err != nil { - select { - case srv.sendc <- err: - case <-sctx.Done(): - case <-cctx.Done(): - } - } - scancel() - ccancel() - }() - return cs -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/cluster_client_adapter.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/cluster_client_adapter.go deleted file mode 100644 index 6c0340998b9c..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/cluster_client_adapter.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" -) - -type cls2clc struct{ cls pb.ClusterServer } - -func ClusterServerToClusterClient(cls pb.ClusterServer) pb.ClusterClient { - return &cls2clc{cls} -} - -func (s *cls2clc) MemberList(ctx context.Context, r *pb.MemberListRequest, opts ...grpc.CallOption) (*pb.MemberListResponse, error) { - return s.cls.MemberList(ctx, r) -} - -func (s *cls2clc) MemberAdd(ctx context.Context, r *pb.MemberAddRequest, opts ...grpc.CallOption) (*pb.MemberAddResponse, error) { - return s.cls.MemberAdd(ctx, r) -} - -func (s *cls2clc) MemberUpdate(ctx context.Context, r *pb.MemberUpdateRequest, opts ...grpc.CallOption) (*pb.MemberUpdateResponse, error) { - return s.cls.MemberUpdate(ctx, r) -} - -func (s *cls2clc) MemberRemove(ctx context.Context, r *pb.MemberRemoveRequest, opts ...grpc.CallOption) (*pb.MemberRemoveResponse, error) { - return s.cls.MemberRemove(ctx, r) -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/doc.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/doc.go deleted file mode 100644 index 7170be233046..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/doc.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package adapter provides gRPC adapters between client and server -// gRPC interfaces without needing to go through a gRPC connection. -package adapter diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/election_client_adapter.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/election_client_adapter.go deleted file mode 100644 index a2ebf138f3be..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/election_client_adapter.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - "github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb" - - "google.golang.org/grpc" -) - -type es2ec struct{ es v3electionpb.ElectionServer } - -func ElectionServerToElectionClient(es v3electionpb.ElectionServer) v3electionpb.ElectionClient { - return &es2ec{es} -} - -func (s *es2ec) Campaign(ctx context.Context, r *v3electionpb.CampaignRequest, opts ...grpc.CallOption) (*v3electionpb.CampaignResponse, error) { - return s.es.Campaign(ctx, r) -} - -func (s *es2ec) Proclaim(ctx context.Context, r *v3electionpb.ProclaimRequest, opts ...grpc.CallOption) (*v3electionpb.ProclaimResponse, error) { - return s.es.Proclaim(ctx, r) -} - -func (s *es2ec) Leader(ctx context.Context, r *v3electionpb.LeaderRequest, opts ...grpc.CallOption) (*v3electionpb.LeaderResponse, error) { - return s.es.Leader(ctx, r) -} - -func (s *es2ec) Resign(ctx context.Context, r *v3electionpb.ResignRequest, opts ...grpc.CallOption) (*v3electionpb.ResignResponse, error) { - return s.es.Resign(ctx, r) -} - -func (s *es2ec) Observe(ctx context.Context, in *v3electionpb.LeaderRequest, opts ...grpc.CallOption) (v3electionpb.Election_ObserveClient, error) { - cs := newPipeStream(ctx, func(ss chanServerStream) error { - return s.es.Observe(in, &es2ecServerStream{ss}) - }) - return &es2ecClientStream{cs}, nil -} - -// es2ecClientStream implements Election_ObserveClient -type es2ecClientStream struct{ chanClientStream } - -// es2ecServerStream implements Election_ObserveServer -type es2ecServerStream struct{ chanServerStream } - -func (s *es2ecClientStream) Send(rr *v3electionpb.LeaderRequest) error { - return s.SendMsg(rr) -} -func (s *es2ecClientStream) Recv() (*v3electionpb.LeaderResponse, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*v3electionpb.LeaderResponse), nil -} - -func (s *es2ecServerStream) Send(rr *v3electionpb.LeaderResponse) error { - return s.SendMsg(rr) -} -func (s *es2ecServerStream) Recv() (*v3electionpb.LeaderRequest, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*v3electionpb.LeaderRequest), nil -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/kv_client_adapter.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/kv_client_adapter.go deleted file mode 100644 index acd5673d0058..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/kv_client_adapter.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - grpc "google.golang.org/grpc" -) - -type kvs2kvc struct{ kvs pb.KVServer } - -func KvServerToKvClient(kvs pb.KVServer) pb.KVClient { - return &kvs2kvc{kvs} -} - -func (s *kvs2kvc) Range(ctx context.Context, in *pb.RangeRequest, opts ...grpc.CallOption) (*pb.RangeResponse, error) { - return s.kvs.Range(ctx, in) -} - -func (s *kvs2kvc) Put(ctx context.Context, in *pb.PutRequest, opts ...grpc.CallOption) (*pb.PutResponse, error) { - return s.kvs.Put(ctx, in) -} - -func (s *kvs2kvc) DeleteRange(ctx context.Context, in *pb.DeleteRangeRequest, opts ...grpc.CallOption) (*pb.DeleteRangeResponse, error) { - return s.kvs.DeleteRange(ctx, in) -} - -func (s *kvs2kvc) Txn(ctx context.Context, in *pb.TxnRequest, opts ...grpc.CallOption) (*pb.TxnResponse, error) { - return s.kvs.Txn(ctx, in) -} - -func (s *kvs2kvc) Compact(ctx context.Context, in *pb.CompactionRequest, opts ...grpc.CallOption) (*pb.CompactionResponse, error) { - return s.kvs.Compact(ctx, in) -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/lease_client_adapter.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/lease_client_adapter.go deleted file mode 100644 index 84c48b591b04..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/lease_client_adapter.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" -) - -type ls2lc struct { - leaseServer pb.LeaseServer -} - -func LeaseServerToLeaseClient(ls pb.LeaseServer) pb.LeaseClient { - return &ls2lc{ls} -} - -func (c *ls2lc) LeaseGrant(ctx context.Context, in *pb.LeaseGrantRequest, opts ...grpc.CallOption) (*pb.LeaseGrantResponse, error) { - return c.leaseServer.LeaseGrant(ctx, in) -} - -func (c *ls2lc) LeaseRevoke(ctx context.Context, in *pb.LeaseRevokeRequest, opts ...grpc.CallOption) (*pb.LeaseRevokeResponse, error) { - return c.leaseServer.LeaseRevoke(ctx, in) -} - -func (c *ls2lc) LeaseKeepAlive(ctx context.Context, opts ...grpc.CallOption) (pb.Lease_LeaseKeepAliveClient, error) { - cs := newPipeStream(ctx, func(ss chanServerStream) error { - return c.leaseServer.LeaseKeepAlive(&ls2lcServerStream{ss}) - }) - return &ls2lcClientStream{cs}, nil -} - -func (c *ls2lc) LeaseTimeToLive(ctx context.Context, in *pb.LeaseTimeToLiveRequest, opts ...grpc.CallOption) (*pb.LeaseTimeToLiveResponse, error) { - return c.leaseServer.LeaseTimeToLive(ctx, in) -} - -func (c *ls2lc) LeaseLeases(ctx context.Context, in *pb.LeaseLeasesRequest, opts ...grpc.CallOption) (*pb.LeaseLeasesResponse, error) { - return c.leaseServer.LeaseLeases(ctx, in) -} - -// ls2lcClientStream implements Lease_LeaseKeepAliveClient -type ls2lcClientStream struct{ chanClientStream } - -// ls2lcServerStream implements Lease_LeaseKeepAliveServer -type ls2lcServerStream struct{ chanServerStream } - -func (s *ls2lcClientStream) Send(rr *pb.LeaseKeepAliveRequest) error { - return s.SendMsg(rr) -} -func (s *ls2lcClientStream) Recv() (*pb.LeaseKeepAliveResponse, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*pb.LeaseKeepAliveResponse), nil -} - -func (s *ls2lcServerStream) Send(rr *pb.LeaseKeepAliveResponse) error { - return s.SendMsg(rr) -} -func (s *ls2lcServerStream) Recv() (*pb.LeaseKeepAliveRequest, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*pb.LeaseKeepAliveRequest), nil -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/lock_client_adapter.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/lock_client_adapter.go deleted file mode 100644 index 9ce7913a3ba0..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/lock_client_adapter.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - "github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb" - - "google.golang.org/grpc" -) - -type ls2lsc struct{ ls v3lockpb.LockServer } - -func LockServerToLockClient(ls v3lockpb.LockServer) v3lockpb.LockClient { - return &ls2lsc{ls} -} - -func (s *ls2lsc) Lock(ctx context.Context, r *v3lockpb.LockRequest, opts ...grpc.CallOption) (*v3lockpb.LockResponse, error) { - return s.ls.Lock(ctx, r) -} - -func (s *ls2lsc) Unlock(ctx context.Context, r *v3lockpb.UnlockRequest, opts ...grpc.CallOption) (*v3lockpb.UnlockResponse, error) { - return s.ls.Unlock(ctx, r) -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/maintenance_client_adapter.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/maintenance_client_adapter.go deleted file mode 100644 index 92d9dfd204ef..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/maintenance_client_adapter.go +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" -) - -type mts2mtc struct{ mts pb.MaintenanceServer } - -func MaintenanceServerToMaintenanceClient(mts pb.MaintenanceServer) pb.MaintenanceClient { - return &mts2mtc{mts} -} - -func (s *mts2mtc) Alarm(ctx context.Context, r *pb.AlarmRequest, opts ...grpc.CallOption) (*pb.AlarmResponse, error) { - return s.mts.Alarm(ctx, r) -} - -func (s *mts2mtc) Status(ctx context.Context, r *pb.StatusRequest, opts ...grpc.CallOption) (*pb.StatusResponse, error) { - return s.mts.Status(ctx, r) -} - -func (s *mts2mtc) Defragment(ctx context.Context, dr *pb.DefragmentRequest, opts ...grpc.CallOption) (*pb.DefragmentResponse, error) { - return s.mts.Defragment(ctx, dr) -} - -func (s *mts2mtc) Hash(ctx context.Context, r *pb.HashRequest, opts ...grpc.CallOption) (*pb.HashResponse, error) { - return s.mts.Hash(ctx, r) -} - -func (s *mts2mtc) HashKV(ctx context.Context, r *pb.HashKVRequest, opts ...grpc.CallOption) (*pb.HashKVResponse, error) { - return s.mts.HashKV(ctx, r) -} - -func (s *mts2mtc) MoveLeader(ctx context.Context, r *pb.MoveLeaderRequest, opts ...grpc.CallOption) (*pb.MoveLeaderResponse, error) { - return s.mts.MoveLeader(ctx, r) -} - -func (s *mts2mtc) Snapshot(ctx context.Context, in *pb.SnapshotRequest, opts ...grpc.CallOption) (pb.Maintenance_SnapshotClient, error) { - cs := newPipeStream(ctx, func(ss chanServerStream) error { - return s.mts.Snapshot(in, &ss2scServerStream{ss}) - }) - return &ss2scClientStream{cs}, nil -} - -// ss2scClientStream implements Maintenance_SnapshotClient -type ss2scClientStream struct{ chanClientStream } - -// ss2scServerStream implements Maintenance_SnapshotServer -type ss2scServerStream struct{ chanServerStream } - -func (s *ss2scClientStream) Send(rr *pb.SnapshotRequest) error { - return s.SendMsg(rr) -} -func (s *ss2scClientStream) Recv() (*pb.SnapshotResponse, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*pb.SnapshotResponse), nil -} - -func (s *ss2scServerStream) Send(rr *pb.SnapshotResponse) error { - return s.SendMsg(rr) -} -func (s *ss2scServerStream) Recv() (*pb.SnapshotRequest, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*pb.SnapshotRequest), nil -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/watch_client_adapter.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/watch_client_adapter.go deleted file mode 100644 index afe61e837b56..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/adapter/watch_client_adapter.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - "errors" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "google.golang.org/grpc" -) - -var errAlreadySentHeader = errors.New("adapter: already sent header") - -type ws2wc struct{ wserv pb.WatchServer } - -func WatchServerToWatchClient(wserv pb.WatchServer) pb.WatchClient { - return &ws2wc{wserv} -} - -func (s *ws2wc) Watch(ctx context.Context, opts ...grpc.CallOption) (pb.Watch_WatchClient, error) { - cs := newPipeStream(ctx, func(ss chanServerStream) error { - return s.wserv.Watch(&ws2wcServerStream{ss}) - }) - return &ws2wcClientStream{cs}, nil -} - -// ws2wcClientStream implements Watch_WatchClient -type ws2wcClientStream struct{ chanClientStream } - -// ws2wcServerStream implements Watch_WatchServer -type ws2wcServerStream struct{ chanServerStream } - -func (s *ws2wcClientStream) Send(wr *pb.WatchRequest) error { - return s.SendMsg(wr) -} -func (s *ws2wcClientStream) Recv() (*pb.WatchResponse, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*pb.WatchResponse), nil -} - -func (s *ws2wcServerStream) Send(wr *pb.WatchResponse) error { - return s.SendMsg(wr) -} -func (s *ws2wcServerStream) Recv() (*pb.WatchRequest, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*pb.WatchRequest), nil -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/auth.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/auth.go deleted file mode 100644 index 0ed8d246d2bd..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/auth.go +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - - "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -type AuthProxy struct { - client *clientv3.Client -} - -func NewAuthProxy(c *clientv3.Client) pb.AuthServer { - return &AuthProxy{client: c} -} - -func (ap *AuthProxy) AuthEnable(ctx context.Context, r *pb.AuthEnableRequest) (*pb.AuthEnableResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).AuthEnable(ctx, r) -} - -func (ap *AuthProxy) AuthDisable(ctx context.Context, r *pb.AuthDisableRequest) (*pb.AuthDisableResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).AuthDisable(ctx, r) -} - -func (ap *AuthProxy) Authenticate(ctx context.Context, r *pb.AuthenticateRequest) (*pb.AuthenticateResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).Authenticate(ctx, r) -} - -func (ap *AuthProxy) RoleAdd(ctx context.Context, r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).RoleAdd(ctx, r) -} - -func (ap *AuthProxy) RoleDelete(ctx context.Context, r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).RoleDelete(ctx, r) -} - -func (ap *AuthProxy) RoleGet(ctx context.Context, r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).RoleGet(ctx, r) -} - -func (ap *AuthProxy) RoleList(ctx context.Context, r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).RoleList(ctx, r) -} - -func (ap *AuthProxy) RoleRevokePermission(ctx context.Context, r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).RoleRevokePermission(ctx, r) -} - -func (ap *AuthProxy) RoleGrantPermission(ctx context.Context, r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).RoleGrantPermission(ctx, r) -} - -func (ap *AuthProxy) UserAdd(ctx context.Context, r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).UserAdd(ctx, r) -} - -func (ap *AuthProxy) UserDelete(ctx context.Context, r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).UserDelete(ctx, r) -} - -func (ap *AuthProxy) UserGet(ctx context.Context, r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).UserGet(ctx, r) -} - -func (ap *AuthProxy) UserList(ctx context.Context, r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).UserList(ctx, r) -} - -func (ap *AuthProxy) UserGrantRole(ctx context.Context, r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).UserGrantRole(ctx, r) -} - -func (ap *AuthProxy) UserRevokeRole(ctx context.Context, r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).UserRevokeRole(ctx, r) -} - -func (ap *AuthProxy) UserChangePassword(ctx context.Context, r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).UserChangePassword(ctx, r) -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/cache/store.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/cache/store.go deleted file mode 100644 index 5765228e50f2..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/cache/store.go +++ /dev/null @@ -1,171 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package cache exports functionality for efficiently caching and mapping -// `RangeRequest`s to corresponding `RangeResponse`s. -package cache - -import ( - "errors" - "sync" - - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/pkg/adt" - "github.com/golang/groupcache/lru" -) - -var ( - DefaultMaxEntries = 2048 - ErrCompacted = rpctypes.ErrGRPCCompacted -) - -type Cache interface { - Add(req *pb.RangeRequest, resp *pb.RangeResponse) - Get(req *pb.RangeRequest) (*pb.RangeResponse, error) - Compact(revision int64) - Invalidate(key []byte, endkey []byte) - Size() int - Close() -} - -// keyFunc returns the key of a request, which is used to look up its caching response in the cache. -func keyFunc(req *pb.RangeRequest) string { - // TODO: use marshalTo to reduce allocation - b, err := req.Marshal() - if err != nil { - panic(err) - } - return string(b) -} - -func NewCache(maxCacheEntries int) Cache { - return &cache{ - lru: lru.New(maxCacheEntries), - compactedRev: -1, - } -} - -func (c *cache) Close() {} - -// cache implements Cache -type cache struct { - mu sync.RWMutex - lru *lru.Cache - - // a reverse index for cache invalidation - cachedRanges adt.IntervalTree - - compactedRev int64 -} - -// Add adds the response of a request to the cache if its revision is larger than the compacted revision of the cache. -func (c *cache) Add(req *pb.RangeRequest, resp *pb.RangeResponse) { - key := keyFunc(req) - - c.mu.Lock() - defer c.mu.Unlock() - - if req.Revision > c.compactedRev { - c.lru.Add(key, resp) - } - // we do not need to invalidate a request with a revision specified. - // so we do not need to add it into the reverse index. - if req.Revision != 0 { - return - } - - var ( - iv *adt.IntervalValue - ivl adt.Interval - ) - if len(req.RangeEnd) != 0 { - ivl = adt.NewStringAffineInterval(string(req.Key), string(req.RangeEnd)) - } else { - ivl = adt.NewStringAffinePoint(string(req.Key)) - } - - iv = c.cachedRanges.Find(ivl) - - if iv == nil { - val := map[string]struct{}{key: {}} - c.cachedRanges.Insert(ivl, val) - } else { - val := iv.Val.(map[string]struct{}) - val[key] = struct{}{} - iv.Val = val - } -} - -// Get looks up the caching response for a given request. -// Get is also responsible for lazy eviction when accessing compacted entries. -func (c *cache) Get(req *pb.RangeRequest) (*pb.RangeResponse, error) { - key := keyFunc(req) - - c.mu.Lock() - defer c.mu.Unlock() - - if req.Revision > 0 && req.Revision < c.compactedRev { - c.lru.Remove(key) - return nil, ErrCompacted - } - - if resp, ok := c.lru.Get(key); ok { - return resp.(*pb.RangeResponse), nil - } - return nil, errors.New("not exist") -} - -// Invalidate invalidates the cache entries that intersecting with the given range from key to endkey. -func (c *cache) Invalidate(key, endkey []byte) { - c.mu.Lock() - defer c.mu.Unlock() - - var ( - ivs []*adt.IntervalValue - ivl adt.Interval - ) - if len(endkey) == 0 { - ivl = adt.NewStringAffinePoint(string(key)) - } else { - ivl = adt.NewStringAffineInterval(string(key), string(endkey)) - } - - ivs = c.cachedRanges.Stab(ivl) - for _, iv := range ivs { - keys := iv.Val.(map[string]struct{}) - for key := range keys { - c.lru.Remove(key) - } - } - // delete after removing all keys since it is destructive to 'ivs' - c.cachedRanges.Delete(ivl) -} - -// Compact invalidate all caching response before the given rev. -// Replace with the invalidation is lazy. The actual removal happens when the entries is accessed. -func (c *cache) Compact(revision int64) { - c.mu.Lock() - defer c.mu.Unlock() - - if revision > c.compactedRev { - c.compactedRev = revision - } -} - -func (c *cache) Size() int { - c.mu.RLock() - defer c.mu.RUnlock() - return c.lru.Len() -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/cluster.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/cluster.go deleted file mode 100644 index 6e8d3c85bfba..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/cluster.go +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - "fmt" - "os" - "sync" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/naming" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "golang.org/x/time/rate" - gnaming "google.golang.org/grpc/naming" -) - -// allow maximum 1 retry per second -const resolveRetryRate = 1 - -type clusterProxy struct { - clus clientv3.Cluster - ctx context.Context - gr *naming.GRPCResolver - - // advertise client URL - advaddr string - prefix string - - umu sync.RWMutex - umap map[string]gnaming.Update -} - -// NewClusterProxy takes optional prefix to fetch grpc-proxy member endpoints. -// The returned channel is closed when there is grpc-proxy endpoint registered -// and the client's context is canceled so the 'register' loop returns. -func NewClusterProxy(c *clientv3.Client, advaddr string, prefix string) (pb.ClusterServer, <-chan struct{}) { - cp := &clusterProxy{ - clus: c.Cluster, - ctx: c.Ctx(), - gr: &naming.GRPCResolver{Client: c}, - - advaddr: advaddr, - prefix: prefix, - umap: make(map[string]gnaming.Update), - } - - donec := make(chan struct{}) - if advaddr != "" && prefix != "" { - go func() { - defer close(donec) - cp.resolve(prefix) - }() - return cp, donec - } - - close(donec) - return cp, donec -} - -func (cp *clusterProxy) resolve(prefix string) { - rm := rate.NewLimiter(rate.Limit(resolveRetryRate), resolveRetryRate) - for rm.Wait(cp.ctx) == nil { - wa, err := cp.gr.Resolve(prefix) - if err != nil { - plog.Warningf("failed to resolve %q (%v)", prefix, err) - continue - } - cp.monitor(wa) - } -} - -func (cp *clusterProxy) monitor(wa gnaming.Watcher) { - for cp.ctx.Err() == nil { - ups, err := wa.Next() - if err != nil { - plog.Warningf("clusterProxy watcher error (%v)", err) - if rpctypes.ErrorDesc(err) == naming.ErrWatcherClosed.Error() { - return - } - } - - cp.umu.Lock() - for i := range ups { - switch ups[i].Op { - case gnaming.Add: - cp.umap[ups[i].Addr] = *ups[i] - case gnaming.Delete: - delete(cp.umap, ups[i].Addr) - } - } - cp.umu.Unlock() - } -} - -func (cp *clusterProxy) MemberAdd(ctx context.Context, r *pb.MemberAddRequest) (*pb.MemberAddResponse, error) { - mresp, err := cp.clus.MemberAdd(ctx, r.PeerURLs) - if err != nil { - return nil, err - } - resp := (pb.MemberAddResponse)(*mresp) - return &resp, err -} - -func (cp *clusterProxy) MemberRemove(ctx context.Context, r *pb.MemberRemoveRequest) (*pb.MemberRemoveResponse, error) { - mresp, err := cp.clus.MemberRemove(ctx, r.ID) - if err != nil { - return nil, err - } - resp := (pb.MemberRemoveResponse)(*mresp) - return &resp, err -} - -func (cp *clusterProxy) MemberUpdate(ctx context.Context, r *pb.MemberUpdateRequest) (*pb.MemberUpdateResponse, error) { - mresp, err := cp.clus.MemberUpdate(ctx, r.ID, r.PeerURLs) - if err != nil { - return nil, err - } - resp := (pb.MemberUpdateResponse)(*mresp) - return &resp, err -} - -func (cp *clusterProxy) membersFromUpdates() ([]*pb.Member, error) { - cp.umu.RLock() - defer cp.umu.RUnlock() - mbs := make([]*pb.Member, 0, len(cp.umap)) - for addr, upt := range cp.umap { - m, err := decodeMeta(fmt.Sprint(upt.Metadata)) - if err != nil { - return nil, err - } - mbs = append(mbs, &pb.Member{Name: m.Name, ClientURLs: []string{addr}}) - } - return mbs, nil -} - -// MemberList wraps member list API with following rules: -// - If 'advaddr' is not empty and 'prefix' is not empty, return registered member lists via resolver -// - If 'advaddr' is not empty and 'prefix' is not empty and registered grpc-proxy members haven't been fetched, return the 'advaddr' -// - If 'advaddr' is not empty and 'prefix' is empty, return 'advaddr' without forcing it to 'register' -// - If 'advaddr' is empty, forward to member list API -func (cp *clusterProxy) MemberList(ctx context.Context, r *pb.MemberListRequest) (*pb.MemberListResponse, error) { - if cp.advaddr != "" { - if cp.prefix != "" { - mbs, err := cp.membersFromUpdates() - if err != nil { - return nil, err - } - if len(mbs) > 0 { - return &pb.MemberListResponse{Members: mbs}, nil - } - } - // prefix is empty or no grpc-proxy members haven't been registered - hostname, _ := os.Hostname() - return &pb.MemberListResponse{Members: []*pb.Member{{Name: hostname, ClientURLs: []string{cp.advaddr}}}}, nil - } - mresp, err := cp.clus.MemberList(ctx) - if err != nil { - return nil, err - } - resp := (pb.MemberListResponse)(*mresp) - return &resp, err -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/doc.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/doc.go deleted file mode 100644 index fc022e3c57e7..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package grpcproxy is an OSI level 7 proxy for etcd v3 API requests. -package grpcproxy diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/election.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/election.go deleted file mode 100644 index 4b4a4cc42109..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/election.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2017 The etcd Lockors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb" -) - -type electionProxy struct { - client *clientv3.Client -} - -func NewElectionProxy(client *clientv3.Client) v3electionpb.ElectionServer { - return &electionProxy{client: client} -} - -func (ep *electionProxy) Campaign(ctx context.Context, req *v3electionpb.CampaignRequest) (*v3electionpb.CampaignResponse, error) { - return v3electionpb.NewElectionClient(ep.client.ActiveConnection()).Campaign(ctx, req) -} - -func (ep *electionProxy) Proclaim(ctx context.Context, req *v3electionpb.ProclaimRequest) (*v3electionpb.ProclaimResponse, error) { - return v3electionpb.NewElectionClient(ep.client.ActiveConnection()).Proclaim(ctx, req) -} - -func (ep *electionProxy) Leader(ctx context.Context, req *v3electionpb.LeaderRequest) (*v3electionpb.LeaderResponse, error) { - return v3electionpb.NewElectionClient(ep.client.ActiveConnection()).Leader(ctx, req) -} - -func (ep *electionProxy) Observe(req *v3electionpb.LeaderRequest, s v3electionpb.Election_ObserveServer) error { - conn := ep.client.ActiveConnection() - ctx, cancel := context.WithCancel(s.Context()) - defer cancel() - sc, err := v3electionpb.NewElectionClient(conn).Observe(ctx, req) - if err != nil { - return err - } - for { - rr, err := sc.Recv() - if err != nil { - return err - } - if err = s.Send(rr); err != nil { - return err - } - } -} - -func (ep *electionProxy) Resign(ctx context.Context, req *v3electionpb.ResignRequest) (*v3electionpb.ResignResponse, error) { - return v3electionpb.NewElectionClient(ep.client.ActiveConnection()).Resign(ctx, req) -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/health.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/health.go deleted file mode 100644 index e5e91f29bb3c..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/health.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - "net/http" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/etcdhttp" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" -) - -// HandleHealth registers health handler on '/health'. -func HandleHealth(mux *http.ServeMux, c *clientv3.Client) { - mux.Handle(etcdhttp.PathHealth, etcdhttp.NewHealthHandler(func() etcdhttp.Health { return checkHealth(c) })) -} - -func checkHealth(c *clientv3.Client) etcdhttp.Health { - h := etcdhttp.Health{Health: "false"} - ctx, cancel := context.WithTimeout(c.Ctx(), time.Second) - _, err := c.Get(ctx, "a") - cancel() - if err == nil || err == rpctypes.ErrPermissionDenied { - h.Health = "true" - } - return h -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/kv.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/kv.go deleted file mode 100644 index 1c9860f98af3..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/kv.go +++ /dev/null @@ -1,232 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - - "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/proxy/grpcproxy/cache" -) - -type kvProxy struct { - kv clientv3.KV - cache cache.Cache -} - -func NewKvProxy(c *clientv3.Client) (pb.KVServer, <-chan struct{}) { - kv := &kvProxy{ - kv: c.KV, - cache: cache.NewCache(cache.DefaultMaxEntries), - } - donec := make(chan struct{}) - close(donec) - return kv, donec -} - -func (p *kvProxy) Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, error) { - if r.Serializable { - resp, err := p.cache.Get(r) - switch err { - case nil: - cacheHits.Inc() - return resp, nil - case cache.ErrCompacted: - cacheHits.Inc() - return nil, err - } - - cachedMisses.Inc() - } - - resp, err := p.kv.Do(ctx, RangeRequestToOp(r)) - if err != nil { - return nil, err - } - - // cache linearizable as serializable - req := *r - req.Serializable = true - gresp := (*pb.RangeResponse)(resp.Get()) - p.cache.Add(&req, gresp) - cacheKeys.Set(float64(p.cache.Size())) - - return gresp, nil -} - -func (p *kvProxy) Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error) { - p.cache.Invalidate(r.Key, nil) - cacheKeys.Set(float64(p.cache.Size())) - - resp, err := p.kv.Do(ctx, PutRequestToOp(r)) - return (*pb.PutResponse)(resp.Put()), err -} - -func (p *kvProxy) DeleteRange(ctx context.Context, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) { - p.cache.Invalidate(r.Key, r.RangeEnd) - cacheKeys.Set(float64(p.cache.Size())) - - resp, err := p.kv.Do(ctx, DelRequestToOp(r)) - return (*pb.DeleteRangeResponse)(resp.Del()), err -} - -func (p *kvProxy) txnToCache(reqs []*pb.RequestOp, resps []*pb.ResponseOp) { - for i := range resps { - switch tv := resps[i].Response.(type) { - case *pb.ResponseOp_ResponsePut: - p.cache.Invalidate(reqs[i].GetRequestPut().Key, nil) - case *pb.ResponseOp_ResponseDeleteRange: - rdr := reqs[i].GetRequestDeleteRange() - p.cache.Invalidate(rdr.Key, rdr.RangeEnd) - case *pb.ResponseOp_ResponseRange: - req := *(reqs[i].GetRequestRange()) - req.Serializable = true - p.cache.Add(&req, tv.ResponseRange) - } - } -} - -func (p *kvProxy) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error) { - op := TxnRequestToOp(r) - opResp, err := p.kv.Do(ctx, op) - if err != nil { - return nil, err - } - resp := opResp.Txn() - - // txn may claim an outdated key is updated; be safe and invalidate - for _, cmp := range r.Compare { - p.cache.Invalidate(cmp.Key, cmp.RangeEnd) - } - // update any fetched keys - if resp.Succeeded { - p.txnToCache(r.Success, resp.Responses) - } else { - p.txnToCache(r.Failure, resp.Responses) - } - - cacheKeys.Set(float64(p.cache.Size())) - - return (*pb.TxnResponse)(resp), nil -} - -func (p *kvProxy) Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error) { - var opts []clientv3.CompactOption - if r.Physical { - opts = append(opts, clientv3.WithCompactPhysical()) - } - - resp, err := p.kv.Compact(ctx, r.Revision, opts...) - if err == nil { - p.cache.Compact(r.Revision) - } - - cacheKeys.Set(float64(p.cache.Size())) - - return (*pb.CompactionResponse)(resp), err -} - -func requestOpToOp(union *pb.RequestOp) clientv3.Op { - switch tv := union.Request.(type) { - case *pb.RequestOp_RequestRange: - if tv.RequestRange != nil { - return RangeRequestToOp(tv.RequestRange) - } - case *pb.RequestOp_RequestPut: - if tv.RequestPut != nil { - return PutRequestToOp(tv.RequestPut) - } - case *pb.RequestOp_RequestDeleteRange: - if tv.RequestDeleteRange != nil { - return DelRequestToOp(tv.RequestDeleteRange) - } - case *pb.RequestOp_RequestTxn: - if tv.RequestTxn != nil { - return TxnRequestToOp(tv.RequestTxn) - } - } - panic("unknown request") -} - -func RangeRequestToOp(r *pb.RangeRequest) clientv3.Op { - opts := []clientv3.OpOption{} - if len(r.RangeEnd) != 0 { - opts = append(opts, clientv3.WithRange(string(r.RangeEnd))) - } - opts = append(opts, clientv3.WithRev(r.Revision)) - opts = append(opts, clientv3.WithLimit(r.Limit)) - opts = append(opts, clientv3.WithSort( - clientv3.SortTarget(r.SortTarget), - clientv3.SortOrder(r.SortOrder)), - ) - opts = append(opts, clientv3.WithMaxCreateRev(r.MaxCreateRevision)) - opts = append(opts, clientv3.WithMinCreateRev(r.MinCreateRevision)) - opts = append(opts, clientv3.WithMaxModRev(r.MaxModRevision)) - opts = append(opts, clientv3.WithMinModRev(r.MinModRevision)) - if r.CountOnly { - opts = append(opts, clientv3.WithCountOnly()) - } - if r.KeysOnly { - opts = append(opts, clientv3.WithKeysOnly()) - } - if r.Serializable { - opts = append(opts, clientv3.WithSerializable()) - } - - return clientv3.OpGet(string(r.Key), opts...) -} - -func PutRequestToOp(r *pb.PutRequest) clientv3.Op { - opts := []clientv3.OpOption{} - opts = append(opts, clientv3.WithLease(clientv3.LeaseID(r.Lease))) - if r.IgnoreValue { - opts = append(opts, clientv3.WithIgnoreValue()) - } - if r.IgnoreLease { - opts = append(opts, clientv3.WithIgnoreLease()) - } - if r.PrevKv { - opts = append(opts, clientv3.WithPrevKV()) - } - return clientv3.OpPut(string(r.Key), string(r.Value), opts...) -} - -func DelRequestToOp(r *pb.DeleteRangeRequest) clientv3.Op { - opts := []clientv3.OpOption{} - if len(r.RangeEnd) != 0 { - opts = append(opts, clientv3.WithRange(string(r.RangeEnd))) - } - if r.PrevKv { - opts = append(opts, clientv3.WithPrevKV()) - } - return clientv3.OpDelete(string(r.Key), opts...) -} - -func TxnRequestToOp(r *pb.TxnRequest) clientv3.Op { - cmps := make([]clientv3.Cmp, len(r.Compare)) - thenops := make([]clientv3.Op, len(r.Success)) - elseops := make([]clientv3.Op, len(r.Failure)) - for i := range r.Compare { - cmps[i] = (clientv3.Cmp)(*r.Compare[i]) - } - for i := range r.Success { - thenops[i] = requestOpToOp(r.Success[i]) - } - for i := range r.Failure { - elseops[i] = requestOpToOp(r.Failure[i]) - } - return clientv3.OpTxn(cmps, thenops, elseops) -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/leader.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/leader.go deleted file mode 100644 index 042c949b7080..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/leader.go +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - "math" - "sync" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - - "golang.org/x/time/rate" - "google.golang.org/grpc" -) - -const ( - lostLeaderKey = "__lostleader" // watched to detect leader loss - retryPerSecond = 10 -) - -type leader struct { - ctx context.Context - w clientv3.Watcher - // mu protects leaderc updates. - mu sync.RWMutex - leaderc chan struct{} - disconnc chan struct{} - donec chan struct{} -} - -func newLeader(ctx context.Context, w clientv3.Watcher) *leader { - l := &leader{ - ctx: clientv3.WithRequireLeader(ctx), - w: w, - leaderc: make(chan struct{}), - disconnc: make(chan struct{}), - donec: make(chan struct{}), - } - // begin assuming leader is lost - close(l.leaderc) - go l.recvLoop() - return l -} - -func (l *leader) recvLoop() { - defer close(l.donec) - - limiter := rate.NewLimiter(rate.Limit(retryPerSecond), retryPerSecond) - rev := int64(math.MaxInt64 - 2) - for limiter.Wait(l.ctx) == nil { - wch := l.w.Watch(l.ctx, lostLeaderKey, clientv3.WithRev(rev), clientv3.WithCreatedNotify()) - cresp, ok := <-wch - if !ok { - l.loseLeader() - continue - } - if cresp.Err() != nil { - l.loseLeader() - if rpctypes.ErrorDesc(cresp.Err()) == grpc.ErrClientConnClosing.Error() { - close(l.disconnc) - return - } - continue - } - l.gotLeader() - <-wch - l.loseLeader() - } -} - -func (l *leader) loseLeader() { - l.mu.RLock() - defer l.mu.RUnlock() - select { - case <-l.leaderc: - default: - close(l.leaderc) - } -} - -// gotLeader will force update the leadership status to having a leader. -func (l *leader) gotLeader() { - l.mu.Lock() - defer l.mu.Unlock() - select { - case <-l.leaderc: - l.leaderc = make(chan struct{}) - default: - } -} - -func (l *leader) disconnectNotify() <-chan struct{} { return l.disconnc } - -func (l *leader) stopNotify() <-chan struct{} { return l.donec } - -// lostNotify returns a channel that is closed if there has been -// a leader loss not yet followed by a leader reacquire. -func (l *leader) lostNotify() <-chan struct{} { - l.mu.RLock() - defer l.mu.RUnlock() - return l.leaderc -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/lease.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/lease.go deleted file mode 100644 index 65f68b0ea0ca..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/lease.go +++ /dev/null @@ -1,382 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - "io" - "sync" - "sync/atomic" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" - "google.golang.org/grpc/metadata" -) - -type leaseProxy struct { - // leaseClient handles req from LeaseGrant() that requires a lease ID. - leaseClient pb.LeaseClient - - lessor clientv3.Lease - - ctx context.Context - - leader *leader - - // mu protects adding outstanding leaseProxyStream through wg. - mu sync.RWMutex - - // wg waits until all outstanding leaseProxyStream quit. - wg sync.WaitGroup -} - -func NewLeaseProxy(c *clientv3.Client) (pb.LeaseServer, <-chan struct{}) { - cctx, cancel := context.WithCancel(c.Ctx()) - lp := &leaseProxy{ - leaseClient: pb.NewLeaseClient(c.ActiveConnection()), - lessor: c.Lease, - ctx: cctx, - leader: newLeader(c.Ctx(), c.Watcher), - } - ch := make(chan struct{}) - go func() { - defer close(ch) - <-lp.leader.stopNotify() - lp.mu.Lock() - select { - case <-lp.ctx.Done(): - case <-lp.leader.disconnectNotify(): - cancel() - } - <-lp.ctx.Done() - lp.mu.Unlock() - lp.wg.Wait() - }() - return lp, ch -} - -func (lp *leaseProxy) LeaseGrant(ctx context.Context, cr *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - rp, err := lp.leaseClient.LeaseGrant(ctx, cr, grpc.FailFast(false)) - if err != nil { - return nil, err - } - lp.leader.gotLeader() - return rp, nil -} - -func (lp *leaseProxy) LeaseRevoke(ctx context.Context, rr *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) { - r, err := lp.lessor.Revoke(ctx, clientv3.LeaseID(rr.ID)) - if err != nil { - return nil, err - } - lp.leader.gotLeader() - return (*pb.LeaseRevokeResponse)(r), nil -} - -func (lp *leaseProxy) LeaseTimeToLive(ctx context.Context, rr *pb.LeaseTimeToLiveRequest) (*pb.LeaseTimeToLiveResponse, error) { - var ( - r *clientv3.LeaseTimeToLiveResponse - err error - ) - if rr.Keys { - r, err = lp.lessor.TimeToLive(ctx, clientv3.LeaseID(rr.ID), clientv3.WithAttachedKeys()) - } else { - r, err = lp.lessor.TimeToLive(ctx, clientv3.LeaseID(rr.ID)) - } - if err != nil { - return nil, err - } - rp := &pb.LeaseTimeToLiveResponse{ - Header: r.ResponseHeader, - ID: int64(r.ID), - TTL: r.TTL, - GrantedTTL: r.GrantedTTL, - Keys: r.Keys, - } - return rp, err -} - -func (lp *leaseProxy) LeaseLeases(ctx context.Context, rr *pb.LeaseLeasesRequest) (*pb.LeaseLeasesResponse, error) { - r, err := lp.lessor.Leases(ctx) - if err != nil { - return nil, err - } - leases := make([]*pb.LeaseStatus, len(r.Leases)) - for i := range r.Leases { - leases[i] = &pb.LeaseStatus{ID: int64(r.Leases[i].ID)} - } - rp := &pb.LeaseLeasesResponse{ - Header: r.ResponseHeader, - Leases: leases, - } - return rp, err -} - -func (lp *leaseProxy) LeaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) error { - lp.mu.Lock() - select { - case <-lp.ctx.Done(): - lp.mu.Unlock() - return lp.ctx.Err() - default: - lp.wg.Add(1) - } - lp.mu.Unlock() - - ctx, cancel := context.WithCancel(stream.Context()) - lps := leaseProxyStream{ - stream: stream, - lessor: lp.lessor, - keepAliveLeases: make(map[int64]*atomicCounter), - respc: make(chan *pb.LeaseKeepAliveResponse), - ctx: ctx, - cancel: cancel, - } - - errc := make(chan error, 2) - - var lostLeaderC <-chan struct{} - if md, ok := metadata.FromOutgoingContext(stream.Context()); ok { - v := md[rpctypes.MetadataRequireLeaderKey] - if len(v) > 0 && v[0] == rpctypes.MetadataHasLeader { - lostLeaderC = lp.leader.lostNotify() - // if leader is known to be lost at creation time, avoid - // letting events through at all - select { - case <-lostLeaderC: - lp.wg.Done() - return rpctypes.ErrNoLeader - default: - } - } - } - stopc := make(chan struct{}, 3) - go func() { - defer func() { stopc <- struct{}{} }() - if err := lps.recvLoop(); err != nil { - errc <- err - } - }() - - go func() { - defer func() { stopc <- struct{}{} }() - if err := lps.sendLoop(); err != nil { - errc <- err - } - }() - - // tears down LeaseKeepAlive stream if leader goes down or entire leaseProxy is terminated. - go func() { - defer func() { stopc <- struct{}{} }() - select { - case <-lostLeaderC: - case <-ctx.Done(): - case <-lp.ctx.Done(): - } - }() - - var err error - select { - case <-stopc: - stopc <- struct{}{} - case err = <-errc: - } - cancel() - - // recv/send may only shutdown after function exits; - // this goroutine notifies lease proxy that the stream is through - go func() { - <-stopc - <-stopc - <-stopc - lps.close() - close(errc) - lp.wg.Done() - }() - - select { - case <-lostLeaderC: - return rpctypes.ErrNoLeader - case <-lp.leader.disconnectNotify(): - return grpc.ErrClientConnClosing - default: - if err != nil { - return err - } - return ctx.Err() - } -} - -type leaseProxyStream struct { - stream pb.Lease_LeaseKeepAliveServer - - lessor clientv3.Lease - // wg tracks keepAliveLoop goroutines - wg sync.WaitGroup - // mu protects keepAliveLeases - mu sync.RWMutex - // keepAliveLeases tracks how many outstanding keepalive requests which need responses are on a lease. - keepAliveLeases map[int64]*atomicCounter - // respc receives lease keepalive responses from etcd backend - respc chan *pb.LeaseKeepAliveResponse - - ctx context.Context - cancel context.CancelFunc -} - -func (lps *leaseProxyStream) recvLoop() error { - for { - rr, err := lps.stream.Recv() - if err == io.EOF { - return nil - } - if err != nil { - return err - } - lps.mu.Lock() - neededResps, ok := lps.keepAliveLeases[rr.ID] - if !ok { - neededResps = &atomicCounter{} - lps.keepAliveLeases[rr.ID] = neededResps - lps.wg.Add(1) - go func() { - defer lps.wg.Done() - if err := lps.keepAliveLoop(rr.ID, neededResps); err != nil { - lps.cancel() - } - }() - } - neededResps.add(1) - lps.mu.Unlock() - } -} - -func (lps *leaseProxyStream) keepAliveLoop(leaseID int64, neededResps *atomicCounter) error { - cctx, ccancel := context.WithCancel(lps.ctx) - defer ccancel() - respc, err := lps.lessor.KeepAlive(cctx, clientv3.LeaseID(leaseID)) - if err != nil { - return err - } - // ticker expires when loop hasn't received keepalive within TTL - var ticker <-chan time.Time - for { - select { - case <-ticker: - lps.mu.Lock() - // if there are outstanding keepAlive reqs at the moment of ticker firing, - // don't close keepAliveLoop(), let it continuing to process the KeepAlive reqs. - if neededResps.get() > 0 { - lps.mu.Unlock() - ticker = nil - continue - } - delete(lps.keepAliveLeases, leaseID) - lps.mu.Unlock() - return nil - case rp, ok := <-respc: - if !ok { - lps.mu.Lock() - delete(lps.keepAliveLeases, leaseID) - lps.mu.Unlock() - if neededResps.get() == 0 { - return nil - } - ttlResp, err := lps.lessor.TimeToLive(cctx, clientv3.LeaseID(leaseID)) - if err != nil { - return err - } - r := &pb.LeaseKeepAliveResponse{ - Header: ttlResp.ResponseHeader, - ID: int64(ttlResp.ID), - TTL: ttlResp.TTL, - } - for neededResps.get() > 0 { - select { - case lps.respc <- r: - neededResps.add(-1) - case <-lps.ctx.Done(): - return nil - } - } - return nil - } - if neededResps.get() == 0 { - continue - } - ticker = time.After(time.Duration(rp.TTL) * time.Second) - r := &pb.LeaseKeepAliveResponse{ - Header: rp.ResponseHeader, - ID: int64(rp.ID), - TTL: rp.TTL, - } - lps.replyToClient(r, neededResps) - } - } -} - -func (lps *leaseProxyStream) replyToClient(r *pb.LeaseKeepAliveResponse, neededResps *atomicCounter) { - timer := time.After(500 * time.Millisecond) - for neededResps.get() > 0 { - select { - case lps.respc <- r: - neededResps.add(-1) - case <-timer: - return - case <-lps.ctx.Done(): - return - } - } -} - -func (lps *leaseProxyStream) sendLoop() error { - for { - select { - case lrp, ok := <-lps.respc: - if !ok { - return nil - } - if err := lps.stream.Send(lrp); err != nil { - return err - } - case <-lps.ctx.Done(): - return lps.ctx.Err() - } - } -} - -func (lps *leaseProxyStream) close() { - lps.cancel() - lps.wg.Wait() - // only close respc channel if all the keepAliveLoop() goroutines have finished - // this ensures those goroutines don't send resp to a closed resp channel - close(lps.respc) -} - -type atomicCounter struct { - counter int64 -} - -func (ac *atomicCounter) add(delta int64) { - atomic.AddInt64(&ac.counter, delta) -} - -func (ac *atomicCounter) get() int64 { - return atomic.LoadInt64(&ac.counter) -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/lock.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/lock.go deleted file mode 100644 index ceef26f0a0f6..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/lock.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2017 The etcd Lockors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb" -) - -type lockProxy struct { - client *clientv3.Client -} - -func NewLockProxy(client *clientv3.Client) v3lockpb.LockServer { - return &lockProxy{client: client} -} - -func (lp *lockProxy) Lock(ctx context.Context, req *v3lockpb.LockRequest) (*v3lockpb.LockResponse, error) { - return v3lockpb.NewLockClient(lp.client.ActiveConnection()).Lock(ctx, req) -} - -func (lp *lockProxy) Unlock(ctx context.Context, req *v3lockpb.UnlockRequest) (*v3lockpb.UnlockResponse, error) { - return v3lockpb.NewLockClient(lp.client.ActiveConnection()).Unlock(ctx, req) -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/logger.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/logger.go deleted file mode 100644 index c2d818043955..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/logger.go +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import "github.com/coreos/pkg/capnslog" - -var plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "grpcproxy") diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/maintenance.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/maintenance.go deleted file mode 100644 index 291e8e3088f5..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/maintenance.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - "io" - - "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -type maintenanceProxy struct { - client *clientv3.Client -} - -func NewMaintenanceProxy(c *clientv3.Client) pb.MaintenanceServer { - return &maintenanceProxy{ - client: c, - } -} - -func (mp *maintenanceProxy) Defragment(ctx context.Context, dr *pb.DefragmentRequest) (*pb.DefragmentResponse, error) { - conn := mp.client.ActiveConnection() - return pb.NewMaintenanceClient(conn).Defragment(ctx, dr) -} - -func (mp *maintenanceProxy) Snapshot(sr *pb.SnapshotRequest, stream pb.Maintenance_SnapshotServer) error { - conn := mp.client.ActiveConnection() - ctx, cancel := context.WithCancel(stream.Context()) - defer cancel() - - ctx = withClientAuthToken(ctx, stream.Context()) - - sc, err := pb.NewMaintenanceClient(conn).Snapshot(ctx, sr) - if err != nil { - return err - } - - for { - rr, err := sc.Recv() - if err != nil { - if err == io.EOF { - return nil - } - return err - } - err = stream.Send(rr) - if err != nil { - return err - } - } -} - -func (mp *maintenanceProxy) Hash(ctx context.Context, r *pb.HashRequest) (*pb.HashResponse, error) { - conn := mp.client.ActiveConnection() - return pb.NewMaintenanceClient(conn).Hash(ctx, r) -} - -func (mp *maintenanceProxy) HashKV(ctx context.Context, r *pb.HashKVRequest) (*pb.HashKVResponse, error) { - conn := mp.client.ActiveConnection() - return pb.NewMaintenanceClient(conn).HashKV(ctx, r) -} - -func (mp *maintenanceProxy) Alarm(ctx context.Context, r *pb.AlarmRequest) (*pb.AlarmResponse, error) { - conn := mp.client.ActiveConnection() - return pb.NewMaintenanceClient(conn).Alarm(ctx, r) -} - -func (mp *maintenanceProxy) Status(ctx context.Context, r *pb.StatusRequest) (*pb.StatusResponse, error) { - conn := mp.client.ActiveConnection() - return pb.NewMaintenanceClient(conn).Status(ctx, r) -} - -func (mp *maintenanceProxy) MoveLeader(ctx context.Context, r *pb.MoveLeaderRequest) (*pb.MoveLeaderResponse, error) { - conn := mp.client.ActiveConnection() - return pb.NewMaintenanceClient(conn).MoveLeader(ctx, r) -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/metrics.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/metrics.go deleted file mode 100644 index ebb82bb727d8..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/metrics.go +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "fmt" - "io/ioutil" - "math/rand" - "net/http" - "strings" - "time" - - "github.com/coreos/etcd/etcdserver/api/etcdhttp" - "github.com/prometheus/client_golang/prometheus" -) - -var ( - watchersCoalescing = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "grpc_proxy", - Name: "watchers_coalescing_total", - Help: "Total number of current watchers coalescing", - }) - eventsCoalescing = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "grpc_proxy", - Name: "events_coalescing_total", - Help: "Total number of events coalescing", - }) - cacheKeys = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "grpc_proxy", - Name: "cache_keys_total", - Help: "Total number of keys/ranges cached", - }) - cacheHits = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "grpc_proxy", - Name: "cache_hits_total", - Help: "Total number of cache hits", - }) - cachedMisses = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "grpc_proxy", - Name: "cache_misses_total", - Help: "Total number of cache misses", - }) -) - -func init() { - prometheus.MustRegister(watchersCoalescing) - prometheus.MustRegister(eventsCoalescing) - prometheus.MustRegister(cacheKeys) - prometheus.MustRegister(cacheHits) - prometheus.MustRegister(cachedMisses) -} - -// HandleMetrics performs a GET request against etcd endpoint and returns '/metrics'. -func HandleMetrics(mux *http.ServeMux, c *http.Client, eps []string) { - // random shuffle endpoints - r := rand.New(rand.NewSource(int64(time.Now().Nanosecond()))) - if len(eps) > 1 { - eps = shuffleEndpoints(r, eps) - } - - pathMetrics := etcdhttp.PathMetrics - mux.HandleFunc(pathMetrics, func(w http.ResponseWriter, r *http.Request) { - target := fmt.Sprintf("%s%s", eps[0], pathMetrics) - if !strings.HasPrefix(target, "http") { - scheme := "http" - if r.TLS != nil { - scheme = "https" - } - target = fmt.Sprintf("%s://%s", scheme, target) - } - - resp, err := c.Get(target) - if err != nil { - http.Error(w, "Internal server error", http.StatusInternalServerError) - } - defer resp.Body.Close() - w.Header().Set("Content-Type", "text/plain; version=0.0.4") - body, _ := ioutil.ReadAll(resp.Body) - fmt.Fprintf(w, "%s", body) - }) -} - -func shuffleEndpoints(r *rand.Rand, eps []string) []string { - // copied from Go 1.9<= rand.Rand.Perm - n := len(eps) - p := make([]int, n) - for i := 0; i < n; i++ { - j := r.Intn(i + 1) - p[i] = p[j] - p[j] = i - } - neps := make([]string, n) - for i, k := range p { - neps[i] = eps[k] - } - return neps -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/register.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/register.go deleted file mode 100644 index 598c71f07aef..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/register.go +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "encoding/json" - "os" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/concurrency" - "github.com/coreos/etcd/clientv3/naming" - - "golang.org/x/time/rate" - gnaming "google.golang.org/grpc/naming" -) - -// allow maximum 1 retry per second -const registerRetryRate = 1 - -// Register registers itself as a grpc-proxy server by writing prefixed-key -// with session of specified TTL (in seconds). The returned channel is closed -// when the client's context is canceled. -func Register(c *clientv3.Client, prefix string, addr string, ttl int) <-chan struct{} { - rm := rate.NewLimiter(rate.Limit(registerRetryRate), registerRetryRate) - - donec := make(chan struct{}) - go func() { - defer close(donec) - - for rm.Wait(c.Ctx()) == nil { - ss, err := registerSession(c, prefix, addr, ttl) - if err != nil { - plog.Warningf("failed to create a session %v", err) - continue - } - select { - case <-c.Ctx().Done(): - ss.Close() - return - - case <-ss.Done(): - plog.Warning("session expired; possible network partition or server restart") - plog.Warning("creating a new session to rejoin") - continue - } - } - }() - - return donec -} - -func registerSession(c *clientv3.Client, prefix string, addr string, ttl int) (*concurrency.Session, error) { - ss, err := concurrency.NewSession(c, concurrency.WithTTL(ttl)) - if err != nil { - return nil, err - } - - gr := &naming.GRPCResolver{Client: c} - if err = gr.Update(c.Ctx(), prefix, gnaming.Update{Op: gnaming.Add, Addr: addr, Metadata: getMeta()}, clientv3.WithLease(ss.Lease())); err != nil { - return nil, err - } - - plog.Infof("registered %q with %d-second lease", addr, ttl) - return ss, nil -} - -// meta represents metadata of proxy register. -type meta struct { - Name string `json:"name"` -} - -func getMeta() string { - hostname, _ := os.Hostname() - bts, _ := json.Marshal(meta{Name: hostname}) - return string(bts) -} - -func decodeMeta(s string) (meta, error) { - m := meta{} - err := json.Unmarshal([]byte(s), &m) - return m, err -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/util.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/util.go deleted file mode 100644 index 2b226fa74ebf..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/util.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - - "google.golang.org/grpc" - "google.golang.org/grpc/metadata" -) - -func getAuthTokenFromClient(ctx context.Context) string { - md, ok := metadata.FromIncomingContext(ctx) - if ok { - ts, ok := md["token"] - if ok { - return ts[0] - } - } - return "" -} - -func withClientAuthToken(ctx context.Context, ctxWithToken context.Context) context.Context { - token := getAuthTokenFromClient(ctxWithToken) - if token != "" { - ctx = context.WithValue(ctx, "token", token) - } - return ctx -} - -type proxyTokenCredential struct { - token string -} - -func (cred *proxyTokenCredential) RequireTransportSecurity() bool { - return false -} - -func (cred *proxyTokenCredential) GetRequestMetadata(ctx context.Context, s ...string) (map[string]string, error) { - return map[string]string{ - "token": cred.token, - }, nil -} - -func AuthUnaryClientInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { - token := getAuthTokenFromClient(ctx) - if token != "" { - tokenCred := &proxyTokenCredential{token} - opts = append(opts, grpc.PerRPCCredentials(tokenCred)) - } - return invoker(ctx, method, req, reply, cc, opts...) -} - -func AuthStreamClientInterceptor(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) { - tokenif := ctx.Value("token") - if tokenif != nil { - tokenCred := &proxyTokenCredential{tokenif.(string)} - opts = append(opts, grpc.PerRPCCredentials(tokenCred)) - } - return streamer(ctx, desc, cc, method, opts...) -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/watch.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/watch.go deleted file mode 100644 index 603095f27f1c..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/watch.go +++ /dev/null @@ -1,298 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - "sync" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/v3rpc" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" - "google.golang.org/grpc/metadata" -) - -type watchProxy struct { - cw clientv3.Watcher - ctx context.Context - - leader *leader - - ranges *watchRanges - - // mu protects adding outstanding watch servers through wg. - mu sync.Mutex - - // wg waits until all outstanding watch servers quit. - wg sync.WaitGroup - - // kv is used for permission checking - kv clientv3.KV -} - -func NewWatchProxy(c *clientv3.Client) (pb.WatchServer, <-chan struct{}) { - cctx, cancel := context.WithCancel(c.Ctx()) - wp := &watchProxy{ - cw: c.Watcher, - ctx: cctx, - leader: newLeader(c.Ctx(), c.Watcher), - - kv: c.KV, // for permission checking - } - wp.ranges = newWatchRanges(wp) - ch := make(chan struct{}) - go func() { - defer close(ch) - <-wp.leader.stopNotify() - wp.mu.Lock() - select { - case <-wp.ctx.Done(): - case <-wp.leader.disconnectNotify(): - cancel() - } - <-wp.ctx.Done() - wp.mu.Unlock() - wp.wg.Wait() - wp.ranges.stop() - }() - return wp, ch -} - -func (wp *watchProxy) Watch(stream pb.Watch_WatchServer) (err error) { - wp.mu.Lock() - select { - case <-wp.ctx.Done(): - wp.mu.Unlock() - select { - case <-wp.leader.disconnectNotify(): - return grpc.ErrClientConnClosing - default: - return wp.ctx.Err() - } - default: - wp.wg.Add(1) - } - wp.mu.Unlock() - - ctx, cancel := context.WithCancel(stream.Context()) - wps := &watchProxyStream{ - ranges: wp.ranges, - watchers: make(map[int64]*watcher), - stream: stream, - watchCh: make(chan *pb.WatchResponse, 1024), - ctx: ctx, - cancel: cancel, - kv: wp.kv, - } - - var lostLeaderC <-chan struct{} - if md, ok := metadata.FromOutgoingContext(stream.Context()); ok { - v := md[rpctypes.MetadataRequireLeaderKey] - if len(v) > 0 && v[0] == rpctypes.MetadataHasLeader { - lostLeaderC = wp.leader.lostNotify() - // if leader is known to be lost at creation time, avoid - // letting events through at all - select { - case <-lostLeaderC: - wp.wg.Done() - return rpctypes.ErrNoLeader - default: - } - } - } - - // post to stopc => terminate server stream; can't use a waitgroup - // since all goroutines will only terminate after Watch() exits. - stopc := make(chan struct{}, 3) - go func() { - defer func() { stopc <- struct{}{} }() - wps.recvLoop() - }() - go func() { - defer func() { stopc <- struct{}{} }() - wps.sendLoop() - }() - // tear down watch if leader goes down or entire watch proxy is terminated - go func() { - defer func() { stopc <- struct{}{} }() - select { - case <-lostLeaderC: - case <-ctx.Done(): - case <-wp.ctx.Done(): - } - }() - - <-stopc - cancel() - - // recv/send may only shutdown after function exits; - // goroutine notifies proxy that stream is through - go func() { - <-stopc - <-stopc - wps.close() - wp.wg.Done() - }() - - select { - case <-lostLeaderC: - return rpctypes.ErrNoLeader - case <-wp.leader.disconnectNotify(): - return grpc.ErrClientConnClosing - default: - return wps.ctx.Err() - } -} - -// watchProxyStream forwards etcd watch events to a proxied client stream. -type watchProxyStream struct { - ranges *watchRanges - - // mu protects watchers and nextWatcherID - mu sync.Mutex - // watchers receive events from watch broadcast. - watchers map[int64]*watcher - // nextWatcherID is the id to assign the next watcher on this stream. - nextWatcherID int64 - - stream pb.Watch_WatchServer - - // watchCh receives watch responses from the watchers. - watchCh chan *pb.WatchResponse - - ctx context.Context - cancel context.CancelFunc - - // kv is used for permission checking - kv clientv3.KV -} - -func (wps *watchProxyStream) close() { - var wg sync.WaitGroup - wps.cancel() - wps.mu.Lock() - wg.Add(len(wps.watchers)) - for _, wpsw := range wps.watchers { - go func(w *watcher) { - wps.ranges.delete(w) - wg.Done() - }(wpsw) - } - wps.watchers = nil - wps.mu.Unlock() - - wg.Wait() - - close(wps.watchCh) -} - -func (wps *watchProxyStream) checkPermissionForWatch(key, rangeEnd []byte) error { - if len(key) == 0 { - // If the length of the key is 0, we need to obtain full range. - // look at clientv3.WithPrefix() - key = []byte{0} - rangeEnd = []byte{0} - } - req := &pb.RangeRequest{ - Serializable: true, - Key: key, - RangeEnd: rangeEnd, - CountOnly: true, - Limit: 1, - } - _, err := wps.kv.Do(wps.ctx, RangeRequestToOp(req)) - return err -} - -func (wps *watchProxyStream) recvLoop() error { - for { - req, err := wps.stream.Recv() - if err != nil { - return err - } - switch uv := req.RequestUnion.(type) { - case *pb.WatchRequest_CreateRequest: - cr := uv.CreateRequest - - if err = wps.checkPermissionForWatch(cr.Key, cr.RangeEnd); err != nil && err == rpctypes.ErrPermissionDenied { - // Return WatchResponse which is caused by permission checking if and only if - // the error is permission denied. For other errors (e.g. timeout or connection closed), - // the permission checking mechanism should do nothing for preserving error code. - wps.watchCh <- &pb.WatchResponse{Header: &pb.ResponseHeader{}, WatchId: -1, Created: true, Canceled: true} - continue - } - - w := &watcher{ - wr: watchRange{string(cr.Key), string(cr.RangeEnd)}, - id: wps.nextWatcherID, - wps: wps, - - nextrev: cr.StartRevision, - progress: cr.ProgressNotify, - prevKV: cr.PrevKv, - filters: v3rpc.FiltersFromRequest(cr), - } - if !w.wr.valid() { - w.post(&pb.WatchResponse{WatchId: -1, Created: true, Canceled: true}) - continue - } - wps.nextWatcherID++ - w.nextrev = cr.StartRevision - wps.watchers[w.id] = w - wps.ranges.add(w) - case *pb.WatchRequest_CancelRequest: - wps.delete(uv.CancelRequest.WatchId) - default: - panic("not implemented") - } - } -} - -func (wps *watchProxyStream) sendLoop() { - for { - select { - case wresp, ok := <-wps.watchCh: - if !ok { - return - } - if err := wps.stream.Send(wresp); err != nil { - return - } - case <-wps.ctx.Done(): - return - } - } -} - -func (wps *watchProxyStream) delete(id int64) { - wps.mu.Lock() - defer wps.mu.Unlock() - - w, ok := wps.watchers[id] - if !ok { - return - } - wps.ranges.delete(w) - delete(wps.watchers, id) - resp := &pb.WatchResponse{ - Header: &w.lastHeader, - WatchId: id, - Canceled: true, - } - wps.watchCh <- resp -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/watch_broadcast.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/watch_broadcast.go deleted file mode 100644 index 46e56c79a9d8..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/watch_broadcast.go +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - "sync" - - "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -// watchBroadcast broadcasts a server watcher to many client watchers. -type watchBroadcast struct { - // cancel stops the underlying etcd server watcher and closes ch. - cancel context.CancelFunc - donec chan struct{} - - // mu protects rev and receivers. - mu sync.RWMutex - // nextrev is the minimum expected next revision of the watcher on ch. - nextrev int64 - // receivers contains all the client-side watchers to serve. - receivers map[*watcher]struct{} - // responses counts the number of responses - responses int -} - -func newWatchBroadcast(wp *watchProxy, w *watcher, update func(*watchBroadcast)) *watchBroadcast { - cctx, cancel := context.WithCancel(wp.ctx) - wb := &watchBroadcast{ - cancel: cancel, - nextrev: w.nextrev, - receivers: make(map[*watcher]struct{}), - donec: make(chan struct{}), - } - wb.add(w) - go func() { - defer close(wb.donec) - - opts := []clientv3.OpOption{ - clientv3.WithRange(w.wr.end), - clientv3.WithProgressNotify(), - clientv3.WithRev(wb.nextrev), - clientv3.WithPrevKV(), - clientv3.WithCreatedNotify(), - } - - cctx = withClientAuthToken(cctx, w.wps.stream.Context()) - - wch := wp.cw.Watch(cctx, w.wr.key, opts...) - - for wr := range wch { - wb.bcast(wr) - update(wb) - } - }() - return wb -} - -func (wb *watchBroadcast) bcast(wr clientv3.WatchResponse) { - wb.mu.Lock() - defer wb.mu.Unlock() - // watchers start on the given revision, if any; ignore header rev on create - if wb.responses > 0 || wb.nextrev == 0 { - wb.nextrev = wr.Header.Revision + 1 - } - wb.responses++ - for r := range wb.receivers { - r.send(wr) - } - if len(wb.receivers) > 0 { - eventsCoalescing.Add(float64(len(wb.receivers) - 1)) - } -} - -// add puts a watcher into receiving a broadcast if its revision at least -// meets the broadcast revision. Returns true if added. -func (wb *watchBroadcast) add(w *watcher) bool { - wb.mu.Lock() - defer wb.mu.Unlock() - if wb.nextrev > w.nextrev || (wb.nextrev == 0 && w.nextrev != 0) { - // wb is too far ahead, w will miss events - // or wb is being established with a current watcher - return false - } - if wb.responses == 0 { - // Newly created; create event will be sent by etcd. - wb.receivers[w] = struct{}{} - return true - } - // already sent by etcd; emulate create event - ok := w.post(&pb.WatchResponse{ - Header: &pb.ResponseHeader{ - // todo: fill in ClusterId - // todo: fill in MemberId: - Revision: w.nextrev, - // todo: fill in RaftTerm: - }, - WatchId: w.id, - Created: true, - }) - if !ok { - return false - } - wb.receivers[w] = struct{}{} - watchersCoalescing.Inc() - - return true -} -func (wb *watchBroadcast) delete(w *watcher) { - wb.mu.Lock() - defer wb.mu.Unlock() - if _, ok := wb.receivers[w]; !ok { - panic("deleting missing watcher from broadcast") - } - delete(wb.receivers, w) - if len(wb.receivers) > 0 { - // do not dec the only left watcher for coalescing. - watchersCoalescing.Dec() - } -} - -func (wb *watchBroadcast) size() int { - wb.mu.RLock() - defer wb.mu.RUnlock() - return len(wb.receivers) -} - -func (wb *watchBroadcast) empty() bool { return wb.size() == 0 } - -func (wb *watchBroadcast) stop() { - if !wb.empty() { - // do not dec the only left watcher for coalescing. - watchersCoalescing.Sub(float64(wb.size() - 1)) - } - - wb.cancel() - <-wb.donec -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/watch_broadcasts.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/watch_broadcasts.go deleted file mode 100644 index 8fe9e5f512e5..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/watch_broadcasts.go +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "sync" -) - -type watchBroadcasts struct { - wp *watchProxy - - // mu protects bcasts and watchers from the coalesce loop. - mu sync.Mutex - bcasts map[*watchBroadcast]struct{} - watchers map[*watcher]*watchBroadcast - - updatec chan *watchBroadcast - donec chan struct{} -} - -// maxCoalesceRecievers prevents a popular watchBroadcast from being coalseced. -const maxCoalesceReceivers = 5 - -func newWatchBroadcasts(wp *watchProxy) *watchBroadcasts { - wbs := &watchBroadcasts{ - wp: wp, - bcasts: make(map[*watchBroadcast]struct{}), - watchers: make(map[*watcher]*watchBroadcast), - updatec: make(chan *watchBroadcast, 1), - donec: make(chan struct{}), - } - go func() { - defer close(wbs.donec) - for wb := range wbs.updatec { - wbs.coalesce(wb) - } - }() - return wbs -} - -func (wbs *watchBroadcasts) coalesce(wb *watchBroadcast) { - if wb.size() >= maxCoalesceReceivers { - return - } - wbs.mu.Lock() - for wbswb := range wbs.bcasts { - if wbswb == wb { - continue - } - wb.mu.Lock() - wbswb.mu.Lock() - // 1. check if wbswb is behind wb so it won't skip any events in wb - // 2. ensure wbswb started; nextrev == 0 may mean wbswb is waiting - // for a current watcher and expects a create event from the server. - if wb.nextrev >= wbswb.nextrev && wbswb.responses > 0 { - for w := range wb.receivers { - wbswb.receivers[w] = struct{}{} - wbs.watchers[w] = wbswb - } - wb.receivers = nil - } - wbswb.mu.Unlock() - wb.mu.Unlock() - if wb.empty() { - delete(wbs.bcasts, wb) - wb.stop() - break - } - } - wbs.mu.Unlock() -} - -func (wbs *watchBroadcasts) add(w *watcher) { - wbs.mu.Lock() - defer wbs.mu.Unlock() - // find fitting bcast - for wb := range wbs.bcasts { - if wb.add(w) { - wbs.watchers[w] = wb - return - } - } - // no fit; create a bcast - wb := newWatchBroadcast(wbs.wp, w, wbs.update) - wbs.watchers[w] = wb - wbs.bcasts[wb] = struct{}{} -} - -// delete removes a watcher and returns the number of remaining watchers. -func (wbs *watchBroadcasts) delete(w *watcher) int { - wbs.mu.Lock() - defer wbs.mu.Unlock() - - wb, ok := wbs.watchers[w] - if !ok { - panic("deleting missing watcher from broadcasts") - } - delete(wbs.watchers, w) - wb.delete(w) - if wb.empty() { - delete(wbs.bcasts, wb) - wb.stop() - } - return len(wbs.bcasts) -} - -func (wbs *watchBroadcasts) stop() { - wbs.mu.Lock() - for wb := range wbs.bcasts { - wb.stop() - } - wbs.bcasts = nil - close(wbs.updatec) - wbs.mu.Unlock() - <-wbs.donec -} - -func (wbs *watchBroadcasts) update(wb *watchBroadcast) { - select { - case wbs.updatec <- wb: - default: - } -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/watch_ranges.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/watch_ranges.go deleted file mode 100644 index 31c6b5925eae..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/watch_ranges.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "sync" -) - -// watchRanges tracks all open watches for the proxy. -type watchRanges struct { - wp *watchProxy - - mu sync.Mutex - bcasts map[watchRange]*watchBroadcasts -} - -func newWatchRanges(wp *watchProxy) *watchRanges { - return &watchRanges{ - wp: wp, - bcasts: make(map[watchRange]*watchBroadcasts), - } -} - -func (wrs *watchRanges) add(w *watcher) { - wrs.mu.Lock() - defer wrs.mu.Unlock() - - if wbs := wrs.bcasts[w.wr]; wbs != nil { - wbs.add(w) - return - } - wbs := newWatchBroadcasts(wrs.wp) - wrs.bcasts[w.wr] = wbs - wbs.add(w) -} - -func (wrs *watchRanges) delete(w *watcher) { - wrs.mu.Lock() - defer wrs.mu.Unlock() - wbs, ok := wrs.bcasts[w.wr] - if !ok { - panic("deleting missing range") - } - if wbs.delete(w) == 0 { - wbs.stop() - delete(wrs.bcasts, w.wr) - } -} - -func (wrs *watchRanges) stop() { - wrs.mu.Lock() - defer wrs.mu.Unlock() - for _, wb := range wrs.bcasts { - wb.stop() - } - wrs.bcasts = nil -} diff --git a/vendor/github.com/coreos/etcd/proxy/grpcproxy/watcher.go b/vendor/github.com/coreos/etcd/proxy/grpcproxy/watcher.go deleted file mode 100644 index 1a497462f99b..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/grpcproxy/watcher.go +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "time" - - "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -type watchRange struct { - key, end string -} - -func (wr *watchRange) valid() bool { - return len(wr.end) == 0 || wr.end > wr.key || (wr.end[0] == 0 && len(wr.end) == 1) -} - -type watcher struct { - // user configuration - - wr watchRange - filters []mvcc.FilterFunc - progress bool - prevKV bool - - // id is the id returned to the client on its watch stream. - id int64 - // nextrev is the minimum expected next event revision. - nextrev int64 - // lastHeader has the last header sent over the stream. - lastHeader pb.ResponseHeader - - // wps is the parent. - wps *watchProxyStream -} - -// send filters out repeated events by discarding revisions older -// than the last one sent over the watch channel. -func (w *watcher) send(wr clientv3.WatchResponse) { - if wr.IsProgressNotify() && !w.progress { - return - } - if w.nextrev > wr.Header.Revision && len(wr.Events) > 0 { - return - } - if w.nextrev == 0 { - // current watch; expect updates following this revision - w.nextrev = wr.Header.Revision + 1 - } - - events := make([]*mvccpb.Event, 0, len(wr.Events)) - - var lastRev int64 - for i := range wr.Events { - ev := (*mvccpb.Event)(wr.Events[i]) - if ev.Kv.ModRevision < w.nextrev { - continue - } else { - // We cannot update w.rev here. - // txn can have multiple events with the same rev. - // If w.nextrev updates here, it would skip events in the same txn. - lastRev = ev.Kv.ModRevision - } - - filtered := false - for _, filter := range w.filters { - if filter(*ev) { - filtered = true - break - } - } - if filtered { - continue - } - - if !w.prevKV { - evCopy := *ev - evCopy.PrevKv = nil - ev = &evCopy - } - events = append(events, ev) - } - - if lastRev >= w.nextrev { - w.nextrev = lastRev + 1 - } - - // all events are filtered out? - if !wr.IsProgressNotify() && !wr.Created && len(events) == 0 && wr.CompactRevision == 0 { - return - } - - w.lastHeader = wr.Header - w.post(&pb.WatchResponse{ - Header: &wr.Header, - Created: wr.Created, - CompactRevision: wr.CompactRevision, - Canceled: wr.Canceled, - WatchId: w.id, - Events: events, - }) -} - -// post puts a watch response on the watcher's proxy stream channel -func (w *watcher) post(wr *pb.WatchResponse) bool { - select { - case w.wps.watchCh <- wr: - case <-time.After(50 * time.Millisecond): - w.wps.cancel() - return false - } - return true -} diff --git a/vendor/github.com/coreos/etcd/proxy/httpproxy/director.go b/vendor/github.com/coreos/etcd/proxy/httpproxy/director.go deleted file mode 100644 index d414501335dd..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/httpproxy/director.go +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package httpproxy - -import ( - "math/rand" - "net/url" - "sync" - "time" -) - -// defaultRefreshInterval is the default proxyRefreshIntervalMs value -// as in etcdmain/config.go. -const defaultRefreshInterval = 30000 * time.Millisecond - -var once sync.Once - -func init() { - rand.Seed(time.Now().UnixNano()) -} - -func newDirector(urlsFunc GetProxyURLs, failureWait time.Duration, refreshInterval time.Duration) *director { - d := &director{ - uf: urlsFunc, - failureWait: failureWait, - } - d.refresh() - go func() { - // In order to prevent missing proxy endpoints in the first try: - // when given refresh interval of defaultRefreshInterval or greater - // and whenever there is no available proxy endpoints, - // give 1-second refreshInterval. - for { - es := d.endpoints() - ri := refreshInterval - if ri >= defaultRefreshInterval { - if len(es) == 0 { - ri = time.Second - } - } - if len(es) > 0 { - once.Do(func() { - var sl []string - for _, e := range es { - sl = append(sl, e.URL.String()) - } - plog.Infof("endpoints found %q", sl) - }) - } - time.Sleep(ri) - d.refresh() - } - }() - return d -} - -type director struct { - sync.Mutex - ep []*endpoint - uf GetProxyURLs - failureWait time.Duration -} - -func (d *director) refresh() { - urls := d.uf() - d.Lock() - defer d.Unlock() - var endpoints []*endpoint - for _, u := range urls { - uu, err := url.Parse(u) - if err != nil { - plog.Printf("upstream URL invalid: %v", err) - continue - } - endpoints = append(endpoints, newEndpoint(*uu, d.failureWait)) - } - - // shuffle array to avoid connections being "stuck" to a single endpoint - for i := range endpoints { - j := rand.Intn(i + 1) - endpoints[i], endpoints[j] = endpoints[j], endpoints[i] - } - - d.ep = endpoints -} - -func (d *director) endpoints() []*endpoint { - d.Lock() - defer d.Unlock() - filtered := make([]*endpoint, 0) - for _, ep := range d.ep { - if ep.Available { - filtered = append(filtered, ep) - } - } - - return filtered -} - -func newEndpoint(u url.URL, failureWait time.Duration) *endpoint { - ep := endpoint{ - URL: u, - Available: true, - failFunc: timedUnavailabilityFunc(failureWait), - } - - return &ep -} - -type endpoint struct { - sync.Mutex - - URL url.URL - Available bool - - failFunc func(ep *endpoint) -} - -func (ep *endpoint) Failed() { - ep.Lock() - if !ep.Available { - ep.Unlock() - return - } - - ep.Available = false - ep.Unlock() - - plog.Printf("marked endpoint %s unavailable", ep.URL.String()) - - if ep.failFunc == nil { - plog.Printf("no failFunc defined, endpoint %s will be unavailable forever.", ep.URL.String()) - return - } - - ep.failFunc(ep) -} - -func timedUnavailabilityFunc(wait time.Duration) func(*endpoint) { - return func(ep *endpoint) { - time.AfterFunc(wait, func() { - ep.Available = true - plog.Printf("marked endpoint %s available, to retest connectivity", ep.URL.String()) - }) - } -} diff --git a/vendor/github.com/coreos/etcd/proxy/httpproxy/doc.go b/vendor/github.com/coreos/etcd/proxy/httpproxy/doc.go deleted file mode 100644 index 7a45099120cb..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/httpproxy/doc.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package httpproxy implements etcd httpproxy. The etcd proxy acts as a reverse -// http proxy forwarding client requests to active etcd cluster members, and does -// not participate in consensus. -package httpproxy diff --git a/vendor/github.com/coreos/etcd/proxy/httpproxy/metrics.go b/vendor/github.com/coreos/etcd/proxy/httpproxy/metrics.go deleted file mode 100644 index f71258cba57b..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/httpproxy/metrics.go +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package httpproxy - -import ( - "net/http" - "strconv" - "time" - - "github.com/prometheus/client_golang/prometheus" -) - -var ( - requestsIncoming = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "proxy", - Name: "requests_total", - Help: "Counter requests incoming by method.", - }, []string{"method"}) - - requestsHandled = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "proxy", - Name: "handled_total", - Help: "Counter of requests fully handled (by authoratitave servers)", - }, []string{"method", "code"}) - - requestsDropped = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "proxy", - Name: "dropped_total", - Help: "Counter of requests dropped on the proxy.", - }, []string{"method", "proxying_error"}) - - requestsHandlingTime = prometheus.NewHistogramVec( - prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "proxy", - Name: "handling_duration_seconds", - Help: "Bucketed histogram of handling time of successful events (non-watches), by method " + - "(GET/PUT etc.).", - Buckets: prometheus.ExponentialBuckets(0.0005, 2, 13), - }, []string{"method"}) -) - -type forwardingError string - -const ( - zeroEndpoints forwardingError = "zero_endpoints" - failedSendingRequest forwardingError = "failed_sending_request" - failedGettingResponse forwardingError = "failed_getting_response" -) - -func init() { - prometheus.MustRegister(requestsIncoming) - prometheus.MustRegister(requestsHandled) - prometheus.MustRegister(requestsDropped) - prometheus.MustRegister(requestsHandlingTime) -} - -func reportIncomingRequest(request *http.Request) { - requestsIncoming.WithLabelValues(request.Method).Inc() -} - -func reportRequestHandled(request *http.Request, response *http.Response, startTime time.Time) { - method := request.Method - requestsHandled.WithLabelValues(method, strconv.Itoa(response.StatusCode)).Inc() - requestsHandlingTime.WithLabelValues(method).Observe(time.Since(startTime).Seconds()) -} - -func reportRequestDropped(request *http.Request, err forwardingError) { - requestsDropped.WithLabelValues(request.Method, string(err)).Inc() -} diff --git a/vendor/github.com/coreos/etcd/proxy/httpproxy/proxy.go b/vendor/github.com/coreos/etcd/proxy/httpproxy/proxy.go deleted file mode 100644 index 3cd3161f3461..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/httpproxy/proxy.go +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package httpproxy - -import ( - "encoding/json" - "net/http" - "strings" - "time" - - "golang.org/x/net/http2" -) - -const ( - // DefaultMaxIdleConnsPerHost indicates the default maximum idle connection - // count maintained between proxy and each member. We set it to 128 to - // let proxy handle 128 concurrent requests in long term smoothly. - // If the number of concurrent requests is bigger than this value, - // proxy needs to create one new connection when handling each request in - // the delta, which is bad because the creation consumes resource and - // may eat up ephemeral ports. - DefaultMaxIdleConnsPerHost = 128 -) - -// GetProxyURLs is a function which should return the current set of URLs to -// which client requests should be proxied. This function will be queried -// periodically by the proxy Handler to refresh the set of available -// backends. -type GetProxyURLs func() []string - -// NewHandler creates a new HTTP handler, listening on the given transport, -// which will proxy requests to an etcd cluster. -// The handler will periodically update its view of the cluster. -func NewHandler(t *http.Transport, urlsFunc GetProxyURLs, failureWait time.Duration, refreshInterval time.Duration) http.Handler { - if t.TLSClientConfig != nil { - // Enable http2, see Issue 5033. - err := http2.ConfigureTransport(t) - if err != nil { - plog.Infof("Error enabling Transport HTTP/2 support: %v", err) - } - } - - p := &reverseProxy{ - director: newDirector(urlsFunc, failureWait, refreshInterval), - transport: t, - } - - mux := http.NewServeMux() - mux.Handle("/", p) - mux.HandleFunc("/v2/config/local/proxy", p.configHandler) - - return mux -} - -// NewReadonlyHandler wraps the given HTTP handler to allow only GET requests -func NewReadonlyHandler(hdlr http.Handler) http.Handler { - readonly := readonlyHandlerFunc(hdlr) - return http.HandlerFunc(readonly) -} - -func readonlyHandlerFunc(next http.Handler) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, req *http.Request) { - if req.Method != "GET" { - w.WriteHeader(http.StatusNotImplemented) - return - } - - next.ServeHTTP(w, req) - } -} - -func (p *reverseProxy) configHandler(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET") { - return - } - - eps := p.director.endpoints() - epstr := make([]string, len(eps)) - for i, e := range eps { - epstr[i] = e.URL.String() - } - - proxyConfig := struct { - Endpoints []string `json:"endpoints"` - }{ - Endpoints: epstr, - } - - json.NewEncoder(w).Encode(proxyConfig) -} - -// allowMethod verifies that the given method is one of the allowed methods, -// and if not, it writes an error to w. A boolean is returned indicating -// whether or not the method is allowed. -func allowMethod(w http.ResponseWriter, m string, ms ...string) bool { - for _, meth := range ms { - if m == meth { - return true - } - } - w.Header().Set("Allow", strings.Join(ms, ",")) - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return false -} diff --git a/vendor/github.com/coreos/etcd/proxy/httpproxy/reverse.go b/vendor/github.com/coreos/etcd/proxy/httpproxy/reverse.go deleted file mode 100644 index 2ecff3aaea94..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/httpproxy/reverse.go +++ /dev/null @@ -1,208 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package httpproxy - -import ( - "bytes" - "context" - "fmt" - "io" - "io/ioutil" - "net" - "net/http" - "net/url" - "strings" - "sync/atomic" - "time" - - "github.com/coreos/etcd/etcdserver/api/v2http/httptypes" - "github.com/coreos/pkg/capnslog" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "proxy/httpproxy") - - // Hop-by-hop headers. These are removed when sent to the backend. - // http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html - // This list of headers borrowed from stdlib httputil.ReverseProxy - singleHopHeaders = []string{ - "Connection", - "Keep-Alive", - "Proxy-Authenticate", - "Proxy-Authorization", - "Te", // canonicalized version of "TE" - "Trailers", - "Transfer-Encoding", - "Upgrade", - } -) - -func removeSingleHopHeaders(hdrs *http.Header) { - for _, h := range singleHopHeaders { - hdrs.Del(h) - } -} - -type reverseProxy struct { - director *director - transport http.RoundTripper -} - -func (p *reverseProxy) ServeHTTP(rw http.ResponseWriter, clientreq *http.Request) { - reportIncomingRequest(clientreq) - proxyreq := new(http.Request) - *proxyreq = *clientreq - startTime := time.Now() - - var ( - proxybody []byte - err error - ) - - if clientreq.Body != nil { - proxybody, err = ioutil.ReadAll(clientreq.Body) - if err != nil { - msg := fmt.Sprintf("failed to read request body: %v", err) - plog.Println(msg) - e := httptypes.NewHTTPError(http.StatusInternalServerError, "httpproxy: "+msg) - if we := e.WriteTo(rw); we != nil { - plog.Debugf("error writing HTTPError (%v) to %s", we, clientreq.RemoteAddr) - } - return - } - } - - // deep-copy the headers, as these will be modified below - proxyreq.Header = make(http.Header) - copyHeader(proxyreq.Header, clientreq.Header) - - normalizeRequest(proxyreq) - removeSingleHopHeaders(&proxyreq.Header) - maybeSetForwardedFor(proxyreq) - - endpoints := p.director.endpoints() - if len(endpoints) == 0 { - msg := "zero endpoints currently available" - reportRequestDropped(clientreq, zeroEndpoints) - - // TODO: limit the rate of the error logging. - plog.Println(msg) - e := httptypes.NewHTTPError(http.StatusServiceUnavailable, "httpproxy: "+msg) - if we := e.WriteTo(rw); we != nil { - plog.Debugf("error writing HTTPError (%v) to %s", we, clientreq.RemoteAddr) - } - return - } - - var requestClosed int32 - completeCh := make(chan bool, 1) - closeNotifier, ok := rw.(http.CloseNotifier) - ctx, cancel := context.WithCancel(context.Background()) - proxyreq = proxyreq.WithContext(ctx) - defer cancel() - if ok { - closeCh := closeNotifier.CloseNotify() - go func() { - select { - case <-closeCh: - atomic.StoreInt32(&requestClosed, 1) - plog.Printf("client %v closed request prematurely", clientreq.RemoteAddr) - cancel() - case <-completeCh: - } - }() - - defer func() { - completeCh <- true - }() - } - - var res *http.Response - - for _, ep := range endpoints { - if proxybody != nil { - proxyreq.Body = ioutil.NopCloser(bytes.NewBuffer(proxybody)) - } - redirectRequest(proxyreq, ep.URL) - - res, err = p.transport.RoundTrip(proxyreq) - if atomic.LoadInt32(&requestClosed) == 1 { - return - } - if err != nil { - reportRequestDropped(clientreq, failedSendingRequest) - plog.Printf("failed to direct request to %s: %v", ep.URL.String(), err) - ep.Failed() - continue - } - - break - } - - if res == nil { - // TODO: limit the rate of the error logging. - msg := fmt.Sprintf("unable to get response from %d endpoint(s)", len(endpoints)) - reportRequestDropped(clientreq, failedGettingResponse) - plog.Println(msg) - e := httptypes.NewHTTPError(http.StatusBadGateway, "httpproxy: "+msg) - if we := e.WriteTo(rw); we != nil { - plog.Debugf("error writing HTTPError (%v) to %s", we, clientreq.RemoteAddr) - } - return - } - - defer res.Body.Close() - reportRequestHandled(clientreq, res, startTime) - removeSingleHopHeaders(&res.Header) - copyHeader(rw.Header(), res.Header) - - rw.WriteHeader(res.StatusCode) - io.Copy(rw, res.Body) -} - -func copyHeader(dst, src http.Header) { - for k, vv := range src { - for _, v := range vv { - dst.Add(k, v) - } - } -} - -func redirectRequest(req *http.Request, loc url.URL) { - req.URL.Scheme = loc.Scheme - req.URL.Host = loc.Host -} - -func normalizeRequest(req *http.Request) { - req.Proto = "HTTP/1.1" - req.ProtoMajor = 1 - req.ProtoMinor = 1 - req.Close = false -} - -func maybeSetForwardedFor(req *http.Request) { - clientIP, _, err := net.SplitHostPort(req.RemoteAddr) - if err != nil { - return - } - - // If we aren't the first proxy retain prior - // X-Forwarded-For information as a comma+space - // separated list and fold multiple headers into one. - if prior, ok := req.Header["X-Forwarded-For"]; ok { - clientIP = strings.Join(prior, ", ") + ", " + clientIP - } - req.Header.Set("X-Forwarded-For", clientIP) -} diff --git a/vendor/github.com/coreos/etcd/proxy/tcpproxy/doc.go b/vendor/github.com/coreos/etcd/proxy/tcpproxy/doc.go deleted file mode 100644 index 6889cacb63ef..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/tcpproxy/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package tcpproxy is an OSI level 4 proxy for routing etcd clients to etcd servers. -package tcpproxy diff --git a/vendor/github.com/coreos/etcd/proxy/tcpproxy/userspace.go b/vendor/github.com/coreos/etcd/proxy/tcpproxy/userspace.go deleted file mode 100644 index 6dc1d1d6d92a..000000000000 --- a/vendor/github.com/coreos/etcd/proxy/tcpproxy/userspace.go +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tcpproxy - -import ( - "fmt" - "io" - "math/rand" - "net" - "sync" - "time" - - "github.com/coreos/pkg/capnslog" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "proxy/tcpproxy") -) - -type remote struct { - mu sync.Mutex - srv *net.SRV - addr string - inactive bool -} - -func (r *remote) inactivate() { - r.mu.Lock() - defer r.mu.Unlock() - r.inactive = true -} - -func (r *remote) tryReactivate() error { - conn, err := net.Dial("tcp", r.addr) - if err != nil { - return err - } - conn.Close() - r.mu.Lock() - defer r.mu.Unlock() - r.inactive = false - return nil -} - -func (r *remote) isActive() bool { - r.mu.Lock() - defer r.mu.Unlock() - return !r.inactive -} - -type TCPProxy struct { - Listener net.Listener - Endpoints []*net.SRV - MonitorInterval time.Duration - - donec chan struct{} - - mu sync.Mutex // guards the following fields - remotes []*remote - pickCount int // for round robin -} - -func (tp *TCPProxy) Run() error { - tp.donec = make(chan struct{}) - if tp.MonitorInterval == 0 { - tp.MonitorInterval = 5 * time.Minute - } - for _, srv := range tp.Endpoints { - addr := fmt.Sprintf("%s:%d", srv.Target, srv.Port) - tp.remotes = append(tp.remotes, &remote{srv: srv, addr: addr}) - } - - eps := []string{} - for _, ep := range tp.Endpoints { - eps = append(eps, fmt.Sprintf("%s:%d", ep.Target, ep.Port)) - } - plog.Printf("ready to proxy client requests to %+v", eps) - - go tp.runMonitor() - for { - in, err := tp.Listener.Accept() - if err != nil { - return err - } - - go tp.serve(in) - } -} - -func (tp *TCPProxy) pick() *remote { - var weighted []*remote - var unweighted []*remote - - bestPr := uint16(65535) - w := 0 - // find best priority class - for _, r := range tp.remotes { - switch { - case !r.isActive(): - case r.srv.Priority < bestPr: - bestPr = r.srv.Priority - w = 0 - weighted = nil - unweighted = []*remote{r} - fallthrough - case r.srv.Priority == bestPr: - if r.srv.Weight > 0 { - weighted = append(weighted, r) - w += int(r.srv.Weight) - } else { - unweighted = append(unweighted, r) - } - } - } - if weighted != nil { - if len(unweighted) > 0 && rand.Intn(100) == 1 { - // In the presence of records containing weights greater - // than 0, records with weight 0 should have a very small - // chance of being selected. - r := unweighted[tp.pickCount%len(unweighted)] - tp.pickCount++ - return r - } - // choose a uniform random number between 0 and the sum computed - // (inclusive), and select the RR whose running sum value is the - // first in the selected order - choose := rand.Intn(w) - for i := 0; i < len(weighted); i++ { - choose -= int(weighted[i].srv.Weight) - if choose <= 0 { - return weighted[i] - } - } - } - if unweighted != nil { - for i := 0; i < len(tp.remotes); i++ { - picked := tp.remotes[tp.pickCount%len(tp.remotes)] - tp.pickCount++ - if picked.isActive() { - return picked - } - } - } - return nil -} - -func (tp *TCPProxy) serve(in net.Conn) { - var ( - err error - out net.Conn - ) - - for { - tp.mu.Lock() - remote := tp.pick() - tp.mu.Unlock() - if remote == nil { - break - } - // TODO: add timeout - out, err = net.Dial("tcp", remote.addr) - if err == nil { - break - } - remote.inactivate() - plog.Warningf("deactivated endpoint [%s] due to %v for %v", remote.addr, err, tp.MonitorInterval) - } - - if out == nil { - in.Close() - return - } - - go func() { - io.Copy(in, out) - in.Close() - out.Close() - }() - - io.Copy(out, in) - out.Close() - in.Close() -} - -func (tp *TCPProxy) runMonitor() { - for { - select { - case <-time.After(tp.MonitorInterval): - tp.mu.Lock() - for _, rem := range tp.remotes { - if rem.isActive() { - continue - } - go func(r *remote) { - if err := r.tryReactivate(); err != nil { - plog.Warningf("failed to activate endpoint [%s] due to %v (stay inactive for another %v)", r.addr, err, tp.MonitorInterval) - } else { - plog.Printf("activated %s", r.addr) - } - }(rem) - } - tp.mu.Unlock() - case <-tp.donec: - return - } - } -} - -func (tp *TCPProxy) Stop() { - // graceful shutdown? - // shutdown current connections? - tp.Listener.Close() - close(tp.donec) -} diff --git a/vendor/github.com/coreos/etcd/raft/doc.go b/vendor/github.com/coreos/etcd/raft/doc.go deleted file mode 100644 index b55c591ff5d7..000000000000 --- a/vendor/github.com/coreos/etcd/raft/doc.go +++ /dev/null @@ -1,300 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package raft sends and receives messages in the Protocol Buffer format -defined in the raftpb package. - -Raft is a protocol with which a cluster of nodes can maintain a replicated state machine. -The state machine is kept in sync through the use of a replicated log. -For more details on Raft, see "In Search of an Understandable Consensus Algorithm" -(https://ramcloud.stanford.edu/raft.pdf) by Diego Ongaro and John Ousterhout. - -A simple example application, _raftexample_, is also available to help illustrate -how to use this package in practice: -https://github.com/coreos/etcd/tree/master/contrib/raftexample - -Usage - -The primary object in raft is a Node. You either start a Node from scratch -using raft.StartNode or start a Node from some initial state using raft.RestartNode. - -To start a node from scratch: - - storage := raft.NewMemoryStorage() - c := &Config{ - ID: 0x01, - ElectionTick: 10, - HeartbeatTick: 1, - Storage: storage, - MaxSizePerMsg: 4096, - MaxInflightMsgs: 256, - } - n := raft.StartNode(c, []raft.Peer{{ID: 0x02}, {ID: 0x03}}) - -To restart a node from previous state: - - storage := raft.NewMemoryStorage() - - // recover the in-memory storage from persistent - // snapshot, state and entries. - storage.ApplySnapshot(snapshot) - storage.SetHardState(state) - storage.Append(entries) - - c := &Config{ - ID: 0x01, - ElectionTick: 10, - HeartbeatTick: 1, - Storage: storage, - MaxSizePerMsg: 4096, - MaxInflightMsgs: 256, - } - - // restart raft without peer information. - // peer information is already included in the storage. - n := raft.RestartNode(c) - -Now that you are holding onto a Node you have a few responsibilities: - -First, you must read from the Node.Ready() channel and process the updates -it contains. These steps may be performed in parallel, except as noted in step -2. - -1. Write HardState, Entries, and Snapshot to persistent storage if they are -not empty. Note that when writing an Entry with Index i, any -previously-persisted entries with Index >= i must be discarded. - -2. Send all Messages to the nodes named in the To field. It is important that -no messages be sent until the latest HardState has been persisted to disk, -and all Entries written by any previous Ready batch (Messages may be sent while -entries from the same batch are being persisted). To reduce the I/O latency, an -optimization can be applied to make leader write to disk in parallel with its -followers (as explained at section 10.2.1 in Raft thesis). If any Message has type -MsgSnap, call Node.ReportSnapshot() after it has been sent (these messages may be -large). - -Note: Marshalling messages is not thread-safe; it is important that you -make sure that no new entries are persisted while marshalling. -The easiest way to achieve this is to serialise the messages directly inside -your main raft loop. - -3. Apply Snapshot (if any) and CommittedEntries to the state machine. -If any committed Entry has Type EntryConfChange, call Node.ApplyConfChange() -to apply it to the node. The configuration change may be cancelled at this point -by setting the NodeID field to zero before calling ApplyConfChange -(but ApplyConfChange must be called one way or the other, and the decision to cancel -must be based solely on the state machine and not external information such as -the observed health of the node). - -4. Call Node.Advance() to signal readiness for the next batch of updates. -This may be done at any time after step 1, although all updates must be processed -in the order they were returned by Ready. - -Second, all persisted log entries must be made available via an -implementation of the Storage interface. The provided MemoryStorage -type can be used for this (if you repopulate its state upon a -restart), or you can supply your own disk-backed implementation. - -Third, when you receive a message from another node, pass it to Node.Step: - - func recvRaftRPC(ctx context.Context, m raftpb.Message) { - n.Step(ctx, m) - } - -Finally, you need to call Node.Tick() at regular intervals (probably -via a time.Ticker). Raft has two important timeouts: heartbeat and the -election timeout. However, internally to the raft package time is -represented by an abstract "tick". - -The total state machine handling loop will look something like this: - - for { - select { - case <-s.Ticker: - n.Tick() - case rd := <-s.Node.Ready(): - saveToStorage(rd.State, rd.Entries, rd.Snapshot) - send(rd.Messages) - if !raft.IsEmptySnap(rd.Snapshot) { - processSnapshot(rd.Snapshot) - } - for _, entry := range rd.CommittedEntries { - process(entry) - if entry.Type == raftpb.EntryConfChange { - var cc raftpb.ConfChange - cc.Unmarshal(entry.Data) - s.Node.ApplyConfChange(cc) - } - } - s.Node.Advance() - case <-s.done: - return - } - } - -To propose changes to the state machine from your node take your application -data, serialize it into a byte slice and call: - - n.Propose(ctx, data) - -If the proposal is committed, data will appear in committed entries with type -raftpb.EntryNormal. There is no guarantee that a proposed command will be -committed; you may have to re-propose after a timeout. - -To add or remove node in a cluster, build ConfChange struct 'cc' and call: - - n.ProposeConfChange(ctx, cc) - -After config change is committed, some committed entry with type -raftpb.EntryConfChange will be returned. You must apply it to node through: - - var cc raftpb.ConfChange - cc.Unmarshal(data) - n.ApplyConfChange(cc) - -Note: An ID represents a unique node in a cluster for all time. A -given ID MUST be used only once even if the old node has been removed. -This means that for example IP addresses make poor node IDs since they -may be reused. Node IDs must be non-zero. - -Implementation notes - -This implementation is up to date with the final Raft thesis -(https://ramcloud.stanford.edu/~ongaro/thesis.pdf), although our -implementation of the membership change protocol differs somewhat from -that described in chapter 4. The key invariant that membership changes -happen one node at a time is preserved, but in our implementation the -membership change takes effect when its entry is applied, not when it -is added to the log (so the entry is committed under the old -membership instead of the new). This is equivalent in terms of safety, -since the old and new configurations are guaranteed to overlap. - -To ensure that we do not attempt to commit two membership changes at -once by matching log positions (which would be unsafe since they -should have different quorum requirements), we simply disallow any -proposed membership change while any uncommitted change appears in -the leader's log. - -This approach introduces a problem when you try to remove a member -from a two-member cluster: If one of the members dies before the -other one receives the commit of the confchange entry, then the member -cannot be removed any more since the cluster cannot make progress. -For this reason it is highly recommended to use three or more nodes in -every cluster. - -MessageType - -Package raft sends and receives message in Protocol Buffer format (defined -in raftpb package). Each state (follower, candidate, leader) implements its -own 'step' method ('stepFollower', 'stepCandidate', 'stepLeader') when -advancing with the given raftpb.Message. Each step is determined by its -raftpb.MessageType. Note that every step is checked by one common method -'Step' that safety-checks the terms of node and incoming message to prevent -stale log entries: - - 'MsgHup' is used for election. If a node is a follower or candidate, the - 'tick' function in 'raft' struct is set as 'tickElection'. If a follower or - candidate has not received any heartbeat before the election timeout, it - passes 'MsgHup' to its Step method and becomes (or remains) a candidate to - start a new election. - - 'MsgBeat' is an internal type that signals the leader to send a heartbeat of - the 'MsgHeartbeat' type. If a node is a leader, the 'tick' function in - the 'raft' struct is set as 'tickHeartbeat', and triggers the leader to - send periodic 'MsgHeartbeat' messages to its followers. - - 'MsgProp' proposes to append data to its log entries. This is a special - type to redirect proposals to leader. Therefore, send method overwrites - raftpb.Message's term with its HardState's term to avoid attaching its - local term to 'MsgProp'. When 'MsgProp' is passed to the leader's 'Step' - method, the leader first calls the 'appendEntry' method to append entries - to its log, and then calls 'bcastAppend' method to send those entries to - its peers. When passed to candidate, 'MsgProp' is dropped. When passed to - follower, 'MsgProp' is stored in follower's mailbox(msgs) by the send - method. It is stored with sender's ID and later forwarded to leader by - rafthttp package. - - 'MsgApp' contains log entries to replicate. A leader calls bcastAppend, - which calls sendAppend, which sends soon-to-be-replicated logs in 'MsgApp' - type. When 'MsgApp' is passed to candidate's Step method, candidate reverts - back to follower, because it indicates that there is a valid leader sending - 'MsgApp' messages. Candidate and follower respond to this message in - 'MsgAppResp' type. - - 'MsgAppResp' is response to log replication request('MsgApp'). When - 'MsgApp' is passed to candidate or follower's Step method, it responds by - calling 'handleAppendEntries' method, which sends 'MsgAppResp' to raft - mailbox. - - 'MsgVote' requests votes for election. When a node is a follower or - candidate and 'MsgHup' is passed to its Step method, then the node calls - 'campaign' method to campaign itself to become a leader. Once 'campaign' - method is called, the node becomes candidate and sends 'MsgVote' to peers - in cluster to request votes. When passed to leader or candidate's Step - method and the message's Term is lower than leader's or candidate's, - 'MsgVote' will be rejected ('MsgVoteResp' is returned with Reject true). - If leader or candidate receives 'MsgVote' with higher term, it will revert - back to follower. When 'MsgVote' is passed to follower, it votes for the - sender only when sender's last term is greater than MsgVote's term or - sender's last term is equal to MsgVote's term but sender's last committed - index is greater than or equal to follower's. - - 'MsgVoteResp' contains responses from voting request. When 'MsgVoteResp' is - passed to candidate, the candidate calculates how many votes it has won. If - it's more than majority (quorum), it becomes leader and calls 'bcastAppend'. - If candidate receives majority of votes of denials, it reverts back to - follower. - - 'MsgPreVote' and 'MsgPreVoteResp' are used in an optional two-phase election - protocol. When Config.PreVote is true, a pre-election is carried out first - (using the same rules as a regular election), and no node increases its term - number unless the pre-election indicates that the campaigining node would win. - This minimizes disruption when a partitioned node rejoins the cluster. - - 'MsgSnap' requests to install a snapshot message. When a node has just - become a leader or the leader receives 'MsgProp' message, it calls - 'bcastAppend' method, which then calls 'sendAppend' method to each - follower. In 'sendAppend', if a leader fails to get term or entries, - the leader requests snapshot by sending 'MsgSnap' type message. - - 'MsgSnapStatus' tells the result of snapshot install message. When a - follower rejected 'MsgSnap', it indicates the snapshot request with - 'MsgSnap' had failed from network issues which causes the network layer - to fail to send out snapshots to its followers. Then leader considers - follower's progress as probe. When 'MsgSnap' were not rejected, it - indicates that the snapshot succeeded and the leader sets follower's - progress to probe and resumes its log replication. - - 'MsgHeartbeat' sends heartbeat from leader. When 'MsgHeartbeat' is passed - to candidate and message's term is higher than candidate's, the candidate - reverts back to follower and updates its committed index from the one in - this heartbeat. And it sends the message to its mailbox. When - 'MsgHeartbeat' is passed to follower's Step method and message's term is - higher than follower's, the follower updates its leaderID with the ID - from the message. - - 'MsgHeartbeatResp' is a response to 'MsgHeartbeat'. When 'MsgHeartbeatResp' - is passed to leader's Step method, the leader knows which follower - responded. And only when the leader's last committed index is greater than - follower's Match index, the leader runs 'sendAppend` method. - - 'MsgUnreachable' tells that request(message) wasn't delivered. When - 'MsgUnreachable' is passed to leader's Step method, the leader discovers - that the follower that sent this 'MsgUnreachable' is not reachable, often - indicating 'MsgApp' is lost. When follower's progress state is replicate, - the leader sets it back to probe. - -*/ -package raft diff --git a/vendor/github.com/coreos/etcd/raft/log.go b/vendor/github.com/coreos/etcd/raft/log.go deleted file mode 100644 index c3036d3c90dd..000000000000 --- a/vendor/github.com/coreos/etcd/raft/log.go +++ /dev/null @@ -1,358 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "fmt" - "log" - - pb "github.com/coreos/etcd/raft/raftpb" -) - -type raftLog struct { - // storage contains all stable entries since the last snapshot. - storage Storage - - // unstable contains all unstable entries and snapshot. - // they will be saved into storage. - unstable unstable - - // committed is the highest log position that is known to be in - // stable storage on a quorum of nodes. - committed uint64 - // applied is the highest log position that the application has - // been instructed to apply to its state machine. - // Invariant: applied <= committed - applied uint64 - - logger Logger -} - -// newLog returns log using the given storage. It recovers the log to the state -// that it just commits and applies the latest snapshot. -func newLog(storage Storage, logger Logger) *raftLog { - if storage == nil { - log.Panic("storage must not be nil") - } - log := &raftLog{ - storage: storage, - logger: logger, - } - firstIndex, err := storage.FirstIndex() - if err != nil { - panic(err) // TODO(bdarnell) - } - lastIndex, err := storage.LastIndex() - if err != nil { - panic(err) // TODO(bdarnell) - } - log.unstable.offset = lastIndex + 1 - log.unstable.logger = logger - // Initialize our committed and applied pointers to the time of the last compaction. - log.committed = firstIndex - 1 - log.applied = firstIndex - 1 - - return log -} - -func (l *raftLog) String() string { - return fmt.Sprintf("committed=%d, applied=%d, unstable.offset=%d, len(unstable.Entries)=%d", l.committed, l.applied, l.unstable.offset, len(l.unstable.entries)) -} - -// maybeAppend returns (0, false) if the entries cannot be appended. Otherwise, -// it returns (last index of new entries, true). -func (l *raftLog) maybeAppend(index, logTerm, committed uint64, ents ...pb.Entry) (lastnewi uint64, ok bool) { - if l.matchTerm(index, logTerm) { - lastnewi = index + uint64(len(ents)) - ci := l.findConflict(ents) - switch { - case ci == 0: - case ci <= l.committed: - l.logger.Panicf("entry %d conflict with committed entry [committed(%d)]", ci, l.committed) - default: - offset := index + 1 - l.append(ents[ci-offset:]...) - } - l.commitTo(min(committed, lastnewi)) - return lastnewi, true - } - return 0, false -} - -func (l *raftLog) append(ents ...pb.Entry) uint64 { - if len(ents) == 0 { - return l.lastIndex() - } - if after := ents[0].Index - 1; after < l.committed { - l.logger.Panicf("after(%d) is out of range [committed(%d)]", after, l.committed) - } - l.unstable.truncateAndAppend(ents) - return l.lastIndex() -} - -// findConflict finds the index of the conflict. -// It returns the first pair of conflicting entries between the existing -// entries and the given entries, if there are any. -// If there is no conflicting entries, and the existing entries contains -// all the given entries, zero will be returned. -// If there is no conflicting entries, but the given entries contains new -// entries, the index of the first new entry will be returned. -// An entry is considered to be conflicting if it has the same index but -// a different term. -// The first entry MUST have an index equal to the argument 'from'. -// The index of the given entries MUST be continuously increasing. -func (l *raftLog) findConflict(ents []pb.Entry) uint64 { - for _, ne := range ents { - if !l.matchTerm(ne.Index, ne.Term) { - if ne.Index <= l.lastIndex() { - l.logger.Infof("found conflict at index %d [existing term: %d, conflicting term: %d]", - ne.Index, l.zeroTermOnErrCompacted(l.term(ne.Index)), ne.Term) - } - return ne.Index - } - } - return 0 -} - -func (l *raftLog) unstableEntries() []pb.Entry { - if len(l.unstable.entries) == 0 { - return nil - } - return l.unstable.entries -} - -// nextEnts returns all the available entries for execution. -// If applied is smaller than the index of snapshot, it returns all committed -// entries after the index of snapshot. -func (l *raftLog) nextEnts() (ents []pb.Entry) { - off := max(l.applied+1, l.firstIndex()) - if l.committed+1 > off { - ents, err := l.slice(off, l.committed+1, noLimit) - if err != nil { - l.logger.Panicf("unexpected error when getting unapplied entries (%v)", err) - } - return ents - } - return nil -} - -// hasNextEnts returns if there is any available entries for execution. This -// is a fast check without heavy raftLog.slice() in raftLog.nextEnts(). -func (l *raftLog) hasNextEnts() bool { - off := max(l.applied+1, l.firstIndex()) - return l.committed+1 > off -} - -func (l *raftLog) snapshot() (pb.Snapshot, error) { - if l.unstable.snapshot != nil { - return *l.unstable.snapshot, nil - } - return l.storage.Snapshot() -} - -func (l *raftLog) firstIndex() uint64 { - if i, ok := l.unstable.maybeFirstIndex(); ok { - return i - } - index, err := l.storage.FirstIndex() - if err != nil { - panic(err) // TODO(bdarnell) - } - return index -} - -func (l *raftLog) lastIndex() uint64 { - if i, ok := l.unstable.maybeLastIndex(); ok { - return i - } - i, err := l.storage.LastIndex() - if err != nil { - panic(err) // TODO(bdarnell) - } - return i -} - -func (l *raftLog) commitTo(tocommit uint64) { - // never decrease commit - if l.committed < tocommit { - if l.lastIndex() < tocommit { - l.logger.Panicf("tocommit(%d) is out of range [lastIndex(%d)]. Was the raft log corrupted, truncated, or lost?", tocommit, l.lastIndex()) - } - l.committed = tocommit - } -} - -func (l *raftLog) appliedTo(i uint64) { - if i == 0 { - return - } - if l.committed < i || i < l.applied { - l.logger.Panicf("applied(%d) is out of range [prevApplied(%d), committed(%d)]", i, l.applied, l.committed) - } - l.applied = i -} - -func (l *raftLog) stableTo(i, t uint64) { l.unstable.stableTo(i, t) } - -func (l *raftLog) stableSnapTo(i uint64) { l.unstable.stableSnapTo(i) } - -func (l *raftLog) lastTerm() uint64 { - t, err := l.term(l.lastIndex()) - if err != nil { - l.logger.Panicf("unexpected error when getting the last term (%v)", err) - } - return t -} - -func (l *raftLog) term(i uint64) (uint64, error) { - // the valid term range is [index of dummy entry, last index] - dummyIndex := l.firstIndex() - 1 - if i < dummyIndex || i > l.lastIndex() { - // TODO: return an error instead? - return 0, nil - } - - if t, ok := l.unstable.maybeTerm(i); ok { - return t, nil - } - - t, err := l.storage.Term(i) - if err == nil { - return t, nil - } - if err == ErrCompacted || err == ErrUnavailable { - return 0, err - } - panic(err) // TODO(bdarnell) -} - -func (l *raftLog) entries(i, maxsize uint64) ([]pb.Entry, error) { - if i > l.lastIndex() { - return nil, nil - } - return l.slice(i, l.lastIndex()+1, maxsize) -} - -// allEntries returns all entries in the log. -func (l *raftLog) allEntries() []pb.Entry { - ents, err := l.entries(l.firstIndex(), noLimit) - if err == nil { - return ents - } - if err == ErrCompacted { // try again if there was a racing compaction - return l.allEntries() - } - // TODO (xiangli): handle error? - panic(err) -} - -// isUpToDate determines if the given (lastIndex,term) log is more up-to-date -// by comparing the index and term of the last entries in the existing logs. -// If the logs have last entries with different terms, then the log with the -// later term is more up-to-date. If the logs end with the same term, then -// whichever log has the larger lastIndex is more up-to-date. If the logs are -// the same, the given log is up-to-date. -func (l *raftLog) isUpToDate(lasti, term uint64) bool { - return term > l.lastTerm() || (term == l.lastTerm() && lasti >= l.lastIndex()) -} - -func (l *raftLog) matchTerm(i, term uint64) bool { - t, err := l.term(i) - if err != nil { - return false - } - return t == term -} - -func (l *raftLog) maybeCommit(maxIndex, term uint64) bool { - if maxIndex > l.committed && l.zeroTermOnErrCompacted(l.term(maxIndex)) == term { - l.commitTo(maxIndex) - return true - } - return false -} - -func (l *raftLog) restore(s pb.Snapshot) { - l.logger.Infof("log [%s] starts to restore snapshot [index: %d, term: %d]", l, s.Metadata.Index, s.Metadata.Term) - l.committed = s.Metadata.Index - l.unstable.restore(s) -} - -// slice returns a slice of log entries from lo through hi-1, inclusive. -func (l *raftLog) slice(lo, hi, maxSize uint64) ([]pb.Entry, error) { - err := l.mustCheckOutOfBounds(lo, hi) - if err != nil { - return nil, err - } - if lo == hi { - return nil, nil - } - var ents []pb.Entry - if lo < l.unstable.offset { - storedEnts, err := l.storage.Entries(lo, min(hi, l.unstable.offset), maxSize) - if err == ErrCompacted { - return nil, err - } else if err == ErrUnavailable { - l.logger.Panicf("entries[%d:%d) is unavailable from storage", lo, min(hi, l.unstable.offset)) - } else if err != nil { - panic(err) // TODO(bdarnell) - } - - // check if ents has reached the size limitation - if uint64(len(storedEnts)) < min(hi, l.unstable.offset)-lo { - return storedEnts, nil - } - - ents = storedEnts - } - if hi > l.unstable.offset { - unstable := l.unstable.slice(max(lo, l.unstable.offset), hi) - if len(ents) > 0 { - ents = append([]pb.Entry{}, ents...) - ents = append(ents, unstable...) - } else { - ents = unstable - } - } - return limitSize(ents, maxSize), nil -} - -// l.firstIndex <= lo <= hi <= l.firstIndex + len(l.entries) -func (l *raftLog) mustCheckOutOfBounds(lo, hi uint64) error { - if lo > hi { - l.logger.Panicf("invalid slice %d > %d", lo, hi) - } - fi := l.firstIndex() - if lo < fi { - return ErrCompacted - } - - length := l.lastIndex() + 1 - fi - if lo < fi || hi > fi+length { - l.logger.Panicf("slice[%d,%d) out of bound [%d,%d]", lo, hi, fi, l.lastIndex()) - } - return nil -} - -func (l *raftLog) zeroTermOnErrCompacted(t uint64, err error) uint64 { - if err == nil { - return t - } - if err == ErrCompacted { - return 0 - } - l.logger.Panicf("unexpected error (%v)", err) - return 0 -} diff --git a/vendor/github.com/coreos/etcd/raft/log_unstable.go b/vendor/github.com/coreos/etcd/raft/log_unstable.go deleted file mode 100644 index 263af9ce405e..000000000000 --- a/vendor/github.com/coreos/etcd/raft/log_unstable.go +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import pb "github.com/coreos/etcd/raft/raftpb" - -// unstable.entries[i] has raft log position i+unstable.offset. -// Note that unstable.offset may be less than the highest log -// position in storage; this means that the next write to storage -// might need to truncate the log before persisting unstable.entries. -type unstable struct { - // the incoming unstable snapshot, if any. - snapshot *pb.Snapshot - // all entries that have not yet been written to storage. - entries []pb.Entry - offset uint64 - - logger Logger -} - -// maybeFirstIndex returns the index of the first possible entry in entries -// if it has a snapshot. -func (u *unstable) maybeFirstIndex() (uint64, bool) { - if u.snapshot != nil { - return u.snapshot.Metadata.Index + 1, true - } - return 0, false -} - -// maybeLastIndex returns the last index if it has at least one -// unstable entry or snapshot. -func (u *unstable) maybeLastIndex() (uint64, bool) { - if l := len(u.entries); l != 0 { - return u.offset + uint64(l) - 1, true - } - if u.snapshot != nil { - return u.snapshot.Metadata.Index, true - } - return 0, false -} - -// maybeTerm returns the term of the entry at index i, if there -// is any. -func (u *unstable) maybeTerm(i uint64) (uint64, bool) { - if i < u.offset { - if u.snapshot == nil { - return 0, false - } - if u.snapshot.Metadata.Index == i { - return u.snapshot.Metadata.Term, true - } - return 0, false - } - - last, ok := u.maybeLastIndex() - if !ok { - return 0, false - } - if i > last { - return 0, false - } - return u.entries[i-u.offset].Term, true -} - -func (u *unstable) stableTo(i, t uint64) { - gt, ok := u.maybeTerm(i) - if !ok { - return - } - // if i < offset, term is matched with the snapshot - // only update the unstable entries if term is matched with - // an unstable entry. - if gt == t && i >= u.offset { - u.entries = u.entries[i+1-u.offset:] - u.offset = i + 1 - u.shrinkEntriesArray() - } -} - -// shrinkEntriesArray discards the underlying array used by the entries slice -// if most of it isn't being used. This avoids holding references to a bunch of -// potentially large entries that aren't needed anymore. Simply clearing the -// entries wouldn't be safe because clients might still be using them. -func (u *unstable) shrinkEntriesArray() { - // We replace the array if we're using less than half of the space in - // it. This number is fairly arbitrary, chosen as an attempt to balance - // memory usage vs number of allocations. It could probably be improved - // with some focused tuning. - const lenMultiple = 2 - if len(u.entries) == 0 { - u.entries = nil - } else if len(u.entries)*lenMultiple < cap(u.entries) { - newEntries := make([]pb.Entry, len(u.entries)) - copy(newEntries, u.entries) - u.entries = newEntries - } -} - -func (u *unstable) stableSnapTo(i uint64) { - if u.snapshot != nil && u.snapshot.Metadata.Index == i { - u.snapshot = nil - } -} - -func (u *unstable) restore(s pb.Snapshot) { - u.offset = s.Metadata.Index + 1 - u.entries = nil - u.snapshot = &s -} - -func (u *unstable) truncateAndAppend(ents []pb.Entry) { - after := ents[0].Index - switch { - case after == u.offset+uint64(len(u.entries)): - // after is the next index in the u.entries - // directly append - u.entries = append(u.entries, ents...) - case after <= u.offset: - u.logger.Infof("replace the unstable entries from index %d", after) - // The log is being truncated to before our current offset - // portion, so set the offset and replace the entries - u.offset = after - u.entries = ents - default: - // truncate to after and copy to u.entries - // then append - u.logger.Infof("truncate the unstable entries before index %d", after) - u.entries = append([]pb.Entry{}, u.slice(u.offset, after)...) - u.entries = append(u.entries, ents...) - } -} - -func (u *unstable) slice(lo uint64, hi uint64) []pb.Entry { - u.mustCheckOutOfBounds(lo, hi) - return u.entries[lo-u.offset : hi-u.offset] -} - -// u.offset <= lo <= hi <= u.offset+len(u.offset) -func (u *unstable) mustCheckOutOfBounds(lo, hi uint64) { - if lo > hi { - u.logger.Panicf("invalid unstable.slice %d > %d", lo, hi) - } - upper := u.offset + uint64(len(u.entries)) - if lo < u.offset || hi > upper { - u.logger.Panicf("unstable.slice[%d,%d) out of bound [%d,%d]", lo, hi, u.offset, upper) - } -} diff --git a/vendor/github.com/coreos/etcd/raft/logger.go b/vendor/github.com/coreos/etcd/raft/logger.go deleted file mode 100644 index 92e55b373e1d..000000000000 --- a/vendor/github.com/coreos/etcd/raft/logger.go +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "fmt" - "io/ioutil" - "log" - "os" -) - -type Logger interface { - Debug(v ...interface{}) - Debugf(format string, v ...interface{}) - - Error(v ...interface{}) - Errorf(format string, v ...interface{}) - - Info(v ...interface{}) - Infof(format string, v ...interface{}) - - Warning(v ...interface{}) - Warningf(format string, v ...interface{}) - - Fatal(v ...interface{}) - Fatalf(format string, v ...interface{}) - - Panic(v ...interface{}) - Panicf(format string, v ...interface{}) -} - -func SetLogger(l Logger) { raftLogger = l } - -var ( - defaultLogger = &DefaultLogger{Logger: log.New(os.Stderr, "raft", log.LstdFlags)} - discardLogger = &DefaultLogger{Logger: log.New(ioutil.Discard, "", 0)} - raftLogger = Logger(defaultLogger) -) - -const ( - calldepth = 2 -) - -// DefaultLogger is a default implementation of the Logger interface. -type DefaultLogger struct { - *log.Logger - debug bool -} - -func (l *DefaultLogger) EnableTimestamps() { - l.SetFlags(l.Flags() | log.Ldate | log.Ltime) -} - -func (l *DefaultLogger) EnableDebug() { - l.debug = true -} - -func (l *DefaultLogger) Debug(v ...interface{}) { - if l.debug { - l.Output(calldepth, header("DEBUG", fmt.Sprint(v...))) - } -} - -func (l *DefaultLogger) Debugf(format string, v ...interface{}) { - if l.debug { - l.Output(calldepth, header("DEBUG", fmt.Sprintf(format, v...))) - } -} - -func (l *DefaultLogger) Info(v ...interface{}) { - l.Output(calldepth, header("INFO", fmt.Sprint(v...))) -} - -func (l *DefaultLogger) Infof(format string, v ...interface{}) { - l.Output(calldepth, header("INFO", fmt.Sprintf(format, v...))) -} - -func (l *DefaultLogger) Error(v ...interface{}) { - l.Output(calldepth, header("ERROR", fmt.Sprint(v...))) -} - -func (l *DefaultLogger) Errorf(format string, v ...interface{}) { - l.Output(calldepth, header("ERROR", fmt.Sprintf(format, v...))) -} - -func (l *DefaultLogger) Warning(v ...interface{}) { - l.Output(calldepth, header("WARN", fmt.Sprint(v...))) -} - -func (l *DefaultLogger) Warningf(format string, v ...interface{}) { - l.Output(calldepth, header("WARN", fmt.Sprintf(format, v...))) -} - -func (l *DefaultLogger) Fatal(v ...interface{}) { - l.Output(calldepth, header("FATAL", fmt.Sprint(v...))) - os.Exit(1) -} - -func (l *DefaultLogger) Fatalf(format string, v ...interface{}) { - l.Output(calldepth, header("FATAL", fmt.Sprintf(format, v...))) - os.Exit(1) -} - -func (l *DefaultLogger) Panic(v ...interface{}) { - l.Logger.Panic(v) -} - -func (l *DefaultLogger) Panicf(format string, v ...interface{}) { - l.Logger.Panicf(format, v...) -} - -func header(lvl, msg string) string { - return fmt.Sprintf("%s: %s", lvl, msg) -} diff --git a/vendor/github.com/coreos/etcd/raft/node.go b/vendor/github.com/coreos/etcd/raft/node.go deleted file mode 100644 index 33a9db840012..000000000000 --- a/vendor/github.com/coreos/etcd/raft/node.go +++ /dev/null @@ -1,539 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "context" - "errors" - - pb "github.com/coreos/etcd/raft/raftpb" -) - -type SnapshotStatus int - -const ( - SnapshotFinish SnapshotStatus = 1 - SnapshotFailure SnapshotStatus = 2 -) - -var ( - emptyState = pb.HardState{} - - // ErrStopped is returned by methods on Nodes that have been stopped. - ErrStopped = errors.New("raft: stopped") -) - -// SoftState provides state that is useful for logging and debugging. -// The state is volatile and does not need to be persisted to the WAL. -type SoftState struct { - Lead uint64 // must use atomic operations to access; keep 64-bit aligned. - RaftState StateType -} - -func (a *SoftState) equal(b *SoftState) bool { - return a.Lead == b.Lead && a.RaftState == b.RaftState -} - -// Ready encapsulates the entries and messages that are ready to read, -// be saved to stable storage, committed or sent to other peers. -// All fields in Ready are read-only. -type Ready struct { - // The current volatile state of a Node. - // SoftState will be nil if there is no update. - // It is not required to consume or store SoftState. - *SoftState - - // The current state of a Node to be saved to stable storage BEFORE - // Messages are sent. - // HardState will be equal to empty state if there is no update. - pb.HardState - - // ReadStates can be used for node to serve linearizable read requests locally - // when its applied index is greater than the index in ReadState. - // Note that the readState will be returned when raft receives msgReadIndex. - // The returned is only valid for the request that requested to read. - ReadStates []ReadState - - // Entries specifies entries to be saved to stable storage BEFORE - // Messages are sent. - Entries []pb.Entry - - // Snapshot specifies the snapshot to be saved to stable storage. - Snapshot pb.Snapshot - - // CommittedEntries specifies entries to be committed to a - // store/state-machine. These have previously been committed to stable - // store. - CommittedEntries []pb.Entry - - // Messages specifies outbound messages to be sent AFTER Entries are - // committed to stable storage. - // If it contains a MsgSnap message, the application MUST report back to raft - // when the snapshot has been received or has failed by calling ReportSnapshot. - Messages []pb.Message - - // MustSync indicates whether the HardState and Entries must be synchronously - // written to disk or if an asynchronous write is permissible. - MustSync bool -} - -func isHardStateEqual(a, b pb.HardState) bool { - return a.Term == b.Term && a.Vote == b.Vote && a.Commit == b.Commit -} - -// IsEmptyHardState returns true if the given HardState is empty. -func IsEmptyHardState(st pb.HardState) bool { - return isHardStateEqual(st, emptyState) -} - -// IsEmptySnap returns true if the given Snapshot is empty. -func IsEmptySnap(sp pb.Snapshot) bool { - return sp.Metadata.Index == 0 -} - -func (rd Ready) containsUpdates() bool { - return rd.SoftState != nil || !IsEmptyHardState(rd.HardState) || - !IsEmptySnap(rd.Snapshot) || len(rd.Entries) > 0 || - len(rd.CommittedEntries) > 0 || len(rd.Messages) > 0 || len(rd.ReadStates) != 0 -} - -// Node represents a node in a raft cluster. -type Node interface { - // Tick increments the internal logical clock for the Node by a single tick. Election - // timeouts and heartbeat timeouts are in units of ticks. - Tick() - // Campaign causes the Node to transition to candidate state and start campaigning to become leader. - Campaign(ctx context.Context) error - // Propose proposes that data be appended to the log. - Propose(ctx context.Context, data []byte) error - // ProposeConfChange proposes config change. - // At most one ConfChange can be in the process of going through consensus. - // Application needs to call ApplyConfChange when applying EntryConfChange type entry. - ProposeConfChange(ctx context.Context, cc pb.ConfChange) error - // Step advances the state machine using the given message. ctx.Err() will be returned, if any. - Step(ctx context.Context, msg pb.Message) error - - // Ready returns a channel that returns the current point-in-time state. - // Users of the Node must call Advance after retrieving the state returned by Ready. - // - // NOTE: No committed entries from the next Ready may be applied until all committed entries - // and snapshots from the previous one have finished. - Ready() <-chan Ready - - // Advance notifies the Node that the application has saved progress up to the last Ready. - // It prepares the node to return the next available Ready. - // - // The application should generally call Advance after it applies the entries in last Ready. - // - // However, as an optimization, the application may call Advance while it is applying the - // commands. For example. when the last Ready contains a snapshot, the application might take - // a long time to apply the snapshot data. To continue receiving Ready without blocking raft - // progress, it can call Advance before finishing applying the last ready. - Advance() - // ApplyConfChange applies config change to the local node. - // Returns an opaque ConfState protobuf which must be recorded - // in snapshots. Will never return nil; it returns a pointer only - // to match MemoryStorage.Compact. - ApplyConfChange(cc pb.ConfChange) *pb.ConfState - - // TransferLeadership attempts to transfer leadership to the given transferee. - TransferLeadership(ctx context.Context, lead, transferee uint64) - - // ReadIndex request a read state. The read state will be set in the ready. - // Read state has a read index. Once the application advances further than the read - // index, any linearizable read requests issued before the read request can be - // processed safely. The read state will have the same rctx attached. - ReadIndex(ctx context.Context, rctx []byte) error - - // Status returns the current status of the raft state machine. - Status() Status - // ReportUnreachable reports the given node is not reachable for the last send. - ReportUnreachable(id uint64) - // ReportSnapshot reports the status of the sent snapshot. - ReportSnapshot(id uint64, status SnapshotStatus) - // Stop performs any necessary termination of the Node. - Stop() -} - -type Peer struct { - ID uint64 - Context []byte -} - -// StartNode returns a new Node given configuration and a list of raft peers. -// It appends a ConfChangeAddNode entry for each given peer to the initial log. -func StartNode(c *Config, peers []Peer) Node { - r := newRaft(c) - // become the follower at term 1 and apply initial configuration - // entries of term 1 - r.becomeFollower(1, None) - for _, peer := range peers { - cc := pb.ConfChange{Type: pb.ConfChangeAddNode, NodeID: peer.ID, Context: peer.Context} - d, err := cc.Marshal() - if err != nil { - panic("unexpected marshal error") - } - e := pb.Entry{Type: pb.EntryConfChange, Term: 1, Index: r.raftLog.lastIndex() + 1, Data: d} - r.raftLog.append(e) - } - // Mark these initial entries as committed. - // TODO(bdarnell): These entries are still unstable; do we need to preserve - // the invariant that committed < unstable? - r.raftLog.committed = r.raftLog.lastIndex() - // Now apply them, mainly so that the application can call Campaign - // immediately after StartNode in tests. Note that these nodes will - // be added to raft twice: here and when the application's Ready - // loop calls ApplyConfChange. The calls to addNode must come after - // all calls to raftLog.append so progress.next is set after these - // bootstrapping entries (it is an error if we try to append these - // entries since they have already been committed). - // We do not set raftLog.applied so the application will be able - // to observe all conf changes via Ready.CommittedEntries. - for _, peer := range peers { - r.addNode(peer.ID) - } - - n := newNode() - n.logger = c.Logger - go n.run(r) - return &n -} - -// RestartNode is similar to StartNode but does not take a list of peers. -// The current membership of the cluster will be restored from the Storage. -// If the caller has an existing state machine, pass in the last log index that -// has been applied to it; otherwise use zero. -func RestartNode(c *Config) Node { - r := newRaft(c) - - n := newNode() - n.logger = c.Logger - go n.run(r) - return &n -} - -// node is the canonical implementation of the Node interface -type node struct { - propc chan pb.Message - recvc chan pb.Message - confc chan pb.ConfChange - confstatec chan pb.ConfState - readyc chan Ready - advancec chan struct{} - tickc chan struct{} - done chan struct{} - stop chan struct{} - status chan chan Status - - logger Logger -} - -func newNode() node { - return node{ - propc: make(chan pb.Message), - recvc: make(chan pb.Message), - confc: make(chan pb.ConfChange), - confstatec: make(chan pb.ConfState), - readyc: make(chan Ready), - advancec: make(chan struct{}), - // make tickc a buffered chan, so raft node can buffer some ticks when the node - // is busy processing raft messages. Raft node will resume process buffered - // ticks when it becomes idle. - tickc: make(chan struct{}, 128), - done: make(chan struct{}), - stop: make(chan struct{}), - status: make(chan chan Status), - } -} - -func (n *node) Stop() { - select { - case n.stop <- struct{}{}: - // Not already stopped, so trigger it - case <-n.done: - // Node has already been stopped - no need to do anything - return - } - // Block until the stop has been acknowledged by run() - <-n.done -} - -func (n *node) run(r *raft) { - var propc chan pb.Message - var readyc chan Ready - var advancec chan struct{} - var prevLastUnstablei, prevLastUnstablet uint64 - var havePrevLastUnstablei bool - var prevSnapi uint64 - var rd Ready - - lead := None - prevSoftSt := r.softState() - prevHardSt := emptyState - - for { - if advancec != nil { - readyc = nil - } else { - rd = newReady(r, prevSoftSt, prevHardSt) - if rd.containsUpdates() { - readyc = n.readyc - } else { - readyc = nil - } - } - - if lead != r.lead { - if r.hasLeader() { - if lead == None { - r.logger.Infof("raft.node: %x elected leader %x at term %d", r.id, r.lead, r.Term) - } else { - r.logger.Infof("raft.node: %x changed leader from %x to %x at term %d", r.id, lead, r.lead, r.Term) - } - propc = n.propc - } else { - r.logger.Infof("raft.node: %x lost leader %x at term %d", r.id, lead, r.Term) - propc = nil - } - lead = r.lead - } - - select { - // TODO: maybe buffer the config propose if there exists one (the way - // described in raft dissertation) - // Currently it is dropped in Step silently. - case m := <-propc: - m.From = r.id - r.Step(m) - case m := <-n.recvc: - // filter out response message from unknown From. - if pr := r.getProgress(m.From); pr != nil || !IsResponseMsg(m.Type) { - r.Step(m) // raft never returns an error - } - case cc := <-n.confc: - if cc.NodeID == None { - r.resetPendingConf() - select { - case n.confstatec <- pb.ConfState{Nodes: r.nodes()}: - case <-n.done: - } - break - } - switch cc.Type { - case pb.ConfChangeAddNode: - r.addNode(cc.NodeID) - case pb.ConfChangeAddLearnerNode: - r.addLearner(cc.NodeID) - case pb.ConfChangeRemoveNode: - // block incoming proposal when local node is - // removed - if cc.NodeID == r.id { - propc = nil - } - r.removeNode(cc.NodeID) - case pb.ConfChangeUpdateNode: - r.resetPendingConf() - default: - panic("unexpected conf type") - } - select { - case n.confstatec <- pb.ConfState{Nodes: r.nodes()}: - case <-n.done: - } - case <-n.tickc: - r.tick() - case readyc <- rd: - if rd.SoftState != nil { - prevSoftSt = rd.SoftState - } - if len(rd.Entries) > 0 { - prevLastUnstablei = rd.Entries[len(rd.Entries)-1].Index - prevLastUnstablet = rd.Entries[len(rd.Entries)-1].Term - havePrevLastUnstablei = true - } - if !IsEmptyHardState(rd.HardState) { - prevHardSt = rd.HardState - } - if !IsEmptySnap(rd.Snapshot) { - prevSnapi = rd.Snapshot.Metadata.Index - } - - r.msgs = nil - r.readStates = nil - advancec = n.advancec - case <-advancec: - if prevHardSt.Commit != 0 { - r.raftLog.appliedTo(prevHardSt.Commit) - } - if havePrevLastUnstablei { - r.raftLog.stableTo(prevLastUnstablei, prevLastUnstablet) - havePrevLastUnstablei = false - } - r.raftLog.stableSnapTo(prevSnapi) - advancec = nil - case c := <-n.status: - c <- getStatus(r) - case <-n.stop: - close(n.done) - return - } - } -} - -// Tick increments the internal logical clock for this Node. Election timeouts -// and heartbeat timeouts are in units of ticks. -func (n *node) Tick() { - select { - case n.tickc <- struct{}{}: - case <-n.done: - default: - n.logger.Warningf("A tick missed to fire. Node blocks too long!") - } -} - -func (n *node) Campaign(ctx context.Context) error { return n.step(ctx, pb.Message{Type: pb.MsgHup}) } - -func (n *node) Propose(ctx context.Context, data []byte) error { - return n.step(ctx, pb.Message{Type: pb.MsgProp, Entries: []pb.Entry{{Data: data}}}) -} - -func (n *node) Step(ctx context.Context, m pb.Message) error { - // ignore unexpected local messages receiving over network - if IsLocalMsg(m.Type) { - // TODO: return an error? - return nil - } - return n.step(ctx, m) -} - -func (n *node) ProposeConfChange(ctx context.Context, cc pb.ConfChange) error { - data, err := cc.Marshal() - if err != nil { - return err - } - return n.Step(ctx, pb.Message{Type: pb.MsgProp, Entries: []pb.Entry{{Type: pb.EntryConfChange, Data: data}}}) -} - -// Step advances the state machine using msgs. The ctx.Err() will be returned, -// if any. -func (n *node) step(ctx context.Context, m pb.Message) error { - ch := n.recvc - if m.Type == pb.MsgProp { - ch = n.propc - } - - select { - case ch <- m: - return nil - case <-ctx.Done(): - return ctx.Err() - case <-n.done: - return ErrStopped - } -} - -func (n *node) Ready() <-chan Ready { return n.readyc } - -func (n *node) Advance() { - select { - case n.advancec <- struct{}{}: - case <-n.done: - } -} - -func (n *node) ApplyConfChange(cc pb.ConfChange) *pb.ConfState { - var cs pb.ConfState - select { - case n.confc <- cc: - case <-n.done: - } - select { - case cs = <-n.confstatec: - case <-n.done: - } - return &cs -} - -func (n *node) Status() Status { - c := make(chan Status) - select { - case n.status <- c: - return <-c - case <-n.done: - return Status{} - } -} - -func (n *node) ReportUnreachable(id uint64) { - select { - case n.recvc <- pb.Message{Type: pb.MsgUnreachable, From: id}: - case <-n.done: - } -} - -func (n *node) ReportSnapshot(id uint64, status SnapshotStatus) { - rej := status == SnapshotFailure - - select { - case n.recvc <- pb.Message{Type: pb.MsgSnapStatus, From: id, Reject: rej}: - case <-n.done: - } -} - -func (n *node) TransferLeadership(ctx context.Context, lead, transferee uint64) { - select { - // manually set 'from' and 'to', so that leader can voluntarily transfers its leadership - case n.recvc <- pb.Message{Type: pb.MsgTransferLeader, From: transferee, To: lead}: - case <-n.done: - case <-ctx.Done(): - } -} - -func (n *node) ReadIndex(ctx context.Context, rctx []byte) error { - return n.step(ctx, pb.Message{Type: pb.MsgReadIndex, Entries: []pb.Entry{{Data: rctx}}}) -} - -func newReady(r *raft, prevSoftSt *SoftState, prevHardSt pb.HardState) Ready { - rd := Ready{ - Entries: r.raftLog.unstableEntries(), - CommittedEntries: r.raftLog.nextEnts(), - Messages: r.msgs, - } - if softSt := r.softState(); !softSt.equal(prevSoftSt) { - rd.SoftState = softSt - } - if hardSt := r.hardState(); !isHardStateEqual(hardSt, prevHardSt) { - rd.HardState = hardSt - } - if r.raftLog.unstable.snapshot != nil { - rd.Snapshot = *r.raftLog.unstable.snapshot - } - if len(r.readStates) != 0 { - rd.ReadStates = r.readStates - } - rd.MustSync = MustSync(rd.HardState, prevHardSt, len(rd.Entries)) - return rd -} - -// MustSync returns true if the hard state and count of Raft entries indicate -// that a synchronous write to persistent storage is required. -func MustSync(st, prevst pb.HardState, entsnum int) bool { - // Persistent state on all servers: - // (Updated on stable storage before responding to RPCs) - // currentTerm - // votedFor - // log entries[] - return entsnum != 0 || st.Vote != prevst.Vote || st.Term != prevst.Term -} diff --git a/vendor/github.com/coreos/etcd/raft/progress.go b/vendor/github.com/coreos/etcd/raft/progress.go deleted file mode 100644 index ef3787db65d3..000000000000 --- a/vendor/github.com/coreos/etcd/raft/progress.go +++ /dev/null @@ -1,284 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import "fmt" - -const ( - ProgressStateProbe ProgressStateType = iota - ProgressStateReplicate - ProgressStateSnapshot -) - -type ProgressStateType uint64 - -var prstmap = [...]string{ - "ProgressStateProbe", - "ProgressStateReplicate", - "ProgressStateSnapshot", -} - -func (st ProgressStateType) String() string { return prstmap[uint64(st)] } - -// Progress represents a follower’s progress in the view of the leader. Leader maintains -// progresses of all followers, and sends entries to the follower based on its progress. -type Progress struct { - Match, Next uint64 - // State defines how the leader should interact with the follower. - // - // When in ProgressStateProbe, leader sends at most one replication message - // per heartbeat interval. It also probes actual progress of the follower. - // - // When in ProgressStateReplicate, leader optimistically increases next - // to the latest entry sent after sending replication message. This is - // an optimized state for fast replicating log entries to the follower. - // - // When in ProgressStateSnapshot, leader should have sent out snapshot - // before and stops sending any replication message. - State ProgressStateType - - // Paused is used in ProgressStateProbe. - // When Paused is true, raft should pause sending replication message to this peer. - Paused bool - // PendingSnapshot is used in ProgressStateSnapshot. - // If there is a pending snapshot, the pendingSnapshot will be set to the - // index of the snapshot. If pendingSnapshot is set, the replication process of - // this Progress will be paused. raft will not resend snapshot until the pending one - // is reported to be failed. - PendingSnapshot uint64 - - // RecentActive is true if the progress is recently active. Receiving any messages - // from the corresponding follower indicates the progress is active. - // RecentActive can be reset to false after an election timeout. - RecentActive bool - - // inflights is a sliding window for the inflight messages. - // Each inflight message contains one or more log entries. - // The max number of entries per message is defined in raft config as MaxSizePerMsg. - // Thus inflight effectively limits both the number of inflight messages - // and the bandwidth each Progress can use. - // When inflights is full, no more message should be sent. - // When a leader sends out a message, the index of the last - // entry should be added to inflights. The index MUST be added - // into inflights in order. - // When a leader receives a reply, the previous inflights should - // be freed by calling inflights.freeTo with the index of the last - // received entry. - ins *inflights - - // IsLearner is true if this progress is tracked for a learner. - IsLearner bool -} - -func (pr *Progress) resetState(state ProgressStateType) { - pr.Paused = false - pr.PendingSnapshot = 0 - pr.State = state - pr.ins.reset() -} - -func (pr *Progress) becomeProbe() { - // If the original state is ProgressStateSnapshot, progress knows that - // the pending snapshot has been sent to this peer successfully, then - // probes from pendingSnapshot + 1. - if pr.State == ProgressStateSnapshot { - pendingSnapshot := pr.PendingSnapshot - pr.resetState(ProgressStateProbe) - pr.Next = max(pr.Match+1, pendingSnapshot+1) - } else { - pr.resetState(ProgressStateProbe) - pr.Next = pr.Match + 1 - } -} - -func (pr *Progress) becomeReplicate() { - pr.resetState(ProgressStateReplicate) - pr.Next = pr.Match + 1 -} - -func (pr *Progress) becomeSnapshot(snapshoti uint64) { - pr.resetState(ProgressStateSnapshot) - pr.PendingSnapshot = snapshoti -} - -// maybeUpdate returns false if the given n index comes from an outdated message. -// Otherwise it updates the progress and returns true. -func (pr *Progress) maybeUpdate(n uint64) bool { - var updated bool - if pr.Match < n { - pr.Match = n - updated = true - pr.resume() - } - if pr.Next < n+1 { - pr.Next = n + 1 - } - return updated -} - -func (pr *Progress) optimisticUpdate(n uint64) { pr.Next = n + 1 } - -// maybeDecrTo returns false if the given to index comes from an out of order message. -// Otherwise it decreases the progress next index to min(rejected, last) and returns true. -func (pr *Progress) maybeDecrTo(rejected, last uint64) bool { - if pr.State == ProgressStateReplicate { - // the rejection must be stale if the progress has matched and "rejected" - // is smaller than "match". - if rejected <= pr.Match { - return false - } - // directly decrease next to match + 1 - pr.Next = pr.Match + 1 - return true - } - - // the rejection must be stale if "rejected" does not match next - 1 - if pr.Next-1 != rejected { - return false - } - - if pr.Next = min(rejected, last+1); pr.Next < 1 { - pr.Next = 1 - } - pr.resume() - return true -} - -func (pr *Progress) pause() { pr.Paused = true } -func (pr *Progress) resume() { pr.Paused = false } - -// IsPaused returns whether sending log entries to this node has been -// paused. A node may be paused because it has rejected recent -// MsgApps, is currently waiting for a snapshot, or has reached the -// MaxInflightMsgs limit. -func (pr *Progress) IsPaused() bool { - switch pr.State { - case ProgressStateProbe: - return pr.Paused - case ProgressStateReplicate: - return pr.ins.full() - case ProgressStateSnapshot: - return true - default: - panic("unexpected state") - } -} - -func (pr *Progress) snapshotFailure() { pr.PendingSnapshot = 0 } - -// needSnapshotAbort returns true if snapshot progress's Match -// is equal or higher than the pendingSnapshot. -func (pr *Progress) needSnapshotAbort() bool { - return pr.State == ProgressStateSnapshot && pr.Match >= pr.PendingSnapshot -} - -func (pr *Progress) String() string { - return fmt.Sprintf("next = %d, match = %d, state = %s, waiting = %v, pendingSnapshot = %d", pr.Next, pr.Match, pr.State, pr.IsPaused(), pr.PendingSnapshot) -} - -type inflights struct { - // the starting index in the buffer - start int - // number of inflights in the buffer - count int - - // the size of the buffer - size int - - // buffer contains the index of the last entry - // inside one message. - buffer []uint64 -} - -func newInflights(size int) *inflights { - return &inflights{ - size: size, - } -} - -// add adds an inflight into inflights -func (in *inflights) add(inflight uint64) { - if in.full() { - panic("cannot add into a full inflights") - } - next := in.start + in.count - size := in.size - if next >= size { - next -= size - } - if next >= len(in.buffer) { - in.growBuf() - } - in.buffer[next] = inflight - in.count++ -} - -// grow the inflight buffer by doubling up to inflights.size. We grow on demand -// instead of preallocating to inflights.size to handle systems which have -// thousands of Raft groups per process. -func (in *inflights) growBuf() { - newSize := len(in.buffer) * 2 - if newSize == 0 { - newSize = 1 - } else if newSize > in.size { - newSize = in.size - } - newBuffer := make([]uint64, newSize) - copy(newBuffer, in.buffer) - in.buffer = newBuffer -} - -// freeTo frees the inflights smaller or equal to the given `to` flight. -func (in *inflights) freeTo(to uint64) { - if in.count == 0 || to < in.buffer[in.start] { - // out of the left side of the window - return - } - - idx := in.start - var i int - for i = 0; i < in.count; i++ { - if to < in.buffer[idx] { // found the first large inflight - break - } - - // increase index and maybe rotate - size := in.size - if idx++; idx >= size { - idx -= size - } - } - // free i inflights and set new start index - in.count -= i - in.start = idx - if in.count == 0 { - // inflights is empty, reset the start index so that we don't grow the - // buffer unnecessarily. - in.start = 0 - } -} - -func (in *inflights) freeFirstOne() { in.freeTo(in.buffer[in.start]) } - -// full returns true if the inflights is full. -func (in *inflights) full() bool { - return in.count == in.size -} - -// resets frees all inflights. -func (in *inflights) reset() { - in.count = 0 - in.start = 0 -} diff --git a/vendor/github.com/coreos/etcd/raft/raft.go b/vendor/github.com/coreos/etcd/raft/raft.go deleted file mode 100644 index b4c0f0248ca2..000000000000 --- a/vendor/github.com/coreos/etcd/raft/raft.go +++ /dev/null @@ -1,1406 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "bytes" - "errors" - "fmt" - "math" - "math/rand" - "sort" - "strings" - "sync" - "time" - - pb "github.com/coreos/etcd/raft/raftpb" -) - -// None is a placeholder node ID used when there is no leader. -const None uint64 = 0 -const noLimit = math.MaxUint64 - -// Possible values for StateType. -const ( - StateFollower StateType = iota - StateCandidate - StateLeader - StatePreCandidate - numStates -) - -type ReadOnlyOption int - -const ( - // ReadOnlySafe guarantees the linearizability of the read only request by - // communicating with the quorum. It is the default and suggested option. - ReadOnlySafe ReadOnlyOption = iota - // ReadOnlyLeaseBased ensures linearizability of the read only request by - // relying on the leader lease. It can be affected by clock drift. - // If the clock drift is unbounded, leader might keep the lease longer than it - // should (clock can move backward/pause without any bound). ReadIndex is not safe - // in that case. - ReadOnlyLeaseBased -) - -// Possible values for CampaignType -const ( - // campaignPreElection represents the first phase of a normal election when - // Config.PreVote is true. - campaignPreElection CampaignType = "CampaignPreElection" - // campaignElection represents a normal (time-based) election (the second phase - // of the election when Config.PreVote is true). - campaignElection CampaignType = "CampaignElection" - // campaignTransfer represents the type of leader transfer - campaignTransfer CampaignType = "CampaignTransfer" -) - -// lockedRand is a small wrapper around rand.Rand to provide -// synchronization. Only the methods needed by the code are exposed -// (e.g. Intn). -type lockedRand struct { - mu sync.Mutex - rand *rand.Rand -} - -func (r *lockedRand) Intn(n int) int { - r.mu.Lock() - v := r.rand.Intn(n) - r.mu.Unlock() - return v -} - -var globalRand = &lockedRand{ - rand: rand.New(rand.NewSource(time.Now().UnixNano())), -} - -// CampaignType represents the type of campaigning -// the reason we use the type of string instead of uint64 -// is because it's simpler to compare and fill in raft entries -type CampaignType string - -// StateType represents the role of a node in a cluster. -type StateType uint64 - -var stmap = [...]string{ - "StateFollower", - "StateCandidate", - "StateLeader", - "StatePreCandidate", -} - -func (st StateType) String() string { - return stmap[uint64(st)] -} - -// Config contains the parameters to start a raft. -type Config struct { - // ID is the identity of the local raft. ID cannot be 0. - ID uint64 - - // peers contains the IDs of all nodes (including self) in the raft cluster. It - // should only be set when starting a new raft cluster. Restarting raft from - // previous configuration will panic if peers is set. peer is private and only - // used for testing right now. - peers []uint64 - - // learners contains the IDs of all leaner nodes (including self if the local node is a leaner) in the raft cluster. - // learners only receives entries from the leader node. It does not vote or promote itself. - learners []uint64 - - // ElectionTick is the number of Node.Tick invocations that must pass between - // elections. That is, if a follower does not receive any message from the - // leader of current term before ElectionTick has elapsed, it will become - // candidate and start an election. ElectionTick must be greater than - // HeartbeatTick. We suggest ElectionTick = 10 * HeartbeatTick to avoid - // unnecessary leader switching. - ElectionTick int - // HeartbeatTick is the number of Node.Tick invocations that must pass between - // heartbeats. That is, a leader sends heartbeat messages to maintain its - // leadership every HeartbeatTick ticks. - HeartbeatTick int - - // Storage is the storage for raft. raft generates entries and states to be - // stored in storage. raft reads the persisted entries and states out of - // Storage when it needs. raft reads out the previous state and configuration - // out of storage when restarting. - Storage Storage - // Applied is the last applied index. It should only be set when restarting - // raft. raft will not return entries to the application smaller or equal to - // Applied. If Applied is unset when restarting, raft might return previous - // applied entries. This is a very application dependent configuration. - Applied uint64 - - // MaxSizePerMsg limits the max size of each append message. Smaller value - // lowers the raft recovery cost(initial probing and message lost during normal - // operation). On the other side, it might affect the throughput during normal - // replication. Note: math.MaxUint64 for unlimited, 0 for at most one entry per - // message. - MaxSizePerMsg uint64 - // MaxInflightMsgs limits the max number of in-flight append messages during - // optimistic replication phase. The application transportation layer usually - // has its own sending buffer over TCP/UDP. Setting MaxInflightMsgs to avoid - // overflowing that sending buffer. TODO (xiangli): feedback to application to - // limit the proposal rate? - MaxInflightMsgs int - - // CheckQuorum specifies if the leader should check quorum activity. Leader - // steps down when quorum is not active for an electionTimeout. - CheckQuorum bool - - // PreVote enables the Pre-Vote algorithm described in raft thesis section - // 9.6. This prevents disruption when a node that has been partitioned away - // rejoins the cluster. - PreVote bool - - // ReadOnlyOption specifies how the read only request is processed. - // - // ReadOnlySafe guarantees the linearizability of the read only request by - // communicating with the quorum. It is the default and suggested option. - // - // ReadOnlyLeaseBased ensures linearizability of the read only request by - // relying on the leader lease. It can be affected by clock drift. - // If the clock drift is unbounded, leader might keep the lease longer than it - // should (clock can move backward/pause without any bound). ReadIndex is not safe - // in that case. - // CheckQuorum MUST be enabled if ReadOnlyOption is ReadOnlyLeaseBased. - ReadOnlyOption ReadOnlyOption - - // Logger is the logger used for raft log. For multinode which can host - // multiple raft group, each raft group can have its own logger - Logger Logger - - // DisableProposalForwarding set to true means that followers will drop - // proposals, rather than forwarding them to the leader. One use case for - // this feature would be in a situation where the Raft leader is used to - // compute the data of a proposal, for example, adding a timestamp from a - // hybrid logical clock to data in a monotonically increasing way. Forwarding - // should be disabled to prevent a follower with an innaccurate hybrid - // logical clock from assigning the timestamp and then forwarding the data - // to the leader. - DisableProposalForwarding bool -} - -func (c *Config) validate() error { - if c.ID == None { - return errors.New("cannot use none as id") - } - - if c.HeartbeatTick <= 0 { - return errors.New("heartbeat tick must be greater than 0") - } - - if c.ElectionTick <= c.HeartbeatTick { - return errors.New("election tick must be greater than heartbeat tick") - } - - if c.Storage == nil { - return errors.New("storage cannot be nil") - } - - if c.MaxInflightMsgs <= 0 { - return errors.New("max inflight messages must be greater than 0") - } - - if c.Logger == nil { - c.Logger = raftLogger - } - - if c.ReadOnlyOption == ReadOnlyLeaseBased && !c.CheckQuorum { - return errors.New("CheckQuorum must be enabled when ReadOnlyOption is ReadOnlyLeaseBased") - } - - return nil -} - -type raft struct { - id uint64 - - Term uint64 - Vote uint64 - - readStates []ReadState - - // the log - raftLog *raftLog - - maxInflight int - maxMsgSize uint64 - prs map[uint64]*Progress - learnerPrs map[uint64]*Progress - - state StateType - - // isLearner is true if the local raft node is a learner. - isLearner bool - - votes map[uint64]bool - - msgs []pb.Message - - // the leader id - lead uint64 - // leadTransferee is id of the leader transfer target when its value is not zero. - // Follow the procedure defined in raft thesis 3.10. - leadTransferee uint64 - // New configuration is ignored if there exists unapplied configuration. - pendingConf bool - - readOnly *readOnly - - // number of ticks since it reached last electionTimeout when it is leader - // or candidate. - // number of ticks since it reached last electionTimeout or received a - // valid message from current leader when it is a follower. - electionElapsed int - - // number of ticks since it reached last heartbeatTimeout. - // only leader keeps heartbeatElapsed. - heartbeatElapsed int - - checkQuorum bool - preVote bool - - heartbeatTimeout int - electionTimeout int - // randomizedElectionTimeout is a random number between - // [electiontimeout, 2 * electiontimeout - 1]. It gets reset - // when raft changes its state to follower or candidate. - randomizedElectionTimeout int - disableProposalForwarding bool - - tick func() - step stepFunc - - logger Logger -} - -func newRaft(c *Config) *raft { - if err := c.validate(); err != nil { - panic(err.Error()) - } - raftlog := newLog(c.Storage, c.Logger) - hs, cs, err := c.Storage.InitialState() - if err != nil { - panic(err) // TODO(bdarnell) - } - peers := c.peers - learners := c.learners - if len(cs.Nodes) > 0 || len(cs.Learners) > 0 { - if len(peers) > 0 || len(learners) > 0 { - // TODO(bdarnell): the peers argument is always nil except in - // tests; the argument should be removed and these tests should be - // updated to specify their nodes through a snapshot. - panic("cannot specify both newRaft(peers, learners) and ConfState.(Nodes, Learners)") - } - peers = cs.Nodes - learners = cs.Learners - } - r := &raft{ - id: c.ID, - lead: None, - isLearner: false, - raftLog: raftlog, - maxMsgSize: c.MaxSizePerMsg, - maxInflight: c.MaxInflightMsgs, - prs: make(map[uint64]*Progress), - learnerPrs: make(map[uint64]*Progress), - electionTimeout: c.ElectionTick, - heartbeatTimeout: c.HeartbeatTick, - logger: c.Logger, - checkQuorum: c.CheckQuorum, - preVote: c.PreVote, - readOnly: newReadOnly(c.ReadOnlyOption), - disableProposalForwarding: c.DisableProposalForwarding, - } - for _, p := range peers { - r.prs[p] = &Progress{Next: 1, ins: newInflights(r.maxInflight)} - } - for _, p := range learners { - if _, ok := r.prs[p]; ok { - panic(fmt.Sprintf("node %x is in both learner and peer list", p)) - } - r.learnerPrs[p] = &Progress{Next: 1, ins: newInflights(r.maxInflight), IsLearner: true} - if r.id == p { - r.isLearner = true - } - } - - if !isHardStateEqual(hs, emptyState) { - r.loadState(hs) - } - if c.Applied > 0 { - raftlog.appliedTo(c.Applied) - } - r.becomeFollower(r.Term, None) - - var nodesStrs []string - for _, n := range r.nodes() { - nodesStrs = append(nodesStrs, fmt.Sprintf("%x", n)) - } - - r.logger.Infof("newRaft %x [peers: [%s], term: %d, commit: %d, applied: %d, lastindex: %d, lastterm: %d]", - r.id, strings.Join(nodesStrs, ","), r.Term, r.raftLog.committed, r.raftLog.applied, r.raftLog.lastIndex(), r.raftLog.lastTerm()) - return r -} - -func (r *raft) hasLeader() bool { return r.lead != None } - -func (r *raft) softState() *SoftState { return &SoftState{Lead: r.lead, RaftState: r.state} } - -func (r *raft) hardState() pb.HardState { - return pb.HardState{ - Term: r.Term, - Vote: r.Vote, - Commit: r.raftLog.committed, - } -} - -func (r *raft) quorum() int { return len(r.prs)/2 + 1 } - -func (r *raft) nodes() []uint64 { - nodes := make([]uint64, 0, len(r.prs)+len(r.learnerPrs)) - for id := range r.prs { - nodes = append(nodes, id) - } - for id := range r.learnerPrs { - nodes = append(nodes, id) - } - sort.Sort(uint64Slice(nodes)) - return nodes -} - -// send persists state to stable storage and then sends to its mailbox. -func (r *raft) send(m pb.Message) { - m.From = r.id - if m.Type == pb.MsgVote || m.Type == pb.MsgVoteResp || m.Type == pb.MsgPreVote || m.Type == pb.MsgPreVoteResp { - if m.Term == 0 { - // All {pre-,}campaign messages need to have the term set when - // sending. - // - MsgVote: m.Term is the term the node is campaigning for, - // non-zero as we increment the term when campaigning. - // - MsgVoteResp: m.Term is the new r.Term if the MsgVote was - // granted, non-zero for the same reason MsgVote is - // - MsgPreVote: m.Term is the term the node will campaign, - // non-zero as we use m.Term to indicate the next term we'll be - // campaigning for - // - MsgPreVoteResp: m.Term is the term received in the original - // MsgPreVote if the pre-vote was granted, non-zero for the - // same reasons MsgPreVote is - panic(fmt.Sprintf("term should be set when sending %s", m.Type)) - } - } else { - if m.Term != 0 { - panic(fmt.Sprintf("term should not be set when sending %s (was %d)", m.Type, m.Term)) - } - // do not attach term to MsgProp, MsgReadIndex - // proposals are a way to forward to the leader and - // should be treated as local message. - // MsgReadIndex is also forwarded to leader. - if m.Type != pb.MsgProp && m.Type != pb.MsgReadIndex { - m.Term = r.Term - } - } - r.msgs = append(r.msgs, m) -} - -func (r *raft) getProgress(id uint64) *Progress { - if pr, ok := r.prs[id]; ok { - return pr - } - - return r.learnerPrs[id] -} - -// sendAppend sends RPC, with entries to the given peer. -func (r *raft) sendAppend(to uint64) { - pr := r.getProgress(to) - if pr.IsPaused() { - return - } - m := pb.Message{} - m.To = to - - term, errt := r.raftLog.term(pr.Next - 1) - ents, erre := r.raftLog.entries(pr.Next, r.maxMsgSize) - - if errt != nil || erre != nil { // send snapshot if we failed to get term or entries - if !pr.RecentActive { - r.logger.Debugf("ignore sending snapshot to %x since it is not recently active", to) - return - } - - m.Type = pb.MsgSnap - snapshot, err := r.raftLog.snapshot() - if err != nil { - if err == ErrSnapshotTemporarilyUnavailable { - r.logger.Debugf("%x failed to send snapshot to %x because snapshot is temporarily unavailable", r.id, to) - return - } - panic(err) // TODO(bdarnell) - } - if IsEmptySnap(snapshot) { - panic("need non-empty snapshot") - } - m.Snapshot = snapshot - sindex, sterm := snapshot.Metadata.Index, snapshot.Metadata.Term - r.logger.Debugf("%x [firstindex: %d, commit: %d] sent snapshot[index: %d, term: %d] to %x [%s]", - r.id, r.raftLog.firstIndex(), r.raftLog.committed, sindex, sterm, to, pr) - pr.becomeSnapshot(sindex) - r.logger.Debugf("%x paused sending replication messages to %x [%s]", r.id, to, pr) - } else { - m.Type = pb.MsgApp - m.Index = pr.Next - 1 - m.LogTerm = term - m.Entries = ents - m.Commit = r.raftLog.committed - if n := len(m.Entries); n != 0 { - switch pr.State { - // optimistically increase the next when in ProgressStateReplicate - case ProgressStateReplicate: - last := m.Entries[n-1].Index - pr.optimisticUpdate(last) - pr.ins.add(last) - case ProgressStateProbe: - pr.pause() - default: - r.logger.Panicf("%x is sending append in unhandled state %s", r.id, pr.State) - } - } - } - r.send(m) -} - -// sendHeartbeat sends an empty MsgApp -func (r *raft) sendHeartbeat(to uint64, ctx []byte) { - // Attach the commit as min(to.matched, r.committed). - // When the leader sends out heartbeat message, - // the receiver(follower) might not be matched with the leader - // or it might not have all the committed entries. - // The leader MUST NOT forward the follower's commit to - // an unmatched index. - commit := min(r.getProgress(to).Match, r.raftLog.committed) - m := pb.Message{ - To: to, - Type: pb.MsgHeartbeat, - Commit: commit, - Context: ctx, - } - - r.send(m) -} - -func (r *raft) forEachProgress(f func(id uint64, pr *Progress)) { - for id, pr := range r.prs { - f(id, pr) - } - - for id, pr := range r.learnerPrs { - f(id, pr) - } -} - -// bcastAppend sends RPC, with entries to all peers that are not up-to-date -// according to the progress recorded in r.prs. -func (r *raft) bcastAppend() { - r.forEachProgress(func(id uint64, _ *Progress) { - if id == r.id { - return - } - - r.sendAppend(id) - }) -} - -// bcastHeartbeat sends RPC, without entries to all the peers. -func (r *raft) bcastHeartbeat() { - lastCtx := r.readOnly.lastPendingRequestCtx() - if len(lastCtx) == 0 { - r.bcastHeartbeatWithCtx(nil) - } else { - r.bcastHeartbeatWithCtx([]byte(lastCtx)) - } -} - -func (r *raft) bcastHeartbeatWithCtx(ctx []byte) { - r.forEachProgress(func(id uint64, _ *Progress) { - if id == r.id { - return - } - r.sendHeartbeat(id, ctx) - }) -} - -// maybeCommit attempts to advance the commit index. Returns true if -// the commit index changed (in which case the caller should call -// r.bcastAppend). -func (r *raft) maybeCommit() bool { - // TODO(bmizerany): optimize.. Currently naive - mis := make(uint64Slice, 0, len(r.prs)) - for _, p := range r.prs { - mis = append(mis, p.Match) - } - sort.Sort(sort.Reverse(mis)) - mci := mis[r.quorum()-1] - return r.raftLog.maybeCommit(mci, r.Term) -} - -func (r *raft) reset(term uint64) { - if r.Term != term { - r.Term = term - r.Vote = None - } - r.lead = None - - r.electionElapsed = 0 - r.heartbeatElapsed = 0 - r.resetRandomizedElectionTimeout() - - r.abortLeaderTransfer() - - r.votes = make(map[uint64]bool) - r.forEachProgress(func(id uint64, pr *Progress) { - *pr = Progress{Next: r.raftLog.lastIndex() + 1, ins: newInflights(r.maxInflight), IsLearner: pr.IsLearner} - if id == r.id { - pr.Match = r.raftLog.lastIndex() - } - }) - - r.pendingConf = false - r.readOnly = newReadOnly(r.readOnly.option) -} - -func (r *raft) appendEntry(es ...pb.Entry) { - li := r.raftLog.lastIndex() - for i := range es { - es[i].Term = r.Term - es[i].Index = li + 1 + uint64(i) - } - r.raftLog.append(es...) - r.getProgress(r.id).maybeUpdate(r.raftLog.lastIndex()) - // Regardless of maybeCommit's return, our caller will call bcastAppend. - r.maybeCommit() -} - -// tickElection is run by followers and candidates after r.electionTimeout. -func (r *raft) tickElection() { - r.electionElapsed++ - - if r.promotable() && r.pastElectionTimeout() { - r.electionElapsed = 0 - r.Step(pb.Message{From: r.id, Type: pb.MsgHup}) - } -} - -// tickHeartbeat is run by leaders to send a MsgBeat after r.heartbeatTimeout. -func (r *raft) tickHeartbeat() { - r.heartbeatElapsed++ - r.electionElapsed++ - - if r.electionElapsed >= r.electionTimeout { - r.electionElapsed = 0 - if r.checkQuorum { - r.Step(pb.Message{From: r.id, Type: pb.MsgCheckQuorum}) - } - // If current leader cannot transfer leadership in electionTimeout, it becomes leader again. - if r.state == StateLeader && r.leadTransferee != None { - r.abortLeaderTransfer() - } - } - - if r.state != StateLeader { - return - } - - if r.heartbeatElapsed >= r.heartbeatTimeout { - r.heartbeatElapsed = 0 - r.Step(pb.Message{From: r.id, Type: pb.MsgBeat}) - } -} - -func (r *raft) becomeFollower(term uint64, lead uint64) { - r.step = stepFollower - r.reset(term) - r.tick = r.tickElection - r.lead = lead - r.state = StateFollower - r.logger.Infof("%x became follower at term %d", r.id, r.Term) -} - -func (r *raft) becomeCandidate() { - // TODO(xiangli) remove the panic when the raft implementation is stable - if r.state == StateLeader { - panic("invalid transition [leader -> candidate]") - } - r.step = stepCandidate - r.reset(r.Term + 1) - r.tick = r.tickElection - r.Vote = r.id - r.state = StateCandidate - r.logger.Infof("%x became candidate at term %d", r.id, r.Term) -} - -func (r *raft) becomePreCandidate() { - // TODO(xiangli) remove the panic when the raft implementation is stable - if r.state == StateLeader { - panic("invalid transition [leader -> pre-candidate]") - } - // Becoming a pre-candidate changes our step functions and state, - // but doesn't change anything else. In particular it does not increase - // r.Term or change r.Vote. - r.step = stepCandidate - r.votes = make(map[uint64]bool) - r.tick = r.tickElection - r.state = StatePreCandidate - r.logger.Infof("%x became pre-candidate at term %d", r.id, r.Term) -} - -func (r *raft) becomeLeader() { - // TODO(xiangli) remove the panic when the raft implementation is stable - if r.state == StateFollower { - panic("invalid transition [follower -> leader]") - } - r.step = stepLeader - r.reset(r.Term) - r.tick = r.tickHeartbeat - r.lead = r.id - r.state = StateLeader - ents, err := r.raftLog.entries(r.raftLog.committed+1, noLimit) - if err != nil { - r.logger.Panicf("unexpected error getting uncommitted entries (%v)", err) - } - - nconf := numOfPendingConf(ents) - if nconf > 1 { - panic("unexpected multiple uncommitted config entry") - } - if nconf == 1 { - r.pendingConf = true - } - - r.appendEntry(pb.Entry{Data: nil}) - r.logger.Infof("%x became leader at term %d", r.id, r.Term) -} - -func (r *raft) campaign(t CampaignType) { - var term uint64 - var voteMsg pb.MessageType - if t == campaignPreElection { - r.becomePreCandidate() - voteMsg = pb.MsgPreVote - // PreVote RPCs are sent for the next term before we've incremented r.Term. - term = r.Term + 1 - } else { - r.becomeCandidate() - voteMsg = pb.MsgVote - term = r.Term - } - if r.quorum() == r.poll(r.id, voteRespMsgType(voteMsg), true) { - // We won the election after voting for ourselves (which must mean that - // this is a single-node cluster). Advance to the next state. - if t == campaignPreElection { - r.campaign(campaignElection) - } else { - r.becomeLeader() - } - return - } - for id := range r.prs { - if id == r.id { - continue - } - r.logger.Infof("%x [logterm: %d, index: %d] sent %s request to %x at term %d", - r.id, r.raftLog.lastTerm(), r.raftLog.lastIndex(), voteMsg, id, r.Term) - - var ctx []byte - if t == campaignTransfer { - ctx = []byte(t) - } - r.send(pb.Message{Term: term, To: id, Type: voteMsg, Index: r.raftLog.lastIndex(), LogTerm: r.raftLog.lastTerm(), Context: ctx}) - } -} - -func (r *raft) poll(id uint64, t pb.MessageType, v bool) (granted int) { - if v { - r.logger.Infof("%x received %s from %x at term %d", r.id, t, id, r.Term) - } else { - r.logger.Infof("%x received %s rejection from %x at term %d", r.id, t, id, r.Term) - } - if _, ok := r.votes[id]; !ok { - r.votes[id] = v - } - for _, vv := range r.votes { - if vv { - granted++ - } - } - return granted -} - -func (r *raft) Step(m pb.Message) error { - // Handle the message term, which may result in our stepping down to a follower. - switch { - case m.Term == 0: - // local message - case m.Term > r.Term: - if m.Type == pb.MsgVote || m.Type == pb.MsgPreVote { - force := bytes.Equal(m.Context, []byte(campaignTransfer)) - inLease := r.checkQuorum && r.lead != None && r.electionElapsed < r.electionTimeout - if !force && inLease { - // If a server receives a RequestVote request within the minimum election timeout - // of hearing from a current leader, it does not update its term or grant its vote - r.logger.Infof("%x [logterm: %d, index: %d, vote: %x] ignored %s from %x [logterm: %d, index: %d] at term %d: lease is not expired (remaining ticks: %d)", - r.id, r.raftLog.lastTerm(), r.raftLog.lastIndex(), r.Vote, m.Type, m.From, m.LogTerm, m.Index, r.Term, r.electionTimeout-r.electionElapsed) - return nil - } - } - switch { - case m.Type == pb.MsgPreVote: - // Never change our term in response to a PreVote - case m.Type == pb.MsgPreVoteResp && !m.Reject: - // We send pre-vote requests with a term in our future. If the - // pre-vote is granted, we will increment our term when we get a - // quorum. If it is not, the term comes from the node that - // rejected our vote so we should become a follower at the new - // term. - default: - r.logger.Infof("%x [term: %d] received a %s message with higher term from %x [term: %d]", - r.id, r.Term, m.Type, m.From, m.Term) - if m.Type == pb.MsgApp || m.Type == pb.MsgHeartbeat || m.Type == pb.MsgSnap { - r.becomeFollower(m.Term, m.From) - } else { - r.becomeFollower(m.Term, None) - } - } - - case m.Term < r.Term: - if r.checkQuorum && (m.Type == pb.MsgHeartbeat || m.Type == pb.MsgApp) { - // We have received messages from a leader at a lower term. It is possible - // that these messages were simply delayed in the network, but this could - // also mean that this node has advanced its term number during a network - // partition, and it is now unable to either win an election or to rejoin - // the majority on the old term. If checkQuorum is false, this will be - // handled by incrementing term numbers in response to MsgVote with a - // higher term, but if checkQuorum is true we may not advance the term on - // MsgVote and must generate other messages to advance the term. The net - // result of these two features is to minimize the disruption caused by - // nodes that have been removed from the cluster's configuration: a - // removed node will send MsgVotes (or MsgPreVotes) which will be ignored, - // but it will not receive MsgApp or MsgHeartbeat, so it will not create - // disruptive term increases - r.send(pb.Message{To: m.From, Type: pb.MsgAppResp}) - } else { - // ignore other cases - r.logger.Infof("%x [term: %d] ignored a %s message with lower term from %x [term: %d]", - r.id, r.Term, m.Type, m.From, m.Term) - } - return nil - } - - switch m.Type { - case pb.MsgHup: - if r.state != StateLeader { - ents, err := r.raftLog.slice(r.raftLog.applied+1, r.raftLog.committed+1, noLimit) - if err != nil { - r.logger.Panicf("unexpected error getting unapplied entries (%v)", err) - } - if n := numOfPendingConf(ents); n != 0 && r.raftLog.committed > r.raftLog.applied { - r.logger.Warningf("%x cannot campaign at term %d since there are still %d pending configuration changes to apply", r.id, r.Term, n) - return nil - } - - r.logger.Infof("%x is starting a new election at term %d", r.id, r.Term) - if r.preVote { - r.campaign(campaignPreElection) - } else { - r.campaign(campaignElection) - } - } else { - r.logger.Debugf("%x ignoring MsgHup because already leader", r.id) - } - - case pb.MsgVote, pb.MsgPreVote: - if r.isLearner { - // TODO: learner may need to vote, in case of node down when confchange. - r.logger.Infof("%x [logterm: %d, index: %d, vote: %x] ignored %s from %x [logterm: %d, index: %d] at term %d: learner can not vote", - r.id, r.raftLog.lastTerm(), r.raftLog.lastIndex(), r.Vote, m.Type, m.From, m.LogTerm, m.Index, r.Term) - return nil - } - // The m.Term > r.Term clause is for MsgPreVote. For MsgVote m.Term should - // always equal r.Term. - if (r.Vote == None || m.Term > r.Term || r.Vote == m.From) && r.raftLog.isUpToDate(m.Index, m.LogTerm) { - r.logger.Infof("%x [logterm: %d, index: %d, vote: %x] cast %s for %x [logterm: %d, index: %d] at term %d", - r.id, r.raftLog.lastTerm(), r.raftLog.lastIndex(), r.Vote, m.Type, m.From, m.LogTerm, m.Index, r.Term) - // When responding to Msg{Pre,}Vote messages we include the term - // from the message, not the local term. To see why consider the - // case where a single node was previously partitioned away and - // it's local term is now of date. If we include the local term - // (recall that for pre-votes we don't update the local term), the - // (pre-)campaigning node on the other end will proceed to ignore - // the message (it ignores all out of date messages). - // The term in the original message and current local term are the - // same in the case of regular votes, but different for pre-votes. - r.send(pb.Message{To: m.From, Term: m.Term, Type: voteRespMsgType(m.Type)}) - if m.Type == pb.MsgVote { - // Only record real votes. - r.electionElapsed = 0 - r.Vote = m.From - } - } else { - r.logger.Infof("%x [logterm: %d, index: %d, vote: %x] rejected %s from %x [logterm: %d, index: %d] at term %d", - r.id, r.raftLog.lastTerm(), r.raftLog.lastIndex(), r.Vote, m.Type, m.From, m.LogTerm, m.Index, r.Term) - r.send(pb.Message{To: m.From, Term: r.Term, Type: voteRespMsgType(m.Type), Reject: true}) - } - - default: - r.step(r, m) - } - return nil -} - -type stepFunc func(r *raft, m pb.Message) - -func stepLeader(r *raft, m pb.Message) { - // These message types do not require any progress for m.From. - switch m.Type { - case pb.MsgBeat: - r.bcastHeartbeat() - return - case pb.MsgCheckQuorum: - if !r.checkQuorumActive() { - r.logger.Warningf("%x stepped down to follower since quorum is not active", r.id) - r.becomeFollower(r.Term, None) - } - return - case pb.MsgProp: - if len(m.Entries) == 0 { - r.logger.Panicf("%x stepped empty MsgProp", r.id) - } - if _, ok := r.prs[r.id]; !ok { - // If we are not currently a member of the range (i.e. this node - // was removed from the configuration while serving as leader), - // drop any new proposals. - return - } - if r.leadTransferee != None { - r.logger.Debugf("%x [term %d] transfer leadership to %x is in progress; dropping proposal", r.id, r.Term, r.leadTransferee) - return - } - - for i, e := range m.Entries { - if e.Type == pb.EntryConfChange { - if r.pendingConf { - r.logger.Infof("propose conf %s ignored since pending unapplied configuration", e.String()) - m.Entries[i] = pb.Entry{Type: pb.EntryNormal} - } - r.pendingConf = true - } - } - r.appendEntry(m.Entries...) - r.bcastAppend() - return - case pb.MsgReadIndex: - if r.quorum() > 1 { - if r.raftLog.zeroTermOnErrCompacted(r.raftLog.term(r.raftLog.committed)) != r.Term { - // Reject read only request when this leader has not committed any log entry at its term. - return - } - - // thinking: use an interally defined context instead of the user given context. - // We can express this in terms of the term and index instead of a user-supplied value. - // This would allow multiple reads to piggyback on the same message. - switch r.readOnly.option { - case ReadOnlySafe: - r.readOnly.addRequest(r.raftLog.committed, m) - r.bcastHeartbeatWithCtx(m.Entries[0].Data) - case ReadOnlyLeaseBased: - ri := r.raftLog.committed - if m.From == None || m.From == r.id { // from local member - r.readStates = append(r.readStates, ReadState{Index: r.raftLog.committed, RequestCtx: m.Entries[0].Data}) - } else { - r.send(pb.Message{To: m.From, Type: pb.MsgReadIndexResp, Index: ri, Entries: m.Entries}) - } - } - } else { - r.readStates = append(r.readStates, ReadState{Index: r.raftLog.committed, RequestCtx: m.Entries[0].Data}) - } - - return - } - - // All other message types require a progress for m.From (pr). - pr := r.getProgress(m.From) - if pr == nil { - r.logger.Debugf("%x no progress available for %x", r.id, m.From) - return - } - switch m.Type { - case pb.MsgAppResp: - pr.RecentActive = true - - if m.Reject { - r.logger.Debugf("%x received msgApp rejection(lastindex: %d) from %x for index %d", - r.id, m.RejectHint, m.From, m.Index) - if pr.maybeDecrTo(m.Index, m.RejectHint) { - r.logger.Debugf("%x decreased progress of %x to [%s]", r.id, m.From, pr) - if pr.State == ProgressStateReplicate { - pr.becomeProbe() - } - r.sendAppend(m.From) - } - } else { - oldPaused := pr.IsPaused() - if pr.maybeUpdate(m.Index) { - switch { - case pr.State == ProgressStateProbe: - pr.becomeReplicate() - case pr.State == ProgressStateSnapshot && pr.needSnapshotAbort(): - r.logger.Debugf("%x snapshot aborted, resumed sending replication messages to %x [%s]", r.id, m.From, pr) - pr.becomeProbe() - case pr.State == ProgressStateReplicate: - pr.ins.freeTo(m.Index) - } - - if r.maybeCommit() { - r.bcastAppend() - } else if oldPaused { - // update() reset the wait state on this node. If we had delayed sending - // an update before, send it now. - r.sendAppend(m.From) - } - // Transfer leadership is in progress. - if m.From == r.leadTransferee && pr.Match == r.raftLog.lastIndex() { - r.logger.Infof("%x sent MsgTimeoutNow to %x after received MsgAppResp", r.id, m.From) - r.sendTimeoutNow(m.From) - } - } - } - case pb.MsgHeartbeatResp: - pr.RecentActive = true - pr.resume() - - // free one slot for the full inflights window to allow progress. - if pr.State == ProgressStateReplicate && pr.ins.full() { - pr.ins.freeFirstOne() - } - if pr.Match < r.raftLog.lastIndex() { - r.sendAppend(m.From) - } - - if r.readOnly.option != ReadOnlySafe || len(m.Context) == 0 { - return - } - - ackCount := r.readOnly.recvAck(m) - if ackCount < r.quorum() { - return - } - - rss := r.readOnly.advance(m) - for _, rs := range rss { - req := rs.req - if req.From == None || req.From == r.id { // from local member - r.readStates = append(r.readStates, ReadState{Index: rs.index, RequestCtx: req.Entries[0].Data}) - } else { - r.send(pb.Message{To: req.From, Type: pb.MsgReadIndexResp, Index: rs.index, Entries: req.Entries}) - } - } - case pb.MsgSnapStatus: - if pr.State != ProgressStateSnapshot { - return - } - if !m.Reject { - pr.becomeProbe() - r.logger.Debugf("%x snapshot succeeded, resumed sending replication messages to %x [%s]", r.id, m.From, pr) - } else { - pr.snapshotFailure() - pr.becomeProbe() - r.logger.Debugf("%x snapshot failed, resumed sending replication messages to %x [%s]", r.id, m.From, pr) - } - // If snapshot finish, wait for the msgAppResp from the remote node before sending - // out the next msgApp. - // If snapshot failure, wait for a heartbeat interval before next try - pr.pause() - case pb.MsgUnreachable: - // During optimistic replication, if the remote becomes unreachable, - // there is huge probability that a MsgApp is lost. - if pr.State == ProgressStateReplicate { - pr.becomeProbe() - } - r.logger.Debugf("%x failed to send message to %x because it is unreachable [%s]", r.id, m.From, pr) - case pb.MsgTransferLeader: - if pr.IsLearner { - r.logger.Debugf("%x is learner. Ignored transferring leadership", r.id) - return - } - leadTransferee := m.From - lastLeadTransferee := r.leadTransferee - if lastLeadTransferee != None { - if lastLeadTransferee == leadTransferee { - r.logger.Infof("%x [term %d] transfer leadership to %x is in progress, ignores request to same node %x", - r.id, r.Term, leadTransferee, leadTransferee) - return - } - r.abortLeaderTransfer() - r.logger.Infof("%x [term %d] abort previous transferring leadership to %x", r.id, r.Term, lastLeadTransferee) - } - if leadTransferee == r.id { - r.logger.Debugf("%x is already leader. Ignored transferring leadership to self", r.id) - return - } - // Transfer leadership to third party. - r.logger.Infof("%x [term %d] starts to transfer leadership to %x", r.id, r.Term, leadTransferee) - // Transfer leadership should be finished in one electionTimeout, so reset r.electionElapsed. - r.electionElapsed = 0 - r.leadTransferee = leadTransferee - if pr.Match == r.raftLog.lastIndex() { - r.sendTimeoutNow(leadTransferee) - r.logger.Infof("%x sends MsgTimeoutNow to %x immediately as %x already has up-to-date log", r.id, leadTransferee, leadTransferee) - } else { - r.sendAppend(leadTransferee) - } - } -} - -// stepCandidate is shared by StateCandidate and StatePreCandidate; the difference is -// whether they respond to MsgVoteResp or MsgPreVoteResp. -func stepCandidate(r *raft, m pb.Message) { - // Only handle vote responses corresponding to our candidacy (while in - // StateCandidate, we may get stale MsgPreVoteResp messages in this term from - // our pre-candidate state). - var myVoteRespType pb.MessageType - if r.state == StatePreCandidate { - myVoteRespType = pb.MsgPreVoteResp - } else { - myVoteRespType = pb.MsgVoteResp - } - switch m.Type { - case pb.MsgProp: - r.logger.Infof("%x no leader at term %d; dropping proposal", r.id, r.Term) - return - case pb.MsgApp: - r.becomeFollower(r.Term, m.From) - r.handleAppendEntries(m) - case pb.MsgHeartbeat: - r.becomeFollower(r.Term, m.From) - r.handleHeartbeat(m) - case pb.MsgSnap: - r.becomeFollower(m.Term, m.From) - r.handleSnapshot(m) - case myVoteRespType: - gr := r.poll(m.From, m.Type, !m.Reject) - r.logger.Infof("%x [quorum:%d] has received %d %s votes and %d vote rejections", r.id, r.quorum(), gr, m.Type, len(r.votes)-gr) - switch r.quorum() { - case gr: - if r.state == StatePreCandidate { - r.campaign(campaignElection) - } else { - r.becomeLeader() - r.bcastAppend() - } - case len(r.votes) - gr: - r.becomeFollower(r.Term, None) - } - case pb.MsgTimeoutNow: - r.logger.Debugf("%x [term %d state %v] ignored MsgTimeoutNow from %x", r.id, r.Term, r.state, m.From) - } -} - -func stepFollower(r *raft, m pb.Message) { - switch m.Type { - case pb.MsgProp: - if r.lead == None { - r.logger.Infof("%x no leader at term %d; dropping proposal", r.id, r.Term) - return - } else if r.disableProposalForwarding { - r.logger.Infof("%x not forwarding to leader %x at term %d; dropping proposal", r.id, r.lead, r.Term) - return - } - m.To = r.lead - r.send(m) - case pb.MsgApp: - r.electionElapsed = 0 - r.lead = m.From - r.handleAppendEntries(m) - case pb.MsgHeartbeat: - r.electionElapsed = 0 - r.lead = m.From - r.handleHeartbeat(m) - case pb.MsgSnap: - r.electionElapsed = 0 - r.lead = m.From - r.handleSnapshot(m) - case pb.MsgTransferLeader: - if r.lead == None { - r.logger.Infof("%x no leader at term %d; dropping leader transfer msg", r.id, r.Term) - return - } - m.To = r.lead - r.send(m) - case pb.MsgTimeoutNow: - if r.promotable() { - r.logger.Infof("%x [term %d] received MsgTimeoutNow from %x and starts an election to get leadership.", r.id, r.Term, m.From) - // Leadership transfers never use pre-vote even if r.preVote is true; we - // know we are not recovering from a partition so there is no need for the - // extra round trip. - r.campaign(campaignTransfer) - } else { - r.logger.Infof("%x received MsgTimeoutNow from %x but is not promotable", r.id, m.From) - } - case pb.MsgReadIndex: - if r.lead == None { - r.logger.Infof("%x no leader at term %d; dropping index reading msg", r.id, r.Term) - return - } - m.To = r.lead - r.send(m) - case pb.MsgReadIndexResp: - if len(m.Entries) != 1 { - r.logger.Errorf("%x invalid format of MsgReadIndexResp from %x, entries count: %d", r.id, m.From, len(m.Entries)) - return - } - r.readStates = append(r.readStates, ReadState{Index: m.Index, RequestCtx: m.Entries[0].Data}) - } -} - -func (r *raft) handleAppendEntries(m pb.Message) { - if m.Index < r.raftLog.committed { - r.send(pb.Message{To: m.From, Type: pb.MsgAppResp, Index: r.raftLog.committed}) - return - } - - if mlastIndex, ok := r.raftLog.maybeAppend(m.Index, m.LogTerm, m.Commit, m.Entries...); ok { - r.send(pb.Message{To: m.From, Type: pb.MsgAppResp, Index: mlastIndex}) - } else { - r.logger.Debugf("%x [logterm: %d, index: %d] rejected msgApp [logterm: %d, index: %d] from %x", - r.id, r.raftLog.zeroTermOnErrCompacted(r.raftLog.term(m.Index)), m.Index, m.LogTerm, m.Index, m.From) - r.send(pb.Message{To: m.From, Type: pb.MsgAppResp, Index: m.Index, Reject: true, RejectHint: r.raftLog.lastIndex()}) - } -} - -func (r *raft) handleHeartbeat(m pb.Message) { - r.raftLog.commitTo(m.Commit) - r.send(pb.Message{To: m.From, Type: pb.MsgHeartbeatResp, Context: m.Context}) -} - -func (r *raft) handleSnapshot(m pb.Message) { - sindex, sterm := m.Snapshot.Metadata.Index, m.Snapshot.Metadata.Term - if r.restore(m.Snapshot) { - r.logger.Infof("%x [commit: %d] restored snapshot [index: %d, term: %d]", - r.id, r.raftLog.committed, sindex, sterm) - r.send(pb.Message{To: m.From, Type: pb.MsgAppResp, Index: r.raftLog.lastIndex()}) - } else { - r.logger.Infof("%x [commit: %d] ignored snapshot [index: %d, term: %d]", - r.id, r.raftLog.committed, sindex, sterm) - r.send(pb.Message{To: m.From, Type: pb.MsgAppResp, Index: r.raftLog.committed}) - } -} - -// restore recovers the state machine from a snapshot. It restores the log and the -// configuration of state machine. -func (r *raft) restore(s pb.Snapshot) bool { - if s.Metadata.Index <= r.raftLog.committed { - return false - } - if r.raftLog.matchTerm(s.Metadata.Index, s.Metadata.Term) { - r.logger.Infof("%x [commit: %d, lastindex: %d, lastterm: %d] fast-forwarded commit to snapshot [index: %d, term: %d]", - r.id, r.raftLog.committed, r.raftLog.lastIndex(), r.raftLog.lastTerm(), s.Metadata.Index, s.Metadata.Term) - r.raftLog.commitTo(s.Metadata.Index) - return false - } - - // The normal peer can't become learner. - if !r.isLearner { - for _, id := range s.Metadata.ConfState.Learners { - if id == r.id { - r.logger.Errorf("%x can't become learner when restores snapshot [index: %d, term: %d]", r.id, s.Metadata.Index, s.Metadata.Term) - return false - } - } - } - - r.logger.Infof("%x [commit: %d, lastindex: %d, lastterm: %d] starts to restore snapshot [index: %d, term: %d]", - r.id, r.raftLog.committed, r.raftLog.lastIndex(), r.raftLog.lastTerm(), s.Metadata.Index, s.Metadata.Term) - - r.raftLog.restore(s) - r.prs = make(map[uint64]*Progress) - r.learnerPrs = make(map[uint64]*Progress) - r.restoreNode(s.Metadata.ConfState.Nodes, false) - r.restoreNode(s.Metadata.ConfState.Learners, true) - return true -} - -func (r *raft) restoreNode(nodes []uint64, isLearner bool) { - for _, n := range nodes { - match, next := uint64(0), r.raftLog.lastIndex()+1 - if n == r.id { - match = next - 1 - r.isLearner = isLearner - } - r.setProgress(n, match, next, isLearner) - r.logger.Infof("%x restored progress of %x [%s]", r.id, n, r.getProgress(n)) - } -} - -// promotable indicates whether state machine can be promoted to leader, -// which is true when its own id is in progress list. -func (r *raft) promotable() bool { - _, ok := r.prs[r.id] - return ok -} - -func (r *raft) addNode(id uint64) { - r.addNodeOrLearnerNode(id, false) -} - -func (r *raft) addLearner(id uint64) { - r.addNodeOrLearnerNode(id, true) -} - -func (r *raft) addNodeOrLearnerNode(id uint64, isLearner bool) { - r.pendingConf = false - pr := r.getProgress(id) - if pr == nil { - r.setProgress(id, 0, r.raftLog.lastIndex()+1, isLearner) - } else { - if isLearner && !pr.IsLearner { - // can only change Learner to Voter - r.logger.Infof("%x ignored addLeaner: do not support changing %x from raft peer to learner.", r.id, id) - return - } - - if isLearner == pr.IsLearner { - // Ignore any redundant addNode calls (which can happen because the - // initial bootstrapping entries are applied twice). - return - } - - // change Learner to Voter, use origin Learner progress - delete(r.learnerPrs, id) - pr.IsLearner = false - r.prs[id] = pr - } - - if r.id == id { - r.isLearner = isLearner - } - - // When a node is first added, we should mark it as recently active. - // Otherwise, CheckQuorum may cause us to step down if it is invoked - // before the added node has a chance to communicate with us. - pr = r.getProgress(id) - pr.RecentActive = true -} - -func (r *raft) removeNode(id uint64) { - r.delProgress(id) - r.pendingConf = false - - // do not try to commit or abort transferring if there is no nodes in the cluster. - if len(r.prs) == 0 && len(r.learnerPrs) == 0 { - return - } - - // The quorum size is now smaller, so see if any pending entries can - // be committed. - if r.maybeCommit() { - r.bcastAppend() - } - // If the removed node is the leadTransferee, then abort the leadership transferring. - if r.state == StateLeader && r.leadTransferee == id { - r.abortLeaderTransfer() - } -} - -func (r *raft) resetPendingConf() { r.pendingConf = false } - -func (r *raft) setProgress(id, match, next uint64, isLearner bool) { - if !isLearner { - delete(r.learnerPrs, id) - r.prs[id] = &Progress{Next: next, Match: match, ins: newInflights(r.maxInflight)} - return - } - - if _, ok := r.prs[id]; ok { - panic(fmt.Sprintf("%x unexpected changing from voter to learner for %x", r.id, id)) - } - r.learnerPrs[id] = &Progress{Next: next, Match: match, ins: newInflights(r.maxInflight), IsLearner: true} -} - -func (r *raft) delProgress(id uint64) { - delete(r.prs, id) - delete(r.learnerPrs, id) -} - -func (r *raft) loadState(state pb.HardState) { - if state.Commit < r.raftLog.committed || state.Commit > r.raftLog.lastIndex() { - r.logger.Panicf("%x state.commit %d is out of range [%d, %d]", r.id, state.Commit, r.raftLog.committed, r.raftLog.lastIndex()) - } - r.raftLog.committed = state.Commit - r.Term = state.Term - r.Vote = state.Vote -} - -// pastElectionTimeout returns true iff r.electionElapsed is greater -// than or equal to the randomized election timeout in -// [electiontimeout, 2 * electiontimeout - 1]. -func (r *raft) pastElectionTimeout() bool { - return r.electionElapsed >= r.randomizedElectionTimeout -} - -func (r *raft) resetRandomizedElectionTimeout() { - r.randomizedElectionTimeout = r.electionTimeout + globalRand.Intn(r.electionTimeout) -} - -// checkQuorumActive returns true if the quorum is active from -// the view of the local raft state machine. Otherwise, it returns -// false. -// checkQuorumActive also resets all RecentActive to false. -func (r *raft) checkQuorumActive() bool { - var act int - - r.forEachProgress(func(id uint64, pr *Progress) { - if id == r.id { // self is always active - act++ - return - } - - if pr.RecentActive && !pr.IsLearner { - act++ - } - - pr.RecentActive = false - }) - - return act >= r.quorum() -} - -func (r *raft) sendTimeoutNow(to uint64) { - r.send(pb.Message{To: to, Type: pb.MsgTimeoutNow}) -} - -func (r *raft) abortLeaderTransfer() { - r.leadTransferee = None -} - -func numOfPendingConf(ents []pb.Entry) int { - n := 0 - for i := range ents { - if ents[i].Type == pb.EntryConfChange { - n++ - } - } - return n -} diff --git a/vendor/github.com/coreos/etcd/raft/raftpb/raft.pb.go b/vendor/github.com/coreos/etcd/raft/raftpb/raft.pb.go deleted file mode 100644 index fd9ee3729ecb..000000000000 --- a/vendor/github.com/coreos/etcd/raft/raftpb/raft.pb.go +++ /dev/null @@ -1,2004 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: raft.proto - -/* - Package raftpb is a generated protocol buffer package. - - It is generated from these files: - raft.proto - - It has these top-level messages: - Entry - SnapshotMetadata - Snapshot - Message - HardState - ConfState - ConfChange -*/ -package raftpb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type EntryType int32 - -const ( - EntryNormal EntryType = 0 - EntryConfChange EntryType = 1 -) - -var EntryType_name = map[int32]string{ - 0: "EntryNormal", - 1: "EntryConfChange", -} -var EntryType_value = map[string]int32{ - "EntryNormal": 0, - "EntryConfChange": 1, -} - -func (x EntryType) Enum() *EntryType { - p := new(EntryType) - *p = x - return p -} -func (x EntryType) String() string { - return proto.EnumName(EntryType_name, int32(x)) -} -func (x *EntryType) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(EntryType_value, data, "EntryType") - if err != nil { - return err - } - *x = EntryType(value) - return nil -} -func (EntryType) EnumDescriptor() ([]byte, []int) { return fileDescriptorRaft, []int{0} } - -type MessageType int32 - -const ( - MsgHup MessageType = 0 - MsgBeat MessageType = 1 - MsgProp MessageType = 2 - MsgApp MessageType = 3 - MsgAppResp MessageType = 4 - MsgVote MessageType = 5 - MsgVoteResp MessageType = 6 - MsgSnap MessageType = 7 - MsgHeartbeat MessageType = 8 - MsgHeartbeatResp MessageType = 9 - MsgUnreachable MessageType = 10 - MsgSnapStatus MessageType = 11 - MsgCheckQuorum MessageType = 12 - MsgTransferLeader MessageType = 13 - MsgTimeoutNow MessageType = 14 - MsgReadIndex MessageType = 15 - MsgReadIndexResp MessageType = 16 - MsgPreVote MessageType = 17 - MsgPreVoteResp MessageType = 18 -) - -var MessageType_name = map[int32]string{ - 0: "MsgHup", - 1: "MsgBeat", - 2: "MsgProp", - 3: "MsgApp", - 4: "MsgAppResp", - 5: "MsgVote", - 6: "MsgVoteResp", - 7: "MsgSnap", - 8: "MsgHeartbeat", - 9: "MsgHeartbeatResp", - 10: "MsgUnreachable", - 11: "MsgSnapStatus", - 12: "MsgCheckQuorum", - 13: "MsgTransferLeader", - 14: "MsgTimeoutNow", - 15: "MsgReadIndex", - 16: "MsgReadIndexResp", - 17: "MsgPreVote", - 18: "MsgPreVoteResp", -} -var MessageType_value = map[string]int32{ - "MsgHup": 0, - "MsgBeat": 1, - "MsgProp": 2, - "MsgApp": 3, - "MsgAppResp": 4, - "MsgVote": 5, - "MsgVoteResp": 6, - "MsgSnap": 7, - "MsgHeartbeat": 8, - "MsgHeartbeatResp": 9, - "MsgUnreachable": 10, - "MsgSnapStatus": 11, - "MsgCheckQuorum": 12, - "MsgTransferLeader": 13, - "MsgTimeoutNow": 14, - "MsgReadIndex": 15, - "MsgReadIndexResp": 16, - "MsgPreVote": 17, - "MsgPreVoteResp": 18, -} - -func (x MessageType) Enum() *MessageType { - p := new(MessageType) - *p = x - return p -} -func (x MessageType) String() string { - return proto.EnumName(MessageType_name, int32(x)) -} -func (x *MessageType) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(MessageType_value, data, "MessageType") - if err != nil { - return err - } - *x = MessageType(value) - return nil -} -func (MessageType) EnumDescriptor() ([]byte, []int) { return fileDescriptorRaft, []int{1} } - -type ConfChangeType int32 - -const ( - ConfChangeAddNode ConfChangeType = 0 - ConfChangeRemoveNode ConfChangeType = 1 - ConfChangeUpdateNode ConfChangeType = 2 - ConfChangeAddLearnerNode ConfChangeType = 3 -) - -var ConfChangeType_name = map[int32]string{ - 0: "ConfChangeAddNode", - 1: "ConfChangeRemoveNode", - 2: "ConfChangeUpdateNode", - 3: "ConfChangeAddLearnerNode", -} -var ConfChangeType_value = map[string]int32{ - "ConfChangeAddNode": 0, - "ConfChangeRemoveNode": 1, - "ConfChangeUpdateNode": 2, - "ConfChangeAddLearnerNode": 3, -} - -func (x ConfChangeType) Enum() *ConfChangeType { - p := new(ConfChangeType) - *p = x - return p -} -func (x ConfChangeType) String() string { - return proto.EnumName(ConfChangeType_name, int32(x)) -} -func (x *ConfChangeType) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(ConfChangeType_value, data, "ConfChangeType") - if err != nil { - return err - } - *x = ConfChangeType(value) - return nil -} -func (ConfChangeType) EnumDescriptor() ([]byte, []int) { return fileDescriptorRaft, []int{2} } - -type Entry struct { - Term uint64 `protobuf:"varint,2,opt,name=Term" json:"Term"` - Index uint64 `protobuf:"varint,3,opt,name=Index" json:"Index"` - Type EntryType `protobuf:"varint,1,opt,name=Type,enum=raftpb.EntryType" json:"Type"` - Data []byte `protobuf:"bytes,4,opt,name=Data" json:"Data,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Entry) Reset() { *m = Entry{} } -func (m *Entry) String() string { return proto.CompactTextString(m) } -func (*Entry) ProtoMessage() {} -func (*Entry) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{0} } - -type SnapshotMetadata struct { - ConfState ConfState `protobuf:"bytes,1,opt,name=conf_state,json=confState" json:"conf_state"` - Index uint64 `protobuf:"varint,2,opt,name=index" json:"index"` - Term uint64 `protobuf:"varint,3,opt,name=term" json:"term"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *SnapshotMetadata) Reset() { *m = SnapshotMetadata{} } -func (m *SnapshotMetadata) String() string { return proto.CompactTextString(m) } -func (*SnapshotMetadata) ProtoMessage() {} -func (*SnapshotMetadata) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{1} } - -type Snapshot struct { - Data []byte `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"` - Metadata SnapshotMetadata `protobuf:"bytes,2,opt,name=metadata" json:"metadata"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Snapshot) Reset() { *m = Snapshot{} } -func (m *Snapshot) String() string { return proto.CompactTextString(m) } -func (*Snapshot) ProtoMessage() {} -func (*Snapshot) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{2} } - -type Message struct { - Type MessageType `protobuf:"varint,1,opt,name=type,enum=raftpb.MessageType" json:"type"` - To uint64 `protobuf:"varint,2,opt,name=to" json:"to"` - From uint64 `protobuf:"varint,3,opt,name=from" json:"from"` - Term uint64 `protobuf:"varint,4,opt,name=term" json:"term"` - LogTerm uint64 `protobuf:"varint,5,opt,name=logTerm" json:"logTerm"` - Index uint64 `protobuf:"varint,6,opt,name=index" json:"index"` - Entries []Entry `protobuf:"bytes,7,rep,name=entries" json:"entries"` - Commit uint64 `protobuf:"varint,8,opt,name=commit" json:"commit"` - Snapshot Snapshot `protobuf:"bytes,9,opt,name=snapshot" json:"snapshot"` - Reject bool `protobuf:"varint,10,opt,name=reject" json:"reject"` - RejectHint uint64 `protobuf:"varint,11,opt,name=rejectHint" json:"rejectHint"` - Context []byte `protobuf:"bytes,12,opt,name=context" json:"context,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Message) Reset() { *m = Message{} } -func (m *Message) String() string { return proto.CompactTextString(m) } -func (*Message) ProtoMessage() {} -func (*Message) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{3} } - -type HardState struct { - Term uint64 `protobuf:"varint,1,opt,name=term" json:"term"` - Vote uint64 `protobuf:"varint,2,opt,name=vote" json:"vote"` - Commit uint64 `protobuf:"varint,3,opt,name=commit" json:"commit"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *HardState) Reset() { *m = HardState{} } -func (m *HardState) String() string { return proto.CompactTextString(m) } -func (*HardState) ProtoMessage() {} -func (*HardState) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{4} } - -type ConfState struct { - Nodes []uint64 `protobuf:"varint,1,rep,name=nodes" json:"nodes,omitempty"` - Learners []uint64 `protobuf:"varint,2,rep,name=learners" json:"learners,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *ConfState) Reset() { *m = ConfState{} } -func (m *ConfState) String() string { return proto.CompactTextString(m) } -func (*ConfState) ProtoMessage() {} -func (*ConfState) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{5} } - -type ConfChange struct { - ID uint64 `protobuf:"varint,1,opt,name=ID" json:"ID"` - Type ConfChangeType `protobuf:"varint,2,opt,name=Type,enum=raftpb.ConfChangeType" json:"Type"` - NodeID uint64 `protobuf:"varint,3,opt,name=NodeID" json:"NodeID"` - Context []byte `protobuf:"bytes,4,opt,name=Context" json:"Context,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *ConfChange) Reset() { *m = ConfChange{} } -func (m *ConfChange) String() string { return proto.CompactTextString(m) } -func (*ConfChange) ProtoMessage() {} -func (*ConfChange) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{6} } - -func init() { - proto.RegisterType((*Entry)(nil), "raftpb.Entry") - proto.RegisterType((*SnapshotMetadata)(nil), "raftpb.SnapshotMetadata") - proto.RegisterType((*Snapshot)(nil), "raftpb.Snapshot") - proto.RegisterType((*Message)(nil), "raftpb.Message") - proto.RegisterType((*HardState)(nil), "raftpb.HardState") - proto.RegisterType((*ConfState)(nil), "raftpb.ConfState") - proto.RegisterType((*ConfChange)(nil), "raftpb.ConfChange") - proto.RegisterEnum("raftpb.EntryType", EntryType_name, EntryType_value) - proto.RegisterEnum("raftpb.MessageType", MessageType_name, MessageType_value) - proto.RegisterEnum("raftpb.ConfChangeType", ConfChangeType_name, ConfChangeType_value) -} -func (m *Entry) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Entry) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Type)) - dAtA[i] = 0x10 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Term)) - dAtA[i] = 0x18 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Index)) - if m.Data != nil { - dAtA[i] = 0x22 - i++ - i = encodeVarintRaft(dAtA, i, uint64(len(m.Data))) - i += copy(dAtA[i:], m.Data) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *SnapshotMetadata) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SnapshotMetadata) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - dAtA[i] = 0xa - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.ConfState.Size())) - n1, err := m.ConfState.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - dAtA[i] = 0x10 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Index)) - dAtA[i] = 0x18 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Term)) - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *Snapshot) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Snapshot) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Data != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRaft(dAtA, i, uint64(len(m.Data))) - i += copy(dAtA[i:], m.Data) - } - dAtA[i] = 0x12 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Metadata.Size())) - n2, err := m.Metadata.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *Message) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Message) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Type)) - dAtA[i] = 0x10 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.To)) - dAtA[i] = 0x18 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.From)) - dAtA[i] = 0x20 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Term)) - dAtA[i] = 0x28 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.LogTerm)) - dAtA[i] = 0x30 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Index)) - if len(m.Entries) > 0 { - for _, msg := range m.Entries { - dAtA[i] = 0x3a - i++ - i = encodeVarintRaft(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - dAtA[i] = 0x40 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Commit)) - dAtA[i] = 0x4a - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Snapshot.Size())) - n3, err := m.Snapshot.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n3 - dAtA[i] = 0x50 - i++ - if m.Reject { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - dAtA[i] = 0x58 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.RejectHint)) - if m.Context != nil { - dAtA[i] = 0x62 - i++ - i = encodeVarintRaft(dAtA, i, uint64(len(m.Context))) - i += copy(dAtA[i:], m.Context) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *HardState) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *HardState) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Term)) - dAtA[i] = 0x10 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Vote)) - dAtA[i] = 0x18 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Commit)) - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *ConfState) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ConfState) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Nodes) > 0 { - for _, num := range m.Nodes { - dAtA[i] = 0x8 - i++ - i = encodeVarintRaft(dAtA, i, uint64(num)) - } - } - if len(m.Learners) > 0 { - for _, num := range m.Learners { - dAtA[i] = 0x10 - i++ - i = encodeVarintRaft(dAtA, i, uint64(num)) - } - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *ConfChange) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ConfChange) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.ID)) - dAtA[i] = 0x10 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Type)) - dAtA[i] = 0x18 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.NodeID)) - if m.Context != nil { - dAtA[i] = 0x22 - i++ - i = encodeVarintRaft(dAtA, i, uint64(len(m.Context))) - i += copy(dAtA[i:], m.Context) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func encodeVarintRaft(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *Entry) Size() (n int) { - var l int - _ = l - n += 1 + sovRaft(uint64(m.Type)) - n += 1 + sovRaft(uint64(m.Term)) - n += 1 + sovRaft(uint64(m.Index)) - if m.Data != nil { - l = len(m.Data) - n += 1 + l + sovRaft(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *SnapshotMetadata) Size() (n int) { - var l int - _ = l - l = m.ConfState.Size() - n += 1 + l + sovRaft(uint64(l)) - n += 1 + sovRaft(uint64(m.Index)) - n += 1 + sovRaft(uint64(m.Term)) - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *Snapshot) Size() (n int) { - var l int - _ = l - if m.Data != nil { - l = len(m.Data) - n += 1 + l + sovRaft(uint64(l)) - } - l = m.Metadata.Size() - n += 1 + l + sovRaft(uint64(l)) - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *Message) Size() (n int) { - var l int - _ = l - n += 1 + sovRaft(uint64(m.Type)) - n += 1 + sovRaft(uint64(m.To)) - n += 1 + sovRaft(uint64(m.From)) - n += 1 + sovRaft(uint64(m.Term)) - n += 1 + sovRaft(uint64(m.LogTerm)) - n += 1 + sovRaft(uint64(m.Index)) - if len(m.Entries) > 0 { - for _, e := range m.Entries { - l = e.Size() - n += 1 + l + sovRaft(uint64(l)) - } - } - n += 1 + sovRaft(uint64(m.Commit)) - l = m.Snapshot.Size() - n += 1 + l + sovRaft(uint64(l)) - n += 2 - n += 1 + sovRaft(uint64(m.RejectHint)) - if m.Context != nil { - l = len(m.Context) - n += 1 + l + sovRaft(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *HardState) Size() (n int) { - var l int - _ = l - n += 1 + sovRaft(uint64(m.Term)) - n += 1 + sovRaft(uint64(m.Vote)) - n += 1 + sovRaft(uint64(m.Commit)) - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *ConfState) Size() (n int) { - var l int - _ = l - if len(m.Nodes) > 0 { - for _, e := range m.Nodes { - n += 1 + sovRaft(uint64(e)) - } - } - if len(m.Learners) > 0 { - for _, e := range m.Learners { - n += 1 + sovRaft(uint64(e)) - } - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *ConfChange) Size() (n int) { - var l int - _ = l - n += 1 + sovRaft(uint64(m.ID)) - n += 1 + sovRaft(uint64(m.Type)) - n += 1 + sovRaft(uint64(m.NodeID)) - if m.Context != nil { - l = len(m.Context) - n += 1 + l + sovRaft(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func sovRaft(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozRaft(x uint64) (n int) { - return sovRaft(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Entry) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Entry: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Entry: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= (EntryType(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType) - } - m.Term = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Term |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) - } - m.Index = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Index |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *SnapshotMetadata) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SnapshotMetadata: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SnapshotMetadata: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ConfState", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.ConfState.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) - } - m.Index = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Index |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType) - } - m.Term = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Term |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Snapshot) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Snapshot: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Snapshot: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Metadata", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Metadata.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Message) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Message: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Message: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= (MessageType(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field To", wireType) - } - m.To = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.To |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field From", wireType) - } - m.From = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.From |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType) - } - m.Term = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Term |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field LogTerm", wireType) - } - m.LogTerm = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.LogTerm |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) - } - m.Index = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Index |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Entries", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Entries = append(m.Entries, Entry{}) - if err := m.Entries[len(m.Entries)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Commit", wireType) - } - m.Commit = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Commit |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 9: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Snapshot", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Snapshot.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 10: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Reject", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Reject = bool(v != 0) - case 11: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RejectHint", wireType) - } - m.RejectHint = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RejectHint |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 12: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Context", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Context = append(m.Context[:0], dAtA[iNdEx:postIndex]...) - if m.Context == nil { - m.Context = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *HardState) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: HardState: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HardState: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType) - } - m.Term = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Term |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Vote", wireType) - } - m.Vote = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Vote |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Commit", wireType) - } - m.Commit = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Commit |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ConfState) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ConfState: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ConfState: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType == 0 { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Nodes = append(m.Nodes, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + packedLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - for iNdEx < postIndex { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Nodes = append(m.Nodes, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field Nodes", wireType) - } - case 2: - if wireType == 0 { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Learners = append(m.Learners, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + packedLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - for iNdEx < postIndex { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Learners = append(m.Learners, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field Learners", wireType) - } - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ConfChange) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ConfChange: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ConfChange: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= (ConfChangeType(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field NodeID", wireType) - } - m.NodeID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.NodeID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Context", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Context = append(m.Context[:0], dAtA[iNdEx:postIndex]...) - if m.Context == nil { - m.Context = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipRaft(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaft - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaft - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaft - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthRaft - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaft - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipRaft(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthRaft = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowRaft = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("raft.proto", fileDescriptorRaft) } - -var fileDescriptorRaft = []byte{ - // 815 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x54, 0xcd, 0x6e, 0x23, 0x45, - 0x10, 0xf6, 0x8c, 0xc7, 0x7f, 0x35, 0x8e, 0xd3, 0xa9, 0x35, 0xa8, 0x15, 0x45, 0xc6, 0xb2, 0x38, - 0x58, 0x41, 0x1b, 0x20, 0x07, 0x0e, 0x48, 0x1c, 0x36, 0x09, 0x52, 0x22, 0xad, 0xa3, 0xc5, 0x9b, - 0xe5, 0x80, 0x84, 0x50, 0xc7, 0x53, 0x9e, 0x18, 0x32, 0xd3, 0xa3, 0x9e, 0xf6, 0xb2, 0xb9, 0x20, - 0x1e, 0x80, 0x07, 0xe0, 0xc2, 0xfb, 0xe4, 0xb8, 0x12, 0x77, 0xc4, 0x86, 0x17, 0x41, 0xdd, 0xd3, - 0x63, 0xcf, 0x24, 0xb7, 0xae, 0xef, 0xab, 0xae, 0xfa, 0xea, 0xeb, 0x9a, 0x01, 0x50, 0x62, 0xa9, - 0x8f, 0x32, 0x25, 0xb5, 0xc4, 0xb6, 0x39, 0x67, 0xd7, 0xfb, 0xc3, 0x58, 0xc6, 0xd2, 0x42, 0x9f, - 0x9b, 0x53, 0xc1, 0x4e, 0x7e, 0x83, 0xd6, 0xb7, 0xa9, 0x56, 0x77, 0xf8, 0x19, 0x04, 0x57, 0x77, - 0x19, 0x71, 0x6f, 0xec, 0x4d, 0x07, 0xc7, 0x7b, 0x47, 0xc5, 0xad, 0x23, 0x4b, 0x1a, 0xe2, 0x24, - 0xb8, 0xff, 0xe7, 0x93, 0xc6, 0xdc, 0x26, 0x21, 0x87, 0xe0, 0x8a, 0x54, 0xc2, 0xfd, 0xb1, 0x37, - 0x0d, 0x36, 0x0c, 0xa9, 0x04, 0xf7, 0xa1, 0x75, 0x91, 0x46, 0xf4, 0x8e, 0x37, 0x2b, 0x54, 0x01, - 0x21, 0x42, 0x70, 0x26, 0xb4, 0xe0, 0xc1, 0xd8, 0x9b, 0xf6, 0xe7, 0xf6, 0x3c, 0xf9, 0xdd, 0x03, - 0xf6, 0x3a, 0x15, 0x59, 0x7e, 0x23, 0xf5, 0x8c, 0xb4, 0x88, 0x84, 0x16, 0xf8, 0x15, 0xc0, 0x42, - 0xa6, 0xcb, 0x9f, 0x72, 0x2d, 0x74, 0xa1, 0x28, 0xdc, 0x2a, 0x3a, 0x95, 0xe9, 0xf2, 0xb5, 0x21, - 0x5c, 0xf1, 0xde, 0xa2, 0x04, 0x4c, 0xf3, 0x95, 0x6d, 0x5e, 0xd5, 0x55, 0x40, 0x46, 0xb2, 0x36, - 0x92, 0xab, 0xba, 0x2c, 0x32, 0xf9, 0x01, 0xba, 0xa5, 0x02, 0x23, 0xd1, 0x28, 0xb0, 0x3d, 0xfb, - 0x73, 0x7b, 0xc6, 0xaf, 0xa1, 0x9b, 0x38, 0x65, 0xb6, 0x70, 0x78, 0xcc, 0x4b, 0x2d, 0x8f, 0x95, - 0xbb, 0xba, 0x9b, 0xfc, 0xc9, 0x5f, 0x4d, 0xe8, 0xcc, 0x28, 0xcf, 0x45, 0x4c, 0xf8, 0x1c, 0x02, - 0xbd, 0x75, 0xf8, 0x59, 0x59, 0xc3, 0xd1, 0x55, 0x8f, 0x4d, 0x1a, 0x0e, 0xc1, 0xd7, 0xb2, 0x36, - 0x89, 0xaf, 0xa5, 0x19, 0x63, 0xa9, 0xe4, 0xa3, 0x31, 0x0c, 0xb2, 0x19, 0x30, 0x78, 0x3c, 0x20, - 0x8e, 0xa0, 0x73, 0x2b, 0x63, 0xfb, 0x60, 0xad, 0x0a, 0x59, 0x82, 0x5b, 0xdb, 0xda, 0x4f, 0x6d, - 0x7b, 0x0e, 0x1d, 0x4a, 0xb5, 0x5a, 0x51, 0xce, 0x3b, 0xe3, 0xe6, 0x34, 0x3c, 0xde, 0xa9, 0x6d, - 0x46, 0x59, 0xca, 0xe5, 0xe0, 0x01, 0xb4, 0x17, 0x32, 0x49, 0x56, 0x9a, 0x77, 0x2b, 0xb5, 0x1c, - 0x86, 0xc7, 0xd0, 0xcd, 0x9d, 0x63, 0xbc, 0x67, 0x9d, 0x64, 0x8f, 0x9d, 0x2c, 0x1d, 0x2c, 0xf3, - 0x4c, 0x45, 0x45, 0x3f, 0xd3, 0x42, 0x73, 0x18, 0x7b, 0xd3, 0x6e, 0x59, 0xb1, 0xc0, 0xf0, 0x53, - 0x80, 0xe2, 0x74, 0xbe, 0x4a, 0x35, 0x0f, 0x2b, 0x3d, 0x2b, 0x38, 0x72, 0xe8, 0x2c, 0x64, 0xaa, - 0xe9, 0x9d, 0xe6, 0x7d, 0xfb, 0xb0, 0x65, 0x38, 0xf9, 0x11, 0x7a, 0xe7, 0x42, 0x45, 0xc5, 0xfa, - 0x94, 0x0e, 0x7a, 0x4f, 0x1c, 0xe4, 0x10, 0xbc, 0x95, 0x9a, 0xea, 0xfb, 0x6e, 0x90, 0xca, 0xc0, - 0xcd, 0xa7, 0x03, 0x4f, 0xbe, 0x81, 0xde, 0x66, 0x5d, 0x71, 0x08, 0xad, 0x54, 0x46, 0x94, 0x73, - 0x6f, 0xdc, 0x9c, 0x06, 0xf3, 0x22, 0xc0, 0x7d, 0xe8, 0xde, 0x92, 0x50, 0x29, 0xa9, 0x9c, 0xfb, - 0x96, 0xd8, 0xc4, 0x93, 0x3f, 0x3c, 0x00, 0x73, 0xff, 0xf4, 0x46, 0xa4, 0xb1, 0xdd, 0x88, 0x8b, - 0xb3, 0x9a, 0x3a, 0xff, 0xe2, 0x0c, 0xbf, 0x70, 0x1f, 0xae, 0x6f, 0xd7, 0xea, 0xe3, 0xea, 0x67, - 0x52, 0xdc, 0x7b, 0xf2, 0xf5, 0x1e, 0x40, 0xfb, 0x52, 0x46, 0x74, 0x71, 0x56, 0xd7, 0x5c, 0x60, - 0xc6, 0xac, 0x53, 0x67, 0x56, 0xf1, 0xa1, 0x96, 0xe1, 0xe1, 0x97, 0xd0, 0xdb, 0xfc, 0x0e, 0x70, - 0x17, 0x42, 0x1b, 0x5c, 0x4a, 0x95, 0x88, 0x5b, 0xd6, 0xc0, 0x67, 0xb0, 0x6b, 0x81, 0x6d, 0x63, - 0xe6, 0x1d, 0xfe, 0xed, 0x43, 0x58, 0x59, 0x70, 0x04, 0x68, 0xcf, 0xf2, 0xf8, 0x7c, 0x9d, 0xb1, - 0x06, 0x86, 0xd0, 0x99, 0xe5, 0xf1, 0x09, 0x09, 0xcd, 0x3c, 0x17, 0xbc, 0x52, 0x32, 0x63, 0xbe, - 0xcb, 0x7a, 0x91, 0x65, 0xac, 0x89, 0x03, 0x80, 0xe2, 0x3c, 0xa7, 0x3c, 0x63, 0x81, 0x4b, 0xfc, - 0x5e, 0x6a, 0x62, 0x2d, 0x23, 0xc2, 0x05, 0x96, 0x6d, 0x3b, 0xd6, 0x2c, 0x13, 0xeb, 0x20, 0x83, - 0xbe, 0x69, 0x46, 0x42, 0xe9, 0x6b, 0xd3, 0xa5, 0x8b, 0x43, 0x60, 0x55, 0xc4, 0x5e, 0xea, 0x21, - 0xc2, 0x60, 0x96, 0xc7, 0x6f, 0x52, 0x45, 0x62, 0x71, 0x23, 0xae, 0x6f, 0x89, 0x01, 0xee, 0xc1, - 0x8e, 0x2b, 0x64, 0x1e, 0x6f, 0x9d, 0xb3, 0xd0, 0xa5, 0x9d, 0xde, 0xd0, 0xe2, 0x97, 0xef, 0xd6, - 0x52, 0xad, 0x13, 0xd6, 0xc7, 0x8f, 0x60, 0x6f, 0x96, 0xc7, 0x57, 0x4a, 0xa4, 0xf9, 0x92, 0xd4, - 0x4b, 0x12, 0x11, 0x29, 0xb6, 0xe3, 0x6e, 0x5f, 0xad, 0x12, 0x92, 0x6b, 0x7d, 0x29, 0x7f, 0x65, - 0x03, 0x27, 0x66, 0x4e, 0x22, 0xb2, 0x3f, 0x43, 0xb6, 0xeb, 0xc4, 0x6c, 0x10, 0x2b, 0x86, 0xb9, - 0x79, 0x5f, 0x29, 0xb2, 0x23, 0xee, 0xb9, 0xae, 0x2e, 0xb6, 0x39, 0x78, 0x78, 0x07, 0x83, 0xfa, - 0xf3, 0x1a, 0x1d, 0x5b, 0xe4, 0x45, 0x14, 0x99, 0xb7, 0x64, 0x0d, 0xe4, 0x30, 0xdc, 0xc2, 0x73, - 0x4a, 0xe4, 0x5b, 0xb2, 0x8c, 0x57, 0x67, 0xde, 0x64, 0x91, 0xd0, 0x05, 0xe3, 0xe3, 0x01, 0xf0, - 0x5a, 0xa9, 0x97, 0xc5, 0x36, 0x5a, 0xb6, 0x79, 0xc2, 0xef, 0x3f, 0x8c, 0x1a, 0xef, 0x3f, 0x8c, - 0x1a, 0xf7, 0x0f, 0x23, 0xef, 0xfd, 0xc3, 0xc8, 0xfb, 0xf7, 0x61, 0xe4, 0xfd, 0xf9, 0xdf, 0xa8, - 0xf1, 0x7f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x86, 0x52, 0x5b, 0xe0, 0x74, 0x06, 0x00, 0x00, -} diff --git a/vendor/github.com/coreos/etcd/raft/rawnode.go b/vendor/github.com/coreos/etcd/raft/rawnode.go deleted file mode 100644 index 925cb851c4ad..000000000000 --- a/vendor/github.com/coreos/etcd/raft/rawnode.go +++ /dev/null @@ -1,266 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "errors" - - pb "github.com/coreos/etcd/raft/raftpb" -) - -// ErrStepLocalMsg is returned when try to step a local raft message -var ErrStepLocalMsg = errors.New("raft: cannot step raft local message") - -// ErrStepPeerNotFound is returned when try to step a response message -// but there is no peer found in raft.prs for that node. -var ErrStepPeerNotFound = errors.New("raft: cannot step as peer not found") - -// RawNode is a thread-unsafe Node. -// The methods of this struct correspond to the methods of Node and are described -// more fully there. -type RawNode struct { - raft *raft - prevSoftSt *SoftState - prevHardSt pb.HardState -} - -func (rn *RawNode) newReady() Ready { - return newReady(rn.raft, rn.prevSoftSt, rn.prevHardSt) -} - -func (rn *RawNode) commitReady(rd Ready) { - if rd.SoftState != nil { - rn.prevSoftSt = rd.SoftState - } - if !IsEmptyHardState(rd.HardState) { - rn.prevHardSt = rd.HardState - } - if rn.prevHardSt.Commit != 0 { - // In most cases, prevHardSt and rd.HardState will be the same - // because when there are new entries to apply we just sent a - // HardState with an updated Commit value. However, on initial - // startup the two are different because we don't send a HardState - // until something changes, but we do send any un-applied but - // committed entries (and previously-committed entries may be - // incorporated into the snapshot, even if rd.CommittedEntries is - // empty). Therefore we mark all committed entries as applied - // whether they were included in rd.HardState or not. - rn.raft.raftLog.appliedTo(rn.prevHardSt.Commit) - } - if len(rd.Entries) > 0 { - e := rd.Entries[len(rd.Entries)-1] - rn.raft.raftLog.stableTo(e.Index, e.Term) - } - if !IsEmptySnap(rd.Snapshot) { - rn.raft.raftLog.stableSnapTo(rd.Snapshot.Metadata.Index) - } - if len(rd.ReadStates) != 0 { - rn.raft.readStates = nil - } -} - -// NewRawNode returns a new RawNode given configuration and a list of raft peers. -func NewRawNode(config *Config, peers []Peer) (*RawNode, error) { - if config.ID == 0 { - panic("config.ID must not be zero") - } - r := newRaft(config) - rn := &RawNode{ - raft: r, - } - lastIndex, err := config.Storage.LastIndex() - if err != nil { - panic(err) // TODO(bdarnell) - } - // If the log is empty, this is a new RawNode (like StartNode); otherwise it's - // restoring an existing RawNode (like RestartNode). - // TODO(bdarnell): rethink RawNode initialization and whether the application needs - // to be able to tell us when it expects the RawNode to exist. - if lastIndex == 0 { - r.becomeFollower(1, None) - ents := make([]pb.Entry, len(peers)) - for i, peer := range peers { - cc := pb.ConfChange{Type: pb.ConfChangeAddNode, NodeID: peer.ID, Context: peer.Context} - data, err := cc.Marshal() - if err != nil { - panic("unexpected marshal error") - } - - ents[i] = pb.Entry{Type: pb.EntryConfChange, Term: 1, Index: uint64(i + 1), Data: data} - } - r.raftLog.append(ents...) - r.raftLog.committed = uint64(len(ents)) - for _, peer := range peers { - r.addNode(peer.ID) - } - } - - // Set the initial hard and soft states after performing all initialization. - rn.prevSoftSt = r.softState() - if lastIndex == 0 { - rn.prevHardSt = emptyState - } else { - rn.prevHardSt = r.hardState() - } - - return rn, nil -} - -// Tick advances the internal logical clock by a single tick. -func (rn *RawNode) Tick() { - rn.raft.tick() -} - -// TickQuiesced advances the internal logical clock by a single tick without -// performing any other state machine processing. It allows the caller to avoid -// periodic heartbeats and elections when all of the peers in a Raft group are -// known to be at the same state. Expected usage is to periodically invoke Tick -// or TickQuiesced depending on whether the group is "active" or "quiesced". -// -// WARNING: Be very careful about using this method as it subverts the Raft -// state machine. You should probably be using Tick instead. -func (rn *RawNode) TickQuiesced() { - rn.raft.electionElapsed++ -} - -// Campaign causes this RawNode to transition to candidate state. -func (rn *RawNode) Campaign() error { - return rn.raft.Step(pb.Message{ - Type: pb.MsgHup, - }) -} - -// Propose proposes data be appended to the raft log. -func (rn *RawNode) Propose(data []byte) error { - return rn.raft.Step(pb.Message{ - Type: pb.MsgProp, - From: rn.raft.id, - Entries: []pb.Entry{ - {Data: data}, - }}) -} - -// ProposeConfChange proposes a config change. -func (rn *RawNode) ProposeConfChange(cc pb.ConfChange) error { - data, err := cc.Marshal() - if err != nil { - return err - } - return rn.raft.Step(pb.Message{ - Type: pb.MsgProp, - Entries: []pb.Entry{ - {Type: pb.EntryConfChange, Data: data}, - }, - }) -} - -// ApplyConfChange applies a config change to the local node. -func (rn *RawNode) ApplyConfChange(cc pb.ConfChange) *pb.ConfState { - if cc.NodeID == None { - rn.raft.resetPendingConf() - return &pb.ConfState{Nodes: rn.raft.nodes()} - } - switch cc.Type { - case pb.ConfChangeAddNode: - rn.raft.addNode(cc.NodeID) - case pb.ConfChangeAddLearnerNode: - rn.raft.addLearner(cc.NodeID) - case pb.ConfChangeRemoveNode: - rn.raft.removeNode(cc.NodeID) - case pb.ConfChangeUpdateNode: - rn.raft.resetPendingConf() - default: - panic("unexpected conf type") - } - return &pb.ConfState{Nodes: rn.raft.nodes()} -} - -// Step advances the state machine using the given message. -func (rn *RawNode) Step(m pb.Message) error { - // ignore unexpected local messages receiving over network - if IsLocalMsg(m.Type) { - return ErrStepLocalMsg - } - if pr := rn.raft.getProgress(m.From); pr != nil || !IsResponseMsg(m.Type) { - return rn.raft.Step(m) - } - return ErrStepPeerNotFound -} - -// Ready returns the current point-in-time state of this RawNode. -func (rn *RawNode) Ready() Ready { - rd := rn.newReady() - rn.raft.msgs = nil - return rd -} - -// HasReady called when RawNode user need to check if any Ready pending. -// Checking logic in this method should be consistent with Ready.containsUpdates(). -func (rn *RawNode) HasReady() bool { - r := rn.raft - if !r.softState().equal(rn.prevSoftSt) { - return true - } - if hardSt := r.hardState(); !IsEmptyHardState(hardSt) && !isHardStateEqual(hardSt, rn.prevHardSt) { - return true - } - if r.raftLog.unstable.snapshot != nil && !IsEmptySnap(*r.raftLog.unstable.snapshot) { - return true - } - if len(r.msgs) > 0 || len(r.raftLog.unstableEntries()) > 0 || r.raftLog.hasNextEnts() { - return true - } - if len(r.readStates) != 0 { - return true - } - return false -} - -// Advance notifies the RawNode that the application has applied and saved progress in the -// last Ready results. -func (rn *RawNode) Advance(rd Ready) { - rn.commitReady(rd) -} - -// Status returns the current status of the given group. -func (rn *RawNode) Status() *Status { - status := getStatus(rn.raft) - return &status -} - -// ReportUnreachable reports the given node is not reachable for the last send. -func (rn *RawNode) ReportUnreachable(id uint64) { - _ = rn.raft.Step(pb.Message{Type: pb.MsgUnreachable, From: id}) -} - -// ReportSnapshot reports the status of the sent snapshot. -func (rn *RawNode) ReportSnapshot(id uint64, status SnapshotStatus) { - rej := status == SnapshotFailure - - _ = rn.raft.Step(pb.Message{Type: pb.MsgSnapStatus, From: id, Reject: rej}) -} - -// TransferLeader tries to transfer leadership to the given transferee. -func (rn *RawNode) TransferLeader(transferee uint64) { - _ = rn.raft.Step(pb.Message{Type: pb.MsgTransferLeader, From: transferee}) -} - -// ReadIndex requests a read state. The read state will be set in ready. -// Read State has a read index. Once the application advances further than the read -// index, any linearizable read requests issued before the read request can be -// processed safely. The read state will have the same rctx attached. -func (rn *RawNode) ReadIndex(rctx []byte) { - _ = rn.raft.Step(pb.Message{Type: pb.MsgReadIndex, Entries: []pb.Entry{{Data: rctx}}}) -} diff --git a/vendor/github.com/coreos/etcd/raft/read_only.go b/vendor/github.com/coreos/etcd/raft/read_only.go deleted file mode 100644 index ae746fa73eb3..000000000000 --- a/vendor/github.com/coreos/etcd/raft/read_only.go +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import pb "github.com/coreos/etcd/raft/raftpb" - -// ReadState provides state for read only query. -// It's caller's responsibility to call ReadIndex first before getting -// this state from ready, it's also caller's duty to differentiate if this -// state is what it requests through RequestCtx, eg. given a unique id as -// RequestCtx -type ReadState struct { - Index uint64 - RequestCtx []byte -} - -type readIndexStatus struct { - req pb.Message - index uint64 - acks map[uint64]struct{} -} - -type readOnly struct { - option ReadOnlyOption - pendingReadIndex map[string]*readIndexStatus - readIndexQueue []string -} - -func newReadOnly(option ReadOnlyOption) *readOnly { - return &readOnly{ - option: option, - pendingReadIndex: make(map[string]*readIndexStatus), - } -} - -// addRequest adds a read only reuqest into readonly struct. -// `index` is the commit index of the raft state machine when it received -// the read only request. -// `m` is the original read only request message from the local or remote node. -func (ro *readOnly) addRequest(index uint64, m pb.Message) { - ctx := string(m.Entries[0].Data) - if _, ok := ro.pendingReadIndex[ctx]; ok { - return - } - ro.pendingReadIndex[ctx] = &readIndexStatus{index: index, req: m, acks: make(map[uint64]struct{})} - ro.readIndexQueue = append(ro.readIndexQueue, ctx) -} - -// recvAck notifies the readonly struct that the raft state machine received -// an acknowledgment of the heartbeat that attached with the read only request -// context. -func (ro *readOnly) recvAck(m pb.Message) int { - rs, ok := ro.pendingReadIndex[string(m.Context)] - if !ok { - return 0 - } - - rs.acks[m.From] = struct{}{} - // add one to include an ack from local node - return len(rs.acks) + 1 -} - -// advance advances the read only request queue kept by the readonly struct. -// It dequeues the requests until it finds the read only request that has -// the same context as the given `m`. -func (ro *readOnly) advance(m pb.Message) []*readIndexStatus { - var ( - i int - found bool - ) - - ctx := string(m.Context) - rss := []*readIndexStatus{} - - for _, okctx := range ro.readIndexQueue { - i++ - rs, ok := ro.pendingReadIndex[okctx] - if !ok { - panic("cannot find corresponding read state from pending map") - } - rss = append(rss, rs) - if okctx == ctx { - found = true - break - } - } - - if found { - ro.readIndexQueue = ro.readIndexQueue[i:] - for _, rs := range rss { - delete(ro.pendingReadIndex, string(rs.req.Entries[0].Data)) - } - return rss - } - - return nil -} - -// lastPendingRequestCtx returns the context of the last pending read only -// request in readonly struct. -func (ro *readOnly) lastPendingRequestCtx() string { - if len(ro.readIndexQueue) == 0 { - return "" - } - return ro.readIndexQueue[len(ro.readIndexQueue)-1] -} diff --git a/vendor/github.com/coreos/etcd/raft/status.go b/vendor/github.com/coreos/etcd/raft/status.go deleted file mode 100644 index f4d3d86a4e39..000000000000 --- a/vendor/github.com/coreos/etcd/raft/status.go +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "fmt" - - pb "github.com/coreos/etcd/raft/raftpb" -) - -type Status struct { - ID uint64 - - pb.HardState - SoftState - - Applied uint64 - Progress map[uint64]Progress - - LeadTransferee uint64 -} - -// getStatus gets a copy of the current raft status. -func getStatus(r *raft) Status { - s := Status{ - ID: r.id, - LeadTransferee: r.leadTransferee, - } - - s.HardState = r.hardState() - s.SoftState = *r.softState() - - s.Applied = r.raftLog.applied - - if s.RaftState == StateLeader { - s.Progress = make(map[uint64]Progress) - for id, p := range r.prs { - s.Progress[id] = *p - } - - for id, p := range r.learnerPrs { - s.Progress[id] = *p - } - } - - return s -} - -// MarshalJSON translates the raft status into JSON. -// TODO: try to simplify this by introducing ID type into raft -func (s Status) MarshalJSON() ([]byte, error) { - j := fmt.Sprintf(`{"id":"%x","term":%d,"vote":"%x","commit":%d,"lead":"%x","raftState":%q,"applied":%d,"progress":{`, - s.ID, s.Term, s.Vote, s.Commit, s.Lead, s.RaftState, s.Applied) - - if len(s.Progress) == 0 { - j += "}," - } else { - for k, v := range s.Progress { - subj := fmt.Sprintf(`"%x":{"match":%d,"next":%d,"state":%q},`, k, v.Match, v.Next, v.State) - j += subj - } - // remove the trailing "," - j = j[:len(j)-1] + "}," - } - - j += fmt.Sprintf(`"leadtransferee":"%x"}`, s.LeadTransferee) - return []byte(j), nil -} - -func (s Status) String() string { - b, err := s.MarshalJSON() - if err != nil { - raftLogger.Panicf("unexpected error: %v", err) - } - return string(b) -} diff --git a/vendor/github.com/coreos/etcd/raft/storage.go b/vendor/github.com/coreos/etcd/raft/storage.go deleted file mode 100644 index 69c3a7d90338..000000000000 --- a/vendor/github.com/coreos/etcd/raft/storage.go +++ /dev/null @@ -1,271 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "errors" - "sync" - - pb "github.com/coreos/etcd/raft/raftpb" -) - -// ErrCompacted is returned by Storage.Entries/Compact when a requested -// index is unavailable because it predates the last snapshot. -var ErrCompacted = errors.New("requested index is unavailable due to compaction") - -// ErrSnapOutOfDate is returned by Storage.CreateSnapshot when a requested -// index is older than the existing snapshot. -var ErrSnapOutOfDate = errors.New("requested index is older than the existing snapshot") - -// ErrUnavailable is returned by Storage interface when the requested log entries -// are unavailable. -var ErrUnavailable = errors.New("requested entry at index is unavailable") - -// ErrSnapshotTemporarilyUnavailable is returned by the Storage interface when the required -// snapshot is temporarily unavailable. -var ErrSnapshotTemporarilyUnavailable = errors.New("snapshot is temporarily unavailable") - -// Storage is an interface that may be implemented by the application -// to retrieve log entries from storage. -// -// If any Storage method returns an error, the raft instance will -// become inoperable and refuse to participate in elections; the -// application is responsible for cleanup and recovery in this case. -type Storage interface { - // InitialState returns the saved HardState and ConfState information. - InitialState() (pb.HardState, pb.ConfState, error) - // Entries returns a slice of log entries in the range [lo,hi). - // MaxSize limits the total size of the log entries returned, but - // Entries returns at least one entry if any. - Entries(lo, hi, maxSize uint64) ([]pb.Entry, error) - // Term returns the term of entry i, which must be in the range - // [FirstIndex()-1, LastIndex()]. The term of the entry before - // FirstIndex is retained for matching purposes even though the - // rest of that entry may not be available. - Term(i uint64) (uint64, error) - // LastIndex returns the index of the last entry in the log. - LastIndex() (uint64, error) - // FirstIndex returns the index of the first log entry that is - // possibly available via Entries (older entries have been incorporated - // into the latest Snapshot; if storage only contains the dummy entry the - // first log entry is not available). - FirstIndex() (uint64, error) - // Snapshot returns the most recent snapshot. - // If snapshot is temporarily unavailable, it should return ErrSnapshotTemporarilyUnavailable, - // so raft state machine could know that Storage needs some time to prepare - // snapshot and call Snapshot later. - Snapshot() (pb.Snapshot, error) -} - -// MemoryStorage implements the Storage interface backed by an -// in-memory array. -type MemoryStorage struct { - // Protects access to all fields. Most methods of MemoryStorage are - // run on the raft goroutine, but Append() is run on an application - // goroutine. - sync.Mutex - - hardState pb.HardState - snapshot pb.Snapshot - // ents[i] has raft log position i+snapshot.Metadata.Index - ents []pb.Entry -} - -// NewMemoryStorage creates an empty MemoryStorage. -func NewMemoryStorage() *MemoryStorage { - return &MemoryStorage{ - // When starting from scratch populate the list with a dummy entry at term zero. - ents: make([]pb.Entry, 1), - } -} - -// InitialState implements the Storage interface. -func (ms *MemoryStorage) InitialState() (pb.HardState, pb.ConfState, error) { - return ms.hardState, ms.snapshot.Metadata.ConfState, nil -} - -// SetHardState saves the current HardState. -func (ms *MemoryStorage) SetHardState(st pb.HardState) error { - ms.Lock() - defer ms.Unlock() - ms.hardState = st - return nil -} - -// Entries implements the Storage interface. -func (ms *MemoryStorage) Entries(lo, hi, maxSize uint64) ([]pb.Entry, error) { - ms.Lock() - defer ms.Unlock() - offset := ms.ents[0].Index - if lo <= offset { - return nil, ErrCompacted - } - if hi > ms.lastIndex()+1 { - raftLogger.Panicf("entries' hi(%d) is out of bound lastindex(%d)", hi, ms.lastIndex()) - } - // only contains dummy entries. - if len(ms.ents) == 1 { - return nil, ErrUnavailable - } - - ents := ms.ents[lo-offset : hi-offset] - return limitSize(ents, maxSize), nil -} - -// Term implements the Storage interface. -func (ms *MemoryStorage) Term(i uint64) (uint64, error) { - ms.Lock() - defer ms.Unlock() - offset := ms.ents[0].Index - if i < offset { - return 0, ErrCompacted - } - if int(i-offset) >= len(ms.ents) { - return 0, ErrUnavailable - } - return ms.ents[i-offset].Term, nil -} - -// LastIndex implements the Storage interface. -func (ms *MemoryStorage) LastIndex() (uint64, error) { - ms.Lock() - defer ms.Unlock() - return ms.lastIndex(), nil -} - -func (ms *MemoryStorage) lastIndex() uint64 { - return ms.ents[0].Index + uint64(len(ms.ents)) - 1 -} - -// FirstIndex implements the Storage interface. -func (ms *MemoryStorage) FirstIndex() (uint64, error) { - ms.Lock() - defer ms.Unlock() - return ms.firstIndex(), nil -} - -func (ms *MemoryStorage) firstIndex() uint64 { - return ms.ents[0].Index + 1 -} - -// Snapshot implements the Storage interface. -func (ms *MemoryStorage) Snapshot() (pb.Snapshot, error) { - ms.Lock() - defer ms.Unlock() - return ms.snapshot, nil -} - -// ApplySnapshot overwrites the contents of this Storage object with -// those of the given snapshot. -func (ms *MemoryStorage) ApplySnapshot(snap pb.Snapshot) error { - ms.Lock() - defer ms.Unlock() - - //handle check for old snapshot being applied - msIndex := ms.snapshot.Metadata.Index - snapIndex := snap.Metadata.Index - if msIndex >= snapIndex { - return ErrSnapOutOfDate - } - - ms.snapshot = snap - ms.ents = []pb.Entry{{Term: snap.Metadata.Term, Index: snap.Metadata.Index}} - return nil -} - -// CreateSnapshot makes a snapshot which can be retrieved with Snapshot() and -// can be used to reconstruct the state at that point. -// If any configuration changes have been made since the last compaction, -// the result of the last ApplyConfChange must be passed in. -func (ms *MemoryStorage) CreateSnapshot(i uint64, cs *pb.ConfState, data []byte) (pb.Snapshot, error) { - ms.Lock() - defer ms.Unlock() - if i <= ms.snapshot.Metadata.Index { - return pb.Snapshot{}, ErrSnapOutOfDate - } - - offset := ms.ents[0].Index - if i > ms.lastIndex() { - raftLogger.Panicf("snapshot %d is out of bound lastindex(%d)", i, ms.lastIndex()) - } - - ms.snapshot.Metadata.Index = i - ms.snapshot.Metadata.Term = ms.ents[i-offset].Term - if cs != nil { - ms.snapshot.Metadata.ConfState = *cs - } - ms.snapshot.Data = data - return ms.snapshot, nil -} - -// Compact discards all log entries prior to compactIndex. -// It is the application's responsibility to not attempt to compact an index -// greater than raftLog.applied. -func (ms *MemoryStorage) Compact(compactIndex uint64) error { - ms.Lock() - defer ms.Unlock() - offset := ms.ents[0].Index - if compactIndex <= offset { - return ErrCompacted - } - if compactIndex > ms.lastIndex() { - raftLogger.Panicf("compact %d is out of bound lastindex(%d)", compactIndex, ms.lastIndex()) - } - - i := compactIndex - offset - ents := make([]pb.Entry, 1, 1+uint64(len(ms.ents))-i) - ents[0].Index = ms.ents[i].Index - ents[0].Term = ms.ents[i].Term - ents = append(ents, ms.ents[i+1:]...) - ms.ents = ents - return nil -} - -// Append the new entries to storage. -// TODO (xiangli): ensure the entries are continuous and -// entries[0].Index > ms.entries[0].Index -func (ms *MemoryStorage) Append(entries []pb.Entry) error { - if len(entries) == 0 { - return nil - } - - ms.Lock() - defer ms.Unlock() - - first := ms.firstIndex() - last := entries[0].Index + uint64(len(entries)) - 1 - - // shortcut if there is no new entry. - if last < first { - return nil - } - // truncate compacted entries - if first > entries[0].Index { - entries = entries[first-entries[0].Index:] - } - - offset := entries[0].Index - ms.ents[0].Index - switch { - case uint64(len(ms.ents)) > offset: - ms.ents = append([]pb.Entry{}, ms.ents[:offset]...) - ms.ents = append(ms.ents, entries...) - case uint64(len(ms.ents)) == offset: - ms.ents = append(ms.ents, entries...) - default: - raftLogger.Panicf("missing log entry [last: %d, append at: %d]", - ms.lastIndex(), entries[0].Index) - } - return nil -} diff --git a/vendor/github.com/coreos/etcd/raft/util.go b/vendor/github.com/coreos/etcd/raft/util.go deleted file mode 100644 index f4141fe65ddf..000000000000 --- a/vendor/github.com/coreos/etcd/raft/util.go +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "bytes" - "fmt" - - pb "github.com/coreos/etcd/raft/raftpb" -) - -func (st StateType) MarshalJSON() ([]byte, error) { - return []byte(fmt.Sprintf("%q", st.String())), nil -} - -// uint64Slice implements sort interface -type uint64Slice []uint64 - -func (p uint64Slice) Len() int { return len(p) } -func (p uint64Slice) Less(i, j int) bool { return p[i] < p[j] } -func (p uint64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } - -func min(a, b uint64) uint64 { - if a > b { - return b - } - return a -} - -func max(a, b uint64) uint64 { - if a > b { - return a - } - return b -} - -func IsLocalMsg(msgt pb.MessageType) bool { - return msgt == pb.MsgHup || msgt == pb.MsgBeat || msgt == pb.MsgUnreachable || - msgt == pb.MsgSnapStatus || msgt == pb.MsgCheckQuorum -} - -func IsResponseMsg(msgt pb.MessageType) bool { - return msgt == pb.MsgAppResp || msgt == pb.MsgVoteResp || msgt == pb.MsgHeartbeatResp || msgt == pb.MsgUnreachable || msgt == pb.MsgPreVoteResp -} - -// voteResponseType maps vote and prevote message types to their corresponding responses. -func voteRespMsgType(msgt pb.MessageType) pb.MessageType { - switch msgt { - case pb.MsgVote: - return pb.MsgVoteResp - case pb.MsgPreVote: - return pb.MsgPreVoteResp - default: - panic(fmt.Sprintf("not a vote message: %s", msgt)) - } -} - -// EntryFormatter can be implemented by the application to provide human-readable formatting -// of entry data. Nil is a valid EntryFormatter and will use a default format. -type EntryFormatter func([]byte) string - -// DescribeMessage returns a concise human-readable description of a -// Message for debugging. -func DescribeMessage(m pb.Message, f EntryFormatter) string { - var buf bytes.Buffer - fmt.Fprintf(&buf, "%x->%x %v Term:%d Log:%d/%d", m.From, m.To, m.Type, m.Term, m.LogTerm, m.Index) - if m.Reject { - fmt.Fprintf(&buf, " Rejected") - if m.RejectHint != 0 { - fmt.Fprintf(&buf, "(Hint:%d)", m.RejectHint) - } - } - if m.Commit != 0 { - fmt.Fprintf(&buf, " Commit:%d", m.Commit) - } - if len(m.Entries) > 0 { - fmt.Fprintf(&buf, " Entries:[") - for i, e := range m.Entries { - if i != 0 { - buf.WriteString(", ") - } - buf.WriteString(DescribeEntry(e, f)) - } - fmt.Fprintf(&buf, "]") - } - if !IsEmptySnap(m.Snapshot) { - fmt.Fprintf(&buf, " Snapshot:%v", m.Snapshot) - } - return buf.String() -} - -// DescribeEntry returns a concise human-readable description of an -// Entry for debugging. -func DescribeEntry(e pb.Entry, f EntryFormatter) string { - var formatted string - if e.Type == pb.EntryNormal && f != nil { - formatted = f(e.Data) - } else { - formatted = fmt.Sprintf("%q", e.Data) - } - return fmt.Sprintf("%d/%d %s %s", e.Term, e.Index, e.Type, formatted) -} - -func limitSize(ents []pb.Entry, maxSize uint64) []pb.Entry { - if len(ents) == 0 { - return ents - } - size := ents[0].Size() - var limit int - for limit = 1; limit < len(ents); limit++ { - size += ents[limit].Size() - if uint64(size) > maxSize { - break - } - } - return ents[:limit] -} diff --git a/vendor/github.com/coreos/etcd/rafthttp/coder.go b/vendor/github.com/coreos/etcd/rafthttp/coder.go deleted file mode 100644 index 86ede972e1f1..000000000000 --- a/vendor/github.com/coreos/etcd/rafthttp/coder.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import "github.com/coreos/etcd/raft/raftpb" - -type encoder interface { - // encode encodes the given message to an output stream. - encode(m *raftpb.Message) error -} - -type decoder interface { - // decode decodes the message from an input stream. - decode() (raftpb.Message, error) -} diff --git a/vendor/github.com/coreos/etcd/rafthttp/doc.go b/vendor/github.com/coreos/etcd/rafthttp/doc.go deleted file mode 100644 index a9486a8bb664..000000000000 --- a/vendor/github.com/coreos/etcd/rafthttp/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package rafthttp implements HTTP transportation layer for etcd/raft pkg. -package rafthttp diff --git a/vendor/github.com/coreos/etcd/rafthttp/http.go b/vendor/github.com/coreos/etcd/rafthttp/http.go deleted file mode 100644 index 223a5deb9bdb..000000000000 --- a/vendor/github.com/coreos/etcd/rafthttp/http.go +++ /dev/null @@ -1,366 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "context" - "errors" - "fmt" - "io/ioutil" - "net/http" - "path" - "strings" - "time" - - pioutil "github.com/coreos/etcd/pkg/ioutil" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/snap" - "github.com/coreos/etcd/version" -) - -const ( - // connReadLimitByte limits the number of bytes - // a single read can read out. - // - // 64KB should be large enough for not causing - // throughput bottleneck as well as small enough - // for not causing a read timeout. - connReadLimitByte = 64 * 1024 -) - -var ( - RaftPrefix = "/raft" - ProbingPrefix = path.Join(RaftPrefix, "probing") - RaftStreamPrefix = path.Join(RaftPrefix, "stream") - RaftSnapshotPrefix = path.Join(RaftPrefix, "snapshot") - - errIncompatibleVersion = errors.New("incompatible version") - errClusterIDMismatch = errors.New("cluster ID mismatch") -) - -type peerGetter interface { - Get(id types.ID) Peer -} - -type writerToResponse interface { - WriteTo(w http.ResponseWriter) -} - -type pipelineHandler struct { - tr Transporter - r Raft - cid types.ID -} - -// newPipelineHandler returns a handler for handling raft messages -// from pipeline for RaftPrefix. -// -// The handler reads out the raft message from request body, -// and forwards it to the given raft state machine for processing. -func newPipelineHandler(tr Transporter, r Raft, cid types.ID) http.Handler { - return &pipelineHandler{ - tr: tr, - r: r, - cid: cid, - } -} - -func (h *pipelineHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if r.Method != "POST" { - w.Header().Set("Allow", "POST") - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return - } - - w.Header().Set("X-Etcd-Cluster-ID", h.cid.String()) - - if err := checkClusterCompatibilityFromHeader(r.Header, h.cid); err != nil { - http.Error(w, err.Error(), http.StatusPreconditionFailed) - return - } - - addRemoteFromRequest(h.tr, r) - - // Limit the data size that could be read from the request body, which ensures that read from - // connection will not time out accidentally due to possible blocking in underlying implementation. - limitedr := pioutil.NewLimitedBufferReader(r.Body, connReadLimitByte) - b, err := ioutil.ReadAll(limitedr) - if err != nil { - plog.Errorf("failed to read raft message (%v)", err) - http.Error(w, "error reading raft message", http.StatusBadRequest) - recvFailures.WithLabelValues(r.RemoteAddr).Inc() - return - } - - var m raftpb.Message - if err := m.Unmarshal(b); err != nil { - plog.Errorf("failed to unmarshal raft message (%v)", err) - http.Error(w, "error unmarshaling raft message", http.StatusBadRequest) - recvFailures.WithLabelValues(r.RemoteAddr).Inc() - return - } - - receivedBytes.WithLabelValues(types.ID(m.From).String()).Add(float64(len(b))) - - if err := h.r.Process(context.TODO(), m); err != nil { - switch v := err.(type) { - case writerToResponse: - v.WriteTo(w) - default: - plog.Warningf("failed to process raft message (%v)", err) - http.Error(w, "error processing raft message", http.StatusInternalServerError) - w.(http.Flusher).Flush() - // disconnect the http stream - panic(err) - } - return - } - - // Write StatusNoContent header after the message has been processed by - // raft, which facilitates the client to report MsgSnap status. - w.WriteHeader(http.StatusNoContent) -} - -type snapshotHandler struct { - tr Transporter - r Raft - snapshotter *snap.Snapshotter - cid types.ID -} - -func newSnapshotHandler(tr Transporter, r Raft, snapshotter *snap.Snapshotter, cid types.ID) http.Handler { - return &snapshotHandler{ - tr: tr, - r: r, - snapshotter: snapshotter, - cid: cid, - } -} - -const unknownSnapshotSender = "UNKNOWN_SNAPSHOT_SENDER" - -// ServeHTTP serves HTTP request to receive and process snapshot message. -// -// If request sender dies without closing underlying TCP connection, -// the handler will keep waiting for the request body until TCP keepalive -// finds out that the connection is broken after several minutes. -// This is acceptable because -// 1. snapshot messages sent through other TCP connections could still be -// received and processed. -// 2. this case should happen rarely, so no further optimization is done. -func (h *snapshotHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - start := time.Now() - - if r.Method != "POST" { - w.Header().Set("Allow", "POST") - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - snapshotReceiveFailures.WithLabelValues(unknownSnapshotSender).Inc() - return - } - - w.Header().Set("X-Etcd-Cluster-ID", h.cid.String()) - - if err := checkClusterCompatibilityFromHeader(r.Header, h.cid); err != nil { - http.Error(w, err.Error(), http.StatusPreconditionFailed) - snapshotReceiveFailures.WithLabelValues(unknownSnapshotSender).Inc() - return - } - - addRemoteFromRequest(h.tr, r) - - dec := &messageDecoder{r: r.Body} - // let snapshots be very large since they can exceed 512MB for large installations - m, err := dec.decodeLimit(uint64(1 << 63)) - from := types.ID(m.From).String() - if err != nil { - msg := fmt.Sprintf("failed to decode raft message (%v)", err) - plog.Errorf(msg) - http.Error(w, msg, http.StatusBadRequest) - recvFailures.WithLabelValues(r.RemoteAddr).Inc() - snapshotReceiveFailures.WithLabelValues(from).Inc() - return - } - - receivedBytes.WithLabelValues(from).Add(float64(m.Size())) - - if m.Type != raftpb.MsgSnap { - plog.Errorf("unexpected raft message type %s on snapshot path", m.Type) - http.Error(w, "wrong raft message type", http.StatusBadRequest) - snapshotReceiveFailures.WithLabelValues(from).Inc() - return - } - - plog.Infof("receiving database snapshot [index:%d, from %s] ...", m.Snapshot.Metadata.Index, types.ID(m.From)) - // save incoming database snapshot. - n, err := h.snapshotter.SaveDBFrom(r.Body, m.Snapshot.Metadata.Index) - if err != nil { - msg := fmt.Sprintf("failed to save KV snapshot (%v)", err) - plog.Error(msg) - http.Error(w, msg, http.StatusInternalServerError) - snapshotReceiveFailures.WithLabelValues(from).Inc() - return - } - receivedBytes.WithLabelValues(from).Add(float64(n)) - plog.Infof("received and saved database snapshot [index: %d, from: %s] successfully", m.Snapshot.Metadata.Index, types.ID(m.From)) - - if err := h.r.Process(context.TODO(), m); err != nil { - switch v := err.(type) { - // Process may return writerToResponse error when doing some - // additional checks before calling raft.Node.Step. - case writerToResponse: - v.WriteTo(w) - default: - msg := fmt.Sprintf("failed to process raft message (%v)", err) - plog.Warningf(msg) - http.Error(w, msg, http.StatusInternalServerError) - snapshotReceiveFailures.WithLabelValues(from).Inc() - } - return - } - // Write StatusNoContent header after the message has been processed by - // raft, which facilitates the client to report MsgSnap status. - w.WriteHeader(http.StatusNoContent) - - snapshotReceive.WithLabelValues(from).Inc() - snapshotReceiveSeconds.WithLabelValues(from).Observe(time.Since(start).Seconds()) -} - -type streamHandler struct { - tr *Transport - peerGetter peerGetter - r Raft - id types.ID - cid types.ID -} - -func newStreamHandler(tr *Transport, pg peerGetter, r Raft, id, cid types.ID) http.Handler { - return &streamHandler{ - tr: tr, - peerGetter: pg, - r: r, - id: id, - cid: cid, - } -} - -func (h *streamHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - w.Header().Set("Allow", "GET") - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return - } - - w.Header().Set("X-Server-Version", version.Version) - w.Header().Set("X-Etcd-Cluster-ID", h.cid.String()) - - if err := checkClusterCompatibilityFromHeader(r.Header, h.cid); err != nil { - http.Error(w, err.Error(), http.StatusPreconditionFailed) - return - } - - var t streamType - switch path.Dir(r.URL.Path) { - case streamTypeMsgAppV2.endpoint(): - t = streamTypeMsgAppV2 - case streamTypeMessage.endpoint(): - t = streamTypeMessage - default: - plog.Debugf("ignored unexpected streaming request path %s", r.URL.Path) - http.Error(w, "invalid path", http.StatusNotFound) - return - } - - fromStr := path.Base(r.URL.Path) - from, err := types.IDFromString(fromStr) - if err != nil { - plog.Errorf("failed to parse from %s into ID (%v)", fromStr, err) - http.Error(w, "invalid from", http.StatusNotFound) - return - } - if h.r.IsIDRemoved(uint64(from)) { - plog.Warningf("rejected the stream from peer %s since it was removed", from) - http.Error(w, "removed member", http.StatusGone) - return - } - p := h.peerGetter.Get(from) - if p == nil { - // This may happen in following cases: - // 1. user starts a remote peer that belongs to a different cluster - // with the same cluster ID. - // 2. local etcd falls behind of the cluster, and cannot recognize - // the members that joined after its current progress. - if urls := r.Header.Get("X-PeerURLs"); urls != "" { - h.tr.AddRemote(from, strings.Split(urls, ",")) - } - plog.Errorf("failed to find member %s in cluster %s", from, h.cid) - http.Error(w, "error sender not found", http.StatusNotFound) - return - } - - wto := h.id.String() - if gto := r.Header.Get("X-Raft-To"); gto != wto { - plog.Errorf("streaming request ignored (ID mismatch got %s want %s)", gto, wto) - http.Error(w, "to field mismatch", http.StatusPreconditionFailed) - return - } - - w.WriteHeader(http.StatusOK) - w.(http.Flusher).Flush() - - c := newCloseNotifier() - conn := &outgoingConn{ - t: t, - Writer: w, - Flusher: w.(http.Flusher), - Closer: c, - } - p.attachOutgoingConn(conn) - <-c.closeNotify() -} - -// checkClusterCompatibilityFromHeader checks the cluster compatibility of -// the local member from the given header. -// It checks whether the version of local member is compatible with -// the versions in the header, and whether the cluster ID of local member -// matches the one in the header. -func checkClusterCompatibilityFromHeader(header http.Header, cid types.ID) error { - if err := checkVersionCompability(header.Get("X-Server-From"), serverVersion(header), minClusterVersion(header)); err != nil { - plog.Errorf("request version incompatibility (%v)", err) - return errIncompatibleVersion - } - if gcid := header.Get("X-Etcd-Cluster-ID"); gcid != cid.String() { - plog.Errorf("request cluster ID mismatch (got %s want %s)", gcid, cid) - return errClusterIDMismatch - } - return nil -} - -type closeNotifier struct { - done chan struct{} -} - -func newCloseNotifier() *closeNotifier { - return &closeNotifier{ - done: make(chan struct{}), - } -} - -func (n *closeNotifier) Close() error { - close(n.done) - return nil -} - -func (n *closeNotifier) closeNotify() <-chan struct{} { return n.done } diff --git a/vendor/github.com/coreos/etcd/rafthttp/metrics.go b/vendor/github.com/coreos/etcd/rafthttp/metrics.go deleted file mode 100644 index 2066663c691d..000000000000 --- a/vendor/github.com/coreos/etcd/rafthttp/metrics.go +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import "github.com/prometheus/client_golang/prometheus" - -var ( - sentBytes = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "peer_sent_bytes_total", - Help: "The total number of bytes sent to peers.", - }, - []string{"To"}, - ) - - receivedBytes = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "peer_received_bytes_total", - Help: "The total number of bytes received from peers.", - }, - []string{"From"}, - ) - - sentFailures = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "peer_sent_failures_total", - Help: "The total number of send failures from peers.", - }, - []string{"To"}, - ) - - recvFailures = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "peer_received_failures_total", - Help: "The total number of receive failures from peers.", - }, - []string{"From"}, - ) - - snapshotSend = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "snapshot_send_success", - Help: "Total number of successful snapshot sends", - }, - []string{"To"}, - ) - - snapshotSendFailures = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "snapshot_send_failures", - Help: "Total number of snapshot send failures", - }, - []string{"To"}, - ) - - snapshotSendSeconds = prometheus.NewHistogramVec(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "snapshot_send_total_duration_seconds", - Help: "Total latency distributions of v3 snapshot sends", - - // lowest bucket start of upper bound 0.1 sec (100 ms) with factor 2 - // highest bucket start of 0.1 sec * 2^9 == 51.2 sec - Buckets: prometheus.ExponentialBuckets(0.1, 2, 10), - }, - []string{"To"}, - ) - - snapshotReceive = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "snapshot_receive_success", - Help: "Total number of successful snapshot receives", - }, - []string{"From"}, - ) - - snapshotReceiveFailures = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "snapshot_receive_failures", - Help: "Total number of snapshot receive failures", - }, - []string{"From"}, - ) - - snapshotReceiveSeconds = prometheus.NewHistogramVec(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "snapshot_receive_total_duration_seconds", - Help: "Total latency distributions of v3 snapshot receives", - - // lowest bucket start of upper bound 0.1 sec (100 ms) with factor 2 - // highest bucket start of 0.1 sec * 2^9 == 51.2 sec - Buckets: prometheus.ExponentialBuckets(0.1, 2, 10), - }, - []string{"From"}, - ) - - rtts = prometheus.NewHistogramVec(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "peer_round_trip_time_seconds", - Help: "Round-Trip-Time histogram between peers.", - Buckets: prometheus.ExponentialBuckets(0.0001, 2, 14), - }, - []string{"To"}, - ) -) - -func init() { - prometheus.MustRegister(sentBytes) - prometheus.MustRegister(receivedBytes) - prometheus.MustRegister(sentFailures) - prometheus.MustRegister(recvFailures) - - prometheus.MustRegister(snapshotSend) - prometheus.MustRegister(snapshotSendFailures) - prometheus.MustRegister(snapshotSendSeconds) - prometheus.MustRegister(snapshotReceive) - prometheus.MustRegister(snapshotReceiveFailures) - prometheus.MustRegister(snapshotReceiveSeconds) - - prometheus.MustRegister(rtts) -} diff --git a/vendor/github.com/coreos/etcd/rafthttp/msg_codec.go b/vendor/github.com/coreos/etcd/rafthttp/msg_codec.go deleted file mode 100644 index ef59bc8883f6..000000000000 --- a/vendor/github.com/coreos/etcd/rafthttp/msg_codec.go +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "encoding/binary" - "errors" - "io" - - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/raft/raftpb" -) - -// messageEncoder is a encoder that can encode all kinds of messages. -// It MUST be used with a paired messageDecoder. -type messageEncoder struct { - w io.Writer -} - -func (enc *messageEncoder) encode(m *raftpb.Message) error { - if err := binary.Write(enc.w, binary.BigEndian, uint64(m.Size())); err != nil { - return err - } - _, err := enc.w.Write(pbutil.MustMarshal(m)) - return err -} - -// messageDecoder is a decoder that can decode all kinds of messages. -type messageDecoder struct { - r io.Reader -} - -var ( - readBytesLimit uint64 = 512 * 1024 * 1024 // 512 MB - ErrExceedSizeLimit = errors.New("rafthttp: error limit exceeded") -) - -func (dec *messageDecoder) decode() (raftpb.Message, error) { - return dec.decodeLimit(readBytesLimit) -} - -func (dec *messageDecoder) decodeLimit(numBytes uint64) (raftpb.Message, error) { - var m raftpb.Message - var l uint64 - if err := binary.Read(dec.r, binary.BigEndian, &l); err != nil { - return m, err - } - if l > numBytes { - return m, ErrExceedSizeLimit - } - buf := make([]byte, int(l)) - if _, err := io.ReadFull(dec.r, buf); err != nil { - return m, err - } - return m, m.Unmarshal(buf) -} diff --git a/vendor/github.com/coreos/etcd/rafthttp/msgappv2_codec.go b/vendor/github.com/coreos/etcd/rafthttp/msgappv2_codec.go deleted file mode 100644 index 013ffe7c7362..000000000000 --- a/vendor/github.com/coreos/etcd/rafthttp/msgappv2_codec.go +++ /dev/null @@ -1,248 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "encoding/binary" - "fmt" - "io" - "time" - - "github.com/coreos/etcd/etcdserver/stats" - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft/raftpb" -) - -const ( - msgTypeLinkHeartbeat uint8 = 0 - msgTypeAppEntries uint8 = 1 - msgTypeApp uint8 = 2 - - msgAppV2BufSize = 1024 * 1024 -) - -// msgappv2 stream sends three types of message: linkHeartbeatMessage, -// AppEntries and MsgApp. AppEntries is the MsgApp that is sent in -// replicate state in raft, whose index and term are fully predictable. -// -// Data format of linkHeartbeatMessage: -// | offset | bytes | description | -// +--------+-------+-------------+ -// | 0 | 1 | \x00 | -// -// Data format of AppEntries: -// | offset | bytes | description | -// +--------+-------+-------------+ -// | 0 | 1 | \x01 | -// | 1 | 8 | length of entries | -// | 9 | 8 | length of first entry | -// | 17 | n1 | first entry | -// ... -// | x | 8 | length of k-th entry data | -// | x+8 | nk | k-th entry data | -// | x+8+nk | 8 | commit index | -// -// Data format of MsgApp: -// | offset | bytes | description | -// +--------+-------+-------------+ -// | 0 | 1 | \x02 | -// | 1 | 8 | length of encoded message | -// | 9 | n | encoded message | -type msgAppV2Encoder struct { - w io.Writer - fs *stats.FollowerStats - - term uint64 - index uint64 - buf []byte - uint64buf []byte - uint8buf []byte -} - -func newMsgAppV2Encoder(w io.Writer, fs *stats.FollowerStats) *msgAppV2Encoder { - return &msgAppV2Encoder{ - w: w, - fs: fs, - buf: make([]byte, msgAppV2BufSize), - uint64buf: make([]byte, 8), - uint8buf: make([]byte, 1), - } -} - -func (enc *msgAppV2Encoder) encode(m *raftpb.Message) error { - start := time.Now() - switch { - case isLinkHeartbeatMessage(m): - enc.uint8buf[0] = byte(msgTypeLinkHeartbeat) - if _, err := enc.w.Write(enc.uint8buf); err != nil { - return err - } - case enc.index == m.Index && enc.term == m.LogTerm && m.LogTerm == m.Term: - enc.uint8buf[0] = byte(msgTypeAppEntries) - if _, err := enc.w.Write(enc.uint8buf); err != nil { - return err - } - // write length of entries - binary.BigEndian.PutUint64(enc.uint64buf, uint64(len(m.Entries))) - if _, err := enc.w.Write(enc.uint64buf); err != nil { - return err - } - for i := 0; i < len(m.Entries); i++ { - // write length of entry - binary.BigEndian.PutUint64(enc.uint64buf, uint64(m.Entries[i].Size())) - if _, err := enc.w.Write(enc.uint64buf); err != nil { - return err - } - if n := m.Entries[i].Size(); n < msgAppV2BufSize { - if _, err := m.Entries[i].MarshalTo(enc.buf); err != nil { - return err - } - if _, err := enc.w.Write(enc.buf[:n]); err != nil { - return err - } - } else { - if _, err := enc.w.Write(pbutil.MustMarshal(&m.Entries[i])); err != nil { - return err - } - } - enc.index++ - } - // write commit index - binary.BigEndian.PutUint64(enc.uint64buf, m.Commit) - if _, err := enc.w.Write(enc.uint64buf); err != nil { - return err - } - enc.fs.Succ(time.Since(start)) - default: - if err := binary.Write(enc.w, binary.BigEndian, msgTypeApp); err != nil { - return err - } - // write size of message - if err := binary.Write(enc.w, binary.BigEndian, uint64(m.Size())); err != nil { - return err - } - // write message - if _, err := enc.w.Write(pbutil.MustMarshal(m)); err != nil { - return err - } - - enc.term = m.Term - enc.index = m.Index - if l := len(m.Entries); l > 0 { - enc.index = m.Entries[l-1].Index - } - enc.fs.Succ(time.Since(start)) - } - return nil -} - -type msgAppV2Decoder struct { - r io.Reader - local, remote types.ID - - term uint64 - index uint64 - buf []byte - uint64buf []byte - uint8buf []byte -} - -func newMsgAppV2Decoder(r io.Reader, local, remote types.ID) *msgAppV2Decoder { - return &msgAppV2Decoder{ - r: r, - local: local, - remote: remote, - buf: make([]byte, msgAppV2BufSize), - uint64buf: make([]byte, 8), - uint8buf: make([]byte, 1), - } -} - -func (dec *msgAppV2Decoder) decode() (raftpb.Message, error) { - var ( - m raftpb.Message - typ uint8 - ) - if _, err := io.ReadFull(dec.r, dec.uint8buf); err != nil { - return m, err - } - typ = uint8(dec.uint8buf[0]) - switch typ { - case msgTypeLinkHeartbeat: - return linkHeartbeatMessage, nil - case msgTypeAppEntries: - m = raftpb.Message{ - Type: raftpb.MsgApp, - From: uint64(dec.remote), - To: uint64(dec.local), - Term: dec.term, - LogTerm: dec.term, - Index: dec.index, - } - - // decode entries - if _, err := io.ReadFull(dec.r, dec.uint64buf); err != nil { - return m, err - } - l := binary.BigEndian.Uint64(dec.uint64buf) - m.Entries = make([]raftpb.Entry, int(l)) - for i := 0; i < int(l); i++ { - if _, err := io.ReadFull(dec.r, dec.uint64buf); err != nil { - return m, err - } - size := binary.BigEndian.Uint64(dec.uint64buf) - var buf []byte - if size < msgAppV2BufSize { - buf = dec.buf[:size] - if _, err := io.ReadFull(dec.r, buf); err != nil { - return m, err - } - } else { - buf = make([]byte, int(size)) - if _, err := io.ReadFull(dec.r, buf); err != nil { - return m, err - } - } - dec.index++ - // 1 alloc - pbutil.MustUnmarshal(&m.Entries[i], buf) - } - // decode commit index - if _, err := io.ReadFull(dec.r, dec.uint64buf); err != nil { - return m, err - } - m.Commit = binary.BigEndian.Uint64(dec.uint64buf) - case msgTypeApp: - var size uint64 - if err := binary.Read(dec.r, binary.BigEndian, &size); err != nil { - return m, err - } - buf := make([]byte, int(size)) - if _, err := io.ReadFull(dec.r, buf); err != nil { - return m, err - } - pbutil.MustUnmarshal(&m, buf) - - dec.term = m.Term - dec.index = m.Index - if l := len(m.Entries); l > 0 { - dec.index = m.Entries[l-1].Index - } - default: - return m, fmt.Errorf("failed to parse type %d in msgappv2 stream", typ) - } - return m, nil -} diff --git a/vendor/github.com/coreos/etcd/rafthttp/peer.go b/vendor/github.com/coreos/etcd/rafthttp/peer.go deleted file mode 100644 index e9a25bb3aa95..000000000000 --- a/vendor/github.com/coreos/etcd/rafthttp/peer.go +++ /dev/null @@ -1,313 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "context" - "sync" - "time" - - "github.com/coreos/etcd/etcdserver/stats" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/snap" - - "golang.org/x/time/rate" -) - -const ( - // ConnReadTimeout and ConnWriteTimeout are the i/o timeout set on each connection rafthttp pkg creates. - // A 5 seconds timeout is good enough for recycling bad connections. Or we have to wait for - // tcp keepalive failing to detect a bad connection, which is at minutes level. - // For long term streaming connections, rafthttp pkg sends application level linkHeartbeatMessage - // to keep the connection alive. - // For short term pipeline connections, the connection MUST be killed to avoid it being - // put back to http pkg connection pool. - ConnReadTimeout = 5 * time.Second - ConnWriteTimeout = 5 * time.Second - - recvBufSize = 4096 - // maxPendingProposals holds the proposals during one leader election process. - // Generally one leader election takes at most 1 sec. It should have - // 0-2 election conflicts, and each one takes 0.5 sec. - // We assume the number of concurrent proposers is smaller than 4096. - // One client blocks on its proposal for at least 1 sec, so 4096 is enough - // to hold all proposals. - maxPendingProposals = 4096 - - streamAppV2 = "streamMsgAppV2" - streamMsg = "streamMsg" - pipelineMsg = "pipeline" - sendSnap = "sendMsgSnap" -) - -type Peer interface { - // send sends the message to the remote peer. The function is non-blocking - // and has no promise that the message will be received by the remote. - // When it fails to send message out, it will report the status to underlying - // raft. - send(m raftpb.Message) - - // sendSnap sends the merged snapshot message to the remote peer. Its behavior - // is similar to send. - sendSnap(m snap.Message) - - // update updates the urls of remote peer. - update(urls types.URLs) - - // attachOutgoingConn attaches the outgoing connection to the peer for - // stream usage. After the call, the ownership of the outgoing - // connection hands over to the peer. The peer will close the connection - // when it is no longer used. - attachOutgoingConn(conn *outgoingConn) - // activeSince returns the time that the connection with the - // peer becomes active. - activeSince() time.Time - // stop performs any necessary finalization and terminates the peer - // elegantly. - stop() -} - -// peer is the representative of a remote raft node. Local raft node sends -// messages to the remote through peer. -// Each peer has two underlying mechanisms to send out a message: stream and -// pipeline. -// A stream is a receiver initialized long-polling connection, which -// is always open to transfer messages. Besides general stream, peer also has -// a optimized stream for sending msgApp since msgApp accounts for large part -// of all messages. Only raft leader uses the optimized stream to send msgApp -// to the remote follower node. -// A pipeline is a series of http clients that send http requests to the remote. -// It is only used when the stream has not been established. -type peer struct { - // id of the remote raft peer node - id types.ID - r Raft - - status *peerStatus - - picker *urlPicker - - msgAppV2Writer *streamWriter - writer *streamWriter - pipeline *pipeline - snapSender *snapshotSender // snapshot sender to send v3 snapshot messages - msgAppV2Reader *streamReader - msgAppReader *streamReader - - recvc chan raftpb.Message - propc chan raftpb.Message - - mu sync.Mutex - paused bool - - cancel context.CancelFunc // cancel pending works in go routine created by peer. - stopc chan struct{} -} - -func startPeer(transport *Transport, urls types.URLs, peerID types.ID, fs *stats.FollowerStats) *peer { - plog.Infof("starting peer %s...", peerID) - defer plog.Infof("started peer %s", peerID) - - status := newPeerStatus(peerID) - picker := newURLPicker(urls) - errorc := transport.ErrorC - r := transport.Raft - pipeline := &pipeline{ - peerID: peerID, - tr: transport, - picker: picker, - status: status, - followerStats: fs, - raft: r, - errorc: errorc, - } - pipeline.start() - - p := &peer{ - id: peerID, - r: r, - status: status, - picker: picker, - msgAppV2Writer: startStreamWriter(peerID, status, fs, r), - writer: startStreamWriter(peerID, status, fs, r), - pipeline: pipeline, - snapSender: newSnapshotSender(transport, picker, peerID, status), - recvc: make(chan raftpb.Message, recvBufSize), - propc: make(chan raftpb.Message, maxPendingProposals), - stopc: make(chan struct{}), - } - - ctx, cancel := context.WithCancel(context.Background()) - p.cancel = cancel - go func() { - for { - select { - case mm := <-p.recvc: - if err := r.Process(ctx, mm); err != nil { - plog.Warningf("failed to process raft message (%v)", err) - } - case <-p.stopc: - return - } - } - }() - - // r.Process might block for processing proposal when there is no leader. - // Thus propc must be put into a separate routine with recvc to avoid blocking - // processing other raft messages. - go func() { - for { - select { - case mm := <-p.propc: - if err := r.Process(ctx, mm); err != nil { - plog.Warningf("failed to process raft message (%v)", err) - } - case <-p.stopc: - return - } - } - }() - - p.msgAppV2Reader = &streamReader{ - peerID: peerID, - typ: streamTypeMsgAppV2, - tr: transport, - picker: picker, - status: status, - recvc: p.recvc, - propc: p.propc, - rl: rate.NewLimiter(transport.DialRetryFrequency, 1), - } - p.msgAppReader = &streamReader{ - peerID: peerID, - typ: streamTypeMessage, - tr: transport, - picker: picker, - status: status, - recvc: p.recvc, - propc: p.propc, - rl: rate.NewLimiter(transport.DialRetryFrequency, 1), - } - - p.msgAppV2Reader.start() - p.msgAppReader.start() - - return p -} - -func (p *peer) send(m raftpb.Message) { - p.mu.Lock() - paused := p.paused - p.mu.Unlock() - - if paused { - return - } - - writec, name := p.pick(m) - select { - case writec <- m: - default: - p.r.ReportUnreachable(m.To) - if isMsgSnap(m) { - p.r.ReportSnapshot(m.To, raft.SnapshotFailure) - } - if p.status.isActive() { - plog.MergeWarningf("dropped internal raft message to %s since %s's sending buffer is full (bad/overloaded network)", p.id, name) - } - plog.Debugf("dropped %s to %s since %s's sending buffer is full", m.Type, p.id, name) - sentFailures.WithLabelValues(types.ID(m.To).String()).Inc() - } -} - -func (p *peer) sendSnap(m snap.Message) { - go p.snapSender.send(m) -} - -func (p *peer) update(urls types.URLs) { - p.picker.update(urls) -} - -func (p *peer) attachOutgoingConn(conn *outgoingConn) { - var ok bool - switch conn.t { - case streamTypeMsgAppV2: - ok = p.msgAppV2Writer.attach(conn) - case streamTypeMessage: - ok = p.writer.attach(conn) - default: - plog.Panicf("unhandled stream type %s", conn.t) - } - if !ok { - conn.Close() - } -} - -func (p *peer) activeSince() time.Time { return p.status.activeSince() } - -// Pause pauses the peer. The peer will simply drops all incoming -// messages without returning an error. -func (p *peer) Pause() { - p.mu.Lock() - defer p.mu.Unlock() - p.paused = true - p.msgAppReader.pause() - p.msgAppV2Reader.pause() -} - -// Resume resumes a paused peer. -func (p *peer) Resume() { - p.mu.Lock() - defer p.mu.Unlock() - p.paused = false - p.msgAppReader.resume() - p.msgAppV2Reader.resume() -} - -func (p *peer) stop() { - plog.Infof("stopping peer %s...", p.id) - defer plog.Infof("stopped peer %s", p.id) - - close(p.stopc) - p.cancel() - p.msgAppV2Writer.stop() - p.writer.stop() - p.pipeline.stop() - p.snapSender.stop() - p.msgAppV2Reader.stop() - p.msgAppReader.stop() -} - -// pick picks a chan for sending the given message. The picked chan and the picked chan -// string name are returned. -func (p *peer) pick(m raftpb.Message) (writec chan<- raftpb.Message, picked string) { - var ok bool - // Considering MsgSnap may have a big size, e.g., 1G, and will block - // stream for a long time, only use one of the N pipelines to send MsgSnap. - if isMsgSnap(m) { - return p.pipeline.msgc, pipelineMsg - } else if writec, ok = p.msgAppV2Writer.writec(); ok && isMsgApp(m) { - return writec, streamAppV2 - } else if writec, ok = p.writer.writec(); ok { - return writec, streamMsg - } - return p.pipeline.msgc, pipelineMsg -} - -func isMsgApp(m raftpb.Message) bool { return m.Type == raftpb.MsgApp } - -func isMsgSnap(m raftpb.Message) bool { return m.Type == raftpb.MsgSnap } diff --git a/vendor/github.com/coreos/etcd/rafthttp/peer_status.go b/vendor/github.com/coreos/etcd/rafthttp/peer_status.go deleted file mode 100644 index 69cbd384ca0c..000000000000 --- a/vendor/github.com/coreos/etcd/rafthttp/peer_status.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "fmt" - "sync" - "time" - - "github.com/coreos/etcd/pkg/types" -) - -type failureType struct { - source string - action string -} - -type peerStatus struct { - id types.ID - mu sync.Mutex // protect variables below - active bool - since time.Time -} - -func newPeerStatus(id types.ID) *peerStatus { - return &peerStatus{ - id: id, - } -} - -func (s *peerStatus) activate() { - s.mu.Lock() - defer s.mu.Unlock() - if !s.active { - plog.Infof("peer %s became active", s.id) - s.active = true - s.since = time.Now() - } -} - -func (s *peerStatus) deactivate(failure failureType, reason string) { - s.mu.Lock() - defer s.mu.Unlock() - msg := fmt.Sprintf("failed to %s %s on %s (%s)", failure.action, s.id, failure.source, reason) - if s.active { - plog.Errorf(msg) - plog.Infof("peer %s became inactive (message send to peer failed)", s.id) - s.active = false - s.since = time.Time{} - return - } - plog.Debugf(msg) -} - -func (s *peerStatus) isActive() bool { - s.mu.Lock() - defer s.mu.Unlock() - return s.active -} - -func (s *peerStatus) activeSince() time.Time { - s.mu.Lock() - defer s.mu.Unlock() - return s.since -} diff --git a/vendor/github.com/coreos/etcd/rafthttp/pipeline.go b/vendor/github.com/coreos/etcd/rafthttp/pipeline.go deleted file mode 100644 index d9f07c3479d9..000000000000 --- a/vendor/github.com/coreos/etcd/rafthttp/pipeline.go +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "bytes" - "context" - "errors" - "io/ioutil" - "sync" - "time" - - "github.com/coreos/etcd/etcdserver/stats" - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft" - "github.com/coreos/etcd/raft/raftpb" -) - -const ( - connPerPipeline = 4 - // pipelineBufSize is the size of pipeline buffer, which helps hold the - // temporary network latency. - // The size ensures that pipeline does not drop messages when the network - // is out of work for less than 1 second in good path. - pipelineBufSize = 64 -) - -var errStopped = errors.New("stopped") - -type pipeline struct { - peerID types.ID - - tr *Transport - picker *urlPicker - status *peerStatus - raft Raft - errorc chan error - // deprecate when we depercate v2 API - followerStats *stats.FollowerStats - - msgc chan raftpb.Message - // wait for the handling routines - wg sync.WaitGroup - stopc chan struct{} -} - -func (p *pipeline) start() { - p.stopc = make(chan struct{}) - p.msgc = make(chan raftpb.Message, pipelineBufSize) - p.wg.Add(connPerPipeline) - for i := 0; i < connPerPipeline; i++ { - go p.handle() - } - plog.Infof("started HTTP pipelining with peer %s", p.peerID) -} - -func (p *pipeline) stop() { - close(p.stopc) - p.wg.Wait() - plog.Infof("stopped HTTP pipelining with peer %s", p.peerID) -} - -func (p *pipeline) handle() { - defer p.wg.Done() - - for { - select { - case m := <-p.msgc: - start := time.Now() - err := p.post(pbutil.MustMarshal(&m)) - end := time.Now() - - if err != nil { - p.status.deactivate(failureType{source: pipelineMsg, action: "write"}, err.Error()) - - if m.Type == raftpb.MsgApp && p.followerStats != nil { - p.followerStats.Fail() - } - p.raft.ReportUnreachable(m.To) - if isMsgSnap(m) { - p.raft.ReportSnapshot(m.To, raft.SnapshotFailure) - } - sentFailures.WithLabelValues(types.ID(m.To).String()).Inc() - continue - } - - p.status.activate() - if m.Type == raftpb.MsgApp && p.followerStats != nil { - p.followerStats.Succ(end.Sub(start)) - } - if isMsgSnap(m) { - p.raft.ReportSnapshot(m.To, raft.SnapshotFinish) - } - sentBytes.WithLabelValues(types.ID(m.To).String()).Add(float64(m.Size())) - case <-p.stopc: - return - } - } -} - -// post POSTs a data payload to a url. Returns nil if the POST succeeds, -// error on any failure. -func (p *pipeline) post(data []byte) (err error) { - u := p.picker.pick() - req := createPostRequest(u, RaftPrefix, bytes.NewBuffer(data), "application/protobuf", p.tr.URLs, p.tr.ID, p.tr.ClusterID) - - done := make(chan struct{}, 1) - ctx, cancel := context.WithCancel(context.Background()) - req = req.WithContext(ctx) - go func() { - select { - case <-done: - case <-p.stopc: - waitSchedule() - cancel() - } - }() - - resp, err := p.tr.pipelineRt.RoundTrip(req) - done <- struct{}{} - if err != nil { - p.picker.unreachable(u) - return err - } - b, err := ioutil.ReadAll(resp.Body) - if err != nil { - p.picker.unreachable(u) - return err - } - resp.Body.Close() - - err = checkPostResponse(resp, b, req, p.peerID) - if err != nil { - p.picker.unreachable(u) - // errMemberRemoved is a critical error since a removed member should - // always be stopped. So we use reportCriticalError to report it to errorc. - if err == errMemberRemoved { - reportCriticalError(err, p.errorc) - } - return err - } - - return nil -} - -// waitSchedule waits other goroutines to be scheduled for a while -func waitSchedule() { time.Sleep(time.Millisecond) } diff --git a/vendor/github.com/coreos/etcd/rafthttp/probing_status.go b/vendor/github.com/coreos/etcd/rafthttp/probing_status.go deleted file mode 100644 index 109a0aea0f1a..000000000000 --- a/vendor/github.com/coreos/etcd/rafthttp/probing_status.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "time" - - "github.com/prometheus/client_golang/prometheus" - "github.com/xiang90/probing" -) - -var ( - // proberInterval must be shorter than read timeout. - // Or the connection will time-out. - proberInterval = ConnReadTimeout - time.Second - statusMonitoringInterval = 30 * time.Second - statusErrorInterval = 5 * time.Second -) - -const ( - // RoundTripperNameRaftMessage is the name of round-tripper that sends - // all other Raft messages, other than "snap.Message". - RoundTripperNameRaftMessage = "ROUND_TRIPPER_RAFT_MESSAGE" - // RoundTripperNameSnapshot is the name of round-tripper that sends merged snapshot message. - RoundTripperNameSnapshot = "ROUND_TRIPPER_SNAPSHOT" -) - -func addPeerToProber(p probing.Prober, id string, us []string, roundTripperName string, rttSecProm *prometheus.HistogramVec) { - hus := make([]string, len(us)) - for i := range us { - hus[i] = us[i] + ProbingPrefix - } - - p.AddHTTP(id, proberInterval, hus) - - s, err := p.Status(id) - if err != nil { - plog.Errorf("failed to add peer %s into prober", id) - } else { - go monitorProbingStatus(s, id, roundTripperName, rttSecProm) - } -} - -func monitorProbingStatus(s probing.Status, id string, roundTripperName string, rttSecProm *prometheus.HistogramVec) { - // set the first interval short to log error early. - interval := statusErrorInterval - for { - select { - case <-time.After(interval): - if !s.Health() { - plog.Warningf("health check for peer %s could not connect: %v (prober %q)", id, s.Err(), roundTripperName) - interval = statusErrorInterval - } else { - interval = statusMonitoringInterval - } - if s.ClockDiff() > time.Second { - plog.Warningf("the clock difference against peer %s is too high [%v > %v] (prober %q)", id, s.ClockDiff(), time.Second, roundTripperName) - } - rttSecProm.WithLabelValues(id).Observe(s.SRTT().Seconds()) - case <-s.StopNotify(): - return - } - } -} diff --git a/vendor/github.com/coreos/etcd/rafthttp/remote.go b/vendor/github.com/coreos/etcd/rafthttp/remote.go deleted file mode 100644 index f7f9d2ceb531..000000000000 --- a/vendor/github.com/coreos/etcd/rafthttp/remote.go +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft/raftpb" -) - -type remote struct { - id types.ID - status *peerStatus - pipeline *pipeline -} - -func startRemote(tr *Transport, urls types.URLs, id types.ID) *remote { - picker := newURLPicker(urls) - status := newPeerStatus(id) - pipeline := &pipeline{ - peerID: id, - tr: tr, - picker: picker, - status: status, - raft: tr.Raft, - errorc: tr.ErrorC, - } - pipeline.start() - - return &remote{ - id: id, - status: status, - pipeline: pipeline, - } -} - -func (g *remote) send(m raftpb.Message) { - select { - case g.pipeline.msgc <- m: - default: - if g.status.isActive() { - plog.MergeWarningf("dropped internal raft message to %s since sending buffer is full (bad/overloaded network)", g.id) - } - plog.Debugf("dropped %s to %s since sending buffer is full", m.Type, g.id) - sentFailures.WithLabelValues(types.ID(m.To).String()).Inc() - } -} - -func (g *remote) stop() { - g.pipeline.stop() -} - -func (g *remote) Pause() { - g.stop() -} - -func (g *remote) Resume() { - g.pipeline.start() -} diff --git a/vendor/github.com/coreos/etcd/rafthttp/snapshot_sender.go b/vendor/github.com/coreos/etcd/rafthttp/snapshot_sender.go deleted file mode 100644 index 24eb53553f55..000000000000 --- a/vendor/github.com/coreos/etcd/rafthttp/snapshot_sender.go +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "bytes" - "context" - "io" - "io/ioutil" - "net/http" - "time" - - "github.com/coreos/etcd/pkg/httputil" - pioutil "github.com/coreos/etcd/pkg/ioutil" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft" - "github.com/coreos/etcd/snap" -) - -var ( - // timeout for reading snapshot response body - snapResponseReadTimeout = 5 * time.Second -) - -type snapshotSender struct { - from, to types.ID - cid types.ID - - tr *Transport - picker *urlPicker - status *peerStatus - r Raft - errorc chan error - - stopc chan struct{} -} - -func newSnapshotSender(tr *Transport, picker *urlPicker, to types.ID, status *peerStatus) *snapshotSender { - return &snapshotSender{ - from: tr.ID, - to: to, - cid: tr.ClusterID, - tr: tr, - picker: picker, - status: status, - r: tr.Raft, - errorc: tr.ErrorC, - stopc: make(chan struct{}), - } -} - -func (s *snapshotSender) stop() { close(s.stopc) } - -func (s *snapshotSender) send(merged snap.Message) { - start := time.Now() - - m := merged.Message - to := types.ID(m.To).String() - - body := createSnapBody(merged) - defer body.Close() - - u := s.picker.pick() - req := createPostRequest(u, RaftSnapshotPrefix, body, "application/octet-stream", s.tr.URLs, s.from, s.cid) - - plog.Infof("start to send database snapshot [index: %d, to %s]...", m.Snapshot.Metadata.Index, types.ID(m.To)) - - err := s.post(req) - defer merged.CloseWithError(err) - if err != nil { - plog.Warningf("database snapshot [index: %d, to: %s] failed to be sent out (%v)", m.Snapshot.Metadata.Index, types.ID(m.To), err) - - // errMemberRemoved is a critical error since a removed member should - // always be stopped. So we use reportCriticalError to report it to errorc. - if err == errMemberRemoved { - reportCriticalError(err, s.errorc) - } - - s.picker.unreachable(u) - s.status.deactivate(failureType{source: sendSnap, action: "post"}, err.Error()) - s.r.ReportUnreachable(m.To) - // report SnapshotFailure to raft state machine. After raft state - // machine knows about it, it would pause a while and retry sending - // new snapshot message. - s.r.ReportSnapshot(m.To, raft.SnapshotFailure) - sentFailures.WithLabelValues(to).Inc() - snapshotSendFailures.WithLabelValues(to).Inc() - return - } - s.status.activate() - s.r.ReportSnapshot(m.To, raft.SnapshotFinish) - plog.Infof("database snapshot [index: %d, to: %s] sent out successfully", m.Snapshot.Metadata.Index, types.ID(m.To)) - - sentBytes.WithLabelValues(to).Add(float64(merged.TotalSize)) - - snapshotSend.WithLabelValues(to).Inc() - snapshotSendSeconds.WithLabelValues(to).Observe(time.Since(start).Seconds()) -} - -// post posts the given request. -// It returns nil when request is sent out and processed successfully. -func (s *snapshotSender) post(req *http.Request) (err error) { - ctx, cancel := context.WithCancel(context.Background()) - req = req.WithContext(ctx) - defer cancel() - - type responseAndError struct { - resp *http.Response - body []byte - err error - } - result := make(chan responseAndError, 1) - - go func() { - resp, err := s.tr.pipelineRt.RoundTrip(req) - if err != nil { - result <- responseAndError{resp, nil, err} - return - } - - // close the response body when timeouts. - // prevents from reading the body forever when the other side dies right after - // successfully receives the request body. - time.AfterFunc(snapResponseReadTimeout, func() { httputil.GracefulClose(resp) }) - body, err := ioutil.ReadAll(resp.Body) - result <- responseAndError{resp, body, err} - }() - - select { - case <-s.stopc: - return errStopped - case r := <-result: - if r.err != nil { - return r.err - } - return checkPostResponse(r.resp, r.body, req, s.to) - } -} - -func createSnapBody(merged snap.Message) io.ReadCloser { - buf := new(bytes.Buffer) - enc := &messageEncoder{w: buf} - // encode raft message - if err := enc.encode(&merged.Message); err != nil { - plog.Panicf("encode message error (%v)", err) - } - - return &pioutil.ReaderAndCloser{ - Reader: io.MultiReader(buf, merged.ReadCloser), - Closer: merged.ReadCloser, - } -} diff --git a/vendor/github.com/coreos/etcd/rafthttp/stream.go b/vendor/github.com/coreos/etcd/rafthttp/stream.go deleted file mode 100644 index af49c18b1d90..000000000000 --- a/vendor/github.com/coreos/etcd/rafthttp/stream.go +++ /dev/null @@ -1,533 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "context" - "fmt" - "io" - "io/ioutil" - "net/http" - "path" - "strings" - "sync" - "time" - - "golang.org/x/time/rate" - - "github.com/coreos/etcd/etcdserver/stats" - "github.com/coreos/etcd/pkg/httputil" - "github.com/coreos/etcd/pkg/transport" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/version" - "github.com/coreos/go-semver/semver" -) - -const ( - streamTypeMessage streamType = "message" - streamTypeMsgAppV2 streamType = "msgappv2" - - streamBufSize = 4096 -) - -var ( - errUnsupportedStreamType = fmt.Errorf("unsupported stream type") - - // the key is in string format "major.minor.patch" - supportedStream = map[string][]streamType{ - "2.0.0": {}, - "2.1.0": {streamTypeMsgAppV2, streamTypeMessage}, - "2.2.0": {streamTypeMsgAppV2, streamTypeMessage}, - "2.3.0": {streamTypeMsgAppV2, streamTypeMessage}, - "3.0.0": {streamTypeMsgAppV2, streamTypeMessage}, - "3.1.0": {streamTypeMsgAppV2, streamTypeMessage}, - "3.2.0": {streamTypeMsgAppV2, streamTypeMessage}, - "3.3.0": {streamTypeMsgAppV2, streamTypeMessage}, - } -) - -type streamType string - -func (t streamType) endpoint() string { - switch t { - case streamTypeMsgAppV2: - return path.Join(RaftStreamPrefix, "msgapp") - case streamTypeMessage: - return path.Join(RaftStreamPrefix, "message") - default: - plog.Panicf("unhandled stream type %v", t) - return "" - } -} - -func (t streamType) String() string { - switch t { - case streamTypeMsgAppV2: - return "stream MsgApp v2" - case streamTypeMessage: - return "stream Message" - default: - return "unknown stream" - } -} - -var ( - // linkHeartbeatMessage is a special message used as heartbeat message in - // link layer. It never conflicts with messages from raft because raft - // doesn't send out messages without From and To fields. - linkHeartbeatMessage = raftpb.Message{Type: raftpb.MsgHeartbeat} -) - -func isLinkHeartbeatMessage(m *raftpb.Message) bool { - return m.Type == raftpb.MsgHeartbeat && m.From == 0 && m.To == 0 -} - -type outgoingConn struct { - t streamType - io.Writer - http.Flusher - io.Closer -} - -// streamWriter writes messages to the attached outgoingConn. -type streamWriter struct { - peerID types.ID - status *peerStatus - fs *stats.FollowerStats - r Raft - - mu sync.Mutex // guard field working and closer - closer io.Closer - working bool - - msgc chan raftpb.Message - connc chan *outgoingConn - stopc chan struct{} - done chan struct{} -} - -// startStreamWriter creates a streamWrite and starts a long running go-routine that accepts -// messages and writes to the attached outgoing connection. -func startStreamWriter(id types.ID, status *peerStatus, fs *stats.FollowerStats, r Raft) *streamWriter { - w := &streamWriter{ - peerID: id, - status: status, - fs: fs, - r: r, - msgc: make(chan raftpb.Message, streamBufSize), - connc: make(chan *outgoingConn), - stopc: make(chan struct{}), - done: make(chan struct{}), - } - go w.run() - return w -} - -func (cw *streamWriter) run() { - var ( - msgc chan raftpb.Message - heartbeatc <-chan time.Time - t streamType - enc encoder - flusher http.Flusher - batched int - ) - tickc := time.NewTicker(ConnReadTimeout / 3) - defer tickc.Stop() - unflushed := 0 - - plog.Infof("started streaming with peer %s (writer)", cw.peerID) - - for { - select { - case <-heartbeatc: - err := enc.encode(&linkHeartbeatMessage) - unflushed += linkHeartbeatMessage.Size() - if err == nil { - flusher.Flush() - batched = 0 - sentBytes.WithLabelValues(cw.peerID.String()).Add(float64(unflushed)) - unflushed = 0 - continue - } - - cw.status.deactivate(failureType{source: t.String(), action: "heartbeat"}, err.Error()) - - sentFailures.WithLabelValues(cw.peerID.String()).Inc() - cw.close() - plog.Warningf("lost the TCP streaming connection with peer %s (%s writer)", cw.peerID, t) - heartbeatc, msgc = nil, nil - - case m := <-msgc: - err := enc.encode(&m) - if err == nil { - unflushed += m.Size() - - if len(msgc) == 0 || batched > streamBufSize/2 { - flusher.Flush() - sentBytes.WithLabelValues(cw.peerID.String()).Add(float64(unflushed)) - unflushed = 0 - batched = 0 - } else { - batched++ - } - - continue - } - - cw.status.deactivate(failureType{source: t.String(), action: "write"}, err.Error()) - cw.close() - plog.Warningf("lost the TCP streaming connection with peer %s (%s writer)", cw.peerID, t) - heartbeatc, msgc = nil, nil - cw.r.ReportUnreachable(m.To) - sentFailures.WithLabelValues(cw.peerID.String()).Inc() - - case conn := <-cw.connc: - cw.mu.Lock() - closed := cw.closeUnlocked() - t = conn.t - switch conn.t { - case streamTypeMsgAppV2: - enc = newMsgAppV2Encoder(conn.Writer, cw.fs) - case streamTypeMessage: - enc = &messageEncoder{w: conn.Writer} - default: - plog.Panicf("unhandled stream type %s", conn.t) - } - flusher = conn.Flusher - unflushed = 0 - cw.status.activate() - cw.closer = conn.Closer - cw.working = true - cw.mu.Unlock() - - if closed { - plog.Warningf("closed an existing TCP streaming connection with peer %s (%s writer)", cw.peerID, t) - } - plog.Infof("established a TCP streaming connection with peer %s (%s writer)", cw.peerID, t) - heartbeatc, msgc = tickc.C, cw.msgc - case <-cw.stopc: - if cw.close() { - plog.Infof("closed the TCP streaming connection with peer %s (%s writer)", cw.peerID, t) - } - plog.Infof("stopped streaming with peer %s (writer)", cw.peerID) - close(cw.done) - return - } - } -} - -func (cw *streamWriter) writec() (chan<- raftpb.Message, bool) { - cw.mu.Lock() - defer cw.mu.Unlock() - return cw.msgc, cw.working -} - -func (cw *streamWriter) close() bool { - cw.mu.Lock() - defer cw.mu.Unlock() - return cw.closeUnlocked() -} - -func (cw *streamWriter) closeUnlocked() bool { - if !cw.working { - return false - } - if err := cw.closer.Close(); err != nil { - plog.Errorf("peer %s (writer) connection close error: %v", cw.peerID, err) - } - if len(cw.msgc) > 0 { - cw.r.ReportUnreachable(uint64(cw.peerID)) - } - cw.msgc = make(chan raftpb.Message, streamBufSize) - cw.working = false - return true -} - -func (cw *streamWriter) attach(conn *outgoingConn) bool { - select { - case cw.connc <- conn: - return true - case <-cw.done: - return false - } -} - -func (cw *streamWriter) stop() { - close(cw.stopc) - <-cw.done -} - -// streamReader is a long-running go-routine that dials to the remote stream -// endpoint and reads messages from the response body returned. -type streamReader struct { - peerID types.ID - typ streamType - - tr *Transport - picker *urlPicker - status *peerStatus - recvc chan<- raftpb.Message - propc chan<- raftpb.Message - - rl *rate.Limiter // alters the frequency of dial retrial attempts - - errorc chan<- error - - mu sync.Mutex - paused bool - closer io.Closer - - ctx context.Context - cancel context.CancelFunc - done chan struct{} -} - -func (cr *streamReader) start() { - cr.done = make(chan struct{}) - if cr.errorc == nil { - cr.errorc = cr.tr.ErrorC - } - if cr.ctx == nil { - cr.ctx, cr.cancel = context.WithCancel(context.Background()) - } - go cr.run() -} - -func (cr *streamReader) run() { - t := cr.typ - plog.Infof("started streaming with peer %s (%s reader)", cr.peerID, t) - for { - rc, err := cr.dial(t) - if err != nil { - if err != errUnsupportedStreamType { - cr.status.deactivate(failureType{source: t.String(), action: "dial"}, err.Error()) - } - } else { - cr.status.activate() - plog.Infof("established a TCP streaming connection with peer %s (%s reader)", cr.peerID, cr.typ) - err = cr.decodeLoop(rc, t) - plog.Warningf("lost the TCP streaming connection with peer %s (%s reader)", cr.peerID, cr.typ) - switch { - // all data is read out - case err == io.EOF: - // connection is closed by the remote - case transport.IsClosedConnError(err): - default: - cr.status.deactivate(failureType{source: t.String(), action: "read"}, err.Error()) - } - } - // Wait for a while before new dial attempt - err = cr.rl.Wait(cr.ctx) - if cr.ctx.Err() != nil { - plog.Infof("stopped streaming with peer %s (%s reader)", cr.peerID, t) - close(cr.done) - return - } - if err != nil { - plog.Errorf("streaming with peer %s (%s reader) rate limiter error: %v", cr.peerID, t, err) - } - } -} - -func (cr *streamReader) decodeLoop(rc io.ReadCloser, t streamType) error { - var dec decoder - cr.mu.Lock() - switch t { - case streamTypeMsgAppV2: - dec = newMsgAppV2Decoder(rc, cr.tr.ID, cr.peerID) - case streamTypeMessage: - dec = &messageDecoder{r: rc} - default: - plog.Panicf("unhandled stream type %s", t) - } - select { - case <-cr.ctx.Done(): - cr.mu.Unlock() - if err := rc.Close(); err != nil { - return err - } - return io.EOF - default: - cr.closer = rc - } - cr.mu.Unlock() - - for { - m, err := dec.decode() - if err != nil { - cr.mu.Lock() - cr.close() - cr.mu.Unlock() - return err - } - - receivedBytes.WithLabelValues(types.ID(m.From).String()).Add(float64(m.Size())) - - cr.mu.Lock() - paused := cr.paused - cr.mu.Unlock() - - if paused { - continue - } - - if isLinkHeartbeatMessage(&m) { - // raft is not interested in link layer - // heartbeat message, so we should ignore - // it. - continue - } - - recvc := cr.recvc - if m.Type == raftpb.MsgProp { - recvc = cr.propc - } - - select { - case recvc <- m: - default: - if cr.status.isActive() { - plog.MergeWarningf("dropped internal raft message from %s since receiving buffer is full (overloaded network)", types.ID(m.From)) - } - plog.Debugf("dropped %s from %s since receiving buffer is full", m.Type, types.ID(m.From)) - recvFailures.WithLabelValues(types.ID(m.From).String()).Inc() - } - } -} - -func (cr *streamReader) stop() { - cr.mu.Lock() - cr.cancel() - cr.close() - cr.mu.Unlock() - <-cr.done -} - -func (cr *streamReader) dial(t streamType) (io.ReadCloser, error) { - u := cr.picker.pick() - uu := u - uu.Path = path.Join(t.endpoint(), cr.tr.ID.String()) - - req, err := http.NewRequest("GET", uu.String(), nil) - if err != nil { - cr.picker.unreachable(u) - return nil, fmt.Errorf("failed to make http request to %v (%v)", u, err) - } - req.Header.Set("X-Server-From", cr.tr.ID.String()) - req.Header.Set("X-Server-Version", version.Version) - req.Header.Set("X-Min-Cluster-Version", version.MinClusterVersion) - req.Header.Set("X-Etcd-Cluster-ID", cr.tr.ClusterID.String()) - req.Header.Set("X-Raft-To", cr.peerID.String()) - - setPeerURLsHeader(req, cr.tr.URLs) - - req = req.WithContext(cr.ctx) - - cr.mu.Lock() - select { - case <-cr.ctx.Done(): - cr.mu.Unlock() - return nil, fmt.Errorf("stream reader is stopped") - default: - } - cr.mu.Unlock() - - resp, err := cr.tr.streamRt.RoundTrip(req) - if err != nil { - cr.picker.unreachable(u) - return nil, err - } - - rv := serverVersion(resp.Header) - lv := semver.Must(semver.NewVersion(version.Version)) - if compareMajorMinorVersion(rv, lv) == -1 && !checkStreamSupport(rv, t) { - httputil.GracefulClose(resp) - cr.picker.unreachable(u) - return nil, errUnsupportedStreamType - } - - switch resp.StatusCode { - case http.StatusGone: - httputil.GracefulClose(resp) - cr.picker.unreachable(u) - reportCriticalError(errMemberRemoved, cr.errorc) - return nil, errMemberRemoved - case http.StatusOK: - return resp.Body, nil - case http.StatusNotFound: - httputil.GracefulClose(resp) - cr.picker.unreachable(u) - return nil, fmt.Errorf("peer %s failed to find local node %s", cr.peerID, cr.tr.ID) - case http.StatusPreconditionFailed: - b, err := ioutil.ReadAll(resp.Body) - if err != nil { - cr.picker.unreachable(u) - return nil, err - } - httputil.GracefulClose(resp) - cr.picker.unreachable(u) - - switch strings.TrimSuffix(string(b), "\n") { - case errIncompatibleVersion.Error(): - plog.Errorf("request sent was ignored by peer %s (server version incompatible)", cr.peerID) - return nil, errIncompatibleVersion - case errClusterIDMismatch.Error(): - plog.Errorf("request sent was ignored (cluster ID mismatch: peer[%s]=%s, local=%s)", - cr.peerID, resp.Header.Get("X-Etcd-Cluster-ID"), cr.tr.ClusterID) - return nil, errClusterIDMismatch - default: - return nil, fmt.Errorf("unhandled error %q when precondition failed", string(b)) - } - default: - httputil.GracefulClose(resp) - cr.picker.unreachable(u) - return nil, fmt.Errorf("unhandled http status %d", resp.StatusCode) - } -} - -func (cr *streamReader) close() { - if cr.closer != nil { - if err := cr.closer.Close(); err != nil { - plog.Errorf("peer %s (reader) connection close error: %v", cr.peerID, err) - } - } - cr.closer = nil -} - -func (cr *streamReader) pause() { - cr.mu.Lock() - defer cr.mu.Unlock() - cr.paused = true -} - -func (cr *streamReader) resume() { - cr.mu.Lock() - defer cr.mu.Unlock() - cr.paused = false -} - -// checkStreamSupport checks whether the stream type is supported in the -// given version. -func checkStreamSupport(v *semver.Version, t streamType) bool { - nv := &semver.Version{Major: v.Major, Minor: v.Minor} - for _, s := range supportedStream[nv.String()] { - if s == t { - return true - } - } - return false -} diff --git a/vendor/github.com/coreos/etcd/rafthttp/transport.go b/vendor/github.com/coreos/etcd/rafthttp/transport.go deleted file mode 100644 index 16e854c8a349..000000000000 --- a/vendor/github.com/coreos/etcd/rafthttp/transport.go +++ /dev/null @@ -1,438 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "context" - "net/http" - "sync" - "time" - - "github.com/coreos/etcd/etcdserver/stats" - "github.com/coreos/etcd/pkg/logutil" - "github.com/coreos/etcd/pkg/transport" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/snap" - - "github.com/coreos/pkg/capnslog" - "github.com/xiang90/probing" - "golang.org/x/time/rate" -) - -var plog = logutil.NewMergeLogger(capnslog.NewPackageLogger("github.com/coreos/etcd", "rafthttp")) - -type Raft interface { - Process(ctx context.Context, m raftpb.Message) error - IsIDRemoved(id uint64) bool - ReportUnreachable(id uint64) - ReportSnapshot(id uint64, status raft.SnapshotStatus) -} - -type Transporter interface { - // Start starts the given Transporter. - // Start MUST be called before calling other functions in the interface. - Start() error - // Handler returns the HTTP handler of the transporter. - // A transporter HTTP handler handles the HTTP requests - // from remote peers. - // The handler MUST be used to handle RaftPrefix(/raft) - // endpoint. - Handler() http.Handler - // Send sends out the given messages to the remote peers. - // Each message has a To field, which is an id that maps - // to an existing peer in the transport. - // If the id cannot be found in the transport, the message - // will be ignored. - Send(m []raftpb.Message) - // SendSnapshot sends out the given snapshot message to a remote peer. - // The behavior of SendSnapshot is similar to Send. - SendSnapshot(m snap.Message) - // AddRemote adds a remote with given peer urls into the transport. - // A remote helps newly joined member to catch up the progress of cluster, - // and will not be used after that. - // It is the caller's responsibility to ensure the urls are all valid, - // or it panics. - AddRemote(id types.ID, urls []string) - // AddPeer adds a peer with given peer urls into the transport. - // It is the caller's responsibility to ensure the urls are all valid, - // or it panics. - // Peer urls are used to connect to the remote peer. - AddPeer(id types.ID, urls []string) - // RemovePeer removes the peer with given id. - RemovePeer(id types.ID) - // RemoveAllPeers removes all the existing peers in the transport. - RemoveAllPeers() - // UpdatePeer updates the peer urls of the peer with the given id. - // It is the caller's responsibility to ensure the urls are all valid, - // or it panics. - UpdatePeer(id types.ID, urls []string) - // ActiveSince returns the time that the connection with the peer - // of the given id becomes active. - // If the connection is active since peer was added, it returns the adding time. - // If the connection is currently inactive, it returns zero time. - ActiveSince(id types.ID) time.Time - // ActivePeers returns the number of active peers. - ActivePeers() int - // Stop closes the connections and stops the transporter. - Stop() -} - -// Transport implements Transporter interface. It provides the functionality -// to send raft messages to peers, and receive raft messages from peers. -// User should call Handler method to get a handler to serve requests -// received from peerURLs. -// User needs to call Start before calling other functions, and call -// Stop when the Transport is no longer used. -type Transport struct { - DialTimeout time.Duration // maximum duration before timing out dial of the request - // DialRetryFrequency defines the frequency of streamReader dial retrial attempts; - // a distinct rate limiter is created per every peer (default value: 10 events/sec) - DialRetryFrequency rate.Limit - - TLSInfo transport.TLSInfo // TLS information used when creating connection - - ID types.ID // local member ID - URLs types.URLs // local peer URLs - ClusterID types.ID // raft cluster ID for request validation - Raft Raft // raft state machine, to which the Transport forwards received messages and reports status - Snapshotter *snap.Snapshotter - ServerStats *stats.ServerStats // used to record general transportation statistics - // used to record transportation statistics with followers when - // performing as leader in raft protocol - LeaderStats *stats.LeaderStats - // ErrorC is used to report detected critical errors, e.g., - // the member has been permanently removed from the cluster - // When an error is received from ErrorC, user should stop raft state - // machine and thus stop the Transport. - ErrorC chan error - - streamRt http.RoundTripper // roundTripper used by streams - pipelineRt http.RoundTripper // roundTripper used by pipelines - - mu sync.RWMutex // protect the remote and peer map - remotes map[types.ID]*remote // remotes map that helps newly joined member to catch up - peers map[types.ID]Peer // peers map - - pipelineProber probing.Prober - streamProber probing.Prober -} - -func (t *Transport) Start() error { - var err error - t.streamRt, err = newStreamRoundTripper(t.TLSInfo, t.DialTimeout) - if err != nil { - return err - } - t.pipelineRt, err = NewRoundTripper(t.TLSInfo, t.DialTimeout) - if err != nil { - return err - } - t.remotes = make(map[types.ID]*remote) - t.peers = make(map[types.ID]Peer) - t.pipelineProber = probing.NewProber(t.pipelineRt) - t.streamProber = probing.NewProber(t.streamRt) - - // If client didn't provide dial retry frequency, use the default - // (100ms backoff between attempts to create a new stream), - // so it doesn't bring too much overhead when retry. - if t.DialRetryFrequency == 0 { - t.DialRetryFrequency = rate.Every(100 * time.Millisecond) - } - return nil -} - -func (t *Transport) Handler() http.Handler { - pipelineHandler := newPipelineHandler(t, t.Raft, t.ClusterID) - streamHandler := newStreamHandler(t, t, t.Raft, t.ID, t.ClusterID) - snapHandler := newSnapshotHandler(t, t.Raft, t.Snapshotter, t.ClusterID) - mux := http.NewServeMux() - mux.Handle(RaftPrefix, pipelineHandler) - mux.Handle(RaftStreamPrefix+"/", streamHandler) - mux.Handle(RaftSnapshotPrefix, snapHandler) - mux.Handle(ProbingPrefix, probing.NewHandler()) - return mux -} - -func (t *Transport) Get(id types.ID) Peer { - t.mu.RLock() - defer t.mu.RUnlock() - return t.peers[id] -} - -func (t *Transport) Send(msgs []raftpb.Message) { - for _, m := range msgs { - if m.To == 0 { - // ignore intentionally dropped message - continue - } - to := types.ID(m.To) - - t.mu.RLock() - p, pok := t.peers[to] - g, rok := t.remotes[to] - t.mu.RUnlock() - - if pok { - if m.Type == raftpb.MsgApp { - t.ServerStats.SendAppendReq(m.Size()) - } - p.send(m) - continue - } - - if rok { - g.send(m) - continue - } - - plog.Debugf("ignored message %s (sent to unknown peer %s)", m.Type, to) - } -} - -func (t *Transport) Stop() { - t.mu.Lock() - defer t.mu.Unlock() - for _, r := range t.remotes { - r.stop() - } - for _, p := range t.peers { - p.stop() - } - t.pipelineProber.RemoveAll() - t.streamProber.RemoveAll() - if tr, ok := t.streamRt.(*http.Transport); ok { - tr.CloseIdleConnections() - } - if tr, ok := t.pipelineRt.(*http.Transport); ok { - tr.CloseIdleConnections() - } - t.peers = nil - t.remotes = nil -} - -// CutPeer drops messages to the specified peer. -func (t *Transport) CutPeer(id types.ID) { - t.mu.RLock() - p, pok := t.peers[id] - g, gok := t.remotes[id] - t.mu.RUnlock() - - if pok { - p.(Pausable).Pause() - } - if gok { - g.Pause() - } -} - -// MendPeer recovers the message dropping behavior of the given peer. -func (t *Transport) MendPeer(id types.ID) { - t.mu.RLock() - p, pok := t.peers[id] - g, gok := t.remotes[id] - t.mu.RUnlock() - - if pok { - p.(Pausable).Resume() - } - if gok { - g.Resume() - } -} - -func (t *Transport) AddRemote(id types.ID, us []string) { - t.mu.Lock() - defer t.mu.Unlock() - if t.remotes == nil { - // there's no clean way to shutdown the golang http server - // (see: https://github.com/golang/go/issues/4674) before - // stopping the transport; ignore any new connections. - return - } - if _, ok := t.peers[id]; ok { - return - } - if _, ok := t.remotes[id]; ok { - return - } - urls, err := types.NewURLs(us) - if err != nil { - plog.Panicf("newURLs %+v should never fail: %+v", us, err) - } - t.remotes[id] = startRemote(t, urls, id) -} - -func (t *Transport) AddPeer(id types.ID, us []string) { - t.mu.Lock() - defer t.mu.Unlock() - - if t.peers == nil { - panic("transport stopped") - } - if _, ok := t.peers[id]; ok { - return - } - urls, err := types.NewURLs(us) - if err != nil { - plog.Panicf("newURLs %+v should never fail: %+v", us, err) - } - fs := t.LeaderStats.Follower(id.String()) - t.peers[id] = startPeer(t, urls, id, fs) - addPeerToProber(t.pipelineProber, id.String(), us, RoundTripperNameSnapshot, rtts) - addPeerToProber(t.streamProber, id.String(), us, RoundTripperNameRaftMessage, rtts) - plog.Infof("added peer %s", id) -} - -func (t *Transport) RemovePeer(id types.ID) { - t.mu.Lock() - defer t.mu.Unlock() - t.removePeer(id) -} - -func (t *Transport) RemoveAllPeers() { - t.mu.Lock() - defer t.mu.Unlock() - for id := range t.peers { - t.removePeer(id) - } -} - -// the caller of this function must have the peers mutex. -func (t *Transport) removePeer(id types.ID) { - if peer, ok := t.peers[id]; ok { - peer.stop() - } else { - plog.Panicf("unexpected removal of unknown peer '%d'", id) - } - delete(t.peers, id) - delete(t.LeaderStats.Followers, id.String()) - t.pipelineProber.Remove(id.String()) - t.streamProber.Remove(id.String()) - plog.Infof("removed peer %s", id) -} - -func (t *Transport) UpdatePeer(id types.ID, us []string) { - t.mu.Lock() - defer t.mu.Unlock() - // TODO: return error or just panic? - if _, ok := t.peers[id]; !ok { - return - } - urls, err := types.NewURLs(us) - if err != nil { - plog.Panicf("newURLs %+v should never fail: %+v", us, err) - } - t.peers[id].update(urls) - - t.pipelineProber.Remove(id.String()) - addPeerToProber(t.pipelineProber, id.String(), us, RoundTripperNameSnapshot, rtts) - t.streamProber.Remove(id.String()) - addPeerToProber(t.streamProber, id.String(), us, RoundTripperNameRaftMessage, rtts) - plog.Infof("updated peer %s", id) -} - -func (t *Transport) ActiveSince(id types.ID) time.Time { - t.mu.Lock() - defer t.mu.Unlock() - if p, ok := t.peers[id]; ok { - return p.activeSince() - } - return time.Time{} -} - -func (t *Transport) SendSnapshot(m snap.Message) { - t.mu.Lock() - defer t.mu.Unlock() - p := t.peers[types.ID(m.To)] - if p == nil { - m.CloseWithError(errMemberNotFound) - return - } - p.sendSnap(m) -} - -// Pausable is a testing interface for pausing transport traffic. -type Pausable interface { - Pause() - Resume() -} - -func (t *Transport) Pause() { - for _, p := range t.peers { - p.(Pausable).Pause() - } -} - -func (t *Transport) Resume() { - for _, p := range t.peers { - p.(Pausable).Resume() - } -} - -// ActivePeers returns a channel that closes when an initial -// peer connection has been established. Use this to wait until the -// first peer connection becomes active. -func (t *Transport) ActivePeers() (cnt int) { - t.mu.RLock() - defer t.mu.RUnlock() - for _, p := range t.peers { - if !p.activeSince().IsZero() { - cnt++ - } - } - return cnt -} - -type nopTransporter struct{} - -func NewNopTransporter() Transporter { - return &nopTransporter{} -} - -func (s *nopTransporter) Start() error { return nil } -func (s *nopTransporter) Handler() http.Handler { return nil } -func (s *nopTransporter) Send(m []raftpb.Message) {} -func (s *nopTransporter) SendSnapshot(m snap.Message) {} -func (s *nopTransporter) AddRemote(id types.ID, us []string) {} -func (s *nopTransporter) AddPeer(id types.ID, us []string) {} -func (s *nopTransporter) RemovePeer(id types.ID) {} -func (s *nopTransporter) RemoveAllPeers() {} -func (s *nopTransporter) UpdatePeer(id types.ID, us []string) {} -func (s *nopTransporter) ActiveSince(id types.ID) time.Time { return time.Time{} } -func (s *nopTransporter) ActivePeers() int { return 0 } -func (s *nopTransporter) Stop() {} -func (s *nopTransporter) Pause() {} -func (s *nopTransporter) Resume() {} - -type snapTransporter struct { - nopTransporter - snapDoneC chan snap.Message - snapDir string -} - -func NewSnapTransporter(snapDir string) (Transporter, <-chan snap.Message) { - ch := make(chan snap.Message, 1) - tr := &snapTransporter{snapDoneC: ch, snapDir: snapDir} - return tr, ch -} - -func (s *snapTransporter) SendSnapshot(m snap.Message) { - ss := snap.New(s.snapDir) - ss.SaveDBFrom(m.ReadCloser, m.Snapshot.Metadata.Index+1) - m.CloseWithError(nil) - s.snapDoneC <- m -} diff --git a/vendor/github.com/coreos/etcd/rafthttp/urlpick.go b/vendor/github.com/coreos/etcd/rafthttp/urlpick.go deleted file mode 100644 index 61839deeb70e..000000000000 --- a/vendor/github.com/coreos/etcd/rafthttp/urlpick.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "net/url" - "sync" - - "github.com/coreos/etcd/pkg/types" -) - -type urlPicker struct { - mu sync.Mutex // guards urls and picked - urls types.URLs - picked int -} - -func newURLPicker(urls types.URLs) *urlPicker { - return &urlPicker{ - urls: urls, - } -} - -func (p *urlPicker) update(urls types.URLs) { - p.mu.Lock() - defer p.mu.Unlock() - p.urls = urls - p.picked = 0 -} - -func (p *urlPicker) pick() url.URL { - p.mu.Lock() - defer p.mu.Unlock() - return p.urls[p.picked] -} - -// unreachable notices the picker that the given url is unreachable, -// and it should use other possible urls. -func (p *urlPicker) unreachable(u url.URL) { - p.mu.Lock() - defer p.mu.Unlock() - if u == p.urls[p.picked] { - p.picked = (p.picked + 1) % len(p.urls) - } -} diff --git a/vendor/github.com/coreos/etcd/rafthttp/util.go b/vendor/github.com/coreos/etcd/rafthttp/util.go deleted file mode 100644 index 6ec3641aa7af..000000000000 --- a/vendor/github.com/coreos/etcd/rafthttp/util.go +++ /dev/null @@ -1,186 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "fmt" - "io" - "net" - "net/http" - "net/url" - "strings" - "time" - - "github.com/coreos/etcd/pkg/transport" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/version" - "github.com/coreos/go-semver/semver" -) - -var ( - errMemberRemoved = fmt.Errorf("the member has been permanently removed from the cluster") - errMemberNotFound = fmt.Errorf("member not found") -) - -// NewListener returns a listener for raft message transfer between peers. -// It uses timeout listener to identify broken streams promptly. -func NewListener(u url.URL, tlsinfo *transport.TLSInfo) (net.Listener, error) { - return transport.NewTimeoutListener(u.Host, u.Scheme, tlsinfo, ConnReadTimeout, ConnWriteTimeout) -} - -// NewRoundTripper returns a roundTripper used to send requests -// to rafthttp listener of remote peers. -func NewRoundTripper(tlsInfo transport.TLSInfo, dialTimeout time.Duration) (http.RoundTripper, error) { - // It uses timeout transport to pair with remote timeout listeners. - // It sets no read/write timeout, because message in requests may - // take long time to write out before reading out the response. - return transport.NewTimeoutTransport(tlsInfo, dialTimeout, 0, 0) -} - -// newStreamRoundTripper returns a roundTripper used to send stream requests -// to rafthttp listener of remote peers. -// Read/write timeout is set for stream roundTripper to promptly -// find out broken status, which minimizes the number of messages -// sent on broken connection. -func newStreamRoundTripper(tlsInfo transport.TLSInfo, dialTimeout time.Duration) (http.RoundTripper, error) { - return transport.NewTimeoutTransport(tlsInfo, dialTimeout, ConnReadTimeout, ConnWriteTimeout) -} - -// createPostRequest creates a HTTP POST request that sends raft message. -func createPostRequest(u url.URL, path string, body io.Reader, ct string, urls types.URLs, from, cid types.ID) *http.Request { - uu := u - uu.Path = path - req, err := http.NewRequest("POST", uu.String(), body) - if err != nil { - plog.Panicf("unexpected new request error (%v)", err) - } - req.Header.Set("Content-Type", ct) - req.Header.Set("X-Server-From", from.String()) - req.Header.Set("X-Server-Version", version.Version) - req.Header.Set("X-Min-Cluster-Version", version.MinClusterVersion) - req.Header.Set("X-Etcd-Cluster-ID", cid.String()) - setPeerURLsHeader(req, urls) - - return req -} - -// checkPostResponse checks the response of the HTTP POST request that sends -// raft message. -func checkPostResponse(resp *http.Response, body []byte, req *http.Request, to types.ID) error { - switch resp.StatusCode { - case http.StatusPreconditionFailed: - switch strings.TrimSuffix(string(body), "\n") { - case errIncompatibleVersion.Error(): - plog.Errorf("request sent was ignored by peer %s (server version incompatible)", to) - return errIncompatibleVersion - case errClusterIDMismatch.Error(): - plog.Errorf("request sent was ignored (cluster ID mismatch: remote[%s]=%s, local=%s)", - to, resp.Header.Get("X-Etcd-Cluster-ID"), req.Header.Get("X-Etcd-Cluster-ID")) - return errClusterIDMismatch - default: - return fmt.Errorf("unhandled error %q when precondition failed", string(body)) - } - case http.StatusForbidden: - return errMemberRemoved - case http.StatusNoContent: - return nil - default: - return fmt.Errorf("unexpected http status %s while posting to %q", http.StatusText(resp.StatusCode), req.URL.String()) - } -} - -// reportCriticalError reports the given error through sending it into -// the given error channel. -// If the error channel is filled up when sending error, it drops the error -// because the fact that error has happened is reported, which is -// good enough. -func reportCriticalError(err error, errc chan<- error) { - select { - case errc <- err: - default: - } -} - -// compareMajorMinorVersion returns an integer comparing two versions based on -// their major and minor version. The result will be 0 if a==b, -1 if a < b, -// and 1 if a > b. -func compareMajorMinorVersion(a, b *semver.Version) int { - na := &semver.Version{Major: a.Major, Minor: a.Minor} - nb := &semver.Version{Major: b.Major, Minor: b.Minor} - switch { - case na.LessThan(*nb): - return -1 - case nb.LessThan(*na): - return 1 - default: - return 0 - } -} - -// serverVersion returns the server version from the given header. -func serverVersion(h http.Header) *semver.Version { - verStr := h.Get("X-Server-Version") - // backward compatibility with etcd 2.0 - if verStr == "" { - verStr = "2.0.0" - } - return semver.Must(semver.NewVersion(verStr)) -} - -// serverVersion returns the min cluster version from the given header. -func minClusterVersion(h http.Header) *semver.Version { - verStr := h.Get("X-Min-Cluster-Version") - // backward compatibility with etcd 2.0 - if verStr == "" { - verStr = "2.0.0" - } - return semver.Must(semver.NewVersion(verStr)) -} - -// checkVersionCompability checks whether the given version is compatible -// with the local version. -func checkVersionCompability(name string, server, minCluster *semver.Version) error { - localServer := semver.Must(semver.NewVersion(version.Version)) - localMinCluster := semver.Must(semver.NewVersion(version.MinClusterVersion)) - if compareMajorMinorVersion(server, localMinCluster) == -1 { - return fmt.Errorf("remote version is too low: remote[%s]=%s, local=%s", name, server, localServer) - } - if compareMajorMinorVersion(minCluster, localServer) == 1 { - return fmt.Errorf("local version is too low: remote[%s]=%s, local=%s", name, server, localServer) - } - return nil -} - -// setPeerURLsHeader reports local urls for peer discovery -func setPeerURLsHeader(req *http.Request, urls types.URLs) { - if urls == nil { - // often not set in unit tests - return - } - peerURLs := make([]string, urls.Len()) - for i := range urls { - peerURLs[i] = urls[i].String() - } - req.Header.Set("X-PeerURLs", strings.Join(peerURLs, ",")) -} - -// addRemoteFromRequest adds a remote peer according to an http request header -func addRemoteFromRequest(tr Transporter, r *http.Request) { - if from, err := types.IDFromString(r.Header.Get("X-Server-From")); err == nil { - if urls := r.Header.Get("X-PeerURLs"); urls != "" { - tr.AddRemote(from, strings.Split(urls, ",")) - } - } -} diff --git a/vendor/github.com/coreos/etcd/snap/db.go b/vendor/github.com/coreos/etcd/snap/db.go deleted file mode 100644 index dcbd3bd6710c..000000000000 --- a/vendor/github.com/coreos/etcd/snap/db.go +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package snap - -import ( - "errors" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "time" - - "github.com/coreos/etcd/pkg/fileutil" -) - -var ErrNoDBSnapshot = errors.New("snap: snapshot file doesn't exist") - -// SaveDBFrom saves snapshot of the database from the given reader. It -// guarantees the save operation is atomic. -func (s *Snapshotter) SaveDBFrom(r io.Reader, id uint64) (int64, error) { - start := time.Now() - - f, err := ioutil.TempFile(s.dir, "tmp") - if err != nil { - return 0, err - } - var n int64 - n, err = io.Copy(f, r) - if err == nil { - fsyncStart := time.Now() - err = fileutil.Fsync(f) - snapDBFsyncSec.Observe(time.Since(fsyncStart).Seconds()) - } - f.Close() - if err != nil { - os.Remove(f.Name()) - return n, err - } - fn := s.dbFilePath(id) - if fileutil.Exist(fn) { - os.Remove(f.Name()) - return n, nil - } - err = os.Rename(f.Name(), fn) - if err != nil { - os.Remove(f.Name()) - return n, err - } - - plog.Infof("saved database snapshot to disk [total bytes: %d]", n) - - snapDBSaveSec.Observe(time.Since(start).Seconds()) - return n, nil -} - -// DBFilePath returns the file path for the snapshot of the database with -// given id. If the snapshot does not exist, it returns error. -func (s *Snapshotter) DBFilePath(id uint64) (string, error) { - if _, err := fileutil.ReadDir(s.dir); err != nil { - return "", err - } - if fn := s.dbFilePath(id); fileutil.Exist(fn) { - return fn, nil - } - return "", ErrNoDBSnapshot -} - -func (s *Snapshotter) dbFilePath(id uint64) string { - return filepath.Join(s.dir, fmt.Sprintf("%016x.snap.db", id)) -} diff --git a/vendor/github.com/coreos/etcd/snap/message.go b/vendor/github.com/coreos/etcd/snap/message.go deleted file mode 100644 index d73713ff169b..000000000000 --- a/vendor/github.com/coreos/etcd/snap/message.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package snap - -import ( - "io" - - "github.com/coreos/etcd/pkg/ioutil" - "github.com/coreos/etcd/raft/raftpb" -) - -// Message is a struct that contains a raft Message and a ReadCloser. The type -// of raft message MUST be MsgSnap, which contains the raft meta-data and an -// additional data []byte field that contains the snapshot of the actual state -// machine. -// Message contains the ReadCloser field for handling large snapshot. This avoid -// copying the entire snapshot into a byte array, which consumes a lot of memory. -// -// User of Message should close the Message after sending it. -type Message struct { - raftpb.Message - ReadCloser io.ReadCloser - TotalSize int64 - closeC chan bool -} - -func NewMessage(rs raftpb.Message, rc io.ReadCloser, rcSize int64) *Message { - return &Message{ - Message: rs, - ReadCloser: ioutil.NewExactReadCloser(rc, rcSize), - TotalSize: int64(rs.Size()) + rcSize, - closeC: make(chan bool, 1), - } -} - -// CloseNotify returns a channel that receives a single value -// when the message sent is finished. true indicates the sent -// is successful. -func (m Message) CloseNotify() <-chan bool { - return m.closeC -} - -func (m Message) CloseWithError(err error) { - if cerr := m.ReadCloser.Close(); cerr != nil { - err = cerr - } - if err == nil { - m.closeC <- true - } else { - m.closeC <- false - } -} diff --git a/vendor/github.com/coreos/etcd/snap/metrics.go b/vendor/github.com/coreos/etcd/snap/metrics.go deleted file mode 100644 index 0d3b7e63e5e8..000000000000 --- a/vendor/github.com/coreos/etcd/snap/metrics.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package snap - -import "github.com/prometheus/client_golang/prometheus" - -var ( - // TODO: save_fsync latency? - saveDurations = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd_debugging", - Subsystem: "snap", - Name: "save_total_duration_seconds", - Help: "The total latency distributions of save called by snapshot.", - Buckets: prometheus.ExponentialBuckets(0.001, 2, 14), - }) - - marshallingDurations = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd_debugging", - Subsystem: "snap", - Name: "save_marshalling_duration_seconds", - Help: "The marshalling cost distributions of save called by snapshot.", - Buckets: prometheus.ExponentialBuckets(0.001, 2, 14), - }) - - snapDBSaveSec = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "snap_db", - Name: "save_total_duration_seconds", - Help: "The total latency distributions of v3 snapshot save", - - // lowest bucket start of upper bound 0.1 sec (100 ms) with factor 2 - // highest bucket start of 0.1 sec * 2^9 == 51.2 sec - Buckets: prometheus.ExponentialBuckets(0.1, 2, 10), - }) - - snapDBFsyncSec = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "snap_db", - Name: "fsync_duration_seconds", - Help: "The latency distributions of fsyncing .snap.db file", - - // lowest bucket start of upper bound 0.001 sec (1 ms) with factor 2 - // highest bucket start of 0.001 sec * 2^13 == 8.192 sec - Buckets: prometheus.ExponentialBuckets(0.001, 2, 14), - }) -) - -func init() { - prometheus.MustRegister(saveDurations) - prometheus.MustRegister(marshallingDurations) - prometheus.MustRegister(snapDBSaveSec) - prometheus.MustRegister(snapDBFsyncSec) -} diff --git a/vendor/github.com/coreos/etcd/snap/snappb/snap.pb.go b/vendor/github.com/coreos/etcd/snap/snappb/snap.pb.go deleted file mode 100644 index e72b577f5b8d..000000000000 --- a/vendor/github.com/coreos/etcd/snap/snappb/snap.pb.go +++ /dev/null @@ -1,336 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: snap.proto - -/* - Package snappb is a generated protocol buffer package. - - It is generated from these files: - snap.proto - - It has these top-level messages: - Snapshot -*/ -package snappb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type Snapshot struct { - Crc uint32 `protobuf:"varint,1,opt,name=crc" json:"crc"` - Data []byte `protobuf:"bytes,2,opt,name=data" json:"data,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Snapshot) Reset() { *m = Snapshot{} } -func (m *Snapshot) String() string { return proto.CompactTextString(m) } -func (*Snapshot) ProtoMessage() {} -func (*Snapshot) Descriptor() ([]byte, []int) { return fileDescriptorSnap, []int{0} } - -func init() { - proto.RegisterType((*Snapshot)(nil), "snappb.snapshot") -} -func (m *Snapshot) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Snapshot) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintSnap(dAtA, i, uint64(m.Crc)) - if m.Data != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintSnap(dAtA, i, uint64(len(m.Data))) - i += copy(dAtA[i:], m.Data) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func encodeVarintSnap(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *Snapshot) Size() (n int) { - var l int - _ = l - n += 1 + sovSnap(uint64(m.Crc)) - if m.Data != nil { - l = len(m.Data) - n += 1 + l + sovSnap(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func sovSnap(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozSnap(x uint64) (n int) { - return sovSnap(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Snapshot) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSnap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: snapshot: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: snapshot: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Crc", wireType) - } - m.Crc = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSnap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Crc |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSnap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthSnap - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipSnap(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthSnap - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipSnap(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSnap - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSnap - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSnap - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthSnap - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSnap - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipSnap(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthSnap = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowSnap = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("snap.proto", fileDescriptorSnap) } - -var fileDescriptorSnap = []byte{ - // 126 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2a, 0xce, 0x4b, 0x2c, - 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x03, 0xb1, 0x0b, 0x92, 0xa4, 0x44, 0xd2, 0xf3, - 0xd3, 0xf3, 0xc1, 0x42, 0xfa, 0x20, 0x16, 0x44, 0x56, 0xc9, 0x8c, 0x8b, 0x03, 0x24, 0x5f, 0x9c, - 0x91, 0x5f, 0x22, 0x24, 0xc6, 0xc5, 0x9c, 0x5c, 0x94, 0x2c, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0xeb, - 0xc4, 0x72, 0xe2, 0x9e, 0x3c, 0x43, 0x10, 0x48, 0x40, 0x48, 0x88, 0x8b, 0x25, 0x25, 0xb1, 0x24, - 0x51, 0x82, 0x49, 0x81, 0x51, 0x83, 0x27, 0x08, 0xcc, 0x76, 0x12, 0x39, 0xf1, 0x50, 0x8e, 0xe1, - 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf1, 0x58, 0x8e, - 0x01, 0x10, 0x00, 0x00, 0xff, 0xff, 0xd8, 0x0f, 0x32, 0xb2, 0x78, 0x00, 0x00, 0x00, -} diff --git a/vendor/github.com/coreos/etcd/snap/snapshotter.go b/vendor/github.com/coreos/etcd/snap/snapshotter.go deleted file mode 100644 index 007555921295..000000000000 --- a/vendor/github.com/coreos/etcd/snap/snapshotter.go +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package snap stores raft nodes' states with snapshots. -package snap - -import ( - "errors" - "fmt" - "hash/crc32" - "io/ioutil" - "os" - "path/filepath" - "sort" - "strings" - "time" - - pioutil "github.com/coreos/etcd/pkg/ioutil" - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/raft" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/snap/snappb" - - "github.com/coreos/pkg/capnslog" -) - -const ( - snapSuffix = ".snap" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "snap") - - ErrNoSnapshot = errors.New("snap: no available snapshot") - ErrEmptySnapshot = errors.New("snap: empty snapshot") - ErrCRCMismatch = errors.New("snap: crc mismatch") - crcTable = crc32.MakeTable(crc32.Castagnoli) - - // A map of valid files that can be present in the snap folder. - validFiles = map[string]bool{ - "db": true, - } -) - -type Snapshotter struct { - dir string -} - -func New(dir string) *Snapshotter { - return &Snapshotter{ - dir: dir, - } -} - -func (s *Snapshotter) SaveSnap(snapshot raftpb.Snapshot) error { - if raft.IsEmptySnap(snapshot) { - return nil - } - return s.save(&snapshot) -} - -func (s *Snapshotter) save(snapshot *raftpb.Snapshot) error { - start := time.Now() - - fname := fmt.Sprintf("%016x-%016x%s", snapshot.Metadata.Term, snapshot.Metadata.Index, snapSuffix) - b := pbutil.MustMarshal(snapshot) - crc := crc32.Update(0, crcTable, b) - snap := snappb.Snapshot{Crc: crc, Data: b} - d, err := snap.Marshal() - if err != nil { - return err - } else { - marshallingDurations.Observe(float64(time.Since(start)) / float64(time.Second)) - } - - err = pioutil.WriteAndSyncFile(filepath.Join(s.dir, fname), d, 0666) - if err == nil { - saveDurations.Observe(float64(time.Since(start)) / float64(time.Second)) - } else { - err1 := os.Remove(filepath.Join(s.dir, fname)) - if err1 != nil { - plog.Errorf("failed to remove broken snapshot file %s", filepath.Join(s.dir, fname)) - } - } - return err -} - -func (s *Snapshotter) Load() (*raftpb.Snapshot, error) { - names, err := s.snapNames() - if err != nil { - return nil, err - } - var snap *raftpb.Snapshot - for _, name := range names { - if snap, err = loadSnap(s.dir, name); err == nil { - break - } - } - if err != nil { - return nil, ErrNoSnapshot - } - return snap, nil -} - -func loadSnap(dir, name string) (*raftpb.Snapshot, error) { - fpath := filepath.Join(dir, name) - snap, err := Read(fpath) - if err != nil { - renameBroken(fpath) - } - return snap, err -} - -// Read reads the snapshot named by snapname and returns the snapshot. -func Read(snapname string) (*raftpb.Snapshot, error) { - b, err := ioutil.ReadFile(snapname) - if err != nil { - plog.Errorf("cannot read file %v: %v", snapname, err) - return nil, err - } - - if len(b) == 0 { - plog.Errorf("unexpected empty snapshot") - return nil, ErrEmptySnapshot - } - - var serializedSnap snappb.Snapshot - if err = serializedSnap.Unmarshal(b); err != nil { - plog.Errorf("corrupted snapshot file %v: %v", snapname, err) - return nil, err - } - - if len(serializedSnap.Data) == 0 || serializedSnap.Crc == 0 { - plog.Errorf("unexpected empty snapshot") - return nil, ErrEmptySnapshot - } - - crc := crc32.Update(0, crcTable, serializedSnap.Data) - if crc != serializedSnap.Crc { - plog.Errorf("corrupted snapshot file %v: crc mismatch", snapname) - return nil, ErrCRCMismatch - } - - var snap raftpb.Snapshot - if err = snap.Unmarshal(serializedSnap.Data); err != nil { - plog.Errorf("corrupted snapshot file %v: %v", snapname, err) - return nil, err - } - return &snap, nil -} - -// snapNames returns the filename of the snapshots in logical time order (from newest to oldest). -// If there is no available snapshots, an ErrNoSnapshot will be returned. -func (s *Snapshotter) snapNames() ([]string, error) { - dir, err := os.Open(s.dir) - if err != nil { - return nil, err - } - defer dir.Close() - names, err := dir.Readdirnames(-1) - if err != nil { - return nil, err - } - snaps := checkSuffix(names) - if len(snaps) == 0 { - return nil, ErrNoSnapshot - } - sort.Sort(sort.Reverse(sort.StringSlice(snaps))) - return snaps, nil -} - -func checkSuffix(names []string) []string { - snaps := []string{} - for i := range names { - if strings.HasSuffix(names[i], snapSuffix) { - snaps = append(snaps, names[i]) - } else { - // If we find a file which is not a snapshot then check if it's - // a vaild file. If not throw out a warning. - if _, ok := validFiles[names[i]]; !ok { - plog.Warningf("skipped unexpected non snapshot file %v", names[i]) - } - } - } - return snaps -} - -func renameBroken(path string) { - brokenPath := path + ".broken" - if err := os.Rename(path, brokenPath); err != nil { - plog.Warningf("cannot rename broken snapshot file %v to %v: %v", path, brokenPath, err) - } -} diff --git a/vendor/github.com/coreos/etcd/snapshot/doc.go b/vendor/github.com/coreos/etcd/snapshot/doc.go deleted file mode 100644 index 1c761be70d12..000000000000 --- a/vendor/github.com/coreos/etcd/snapshot/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package snapshot implements utilities around etcd snapshot. -package snapshot diff --git a/vendor/github.com/coreos/etcd/snapshot/util.go b/vendor/github.com/coreos/etcd/snapshot/util.go deleted file mode 100644 index 93ba70b6c610..000000000000 --- a/vendor/github.com/coreos/etcd/snapshot/util.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package snapshot - -import "encoding/binary" - -type revision struct { - main int64 - sub int64 -} - -func bytesToRev(bytes []byte) revision { - return revision{ - main: int64(binary.BigEndian.Uint64(bytes[0:8])), - sub: int64(binary.BigEndian.Uint64(bytes[9:])), - } -} - -// initIndex implements ConsistentIndexGetter so the snapshot won't block -// the new raft instance by waiting for a future raft index. -type initIndex int - -func (i *initIndex) ConsistentIndex() uint64 { return uint64(*i) } diff --git a/vendor/github.com/coreos/etcd/snapshot/v3_snapshot.go b/vendor/github.com/coreos/etcd/snapshot/v3_snapshot.go deleted file mode 100644 index 87da3fb863d1..000000000000 --- a/vendor/github.com/coreos/etcd/snapshot/v3_snapshot.go +++ /dev/null @@ -1,485 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package snapshot - -import ( - "context" - "crypto/sha256" - "encoding/json" - "fmt" - "hash/crc32" - "io" - "math" - "os" - "path/filepath" - "reflect" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/pkg/fileutil" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/snap" - "github.com/coreos/etcd/store" - "github.com/coreos/etcd/wal" - "github.com/coreos/etcd/wal/walpb" - - bolt "github.com/coreos/bbolt" - "go.uber.org/zap" -) - -// Manager defines snapshot methods. -type Manager interface { - // Save fetches snapshot from remote etcd server and saves data - // to target path. If the context "ctx" is canceled or timed out, - // snapshot save stream will error out (e.g. context.Canceled, - // context.DeadlineExceeded). Make sure to specify only one endpoint - // in client configuration. Snapshot API must be requested to a - // selected node, and saved snapshot is the point-in-time state of - // the selected node. - Save(ctx context.Context, cfg clientv3.Config, dbPath string) error - - // Status returns the snapshot file information. - Status(dbPath string) (Status, error) - - // Restore restores a new etcd data directory from given snapshot - // file. It returns an error if specified data directory already - // exists, to prevent unintended data directory overwrites. - Restore(cfg RestoreConfig) error -} - -// NewV3 returns a new snapshot Manager for v3.x snapshot. -func NewV3(lg *zap.Logger) Manager { - if lg == nil { - lg = zap.NewExample() - } - return &v3Manager{lg: lg} -} - -type v3Manager struct { - lg *zap.Logger - - name string - dbPath string - walDir string - snapDir string - cl *membership.RaftCluster - - skipHashCheck bool -} - -// Save fetches snapshot from remote etcd server and saves data to target path. -func (s *v3Manager) Save(ctx context.Context, cfg clientv3.Config, dbPath string) error { - if len(cfg.Endpoints) != 1 { - return fmt.Errorf("snapshot must be requested to one selected node, not multiple %v", cfg.Endpoints) - } - cli, err := clientv3.New(cfg) - if err != nil { - return err - } - defer cli.Close() - - partpath := dbPath + ".part" - defer os.RemoveAll(partpath) - - var f *os.File - f, err = os.Create(partpath) - if err != nil { - return fmt.Errorf("could not open %s (%v)", partpath, err) - } - s.lg.Info( - "created temporary db file", - zap.String("path", partpath), - ) - - now := time.Now() - var rd io.ReadCloser - rd, err = cli.Snapshot(ctx) - if err != nil { - return err - } - s.lg.Info( - "fetching snapshot", - zap.String("endpoint", cfg.Endpoints[0]), - ) - if _, err = io.Copy(f, rd); err != nil { - return err - } - if err = fileutil.Fsync(f); err != nil { - return err - } - if err = f.Close(); err != nil { - return err - } - s.lg.Info( - "fetched snapshot", - zap.String("endpoint", cfg.Endpoints[0]), - zap.Duration("took", time.Since(now)), - ) - - if err = os.Rename(partpath, dbPath); err != nil { - return fmt.Errorf("could not rename %s to %s (%v)", partpath, dbPath, err) - } - s.lg.Info("saved", zap.String("path", dbPath)) - return nil -} - -// Status is the snapshot file status. -type Status struct { - Hash uint32 `json:"hash"` - Revision int64 `json:"revision"` - TotalKey int `json:"totalKey"` - TotalSize int64 `json:"totalSize"` -} - -// Status returns the snapshot file information. -func (s *v3Manager) Status(dbPath string) (ds Status, err error) { - if _, err = os.Stat(dbPath); err != nil { - return ds, err - } - - db, err := bolt.Open(dbPath, 0400, &bolt.Options{ReadOnly: true}) - if err != nil { - return ds, err - } - defer db.Close() - - h := crc32.New(crc32.MakeTable(crc32.Castagnoli)) - - if err = db.View(func(tx *bolt.Tx) error { - ds.TotalSize = tx.Size() - c := tx.Cursor() - for next, _ := c.First(); next != nil; next, _ = c.Next() { - b := tx.Bucket(next) - if b == nil { - return fmt.Errorf("cannot get hash of bucket %s", string(next)) - } - h.Write(next) - iskeyb := (string(next) == "key") - b.ForEach(func(k, v []byte) error { - h.Write(k) - h.Write(v) - if iskeyb { - rev := bytesToRev(k) - ds.Revision = rev.main - } - ds.TotalKey++ - return nil - }) - } - return nil - }); err != nil { - return ds, err - } - - ds.Hash = h.Sum32() - return ds, nil -} - -// RestoreConfig configures snapshot restore operation. -type RestoreConfig struct { - // SnapshotPath is the path of snapshot file to restore from. - SnapshotPath string - - // Name is the human-readable name of this member. - Name string - - // OutputDataDir is the target data directory to save restored data. - // OutputDataDir should not conflict with existing etcd data directory. - // If OutputDataDir already exists, it will return an error to prevent - // unintended data directory overwrites. - // If empty, defaults to "[Name].etcd" if not given. - OutputDataDir string - // OutputWALDir is the target WAL data directory. - // If empty, defaults to "[OutputDataDir]/member/wal" if not given. - OutputWALDir string - - // PeerURLs is a list of member's peer URLs to advertise to the rest of the cluster. - PeerURLs []string - - // InitialCluster is the initial cluster configuration for restore bootstrap. - InitialCluster string - // InitialClusterToken is the initial cluster token for etcd cluster during restore bootstrap. - InitialClusterToken string - - // SkipHashCheck is "true" to ignore snapshot integrity hash value - // (required if copied from data directory). - SkipHashCheck bool -} - -// Restore restores a new etcd data directory from given snapshot file. -func (s *v3Manager) Restore(cfg RestoreConfig) error { - pURLs, err := types.NewURLs(cfg.PeerURLs) - if err != nil { - return err - } - var ics types.URLsMap - ics, err = types.NewURLsMap(cfg.InitialCluster) - if err != nil { - return err - } - - srv := etcdserver.ServerConfig{ - Name: cfg.Name, - PeerURLs: pURLs, - InitialPeerURLsMap: ics, - InitialClusterToken: cfg.InitialClusterToken, - } - if err = srv.VerifyBootstrap(); err != nil { - return err - } - - s.cl, err = membership.NewClusterFromURLsMap(cfg.InitialClusterToken, ics) - if err != nil { - return err - } - - dataDir := cfg.OutputDataDir - if dataDir == "" { - dataDir = cfg.Name + ".etcd" - } - if fileutil.Exist(dataDir) { - return fmt.Errorf("data-dir %q exists", dataDir) - } - - walDir := cfg.OutputWALDir - if walDir == "" { - walDir = filepath.Join(dataDir, "member", "wal") - } else if fileutil.Exist(walDir) { - return fmt.Errorf("wal-dir %q exists", walDir) - } - - s.name = cfg.Name - s.dbPath = cfg.SnapshotPath - s.walDir = walDir - s.snapDir = filepath.Join(dataDir, "member", "snap") - s.skipHashCheck = cfg.SkipHashCheck - - s.lg.Info( - "restoring snapshot", - zap.String("path", s.dbPath), - zap.String("wal-dir", s.walDir), - zap.String("data-dir", dataDir), - zap.String("snap-dir", s.snapDir), - ) - if err = s.saveDB(); err != nil { - return err - } - if err = s.saveWALAndSnap(); err != nil { - return err - } - s.lg.Info( - "restored snapshot", - zap.String("path", s.dbPath), - zap.String("wal-dir", s.walDir), - zap.String("data-dir", dataDir), - zap.String("snap-dir", s.snapDir), - ) - - return nil -} - -// saveDB copies the database snapshot to the snapshot directory -func (s *v3Manager) saveDB() error { - f, ferr := os.OpenFile(s.dbPath, os.O_RDONLY, 0600) - if ferr != nil { - return ferr - } - defer f.Close() - - // get snapshot integrity hash - if _, err := f.Seek(-sha256.Size, io.SeekEnd); err != nil { - return err - } - sha := make([]byte, sha256.Size) - if _, err := f.Read(sha); err != nil { - return err - } - if _, err := f.Seek(0, io.SeekStart); err != nil { - return err - } - - if err := fileutil.CreateDirAll(s.snapDir); err != nil { - return err - } - - dbpath := filepath.Join(s.snapDir, "db") - db, dberr := os.OpenFile(dbpath, os.O_RDWR|os.O_CREATE, 0600) - if dberr != nil { - return dberr - } - if _, err := io.Copy(db, f); err != nil { - return err - } - - // truncate away integrity hash, if any. - off, serr := db.Seek(0, io.SeekEnd) - if serr != nil { - return serr - } - hasHash := (off % 512) == sha256.Size - if hasHash { - if err := db.Truncate(off - sha256.Size); err != nil { - return err - } - } - - if !hasHash && !s.skipHashCheck { - return fmt.Errorf("snapshot missing hash but --skip-hash-check=false") - } - - if hasHash && !s.skipHashCheck { - // check for match - if _, err := db.Seek(0, io.SeekStart); err != nil { - return err - } - h := sha256.New() - if _, err := io.Copy(h, db); err != nil { - return err - } - dbsha := h.Sum(nil) - if !reflect.DeepEqual(sha, dbsha) { - return fmt.Errorf("expected sha256 %v, got %v", sha, dbsha) - } - } - - // db hash is OK, can now modify DB so it can be part of a new cluster - db.Close() - - commit := len(s.cl.Members()) - - // update consistentIndex so applies go through on etcdserver despite - // having a new raft instance - be := backend.NewDefaultBackend(dbpath) - - // a lessor never timeouts leases - lessor := lease.NewLessor(be, math.MaxInt64) - - mvs := mvcc.NewStore(be, lessor, (*initIndex)(&commit)) - txn := mvs.Write() - btx := be.BatchTx() - del := func(k, v []byte) error { - txn.DeleteRange(k, nil) - return nil - } - - // delete stored members from old cluster since using new members - btx.UnsafeForEach([]byte("members"), del) - - // todo: add back new members when we start to deprecate old snap file. - btx.UnsafeForEach([]byte("members_removed"), del) - - // trigger write-out of new consistent index - txn.End() - - mvs.Commit() - mvs.Close() - be.Close() - - return nil -} - -// saveWALAndSnap creates a WAL for the initial cluster -func (s *v3Manager) saveWALAndSnap() error { - if err := fileutil.CreateDirAll(s.walDir); err != nil { - return err - } - - // add members again to persist them to the store we create. - st := store.New(etcdserver.StoreClusterPrefix, etcdserver.StoreKeysPrefix) - s.cl.SetStore(st) - for _, m := range s.cl.Members() { - s.cl.AddMember(m) - } - - m := s.cl.MemberByName(s.name) - md := &etcdserverpb.Metadata{NodeID: uint64(m.ID), ClusterID: uint64(s.cl.ID())} - metadata, merr := md.Marshal() - if merr != nil { - return merr - } - w, walerr := wal.Create(s.walDir, metadata) - if walerr != nil { - return walerr - } - defer w.Close() - - peers := make([]raft.Peer, len(s.cl.MemberIDs())) - for i, id := range s.cl.MemberIDs() { - ctx, err := json.Marshal((*s.cl).Member(id)) - if err != nil { - return err - } - peers[i] = raft.Peer{ID: uint64(id), Context: ctx} - } - - ents := make([]raftpb.Entry, len(peers)) - nodeIDs := make([]uint64, len(peers)) - for i, p := range peers { - nodeIDs[i] = p.ID - cc := raftpb.ConfChange{ - Type: raftpb.ConfChangeAddNode, - NodeID: p.ID, - Context: p.Context, - } - d, err := cc.Marshal() - if err != nil { - return err - } - ents[i] = raftpb.Entry{ - Type: raftpb.EntryConfChange, - Term: 1, - Index: uint64(i + 1), - Data: d, - } - } - - commit, term := uint64(len(ents)), uint64(1) - if err := w.Save(raftpb.HardState{ - Term: term, - Vote: peers[0].ID, - Commit: commit, - }, ents); err != nil { - return err - } - - b, berr := st.Save() - if berr != nil { - return berr - } - raftSnap := raftpb.Snapshot{ - Data: b, - Metadata: raftpb.SnapshotMetadata{ - Index: commit, - Term: term, - ConfState: raftpb.ConfState{ - Nodes: nodeIDs, - }, - }, - } - sn := snap.New(s.snapDir) - if err := sn.SaveSnap(raftSnap); err != nil { - return err - } - - return w.SaveSnapshot(walpb.Snapshot{Index: commit, Term: term}) -} diff --git a/vendor/github.com/coreos/etcd/store/doc.go b/vendor/github.com/coreos/etcd/store/doc.go deleted file mode 100644 index 612df927976e..000000000000 --- a/vendor/github.com/coreos/etcd/store/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package store defines etcd's in-memory key/value store. -package store diff --git a/vendor/github.com/coreos/etcd/store/event.go b/vendor/github.com/coreos/etcd/store/event.go deleted file mode 100644 index efcddb0e0538..000000000000 --- a/vendor/github.com/coreos/etcd/store/event.go +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package store - -const ( - Get = "get" - Create = "create" - Set = "set" - Update = "update" - Delete = "delete" - CompareAndSwap = "compareAndSwap" - CompareAndDelete = "compareAndDelete" - Expire = "expire" -) - -type Event struct { - Action string `json:"action"` - Node *NodeExtern `json:"node,omitempty"` - PrevNode *NodeExtern `json:"prevNode,omitempty"` - EtcdIndex uint64 `json:"-"` - Refresh bool `json:"refresh,omitempty"` -} - -func newEvent(action string, key string, modifiedIndex, createdIndex uint64) *Event { - n := &NodeExtern{ - Key: key, - ModifiedIndex: modifiedIndex, - CreatedIndex: createdIndex, - } - - return &Event{ - Action: action, - Node: n, - } -} - -func (e *Event) IsCreated() bool { - if e.Action == Create { - return true - } - return e.Action == Set && e.PrevNode == nil -} - -func (e *Event) Index() uint64 { - return e.Node.ModifiedIndex -} - -func (e *Event) Clone() *Event { - return &Event{ - Action: e.Action, - EtcdIndex: e.EtcdIndex, - Node: e.Node.Clone(), - PrevNode: e.PrevNode.Clone(), - } -} - -func (e *Event) SetRefresh() { - e.Refresh = true -} diff --git a/vendor/github.com/coreos/etcd/store/event_history.go b/vendor/github.com/coreos/etcd/store/event_history.go deleted file mode 100644 index 235d87a26649..000000000000 --- a/vendor/github.com/coreos/etcd/store/event_history.go +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package store - -import ( - "fmt" - "path" - "strings" - "sync" - - etcdErr "github.com/coreos/etcd/error" -) - -type EventHistory struct { - Queue eventQueue - StartIndex uint64 - LastIndex uint64 - rwl sync.RWMutex -} - -func newEventHistory(capacity int) *EventHistory { - return &EventHistory{ - Queue: eventQueue{ - Capacity: capacity, - Events: make([]*Event, capacity), - }, - } -} - -// addEvent function adds event into the eventHistory -func (eh *EventHistory) addEvent(e *Event) *Event { - eh.rwl.Lock() - defer eh.rwl.Unlock() - - eh.Queue.insert(e) - - eh.LastIndex = e.Index() - - eh.StartIndex = eh.Queue.Events[eh.Queue.Front].Index() - - return e -} - -// scan enumerates events from the index history and stops at the first point -// where the key matches. -func (eh *EventHistory) scan(key string, recursive bool, index uint64) (*Event, *etcdErr.Error) { - eh.rwl.RLock() - defer eh.rwl.RUnlock() - - // index should be after the event history's StartIndex - if index < eh.StartIndex { - return nil, - etcdErr.NewError(etcdErr.EcodeEventIndexCleared, - fmt.Sprintf("the requested history has been cleared [%v/%v]", - eh.StartIndex, index), 0) - } - - // the index should come before the size of the queue minus the duplicate count - if index > eh.LastIndex { // future index - return nil, nil - } - - offset := index - eh.StartIndex - i := (eh.Queue.Front + int(offset)) % eh.Queue.Capacity - - for { - e := eh.Queue.Events[i] - - if !e.Refresh { - ok := (e.Node.Key == key) - - if recursive { - // add tailing slash - nkey := path.Clean(key) - if nkey[len(nkey)-1] != '/' { - nkey = nkey + "/" - } - - ok = ok || strings.HasPrefix(e.Node.Key, nkey) - } - - if (e.Action == Delete || e.Action == Expire) && e.PrevNode != nil && e.PrevNode.Dir { - ok = ok || strings.HasPrefix(key, e.PrevNode.Key) - } - - if ok { - return e, nil - } - } - - i = (i + 1) % eh.Queue.Capacity - - if i == eh.Queue.Back { - return nil, nil - } - } -} - -// clone will be protected by a stop-world lock -// do not need to obtain internal lock -func (eh *EventHistory) clone() *EventHistory { - clonedQueue := eventQueue{ - Capacity: eh.Queue.Capacity, - Events: make([]*Event, eh.Queue.Capacity), - Size: eh.Queue.Size, - Front: eh.Queue.Front, - Back: eh.Queue.Back, - } - - copy(clonedQueue.Events, eh.Queue.Events) - return &EventHistory{ - StartIndex: eh.StartIndex, - Queue: clonedQueue, - LastIndex: eh.LastIndex, - } - -} diff --git a/vendor/github.com/coreos/etcd/store/event_queue.go b/vendor/github.com/coreos/etcd/store/event_queue.go deleted file mode 100644 index 767b835913e7..000000000000 --- a/vendor/github.com/coreos/etcd/store/event_queue.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package store - -type eventQueue struct { - Events []*Event - Size int - Front int - Back int - Capacity int -} - -func (eq *eventQueue) insert(e *Event) { - eq.Events[eq.Back] = e - eq.Back = (eq.Back + 1) % eq.Capacity - - if eq.Size == eq.Capacity { //dequeue - eq.Front = (eq.Front + 1) % eq.Capacity - } else { - eq.Size++ - } -} diff --git a/vendor/github.com/coreos/etcd/store/metrics.go b/vendor/github.com/coreos/etcd/store/metrics.go deleted file mode 100644 index 077c0fa23ea2..000000000000 --- a/vendor/github.com/coreos/etcd/store/metrics.go +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package store - -import ( - "github.com/prometheus/client_golang/prometheus" -) - -// Set of raw Prometheus metrics. -// Labels -// * action = declared in event.go -// * outcome = Outcome -// Do not increment directly, use Report* methods. -var ( - readCounter = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "store", - Name: "reads_total", - Help: "Total number of reads action by (get/getRecursive), local to this member.", - }, []string{"action"}) - - writeCounter = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "store", - Name: "writes_total", - Help: "Total number of writes (e.g. set/compareAndDelete) seen by this member.", - }, []string{"action"}) - - readFailedCounter = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "store", - Name: "reads_failed_total", - Help: "Failed read actions by (get/getRecursive), local to this member.", - }, []string{"action"}) - - writeFailedCounter = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "store", - Name: "writes_failed_total", - Help: "Failed write actions (e.g. set/compareAndDelete), seen by this member.", - }, []string{"action"}) - - expireCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "store", - Name: "expires_total", - Help: "Total number of expired keys.", - }) - - watchRequests = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "store", - Name: "watch_requests_total", - Help: "Total number of incoming watch requests (new or reestablished).", - }) - - watcherCount = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "store", - Name: "watchers", - Help: "Count of currently active watchers.", - }) -) - -const ( - GetRecursive = "getRecursive" -) - -func init() { - if prometheus.Register(readCounter) != nil { - // Tests will try to double register since the tests use both - // store and store_test packages; ignore second attempts. - return - } - prometheus.MustRegister(writeCounter) - prometheus.MustRegister(expireCounter) - prometheus.MustRegister(watchRequests) - prometheus.MustRegister(watcherCount) -} - -func reportReadSuccess(read_action string) { - readCounter.WithLabelValues(read_action).Inc() -} - -func reportReadFailure(read_action string) { - readCounter.WithLabelValues(read_action).Inc() - readFailedCounter.WithLabelValues(read_action).Inc() -} - -func reportWriteSuccess(write_action string) { - writeCounter.WithLabelValues(write_action).Inc() -} - -func reportWriteFailure(write_action string) { - writeCounter.WithLabelValues(write_action).Inc() - writeFailedCounter.WithLabelValues(write_action).Inc() -} - -func reportExpiredKey() { - expireCounter.Inc() -} - -func reportWatchRequest() { - watchRequests.Inc() -} - -func reportWatcherAdded() { - watcherCount.Inc() -} - -func reportWatcherRemoved() { - watcherCount.Dec() -} diff --git a/vendor/github.com/coreos/etcd/store/node.go b/vendor/github.com/coreos/etcd/store/node.go deleted file mode 100644 index c3c87431cb87..000000000000 --- a/vendor/github.com/coreos/etcd/store/node.go +++ /dev/null @@ -1,395 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package store - -import ( - "path" - "sort" - "time" - - etcdErr "github.com/coreos/etcd/error" - "github.com/jonboulle/clockwork" -) - -// explanations of Compare function result -const ( - CompareMatch = iota - CompareIndexNotMatch - CompareValueNotMatch - CompareNotMatch -) - -var Permanent time.Time - -// node is the basic element in the store system. -// A key-value pair will have a string value -// A directory will have a children map -type node struct { - Path string - - CreatedIndex uint64 - ModifiedIndex uint64 - - Parent *node `json:"-"` // should not encode this field! avoid circular dependency. - - ExpireTime time.Time - Value string // for key-value pair - Children map[string]*node // for directory - - // A reference to the store this node is attached to. - store *store -} - -// newKV creates a Key-Value pair -func newKV(store *store, nodePath string, value string, createdIndex uint64, parent *node, expireTime time.Time) *node { - return &node{ - Path: nodePath, - CreatedIndex: createdIndex, - ModifiedIndex: createdIndex, - Parent: parent, - store: store, - ExpireTime: expireTime, - Value: value, - } -} - -// newDir creates a directory -func newDir(store *store, nodePath string, createdIndex uint64, parent *node, expireTime time.Time) *node { - return &node{ - Path: nodePath, - CreatedIndex: createdIndex, - ModifiedIndex: createdIndex, - Parent: parent, - ExpireTime: expireTime, - Children: make(map[string]*node), - store: store, - } -} - -// IsHidden function checks if the node is a hidden node. A hidden node -// will begin with '_' -// A hidden node will not be shown via get command under a directory -// For example if we have /foo/_hidden and /foo/notHidden, get "/foo" -// will only return /foo/notHidden -func (n *node) IsHidden() bool { - _, name := path.Split(n.Path) - - return name[0] == '_' -} - -// IsPermanent function checks if the node is a permanent one. -func (n *node) IsPermanent() bool { - // we use a uninitialized time.Time to indicate the node is a - // permanent one. - // the uninitialized time.Time should equal zero. - return n.ExpireTime.IsZero() -} - -// IsDir function checks whether the node is a directory. -// If the node is a directory, the function will return true. -// Otherwise the function will return false. -func (n *node) IsDir() bool { - return n.Children != nil -} - -// Read function gets the value of the node. -// If the receiver node is not a key-value pair, a "Not A File" error will be returned. -func (n *node) Read() (string, *etcdErr.Error) { - if n.IsDir() { - return "", etcdErr.NewError(etcdErr.EcodeNotFile, "", n.store.CurrentIndex) - } - - return n.Value, nil -} - -// Write function set the value of the node to the given value. -// If the receiver node is a directory, a "Not A File" error will be returned. -func (n *node) Write(value string, index uint64) *etcdErr.Error { - if n.IsDir() { - return etcdErr.NewError(etcdErr.EcodeNotFile, "", n.store.CurrentIndex) - } - - n.Value = value - n.ModifiedIndex = index - - return nil -} - -func (n *node) expirationAndTTL(clock clockwork.Clock) (*time.Time, int64) { - if !n.IsPermanent() { - /* compute ttl as: - ceiling( (expireTime - timeNow) / nanosecondsPerSecond ) - which ranges from 1..n - rather than as: - ( (expireTime - timeNow) / nanosecondsPerSecond ) + 1 - which ranges 1..n+1 - */ - ttlN := n.ExpireTime.Sub(clock.Now()) - ttl := ttlN / time.Second - if (ttlN % time.Second) > 0 { - ttl++ - } - t := n.ExpireTime.UTC() - return &t, int64(ttl) - } - return nil, 0 -} - -// List function return a slice of nodes under the receiver node. -// If the receiver node is not a directory, a "Not A Directory" error will be returned. -func (n *node) List() ([]*node, *etcdErr.Error) { - if !n.IsDir() { - return nil, etcdErr.NewError(etcdErr.EcodeNotDir, "", n.store.CurrentIndex) - } - - nodes := make([]*node, len(n.Children)) - - i := 0 - for _, node := range n.Children { - nodes[i] = node - i++ - } - - return nodes, nil -} - -// GetChild function returns the child node under the directory node. -// On success, it returns the file node -func (n *node) GetChild(name string) (*node, *etcdErr.Error) { - if !n.IsDir() { - return nil, etcdErr.NewError(etcdErr.EcodeNotDir, n.Path, n.store.CurrentIndex) - } - - child, ok := n.Children[name] - - if ok { - return child, nil - } - - return nil, nil -} - -// Add function adds a node to the receiver node. -// If the receiver is not a directory, a "Not A Directory" error will be returned. -// If there is an existing node with the same name under the directory, a "Already Exist" -// error will be returned -func (n *node) Add(child *node) *etcdErr.Error { - if !n.IsDir() { - return etcdErr.NewError(etcdErr.EcodeNotDir, "", n.store.CurrentIndex) - } - - _, name := path.Split(child.Path) - - if _, ok := n.Children[name]; ok { - return etcdErr.NewError(etcdErr.EcodeNodeExist, "", n.store.CurrentIndex) - } - - n.Children[name] = child - - return nil -} - -// Remove function remove the node. -func (n *node) Remove(dir, recursive bool, callback func(path string)) *etcdErr.Error { - if !n.IsDir() { // key-value pair - _, name := path.Split(n.Path) - - // find its parent and remove the node from the map - if n.Parent != nil && n.Parent.Children[name] == n { - delete(n.Parent.Children, name) - } - - if callback != nil { - callback(n.Path) - } - - if !n.IsPermanent() { - n.store.ttlKeyHeap.remove(n) - } - - return nil - } - - if !dir { - // cannot delete a directory without dir set to true - return etcdErr.NewError(etcdErr.EcodeNotFile, n.Path, n.store.CurrentIndex) - } - - if len(n.Children) != 0 && !recursive { - // cannot delete a directory if it is not empty and the operation - // is not recursive - return etcdErr.NewError(etcdErr.EcodeDirNotEmpty, n.Path, n.store.CurrentIndex) - } - - for _, child := range n.Children { // delete all children - child.Remove(true, true, callback) - } - - // delete self - _, name := path.Split(n.Path) - if n.Parent != nil && n.Parent.Children[name] == n { - delete(n.Parent.Children, name) - - if callback != nil { - callback(n.Path) - } - - if !n.IsPermanent() { - n.store.ttlKeyHeap.remove(n) - } - } - - return nil -} - -func (n *node) Repr(recursive, sorted bool, clock clockwork.Clock) *NodeExtern { - if n.IsDir() { - node := &NodeExtern{ - Key: n.Path, - Dir: true, - ModifiedIndex: n.ModifiedIndex, - CreatedIndex: n.CreatedIndex, - } - node.Expiration, node.TTL = n.expirationAndTTL(clock) - - if !recursive { - return node - } - - children, _ := n.List() - node.Nodes = make(NodeExterns, len(children)) - - // we do not use the index in the children slice directly - // we need to skip the hidden one - i := 0 - - for _, child := range children { - - if child.IsHidden() { // get will not list hidden node - continue - } - - node.Nodes[i] = child.Repr(recursive, sorted, clock) - - i++ - } - - // eliminate hidden nodes - node.Nodes = node.Nodes[:i] - if sorted { - sort.Sort(node.Nodes) - } - - return node - } - - // since n.Value could be changed later, so we need to copy the value out - value := n.Value - node := &NodeExtern{ - Key: n.Path, - Value: &value, - ModifiedIndex: n.ModifiedIndex, - CreatedIndex: n.CreatedIndex, - } - node.Expiration, node.TTL = n.expirationAndTTL(clock) - return node -} - -func (n *node) UpdateTTL(expireTime time.Time) { - if !n.IsPermanent() { - if expireTime.IsZero() { - // from ttl to permanent - n.ExpireTime = expireTime - // remove from ttl heap - n.store.ttlKeyHeap.remove(n) - return - } - - // update ttl - n.ExpireTime = expireTime - // update ttl heap - n.store.ttlKeyHeap.update(n) - return - } - - if expireTime.IsZero() { - return - } - - // from permanent to ttl - n.ExpireTime = expireTime - // push into ttl heap - n.store.ttlKeyHeap.push(n) -} - -// Compare function compares node index and value with provided ones. -// second result value explains result and equals to one of Compare.. constants -func (n *node) Compare(prevValue string, prevIndex uint64) (ok bool, which int) { - indexMatch := (prevIndex == 0 || n.ModifiedIndex == prevIndex) - valueMatch := (prevValue == "" || n.Value == prevValue) - ok = valueMatch && indexMatch - switch { - case valueMatch && indexMatch: - which = CompareMatch - case indexMatch && !valueMatch: - which = CompareValueNotMatch - case valueMatch && !indexMatch: - which = CompareIndexNotMatch - default: - which = CompareNotMatch - } - return ok, which -} - -// Clone function clone the node recursively and return the new node. -// If the node is a directory, it will clone all the content under this directory. -// If the node is a key-value pair, it will clone the pair. -func (n *node) Clone() *node { - if !n.IsDir() { - newkv := newKV(n.store, n.Path, n.Value, n.CreatedIndex, n.Parent, n.ExpireTime) - newkv.ModifiedIndex = n.ModifiedIndex - return newkv - } - - clone := newDir(n.store, n.Path, n.CreatedIndex, n.Parent, n.ExpireTime) - clone.ModifiedIndex = n.ModifiedIndex - - for key, child := range n.Children { - clone.Children[key] = child.Clone() - } - - return clone -} - -// recoverAndclean function help to do recovery. -// Two things need to be done: 1. recovery structure; 2. delete expired nodes -// -// If the node is a directory, it will help recover children's parent pointer and recursively -// call this function on its children. -// We check the expire last since we need to recover the whole structure first and add all the -// notifications into the event history. -func (n *node) recoverAndclean() { - if n.IsDir() { - for _, child := range n.Children { - child.Parent = n - child.store = n.store - child.recoverAndclean() - } - } - - if !n.ExpireTime.IsZero() { - n.store.ttlKeyHeap.push(n) - } -} diff --git a/vendor/github.com/coreos/etcd/store/node_extern.go b/vendor/github.com/coreos/etcd/store/node_extern.go deleted file mode 100644 index 7ba870cbe7b8..000000000000 --- a/vendor/github.com/coreos/etcd/store/node_extern.go +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package store - -import ( - "sort" - "time" - - "github.com/jonboulle/clockwork" -) - -// NodeExtern is the external representation of the -// internal node with additional fields -// PrevValue is the previous value of the node -// TTL is time to live in second -type NodeExtern struct { - Key string `json:"key,omitempty"` - Value *string `json:"value,omitempty"` - Dir bool `json:"dir,omitempty"` - Expiration *time.Time `json:"expiration,omitempty"` - TTL int64 `json:"ttl,omitempty"` - Nodes NodeExterns `json:"nodes,omitempty"` - ModifiedIndex uint64 `json:"modifiedIndex,omitempty"` - CreatedIndex uint64 `json:"createdIndex,omitempty"` -} - -func (eNode *NodeExtern) loadInternalNode(n *node, recursive, sorted bool, clock clockwork.Clock) { - if n.IsDir() { // node is a directory - eNode.Dir = true - - children, _ := n.List() - eNode.Nodes = make(NodeExterns, len(children)) - - // we do not use the index in the children slice directly - // we need to skip the hidden one - i := 0 - - for _, child := range children { - if child.IsHidden() { // get will not return hidden nodes - continue - } - - eNode.Nodes[i] = child.Repr(recursive, sorted, clock) - i++ - } - - // eliminate hidden nodes - eNode.Nodes = eNode.Nodes[:i] - - if sorted { - sort.Sort(eNode.Nodes) - } - - } else { // node is a file - value, _ := n.Read() - eNode.Value = &value - } - - eNode.Expiration, eNode.TTL = n.expirationAndTTL(clock) -} - -func (eNode *NodeExtern) Clone() *NodeExtern { - if eNode == nil { - return nil - } - nn := &NodeExtern{ - Key: eNode.Key, - Dir: eNode.Dir, - TTL: eNode.TTL, - ModifiedIndex: eNode.ModifiedIndex, - CreatedIndex: eNode.CreatedIndex, - } - if eNode.Value != nil { - s := *eNode.Value - nn.Value = &s - } - if eNode.Expiration != nil { - t := *eNode.Expiration - nn.Expiration = &t - } - if eNode.Nodes != nil { - nn.Nodes = make(NodeExterns, len(eNode.Nodes)) - for i, n := range eNode.Nodes { - nn.Nodes[i] = n.Clone() - } - } - return nn -} - -type NodeExterns []*NodeExtern - -// interfaces for sorting - -func (ns NodeExterns) Len() int { - return len(ns) -} - -func (ns NodeExterns) Less(i, j int) bool { - return ns[i].Key < ns[j].Key -} - -func (ns NodeExterns) Swap(i, j int) { - ns[i], ns[j] = ns[j], ns[i] -} diff --git a/vendor/github.com/coreos/etcd/store/stats.go b/vendor/github.com/coreos/etcd/store/stats.go deleted file mode 100644 index ce464dda6b88..000000000000 --- a/vendor/github.com/coreos/etcd/store/stats.go +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package store - -import ( - "encoding/json" - "sync/atomic" -) - -const ( - SetSuccess = iota - SetFail - DeleteSuccess - DeleteFail - CreateSuccess - CreateFail - UpdateSuccess - UpdateFail - CompareAndSwapSuccess - CompareAndSwapFail - GetSuccess - GetFail - ExpireCount - CompareAndDeleteSuccess - CompareAndDeleteFail -) - -type Stats struct { - // Number of get requests - - GetSuccess uint64 `json:"getsSuccess"` - GetFail uint64 `json:"getsFail"` - - // Number of sets requests - - SetSuccess uint64 `json:"setsSuccess"` - SetFail uint64 `json:"setsFail"` - - // Number of delete requests - - DeleteSuccess uint64 `json:"deleteSuccess"` - DeleteFail uint64 `json:"deleteFail"` - - // Number of update requests - - UpdateSuccess uint64 `json:"updateSuccess"` - UpdateFail uint64 `json:"updateFail"` - - // Number of create requests - - CreateSuccess uint64 `json:"createSuccess"` - CreateFail uint64 `json:"createFail"` - - // Number of testAndSet requests - - CompareAndSwapSuccess uint64 `json:"compareAndSwapSuccess"` - CompareAndSwapFail uint64 `json:"compareAndSwapFail"` - - // Number of compareAndDelete requests - - CompareAndDeleteSuccess uint64 `json:"compareAndDeleteSuccess"` - CompareAndDeleteFail uint64 `json:"compareAndDeleteFail"` - - ExpireCount uint64 `json:"expireCount"` - - Watchers uint64 `json:"watchers"` -} - -func newStats() *Stats { - s := new(Stats) - return s -} - -func (s *Stats) clone() *Stats { - return &Stats{ - GetSuccess: s.GetSuccess, - GetFail: s.GetFail, - SetSuccess: s.SetSuccess, - SetFail: s.SetFail, - DeleteSuccess: s.DeleteSuccess, - DeleteFail: s.DeleteFail, - UpdateSuccess: s.UpdateSuccess, - UpdateFail: s.UpdateFail, - CreateSuccess: s.CreateSuccess, - CreateFail: s.CreateFail, - CompareAndSwapSuccess: s.CompareAndSwapSuccess, - CompareAndSwapFail: s.CompareAndSwapFail, - CompareAndDeleteSuccess: s.CompareAndDeleteSuccess, - CompareAndDeleteFail: s.CompareAndDeleteFail, - ExpireCount: s.ExpireCount, - Watchers: s.Watchers, - } -} - -func (s *Stats) toJson() []byte { - b, _ := json.Marshal(s) - return b -} - -func (s *Stats) Inc(field int) { - switch field { - case SetSuccess: - atomic.AddUint64(&s.SetSuccess, 1) - case SetFail: - atomic.AddUint64(&s.SetFail, 1) - case CreateSuccess: - atomic.AddUint64(&s.CreateSuccess, 1) - case CreateFail: - atomic.AddUint64(&s.CreateFail, 1) - case DeleteSuccess: - atomic.AddUint64(&s.DeleteSuccess, 1) - case DeleteFail: - atomic.AddUint64(&s.DeleteFail, 1) - case GetSuccess: - atomic.AddUint64(&s.GetSuccess, 1) - case GetFail: - atomic.AddUint64(&s.GetFail, 1) - case UpdateSuccess: - atomic.AddUint64(&s.UpdateSuccess, 1) - case UpdateFail: - atomic.AddUint64(&s.UpdateFail, 1) - case CompareAndSwapSuccess: - atomic.AddUint64(&s.CompareAndSwapSuccess, 1) - case CompareAndSwapFail: - atomic.AddUint64(&s.CompareAndSwapFail, 1) - case CompareAndDeleteSuccess: - atomic.AddUint64(&s.CompareAndDeleteSuccess, 1) - case CompareAndDeleteFail: - atomic.AddUint64(&s.CompareAndDeleteFail, 1) - case ExpireCount: - atomic.AddUint64(&s.ExpireCount, 1) - } -} diff --git a/vendor/github.com/coreos/etcd/store/store.go b/vendor/github.com/coreos/etcd/store/store.go deleted file mode 100644 index edf7f21942b9..000000000000 --- a/vendor/github.com/coreos/etcd/store/store.go +++ /dev/null @@ -1,791 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package store - -import ( - "encoding/json" - "fmt" - "path" - "strconv" - "strings" - "sync" - "time" - - etcdErr "github.com/coreos/etcd/error" - "github.com/coreos/etcd/pkg/types" - "github.com/jonboulle/clockwork" -) - -// The default version to set when the store is first initialized. -const defaultVersion = 2 - -var minExpireTime time.Time - -func init() { - minExpireTime, _ = time.Parse(time.RFC3339, "2000-01-01T00:00:00Z") -} - -type Store interface { - Version() int - Index() uint64 - - Get(nodePath string, recursive, sorted bool) (*Event, error) - Set(nodePath string, dir bool, value string, expireOpts TTLOptionSet) (*Event, error) - Update(nodePath string, newValue string, expireOpts TTLOptionSet) (*Event, error) - Create(nodePath string, dir bool, value string, unique bool, - expireOpts TTLOptionSet) (*Event, error) - CompareAndSwap(nodePath string, prevValue string, prevIndex uint64, - value string, expireOpts TTLOptionSet) (*Event, error) - Delete(nodePath string, dir, recursive bool) (*Event, error) - CompareAndDelete(nodePath string, prevValue string, prevIndex uint64) (*Event, error) - - Watch(prefix string, recursive, stream bool, sinceIndex uint64) (Watcher, error) - - Save() ([]byte, error) - Recovery(state []byte) error - - Clone() Store - SaveNoCopy() ([]byte, error) - - JsonStats() []byte - DeleteExpiredKeys(cutoff time.Time) - - HasTTLKeys() bool -} - -type TTLOptionSet struct { - ExpireTime time.Time - Refresh bool -} - -type store struct { - Root *node - WatcherHub *watcherHub - CurrentIndex uint64 - Stats *Stats - CurrentVersion int - ttlKeyHeap *ttlKeyHeap // need to recovery manually - worldLock sync.RWMutex // stop the world lock - clock clockwork.Clock - readonlySet types.Set -} - -// New creates a store where the given namespaces will be created as initial directories. -func New(namespaces ...string) Store { - s := newStore(namespaces...) - s.clock = clockwork.NewRealClock() - return s -} - -func newStore(namespaces ...string) *store { - s := new(store) - s.CurrentVersion = defaultVersion - s.Root = newDir(s, "/", s.CurrentIndex, nil, Permanent) - for _, namespace := range namespaces { - s.Root.Add(newDir(s, namespace, s.CurrentIndex, s.Root, Permanent)) - } - s.Stats = newStats() - s.WatcherHub = newWatchHub(1000) - s.ttlKeyHeap = newTtlKeyHeap() - s.readonlySet = types.NewUnsafeSet(append(namespaces, "/")...) - return s -} - -// Version retrieves current version of the store. -func (s *store) Version() int { - return s.CurrentVersion -} - -// Index retrieves the current index of the store. -func (s *store) Index() uint64 { - s.worldLock.RLock() - defer s.worldLock.RUnlock() - return s.CurrentIndex -} - -// Get returns a get event. -// If recursive is true, it will return all the content under the node path. -// If sorted is true, it will sort the content by keys. -func (s *store) Get(nodePath string, recursive, sorted bool) (*Event, error) { - var err *etcdErr.Error - - s.worldLock.RLock() - defer s.worldLock.RUnlock() - - defer func() { - if err == nil { - s.Stats.Inc(GetSuccess) - if recursive { - reportReadSuccess(GetRecursive) - } else { - reportReadSuccess(Get) - } - return - } - - s.Stats.Inc(GetFail) - if recursive { - reportReadFailure(GetRecursive) - } else { - reportReadFailure(Get) - } - }() - - n, err := s.internalGet(nodePath) - if err != nil { - return nil, err - } - - e := newEvent(Get, nodePath, n.ModifiedIndex, n.CreatedIndex) - e.EtcdIndex = s.CurrentIndex - e.Node.loadInternalNode(n, recursive, sorted, s.clock) - - return e, nil -} - -// Create creates the node at nodePath. Create will help to create intermediate directories with no ttl. -// If the node has already existed, create will fail. -// If any node on the path is a file, create will fail. -func (s *store) Create(nodePath string, dir bool, value string, unique bool, expireOpts TTLOptionSet) (*Event, error) { - var err *etcdErr.Error - - s.worldLock.Lock() - defer s.worldLock.Unlock() - - defer func() { - if err == nil { - s.Stats.Inc(CreateSuccess) - reportWriteSuccess(Create) - return - } - - s.Stats.Inc(CreateFail) - reportWriteFailure(Create) - }() - - e, err := s.internalCreate(nodePath, dir, value, unique, false, expireOpts.ExpireTime, Create) - if err != nil { - return nil, err - } - - e.EtcdIndex = s.CurrentIndex - s.WatcherHub.notify(e) - - return e, nil -} - -// Set creates or replace the node at nodePath. -func (s *store) Set(nodePath string, dir bool, value string, expireOpts TTLOptionSet) (*Event, error) { - var err *etcdErr.Error - - s.worldLock.Lock() - defer s.worldLock.Unlock() - - defer func() { - if err == nil { - s.Stats.Inc(SetSuccess) - reportWriteSuccess(Set) - return - } - - s.Stats.Inc(SetFail) - reportWriteFailure(Set) - }() - - // Get prevNode value - n, getErr := s.internalGet(nodePath) - if getErr != nil && getErr.ErrorCode != etcdErr.EcodeKeyNotFound { - err = getErr - return nil, err - } - - if expireOpts.Refresh { - if getErr != nil { - err = getErr - return nil, err - } else { - value = n.Value - } - } - - // Set new value - e, err := s.internalCreate(nodePath, dir, value, false, true, expireOpts.ExpireTime, Set) - if err != nil { - return nil, err - } - e.EtcdIndex = s.CurrentIndex - - // Put prevNode into event - if getErr == nil { - prev := newEvent(Get, nodePath, n.ModifiedIndex, n.CreatedIndex) - prev.Node.loadInternalNode(n, false, false, s.clock) - e.PrevNode = prev.Node - } - - if !expireOpts.Refresh { - s.WatcherHub.notify(e) - } else { - e.SetRefresh() - s.WatcherHub.add(e) - } - - return e, nil -} - -// returns user-readable cause of failed comparison -func getCompareFailCause(n *node, which int, prevValue string, prevIndex uint64) string { - switch which { - case CompareIndexNotMatch: - return fmt.Sprintf("[%v != %v]", prevIndex, n.ModifiedIndex) - case CompareValueNotMatch: - return fmt.Sprintf("[%v != %v]", prevValue, n.Value) - default: - return fmt.Sprintf("[%v != %v] [%v != %v]", prevValue, n.Value, prevIndex, n.ModifiedIndex) - } -} - -func (s *store) CompareAndSwap(nodePath string, prevValue string, prevIndex uint64, - value string, expireOpts TTLOptionSet) (*Event, error) { - - var err *etcdErr.Error - - s.worldLock.Lock() - defer s.worldLock.Unlock() - - defer func() { - if err == nil { - s.Stats.Inc(CompareAndSwapSuccess) - reportWriteSuccess(CompareAndSwap) - return - } - - s.Stats.Inc(CompareAndSwapFail) - reportWriteFailure(CompareAndSwap) - }() - - nodePath = path.Clean(path.Join("/", nodePath)) - // we do not allow the user to change "/" - if s.readonlySet.Contains(nodePath) { - return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, "/", s.CurrentIndex) - } - - n, err := s.internalGet(nodePath) - if err != nil { - return nil, err - } - if n.IsDir() { // can only compare and swap file - err = etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, s.CurrentIndex) - return nil, err - } - - // If both of the prevValue and prevIndex are given, we will test both of them. - // Command will be executed, only if both of the tests are successful. - if ok, which := n.Compare(prevValue, prevIndex); !ok { - cause := getCompareFailCause(n, which, prevValue, prevIndex) - err = etcdErr.NewError(etcdErr.EcodeTestFailed, cause, s.CurrentIndex) - return nil, err - } - - if expireOpts.Refresh { - value = n.Value - } - - // update etcd index - s.CurrentIndex++ - - e := newEvent(CompareAndSwap, nodePath, s.CurrentIndex, n.CreatedIndex) - e.EtcdIndex = s.CurrentIndex - e.PrevNode = n.Repr(false, false, s.clock) - eNode := e.Node - - // if test succeed, write the value - n.Write(value, s.CurrentIndex) - n.UpdateTTL(expireOpts.ExpireTime) - - // copy the value for safety - valueCopy := value - eNode.Value = &valueCopy - eNode.Expiration, eNode.TTL = n.expirationAndTTL(s.clock) - - if !expireOpts.Refresh { - s.WatcherHub.notify(e) - } else { - e.SetRefresh() - s.WatcherHub.add(e) - } - - return e, nil -} - -// Delete deletes the node at the given path. -// If the node is a directory, recursive must be true to delete it. -func (s *store) Delete(nodePath string, dir, recursive bool) (*Event, error) { - var err *etcdErr.Error - - s.worldLock.Lock() - defer s.worldLock.Unlock() - - defer func() { - if err == nil { - s.Stats.Inc(DeleteSuccess) - reportWriteSuccess(Delete) - return - } - - s.Stats.Inc(DeleteFail) - reportWriteFailure(Delete) - }() - - nodePath = path.Clean(path.Join("/", nodePath)) - // we do not allow the user to change "/" - if s.readonlySet.Contains(nodePath) { - return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, "/", s.CurrentIndex) - } - - // recursive implies dir - if recursive { - dir = true - } - - n, err := s.internalGet(nodePath) - if err != nil { // if the node does not exist, return error - return nil, err - } - - nextIndex := s.CurrentIndex + 1 - e := newEvent(Delete, nodePath, nextIndex, n.CreatedIndex) - e.EtcdIndex = nextIndex - e.PrevNode = n.Repr(false, false, s.clock) - eNode := e.Node - - if n.IsDir() { - eNode.Dir = true - } - - callback := func(path string) { // notify function - // notify the watchers with deleted set true - s.WatcherHub.notifyWatchers(e, path, true) - } - - err = n.Remove(dir, recursive, callback) - if err != nil { - return nil, err - } - - // update etcd index - s.CurrentIndex++ - - s.WatcherHub.notify(e) - - return e, nil -} - -func (s *store) CompareAndDelete(nodePath string, prevValue string, prevIndex uint64) (*Event, error) { - var err *etcdErr.Error - - s.worldLock.Lock() - defer s.worldLock.Unlock() - - defer func() { - if err == nil { - s.Stats.Inc(CompareAndDeleteSuccess) - reportWriteSuccess(CompareAndDelete) - return - } - - s.Stats.Inc(CompareAndDeleteFail) - reportWriteFailure(CompareAndDelete) - }() - - nodePath = path.Clean(path.Join("/", nodePath)) - - n, err := s.internalGet(nodePath) - if err != nil { // if the node does not exist, return error - return nil, err - } - if n.IsDir() { // can only compare and delete file - return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, s.CurrentIndex) - } - - // If both of the prevValue and prevIndex are given, we will test both of them. - // Command will be executed, only if both of the tests are successful. - if ok, which := n.Compare(prevValue, prevIndex); !ok { - cause := getCompareFailCause(n, which, prevValue, prevIndex) - return nil, etcdErr.NewError(etcdErr.EcodeTestFailed, cause, s.CurrentIndex) - } - - // update etcd index - s.CurrentIndex++ - - e := newEvent(CompareAndDelete, nodePath, s.CurrentIndex, n.CreatedIndex) - e.EtcdIndex = s.CurrentIndex - e.PrevNode = n.Repr(false, false, s.clock) - - callback := func(path string) { // notify function - // notify the watchers with deleted set true - s.WatcherHub.notifyWatchers(e, path, true) - } - - err = n.Remove(false, false, callback) - if err != nil { - return nil, err - } - - s.WatcherHub.notify(e) - - return e, nil -} - -func (s *store) Watch(key string, recursive, stream bool, sinceIndex uint64) (Watcher, error) { - s.worldLock.RLock() - defer s.worldLock.RUnlock() - - key = path.Clean(path.Join("/", key)) - if sinceIndex == 0 { - sinceIndex = s.CurrentIndex + 1 - } - // WatcherHub does not know about the current index, so we need to pass it in - w, err := s.WatcherHub.watch(key, recursive, stream, sinceIndex, s.CurrentIndex) - if err != nil { - return nil, err - } - - return w, nil -} - -// walk walks all the nodePath and apply the walkFunc on each directory -func (s *store) walk(nodePath string, walkFunc func(prev *node, component string) (*node, *etcdErr.Error)) (*node, *etcdErr.Error) { - components := strings.Split(nodePath, "/") - - curr := s.Root - var err *etcdErr.Error - - for i := 1; i < len(components); i++ { - if len(components[i]) == 0 { // ignore empty string - return curr, nil - } - - curr, err = walkFunc(curr, components[i]) - if err != nil { - return nil, err - } - } - - return curr, nil -} - -// Update updates the value/ttl of the node. -// If the node is a file, the value and the ttl can be updated. -// If the node is a directory, only the ttl can be updated. -func (s *store) Update(nodePath string, newValue string, expireOpts TTLOptionSet) (*Event, error) { - var err *etcdErr.Error - - s.worldLock.Lock() - defer s.worldLock.Unlock() - - defer func() { - if err == nil { - s.Stats.Inc(UpdateSuccess) - reportWriteSuccess(Update) - return - } - - s.Stats.Inc(UpdateFail) - reportWriteFailure(Update) - }() - - nodePath = path.Clean(path.Join("/", nodePath)) - // we do not allow the user to change "/" - if s.readonlySet.Contains(nodePath) { - return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, "/", s.CurrentIndex) - } - - currIndex, nextIndex := s.CurrentIndex, s.CurrentIndex+1 - - n, err := s.internalGet(nodePath) - if err != nil { // if the node does not exist, return error - return nil, err - } - if n.IsDir() && len(newValue) != 0 { - // if the node is a directory, we cannot update value to non-empty - return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, currIndex) - } - - if expireOpts.Refresh { - newValue = n.Value - } - - e := newEvent(Update, nodePath, nextIndex, n.CreatedIndex) - e.EtcdIndex = nextIndex - e.PrevNode = n.Repr(false, false, s.clock) - eNode := e.Node - - n.Write(newValue, nextIndex) - - if n.IsDir() { - eNode.Dir = true - } else { - // copy the value for safety - newValueCopy := newValue - eNode.Value = &newValueCopy - } - - // update ttl - n.UpdateTTL(expireOpts.ExpireTime) - - eNode.Expiration, eNode.TTL = n.expirationAndTTL(s.clock) - - if !expireOpts.Refresh { - s.WatcherHub.notify(e) - } else { - e.SetRefresh() - s.WatcherHub.add(e) - } - - s.CurrentIndex = nextIndex - - return e, nil -} - -func (s *store) internalCreate(nodePath string, dir bool, value string, unique, replace bool, - expireTime time.Time, action string) (*Event, *etcdErr.Error) { - - currIndex, nextIndex := s.CurrentIndex, s.CurrentIndex+1 - - if unique { // append unique item under the node path - nodePath += "/" + fmt.Sprintf("%020s", strconv.FormatUint(nextIndex, 10)) - } - - nodePath = path.Clean(path.Join("/", nodePath)) - - // we do not allow the user to change "/" - if s.readonlySet.Contains(nodePath) { - return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, "/", currIndex) - } - - // Assume expire times that are way in the past are - // This can occur when the time is serialized to JS - if expireTime.Before(minExpireTime) { - expireTime = Permanent - } - - dirName, nodeName := path.Split(nodePath) - - // walk through the nodePath, create dirs and get the last directory node - d, err := s.walk(dirName, s.checkDir) - - if err != nil { - s.Stats.Inc(SetFail) - reportWriteFailure(action) - err.Index = currIndex - return nil, err - } - - e := newEvent(action, nodePath, nextIndex, nextIndex) - eNode := e.Node - - n, _ := d.GetChild(nodeName) - - // force will try to replace an existing file - if n != nil { - if replace { - if n.IsDir() { - return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, currIndex) - } - e.PrevNode = n.Repr(false, false, s.clock) - - n.Remove(false, false, nil) - } else { - return nil, etcdErr.NewError(etcdErr.EcodeNodeExist, nodePath, currIndex) - } - } - - if !dir { // create file - // copy the value for safety - valueCopy := value - eNode.Value = &valueCopy - - n = newKV(s, nodePath, value, nextIndex, d, expireTime) - - } else { // create directory - eNode.Dir = true - - n = newDir(s, nodePath, nextIndex, d, expireTime) - } - - // we are sure d is a directory and does not have the children with name n.Name - d.Add(n) - - // node with TTL - if !n.IsPermanent() { - s.ttlKeyHeap.push(n) - - eNode.Expiration, eNode.TTL = n.expirationAndTTL(s.clock) - } - - s.CurrentIndex = nextIndex - - return e, nil -} - -// InternalGet gets the node of the given nodePath. -func (s *store) internalGet(nodePath string) (*node, *etcdErr.Error) { - nodePath = path.Clean(path.Join("/", nodePath)) - - walkFunc := func(parent *node, name string) (*node, *etcdErr.Error) { - - if !parent.IsDir() { - err := etcdErr.NewError(etcdErr.EcodeNotDir, parent.Path, s.CurrentIndex) - return nil, err - } - - child, ok := parent.Children[name] - if ok { - return child, nil - } - - return nil, etcdErr.NewError(etcdErr.EcodeKeyNotFound, path.Join(parent.Path, name), s.CurrentIndex) - } - - f, err := s.walk(nodePath, walkFunc) - - if err != nil { - return nil, err - } - return f, nil -} - -// DeleteExpiredKeys will delete all expired keys -func (s *store) DeleteExpiredKeys(cutoff time.Time) { - s.worldLock.Lock() - defer s.worldLock.Unlock() - - for { - node := s.ttlKeyHeap.top() - if node == nil || node.ExpireTime.After(cutoff) { - break - } - - s.CurrentIndex++ - e := newEvent(Expire, node.Path, s.CurrentIndex, node.CreatedIndex) - e.EtcdIndex = s.CurrentIndex - e.PrevNode = node.Repr(false, false, s.clock) - if node.IsDir() { - e.Node.Dir = true - } - - callback := func(path string) { // notify function - // notify the watchers with deleted set true - s.WatcherHub.notifyWatchers(e, path, true) - } - - s.ttlKeyHeap.pop() - node.Remove(true, true, callback) - - reportExpiredKey() - s.Stats.Inc(ExpireCount) - - s.WatcherHub.notify(e) - } - -} - -// checkDir will check whether the component is a directory under parent node. -// If it is a directory, this function will return the pointer to that node. -// If it does not exist, this function will create a new directory and return the pointer to that node. -// If it is a file, this function will return error. -func (s *store) checkDir(parent *node, dirName string) (*node, *etcdErr.Error) { - node, ok := parent.Children[dirName] - - if ok { - if node.IsDir() { - return node, nil - } - - return nil, etcdErr.NewError(etcdErr.EcodeNotDir, node.Path, s.CurrentIndex) - } - - n := newDir(s, path.Join(parent.Path, dirName), s.CurrentIndex+1, parent, Permanent) - - parent.Children[dirName] = n - - return n, nil -} - -// Save saves the static state of the store system. -// It will not be able to save the state of watchers. -// It will not save the parent field of the node. Or there will -// be cyclic dependencies issue for the json package. -func (s *store) Save() ([]byte, error) { - b, err := json.Marshal(s.Clone()) - if err != nil { - return nil, err - } - - return b, nil -} - -func (s *store) SaveNoCopy() ([]byte, error) { - b, err := json.Marshal(s) - if err != nil { - return nil, err - } - - return b, nil -} - -func (s *store) Clone() Store { - s.worldLock.Lock() - - clonedStore := newStore() - clonedStore.CurrentIndex = s.CurrentIndex - clonedStore.Root = s.Root.Clone() - clonedStore.WatcherHub = s.WatcherHub.clone() - clonedStore.Stats = s.Stats.clone() - clonedStore.CurrentVersion = s.CurrentVersion - - s.worldLock.Unlock() - return clonedStore -} - -// Recovery recovers the store system from a static state -// It needs to recover the parent field of the nodes. -// It needs to delete the expired nodes since the saved time and also -// needs to create monitoring go routines. -func (s *store) Recovery(state []byte) error { - s.worldLock.Lock() - defer s.worldLock.Unlock() - err := json.Unmarshal(state, s) - - if err != nil { - return err - } - - s.ttlKeyHeap = newTtlKeyHeap() - - s.Root.recoverAndclean() - return nil -} - -func (s *store) JsonStats() []byte { - s.Stats.Watchers = uint64(s.WatcherHub.count) - return s.Stats.toJson() -} - -func (s *store) HasTTLKeys() bool { - s.worldLock.RLock() - defer s.worldLock.RUnlock() - return s.ttlKeyHeap.Len() != 0 -} diff --git a/vendor/github.com/coreos/etcd/store/ttl_key_heap.go b/vendor/github.com/coreos/etcd/store/ttl_key_heap.go deleted file mode 100644 index 21ae9b7c6999..000000000000 --- a/vendor/github.com/coreos/etcd/store/ttl_key_heap.go +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package store - -import ( - "container/heap" -) - -// An TTLKeyHeap is a min-heap of TTLKeys order by expiration time -type ttlKeyHeap struct { - array []*node - keyMap map[*node]int -} - -func newTtlKeyHeap() *ttlKeyHeap { - h := &ttlKeyHeap{keyMap: make(map[*node]int)} - heap.Init(h) - return h -} - -func (h ttlKeyHeap) Len() int { - return len(h.array) -} - -func (h ttlKeyHeap) Less(i, j int) bool { - return h.array[i].ExpireTime.Before(h.array[j].ExpireTime) -} - -func (h ttlKeyHeap) Swap(i, j int) { - // swap node - h.array[i], h.array[j] = h.array[j], h.array[i] - - // update map - h.keyMap[h.array[i]] = i - h.keyMap[h.array[j]] = j -} - -func (h *ttlKeyHeap) Push(x interface{}) { - n, _ := x.(*node) - h.keyMap[n] = len(h.array) - h.array = append(h.array, n) -} - -func (h *ttlKeyHeap) Pop() interface{} { - old := h.array - n := len(old) - x := old[n-1] - // Set slice element to nil, so GC can recycle the node. - // This is due to golang GC doesn't support partial recycling: - // https://github.com/golang/go/issues/9618 - old[n-1] = nil - h.array = old[0 : n-1] - delete(h.keyMap, x) - return x -} - -func (h *ttlKeyHeap) top() *node { - if h.Len() != 0 { - return h.array[0] - } - return nil -} - -func (h *ttlKeyHeap) pop() *node { - x := heap.Pop(h) - n, _ := x.(*node) - return n -} - -func (h *ttlKeyHeap) push(x interface{}) { - heap.Push(h, x) -} - -func (h *ttlKeyHeap) update(n *node) { - index, ok := h.keyMap[n] - if ok { - heap.Remove(h, index) - heap.Push(h, n) - } -} - -func (h *ttlKeyHeap) remove(n *node) { - index, ok := h.keyMap[n] - if ok { - heap.Remove(h, index) - } -} diff --git a/vendor/github.com/coreos/etcd/store/watcher.go b/vendor/github.com/coreos/etcd/store/watcher.go deleted file mode 100644 index a236ec777037..000000000000 --- a/vendor/github.com/coreos/etcd/store/watcher.go +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package store - -type Watcher interface { - EventChan() chan *Event - StartIndex() uint64 // The EtcdIndex at which the Watcher was created - Remove() -} - -type watcher struct { - eventChan chan *Event - stream bool - recursive bool - sinceIndex uint64 - startIndex uint64 - hub *watcherHub - removed bool - remove func() -} - -func (w *watcher) EventChan() chan *Event { - return w.eventChan -} - -func (w *watcher) StartIndex() uint64 { - return w.startIndex -} - -// notify function notifies the watcher. If the watcher interests in the given path, -// the function will return true. -func (w *watcher) notify(e *Event, originalPath bool, deleted bool) bool { - // watcher is interested the path in three cases and under one condition - // the condition is that the event happens after the watcher's sinceIndex - - // 1. the path at which the event happens is the path the watcher is watching at. - // For example if the watcher is watching at "/foo" and the event happens at "/foo", - // the watcher must be interested in that event. - - // 2. the watcher is a recursive watcher, it interests in the event happens after - // its watching path. For example if watcher A watches at "/foo" and it is a recursive - // one, it will interest in the event happens at "/foo/bar". - - // 3. when we delete a directory, we need to force notify all the watchers who watches - // at the file we need to delete. - // For example a watcher is watching at "/foo/bar". And we deletes "/foo". The watcher - // should get notified even if "/foo" is not the path it is watching. - if (w.recursive || originalPath || deleted) && e.Index() >= w.sinceIndex { - // We cannot block here if the eventChan capacity is full, otherwise - // etcd will hang. eventChan capacity is full when the rate of - // notifications are higher than our send rate. - // If this happens, we close the channel. - select { - case w.eventChan <- e: - default: - // We have missed a notification. Remove the watcher. - // Removing the watcher also closes the eventChan. - w.remove() - } - return true - } - return false -} - -// Remove removes the watcher from watcherHub -// The actual remove function is guaranteed to only be executed once -func (w *watcher) Remove() { - w.hub.mutex.Lock() - defer w.hub.mutex.Unlock() - - close(w.eventChan) - if w.remove != nil { - w.remove() - } -} - -// nopWatcher is a watcher that receives nothing, always blocking. -type nopWatcher struct{} - -func NewNopWatcher() Watcher { return &nopWatcher{} } -func (w *nopWatcher) EventChan() chan *Event { return nil } -func (w *nopWatcher) StartIndex() uint64 { return 0 } -func (w *nopWatcher) Remove() {} diff --git a/vendor/github.com/coreos/etcd/store/watcher_hub.go b/vendor/github.com/coreos/etcd/store/watcher_hub.go deleted file mode 100644 index 13c23e391d91..000000000000 --- a/vendor/github.com/coreos/etcd/store/watcher_hub.go +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package store - -import ( - "container/list" - "path" - "strings" - "sync" - "sync/atomic" - - etcdErr "github.com/coreos/etcd/error" -) - -// A watcherHub contains all subscribed watchers -// watchers is a map with watched path as key and watcher as value -// EventHistory keeps the old events for watcherHub. It is used to help -// watcher to get a continuous event history. Or a watcher might miss the -// event happens between the end of the first watch command and the start -// of the second command. -type watcherHub struct { - // count must be the first element to keep 64-bit alignment for atomic - // access - - count int64 // current number of watchers. - - mutex sync.Mutex - watchers map[string]*list.List - EventHistory *EventHistory -} - -// newWatchHub creates a watcherHub. The capacity determines how many events we will -// keep in the eventHistory. -// Typically, we only need to keep a small size of history[smaller than 20K]. -// Ideally, it should smaller than 20K/s[max throughput] * 2 * 50ms[RTT] = 2000 -func newWatchHub(capacity int) *watcherHub { - return &watcherHub{ - watchers: make(map[string]*list.List), - EventHistory: newEventHistory(capacity), - } -} - -// Watch function returns a Watcher. -// If recursive is true, the first change after index under key will be sent to the event channel of the watcher. -// If recursive is false, the first change after index at key will be sent to the event channel of the watcher. -// If index is zero, watch will start from the current index + 1. -func (wh *watcherHub) watch(key string, recursive, stream bool, index, storeIndex uint64) (Watcher, *etcdErr.Error) { - reportWatchRequest() - event, err := wh.EventHistory.scan(key, recursive, index) - - if err != nil { - err.Index = storeIndex - return nil, err - } - - w := &watcher{ - eventChan: make(chan *Event, 100), // use a buffered channel - recursive: recursive, - stream: stream, - sinceIndex: index, - startIndex: storeIndex, - hub: wh, - } - - wh.mutex.Lock() - defer wh.mutex.Unlock() - // If the event exists in the known history, append the EtcdIndex and return immediately - if event != nil { - ne := event.Clone() - ne.EtcdIndex = storeIndex - w.eventChan <- ne - return w, nil - } - - l, ok := wh.watchers[key] - - var elem *list.Element - - if ok { // add the new watcher to the back of the list - elem = l.PushBack(w) - } else { // create a new list and add the new watcher - l = list.New() - elem = l.PushBack(w) - wh.watchers[key] = l - } - - w.remove = func() { - if w.removed { // avoid removing it twice - return - } - w.removed = true - l.Remove(elem) - atomic.AddInt64(&wh.count, -1) - reportWatcherRemoved() - if l.Len() == 0 { - delete(wh.watchers, key) - } - } - - atomic.AddInt64(&wh.count, 1) - reportWatcherAdded() - - return w, nil -} - -func (wh *watcherHub) add(e *Event) { - wh.EventHistory.addEvent(e) -} - -// notify function accepts an event and notify to the watchers. -func (wh *watcherHub) notify(e *Event) { - e = wh.EventHistory.addEvent(e) // add event into the eventHistory - - segments := strings.Split(e.Node.Key, "/") - - currPath := "/" - - // walk through all the segments of the path and notify the watchers - // if the path is "/foo/bar", it will notify watchers with path "/", - // "/foo" and "/foo/bar" - - for _, segment := range segments { - currPath = path.Join(currPath, segment) - // notify the watchers who interests in the changes of current path - wh.notifyWatchers(e, currPath, false) - } -} - -func (wh *watcherHub) notifyWatchers(e *Event, nodePath string, deleted bool) { - wh.mutex.Lock() - defer wh.mutex.Unlock() - - l, ok := wh.watchers[nodePath] - if ok { - curr := l.Front() - - for curr != nil { - next := curr.Next() // save reference to the next one in the list - - w, _ := curr.Value.(*watcher) - - originalPath := (e.Node.Key == nodePath) - if (originalPath || !isHidden(nodePath, e.Node.Key)) && w.notify(e, originalPath, deleted) { - if !w.stream { // do not remove the stream watcher - // if we successfully notify a watcher - // we need to remove the watcher from the list - // and decrease the counter - w.removed = true - l.Remove(curr) - atomic.AddInt64(&wh.count, -1) - reportWatcherRemoved() - } - } - - curr = next // update current to the next element in the list - } - - if l.Len() == 0 { - // if we have notified all watcher in the list - // we can delete the list - delete(wh.watchers, nodePath) - } - } -} - -// clone function clones the watcherHub and return the cloned one. -// only clone the static content. do not clone the current watchers. -func (wh *watcherHub) clone() *watcherHub { - clonedHistory := wh.EventHistory.clone() - - return &watcherHub{ - EventHistory: clonedHistory, - } -} - -// isHidden checks to see if key path is considered hidden to watch path i.e. the -// last element is hidden or it's within a hidden directory -func isHidden(watchPath, keyPath string) bool { - // When deleting a directory, watchPath might be deeper than the actual keyPath - // For example, when deleting /foo we also need to notify watchers on /foo/bar. - if len(watchPath) > len(keyPath) { - return false - } - // if watch path is just a "/", after path will start without "/" - // add a "/" to deal with the special case when watchPath is "/" - afterPath := path.Clean("/" + keyPath[len(watchPath):]) - return strings.Contains(afterPath, "/_") -} diff --git a/vendor/github.com/coreos/etcd/version/version.go b/vendor/github.com/coreos/etcd/version/version.go deleted file mode 100644 index c2bf7cfd5612..000000000000 --- a/vendor/github.com/coreos/etcd/version/version.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package version implements etcd version parsing and contains latest version -// information. -package version - -import ( - "fmt" - "strings" - - "github.com/coreos/go-semver/semver" -) - -var ( - // MinClusterVersion is the min cluster version this etcd binary is compatible with. - MinClusterVersion = "3.0.0" - Version = "3.3.13" - APIVersion = "unknown" - - // Git SHA Value will be set during build - GitSHA = "Not provided (use ./build instead of go build)" -) - -func init() { - ver, err := semver.NewVersion(Version) - if err == nil { - APIVersion = fmt.Sprintf("%d.%d", ver.Major, ver.Minor) - } -} - -type Versions struct { - Server string `json:"etcdserver"` - Cluster string `json:"etcdcluster"` - // TODO: raft state machine version -} - -// Cluster only keeps the major.minor. -func Cluster(v string) string { - vs := strings.Split(v, ".") - if len(vs) <= 2 { - return v - } - return fmt.Sprintf("%s.%s", vs[0], vs[1]) -} diff --git a/vendor/github.com/coreos/etcd/wal/decoder.go b/vendor/github.com/coreos/etcd/wal/decoder.go deleted file mode 100644 index 6a217f897b01..000000000000 --- a/vendor/github.com/coreos/etcd/wal/decoder.go +++ /dev/null @@ -1,188 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import ( - "bufio" - "encoding/binary" - "hash" - "io" - "sync" - - "github.com/coreos/etcd/pkg/crc" - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/wal/walpb" -) - -const minSectorSize = 512 - -// frameSizeBytes is frame size in bytes, including record size and padding size. -const frameSizeBytes = 8 - -type decoder struct { - mu sync.Mutex - brs []*bufio.Reader - - // lastValidOff file offset following the last valid decoded record - lastValidOff int64 - crc hash.Hash32 -} - -func newDecoder(r ...io.Reader) *decoder { - readers := make([]*bufio.Reader, len(r)) - for i := range r { - readers[i] = bufio.NewReader(r[i]) - } - return &decoder{ - brs: readers, - crc: crc.New(0, crcTable), - } -} - -func (d *decoder) decode(rec *walpb.Record) error { - rec.Reset() - d.mu.Lock() - defer d.mu.Unlock() - return d.decodeRecord(rec) -} - -func (d *decoder) decodeRecord(rec *walpb.Record) error { - if len(d.brs) == 0 { - return io.EOF - } - - l, err := readInt64(d.brs[0]) - if err == io.EOF || (err == nil && l == 0) { - // hit end of file or preallocated space - d.brs = d.brs[1:] - if len(d.brs) == 0 { - return io.EOF - } - d.lastValidOff = 0 - return d.decodeRecord(rec) - } - if err != nil { - return err - } - - recBytes, padBytes := decodeFrameSize(l) - - data := make([]byte, recBytes+padBytes) - if _, err = io.ReadFull(d.brs[0], data); err != nil { - // ReadFull returns io.EOF only if no bytes were read - // the decoder should treat this as an ErrUnexpectedEOF instead. - if err == io.EOF { - err = io.ErrUnexpectedEOF - } - return err - } - if err := rec.Unmarshal(data[:recBytes]); err != nil { - if d.isTornEntry(data) { - return io.ErrUnexpectedEOF - } - return err - } - - // skip crc checking if the record type is crcType - if rec.Type != crcType { - d.crc.Write(rec.Data) - if err := rec.Validate(d.crc.Sum32()); err != nil { - if d.isTornEntry(data) { - return io.ErrUnexpectedEOF - } - return err - } - } - // record decoded as valid; point last valid offset to end of record - d.lastValidOff += frameSizeBytes + recBytes + padBytes - return nil -} - -func decodeFrameSize(lenField int64) (recBytes int64, padBytes int64) { - // the record size is stored in the lower 56 bits of the 64-bit length - recBytes = int64(uint64(lenField) & ^(uint64(0xff) << 56)) - // non-zero padding is indicated by set MSb / a negative length - if lenField < 0 { - // padding is stored in lower 3 bits of length MSB - padBytes = int64((uint64(lenField) >> 56) & 0x7) - } - return recBytes, padBytes -} - -// isTornEntry determines whether the last entry of the WAL was partially written -// and corrupted because of a torn write. -func (d *decoder) isTornEntry(data []byte) bool { - if len(d.brs) != 1 { - return false - } - - fileOff := d.lastValidOff + frameSizeBytes - curOff := 0 - chunks := [][]byte{} - // split data on sector boundaries - for curOff < len(data) { - chunkLen := int(minSectorSize - (fileOff % minSectorSize)) - if chunkLen > len(data)-curOff { - chunkLen = len(data) - curOff - } - chunks = append(chunks, data[curOff:curOff+chunkLen]) - fileOff += int64(chunkLen) - curOff += chunkLen - } - - // if any data for a sector chunk is all 0, it's a torn write - for _, sect := range chunks { - isZero := true - for _, v := range sect { - if v != 0 { - isZero = false - break - } - } - if isZero { - return true - } - } - return false -} - -func (d *decoder) updateCRC(prevCrc uint32) { - d.crc = crc.New(prevCrc, crcTable) -} - -func (d *decoder) lastCRC() uint32 { - return d.crc.Sum32() -} - -func (d *decoder) lastOffset() int64 { return d.lastValidOff } - -func mustUnmarshalEntry(d []byte) raftpb.Entry { - var e raftpb.Entry - pbutil.MustUnmarshal(&e, d) - return e -} - -func mustUnmarshalState(d []byte) raftpb.HardState { - var s raftpb.HardState - pbutil.MustUnmarshal(&s, d) - return s -} - -func readInt64(r io.Reader) (int64, error) { - var n int64 - err := binary.Read(r, binary.LittleEndian, &n) - return n, err -} diff --git a/vendor/github.com/coreos/etcd/wal/doc.go b/vendor/github.com/coreos/etcd/wal/doc.go deleted file mode 100644 index a3abd69613d4..000000000000 --- a/vendor/github.com/coreos/etcd/wal/doc.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package wal provides an implementation of a write ahead log that is used by -etcd. - -A WAL is created at a particular directory and is made up of a number of -segmented WAL files. Inside of each file the raft state and entries are appended -to it with the Save method: - - metadata := []byte{} - w, err := wal.Create("/var/lib/etcd", metadata) - ... - err := w.Save(s, ents) - -After saving a raft snapshot to disk, SaveSnapshot method should be called to -record it. So WAL can match with the saved snapshot when restarting. - - err := w.SaveSnapshot(walpb.Snapshot{Index: 10, Term: 2}) - -When a user has finished using a WAL it must be closed: - - w.Close() - -Each WAL file is a stream of WAL records. A WAL record is a length field and a wal record -protobuf. The record protobuf contains a CRC, a type, and a data payload. The length field is a -64-bit packed structure holding the length of the remaining logical record data in its lower -56 bits and its physical padding in the first three bits of the most significant byte. Each -record is 8-byte aligned so that the length field is never torn. The CRC contains the CRC32 -value of all record protobufs preceding the current record. - -WAL files are placed inside of the directory in the following format: -$seq-$index.wal - -The first WAL file to be created will be 0000000000000000-0000000000000000.wal -indicating an initial sequence of 0 and an initial raft index of 0. The first -entry written to WAL MUST have raft index 0. - -WAL will cut its current tail wal file if its size exceeds 64MB. This will increment an internal -sequence number and cause a new file to be created. If the last raft index saved -was 0x20 and this is the first time cut has been called on this WAL then the sequence will -increment from 0x0 to 0x1. The new file will be: 0000000000000001-0000000000000021.wal. -If a second cut issues 0x10 entries with incremental index later then the file will be called: -0000000000000002-0000000000000031.wal. - -At a later time a WAL can be opened at a particular snapshot. If there is no -snapshot, an empty snapshot should be passed in. - - w, err := wal.Open("/var/lib/etcd", walpb.Snapshot{Index: 10, Term: 2}) - ... - -The snapshot must have been written to the WAL. - -Additional items cannot be Saved to this WAL until all of the items from the given -snapshot to the end of the WAL are read first: - - metadata, state, ents, err := w.ReadAll() - -This will give you the metadata, the last raft.State and the slice of -raft.Entry items in the log. - -*/ -package wal diff --git a/vendor/github.com/coreos/etcd/wal/encoder.go b/vendor/github.com/coreos/etcd/wal/encoder.go deleted file mode 100644 index e8040b8dff13..000000000000 --- a/vendor/github.com/coreos/etcd/wal/encoder.go +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import ( - "encoding/binary" - "hash" - "io" - "os" - "sync" - - "github.com/coreos/etcd/pkg/crc" - "github.com/coreos/etcd/pkg/ioutil" - "github.com/coreos/etcd/wal/walpb" -) - -// walPageBytes is the alignment for flushing records to the backing Writer. -// It should be a multiple of the minimum sector size so that WAL can safely -// distinguish between torn writes and ordinary data corruption. -const walPageBytes = 8 * minSectorSize - -type encoder struct { - mu sync.Mutex - bw *ioutil.PageWriter - - crc hash.Hash32 - buf []byte - uint64buf []byte -} - -func newEncoder(w io.Writer, prevCrc uint32, pageOffset int) *encoder { - return &encoder{ - bw: ioutil.NewPageWriter(w, walPageBytes, pageOffset), - crc: crc.New(prevCrc, crcTable), - // 1MB buffer - buf: make([]byte, 1024*1024), - uint64buf: make([]byte, 8), - } -} - -// newFileEncoder creates a new encoder with current file offset for the page writer. -func newFileEncoder(f *os.File, prevCrc uint32) (*encoder, error) { - offset, err := f.Seek(0, io.SeekCurrent) - if err != nil { - return nil, err - } - return newEncoder(f, prevCrc, int(offset)), nil -} - -func (e *encoder) encode(rec *walpb.Record) error { - e.mu.Lock() - defer e.mu.Unlock() - - e.crc.Write(rec.Data) - rec.Crc = e.crc.Sum32() - var ( - data []byte - err error - n int - ) - - if rec.Size() > len(e.buf) { - data, err = rec.Marshal() - if err != nil { - return err - } - } else { - n, err = rec.MarshalTo(e.buf) - if err != nil { - return err - } - data = e.buf[:n] - } - - lenField, padBytes := encodeFrameSize(len(data)) - if err = writeUint64(e.bw, lenField, e.uint64buf); err != nil { - return err - } - - if padBytes != 0 { - data = append(data, make([]byte, padBytes)...) - } - _, err = e.bw.Write(data) - return err -} - -func encodeFrameSize(dataBytes int) (lenField uint64, padBytes int) { - lenField = uint64(dataBytes) - // force 8 byte alignment so length never gets a torn write - padBytes = (8 - (dataBytes % 8)) % 8 - if padBytes != 0 { - lenField |= uint64(0x80|padBytes) << 56 - } - return lenField, padBytes -} - -func (e *encoder) flush() error { - e.mu.Lock() - defer e.mu.Unlock() - return e.bw.Flush() -} - -func writeUint64(w io.Writer, n uint64, buf []byte) error { - // http://golang.org/src/encoding/binary/binary.go - binary.LittleEndian.PutUint64(buf, n) - _, err := w.Write(buf) - return err -} diff --git a/vendor/github.com/coreos/etcd/wal/file_pipeline.go b/vendor/github.com/coreos/etcd/wal/file_pipeline.go deleted file mode 100644 index 3a1c57c1c960..000000000000 --- a/vendor/github.com/coreos/etcd/wal/file_pipeline.go +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import ( - "fmt" - "os" - "path/filepath" - - "github.com/coreos/etcd/pkg/fileutil" -) - -// filePipeline pipelines allocating disk space -type filePipeline struct { - // dir to put files - dir string - // size of files to make, in bytes - size int64 - // count number of files generated - count int - - filec chan *fileutil.LockedFile - errc chan error - donec chan struct{} -} - -func newFilePipeline(dir string, fileSize int64) *filePipeline { - fp := &filePipeline{ - dir: dir, - size: fileSize, - filec: make(chan *fileutil.LockedFile), - errc: make(chan error, 1), - donec: make(chan struct{}), - } - go fp.run() - return fp -} - -// Open returns a fresh file for writing. Rename the file before calling -// Open again or there will be file collisions. -func (fp *filePipeline) Open() (f *fileutil.LockedFile, err error) { - select { - case f = <-fp.filec: - case err = <-fp.errc: - } - return f, err -} - -func (fp *filePipeline) Close() error { - close(fp.donec) - return <-fp.errc -} - -func (fp *filePipeline) alloc() (f *fileutil.LockedFile, err error) { - // count % 2 so this file isn't the same as the one last published - fpath := filepath.Join(fp.dir, fmt.Sprintf("%d.tmp", fp.count%2)) - if f, err = fileutil.LockFile(fpath, os.O_CREATE|os.O_WRONLY, fileutil.PrivateFileMode); err != nil { - return nil, err - } - if err = fileutil.Preallocate(f.File, fp.size, true); err != nil { - plog.Errorf("failed to allocate space when creating new wal file (%v)", err) - f.Close() - return nil, err - } - fp.count++ - return f, nil -} - -func (fp *filePipeline) run() { - defer close(fp.errc) - for { - f, err := fp.alloc() - if err != nil { - fp.errc <- err - return - } - select { - case fp.filec <- f: - case <-fp.donec: - os.Remove(f.Name()) - f.Close() - return - } - } -} diff --git a/vendor/github.com/coreos/etcd/wal/metrics.go b/vendor/github.com/coreos/etcd/wal/metrics.go deleted file mode 100644 index 9e089d380f9b..000000000000 --- a/vendor/github.com/coreos/etcd/wal/metrics.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import "github.com/prometheus/client_golang/prometheus" - -var ( - syncDurations = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "disk", - Name: "wal_fsync_duration_seconds", - Help: "The latency distributions of fsync called by wal.", - Buckets: prometheus.ExponentialBuckets(0.001, 2, 14), - }) -) - -func init() { - prometheus.MustRegister(syncDurations) -} diff --git a/vendor/github.com/coreos/etcd/wal/repair.go b/vendor/github.com/coreos/etcd/wal/repair.go deleted file mode 100644 index 091036b57b9a..000000000000 --- a/vendor/github.com/coreos/etcd/wal/repair.go +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import ( - "io" - "os" - "path/filepath" - - "github.com/coreos/etcd/pkg/fileutil" - "github.com/coreos/etcd/wal/walpb" -) - -// Repair tries to repair ErrUnexpectedEOF in the -// last wal file by truncating. -func Repair(dirpath string) bool { - f, err := openLast(dirpath) - if err != nil { - return false - } - defer f.Close() - - rec := &walpb.Record{} - decoder := newDecoder(f) - for { - lastOffset := decoder.lastOffset() - err := decoder.decode(rec) - switch err { - case nil: - // update crc of the decoder when necessary - switch rec.Type { - case crcType: - crc := decoder.crc.Sum32() - // current crc of decoder must match the crc of the record. - // do no need to match 0 crc, since the decoder is a new one at this case. - if crc != 0 && rec.Validate(crc) != nil { - return false - } - decoder.updateCRC(rec.Crc) - } - continue - case io.EOF: - return true - case io.ErrUnexpectedEOF: - plog.Noticef("repairing %v", f.Name()) - bf, bferr := os.Create(f.Name() + ".broken") - if bferr != nil { - plog.Errorf("could not repair %v, failed to create backup file", f.Name()) - return false - } - defer bf.Close() - - if _, err = f.Seek(0, io.SeekStart); err != nil { - plog.Errorf("could not repair %v, failed to read file", f.Name()) - return false - } - - if _, err = io.Copy(bf, f); err != nil { - plog.Errorf("could not repair %v, failed to copy file", f.Name()) - return false - } - - if err = f.Truncate(int64(lastOffset)); err != nil { - plog.Errorf("could not repair %v, failed to truncate file", f.Name()) - return false - } - if err = fileutil.Fsync(f.File); err != nil { - plog.Errorf("could not repair %v, failed to sync file", f.Name()) - return false - } - return true - default: - plog.Errorf("could not repair error (%v)", err) - return false - } - } -} - -// openLast opens the last wal file for read and write. -func openLast(dirpath string) (*fileutil.LockedFile, error) { - names, err := readWalNames(dirpath) - if err != nil { - return nil, err - } - last := filepath.Join(dirpath, names[len(names)-1]) - return fileutil.LockFile(last, os.O_RDWR, fileutil.PrivateFileMode) -} diff --git a/vendor/github.com/coreos/etcd/wal/util.go b/vendor/github.com/coreos/etcd/wal/util.go deleted file mode 100644 index 5c56e228872d..000000000000 --- a/vendor/github.com/coreos/etcd/wal/util.go +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import ( - "errors" - "fmt" - "strings" - - "github.com/coreos/etcd/pkg/fileutil" -) - -var ( - badWalName = errors.New("bad wal name") -) - -func Exist(dirpath string) bool { - names, err := fileutil.ReadDir(dirpath) - if err != nil { - return false - } - return len(names) != 0 -} - -// searchIndex returns the last array index of names whose raft index section is -// equal to or smaller than the given index. -// The given names MUST be sorted. -func searchIndex(names []string, index uint64) (int, bool) { - for i := len(names) - 1; i >= 0; i-- { - name := names[i] - _, curIndex, err := parseWalName(name) - if err != nil { - plog.Panicf("parse correct name should never fail: %v", err) - } - if index >= curIndex { - return i, true - } - } - return -1, false -} - -// names should have been sorted based on sequence number. -// isValidSeq checks whether seq increases continuously. -func isValidSeq(names []string) bool { - var lastSeq uint64 - for _, name := range names { - curSeq, _, err := parseWalName(name) - if err != nil { - plog.Panicf("parse correct name should never fail: %v", err) - } - if lastSeq != 0 && lastSeq != curSeq-1 { - return false - } - lastSeq = curSeq - } - return true -} -func readWalNames(dirpath string) ([]string, error) { - names, err := fileutil.ReadDir(dirpath) - if err != nil { - return nil, err - } - wnames := checkWalNames(names) - if len(wnames) == 0 { - return nil, ErrFileNotFound - } - return wnames, nil -} - -func checkWalNames(names []string) []string { - wnames := make([]string, 0) - for _, name := range names { - if _, _, err := parseWalName(name); err != nil { - // don't complain about left over tmp files - if !strings.HasSuffix(name, ".tmp") { - plog.Warningf("ignored file %v in wal", name) - } - continue - } - wnames = append(wnames, name) - } - return wnames -} - -func parseWalName(str string) (seq, index uint64, err error) { - if !strings.HasSuffix(str, ".wal") { - return 0, 0, badWalName - } - _, err = fmt.Sscanf(str, "%016x-%016x.wal", &seq, &index) - return seq, index, err -} - -func walName(seq, index uint64) string { - return fmt.Sprintf("%016x-%016x.wal", seq, index) -} diff --git a/vendor/github.com/coreos/etcd/wal/wal.go b/vendor/github.com/coreos/etcd/wal/wal.go deleted file mode 100644 index ef63b52ccbcd..000000000000 --- a/vendor/github.com/coreos/etcd/wal/wal.go +++ /dev/null @@ -1,772 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import ( - "bytes" - "errors" - "fmt" - "hash/crc32" - "io" - "os" - "path/filepath" - "sync" - "time" - - "github.com/coreos/etcd/pkg/fileutil" - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/raft" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/wal/walpb" - - "github.com/coreos/pkg/capnslog" -) - -const ( - metadataType int64 = iota + 1 - entryType - stateType - crcType - snapshotType - - // warnSyncDuration is the amount of time allotted to an fsync before - // logging a warning - warnSyncDuration = time.Second -) - -var ( - // SegmentSizeBytes is the preallocated size of each wal segment file. - // The actual size might be larger than this. In general, the default - // value should be used, but this is defined as an exported variable - // so that tests can set a different segment size. - SegmentSizeBytes int64 = 64 * 1000 * 1000 // 64MB - - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "wal") - - ErrMetadataConflict = errors.New("wal: conflicting metadata found") - ErrFileNotFound = errors.New("wal: file not found") - ErrCRCMismatch = errors.New("wal: crc mismatch") - ErrSnapshotMismatch = errors.New("wal: snapshot mismatch") - ErrSnapshotNotFound = errors.New("wal: snapshot not found") - crcTable = crc32.MakeTable(crc32.Castagnoli) -) - -// WAL is a logical representation of the stable storage. -// WAL is either in read mode or append mode but not both. -// A newly created WAL is in append mode, and ready for appending records. -// A just opened WAL is in read mode, and ready for reading records. -// The WAL will be ready for appending after reading out all the previous records. -type WAL struct { - dir string // the living directory of the underlay files - - // dirFile is a fd for the wal directory for syncing on Rename - dirFile *os.File - - metadata []byte // metadata recorded at the head of each WAL - state raftpb.HardState // hardstate recorded at the head of WAL - - start walpb.Snapshot // snapshot to start reading - decoder *decoder // decoder to decode records - readClose func() error // closer for decode reader - - mu sync.Mutex - enti uint64 // index of the last entry saved to the wal - encoder *encoder // encoder to encode records - - locks []*fileutil.LockedFile // the locked files the WAL holds (the name is increasing) - fp *filePipeline -} - -// Create creates a WAL ready for appending records. The given metadata is -// recorded at the head of each WAL file, and can be retrieved with ReadAll. -func Create(dirpath string, metadata []byte) (*WAL, error) { - if Exist(dirpath) { - return nil, os.ErrExist - } - - // keep temporary wal directory so WAL initialization appears atomic - tmpdirpath := filepath.Clean(dirpath) + ".tmp" - if fileutil.Exist(tmpdirpath) { - if err := os.RemoveAll(tmpdirpath); err != nil { - return nil, err - } - } - if err := fileutil.CreateDirAll(tmpdirpath); err != nil { - return nil, err - } - - p := filepath.Join(tmpdirpath, walName(0, 0)) - f, err := fileutil.LockFile(p, os.O_WRONLY|os.O_CREATE, fileutil.PrivateFileMode) - if err != nil { - return nil, err - } - if _, err = f.Seek(0, io.SeekEnd); err != nil { - return nil, err - } - if err = fileutil.Preallocate(f.File, SegmentSizeBytes, true); err != nil { - return nil, err - } - - w := &WAL{ - dir: dirpath, - metadata: metadata, - } - w.encoder, err = newFileEncoder(f.File, 0) - if err != nil { - return nil, err - } - w.locks = append(w.locks, f) - if err = w.saveCrc(0); err != nil { - return nil, err - } - if err = w.encoder.encode(&walpb.Record{Type: metadataType, Data: metadata}); err != nil { - return nil, err - } - if err = w.SaveSnapshot(walpb.Snapshot{}); err != nil { - return nil, err - } - - if w, err = w.renameWal(tmpdirpath); err != nil { - return nil, err - } - - // directory was renamed; sync parent dir to persist rename - pdir, perr := fileutil.OpenDir(filepath.Dir(w.dir)) - if perr != nil { - return nil, perr - } - if perr = fileutil.Fsync(pdir); perr != nil { - return nil, perr - } - if perr = pdir.Close(); err != nil { - return nil, perr - } - - return w, nil -} - -func (w *WAL) renameWal(tmpdirpath string) (*WAL, error) { - if err := os.RemoveAll(w.dir); err != nil { - return nil, err - } - // On non-Windows platforms, hold the lock while renaming. Releasing - // the lock and trying to reacquire it quickly can be flaky because - // it's possible the process will fork to spawn a process while this is - // happening. The fds are set up as close-on-exec by the Go runtime, - // but there is a window between the fork and the exec where another - // process holds the lock. - if err := os.Rename(tmpdirpath, w.dir); err != nil { - if _, ok := err.(*os.LinkError); ok { - return w.renameWalUnlock(tmpdirpath) - } - return nil, err - } - w.fp = newFilePipeline(w.dir, SegmentSizeBytes) - df, err := fileutil.OpenDir(w.dir) - w.dirFile = df - return w, err -} - -func (w *WAL) renameWalUnlock(tmpdirpath string) (*WAL, error) { - // rename of directory with locked files doesn't work on windows/cifs; - // close the WAL to release the locks so the directory can be renamed. - plog.Infof("releasing file lock to rename %q to %q", tmpdirpath, w.dir) - w.Close() - if err := os.Rename(tmpdirpath, w.dir); err != nil { - return nil, err - } - // reopen and relock - newWAL, oerr := Open(w.dir, walpb.Snapshot{}) - if oerr != nil { - return nil, oerr - } - if _, _, _, err := newWAL.ReadAll(); err != nil { - newWAL.Close() - return nil, err - } - return newWAL, nil -} - -// Open opens the WAL at the given snap. -// The snap SHOULD have been previously saved to the WAL, or the following -// ReadAll will fail. -// The returned WAL is ready to read and the first record will be the one after -// the given snap. The WAL cannot be appended to before reading out all of its -// previous records. -func Open(dirpath string, snap walpb.Snapshot) (*WAL, error) { - w, err := openAtIndex(dirpath, snap, true) - if err != nil { - return nil, err - } - if w.dirFile, err = fileutil.OpenDir(w.dir); err != nil { - return nil, err - } - return w, nil -} - -// OpenForRead only opens the wal files for read. -// Write on a read only wal panics. -func OpenForRead(dirpath string, snap walpb.Snapshot) (*WAL, error) { - return openAtIndex(dirpath, snap, false) -} - -func openAtIndex(dirpath string, snap walpb.Snapshot, write bool) (*WAL, error) { - names, nameIndex, err := selectWALFiles(dirpath, snap) - if err != nil { - return nil, err - } - - rs, ls, closer, err := openWALFiles(dirpath, names, nameIndex, write) - if err != nil { - return nil, err - } - - // create a WAL ready for reading - w := &WAL{ - dir: dirpath, - start: snap, - decoder: newDecoder(rs...), - readClose: closer, - locks: ls, - } - - if write { - // write reuses the file descriptors from read; don't close so - // WAL can append without dropping the file lock - w.readClose = nil - if _, _, err := parseWalName(filepath.Base(w.tail().Name())); err != nil { - closer() - return nil, err - } - w.fp = newFilePipeline(w.dir, SegmentSizeBytes) - } - - return w, nil -} - -func selectWALFiles(dirpath string, snap walpb.Snapshot) ([]string, int, error) { - names, err := readWalNames(dirpath) - if err != nil { - return nil, -1, err - } - - nameIndex, ok := searchIndex(names, snap.Index) - if !ok || !isValidSeq(names[nameIndex:]) { - err = ErrFileNotFound - return nil, -1, err - } - - return names, nameIndex, nil -} - -func openWALFiles(dirpath string, names []string, nameIndex int, write bool) ([]io.Reader, []*fileutil.LockedFile, func() error, error) { - rcs := make([]io.ReadCloser, 0) - rs := make([]io.Reader, 0) - ls := make([]*fileutil.LockedFile, 0) - for _, name := range names[nameIndex:] { - p := filepath.Join(dirpath, name) - if write { - l, err := fileutil.TryLockFile(p, os.O_RDWR, fileutil.PrivateFileMode) - if err != nil { - closeAll(rcs...) - return nil, nil, nil, err - } - ls = append(ls, l) - rcs = append(rcs, l) - } else { - rf, err := os.OpenFile(p, os.O_RDONLY, fileutil.PrivateFileMode) - if err != nil { - closeAll(rcs...) - return nil, nil, nil, err - } - ls = append(ls, nil) - rcs = append(rcs, rf) - } - rs = append(rs, rcs[len(rcs)-1]) - } - - closer := func() error { return closeAll(rcs...) } - - return rs, ls, closer, nil -} - -// ReadAll reads out records of the current WAL. -// If opened in write mode, it must read out all records until EOF. Or an error -// will be returned. -// If opened in read mode, it will try to read all records if possible. -// If it cannot read out the expected snap, it will return ErrSnapshotNotFound. -// If loaded snap doesn't match with the expected one, it will return -// all the records and error ErrSnapshotMismatch. -// TODO: detect not-last-snap error. -// TODO: maybe loose the checking of match. -// After ReadAll, the WAL will be ready for appending new records. -func (w *WAL) ReadAll() (metadata []byte, state raftpb.HardState, ents []raftpb.Entry, err error) { - w.mu.Lock() - defer w.mu.Unlock() - - rec := &walpb.Record{} - decoder := w.decoder - - var match bool - for err = decoder.decode(rec); err == nil; err = decoder.decode(rec) { - switch rec.Type { - case entryType: - e := mustUnmarshalEntry(rec.Data) - if e.Index > w.start.Index { - ents = append(ents[:e.Index-w.start.Index-1], e) - } - w.enti = e.Index - case stateType: - state = mustUnmarshalState(rec.Data) - case metadataType: - if metadata != nil && !bytes.Equal(metadata, rec.Data) { - state.Reset() - return nil, state, nil, ErrMetadataConflict - } - metadata = rec.Data - case crcType: - crc := decoder.crc.Sum32() - // current crc of decoder must match the crc of the record. - // do no need to match 0 crc, since the decoder is a new one at this case. - if crc != 0 && rec.Validate(crc) != nil { - state.Reset() - return nil, state, nil, ErrCRCMismatch - } - decoder.updateCRC(rec.Crc) - case snapshotType: - var snap walpb.Snapshot - pbutil.MustUnmarshal(&snap, rec.Data) - if snap.Index == w.start.Index { - if snap.Term != w.start.Term { - state.Reset() - return nil, state, nil, ErrSnapshotMismatch - } - match = true - } - default: - state.Reset() - return nil, state, nil, fmt.Errorf("unexpected block type %d", rec.Type) - } - } - - switch w.tail() { - case nil: - // We do not have to read out all entries in read mode. - // The last record maybe a partial written one, so - // ErrunexpectedEOF might be returned. - if err != io.EOF && err != io.ErrUnexpectedEOF { - state.Reset() - return nil, state, nil, err - } - default: - // We must read all of the entries if WAL is opened in write mode. - if err != io.EOF { - state.Reset() - return nil, state, nil, err - } - // decodeRecord() will return io.EOF if it detects a zero record, - // but this zero record may be followed by non-zero records from - // a torn write. Overwriting some of these non-zero records, but - // not all, will cause CRC errors on WAL open. Since the records - // were never fully synced to disk in the first place, it's safe - // to zero them out to avoid any CRC errors from new writes. - if _, err = w.tail().Seek(w.decoder.lastOffset(), io.SeekStart); err != nil { - return nil, state, nil, err - } - if err = fileutil.ZeroToEnd(w.tail().File); err != nil { - return nil, state, nil, err - } - } - - err = nil - if !match { - err = ErrSnapshotNotFound - } - - // close decoder, disable reading - if w.readClose != nil { - w.readClose() - w.readClose = nil - } - w.start = walpb.Snapshot{} - - w.metadata = metadata - - if w.tail() != nil { - // create encoder (chain crc with the decoder), enable appending - w.encoder, err = newFileEncoder(w.tail().File, w.decoder.lastCRC()) - if err != nil { - return - } - } - w.decoder = nil - - return metadata, state, ents, err -} - -// Verify reads through the given WAL and verifies that it is not corrupted. -// It creates a new decoder to read through the records of the given WAL. -// It does not conflict with any open WAL, but it is recommended not to -// call this function after opening the WAL for writing. -// If it cannot read out the expected snap, it will return ErrSnapshotNotFound. -// If the loaded snap doesn't match with the expected one, it will -// return error ErrSnapshotMismatch. -func Verify(walDir string, snap walpb.Snapshot) error { - var metadata []byte - var err error - var match bool - - rec := &walpb.Record{} - - names, nameIndex, err := selectWALFiles(walDir, snap) - if err != nil { - return err - } - - // open wal files in read mode, so that there is no conflict - // when the same WAL is opened elsewhere in write mode - rs, _, closer, err := openWALFiles(walDir, names, nameIndex, false) - if err != nil { - return err - } - - // create a new decoder from the readers on the WAL files - decoder := newDecoder(rs...) - - for err = decoder.decode(rec); err == nil; err = decoder.decode(rec) { - switch rec.Type { - case metadataType: - if metadata != nil && !bytes.Equal(metadata, rec.Data) { - return ErrMetadataConflict - } - metadata = rec.Data - case crcType: - crc := decoder.crc.Sum32() - // Current crc of decoder must match the crc of the record. - // We need not match 0 crc, since the decoder is a new one at this point. - if crc != 0 && rec.Validate(crc) != nil { - return ErrCRCMismatch - } - decoder.updateCRC(rec.Crc) - case snapshotType: - var loadedSnap walpb.Snapshot - pbutil.MustUnmarshal(&loadedSnap, rec.Data) - if loadedSnap.Index == snap.Index { - if loadedSnap.Term != snap.Term { - return ErrSnapshotMismatch - } - match = true - } - // We ignore all entry and state type records as these - // are not necessary for validating the WAL contents - case entryType: - case stateType: - default: - return fmt.Errorf("unexpected block type %d", rec.Type) - } - } - - if closer != nil { - closer() - } - - // We do not have to read out all the WAL entries - // as the decoder is opened in read mode. - if err != io.EOF && err != io.ErrUnexpectedEOF { - return err - } - - if !match { - return ErrSnapshotNotFound - } - - return nil -} - -// cut closes current file written and creates a new one ready to append. -// cut first creates a temp wal file and writes necessary headers into it. -// Then cut atomically rename temp wal file to a wal file. -func (w *WAL) cut() error { - // close old wal file; truncate to avoid wasting space if an early cut - off, serr := w.tail().Seek(0, io.SeekCurrent) - if serr != nil { - return serr - } - if err := w.tail().Truncate(off); err != nil { - return err - } - if err := w.sync(); err != nil { - return err - } - - fpath := filepath.Join(w.dir, walName(w.seq()+1, w.enti+1)) - - // create a temp wal file with name sequence + 1, or truncate the existing one - newTail, err := w.fp.Open() - if err != nil { - return err - } - - // update writer and save the previous crc - w.locks = append(w.locks, newTail) - prevCrc := w.encoder.crc.Sum32() - w.encoder, err = newFileEncoder(w.tail().File, prevCrc) - if err != nil { - return err - } - if err = w.saveCrc(prevCrc); err != nil { - return err - } - if err = w.encoder.encode(&walpb.Record{Type: metadataType, Data: w.metadata}); err != nil { - return err - } - if err = w.saveState(&w.state); err != nil { - return err - } - // atomically move temp wal file to wal file - if err = w.sync(); err != nil { - return err - } - - off, err = w.tail().Seek(0, io.SeekCurrent) - if err != nil { - return err - } - - if err = os.Rename(newTail.Name(), fpath); err != nil { - return err - } - if err = fileutil.Fsync(w.dirFile); err != nil { - return err - } - - // reopen newTail with its new path so calls to Name() match the wal filename format - newTail.Close() - - if newTail, err = fileutil.LockFile(fpath, os.O_WRONLY, fileutil.PrivateFileMode); err != nil { - return err - } - if _, err = newTail.Seek(off, io.SeekStart); err != nil { - return err - } - - w.locks[len(w.locks)-1] = newTail - - prevCrc = w.encoder.crc.Sum32() - w.encoder, err = newFileEncoder(w.tail().File, prevCrc) - if err != nil { - return err - } - - plog.Infof("segmented wal file %v is created", fpath) - return nil -} - -func (w *WAL) sync() error { - if w.encoder != nil { - if err := w.encoder.flush(); err != nil { - return err - } - } - start := time.Now() - err := fileutil.Fdatasync(w.tail().File) - - duration := time.Since(start) - if duration > warnSyncDuration { - plog.Warningf("sync duration of %v, expected less than %v", duration, warnSyncDuration) - } - syncDurations.Observe(duration.Seconds()) - - return err -} - -// ReleaseLockTo releases the locks, which has smaller index than the given index -// except the largest one among them. -// For example, if WAL is holding lock 1,2,3,4,5,6, ReleaseLockTo(4) will release -// lock 1,2 but keep 3. ReleaseLockTo(5) will release 1,2,3 but keep 4. -func (w *WAL) ReleaseLockTo(index uint64) error { - w.mu.Lock() - defer w.mu.Unlock() - - if len(w.locks) == 0 { - return nil - } - - var smaller int - found := false - - for i, l := range w.locks { - _, lockIndex, err := parseWalName(filepath.Base(l.Name())) - if err != nil { - return err - } - if lockIndex >= index { - smaller = i - 1 - found = true - break - } - } - - // if no lock index is greater than the release index, we can - // release lock up to the last one(excluding). - if !found { - smaller = len(w.locks) - 1 - } - - if smaller <= 0 { - return nil - } - - for i := 0; i < smaller; i++ { - if w.locks[i] == nil { - continue - } - w.locks[i].Close() - } - w.locks = w.locks[smaller:] - - return nil -} - -func (w *WAL) Close() error { - w.mu.Lock() - defer w.mu.Unlock() - - if w.fp != nil { - w.fp.Close() - w.fp = nil - } - - if w.tail() != nil { - if err := w.sync(); err != nil { - return err - } - } - for _, l := range w.locks { - if l == nil { - continue - } - if err := l.Close(); err != nil { - plog.Errorf("failed to unlock during closing wal: %s", err) - } - } - - return w.dirFile.Close() -} - -func (w *WAL) saveEntry(e *raftpb.Entry) error { - // TODO: add MustMarshalTo to reduce one allocation. - b := pbutil.MustMarshal(e) - rec := &walpb.Record{Type: entryType, Data: b} - if err := w.encoder.encode(rec); err != nil { - return err - } - w.enti = e.Index - return nil -} - -func (w *WAL) saveState(s *raftpb.HardState) error { - if raft.IsEmptyHardState(*s) { - return nil - } - w.state = *s - b := pbutil.MustMarshal(s) - rec := &walpb.Record{Type: stateType, Data: b} - return w.encoder.encode(rec) -} - -func (w *WAL) Save(st raftpb.HardState, ents []raftpb.Entry) error { - w.mu.Lock() - defer w.mu.Unlock() - - // short cut, do not call sync - if raft.IsEmptyHardState(st) && len(ents) == 0 { - return nil - } - - mustSync := raft.MustSync(st, w.state, len(ents)) - - // TODO(xiangli): no more reference operator - for i := range ents { - if err := w.saveEntry(&ents[i]); err != nil { - return err - } - } - if err := w.saveState(&st); err != nil { - return err - } - - curOff, err := w.tail().Seek(0, io.SeekCurrent) - if err != nil { - return err - } - if curOff < SegmentSizeBytes { - if mustSync { - return w.sync() - } - return nil - } - - return w.cut() -} - -func (w *WAL) SaveSnapshot(e walpb.Snapshot) error { - b := pbutil.MustMarshal(&e) - - w.mu.Lock() - defer w.mu.Unlock() - - rec := &walpb.Record{Type: snapshotType, Data: b} - if err := w.encoder.encode(rec); err != nil { - return err - } - // update enti only when snapshot is ahead of last index - if w.enti < e.Index { - w.enti = e.Index - } - return w.sync() -} - -func (w *WAL) saveCrc(prevCrc uint32) error { - return w.encoder.encode(&walpb.Record{Type: crcType, Crc: prevCrc}) -} - -func (w *WAL) tail() *fileutil.LockedFile { - if len(w.locks) > 0 { - return w.locks[len(w.locks)-1] - } - return nil -} - -func (w *WAL) seq() uint64 { - t := w.tail() - if t == nil { - return 0 - } - seq, _, err := parseWalName(filepath.Base(t.Name())) - if err != nil { - plog.Fatalf("bad wal name %s (%v)", t.Name(), err) - } - return seq -} - -func closeAll(rcs ...io.ReadCloser) error { - for _, f := range rcs { - if err := f.Close(); err != nil { - return err - } - } - return nil -} diff --git a/vendor/github.com/coreos/etcd/wal/walpb/record.go b/vendor/github.com/coreos/etcd/wal/walpb/record.go deleted file mode 100644 index 30a05e0c139c..000000000000 --- a/vendor/github.com/coreos/etcd/wal/walpb/record.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package walpb - -import "errors" - -var ( - ErrCRCMismatch = errors.New("walpb: crc mismatch") -) - -func (rec *Record) Validate(crc uint32) error { - if rec.Crc == crc { - return nil - } - rec.Reset() - return ErrCRCMismatch -} diff --git a/vendor/github.com/coreos/etcd/wal/walpb/record.pb.go b/vendor/github.com/coreos/etcd/wal/walpb/record.pb.go deleted file mode 100644 index 3ce63ddc2eb6..000000000000 --- a/vendor/github.com/coreos/etcd/wal/walpb/record.pb.go +++ /dev/null @@ -1,504 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: record.proto - -/* - Package walpb is a generated protocol buffer package. - - It is generated from these files: - record.proto - - It has these top-level messages: - Record - Snapshot -*/ -package walpb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type Record struct { - Type int64 `protobuf:"varint,1,opt,name=type" json:"type"` - Crc uint32 `protobuf:"varint,2,opt,name=crc" json:"crc"` - Data []byte `protobuf:"bytes,3,opt,name=data" json:"data,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Record) Reset() { *m = Record{} } -func (m *Record) String() string { return proto.CompactTextString(m) } -func (*Record) ProtoMessage() {} -func (*Record) Descriptor() ([]byte, []int) { return fileDescriptorRecord, []int{0} } - -type Snapshot struct { - Index uint64 `protobuf:"varint,1,opt,name=index" json:"index"` - Term uint64 `protobuf:"varint,2,opt,name=term" json:"term"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Snapshot) Reset() { *m = Snapshot{} } -func (m *Snapshot) String() string { return proto.CompactTextString(m) } -func (*Snapshot) ProtoMessage() {} -func (*Snapshot) Descriptor() ([]byte, []int) { return fileDescriptorRecord, []int{1} } - -func init() { - proto.RegisterType((*Record)(nil), "walpb.Record") - proto.RegisterType((*Snapshot)(nil), "walpb.Snapshot") -} -func (m *Record) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Record) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRecord(dAtA, i, uint64(m.Type)) - dAtA[i] = 0x10 - i++ - i = encodeVarintRecord(dAtA, i, uint64(m.Crc)) - if m.Data != nil { - dAtA[i] = 0x1a - i++ - i = encodeVarintRecord(dAtA, i, uint64(len(m.Data))) - i += copy(dAtA[i:], m.Data) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *Snapshot) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Snapshot) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRecord(dAtA, i, uint64(m.Index)) - dAtA[i] = 0x10 - i++ - i = encodeVarintRecord(dAtA, i, uint64(m.Term)) - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func encodeVarintRecord(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *Record) Size() (n int) { - var l int - _ = l - n += 1 + sovRecord(uint64(m.Type)) - n += 1 + sovRecord(uint64(m.Crc)) - if m.Data != nil { - l = len(m.Data) - n += 1 + l + sovRecord(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *Snapshot) Size() (n int) { - var l int - _ = l - n += 1 + sovRecord(uint64(m.Index)) - n += 1 + sovRecord(uint64(m.Term)) - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func sovRecord(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozRecord(x uint64) (n int) { - return sovRecord(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Record) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Record: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Record: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Crc", wireType) - } - m.Crc = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Crc |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRecord - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRecord(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRecord - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Snapshot) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Snapshot: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Snapshot: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) - } - m.Index = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Index |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType) - } - m.Term = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Term |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRecord(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRecord - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipRecord(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRecord - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRecord - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRecord - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthRecord - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRecord - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipRecord(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthRecord = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowRecord = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("record.proto", fileDescriptorRecord) } - -var fileDescriptorRecord = []byte{ - // 186 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x29, 0x4a, 0x4d, 0xce, - 0x2f, 0x4a, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x2d, 0x4f, 0xcc, 0x29, 0x48, 0x92, - 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x8b, 0xe8, 0x83, 0x58, 0x10, 0x49, 0x25, 0x3f, 0x2e, 0xb6, - 0x20, 0xb0, 0x62, 0x21, 0x09, 0x2e, 0x96, 0x92, 0xca, 0x82, 0x54, 0x09, 0x46, 0x05, 0x46, 0x0d, - 0x66, 0x27, 0x96, 0x13, 0xf7, 0xe4, 0x19, 0x82, 0xc0, 0x22, 0x42, 0x62, 0x5c, 0xcc, 0xc9, 0x45, - 0xc9, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0xbc, 0x50, 0x09, 0x90, 0x80, 0x90, 0x10, 0x17, 0x4b, 0x4a, - 0x62, 0x49, 0xa2, 0x04, 0xb3, 0x02, 0xa3, 0x06, 0x4f, 0x10, 0x98, 0xad, 0xe4, 0xc0, 0xc5, 0x11, - 0x9c, 0x97, 0x58, 0x50, 0x9c, 0x91, 0x5f, 0x22, 0x24, 0xc5, 0xc5, 0x9a, 0x99, 0x97, 0x92, 0x5a, - 0x01, 0x36, 0x92, 0x05, 0xaa, 0x13, 0x22, 0x04, 0xb6, 0x2d, 0xb5, 0x28, 0x17, 0x6c, 0x28, 0x0b, - 0xdc, 0xb6, 0xd4, 0xa2, 0x5c, 0x27, 0x91, 0x13, 0x0f, 0xe5, 0x18, 0x4e, 0x3c, 0x92, 0x63, 0xbc, - 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x19, 0x8f, 0xe5, 0x18, 0x00, 0x01, 0x00, 0x00, - 0xff, 0xff, 0x7f, 0x5e, 0x5c, 0x46, 0xd3, 0x00, 0x00, 0x00, -} diff --git a/vendor/go.etcd.io/etcd/LICENSE b/vendor/go.etcd.io/etcd/LICENSE deleted file mode 100644 index d64569567334..000000000000 --- a/vendor/go.etcd.io/etcd/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/go.etcd.io/etcd/NOTICE b/vendor/go.etcd.io/etcd/NOTICE deleted file mode 100644 index b39ddfa5cbde..000000000000 --- a/vendor/go.etcd.io/etcd/NOTICE +++ /dev/null @@ -1,5 +0,0 @@ -CoreOS Project -Copyright 2014 CoreOS, Inc - -This product includes software developed at CoreOS, Inc. -(http://www.coreos.com/). diff --git a/vendor/go.etcd.io/etcd/auth/authpb/auth.pb.go b/vendor/go.etcd.io/etcd/auth/authpb/auth.pb.go deleted file mode 100644 index 1a940c39b26e..000000000000 --- a/vendor/go.etcd.io/etcd/auth/authpb/auth.pb.go +++ /dev/null @@ -1,807 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: auth.proto - -/* - Package authpb is a generated protocol buffer package. - - It is generated from these files: - auth.proto - - It has these top-level messages: - User - Permission - Role -*/ -package authpb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type Permission_Type int32 - -const ( - READ Permission_Type = 0 - WRITE Permission_Type = 1 - READWRITE Permission_Type = 2 -) - -var Permission_Type_name = map[int32]string{ - 0: "READ", - 1: "WRITE", - 2: "READWRITE", -} -var Permission_Type_value = map[string]int32{ - "READ": 0, - "WRITE": 1, - "READWRITE": 2, -} - -func (x Permission_Type) String() string { - return proto.EnumName(Permission_Type_name, int32(x)) -} -func (Permission_Type) EnumDescriptor() ([]byte, []int) { return fileDescriptorAuth, []int{1, 0} } - -// User is a single entry in the bucket authUsers -type User struct { - Name []byte `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Password []byte `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` - Roles []string `protobuf:"bytes,3,rep,name=roles" json:"roles,omitempty"` -} - -func (m *User) Reset() { *m = User{} } -func (m *User) String() string { return proto.CompactTextString(m) } -func (*User) ProtoMessage() {} -func (*User) Descriptor() ([]byte, []int) { return fileDescriptorAuth, []int{0} } - -// Permission is a single entity -type Permission struct { - PermType Permission_Type `protobuf:"varint,1,opt,name=permType,proto3,enum=authpb.Permission_Type" json:"permType,omitempty"` - Key []byte `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` - RangeEnd []byte `protobuf:"bytes,3,opt,name=range_end,json=rangeEnd,proto3" json:"range_end,omitempty"` -} - -func (m *Permission) Reset() { *m = Permission{} } -func (m *Permission) String() string { return proto.CompactTextString(m) } -func (*Permission) ProtoMessage() {} -func (*Permission) Descriptor() ([]byte, []int) { return fileDescriptorAuth, []int{1} } - -// Role is a single entry in the bucket authRoles -type Role struct { - Name []byte `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - KeyPermission []*Permission `protobuf:"bytes,2,rep,name=keyPermission" json:"keyPermission,omitempty"` -} - -func (m *Role) Reset() { *m = Role{} } -func (m *Role) String() string { return proto.CompactTextString(m) } -func (*Role) ProtoMessage() {} -func (*Role) Descriptor() ([]byte, []int) { return fileDescriptorAuth, []int{2} } - -func init() { - proto.RegisterType((*User)(nil), "authpb.User") - proto.RegisterType((*Permission)(nil), "authpb.Permission") - proto.RegisterType((*Role)(nil), "authpb.Role") - proto.RegisterEnum("authpb.Permission_Type", Permission_Type_name, Permission_Type_value) -} -func (m *User) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *User) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintAuth(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.Password) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintAuth(dAtA, i, uint64(len(m.Password))) - i += copy(dAtA[i:], m.Password) - } - if len(m.Roles) > 0 { - for _, s := range m.Roles { - dAtA[i] = 0x1a - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - return i, nil -} - -func (m *Permission) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Permission) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.PermType != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintAuth(dAtA, i, uint64(m.PermType)) - } - if len(m.Key) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintAuth(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - if len(m.RangeEnd) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintAuth(dAtA, i, uint64(len(m.RangeEnd))) - i += copy(dAtA[i:], m.RangeEnd) - } - return i, nil -} - -func (m *Role) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Role) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintAuth(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.KeyPermission) > 0 { - for _, msg := range m.KeyPermission { - dAtA[i] = 0x12 - i++ - i = encodeVarintAuth(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func encodeVarintAuth(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *User) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovAuth(uint64(l)) - } - l = len(m.Password) - if l > 0 { - n += 1 + l + sovAuth(uint64(l)) - } - if len(m.Roles) > 0 { - for _, s := range m.Roles { - l = len(s) - n += 1 + l + sovAuth(uint64(l)) - } - } - return n -} - -func (m *Permission) Size() (n int) { - var l int - _ = l - if m.PermType != 0 { - n += 1 + sovAuth(uint64(m.PermType)) - } - l = len(m.Key) - if l > 0 { - n += 1 + l + sovAuth(uint64(l)) - } - l = len(m.RangeEnd) - if l > 0 { - n += 1 + l + sovAuth(uint64(l)) - } - return n -} - -func (m *Role) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovAuth(uint64(l)) - } - if len(m.KeyPermission) > 0 { - for _, e := range m.KeyPermission { - l = e.Size() - n += 1 + l + sovAuth(uint64(l)) - } - } - return n -} - -func sovAuth(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozAuth(x uint64) (n int) { - return sovAuth(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *User) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: User: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: User: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthAuth - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = append(m.Name[:0], dAtA[iNdEx:postIndex]...) - if m.Name == nil { - m.Name = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Password", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthAuth - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Password = append(m.Password[:0], dAtA[iNdEx:postIndex]...) - if m.Password == nil { - m.Password = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Roles", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthAuth - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Roles = append(m.Roles, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipAuth(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthAuth - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Permission) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Permission: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Permission: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PermType", wireType) - } - m.PermType = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.PermType |= (Permission_Type(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthAuth - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RangeEnd", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthAuth - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RangeEnd = append(m.RangeEnd[:0], dAtA[iNdEx:postIndex]...) - if m.RangeEnd == nil { - m.RangeEnd = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipAuth(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthAuth - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Role) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Role: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Role: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthAuth - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = append(m.Name[:0], dAtA[iNdEx:postIndex]...) - if m.Name == nil { - m.Name = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field KeyPermission", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthAuth - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.KeyPermission = append(m.KeyPermission, &Permission{}) - if err := m.KeyPermission[len(m.KeyPermission)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipAuth(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthAuth - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipAuth(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowAuth - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowAuth - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowAuth - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthAuth - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowAuth - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipAuth(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthAuth = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowAuth = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("auth.proto", fileDescriptorAuth) } - -var fileDescriptorAuth = []byte{ - // 288 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0xc1, 0x4a, 0xc3, 0x30, - 0x1c, 0xc6, 0x9b, 0xb6, 0x1b, 0xed, 0x5f, 0x27, 0x25, 0x0c, 0x0c, 0x13, 0x42, 0xe9, 0xa9, 0x78, - 0xa8, 0xb0, 0x5d, 0xbc, 0x2a, 0xf6, 0x20, 0x78, 0x90, 0x50, 0xf1, 0x28, 0x1d, 0x0d, 0x75, 0x6c, - 0x6d, 0x4a, 0x32, 0x91, 0xbe, 0x89, 0x07, 0x1f, 0x68, 0xc7, 0x3d, 0x82, 0xab, 0x2f, 0x22, 0x4d, - 0x64, 0x43, 0xdc, 0xed, 0xfb, 0xbe, 0xff, 0x97, 0xe4, 0x97, 0x3f, 0x40, 0xfe, 0xb6, 0x7e, 0x4d, - 0x1a, 0x29, 0xd6, 0x02, 0x0f, 0x7b, 0xdd, 0xcc, 0x27, 0xe3, 0x52, 0x94, 0x42, 0x47, 0x57, 0xbd, - 0x32, 0xd3, 0xe8, 0x01, 0xdc, 0x27, 0xc5, 0x25, 0xc6, 0xe0, 0xd6, 0x79, 0xc5, 0x09, 0x0a, 0x51, - 0x7c, 0xca, 0xb4, 0xc6, 0x13, 0xf0, 0x9a, 0x5c, 0xa9, 0x77, 0x21, 0x0b, 0x62, 0xeb, 0x7c, 0xef, - 0xf1, 0x18, 0x06, 0x52, 0xac, 0xb8, 0x22, 0x4e, 0xe8, 0xc4, 0x3e, 0x33, 0x26, 0xfa, 0x44, 0x00, - 0x8f, 0x5c, 0x56, 0x0b, 0xa5, 0x16, 0xa2, 0xc6, 0x33, 0xf0, 0x1a, 0x2e, 0xab, 0xac, 0x6d, 0xcc, - 0xc5, 0x67, 0xd3, 0xf3, 0xc4, 0xd0, 0x24, 0x87, 0x56, 0xd2, 0x8f, 0xd9, 0xbe, 0x88, 0x03, 0x70, - 0x96, 0xbc, 0xfd, 0x7d, 0xb0, 0x97, 0xf8, 0x02, 0x7c, 0x99, 0xd7, 0x25, 0x7f, 0xe1, 0x75, 0x41, - 0x1c, 0x03, 0xa2, 0x83, 0xb4, 0x2e, 0xa2, 0x4b, 0x70, 0xf5, 0x31, 0x0f, 0x5c, 0x96, 0xde, 0xdc, - 0x05, 0x16, 0xf6, 0x61, 0xf0, 0xcc, 0xee, 0xb3, 0x34, 0x40, 0x78, 0x04, 0x7e, 0x1f, 0x1a, 0x6b, - 0x47, 0x19, 0xb8, 0x4c, 0xac, 0xf8, 0xd1, 0xcf, 0x5e, 0xc3, 0x68, 0xc9, 0xdb, 0x03, 0x16, 0xb1, - 0x43, 0x27, 0x3e, 0x99, 0xe2, 0xff, 0xc0, 0xec, 0x6f, 0xf1, 0x96, 0x6c, 0x76, 0xd4, 0xda, 0xee, - 0xa8, 0xb5, 0xe9, 0x28, 0xda, 0x76, 0x14, 0x7d, 0x75, 0x14, 0x7d, 0x7c, 0x53, 0x6b, 0x3e, 0xd4, - 0x3b, 0x9e, 0xfd, 0x04, 0x00, 0x00, 0xff, 0xff, 0xcc, 0x76, 0x8d, 0x4f, 0x8f, 0x01, 0x00, 0x00, -} diff --git a/vendor/go.etcd.io/etcd/auth/doc.go b/vendor/go.etcd.io/etcd/auth/doc.go deleted file mode 100644 index 72741a107745..000000000000 --- a/vendor/go.etcd.io/etcd/auth/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package auth provides client role authentication for accessing keys in etcd. -package auth diff --git a/vendor/go.etcd.io/etcd/auth/jwt.go b/vendor/go.etcd.io/etcd/auth/jwt.go deleted file mode 100644 index 99b2d6b5c714..000000000000 --- a/vendor/go.etcd.io/etcd/auth/jwt.go +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth - -import ( - "context" - "crypto/rsa" - "io/ioutil" - - jwt "github.com/dgrijalva/jwt-go" -) - -type tokenJWT struct { - signMethod string - signKey *rsa.PrivateKey - verifyKey *rsa.PublicKey -} - -func (t *tokenJWT) enable() {} -func (t *tokenJWT) disable() {} -func (t *tokenJWT) invalidateUser(string) {} -func (t *tokenJWT) genTokenPrefix() (string, error) { return "", nil } - -func (t *tokenJWT) info(ctx context.Context, token string, rev uint64) (*AuthInfo, bool) { - // rev isn't used in JWT, it is only used in simple token - var ( - username string - revision uint64 - ) - - parsed, err := jwt.Parse(token, func(token *jwt.Token) (interface{}, error) { - return t.verifyKey, nil - }) - - switch err.(type) { - case nil: - if !parsed.Valid { - plog.Warningf("invalid jwt token: %s", token) - return nil, false - } - - claims := parsed.Claims.(jwt.MapClaims) - - username = claims["username"].(string) - revision = uint64(claims["revision"].(float64)) - default: - plog.Warningf("failed to parse jwt token: %s", err) - return nil, false - } - - return &AuthInfo{Username: username, Revision: revision}, true -} - -func (t *tokenJWT) assign(ctx context.Context, username string, revision uint64) (string, error) { - // Future work: let a jwt token include permission information would be useful for - // permission checking in proxy side. - tk := jwt.NewWithClaims(jwt.GetSigningMethod(t.signMethod), - jwt.MapClaims{ - "username": username, - "revision": revision, - }) - - token, err := tk.SignedString(t.signKey) - if err != nil { - plog.Debugf("failed to sign jwt token: %s", err) - return "", err - } - - plog.Debugf("jwt token: %s", token) - - return token, err -} - -func prepareOpts(opts map[string]string) (jwtSignMethod, jwtPubKeyPath, jwtPrivKeyPath string, err error) { - for k, v := range opts { - switch k { - case "sign-method": - jwtSignMethod = v - case "pub-key": - jwtPubKeyPath = v - case "priv-key": - jwtPrivKeyPath = v - default: - plog.Errorf("unknown token specific option: %s", k) - return "", "", "", ErrInvalidAuthOpts - } - } - if len(jwtSignMethod) == 0 { - return "", "", "", ErrInvalidAuthOpts - } - return jwtSignMethod, jwtPubKeyPath, jwtPrivKeyPath, nil -} - -func newTokenProviderJWT(opts map[string]string) (*tokenJWT, error) { - jwtSignMethod, jwtPubKeyPath, jwtPrivKeyPath, err := prepareOpts(opts) - if err != nil { - return nil, ErrInvalidAuthOpts - } - - t := &tokenJWT{} - - t.signMethod = jwtSignMethod - - verifyBytes, err := ioutil.ReadFile(jwtPubKeyPath) - if err != nil { - plog.Errorf("failed to read public key (%s) for jwt: %s", jwtPubKeyPath, err) - return nil, err - } - t.verifyKey, err = jwt.ParseRSAPublicKeyFromPEM(verifyBytes) - if err != nil { - plog.Errorf("failed to parse public key (%s): %s", jwtPubKeyPath, err) - return nil, err - } - - signBytes, err := ioutil.ReadFile(jwtPrivKeyPath) - if err != nil { - plog.Errorf("failed to read private key (%s) for jwt: %s", jwtPrivKeyPath, err) - return nil, err - } - t.signKey, err = jwt.ParseRSAPrivateKeyFromPEM(signBytes) - if err != nil { - plog.Errorf("failed to parse private key (%s): %s", jwtPrivKeyPath, err) - return nil, err - } - - return t, nil -} diff --git a/vendor/go.etcd.io/etcd/auth/nop.go b/vendor/go.etcd.io/etcd/auth/nop.go deleted file mode 100644 index d4378747bd8b..000000000000 --- a/vendor/go.etcd.io/etcd/auth/nop.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth - -import ( - "context" -) - -type tokenNop struct{} - -func (t *tokenNop) enable() {} -func (t *tokenNop) disable() {} -func (t *tokenNop) invalidateUser(string) {} -func (t *tokenNop) genTokenPrefix() (string, error) { return "", nil } -func (t *tokenNop) info(ctx context.Context, token string, rev uint64) (*AuthInfo, bool) { - return nil, false -} -func (t *tokenNop) assign(ctx context.Context, username string, revision uint64) (string, error) { - return "", ErrAuthFailed -} -func newTokenProviderNop() (*tokenNop, error) { - return &tokenNop{}, nil -} diff --git a/vendor/go.etcd.io/etcd/auth/range_perm_cache.go b/vendor/go.etcd.io/etcd/auth/range_perm_cache.go deleted file mode 100644 index 691b65ba38e7..000000000000 --- a/vendor/go.etcd.io/etcd/auth/range_perm_cache.go +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth - -import ( - "github.com/coreos/etcd/auth/authpb" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/pkg/adt" -) - -func getMergedPerms(tx backend.BatchTx, userName string) *unifiedRangePermissions { - user := getUser(tx, userName) - if user == nil { - plog.Errorf("invalid user name %s", userName) - return nil - } - - readPerms := &adt.IntervalTree{} - writePerms := &adt.IntervalTree{} - - for _, roleName := range user.Roles { - role := getRole(tx, roleName) - if role == nil { - continue - } - - for _, perm := range role.KeyPermission { - var ivl adt.Interval - var rangeEnd []byte - - if len(perm.RangeEnd) != 1 || perm.RangeEnd[0] != 0 { - rangeEnd = perm.RangeEnd - } - - if len(perm.RangeEnd) != 0 { - ivl = adt.NewBytesAffineInterval(perm.Key, rangeEnd) - } else { - ivl = adt.NewBytesAffinePoint(perm.Key) - } - - switch perm.PermType { - case authpb.READWRITE: - readPerms.Insert(ivl, struct{}{}) - writePerms.Insert(ivl, struct{}{}) - - case authpb.READ: - readPerms.Insert(ivl, struct{}{}) - - case authpb.WRITE: - writePerms.Insert(ivl, struct{}{}) - } - } - } - - return &unifiedRangePermissions{ - readPerms: readPerms, - writePerms: writePerms, - } -} - -func checkKeyInterval(cachedPerms *unifiedRangePermissions, key, rangeEnd []byte, permtyp authpb.Permission_Type) bool { - if len(rangeEnd) == 1 && rangeEnd[0] == 0 { - rangeEnd = nil - } - - ivl := adt.NewBytesAffineInterval(key, rangeEnd) - switch permtyp { - case authpb.READ: - return cachedPerms.readPerms.Contains(ivl) - case authpb.WRITE: - return cachedPerms.writePerms.Contains(ivl) - default: - plog.Panicf("unknown auth type: %v", permtyp) - } - return false -} - -func checkKeyPoint(cachedPerms *unifiedRangePermissions, key []byte, permtyp authpb.Permission_Type) bool { - pt := adt.NewBytesAffinePoint(key) - switch permtyp { - case authpb.READ: - return cachedPerms.readPerms.Intersects(pt) - case authpb.WRITE: - return cachedPerms.writePerms.Intersects(pt) - default: - plog.Panicf("unknown auth type: %v", permtyp) - } - return false -} - -func (as *authStore) isRangeOpPermitted(tx backend.BatchTx, userName string, key, rangeEnd []byte, permtyp authpb.Permission_Type) bool { - // assumption: tx is Lock()ed - _, ok := as.rangePermCache[userName] - if !ok { - perms := getMergedPerms(tx, userName) - if perms == nil { - plog.Errorf("failed to create a unified permission of user %s", userName) - return false - } - as.rangePermCache[userName] = perms - } - - if len(rangeEnd) == 0 { - return checkKeyPoint(as.rangePermCache[userName], key, permtyp) - } - - return checkKeyInterval(as.rangePermCache[userName], key, rangeEnd, permtyp) -} - -func (as *authStore) clearCachedPerm() { - as.rangePermCache = make(map[string]*unifiedRangePermissions) -} - -func (as *authStore) invalidateCachedPerm(userName string) { - delete(as.rangePermCache, userName) -} - -type unifiedRangePermissions struct { - readPerms *adt.IntervalTree - writePerms *adt.IntervalTree -} diff --git a/vendor/go.etcd.io/etcd/auth/simple_token.go b/vendor/go.etcd.io/etcd/auth/simple_token.go deleted file mode 100644 index ac55ad7f13fc..000000000000 --- a/vendor/go.etcd.io/etcd/auth/simple_token.go +++ /dev/null @@ -1,223 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth - -// CAUTION: This randum number based token mechanism is only for testing purpose. -// JWT based mechanism will be added in the near future. - -import ( - "context" - "crypto/rand" - "fmt" - "math/big" - "strconv" - "strings" - "sync" - "time" -) - -const ( - letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" - defaultSimpleTokenLength = 16 -) - -// var for testing purposes -var ( - simpleTokenTTL = 5 * time.Minute - simpleTokenTTLResolution = 1 * time.Second -) - -type simpleTokenTTLKeeper struct { - tokens map[string]time.Time - donec chan struct{} - stopc chan struct{} - deleteTokenFunc func(string) - mu *sync.Mutex -} - -func (tm *simpleTokenTTLKeeper) stop() { - select { - case tm.stopc <- struct{}{}: - case <-tm.donec: - } - <-tm.donec -} - -func (tm *simpleTokenTTLKeeper) addSimpleToken(token string) { - tm.tokens[token] = time.Now().Add(simpleTokenTTL) -} - -func (tm *simpleTokenTTLKeeper) resetSimpleToken(token string) { - if _, ok := tm.tokens[token]; ok { - tm.tokens[token] = time.Now().Add(simpleTokenTTL) - } -} - -func (tm *simpleTokenTTLKeeper) deleteSimpleToken(token string) { - delete(tm.tokens, token) -} - -func (tm *simpleTokenTTLKeeper) run() { - tokenTicker := time.NewTicker(simpleTokenTTLResolution) - defer func() { - tokenTicker.Stop() - close(tm.donec) - }() - for { - select { - case <-tokenTicker.C: - nowtime := time.Now() - tm.mu.Lock() - for t, tokenendtime := range tm.tokens { - if nowtime.After(tokenendtime) { - tm.deleteTokenFunc(t) - delete(tm.tokens, t) - } - } - tm.mu.Unlock() - case <-tm.stopc: - return - } - } -} - -type tokenSimple struct { - indexWaiter func(uint64) <-chan struct{} - simpleTokenKeeper *simpleTokenTTLKeeper - simpleTokensMu sync.Mutex - simpleTokens map[string]string // token -> username -} - -func (t *tokenSimple) genTokenPrefix() (string, error) { - ret := make([]byte, defaultSimpleTokenLength) - - for i := 0; i < defaultSimpleTokenLength; i++ { - bInt, err := rand.Int(rand.Reader, big.NewInt(int64(len(letters)))) - if err != nil { - return "", err - } - - ret[i] = letters[bInt.Int64()] - } - - return string(ret), nil -} - -func (t *tokenSimple) assignSimpleTokenToUser(username, token string) { - t.simpleTokensMu.Lock() - defer t.simpleTokensMu.Unlock() - if t.simpleTokenKeeper == nil { - return - } - - _, ok := t.simpleTokens[token] - if ok { - plog.Panicf("token %s is alredy used", token) - } - - t.simpleTokens[token] = username - t.simpleTokenKeeper.addSimpleToken(token) -} - -func (t *tokenSimple) invalidateUser(username string) { - if t.simpleTokenKeeper == nil { - return - } - t.simpleTokensMu.Lock() - for token, name := range t.simpleTokens { - if strings.Compare(name, username) == 0 { - delete(t.simpleTokens, token) - t.simpleTokenKeeper.deleteSimpleToken(token) - } - } - t.simpleTokensMu.Unlock() -} - -func (t *tokenSimple) enable() { - delf := func(tk string) { - if username, ok := t.simpleTokens[tk]; ok { - plog.Infof("deleting token %s for user %s", tk, username) - delete(t.simpleTokens, tk) - } - } - t.simpleTokenKeeper = &simpleTokenTTLKeeper{ - tokens: make(map[string]time.Time), - donec: make(chan struct{}), - stopc: make(chan struct{}), - deleteTokenFunc: delf, - mu: &t.simpleTokensMu, - } - go t.simpleTokenKeeper.run() -} - -func (t *tokenSimple) disable() { - t.simpleTokensMu.Lock() - tk := t.simpleTokenKeeper - t.simpleTokenKeeper = nil - t.simpleTokens = make(map[string]string) // invalidate all tokens - t.simpleTokensMu.Unlock() - if tk != nil { - tk.stop() - } -} - -func (t *tokenSimple) info(ctx context.Context, token string, revision uint64) (*AuthInfo, bool) { - if !t.isValidSimpleToken(ctx, token) { - return nil, false - } - t.simpleTokensMu.Lock() - username, ok := t.simpleTokens[token] - if ok && t.simpleTokenKeeper != nil { - t.simpleTokenKeeper.resetSimpleToken(token) - } - t.simpleTokensMu.Unlock() - return &AuthInfo{Username: username, Revision: revision}, ok -} - -func (t *tokenSimple) assign(ctx context.Context, username string, rev uint64) (string, error) { - // rev isn't used in simple token, it is only used in JWT - index := ctx.Value(AuthenticateParamIndex{}).(uint64) - simpleTokenPrefix := ctx.Value(AuthenticateParamSimpleTokenPrefix{}).(string) - token := fmt.Sprintf("%s.%d", simpleTokenPrefix, index) - t.assignSimpleTokenToUser(username, token) - - return token, nil -} - -func (t *tokenSimple) isValidSimpleToken(ctx context.Context, token string) bool { - splitted := strings.Split(token, ".") - if len(splitted) != 2 { - return false - } - index, err := strconv.Atoi(splitted[1]) - if err != nil { - return false - } - - select { - case <-t.indexWaiter(uint64(index)): - return true - case <-ctx.Done(): - } - - return false -} - -func newTokenProviderSimple(indexWaiter func(uint64) <-chan struct{}) *tokenSimple { - return &tokenSimple{ - simpleTokens: make(map[string]string), - indexWaiter: indexWaiter, - } -} diff --git a/vendor/go.etcd.io/etcd/auth/store.go b/vendor/go.etcd.io/etcd/auth/store.go deleted file mode 100644 index d676cb5553bb..000000000000 --- a/vendor/go.etcd.io/etcd/auth/store.go +++ /dev/null @@ -1,1136 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth - -import ( - "bytes" - "context" - "encoding/binary" - "errors" - "sort" - "strings" - "sync" - "sync/atomic" - - "github.com/coreos/etcd/auth/authpb" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc/backend" - - "github.com/coreos/pkg/capnslog" - "golang.org/x/crypto/bcrypt" - "google.golang.org/grpc/credentials" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/peer" -) - -var ( - enableFlagKey = []byte("authEnabled") - authEnabled = []byte{1} - authDisabled = []byte{0} - - revisionKey = []byte("authRevision") - - authBucketName = []byte("auth") - authUsersBucketName = []byte("authUsers") - authRolesBucketName = []byte("authRoles") - - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "auth") - - ErrRootUserNotExist = errors.New("auth: root user does not exist") - ErrRootRoleNotExist = errors.New("auth: root user does not have root role") - ErrUserAlreadyExist = errors.New("auth: user already exists") - ErrUserEmpty = errors.New("auth: user name is empty") - ErrUserNotFound = errors.New("auth: user not found") - ErrRoleAlreadyExist = errors.New("auth: role already exists") - ErrRoleNotFound = errors.New("auth: role not found") - ErrAuthFailed = errors.New("auth: authentication failed, invalid user ID or password") - ErrPermissionDenied = errors.New("auth: permission denied") - ErrRoleNotGranted = errors.New("auth: role is not granted to the user") - ErrPermissionNotGranted = errors.New("auth: permission is not granted to the role") - ErrAuthNotEnabled = errors.New("auth: authentication is not enabled") - ErrAuthOldRevision = errors.New("auth: revision in header is old") - ErrInvalidAuthToken = errors.New("auth: invalid auth token") - ErrInvalidAuthOpts = errors.New("auth: invalid auth options") - ErrInvalidAuthMgmt = errors.New("auth: invalid auth management") - - // BcryptCost is the algorithm cost / strength for hashing auth passwords - BcryptCost = bcrypt.DefaultCost -) - -const ( - rootUser = "root" - rootRole = "root" - - tokenTypeSimple = "simple" - tokenTypeJWT = "jwt" - - revBytesLen = 8 -) - -type AuthInfo struct { - Username string - Revision uint64 -} - -// AuthenticateParamIndex is used for a key of context in the parameters of Authenticate() -type AuthenticateParamIndex struct{} - -// AuthenticateParamSimpleTokenPrefix is used for a key of context in the parameters of Authenticate() -type AuthenticateParamSimpleTokenPrefix struct{} - -type AuthStore interface { - // AuthEnable turns on the authentication feature - AuthEnable() error - - // AuthDisable turns off the authentication feature - AuthDisable() - - // Authenticate does authentication based on given user name and password - Authenticate(ctx context.Context, username, password string) (*pb.AuthenticateResponse, error) - - // Recover recovers the state of auth store from the given backend - Recover(b backend.Backend) - - // UserAdd adds a new user - UserAdd(r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) - - // UserDelete deletes a user - UserDelete(r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) - - // UserChangePassword changes a password of a user - UserChangePassword(r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) - - // UserGrantRole grants a role to the user - UserGrantRole(r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) - - // UserGet gets the detailed information of a users - UserGet(r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) - - // UserRevokeRole revokes a role of a user - UserRevokeRole(r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) - - // RoleAdd adds a new role - RoleAdd(r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) - - // RoleGrantPermission grants a permission to a role - RoleGrantPermission(r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) - - // RoleGet gets the detailed information of a role - RoleGet(r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) - - // RoleRevokePermission gets the detailed information of a role - RoleRevokePermission(r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) - - // RoleDelete gets the detailed information of a role - RoleDelete(r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) - - // UserList gets a list of all users - UserList(r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) - - // RoleList gets a list of all roles - RoleList(r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) - - // IsPutPermitted checks put permission of the user - IsPutPermitted(authInfo *AuthInfo, key []byte) error - - // IsRangePermitted checks range permission of the user - IsRangePermitted(authInfo *AuthInfo, key, rangeEnd []byte) error - - // IsDeleteRangePermitted checks delete-range permission of the user - IsDeleteRangePermitted(authInfo *AuthInfo, key, rangeEnd []byte) error - - // IsAdminPermitted checks admin permission of the user - IsAdminPermitted(authInfo *AuthInfo) error - - // GenTokenPrefix produces a random string in a case of simple token - // in a case of JWT, it produces an empty string - GenTokenPrefix() (string, error) - - // Revision gets current revision of authStore - Revision() uint64 - - // CheckPassword checks a given pair of username and password is correct - CheckPassword(username, password string) (uint64, error) - - // Close does cleanup of AuthStore - Close() error - - // AuthInfoFromCtx gets AuthInfo from gRPC's context - AuthInfoFromCtx(ctx context.Context) (*AuthInfo, error) - - // AuthInfoFromTLS gets AuthInfo from TLS info of gRPC's context - AuthInfoFromTLS(ctx context.Context) *AuthInfo - - // WithRoot generates and installs a token that can be used as a root credential - WithRoot(ctx context.Context) context.Context - - // HasRole checks that user has role - HasRole(user, role string) bool -} - -type TokenProvider interface { - info(ctx context.Context, token string, revision uint64) (*AuthInfo, bool) - assign(ctx context.Context, username string, revision uint64) (string, error) - enable() - disable() - - invalidateUser(string) - genTokenPrefix() (string, error) -} - -type authStore struct { - // atomic operations; need 64-bit align, or 32-bit tests will crash - revision uint64 - - be backend.Backend - enabled bool - enabledMu sync.RWMutex - - rangePermCache map[string]*unifiedRangePermissions // username -> unifiedRangePermissions - - tokenProvider TokenProvider -} - -func (as *authStore) AuthEnable() error { - as.enabledMu.Lock() - defer as.enabledMu.Unlock() - if as.enabled { - plog.Noticef("Authentication already enabled") - return nil - } - b := as.be - tx := b.BatchTx() - tx.Lock() - defer func() { - tx.Unlock() - b.ForceCommit() - }() - - u := getUser(tx, rootUser) - if u == nil { - return ErrRootUserNotExist - } - - if !hasRootRole(u) { - return ErrRootRoleNotExist - } - - tx.UnsafePut(authBucketName, enableFlagKey, authEnabled) - - as.enabled = true - as.tokenProvider.enable() - - as.rangePermCache = make(map[string]*unifiedRangePermissions) - - as.setRevision(getRevision(tx)) - - plog.Noticef("Authentication enabled") - - return nil -} - -func (as *authStore) AuthDisable() { - as.enabledMu.Lock() - defer as.enabledMu.Unlock() - if !as.enabled { - return - } - b := as.be - tx := b.BatchTx() - tx.Lock() - tx.UnsafePut(authBucketName, enableFlagKey, authDisabled) - as.commitRevision(tx) - tx.Unlock() - b.ForceCommit() - - as.enabled = false - as.tokenProvider.disable() - - plog.Noticef("Authentication disabled") -} - -func (as *authStore) Close() error { - as.enabledMu.Lock() - defer as.enabledMu.Unlock() - if !as.enabled { - return nil - } - as.tokenProvider.disable() - return nil -} - -func (as *authStore) Authenticate(ctx context.Context, username, password string) (*pb.AuthenticateResponse, error) { - if !as.isAuthEnabled() { - return nil, ErrAuthNotEnabled - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(tx, username) - if user == nil { - return nil, ErrAuthFailed - } - - // Password checking is already performed in the API layer, so we don't need to check for now. - // Staleness of password can be detected with OCC in the API layer, too. - - token, err := as.tokenProvider.assign(ctx, username, as.Revision()) - if err != nil { - return nil, err - } - - plog.Debugf("authorized %s, token is %s", username, token) - return &pb.AuthenticateResponse{Token: token}, nil -} - -func (as *authStore) CheckPassword(username, password string) (uint64, error) { - if !as.isAuthEnabled() { - return 0, ErrAuthNotEnabled - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(tx, username) - if user == nil { - return 0, ErrAuthFailed - } - - if bcrypt.CompareHashAndPassword(user.Password, []byte(password)) != nil { - plog.Noticef("authentication failed, invalid password for user %s", username) - return 0, ErrAuthFailed - } - - return getRevision(tx), nil -} - -func (as *authStore) Recover(be backend.Backend) { - enabled := false - as.be = be - tx := be.BatchTx() - tx.Lock() - _, vs := tx.UnsafeRange(authBucketName, enableFlagKey, nil, 0) - if len(vs) == 1 { - if bytes.Equal(vs[0], authEnabled) { - enabled = true - } - } - - as.setRevision(getRevision(tx)) - - tx.Unlock() - - as.enabledMu.Lock() - as.enabled = enabled - as.enabledMu.Unlock() -} - -func (as *authStore) UserAdd(r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) { - if len(r.Name) == 0 { - return nil, ErrUserEmpty - } - - hashed, err := bcrypt.GenerateFromPassword([]byte(r.Password), BcryptCost) - if err != nil { - plog.Errorf("failed to hash password: %s", err) - return nil, err - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(tx, r.Name) - if user != nil { - return nil, ErrUserAlreadyExist - } - - newUser := &authpb.User{ - Name: []byte(r.Name), - Password: hashed, - } - - putUser(tx, newUser) - - as.commitRevision(tx) - - plog.Noticef("added a new user: %s", r.Name) - - return &pb.AuthUserAddResponse{}, nil -} - -func (as *authStore) UserDelete(r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) { - if as.enabled && strings.Compare(r.Name, rootUser) == 0 { - plog.Errorf("the user root must not be deleted") - return nil, ErrInvalidAuthMgmt - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(tx, r.Name) - if user == nil { - return nil, ErrUserNotFound - } - - delUser(tx, r.Name) - - as.commitRevision(tx) - - as.invalidateCachedPerm(r.Name) - as.tokenProvider.invalidateUser(r.Name) - - plog.Noticef("deleted a user: %s", r.Name) - - return &pb.AuthUserDeleteResponse{}, nil -} - -func (as *authStore) UserChangePassword(r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) { - // TODO(mitake): measure the cost of bcrypt.GenerateFromPassword() - // If the cost is too high, we should move the encryption to outside of the raft - hashed, err := bcrypt.GenerateFromPassword([]byte(r.Password), BcryptCost) - if err != nil { - plog.Errorf("failed to hash password: %s", err) - return nil, err - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(tx, r.Name) - if user == nil { - return nil, ErrUserNotFound - } - - updatedUser := &authpb.User{ - Name: []byte(r.Name), - Roles: user.Roles, - Password: hashed, - } - - putUser(tx, updatedUser) - - as.commitRevision(tx) - - as.invalidateCachedPerm(r.Name) - as.tokenProvider.invalidateUser(r.Name) - - plog.Noticef("changed a password of a user: %s", r.Name) - - return &pb.AuthUserChangePasswordResponse{}, nil -} - -func (as *authStore) UserGrantRole(r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(tx, r.User) - if user == nil { - return nil, ErrUserNotFound - } - - if r.Role != rootRole { - role := getRole(tx, r.Role) - if role == nil { - return nil, ErrRoleNotFound - } - } - - idx := sort.SearchStrings(user.Roles, r.Role) - if idx < len(user.Roles) && strings.Compare(user.Roles[idx], r.Role) == 0 { - plog.Warningf("user %s is already granted role %s", r.User, r.Role) - return &pb.AuthUserGrantRoleResponse{}, nil - } - - user.Roles = append(user.Roles, r.Role) - sort.Strings(user.Roles) - - putUser(tx, user) - - as.invalidateCachedPerm(r.User) - - as.commitRevision(tx) - - plog.Noticef("granted role %s to user %s", r.Role, r.User) - return &pb.AuthUserGrantRoleResponse{}, nil -} - -func (as *authStore) UserGet(r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - user := getUser(tx, r.Name) - tx.Unlock() - - if user == nil { - return nil, ErrUserNotFound - } - - var resp pb.AuthUserGetResponse - resp.Roles = append(resp.Roles, user.Roles...) - return &resp, nil -} - -func (as *authStore) UserList(r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - users := getAllUsers(tx) - tx.Unlock() - - resp := &pb.AuthUserListResponse{Users: make([]string, len(users))} - for i := range users { - resp.Users[i] = string(users[i].Name) - } - return resp, nil -} - -func (as *authStore) UserRevokeRole(r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) { - if as.enabled && strings.Compare(r.Name, rootUser) == 0 && strings.Compare(r.Role, rootRole) == 0 { - plog.Errorf("the role root must not be revoked from the user root") - return nil, ErrInvalidAuthMgmt - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(tx, r.Name) - if user == nil { - return nil, ErrUserNotFound - } - - updatedUser := &authpb.User{ - Name: user.Name, - Password: user.Password, - } - - for _, role := range user.Roles { - if strings.Compare(role, r.Role) != 0 { - updatedUser.Roles = append(updatedUser.Roles, role) - } - } - - if len(updatedUser.Roles) == len(user.Roles) { - return nil, ErrRoleNotGranted - } - - putUser(tx, updatedUser) - - as.invalidateCachedPerm(r.Name) - - as.commitRevision(tx) - - plog.Noticef("revoked role %s from user %s", r.Role, r.Name) - return &pb.AuthUserRevokeRoleResponse{}, nil -} - -func (as *authStore) RoleGet(r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - var resp pb.AuthRoleGetResponse - - role := getRole(tx, r.Role) - if role == nil { - return nil, ErrRoleNotFound - } - resp.Perm = append(resp.Perm, role.KeyPermission...) - return &resp, nil -} - -func (as *authStore) RoleList(r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - roles := getAllRoles(tx) - tx.Unlock() - - resp := &pb.AuthRoleListResponse{Roles: make([]string, len(roles))} - for i := range roles { - resp.Roles[i] = string(roles[i].Name) - } - return resp, nil -} - -func (as *authStore) RoleRevokePermission(r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - role := getRole(tx, r.Role) - if role == nil { - return nil, ErrRoleNotFound - } - - updatedRole := &authpb.Role{ - Name: role.Name, - } - - for _, perm := range role.KeyPermission { - if !bytes.Equal(perm.Key, []byte(r.Key)) || !bytes.Equal(perm.RangeEnd, []byte(r.RangeEnd)) { - updatedRole.KeyPermission = append(updatedRole.KeyPermission, perm) - } - } - - if len(role.KeyPermission) == len(updatedRole.KeyPermission) { - return nil, ErrPermissionNotGranted - } - - putRole(tx, updatedRole) - - // TODO(mitake): currently single role update invalidates every cache - // It should be optimized. - as.clearCachedPerm() - - as.commitRevision(tx) - - plog.Noticef("revoked key %s from role %s", r.Key, r.Role) - return &pb.AuthRoleRevokePermissionResponse{}, nil -} - -func (as *authStore) RoleDelete(r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) { - if as.enabled && strings.Compare(r.Role, rootRole) == 0 { - plog.Errorf("the role root must not be deleted") - return nil, ErrInvalidAuthMgmt - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - role := getRole(tx, r.Role) - if role == nil { - return nil, ErrRoleNotFound - } - - delRole(tx, r.Role) - - users := getAllUsers(tx) - for _, user := range users { - updatedUser := &authpb.User{ - Name: user.Name, - Password: user.Password, - } - - for _, role := range user.Roles { - if strings.Compare(role, r.Role) != 0 { - updatedUser.Roles = append(updatedUser.Roles, role) - } - } - - if len(updatedUser.Roles) == len(user.Roles) { - continue - } - - putUser(tx, updatedUser) - - as.invalidateCachedPerm(string(user.Name)) - } - - as.commitRevision(tx) - - plog.Noticef("deleted role %s", r.Role) - return &pb.AuthRoleDeleteResponse{}, nil -} - -func (as *authStore) RoleAdd(r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - role := getRole(tx, r.Name) - if role != nil { - return nil, ErrRoleAlreadyExist - } - - newRole := &authpb.Role{ - Name: []byte(r.Name), - } - - putRole(tx, newRole) - - as.commitRevision(tx) - - plog.Noticef("Role %s is created", r.Name) - - return &pb.AuthRoleAddResponse{}, nil -} - -func (as *authStore) authInfoFromToken(ctx context.Context, token string) (*AuthInfo, bool) { - return as.tokenProvider.info(ctx, token, as.Revision()) -} - -type permSlice []*authpb.Permission - -func (perms permSlice) Len() int { - return len(perms) -} - -func (perms permSlice) Less(i, j int) bool { - return bytes.Compare(perms[i].Key, perms[j].Key) < 0 -} - -func (perms permSlice) Swap(i, j int) { - perms[i], perms[j] = perms[j], perms[i] -} - -func (as *authStore) RoleGrantPermission(r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - role := getRole(tx, r.Name) - if role == nil { - return nil, ErrRoleNotFound - } - - idx := sort.Search(len(role.KeyPermission), func(i int) bool { - return bytes.Compare(role.KeyPermission[i].Key, []byte(r.Perm.Key)) >= 0 - }) - - if idx < len(role.KeyPermission) && bytes.Equal(role.KeyPermission[idx].Key, r.Perm.Key) && bytes.Equal(role.KeyPermission[idx].RangeEnd, r.Perm.RangeEnd) { - // update existing permission - role.KeyPermission[idx].PermType = r.Perm.PermType - } else { - // append new permission to the role - newPerm := &authpb.Permission{ - Key: []byte(r.Perm.Key), - RangeEnd: []byte(r.Perm.RangeEnd), - PermType: r.Perm.PermType, - } - - role.KeyPermission = append(role.KeyPermission, newPerm) - sort.Sort(permSlice(role.KeyPermission)) - } - - putRole(tx, role) - - // TODO(mitake): currently single role update invalidates every cache - // It should be optimized. - as.clearCachedPerm() - - as.commitRevision(tx) - - plog.Noticef("role %s's permission of key %s is updated as %s", r.Name, r.Perm.Key, authpb.Permission_Type_name[int32(r.Perm.PermType)]) - - return &pb.AuthRoleGrantPermissionResponse{}, nil -} - -func (as *authStore) isOpPermitted(userName string, revision uint64, key, rangeEnd []byte, permTyp authpb.Permission_Type) error { - // TODO(mitake): this function would be costly so we need a caching mechanism - if !as.isAuthEnabled() { - return nil - } - - // only gets rev == 0 when passed AuthInfo{}; no user given - if revision == 0 { - return ErrUserEmpty - } - - if revision < as.Revision() { - return ErrAuthOldRevision - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(tx, userName) - if user == nil { - plog.Errorf("invalid user name %s for permission checking", userName) - return ErrPermissionDenied - } - - // root role should have permission on all ranges - if hasRootRole(user) { - return nil - } - - if as.isRangeOpPermitted(tx, userName, key, rangeEnd, permTyp) { - return nil - } - - return ErrPermissionDenied -} - -func (as *authStore) IsPutPermitted(authInfo *AuthInfo, key []byte) error { - return as.isOpPermitted(authInfo.Username, authInfo.Revision, key, nil, authpb.WRITE) -} - -func (as *authStore) IsRangePermitted(authInfo *AuthInfo, key, rangeEnd []byte) error { - return as.isOpPermitted(authInfo.Username, authInfo.Revision, key, rangeEnd, authpb.READ) -} - -func (as *authStore) IsDeleteRangePermitted(authInfo *AuthInfo, key, rangeEnd []byte) error { - return as.isOpPermitted(authInfo.Username, authInfo.Revision, key, rangeEnd, authpb.WRITE) -} - -func (as *authStore) IsAdminPermitted(authInfo *AuthInfo) error { - if !as.isAuthEnabled() { - return nil - } - if authInfo == nil { - return ErrUserEmpty - } - - tx := as.be.BatchTx() - tx.Lock() - u := getUser(tx, authInfo.Username) - tx.Unlock() - - if u == nil { - return ErrUserNotFound - } - - if !hasRootRole(u) { - return ErrPermissionDenied - } - - return nil -} - -func getUser(tx backend.BatchTx, username string) *authpb.User { - _, vs := tx.UnsafeRange(authUsersBucketName, []byte(username), nil, 0) - if len(vs) == 0 { - return nil - } - - user := &authpb.User{} - err := user.Unmarshal(vs[0]) - if err != nil { - plog.Panicf("failed to unmarshal user struct (name: %s): %s", username, err) - } - return user -} - -func getAllUsers(tx backend.BatchTx) []*authpb.User { - _, vs := tx.UnsafeRange(authUsersBucketName, []byte{0}, []byte{0xff}, -1) - if len(vs) == 0 { - return nil - } - - users := make([]*authpb.User, len(vs)) - for i := range vs { - user := &authpb.User{} - err := user.Unmarshal(vs[i]) - if err != nil { - plog.Panicf("failed to unmarshal user struct: %s", err) - } - users[i] = user - } - return users -} - -func putUser(tx backend.BatchTx, user *authpb.User) { - b, err := user.Marshal() - if err != nil { - plog.Panicf("failed to marshal user struct (name: %s): %s", user.Name, err) - } - tx.UnsafePut(authUsersBucketName, user.Name, b) -} - -func delUser(tx backend.BatchTx, username string) { - tx.UnsafeDelete(authUsersBucketName, []byte(username)) -} - -func getRole(tx backend.BatchTx, rolename string) *authpb.Role { - _, vs := tx.UnsafeRange(authRolesBucketName, []byte(rolename), nil, 0) - if len(vs) == 0 { - return nil - } - - role := &authpb.Role{} - err := role.Unmarshal(vs[0]) - if err != nil { - plog.Panicf("failed to unmarshal role struct (name: %s): %s", rolename, err) - } - return role -} - -func getAllRoles(tx backend.BatchTx) []*authpb.Role { - _, vs := tx.UnsafeRange(authRolesBucketName, []byte{0}, []byte{0xff}, -1) - if len(vs) == 0 { - return nil - } - - roles := make([]*authpb.Role, len(vs)) - for i := range vs { - role := &authpb.Role{} - err := role.Unmarshal(vs[i]) - if err != nil { - plog.Panicf("failed to unmarshal role struct: %s", err) - } - roles[i] = role - } - return roles -} - -func putRole(tx backend.BatchTx, role *authpb.Role) { - b, err := role.Marshal() - if err != nil { - plog.Panicf("failed to marshal role struct (name: %s): %s", role.Name, err) - } - - tx.UnsafePut(authRolesBucketName, []byte(role.Name), b) -} - -func delRole(tx backend.BatchTx, rolename string) { - tx.UnsafeDelete(authRolesBucketName, []byte(rolename)) -} - -func (as *authStore) isAuthEnabled() bool { - as.enabledMu.RLock() - defer as.enabledMu.RUnlock() - return as.enabled -} - -func NewAuthStore(be backend.Backend, tp TokenProvider) *authStore { - tx := be.BatchTx() - tx.Lock() - - tx.UnsafeCreateBucket(authBucketName) - tx.UnsafeCreateBucket(authUsersBucketName) - tx.UnsafeCreateBucket(authRolesBucketName) - - enabled := false - _, vs := tx.UnsafeRange(authBucketName, enableFlagKey, nil, 0) - if len(vs) == 1 { - if bytes.Equal(vs[0], authEnabled) { - enabled = true - } - } - - as := &authStore{ - be: be, - revision: getRevision(tx), - enabled: enabled, - rangePermCache: make(map[string]*unifiedRangePermissions), - tokenProvider: tp, - } - - if enabled { - as.tokenProvider.enable() - } - - if as.Revision() == 0 { - as.commitRevision(tx) - } - - tx.Unlock() - be.ForceCommit() - - return as -} - -func hasRootRole(u *authpb.User) bool { - // u.Roles is sorted in UserGrantRole(), so we can use binary search. - idx := sort.SearchStrings(u.Roles, rootRole) - return idx != len(u.Roles) && u.Roles[idx] == rootRole -} - -func (as *authStore) commitRevision(tx backend.BatchTx) { - atomic.AddUint64(&as.revision, 1) - revBytes := make([]byte, revBytesLen) - binary.BigEndian.PutUint64(revBytes, as.Revision()) - tx.UnsafePut(authBucketName, revisionKey, revBytes) -} - -func getRevision(tx backend.BatchTx) uint64 { - _, vs := tx.UnsafeRange(authBucketName, []byte(revisionKey), nil, 0) - if len(vs) != 1 { - // this can happen in the initialization phase - return 0 - } - - return binary.BigEndian.Uint64(vs[0]) -} - -func (as *authStore) setRevision(rev uint64) { - atomic.StoreUint64(&as.revision, rev) -} - -func (as *authStore) Revision() uint64 { - return atomic.LoadUint64(&as.revision) -} - -func (as *authStore) AuthInfoFromTLS(ctx context.Context) *AuthInfo { - peer, ok := peer.FromContext(ctx) - if !ok || peer == nil || peer.AuthInfo == nil { - return nil - } - - tlsInfo := peer.AuthInfo.(credentials.TLSInfo) - for _, chains := range tlsInfo.State.VerifiedChains { - for _, chain := range chains { - cn := chain.Subject.CommonName - plog.Debugf("found common name %s", cn) - - ai := &AuthInfo{ - Username: cn, - Revision: as.Revision(), - } - md, ok := metadata.FromIncomingContext(ctx) - if !ok { - return nil - } - - // gRPC-gateway proxy request to etcd server includes Grpcgateway-Accept - // header. The proxy uses etcd client server certificate. If the certificate - // has a CommonName we should never use this for authentication. - if gw := md["grpcgateway-accept"]; len(gw) > 0 { - plog.Warningf("ignoring common name in gRPC-gateway proxy request %s", ai.Username) - return nil - } - return ai - } - } - - return nil -} - -func (as *authStore) AuthInfoFromCtx(ctx context.Context) (*AuthInfo, error) { - md, ok := metadata.FromIncomingContext(ctx) - if !ok { - return nil, nil - } - - //TODO(mitake|hexfusion) review unifying key names - ts, ok := md["token"] - if !ok { - ts, ok = md["authorization"] - } - if !ok { - return nil, nil - } - - token := ts[0] - authInfo, uok := as.authInfoFromToken(ctx, token) - if !uok { - plog.Warningf("invalid auth token: %s", token) - return nil, ErrInvalidAuthToken - } - - return authInfo, nil -} - -func (as *authStore) GenTokenPrefix() (string, error) { - return as.tokenProvider.genTokenPrefix() -} - -func decomposeOpts(optstr string) (string, map[string]string, error) { - opts := strings.Split(optstr, ",") - tokenType := opts[0] - - typeSpecificOpts := make(map[string]string) - for i := 1; i < len(opts); i++ { - pair := strings.Split(opts[i], "=") - - if len(pair) != 2 { - plog.Errorf("invalid token specific option: %s", optstr) - return "", nil, ErrInvalidAuthOpts - } - - if _, ok := typeSpecificOpts[pair[0]]; ok { - plog.Errorf("invalid token specific option, duplicated parameters (%s): %s", pair[0], optstr) - return "", nil, ErrInvalidAuthOpts - } - - typeSpecificOpts[pair[0]] = pair[1] - } - - return tokenType, typeSpecificOpts, nil - -} - -func NewTokenProvider(tokenOpts string, indexWaiter func(uint64) <-chan struct{}) (TokenProvider, error) { - tokenType, typeSpecificOpts, err := decomposeOpts(tokenOpts) - if err != nil { - return nil, ErrInvalidAuthOpts - } - - switch tokenType { - case tokenTypeSimple: - plog.Warningf("simple token is not cryptographically signed") - return newTokenProviderSimple(indexWaiter), nil - - case tokenTypeJWT: - return newTokenProviderJWT(typeSpecificOpts) - - case "": - return newTokenProviderNop() - default: - plog.Errorf("unknown token type: %s", tokenType) - return nil, ErrInvalidAuthOpts - } -} - -func (as *authStore) WithRoot(ctx context.Context) context.Context { - if !as.isAuthEnabled() { - return ctx - } - - var ctxForAssign context.Context - if ts, ok := as.tokenProvider.(*tokenSimple); ok && ts != nil { - ctx1 := context.WithValue(ctx, AuthenticateParamIndex{}, uint64(0)) - prefix, err := ts.genTokenPrefix() - if err != nil { - plog.Errorf("failed to generate prefix of internally used token") - return ctx - } - ctxForAssign = context.WithValue(ctx1, AuthenticateParamSimpleTokenPrefix{}, prefix) - } else { - ctxForAssign = ctx - } - - token, err := as.tokenProvider.assign(ctxForAssign, "root", as.Revision()) - if err != nil { - // this must not happen - plog.Errorf("failed to assign token for lease revoking: %s", err) - return ctx - } - - mdMap := map[string]string{ - "token": token, - } - tokenMD := metadata.New(mdMap) - - // use "mdIncomingKey{}" since it's called from local etcdserver - return metadata.NewIncomingContext(ctx, tokenMD) -} - -func (as *authStore) HasRole(user, role string) bool { - tx := as.be.BatchTx() - tx.Lock() - u := getUser(tx, user) - tx.Unlock() - - if u == nil { - plog.Warningf("tried to check user %s has role %s, but user %s doesn't exist", user, role, user) - return false - } - - for _, r := range u.Roles { - if role == r { - return true - } - } - - return false -} diff --git a/vendor/go.etcd.io/etcd/client/auth_role.go b/vendor/go.etcd.io/etcd/client/auth_role.go deleted file mode 100644 index b6ba7e150dc6..000000000000 --- a/vendor/go.etcd.io/etcd/client/auth_role.go +++ /dev/null @@ -1,236 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "bytes" - "context" - "encoding/json" - "net/http" - "net/url" -) - -type Role struct { - Role string `json:"role"` - Permissions Permissions `json:"permissions"` - Grant *Permissions `json:"grant,omitempty"` - Revoke *Permissions `json:"revoke,omitempty"` -} - -type Permissions struct { - KV rwPermission `json:"kv"` -} - -type rwPermission struct { - Read []string `json:"read"` - Write []string `json:"write"` -} - -type PermissionType int - -const ( - ReadPermission PermissionType = iota - WritePermission - ReadWritePermission -) - -// NewAuthRoleAPI constructs a new AuthRoleAPI that uses HTTP to -// interact with etcd's role creation and modification features. -func NewAuthRoleAPI(c Client) AuthRoleAPI { - return &httpAuthRoleAPI{ - client: c, - } -} - -type AuthRoleAPI interface { - // AddRole adds a role. - AddRole(ctx context.Context, role string) error - - // RemoveRole removes a role. - RemoveRole(ctx context.Context, role string) error - - // GetRole retrieves role details. - GetRole(ctx context.Context, role string) (*Role, error) - - // GrantRoleKV grants a role some permission prefixes for the KV store. - GrantRoleKV(ctx context.Context, role string, prefixes []string, permType PermissionType) (*Role, error) - - // RevokeRoleKV revokes some permission prefixes for a role on the KV store. - RevokeRoleKV(ctx context.Context, role string, prefixes []string, permType PermissionType) (*Role, error) - - // ListRoles lists roles. - ListRoles(ctx context.Context) ([]string, error) -} - -type httpAuthRoleAPI struct { - client httpClient -} - -type authRoleAPIAction struct { - verb string - name string - role *Role -} - -type authRoleAPIList struct{} - -func (list *authRoleAPIList) HTTPRequest(ep url.URL) *http.Request { - u := v2AuthURL(ep, "roles", "") - req, _ := http.NewRequest("GET", u.String(), nil) - req.Header.Set("Content-Type", "application/json") - return req -} - -func (l *authRoleAPIAction) HTTPRequest(ep url.URL) *http.Request { - u := v2AuthURL(ep, "roles", l.name) - if l.role == nil { - req, _ := http.NewRequest(l.verb, u.String(), nil) - return req - } - b, err := json.Marshal(l.role) - if err != nil { - panic(err) - } - body := bytes.NewReader(b) - req, _ := http.NewRequest(l.verb, u.String(), body) - req.Header.Set("Content-Type", "application/json") - return req -} - -func (r *httpAuthRoleAPI) ListRoles(ctx context.Context) ([]string, error) { - resp, body, err := r.client.Do(ctx, &authRoleAPIList{}) - if err != nil { - return nil, err - } - if err = assertStatusCode(resp.StatusCode, http.StatusOK); err != nil { - return nil, err - } - var roleList struct { - Roles []Role `json:"roles"` - } - if err = json.Unmarshal(body, &roleList); err != nil { - return nil, err - } - ret := make([]string, 0, len(roleList.Roles)) - for _, r := range roleList.Roles { - ret = append(ret, r.Role) - } - return ret, nil -} - -func (r *httpAuthRoleAPI) AddRole(ctx context.Context, rolename string) error { - role := &Role{ - Role: rolename, - } - return r.addRemoveRole(ctx, &authRoleAPIAction{ - verb: "PUT", - name: rolename, - role: role, - }) -} - -func (r *httpAuthRoleAPI) RemoveRole(ctx context.Context, rolename string) error { - return r.addRemoveRole(ctx, &authRoleAPIAction{ - verb: "DELETE", - name: rolename, - }) -} - -func (r *httpAuthRoleAPI) addRemoveRole(ctx context.Context, req *authRoleAPIAction) error { - resp, body, err := r.client.Do(ctx, req) - if err != nil { - return err - } - if err := assertStatusCode(resp.StatusCode, http.StatusOK, http.StatusCreated); err != nil { - var sec authError - err := json.Unmarshal(body, &sec) - if err != nil { - return err - } - return sec - } - return nil -} - -func (r *httpAuthRoleAPI) GetRole(ctx context.Context, rolename string) (*Role, error) { - return r.modRole(ctx, &authRoleAPIAction{ - verb: "GET", - name: rolename, - }) -} - -func buildRWPermission(prefixes []string, permType PermissionType) rwPermission { - var out rwPermission - switch permType { - case ReadPermission: - out.Read = prefixes - case WritePermission: - out.Write = prefixes - case ReadWritePermission: - out.Read = prefixes - out.Write = prefixes - } - return out -} - -func (r *httpAuthRoleAPI) GrantRoleKV(ctx context.Context, rolename string, prefixes []string, permType PermissionType) (*Role, error) { - rwp := buildRWPermission(prefixes, permType) - role := &Role{ - Role: rolename, - Grant: &Permissions{ - KV: rwp, - }, - } - return r.modRole(ctx, &authRoleAPIAction{ - verb: "PUT", - name: rolename, - role: role, - }) -} - -func (r *httpAuthRoleAPI) RevokeRoleKV(ctx context.Context, rolename string, prefixes []string, permType PermissionType) (*Role, error) { - rwp := buildRWPermission(prefixes, permType) - role := &Role{ - Role: rolename, - Revoke: &Permissions{ - KV: rwp, - }, - } - return r.modRole(ctx, &authRoleAPIAction{ - verb: "PUT", - name: rolename, - role: role, - }) -} - -func (r *httpAuthRoleAPI) modRole(ctx context.Context, req *authRoleAPIAction) (*Role, error) { - resp, body, err := r.client.Do(ctx, req) - if err != nil { - return nil, err - } - if err = assertStatusCode(resp.StatusCode, http.StatusOK); err != nil { - var sec authError - err = json.Unmarshal(body, &sec) - if err != nil { - return nil, err - } - return nil, sec - } - var role Role - if err = json.Unmarshal(body, &role); err != nil { - return nil, err - } - return &role, nil -} diff --git a/vendor/go.etcd.io/etcd/client/auth_user.go b/vendor/go.etcd.io/etcd/client/auth_user.go deleted file mode 100644 index 8e7e2efe8333..000000000000 --- a/vendor/go.etcd.io/etcd/client/auth_user.go +++ /dev/null @@ -1,319 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "bytes" - "context" - "encoding/json" - "net/http" - "net/url" - "path" -) - -var ( - defaultV2AuthPrefix = "/v2/auth" -) - -type User struct { - User string `json:"user"` - Password string `json:"password,omitempty"` - Roles []string `json:"roles"` - Grant []string `json:"grant,omitempty"` - Revoke []string `json:"revoke,omitempty"` -} - -// userListEntry is the user representation given by the server for ListUsers -type userListEntry struct { - User string `json:"user"` - Roles []Role `json:"roles"` -} - -type UserRoles struct { - User string `json:"user"` - Roles []Role `json:"roles"` -} - -func v2AuthURL(ep url.URL, action string, name string) *url.URL { - if name != "" { - ep.Path = path.Join(ep.Path, defaultV2AuthPrefix, action, name) - return &ep - } - ep.Path = path.Join(ep.Path, defaultV2AuthPrefix, action) - return &ep -} - -// NewAuthAPI constructs a new AuthAPI that uses HTTP to -// interact with etcd's general auth features. -func NewAuthAPI(c Client) AuthAPI { - return &httpAuthAPI{ - client: c, - } -} - -type AuthAPI interface { - // Enable auth. - Enable(ctx context.Context) error - - // Disable auth. - Disable(ctx context.Context) error -} - -type httpAuthAPI struct { - client httpClient -} - -func (s *httpAuthAPI) Enable(ctx context.Context) error { - return s.enableDisable(ctx, &authAPIAction{"PUT"}) -} - -func (s *httpAuthAPI) Disable(ctx context.Context) error { - return s.enableDisable(ctx, &authAPIAction{"DELETE"}) -} - -func (s *httpAuthAPI) enableDisable(ctx context.Context, req httpAction) error { - resp, body, err := s.client.Do(ctx, req) - if err != nil { - return err - } - if err = assertStatusCode(resp.StatusCode, http.StatusOK, http.StatusCreated); err != nil { - var sec authError - err = json.Unmarshal(body, &sec) - if err != nil { - return err - } - return sec - } - return nil -} - -type authAPIAction struct { - verb string -} - -func (l *authAPIAction) HTTPRequest(ep url.URL) *http.Request { - u := v2AuthURL(ep, "enable", "") - req, _ := http.NewRequest(l.verb, u.String(), nil) - return req -} - -type authError struct { - Message string `json:"message"` - Code int `json:"-"` -} - -func (e authError) Error() string { - return e.Message -} - -// NewAuthUserAPI constructs a new AuthUserAPI that uses HTTP to -// interact with etcd's user creation and modification features. -func NewAuthUserAPI(c Client) AuthUserAPI { - return &httpAuthUserAPI{ - client: c, - } -} - -type AuthUserAPI interface { - // AddUser adds a user. - AddUser(ctx context.Context, username string, password string) error - - // RemoveUser removes a user. - RemoveUser(ctx context.Context, username string) error - - // GetUser retrieves user details. - GetUser(ctx context.Context, username string) (*User, error) - - // GrantUser grants a user some permission roles. - GrantUser(ctx context.Context, username string, roles []string) (*User, error) - - // RevokeUser revokes some permission roles from a user. - RevokeUser(ctx context.Context, username string, roles []string) (*User, error) - - // ChangePassword changes the user's password. - ChangePassword(ctx context.Context, username string, password string) (*User, error) - - // ListUsers lists the users. - ListUsers(ctx context.Context) ([]string, error) -} - -type httpAuthUserAPI struct { - client httpClient -} - -type authUserAPIAction struct { - verb string - username string - user *User -} - -type authUserAPIList struct{} - -func (list *authUserAPIList) HTTPRequest(ep url.URL) *http.Request { - u := v2AuthURL(ep, "users", "") - req, _ := http.NewRequest("GET", u.String(), nil) - req.Header.Set("Content-Type", "application/json") - return req -} - -func (l *authUserAPIAction) HTTPRequest(ep url.URL) *http.Request { - u := v2AuthURL(ep, "users", l.username) - if l.user == nil { - req, _ := http.NewRequest(l.verb, u.String(), nil) - return req - } - b, err := json.Marshal(l.user) - if err != nil { - panic(err) - } - body := bytes.NewReader(b) - req, _ := http.NewRequest(l.verb, u.String(), body) - req.Header.Set("Content-Type", "application/json") - return req -} - -func (u *httpAuthUserAPI) ListUsers(ctx context.Context) ([]string, error) { - resp, body, err := u.client.Do(ctx, &authUserAPIList{}) - if err != nil { - return nil, err - } - if err = assertStatusCode(resp.StatusCode, http.StatusOK); err != nil { - var sec authError - err = json.Unmarshal(body, &sec) - if err != nil { - return nil, err - } - return nil, sec - } - - var userList struct { - Users []userListEntry `json:"users"` - } - - if err = json.Unmarshal(body, &userList); err != nil { - return nil, err - } - - ret := make([]string, 0, len(userList.Users)) - for _, u := range userList.Users { - ret = append(ret, u.User) - } - return ret, nil -} - -func (u *httpAuthUserAPI) AddUser(ctx context.Context, username string, password string) error { - user := &User{ - User: username, - Password: password, - } - return u.addRemoveUser(ctx, &authUserAPIAction{ - verb: "PUT", - username: username, - user: user, - }) -} - -func (u *httpAuthUserAPI) RemoveUser(ctx context.Context, username string) error { - return u.addRemoveUser(ctx, &authUserAPIAction{ - verb: "DELETE", - username: username, - }) -} - -func (u *httpAuthUserAPI) addRemoveUser(ctx context.Context, req *authUserAPIAction) error { - resp, body, err := u.client.Do(ctx, req) - if err != nil { - return err - } - if err = assertStatusCode(resp.StatusCode, http.StatusOK, http.StatusCreated); err != nil { - var sec authError - err = json.Unmarshal(body, &sec) - if err != nil { - return err - } - return sec - } - return nil -} - -func (u *httpAuthUserAPI) GetUser(ctx context.Context, username string) (*User, error) { - return u.modUser(ctx, &authUserAPIAction{ - verb: "GET", - username: username, - }) -} - -func (u *httpAuthUserAPI) GrantUser(ctx context.Context, username string, roles []string) (*User, error) { - user := &User{ - User: username, - Grant: roles, - } - return u.modUser(ctx, &authUserAPIAction{ - verb: "PUT", - username: username, - user: user, - }) -} - -func (u *httpAuthUserAPI) RevokeUser(ctx context.Context, username string, roles []string) (*User, error) { - user := &User{ - User: username, - Revoke: roles, - } - return u.modUser(ctx, &authUserAPIAction{ - verb: "PUT", - username: username, - user: user, - }) -} - -func (u *httpAuthUserAPI) ChangePassword(ctx context.Context, username string, password string) (*User, error) { - user := &User{ - User: username, - Password: password, - } - return u.modUser(ctx, &authUserAPIAction{ - verb: "PUT", - username: username, - user: user, - }) -} - -func (u *httpAuthUserAPI) modUser(ctx context.Context, req *authUserAPIAction) (*User, error) { - resp, body, err := u.client.Do(ctx, req) - if err != nil { - return nil, err - } - if err = assertStatusCode(resp.StatusCode, http.StatusOK); err != nil { - var sec authError - err = json.Unmarshal(body, &sec) - if err != nil { - return nil, err - } - return nil, sec - } - var user User - if err = json.Unmarshal(body, &user); err != nil { - var userR UserRoles - if urerr := json.Unmarshal(body, &userR); urerr != nil { - return nil, err - } - user.User = userR.User - for _, r := range userR.Roles { - user.Roles = append(user.Roles, r.Role) - } - } - return &user, nil -} diff --git a/vendor/go.etcd.io/etcd/client/cancelreq.go b/vendor/go.etcd.io/etcd/client/cancelreq.go deleted file mode 100644 index 76d1f040198b..000000000000 --- a/vendor/go.etcd.io/etcd/client/cancelreq.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// borrowed from golang/net/context/ctxhttp/cancelreq.go - -package client - -import "net/http" - -func requestCanceler(tr CancelableTransport, req *http.Request) func() { - ch := make(chan struct{}) - req.Cancel = ch - - return func() { - close(ch) - } -} diff --git a/vendor/go.etcd.io/etcd/client/client.go b/vendor/go.etcd.io/etcd/client/client.go deleted file mode 100644 index e6874505666b..000000000000 --- a/vendor/go.etcd.io/etcd/client/client.go +++ /dev/null @@ -1,710 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "math/rand" - "net" - "net/http" - "net/url" - "sort" - "strconv" - "sync" - "time" - - "github.com/coreos/etcd/version" -) - -var ( - ErrNoEndpoints = errors.New("client: no endpoints available") - ErrTooManyRedirects = errors.New("client: too many redirects") - ErrClusterUnavailable = errors.New("client: etcd cluster is unavailable or misconfigured") - ErrNoLeaderEndpoint = errors.New("client: no leader endpoint available") - errTooManyRedirectChecks = errors.New("client: too many redirect checks") - - // oneShotCtxValue is set on a context using WithValue(&oneShotValue) so - // that Do() will not retry a request - oneShotCtxValue interface{} -) - -var DefaultRequestTimeout = 5 * time.Second - -var DefaultTransport CancelableTransport = &http.Transport{ - Proxy: http.ProxyFromEnvironment, - Dial: (&net.Dialer{ - Timeout: 30 * time.Second, - KeepAlive: 30 * time.Second, - }).Dial, - TLSHandshakeTimeout: 10 * time.Second, -} - -type EndpointSelectionMode int - -const ( - // EndpointSelectionRandom is the default value of the 'SelectionMode'. - // As the name implies, the client object will pick a node from the members - // of the cluster in a random fashion. If the cluster has three members, A, B, - // and C, the client picks any node from its three members as its request - // destination. - EndpointSelectionRandom EndpointSelectionMode = iota - - // If 'SelectionMode' is set to 'EndpointSelectionPrioritizeLeader', - // requests are sent directly to the cluster leader. This reduces - // forwarding roundtrips compared to making requests to etcd followers - // who then forward them to the cluster leader. In the event of a leader - // failure, however, clients configured this way cannot prioritize among - // the remaining etcd followers. Therefore, when a client sets 'SelectionMode' - // to 'EndpointSelectionPrioritizeLeader', it must use 'client.AutoSync()' to - // maintain its knowledge of current cluster state. - // - // This mode should be used with Client.AutoSync(). - EndpointSelectionPrioritizeLeader -) - -type Config struct { - // Endpoints defines a set of URLs (schemes, hosts and ports only) - // that can be used to communicate with a logical etcd cluster. For - // example, a three-node cluster could be provided like so: - // - // Endpoints: []string{ - // "http://node1.example.com:2379", - // "http://node2.example.com:2379", - // "http://node3.example.com:2379", - // } - // - // If multiple endpoints are provided, the Client will attempt to - // use them all in the event that one or more of them are unusable. - // - // If Client.Sync is ever called, the Client may cache an alternate - // set of endpoints to continue operation. - Endpoints []string - - // Transport is used by the Client to drive HTTP requests. If not - // provided, DefaultTransport will be used. - Transport CancelableTransport - - // CheckRedirect specifies the policy for handling HTTP redirects. - // If CheckRedirect is not nil, the Client calls it before - // following an HTTP redirect. The sole argument is the number of - // requests that have already been made. If CheckRedirect returns - // an error, Client.Do will not make any further requests and return - // the error back it to the caller. - // - // If CheckRedirect is nil, the Client uses its default policy, - // which is to stop after 10 consecutive requests. - CheckRedirect CheckRedirectFunc - - // Username specifies the user credential to add as an authorization header - Username string - - // Password is the password for the specified user to add as an authorization header - // to the request. - Password string - - // HeaderTimeoutPerRequest specifies the time limit to wait for response - // header in a single request made by the Client. The timeout includes - // connection time, any redirects, and header wait time. - // - // For non-watch GET request, server returns the response body immediately. - // For PUT/POST/DELETE request, server will attempt to commit request - // before responding, which is expected to take `100ms + 2 * RTT`. - // For watch request, server returns the header immediately to notify Client - // watch start. But if server is behind some kind of proxy, the response - // header may be cached at proxy, and Client cannot rely on this behavior. - // - // Especially, wait request will ignore this timeout. - // - // One API call may send multiple requests to different etcd servers until it - // succeeds. Use context of the API to specify the overall timeout. - // - // A HeaderTimeoutPerRequest of zero means no timeout. - HeaderTimeoutPerRequest time.Duration - - // SelectionMode is an EndpointSelectionMode enum that specifies the - // policy for choosing the etcd cluster node to which requests are sent. - SelectionMode EndpointSelectionMode -} - -func (cfg *Config) transport() CancelableTransport { - if cfg.Transport == nil { - return DefaultTransport - } - return cfg.Transport -} - -func (cfg *Config) checkRedirect() CheckRedirectFunc { - if cfg.CheckRedirect == nil { - return DefaultCheckRedirect - } - return cfg.CheckRedirect -} - -// CancelableTransport mimics net/http.Transport, but requires that -// the object also support request cancellation. -type CancelableTransport interface { - http.RoundTripper - CancelRequest(req *http.Request) -} - -type CheckRedirectFunc func(via int) error - -// DefaultCheckRedirect follows up to 10 redirects, but no more. -var DefaultCheckRedirect CheckRedirectFunc = func(via int) error { - if via > 10 { - return ErrTooManyRedirects - } - return nil -} - -type Client interface { - // Sync updates the internal cache of the etcd cluster's membership. - Sync(context.Context) error - - // AutoSync periodically calls Sync() every given interval. - // The recommended sync interval is 10 seconds to 1 minute, which does - // not bring too much overhead to server and makes client catch up the - // cluster change in time. - // - // The example to use it: - // - // for { - // err := client.AutoSync(ctx, 10*time.Second) - // if err == context.DeadlineExceeded || err == context.Canceled { - // break - // } - // log.Print(err) - // } - AutoSync(context.Context, time.Duration) error - - // Endpoints returns a copy of the current set of API endpoints used - // by Client to resolve HTTP requests. If Sync has ever been called, - // this may differ from the initial Endpoints provided in the Config. - Endpoints() []string - - // SetEndpoints sets the set of API endpoints used by Client to resolve - // HTTP requests. If the given endpoints are not valid, an error will be - // returned - SetEndpoints(eps []string) error - - // GetVersion retrieves the current etcd server and cluster version - GetVersion(ctx context.Context) (*version.Versions, error) - - httpClient -} - -func New(cfg Config) (Client, error) { - c := &httpClusterClient{ - clientFactory: newHTTPClientFactory(cfg.transport(), cfg.checkRedirect(), cfg.HeaderTimeoutPerRequest), - rand: rand.New(rand.NewSource(int64(time.Now().Nanosecond()))), - selectionMode: cfg.SelectionMode, - } - if cfg.Username != "" { - c.credentials = &credentials{ - username: cfg.Username, - password: cfg.Password, - } - } - if err := c.SetEndpoints(cfg.Endpoints); err != nil { - return nil, err - } - return c, nil -} - -type httpClient interface { - Do(context.Context, httpAction) (*http.Response, []byte, error) -} - -func newHTTPClientFactory(tr CancelableTransport, cr CheckRedirectFunc, headerTimeout time.Duration) httpClientFactory { - return func(ep url.URL) httpClient { - return &redirectFollowingHTTPClient{ - checkRedirect: cr, - client: &simpleHTTPClient{ - transport: tr, - endpoint: ep, - headerTimeout: headerTimeout, - }, - } - } -} - -type credentials struct { - username string - password string -} - -type httpClientFactory func(url.URL) httpClient - -type httpAction interface { - HTTPRequest(url.URL) *http.Request -} - -type httpClusterClient struct { - clientFactory httpClientFactory - endpoints []url.URL - pinned int - credentials *credentials - sync.RWMutex - rand *rand.Rand - selectionMode EndpointSelectionMode -} - -func (c *httpClusterClient) getLeaderEndpoint(ctx context.Context, eps []url.URL) (string, error) { - ceps := make([]url.URL, len(eps)) - copy(ceps, eps) - - // To perform a lookup on the new endpoint list without using the current - // client, we'll copy it - clientCopy := &httpClusterClient{ - clientFactory: c.clientFactory, - credentials: c.credentials, - rand: c.rand, - - pinned: 0, - endpoints: ceps, - } - - mAPI := NewMembersAPI(clientCopy) - leader, err := mAPI.Leader(ctx) - if err != nil { - return "", err - } - if len(leader.ClientURLs) == 0 { - return "", ErrNoLeaderEndpoint - } - - return leader.ClientURLs[0], nil // TODO: how to handle multiple client URLs? -} - -func (c *httpClusterClient) parseEndpoints(eps []string) ([]url.URL, error) { - if len(eps) == 0 { - return []url.URL{}, ErrNoEndpoints - } - - neps := make([]url.URL, len(eps)) - for i, ep := range eps { - u, err := url.Parse(ep) - if err != nil { - return []url.URL{}, err - } - neps[i] = *u - } - return neps, nil -} - -func (c *httpClusterClient) SetEndpoints(eps []string) error { - neps, err := c.parseEndpoints(eps) - if err != nil { - return err - } - - c.Lock() - defer c.Unlock() - - c.endpoints = shuffleEndpoints(c.rand, neps) - // We're not doing anything for PrioritizeLeader here. This is - // due to not having a context meaning we can't call getLeaderEndpoint - // However, if you're using PrioritizeLeader, you've already been told - // to regularly call sync, where we do have a ctx, and can figure the - // leader. PrioritizeLeader is also quite a loose guarantee, so deal - // with it - c.pinned = 0 - - return nil -} - -func (c *httpClusterClient) Do(ctx context.Context, act httpAction) (*http.Response, []byte, error) { - action := act - c.RLock() - leps := len(c.endpoints) - eps := make([]url.URL, leps) - n := copy(eps, c.endpoints) - pinned := c.pinned - - if c.credentials != nil { - action = &authedAction{ - act: act, - credentials: *c.credentials, - } - } - c.RUnlock() - - if leps == 0 { - return nil, nil, ErrNoEndpoints - } - - if leps != n { - return nil, nil, errors.New("unable to pick endpoint: copy failed") - } - - var resp *http.Response - var body []byte - var err error - cerr := &ClusterError{} - isOneShot := ctx.Value(&oneShotCtxValue) != nil - - for i := pinned; i < leps+pinned; i++ { - k := i % leps - hc := c.clientFactory(eps[k]) - resp, body, err = hc.Do(ctx, action) - if err != nil { - cerr.Errors = append(cerr.Errors, err) - if err == ctx.Err() { - return nil, nil, ctx.Err() - } - if err == context.Canceled || err == context.DeadlineExceeded { - return nil, nil, err - } - } else if resp.StatusCode/100 == 5 { - switch resp.StatusCode { - case http.StatusInternalServerError, http.StatusServiceUnavailable: - // TODO: make sure this is a no leader response - cerr.Errors = append(cerr.Errors, fmt.Errorf("client: etcd member %s has no leader", eps[k].String())) - default: - cerr.Errors = append(cerr.Errors, fmt.Errorf("client: etcd member %s returns server error [%s]", eps[k].String(), http.StatusText(resp.StatusCode))) - } - err = cerr.Errors[0] - } - if err != nil { - if !isOneShot { - continue - } - c.Lock() - c.pinned = (k + 1) % leps - c.Unlock() - return nil, nil, err - } - if k != pinned { - c.Lock() - c.pinned = k - c.Unlock() - } - return resp, body, nil - } - - return nil, nil, cerr -} - -func (c *httpClusterClient) Endpoints() []string { - c.RLock() - defer c.RUnlock() - - eps := make([]string, len(c.endpoints)) - for i, ep := range c.endpoints { - eps[i] = ep.String() - } - - return eps -} - -func (c *httpClusterClient) Sync(ctx context.Context) error { - mAPI := NewMembersAPI(c) - ms, err := mAPI.List(ctx) - if err != nil { - return err - } - - var eps []string - for _, m := range ms { - eps = append(eps, m.ClientURLs...) - } - - neps, err := c.parseEndpoints(eps) - if err != nil { - return err - } - - npin := 0 - - switch c.selectionMode { - case EndpointSelectionRandom: - c.RLock() - eq := endpointsEqual(c.endpoints, neps) - c.RUnlock() - - if eq { - return nil - } - // When items in the endpoint list changes, we choose a new pin - neps = shuffleEndpoints(c.rand, neps) - case EndpointSelectionPrioritizeLeader: - nle, err := c.getLeaderEndpoint(ctx, neps) - if err != nil { - return ErrNoLeaderEndpoint - } - - for i, n := range neps { - if n.String() == nle { - npin = i - break - } - } - default: - return fmt.Errorf("invalid endpoint selection mode: %d", c.selectionMode) - } - - c.Lock() - defer c.Unlock() - c.endpoints = neps - c.pinned = npin - - return nil -} - -func (c *httpClusterClient) AutoSync(ctx context.Context, interval time.Duration) error { - ticker := time.NewTicker(interval) - defer ticker.Stop() - for { - err := c.Sync(ctx) - if err != nil { - return err - } - select { - case <-ctx.Done(): - return ctx.Err() - case <-ticker.C: - } - } -} - -func (c *httpClusterClient) GetVersion(ctx context.Context) (*version.Versions, error) { - act := &getAction{Prefix: "/version"} - - resp, body, err := c.Do(ctx, act) - if err != nil { - return nil, err - } - - switch resp.StatusCode { - case http.StatusOK: - if len(body) == 0 { - return nil, ErrEmptyBody - } - var vresp version.Versions - if err := json.Unmarshal(body, &vresp); err != nil { - return nil, ErrInvalidJSON - } - return &vresp, nil - default: - var etcdErr Error - if err := json.Unmarshal(body, &etcdErr); err != nil { - return nil, ErrInvalidJSON - } - return nil, etcdErr - } -} - -type roundTripResponse struct { - resp *http.Response - err error -} - -type simpleHTTPClient struct { - transport CancelableTransport - endpoint url.URL - headerTimeout time.Duration -} - -func (c *simpleHTTPClient) Do(ctx context.Context, act httpAction) (*http.Response, []byte, error) { - req := act.HTTPRequest(c.endpoint) - - if err := printcURL(req); err != nil { - return nil, nil, err - } - - isWait := false - if req != nil && req.URL != nil { - ws := req.URL.Query().Get("wait") - if len(ws) != 0 { - var err error - isWait, err = strconv.ParseBool(ws) - if err != nil { - return nil, nil, fmt.Errorf("wrong wait value %s (%v for %+v)", ws, err, req) - } - } - } - - var hctx context.Context - var hcancel context.CancelFunc - if !isWait && c.headerTimeout > 0 { - hctx, hcancel = context.WithTimeout(ctx, c.headerTimeout) - } else { - hctx, hcancel = context.WithCancel(ctx) - } - defer hcancel() - - reqcancel := requestCanceler(c.transport, req) - - rtchan := make(chan roundTripResponse, 1) - go func() { - resp, err := c.transport.RoundTrip(req) - rtchan <- roundTripResponse{resp: resp, err: err} - close(rtchan) - }() - - var resp *http.Response - var err error - - select { - case rtresp := <-rtchan: - resp, err = rtresp.resp, rtresp.err - case <-hctx.Done(): - // cancel and wait for request to actually exit before continuing - reqcancel() - rtresp := <-rtchan - resp = rtresp.resp - switch { - case ctx.Err() != nil: - err = ctx.Err() - case hctx.Err() != nil: - err = fmt.Errorf("client: endpoint %s exceeded header timeout", c.endpoint.String()) - default: - panic("failed to get error from context") - } - } - - // always check for resp nil-ness to deal with possible - // race conditions between channels above - defer func() { - if resp != nil { - resp.Body.Close() - } - }() - - if err != nil { - return nil, nil, err - } - - var body []byte - done := make(chan struct{}) - go func() { - body, err = ioutil.ReadAll(resp.Body) - done <- struct{}{} - }() - - select { - case <-ctx.Done(): - resp.Body.Close() - <-done - return nil, nil, ctx.Err() - case <-done: - } - - return resp, body, err -} - -type authedAction struct { - act httpAction - credentials credentials -} - -func (a *authedAction) HTTPRequest(url url.URL) *http.Request { - r := a.act.HTTPRequest(url) - r.SetBasicAuth(a.credentials.username, a.credentials.password) - return r -} - -type redirectFollowingHTTPClient struct { - client httpClient - checkRedirect CheckRedirectFunc -} - -func (r *redirectFollowingHTTPClient) Do(ctx context.Context, act httpAction) (*http.Response, []byte, error) { - next := act - for i := 0; i < 100; i++ { - if i > 0 { - if err := r.checkRedirect(i); err != nil { - return nil, nil, err - } - } - resp, body, err := r.client.Do(ctx, next) - if err != nil { - return nil, nil, err - } - if resp.StatusCode/100 == 3 { - hdr := resp.Header.Get("Location") - if hdr == "" { - return nil, nil, fmt.Errorf("Location header not set") - } - loc, err := url.Parse(hdr) - if err != nil { - return nil, nil, fmt.Errorf("Location header not valid URL: %s", hdr) - } - next = &redirectedHTTPAction{ - action: act, - location: *loc, - } - continue - } - return resp, body, nil - } - - return nil, nil, errTooManyRedirectChecks -} - -type redirectedHTTPAction struct { - action httpAction - location url.URL -} - -func (r *redirectedHTTPAction) HTTPRequest(ep url.URL) *http.Request { - orig := r.action.HTTPRequest(ep) - orig.URL = &r.location - return orig -} - -func shuffleEndpoints(r *rand.Rand, eps []url.URL) []url.URL { - // copied from Go 1.9<= rand.Rand.Perm - n := len(eps) - p := make([]int, n) - for i := 0; i < n; i++ { - j := r.Intn(i + 1) - p[i] = p[j] - p[j] = i - } - neps := make([]url.URL, n) - for i, k := range p { - neps[i] = eps[k] - } - return neps -} - -func endpointsEqual(left, right []url.URL) bool { - if len(left) != len(right) { - return false - } - - sLeft := make([]string, len(left)) - sRight := make([]string, len(right)) - for i, l := range left { - sLeft[i] = l.String() - } - for i, r := range right { - sRight[i] = r.String() - } - - sort.Strings(sLeft) - sort.Strings(sRight) - for i := range sLeft { - if sLeft[i] != sRight[i] { - return false - } - } - return true -} diff --git a/vendor/go.etcd.io/etcd/client/cluster_error.go b/vendor/go.etcd.io/etcd/client/cluster_error.go deleted file mode 100644 index 34618cdbd9e6..000000000000 --- a/vendor/go.etcd.io/etcd/client/cluster_error.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import "fmt" - -type ClusterError struct { - Errors []error -} - -func (ce *ClusterError) Error() string { - s := ErrClusterUnavailable.Error() - for i, e := range ce.Errors { - s += fmt.Sprintf("; error #%d: %s\n", i, e) - } - return s -} - -func (ce *ClusterError) Detail() string { - s := "" - for i, e := range ce.Errors { - s += fmt.Sprintf("error #%d: %s\n", i, e) - } - return s -} diff --git a/vendor/go.etcd.io/etcd/client/curl.go b/vendor/go.etcd.io/etcd/client/curl.go deleted file mode 100644 index c8bc9fba20ec..000000000000 --- a/vendor/go.etcd.io/etcd/client/curl.go +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "os" -) - -var ( - cURLDebug = false -) - -func EnablecURLDebug() { - cURLDebug = true -} - -func DisablecURLDebug() { - cURLDebug = false -} - -// printcURL prints the cURL equivalent request to stderr. -// It returns an error if the body of the request cannot -// be read. -// The caller MUST cancel the request if there is an error. -func printcURL(req *http.Request) error { - if !cURLDebug { - return nil - } - var ( - command string - b []byte - err error - ) - - if req.URL != nil { - command = fmt.Sprintf("curl -X %s %s", req.Method, req.URL.String()) - } - - if req.Body != nil { - b, err = ioutil.ReadAll(req.Body) - if err != nil { - return err - } - command += fmt.Sprintf(" -d %q", string(b)) - } - - fmt.Fprintf(os.Stderr, "cURL Command: %s\n", command) - - // reset body - body := bytes.NewBuffer(b) - req.Body = ioutil.NopCloser(body) - - return nil -} diff --git a/vendor/go.etcd.io/etcd/client/discover.go b/vendor/go.etcd.io/etcd/client/discover.go deleted file mode 100644 index 442e35fe543b..000000000000 --- a/vendor/go.etcd.io/etcd/client/discover.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "github.com/coreos/etcd/pkg/srv" -) - -// Discoverer is an interface that wraps the Discover method. -type Discoverer interface { - // Discover looks up the etcd servers for the domain. - Discover(domain string) ([]string, error) -} - -type srvDiscover struct{} - -// NewSRVDiscover constructs a new Discoverer that uses the stdlib to lookup SRV records. -func NewSRVDiscover() Discoverer { - return &srvDiscover{} -} - -func (d *srvDiscover) Discover(domain string) ([]string, error) { - srvs, err := srv.GetClient("etcd-client", domain) - if err != nil { - return nil, err - } - return srvs.Endpoints, nil -} diff --git a/vendor/go.etcd.io/etcd/client/doc.go b/vendor/go.etcd.io/etcd/client/doc.go deleted file mode 100644 index ad4eca4e1635..000000000000 --- a/vendor/go.etcd.io/etcd/client/doc.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package client provides bindings for the etcd APIs. - -Create a Config and exchange it for a Client: - - import ( - "net/http" - "context" - - "github.com/coreos/etcd/client" - ) - - cfg := client.Config{ - Endpoints: []string{"http://127.0.0.1:2379"}, - Transport: DefaultTransport, - } - - c, err := client.New(cfg) - if err != nil { - // handle error - } - -Clients are safe for concurrent use by multiple goroutines. - -Create a KeysAPI using the Client, then use it to interact with etcd: - - kAPI := client.NewKeysAPI(c) - - // create a new key /foo with the value "bar" - _, err = kAPI.Create(context.Background(), "/foo", "bar") - if err != nil { - // handle error - } - - // delete the newly created key only if the value is still "bar" - _, err = kAPI.Delete(context.Background(), "/foo", &DeleteOptions{PrevValue: "bar"}) - if err != nil { - // handle error - } - -Use a custom context to set timeouts on your operations: - - import "time" - - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - - // set a new key, ignoring its previous state - _, err := kAPI.Set(ctx, "/ping", "pong", nil) - if err != nil { - if err == context.DeadlineExceeded { - // request took longer than 5s - } else { - // handle error - } - } - -*/ -package client diff --git a/vendor/go.etcd.io/etcd/client/json.go b/vendor/go.etcd.io/etcd/client/json.go deleted file mode 100644 index 97cdbcd7cfa5..000000000000 --- a/vendor/go.etcd.io/etcd/client/json.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2019 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "github.com/json-iterator/go" - "github.com/modern-go/reflect2" - "strconv" - "unsafe" -) - -type customNumberExtension struct { - jsoniter.DummyExtension -} - -func (cne *customNumberExtension) CreateDecoder(typ reflect2.Type) jsoniter.ValDecoder { - if typ.String() == "interface {}" { - return customNumberDecoder{} - } - return nil -} - -type customNumberDecoder struct { -} - -func (customNumberDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { - switch iter.WhatIsNext() { - case jsoniter.NumberValue: - var number jsoniter.Number - iter.ReadVal(&number) - i64, err := strconv.ParseInt(string(number), 10, 64) - if err == nil { - *(*interface{})(ptr) = i64 - return - } - f64, err := strconv.ParseFloat(string(number), 64) - if err == nil { - *(*interface{})(ptr) = f64 - return - } - iter.ReportError("DecodeNumber", err.Error()) - default: - *(*interface{})(ptr) = iter.Read() - } -} - -// caseSensitiveJsonIterator returns a jsoniterator API that's configured to be -// case-sensitive when unmarshalling, and otherwise compatible with -// the encoding/json standard library. -func caseSensitiveJsonIterator() jsoniter.API { - config := jsoniter.Config{ - EscapeHTML: true, - SortMapKeys: true, - ValidateJsonRawMessage: true, - CaseSensitive: true, - }.Froze() - // Force jsoniter to decode number to interface{} via int64/float64, if possible. - config.RegisterExtension(&customNumberExtension{}) - return config -} diff --git a/vendor/go.etcd.io/etcd/client/keys.go b/vendor/go.etcd.io/etcd/client/keys.go deleted file mode 100644 index f8f2c7b186c2..000000000000 --- a/vendor/go.etcd.io/etcd/client/keys.go +++ /dev/null @@ -1,680 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "net/url" - "strconv" - "strings" - "time" - - "github.com/coreos/etcd/pkg/pathutil" -) - -const ( - ErrorCodeKeyNotFound = 100 - ErrorCodeTestFailed = 101 - ErrorCodeNotFile = 102 - ErrorCodeNotDir = 104 - ErrorCodeNodeExist = 105 - ErrorCodeRootROnly = 107 - ErrorCodeDirNotEmpty = 108 - ErrorCodeUnauthorized = 110 - - ErrorCodePrevValueRequired = 201 - ErrorCodeTTLNaN = 202 - ErrorCodeIndexNaN = 203 - ErrorCodeInvalidField = 209 - ErrorCodeInvalidForm = 210 - - ErrorCodeRaftInternal = 300 - ErrorCodeLeaderElect = 301 - - ErrorCodeWatcherCleared = 400 - ErrorCodeEventIndexCleared = 401 -) - -type Error struct { - Code int `json:"errorCode"` - Message string `json:"message"` - Cause string `json:"cause"` - Index uint64 `json:"index"` -} - -func (e Error) Error() string { - return fmt.Sprintf("%v: %v (%v) [%v]", e.Code, e.Message, e.Cause, e.Index) -} - -var ( - ErrInvalidJSON = errors.New("client: response is invalid json. The endpoint is probably not valid etcd cluster endpoint.") - ErrEmptyBody = errors.New("client: response body is empty") -) - -// PrevExistType is used to define an existence condition when setting -// or deleting Nodes. -type PrevExistType string - -const ( - PrevIgnore = PrevExistType("") - PrevExist = PrevExistType("true") - PrevNoExist = PrevExistType("false") -) - -var ( - defaultV2KeysPrefix = "/v2/keys" -) - -// NewKeysAPI builds a KeysAPI that interacts with etcd's key-value -// API over HTTP. -func NewKeysAPI(c Client) KeysAPI { - return NewKeysAPIWithPrefix(c, defaultV2KeysPrefix) -} - -// NewKeysAPIWithPrefix acts like NewKeysAPI, but allows the caller -// to provide a custom base URL path. This should only be used in -// very rare cases. -func NewKeysAPIWithPrefix(c Client, p string) KeysAPI { - return &httpKeysAPI{ - client: c, - prefix: p, - } -} - -type KeysAPI interface { - // Get retrieves a set of Nodes from etcd - Get(ctx context.Context, key string, opts *GetOptions) (*Response, error) - - // Set assigns a new value to a Node identified by a given key. The caller - // may define a set of conditions in the SetOptions. If SetOptions.Dir=true - // then value is ignored. - Set(ctx context.Context, key, value string, opts *SetOptions) (*Response, error) - - // Delete removes a Node identified by the given key, optionally destroying - // all of its children as well. The caller may define a set of required - // conditions in an DeleteOptions object. - Delete(ctx context.Context, key string, opts *DeleteOptions) (*Response, error) - - // Create is an alias for Set w/ PrevExist=false - Create(ctx context.Context, key, value string) (*Response, error) - - // CreateInOrder is used to atomically create in-order keys within the given directory. - CreateInOrder(ctx context.Context, dir, value string, opts *CreateInOrderOptions) (*Response, error) - - // Update is an alias for Set w/ PrevExist=true - Update(ctx context.Context, key, value string) (*Response, error) - - // Watcher builds a new Watcher targeted at a specific Node identified - // by the given key. The Watcher may be configured at creation time - // through a WatcherOptions object. The returned Watcher is designed - // to emit events that happen to a Node, and optionally to its children. - Watcher(key string, opts *WatcherOptions) Watcher -} - -type WatcherOptions struct { - // AfterIndex defines the index after-which the Watcher should - // start emitting events. For example, if a value of 5 is - // provided, the first event will have an index >= 6. - // - // Setting AfterIndex to 0 (default) means that the Watcher - // should start watching for events starting at the current - // index, whatever that may be. - AfterIndex uint64 - - // Recursive specifies whether or not the Watcher should emit - // events that occur in children of the given keyspace. If set - // to false (default), events will be limited to those that - // occur for the exact key. - Recursive bool -} - -type CreateInOrderOptions struct { - // TTL defines a period of time after-which the Node should - // expire and no longer exist. Values <= 0 are ignored. Given - // that the zero-value is ignored, TTL cannot be used to set - // a TTL of 0. - TTL time.Duration -} - -type SetOptions struct { - // PrevValue specifies what the current value of the Node must - // be in order for the Set operation to succeed. - // - // Leaving this field empty means that the caller wishes to - // ignore the current value of the Node. This cannot be used - // to compare the Node's current value to an empty string. - // - // PrevValue is ignored if Dir=true - PrevValue string - - // PrevIndex indicates what the current ModifiedIndex of the - // Node must be in order for the Set operation to succeed. - // - // If PrevIndex is set to 0 (default), no comparison is made. - PrevIndex uint64 - - // PrevExist specifies whether the Node must currently exist - // (PrevExist) or not (PrevNoExist). If the caller does not - // care about existence, set PrevExist to PrevIgnore, or simply - // leave it unset. - PrevExist PrevExistType - - // TTL defines a period of time after-which the Node should - // expire and no longer exist. Values <= 0 are ignored. Given - // that the zero-value is ignored, TTL cannot be used to set - // a TTL of 0. - TTL time.Duration - - // Refresh set to true means a TTL value can be updated - // without firing a watch or changing the node value. A - // value must not be provided when refreshing a key. - Refresh bool - - // Dir specifies whether or not this Node should be created as a directory. - Dir bool - - // NoValueOnSuccess specifies whether the response contains the current value of the Node. - // If set, the response will only contain the current value when the request fails. - NoValueOnSuccess bool -} - -type GetOptions struct { - // Recursive defines whether or not all children of the Node - // should be returned. - Recursive bool - - // Sort instructs the server whether or not to sort the Nodes. - // If true, the Nodes are sorted alphabetically by key in - // ascending order (A to z). If false (default), the Nodes will - // not be sorted and the ordering used should not be considered - // predictable. - Sort bool - - // Quorum specifies whether it gets the latest committed value that - // has been applied in quorum of members, which ensures external - // consistency (or linearizability). - Quorum bool -} - -type DeleteOptions struct { - // PrevValue specifies what the current value of the Node must - // be in order for the Delete operation to succeed. - // - // Leaving this field empty means that the caller wishes to - // ignore the current value of the Node. This cannot be used - // to compare the Node's current value to an empty string. - PrevValue string - - // PrevIndex indicates what the current ModifiedIndex of the - // Node must be in order for the Delete operation to succeed. - // - // If PrevIndex is set to 0 (default), no comparison is made. - PrevIndex uint64 - - // Recursive defines whether or not all children of the Node - // should be deleted. If set to true, all children of the Node - // identified by the given key will be deleted. If left unset - // or explicitly set to false, only a single Node will be - // deleted. - Recursive bool - - // Dir specifies whether or not this Node should be removed as a directory. - Dir bool -} - -type Watcher interface { - // Next blocks until an etcd event occurs, then returns a Response - // representing that event. The behavior of Next depends on the - // WatcherOptions used to construct the Watcher. Next is designed to - // be called repeatedly, each time blocking until a subsequent event - // is available. - // - // If the provided context is cancelled, Next will return a non-nil - // error. Any other failures encountered while waiting for the next - // event (connection issues, deserialization failures, etc) will - // also result in a non-nil error. - Next(context.Context) (*Response, error) -} - -type Response struct { - // Action is the name of the operation that occurred. Possible values - // include get, set, delete, update, create, compareAndSwap, - // compareAndDelete and expire. - Action string `json:"action"` - - // Node represents the state of the relevant etcd Node. - Node *Node `json:"node"` - - // PrevNode represents the previous state of the Node. PrevNode is non-nil - // only if the Node existed before the action occurred and the action - // caused a change to the Node. - PrevNode *Node `json:"prevNode"` - - // Index holds the cluster-level index at the time the Response was generated. - // This index is not tied to the Node(s) contained in this Response. - Index uint64 `json:"-"` - - // ClusterID holds the cluster-level ID reported by the server. This - // should be different for different etcd clusters. - ClusterID string `json:"-"` -} - -type Node struct { - // Key represents the unique location of this Node (e.g. "/foo/bar"). - Key string `json:"key"` - - // Dir reports whether node describes a directory. - Dir bool `json:"dir,omitempty"` - - // Value is the current data stored on this Node. If this Node - // is a directory, Value will be empty. - Value string `json:"value"` - - // Nodes holds the children of this Node, only if this Node is a directory. - // This slice of will be arbitrarily deep (children, grandchildren, great- - // grandchildren, etc.) if a recursive Get or Watch request were made. - Nodes Nodes `json:"nodes"` - - // CreatedIndex is the etcd index at-which this Node was created. - CreatedIndex uint64 `json:"createdIndex"` - - // ModifiedIndex is the etcd index at-which this Node was last modified. - ModifiedIndex uint64 `json:"modifiedIndex"` - - // Expiration is the server side expiration time of the key. - Expiration *time.Time `json:"expiration,omitempty"` - - // TTL is the time to live of the key in second. - TTL int64 `json:"ttl,omitempty"` -} - -func (n *Node) String() string { - return fmt.Sprintf("{Key: %s, CreatedIndex: %d, ModifiedIndex: %d, TTL: %d}", n.Key, n.CreatedIndex, n.ModifiedIndex, n.TTL) -} - -// TTLDuration returns the Node's TTL as a time.Duration object -func (n *Node) TTLDuration() time.Duration { - return time.Duration(n.TTL) * time.Second -} - -type Nodes []*Node - -// interfaces for sorting - -func (ns Nodes) Len() int { return len(ns) } -func (ns Nodes) Less(i, j int) bool { return ns[i].Key < ns[j].Key } -func (ns Nodes) Swap(i, j int) { ns[i], ns[j] = ns[j], ns[i] } - -type httpKeysAPI struct { - client httpClient - prefix string -} - -func (k *httpKeysAPI) Set(ctx context.Context, key, val string, opts *SetOptions) (*Response, error) { - act := &setAction{ - Prefix: k.prefix, - Key: key, - Value: val, - } - - if opts != nil { - act.PrevValue = opts.PrevValue - act.PrevIndex = opts.PrevIndex - act.PrevExist = opts.PrevExist - act.TTL = opts.TTL - act.Refresh = opts.Refresh - act.Dir = opts.Dir - act.NoValueOnSuccess = opts.NoValueOnSuccess - } - - doCtx := ctx - if act.PrevExist == PrevNoExist { - doCtx = context.WithValue(doCtx, &oneShotCtxValue, &oneShotCtxValue) - } - resp, body, err := k.client.Do(doCtx, act) - if err != nil { - return nil, err - } - - return unmarshalHTTPResponse(resp.StatusCode, resp.Header, body) -} - -func (k *httpKeysAPI) Create(ctx context.Context, key, val string) (*Response, error) { - return k.Set(ctx, key, val, &SetOptions{PrevExist: PrevNoExist}) -} - -func (k *httpKeysAPI) CreateInOrder(ctx context.Context, dir, val string, opts *CreateInOrderOptions) (*Response, error) { - act := &createInOrderAction{ - Prefix: k.prefix, - Dir: dir, - Value: val, - } - - if opts != nil { - act.TTL = opts.TTL - } - - resp, body, err := k.client.Do(ctx, act) - if err != nil { - return nil, err - } - - return unmarshalHTTPResponse(resp.StatusCode, resp.Header, body) -} - -func (k *httpKeysAPI) Update(ctx context.Context, key, val string) (*Response, error) { - return k.Set(ctx, key, val, &SetOptions{PrevExist: PrevExist}) -} - -func (k *httpKeysAPI) Delete(ctx context.Context, key string, opts *DeleteOptions) (*Response, error) { - act := &deleteAction{ - Prefix: k.prefix, - Key: key, - } - - if opts != nil { - act.PrevValue = opts.PrevValue - act.PrevIndex = opts.PrevIndex - act.Dir = opts.Dir - act.Recursive = opts.Recursive - } - - doCtx := context.WithValue(ctx, &oneShotCtxValue, &oneShotCtxValue) - resp, body, err := k.client.Do(doCtx, act) - if err != nil { - return nil, err - } - - return unmarshalHTTPResponse(resp.StatusCode, resp.Header, body) -} - -func (k *httpKeysAPI) Get(ctx context.Context, key string, opts *GetOptions) (*Response, error) { - act := &getAction{ - Prefix: k.prefix, - Key: key, - } - - if opts != nil { - act.Recursive = opts.Recursive - act.Sorted = opts.Sort - act.Quorum = opts.Quorum - } - - resp, body, err := k.client.Do(ctx, act) - if err != nil { - return nil, err - } - - return unmarshalHTTPResponse(resp.StatusCode, resp.Header, body) -} - -func (k *httpKeysAPI) Watcher(key string, opts *WatcherOptions) Watcher { - act := waitAction{ - Prefix: k.prefix, - Key: key, - } - - if opts != nil { - act.Recursive = opts.Recursive - if opts.AfterIndex > 0 { - act.WaitIndex = opts.AfterIndex + 1 - } - } - - return &httpWatcher{ - client: k.client, - nextWait: act, - } -} - -type httpWatcher struct { - client httpClient - nextWait waitAction -} - -func (hw *httpWatcher) Next(ctx context.Context) (*Response, error) { - for { - httpresp, body, err := hw.client.Do(ctx, &hw.nextWait) - if err != nil { - return nil, err - } - - resp, err := unmarshalHTTPResponse(httpresp.StatusCode, httpresp.Header, body) - if err != nil { - if err == ErrEmptyBody { - continue - } - return nil, err - } - - hw.nextWait.WaitIndex = resp.Node.ModifiedIndex + 1 - return resp, nil - } -} - -// v2KeysURL forms a URL representing the location of a key. -// The endpoint argument represents the base URL of an etcd -// server. The prefix is the path needed to route from the -// provided endpoint's path to the root of the keys API -// (typically "/v2/keys"). -func v2KeysURL(ep url.URL, prefix, key string) *url.URL { - // We concatenate all parts together manually. We cannot use - // path.Join because it does not reserve trailing slash. - // We call CanonicalURLPath to further cleanup the path. - if prefix != "" && prefix[0] != '/' { - prefix = "/" + prefix - } - if key != "" && key[0] != '/' { - key = "/" + key - } - ep.Path = pathutil.CanonicalURLPath(ep.Path + prefix + key) - return &ep -} - -type getAction struct { - Prefix string - Key string - Recursive bool - Sorted bool - Quorum bool -} - -func (g *getAction) HTTPRequest(ep url.URL) *http.Request { - u := v2KeysURL(ep, g.Prefix, g.Key) - - params := u.Query() - params.Set("recursive", strconv.FormatBool(g.Recursive)) - params.Set("sorted", strconv.FormatBool(g.Sorted)) - params.Set("quorum", strconv.FormatBool(g.Quorum)) - u.RawQuery = params.Encode() - - req, _ := http.NewRequest("GET", u.String(), nil) - return req -} - -type waitAction struct { - Prefix string - Key string - WaitIndex uint64 - Recursive bool -} - -func (w *waitAction) HTTPRequest(ep url.URL) *http.Request { - u := v2KeysURL(ep, w.Prefix, w.Key) - - params := u.Query() - params.Set("wait", "true") - params.Set("waitIndex", strconv.FormatUint(w.WaitIndex, 10)) - params.Set("recursive", strconv.FormatBool(w.Recursive)) - u.RawQuery = params.Encode() - - req, _ := http.NewRequest("GET", u.String(), nil) - return req -} - -type setAction struct { - Prefix string - Key string - Value string - PrevValue string - PrevIndex uint64 - PrevExist PrevExistType - TTL time.Duration - Refresh bool - Dir bool - NoValueOnSuccess bool -} - -func (a *setAction) HTTPRequest(ep url.URL) *http.Request { - u := v2KeysURL(ep, a.Prefix, a.Key) - - params := u.Query() - form := url.Values{} - - // we're either creating a directory or setting a key - if a.Dir { - params.Set("dir", strconv.FormatBool(a.Dir)) - } else { - // These options are only valid for setting a key - if a.PrevValue != "" { - params.Set("prevValue", a.PrevValue) - } - form.Add("value", a.Value) - } - - // Options which apply to both setting a key and creating a dir - if a.PrevIndex != 0 { - params.Set("prevIndex", strconv.FormatUint(a.PrevIndex, 10)) - } - if a.PrevExist != PrevIgnore { - params.Set("prevExist", string(a.PrevExist)) - } - if a.TTL > 0 { - form.Add("ttl", strconv.FormatUint(uint64(a.TTL.Seconds()), 10)) - } - - if a.Refresh { - form.Add("refresh", "true") - } - if a.NoValueOnSuccess { - params.Set("noValueOnSuccess", strconv.FormatBool(a.NoValueOnSuccess)) - } - - u.RawQuery = params.Encode() - body := strings.NewReader(form.Encode()) - - req, _ := http.NewRequest("PUT", u.String(), body) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - - return req -} - -type deleteAction struct { - Prefix string - Key string - PrevValue string - PrevIndex uint64 - Dir bool - Recursive bool -} - -func (a *deleteAction) HTTPRequest(ep url.URL) *http.Request { - u := v2KeysURL(ep, a.Prefix, a.Key) - - params := u.Query() - if a.PrevValue != "" { - params.Set("prevValue", a.PrevValue) - } - if a.PrevIndex != 0 { - params.Set("prevIndex", strconv.FormatUint(a.PrevIndex, 10)) - } - if a.Dir { - params.Set("dir", "true") - } - if a.Recursive { - params.Set("recursive", "true") - } - u.RawQuery = params.Encode() - - req, _ := http.NewRequest("DELETE", u.String(), nil) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - - return req -} - -type createInOrderAction struct { - Prefix string - Dir string - Value string - TTL time.Duration -} - -func (a *createInOrderAction) HTTPRequest(ep url.URL) *http.Request { - u := v2KeysURL(ep, a.Prefix, a.Dir) - - form := url.Values{} - form.Add("value", a.Value) - if a.TTL > 0 { - form.Add("ttl", strconv.FormatUint(uint64(a.TTL.Seconds()), 10)) - } - body := strings.NewReader(form.Encode()) - - req, _ := http.NewRequest("POST", u.String(), body) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - return req -} - -func unmarshalHTTPResponse(code int, header http.Header, body []byte) (res *Response, err error) { - switch code { - case http.StatusOK, http.StatusCreated: - if len(body) == 0 { - return nil, ErrEmptyBody - } - res, err = unmarshalSuccessfulKeysResponse(header, body) - default: - err = unmarshalFailedKeysResponse(body) - } - return res, err -} - -var jsonIterator = caseSensitiveJsonIterator() - -func unmarshalSuccessfulKeysResponse(header http.Header, body []byte) (*Response, error) { - var res Response - err := jsonIterator.Unmarshal(body, &res) - if err != nil { - return nil, ErrInvalidJSON - } - if header.Get("X-Etcd-Index") != "" { - res.Index, err = strconv.ParseUint(header.Get("X-Etcd-Index"), 10, 64) - if err != nil { - return nil, err - } - } - res.ClusterID = header.Get("X-Etcd-Cluster-ID") - return &res, nil -} - -func unmarshalFailedKeysResponse(body []byte) error { - var etcdErr Error - if err := json.Unmarshal(body, &etcdErr); err != nil { - return ErrInvalidJSON - } - return etcdErr -} diff --git a/vendor/go.etcd.io/etcd/client/members.go b/vendor/go.etcd.io/etcd/client/members.go deleted file mode 100644 index aafa3d1b8706..000000000000 --- a/vendor/go.etcd.io/etcd/client/members.go +++ /dev/null @@ -1,303 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "bytes" - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - "path" - - "github.com/coreos/etcd/pkg/types" -) - -var ( - defaultV2MembersPrefix = "/v2/members" - defaultLeaderSuffix = "/leader" -) - -type Member struct { - // ID is the unique identifier of this Member. - ID string `json:"id"` - - // Name is a human-readable, non-unique identifier of this Member. - Name string `json:"name"` - - // PeerURLs represents the HTTP(S) endpoints this Member uses to - // participate in etcd's consensus protocol. - PeerURLs []string `json:"peerURLs"` - - // ClientURLs represents the HTTP(S) endpoints on which this Member - // serves its client-facing APIs. - ClientURLs []string `json:"clientURLs"` -} - -type memberCollection []Member - -func (c *memberCollection) UnmarshalJSON(data []byte) error { - d := struct { - Members []Member - }{} - - if err := json.Unmarshal(data, &d); err != nil { - return err - } - - if d.Members == nil { - *c = make([]Member, 0) - return nil - } - - *c = d.Members - return nil -} - -type memberCreateOrUpdateRequest struct { - PeerURLs types.URLs -} - -func (m *memberCreateOrUpdateRequest) MarshalJSON() ([]byte, error) { - s := struct { - PeerURLs []string `json:"peerURLs"` - }{ - PeerURLs: make([]string, len(m.PeerURLs)), - } - - for i, u := range m.PeerURLs { - s.PeerURLs[i] = u.String() - } - - return json.Marshal(&s) -} - -// NewMembersAPI constructs a new MembersAPI that uses HTTP to -// interact with etcd's membership API. -func NewMembersAPI(c Client) MembersAPI { - return &httpMembersAPI{ - client: c, - } -} - -type MembersAPI interface { - // List enumerates the current cluster membership. - List(ctx context.Context) ([]Member, error) - - // Add instructs etcd to accept a new Member into the cluster. - Add(ctx context.Context, peerURL string) (*Member, error) - - // Remove demotes an existing Member out of the cluster. - Remove(ctx context.Context, mID string) error - - // Update instructs etcd to update an existing Member in the cluster. - Update(ctx context.Context, mID string, peerURLs []string) error - - // Leader gets current leader of the cluster - Leader(ctx context.Context) (*Member, error) -} - -type httpMembersAPI struct { - client httpClient -} - -func (m *httpMembersAPI) List(ctx context.Context) ([]Member, error) { - req := &membersAPIActionList{} - resp, body, err := m.client.Do(ctx, req) - if err != nil { - return nil, err - } - - if err := assertStatusCode(resp.StatusCode, http.StatusOK); err != nil { - return nil, err - } - - var mCollection memberCollection - if err := json.Unmarshal(body, &mCollection); err != nil { - return nil, err - } - - return []Member(mCollection), nil -} - -func (m *httpMembersAPI) Add(ctx context.Context, peerURL string) (*Member, error) { - urls, err := types.NewURLs([]string{peerURL}) - if err != nil { - return nil, err - } - - req := &membersAPIActionAdd{peerURLs: urls} - resp, body, err := m.client.Do(ctx, req) - if err != nil { - return nil, err - } - - if err := assertStatusCode(resp.StatusCode, http.StatusCreated, http.StatusConflict); err != nil { - return nil, err - } - - if resp.StatusCode != http.StatusCreated { - var merr membersError - if err := json.Unmarshal(body, &merr); err != nil { - return nil, err - } - return nil, merr - } - - var memb Member - if err := json.Unmarshal(body, &memb); err != nil { - return nil, err - } - - return &memb, nil -} - -func (m *httpMembersAPI) Update(ctx context.Context, memberID string, peerURLs []string) error { - urls, err := types.NewURLs(peerURLs) - if err != nil { - return err - } - - req := &membersAPIActionUpdate{peerURLs: urls, memberID: memberID} - resp, body, err := m.client.Do(ctx, req) - if err != nil { - return err - } - - if err := assertStatusCode(resp.StatusCode, http.StatusNoContent, http.StatusNotFound, http.StatusConflict); err != nil { - return err - } - - if resp.StatusCode != http.StatusNoContent { - var merr membersError - if err := json.Unmarshal(body, &merr); err != nil { - return err - } - return merr - } - - return nil -} - -func (m *httpMembersAPI) Remove(ctx context.Context, memberID string) error { - req := &membersAPIActionRemove{memberID: memberID} - resp, _, err := m.client.Do(ctx, req) - if err != nil { - return err - } - - return assertStatusCode(resp.StatusCode, http.StatusNoContent, http.StatusGone) -} - -func (m *httpMembersAPI) Leader(ctx context.Context) (*Member, error) { - req := &membersAPIActionLeader{} - resp, body, err := m.client.Do(ctx, req) - if err != nil { - return nil, err - } - - if err := assertStatusCode(resp.StatusCode, http.StatusOK); err != nil { - return nil, err - } - - var leader Member - if err := json.Unmarshal(body, &leader); err != nil { - return nil, err - } - - return &leader, nil -} - -type membersAPIActionList struct{} - -func (l *membersAPIActionList) HTTPRequest(ep url.URL) *http.Request { - u := v2MembersURL(ep) - req, _ := http.NewRequest("GET", u.String(), nil) - return req -} - -type membersAPIActionRemove struct { - memberID string -} - -func (d *membersAPIActionRemove) HTTPRequest(ep url.URL) *http.Request { - u := v2MembersURL(ep) - u.Path = path.Join(u.Path, d.memberID) - req, _ := http.NewRequest("DELETE", u.String(), nil) - return req -} - -type membersAPIActionAdd struct { - peerURLs types.URLs -} - -func (a *membersAPIActionAdd) HTTPRequest(ep url.URL) *http.Request { - u := v2MembersURL(ep) - m := memberCreateOrUpdateRequest{PeerURLs: a.peerURLs} - b, _ := json.Marshal(&m) - req, _ := http.NewRequest("POST", u.String(), bytes.NewReader(b)) - req.Header.Set("Content-Type", "application/json") - return req -} - -type membersAPIActionUpdate struct { - memberID string - peerURLs types.URLs -} - -func (a *membersAPIActionUpdate) HTTPRequest(ep url.URL) *http.Request { - u := v2MembersURL(ep) - m := memberCreateOrUpdateRequest{PeerURLs: a.peerURLs} - u.Path = path.Join(u.Path, a.memberID) - b, _ := json.Marshal(&m) - req, _ := http.NewRequest("PUT", u.String(), bytes.NewReader(b)) - req.Header.Set("Content-Type", "application/json") - return req -} - -func assertStatusCode(got int, want ...int) (err error) { - for _, w := range want { - if w == got { - return nil - } - } - return fmt.Errorf("unexpected status code %d", got) -} - -type membersAPIActionLeader struct{} - -func (l *membersAPIActionLeader) HTTPRequest(ep url.URL) *http.Request { - u := v2MembersURL(ep) - u.Path = path.Join(u.Path, defaultLeaderSuffix) - req, _ := http.NewRequest("GET", u.String(), nil) - return req -} - -// v2MembersURL add the necessary path to the provided endpoint -// to route requests to the default v2 members API. -func v2MembersURL(ep url.URL) *url.URL { - ep.Path = path.Join(ep.Path, defaultV2MembersPrefix) - return &ep -} - -type membersError struct { - Message string `json:"message"` - Code int `json:"-"` -} - -func (e membersError) Error() string { - return e.Message -} diff --git a/vendor/go.etcd.io/etcd/client/util.go b/vendor/go.etcd.io/etcd/client/util.go deleted file mode 100644 index 15a8babff4d4..000000000000 --- a/vendor/go.etcd.io/etcd/client/util.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "regexp" -) - -var ( - roleNotFoundRegExp *regexp.Regexp - userNotFoundRegExp *regexp.Regexp -) - -func init() { - roleNotFoundRegExp = regexp.MustCompile("auth: Role .* does not exist.") - userNotFoundRegExp = regexp.MustCompile("auth: User .* does not exist.") -} - -// IsKeyNotFound returns true if the error code is ErrorCodeKeyNotFound. -func IsKeyNotFound(err error) bool { - if cErr, ok := err.(Error); ok { - return cErr.Code == ErrorCodeKeyNotFound - } - return false -} - -// IsRoleNotFound returns true if the error means role not found of v2 API. -func IsRoleNotFound(err error) bool { - if ae, ok := err.(authError); ok { - return roleNotFoundRegExp.MatchString(ae.Message) - } - return false -} - -// IsUserNotFound returns true if the error means user not found of v2 API. -func IsUserNotFound(err error) bool { - if ae, ok := err.(authError); ok { - return userNotFoundRegExp.MatchString(ae.Message) - } - return false -} diff --git a/vendor/go.etcd.io/etcd/clientv3/auth.go b/vendor/go.etcd.io/etcd/clientv3/auth.go deleted file mode 100644 index 7545bb6ca1ca..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/auth.go +++ /dev/null @@ -1,233 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - "fmt" - "strings" - - "github.com/coreos/etcd/auth/authpb" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" -) - -type ( - AuthEnableResponse pb.AuthEnableResponse - AuthDisableResponse pb.AuthDisableResponse - AuthenticateResponse pb.AuthenticateResponse - AuthUserAddResponse pb.AuthUserAddResponse - AuthUserDeleteResponse pb.AuthUserDeleteResponse - AuthUserChangePasswordResponse pb.AuthUserChangePasswordResponse - AuthUserGrantRoleResponse pb.AuthUserGrantRoleResponse - AuthUserGetResponse pb.AuthUserGetResponse - AuthUserRevokeRoleResponse pb.AuthUserRevokeRoleResponse - AuthRoleAddResponse pb.AuthRoleAddResponse - AuthRoleGrantPermissionResponse pb.AuthRoleGrantPermissionResponse - AuthRoleGetResponse pb.AuthRoleGetResponse - AuthRoleRevokePermissionResponse pb.AuthRoleRevokePermissionResponse - AuthRoleDeleteResponse pb.AuthRoleDeleteResponse - AuthUserListResponse pb.AuthUserListResponse - AuthRoleListResponse pb.AuthRoleListResponse - - PermissionType authpb.Permission_Type - Permission authpb.Permission -) - -const ( - PermRead = authpb.READ - PermWrite = authpb.WRITE - PermReadWrite = authpb.READWRITE -) - -type Auth interface { - // AuthEnable enables auth of an etcd cluster. - AuthEnable(ctx context.Context) (*AuthEnableResponse, error) - - // AuthDisable disables auth of an etcd cluster. - AuthDisable(ctx context.Context) (*AuthDisableResponse, error) - - // UserAdd adds a new user to an etcd cluster. - UserAdd(ctx context.Context, name string, password string) (*AuthUserAddResponse, error) - - // UserDelete deletes a user from an etcd cluster. - UserDelete(ctx context.Context, name string) (*AuthUserDeleteResponse, error) - - // UserChangePassword changes a password of a user. - UserChangePassword(ctx context.Context, name string, password string) (*AuthUserChangePasswordResponse, error) - - // UserGrantRole grants a role to a user. - UserGrantRole(ctx context.Context, user string, role string) (*AuthUserGrantRoleResponse, error) - - // UserGet gets a detailed information of a user. - UserGet(ctx context.Context, name string) (*AuthUserGetResponse, error) - - // UserList gets a list of all users. - UserList(ctx context.Context) (*AuthUserListResponse, error) - - // UserRevokeRole revokes a role of a user. - UserRevokeRole(ctx context.Context, name string, role string) (*AuthUserRevokeRoleResponse, error) - - // RoleAdd adds a new role to an etcd cluster. - RoleAdd(ctx context.Context, name string) (*AuthRoleAddResponse, error) - - // RoleGrantPermission grants a permission to a role. - RoleGrantPermission(ctx context.Context, name string, key, rangeEnd string, permType PermissionType) (*AuthRoleGrantPermissionResponse, error) - - // RoleGet gets a detailed information of a role. - RoleGet(ctx context.Context, role string) (*AuthRoleGetResponse, error) - - // RoleList gets a list of all roles. - RoleList(ctx context.Context) (*AuthRoleListResponse, error) - - // RoleRevokePermission revokes a permission from a role. - RoleRevokePermission(ctx context.Context, role string, key, rangeEnd string) (*AuthRoleRevokePermissionResponse, error) - - // RoleDelete deletes a role. - RoleDelete(ctx context.Context, role string) (*AuthRoleDeleteResponse, error) -} - -type auth struct { - remote pb.AuthClient - callOpts []grpc.CallOption -} - -func NewAuth(c *Client) Auth { - api := &auth{remote: RetryAuthClient(c)} - if c != nil { - api.callOpts = c.callOpts - } - return api -} - -func (auth *auth) AuthEnable(ctx context.Context) (*AuthEnableResponse, error) { - resp, err := auth.remote.AuthEnable(ctx, &pb.AuthEnableRequest{}, auth.callOpts...) - return (*AuthEnableResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) AuthDisable(ctx context.Context) (*AuthDisableResponse, error) { - resp, err := auth.remote.AuthDisable(ctx, &pb.AuthDisableRequest{}, auth.callOpts...) - return (*AuthDisableResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) UserAdd(ctx context.Context, name string, password string) (*AuthUserAddResponse, error) { - resp, err := auth.remote.UserAdd(ctx, &pb.AuthUserAddRequest{Name: name, Password: password}, auth.callOpts...) - return (*AuthUserAddResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) UserDelete(ctx context.Context, name string) (*AuthUserDeleteResponse, error) { - resp, err := auth.remote.UserDelete(ctx, &pb.AuthUserDeleteRequest{Name: name}, auth.callOpts...) - return (*AuthUserDeleteResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) UserChangePassword(ctx context.Context, name string, password string) (*AuthUserChangePasswordResponse, error) { - resp, err := auth.remote.UserChangePassword(ctx, &pb.AuthUserChangePasswordRequest{Name: name, Password: password}, auth.callOpts...) - return (*AuthUserChangePasswordResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) UserGrantRole(ctx context.Context, user string, role string) (*AuthUserGrantRoleResponse, error) { - resp, err := auth.remote.UserGrantRole(ctx, &pb.AuthUserGrantRoleRequest{User: user, Role: role}, auth.callOpts...) - return (*AuthUserGrantRoleResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) UserGet(ctx context.Context, name string) (*AuthUserGetResponse, error) { - resp, err := auth.remote.UserGet(ctx, &pb.AuthUserGetRequest{Name: name}, auth.callOpts...) - return (*AuthUserGetResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) UserList(ctx context.Context) (*AuthUserListResponse, error) { - resp, err := auth.remote.UserList(ctx, &pb.AuthUserListRequest{}, auth.callOpts...) - return (*AuthUserListResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) UserRevokeRole(ctx context.Context, name string, role string) (*AuthUserRevokeRoleResponse, error) { - resp, err := auth.remote.UserRevokeRole(ctx, &pb.AuthUserRevokeRoleRequest{Name: name, Role: role}, auth.callOpts...) - return (*AuthUserRevokeRoleResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) RoleAdd(ctx context.Context, name string) (*AuthRoleAddResponse, error) { - resp, err := auth.remote.RoleAdd(ctx, &pb.AuthRoleAddRequest{Name: name}, auth.callOpts...) - return (*AuthRoleAddResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) RoleGrantPermission(ctx context.Context, name string, key, rangeEnd string, permType PermissionType) (*AuthRoleGrantPermissionResponse, error) { - perm := &authpb.Permission{ - Key: []byte(key), - RangeEnd: []byte(rangeEnd), - PermType: authpb.Permission_Type(permType), - } - resp, err := auth.remote.RoleGrantPermission(ctx, &pb.AuthRoleGrantPermissionRequest{Name: name, Perm: perm}, auth.callOpts...) - return (*AuthRoleGrantPermissionResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) RoleGet(ctx context.Context, role string) (*AuthRoleGetResponse, error) { - resp, err := auth.remote.RoleGet(ctx, &pb.AuthRoleGetRequest{Role: role}, auth.callOpts...) - return (*AuthRoleGetResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) RoleList(ctx context.Context) (*AuthRoleListResponse, error) { - resp, err := auth.remote.RoleList(ctx, &pb.AuthRoleListRequest{}, auth.callOpts...) - return (*AuthRoleListResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) RoleRevokePermission(ctx context.Context, role string, key, rangeEnd string) (*AuthRoleRevokePermissionResponse, error) { - resp, err := auth.remote.RoleRevokePermission(ctx, &pb.AuthRoleRevokePermissionRequest{Role: role, Key: key, RangeEnd: rangeEnd}, auth.callOpts...) - return (*AuthRoleRevokePermissionResponse)(resp), toErr(ctx, err) -} - -func (auth *auth) RoleDelete(ctx context.Context, role string) (*AuthRoleDeleteResponse, error) { - resp, err := auth.remote.RoleDelete(ctx, &pb.AuthRoleDeleteRequest{Role: role}, auth.callOpts...) - return (*AuthRoleDeleteResponse)(resp), toErr(ctx, err) -} - -func StrToPermissionType(s string) (PermissionType, error) { - val, ok := authpb.Permission_Type_value[strings.ToUpper(s)] - if ok { - return PermissionType(val), nil - } - return PermissionType(-1), fmt.Errorf("invalid permission type: %s", s) -} - -type authenticator struct { - conn *grpc.ClientConn // conn in-use - remote pb.AuthClient - callOpts []grpc.CallOption -} - -func (auth *authenticator) authenticate(ctx context.Context, name string, password string) (*AuthenticateResponse, error) { - resp, err := auth.remote.Authenticate(ctx, &pb.AuthenticateRequest{Name: name, Password: password}, auth.callOpts...) - return (*AuthenticateResponse)(resp), toErr(ctx, err) -} - -func (auth *authenticator) close() { - auth.conn.Close() -} - -func newAuthenticator(endpoint string, opts []grpc.DialOption, c *Client) (*authenticator, error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return nil, err - } - - api := &authenticator{ - conn: conn, - remote: pb.NewAuthClient(conn), - } - if c != nil { - api.callOpts = c.callOpts - } - return api, nil -} diff --git a/vendor/go.etcd.io/etcd/clientv3/client.go b/vendor/go.etcd.io/etcd/clientv3/client.go deleted file mode 100644 index 78db5d4bfaf1..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/client.go +++ /dev/null @@ -1,578 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - "crypto/tls" - "errors" - "fmt" - "net" - "net/url" - "strconv" - "strings" - "sync" - "time" - - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/credentials" - "google.golang.org/grpc/keepalive" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" -) - -var ( - ErrNoAvailableEndpoints = errors.New("etcdclient: no available endpoints") - ErrOldCluster = errors.New("etcdclient: old cluster version") -) - -// Client provides and manages an etcd v3 client session. -type Client struct { - Cluster - KV - Lease - Watcher - Auth - Maintenance - - conn *grpc.ClientConn - dialerrc chan error - - cfg Config - creds *credentials.TransportCredentials - balancer *healthBalancer - mu *sync.RWMutex - - ctx context.Context - cancel context.CancelFunc - - // Username is a user name for authentication. - Username string - // Password is a password for authentication. - Password string - // tokenCred is an instance of WithPerRPCCredentials()'s argument - tokenCred *authTokenCredential - - callOpts []grpc.CallOption -} - -// New creates a new etcdv3 client from a given configuration. -func New(cfg Config) (*Client, error) { - if len(cfg.Endpoints) == 0 { - return nil, ErrNoAvailableEndpoints - } - - return newClient(&cfg) -} - -// NewCtxClient creates a client with a context but no underlying grpc -// connection. This is useful for embedded cases that override the -// service interface implementations and do not need connection management. -func NewCtxClient(ctx context.Context) *Client { - cctx, cancel := context.WithCancel(ctx) - return &Client{ctx: cctx, cancel: cancel} -} - -// NewFromURL creates a new etcdv3 client from a URL. -func NewFromURL(url string) (*Client, error) { - return New(Config{Endpoints: []string{url}}) -} - -// Close shuts down the client's etcd connections. -func (c *Client) Close() error { - c.cancel() - c.Watcher.Close() - c.Lease.Close() - if c.conn != nil { - return toErr(c.ctx, c.conn.Close()) - } - return c.ctx.Err() -} - -// Ctx is a context for "out of band" messages (e.g., for sending -// "clean up" message when another context is canceled). It is -// canceled on client Close(). -func (c *Client) Ctx() context.Context { return c.ctx } - -// Endpoints lists the registered endpoints for the client. -func (c *Client) Endpoints() []string { - c.mu.RLock() - defer c.mu.RUnlock() - // copy the slice; protect original endpoints from being changed - eps := make([]string, len(c.cfg.Endpoints)) - copy(eps, c.cfg.Endpoints) - return eps -} - -// SetEndpoints updates client's endpoints. -func (c *Client) SetEndpoints(eps ...string) { - c.mu.Lock() - c.cfg.Endpoints = eps - c.mu.Unlock() - c.balancer.updateAddrs(eps...) - - // updating notifyCh can trigger new connections, - // need update addrs if all connections are down - // or addrs does not include pinAddr. - c.balancer.mu.RLock() - update := !hasAddr(c.balancer.addrs, c.balancer.pinAddr) - c.balancer.mu.RUnlock() - if update { - select { - case c.balancer.updateAddrsC <- notifyNext: - case <-c.balancer.stopc: - } - } -} - -// Sync synchronizes client's endpoints with the known endpoints from the etcd membership. -func (c *Client) Sync(ctx context.Context) error { - mresp, err := c.MemberList(ctx) - if err != nil { - return err - } - var eps []string - for _, m := range mresp.Members { - eps = append(eps, m.ClientURLs...) - } - c.SetEndpoints(eps...) - return nil -} - -func (c *Client) autoSync() { - if c.cfg.AutoSyncInterval == time.Duration(0) { - return - } - - for { - select { - case <-c.ctx.Done(): - return - case <-time.After(c.cfg.AutoSyncInterval): - ctx, cancel := context.WithTimeout(c.ctx, 5*time.Second) - err := c.Sync(ctx) - cancel() - if err != nil && err != c.ctx.Err() { - logger.Println("Auto sync endpoints failed:", err) - } - } - } -} - -type authTokenCredential struct { - token string - tokenMu *sync.RWMutex -} - -func (cred authTokenCredential) RequireTransportSecurity() bool { - return false -} - -func (cred authTokenCredential) GetRequestMetadata(ctx context.Context, s ...string) (map[string]string, error) { - cred.tokenMu.RLock() - defer cred.tokenMu.RUnlock() - return map[string]string{ - "token": cred.token, - }, nil -} - -func parseEndpoint(endpoint string) (proto string, host string, scheme string) { - proto = "tcp" - host = endpoint - url, uerr := url.Parse(endpoint) - if uerr != nil || !strings.Contains(endpoint, "://") { - return proto, host, scheme - } - scheme = url.Scheme - - // strip scheme:// prefix since grpc dials by host - host = url.Host - switch url.Scheme { - case "http", "https": - case "unix", "unixs": - proto = "unix" - host = url.Host + url.Path - default: - proto, host = "", "" - } - return proto, host, scheme -} - -func (c *Client) processCreds(scheme string) (creds *credentials.TransportCredentials) { - creds = c.creds - switch scheme { - case "unix": - case "http": - creds = nil - case "https", "unixs": - if creds != nil { - break - } - tlsconfig := &tls.Config{} - emptyCreds := credentials.NewTLS(tlsconfig) - creds = &emptyCreds - default: - creds = nil - } - return creds -} - -// dialSetupOpts gives the dial opts prior to any authentication -func (c *Client) dialSetupOpts(endpoint string, dopts ...grpc.DialOption) (opts []grpc.DialOption) { - if c.cfg.DialTimeout > 0 { - opts = []grpc.DialOption{grpc.WithTimeout(c.cfg.DialTimeout)} - } - if c.cfg.DialKeepAliveTime > 0 { - params := keepalive.ClientParameters{ - Time: c.cfg.DialKeepAliveTime, - Timeout: c.cfg.DialKeepAliveTimeout, - } - opts = append(opts, grpc.WithKeepaliveParams(params)) - } - opts = append(opts, dopts...) - - f := func(host string, t time.Duration) (net.Conn, error) { - proto, host, _ := parseEndpoint(c.balancer.endpoint(host)) - if host == "" && endpoint != "" { - // dialing an endpoint not in the balancer; use - // endpoint passed into dial - proto, host, _ = parseEndpoint(endpoint) - } - if proto == "" { - return nil, fmt.Errorf("unknown scheme for %q", host) - } - select { - case <-c.ctx.Done(): - return nil, c.ctx.Err() - default: - } - dialer := &net.Dialer{Timeout: t} - conn, err := dialer.DialContext(c.ctx, proto, host) - if err != nil { - select { - case c.dialerrc <- err: - default: - } - } - return conn, err - } - opts = append(opts, grpc.WithDialer(f)) - - creds := c.creds - if _, _, scheme := parseEndpoint(endpoint); len(scheme) != 0 { - creds = c.processCreds(scheme) - } - if creds != nil { - opts = append(opts, grpc.WithTransportCredentials(*creds)) - } else { - opts = append(opts, grpc.WithInsecure()) - } - - return opts -} - -// Dial connects to a single endpoint using the client's config. -func (c *Client) Dial(endpoint string) (*grpc.ClientConn, error) { - return c.dial(endpoint) -} - -func (c *Client) getToken(ctx context.Context) error { - var err error // return last error in a case of fail - var auth *authenticator - - for i := 0; i < len(c.cfg.Endpoints); i++ { - endpoint := c.cfg.Endpoints[i] - host := getHost(endpoint) - // use dial options without dopts to avoid reusing the client balancer - auth, err = newAuthenticator(host, c.dialSetupOpts(endpoint), c) - if err != nil { - continue - } - defer auth.close() - - var resp *AuthenticateResponse - resp, err = auth.authenticate(ctx, c.Username, c.Password) - if err != nil { - continue - } - - c.tokenCred.tokenMu.Lock() - c.tokenCred.token = resp.Token - c.tokenCred.tokenMu.Unlock() - - return nil - } - - return err -} - -func (c *Client) dial(endpoint string, dopts ...grpc.DialOption) (*grpc.ClientConn, error) { - opts := c.dialSetupOpts(endpoint, dopts...) - host := getHost(endpoint) - if c.Username != "" && c.Password != "" { - c.tokenCred = &authTokenCredential{ - tokenMu: &sync.RWMutex{}, - } - - ctx := c.ctx - if c.cfg.DialTimeout > 0 { - cctx, cancel := context.WithTimeout(ctx, c.cfg.DialTimeout) - defer cancel() - ctx = cctx - } - - err := c.getToken(ctx) - if err != nil { - if toErr(ctx, err) != rpctypes.ErrAuthNotEnabled { - if err == ctx.Err() && ctx.Err() != c.ctx.Err() { - err = context.DeadlineExceeded - } - return nil, err - } - } else { - opts = append(opts, grpc.WithPerRPCCredentials(c.tokenCred)) - } - } - - opts = append(opts, c.cfg.DialOptions...) - - conn, err := grpc.DialContext(c.ctx, host, opts...) - if err != nil { - return nil, err - } - return conn, nil -} - -// WithRequireLeader requires client requests to only succeed -// when the cluster has a leader. -func WithRequireLeader(ctx context.Context) context.Context { - md := metadata.Pairs(rpctypes.MetadataRequireLeaderKey, rpctypes.MetadataHasLeader) - return metadata.NewOutgoingContext(ctx, md) -} - -func newClient(cfg *Config) (*Client, error) { - if cfg == nil { - cfg = &Config{} - } - var creds *credentials.TransportCredentials - if cfg.TLS != nil { - c := credentials.NewTLS(cfg.TLS) - creds = &c - } - - // use a temporary skeleton client to bootstrap first connection - baseCtx := context.TODO() - if cfg.Context != nil { - baseCtx = cfg.Context - } - - ctx, cancel := context.WithCancel(baseCtx) - client := &Client{ - conn: nil, - dialerrc: make(chan error, 1), - cfg: *cfg, - creds: creds, - ctx: ctx, - cancel: cancel, - mu: new(sync.RWMutex), - callOpts: defaultCallOpts, - } - if cfg.Username != "" && cfg.Password != "" { - client.Username = cfg.Username - client.Password = cfg.Password - } - if cfg.MaxCallSendMsgSize > 0 || cfg.MaxCallRecvMsgSize > 0 { - if cfg.MaxCallRecvMsgSize > 0 && cfg.MaxCallSendMsgSize > cfg.MaxCallRecvMsgSize { - return nil, fmt.Errorf("gRPC message recv limit (%d bytes) must be greater than send limit (%d bytes)", cfg.MaxCallRecvMsgSize, cfg.MaxCallSendMsgSize) - } - callOpts := []grpc.CallOption{ - defaultFailFast, - defaultMaxCallSendMsgSize, - defaultMaxCallRecvMsgSize, - } - if cfg.MaxCallSendMsgSize > 0 { - callOpts[1] = grpc.MaxCallSendMsgSize(cfg.MaxCallSendMsgSize) - } - if cfg.MaxCallRecvMsgSize > 0 { - callOpts[2] = grpc.MaxCallRecvMsgSize(cfg.MaxCallRecvMsgSize) - } - client.callOpts = callOpts - } - - client.balancer = newHealthBalancer(cfg.Endpoints, cfg.DialTimeout, func(ep string) (bool, error) { - return grpcHealthCheck(client, ep) - }) - - // use Endpoints[0] so that for https:// without any tls config given, then - // grpc will assume the certificate server name is the endpoint host. - conn, err := client.dial(cfg.Endpoints[0], grpc.WithBalancer(client.balancer)) - if err != nil { - client.cancel() - client.balancer.Close() - return nil, err - } - client.conn = conn - - // wait for a connection - if cfg.DialTimeout > 0 { - hasConn := false - waitc := time.After(cfg.DialTimeout) - select { - case <-client.balancer.ready(): - hasConn = true - case <-ctx.Done(): - case <-waitc: - } - if !hasConn { - err := context.DeadlineExceeded - select { - case err = <-client.dialerrc: - default: - } - client.cancel() - client.balancer.Close() - conn.Close() - return nil, err - } - } - - client.Cluster = NewCluster(client) - client.KV = NewKV(client) - client.Lease = NewLease(client) - client.Watcher = NewWatcher(client) - client.Auth = NewAuth(client) - client.Maintenance = NewMaintenance(client) - - if cfg.RejectOldCluster { - if err := client.checkVersion(); err != nil { - client.Close() - return nil, err - } - } - - go client.autoSync() - return client, nil -} - -func (c *Client) checkVersion() (err error) { - var wg sync.WaitGroup - errc := make(chan error, len(c.cfg.Endpoints)) - ctx, cancel := context.WithCancel(c.ctx) - if c.cfg.DialTimeout > 0 { - ctx, cancel = context.WithTimeout(ctx, c.cfg.DialTimeout) - } - wg.Add(len(c.cfg.Endpoints)) - for _, ep := range c.cfg.Endpoints { - // if cluster is current, any endpoint gives a recent version - go func(e string) { - defer wg.Done() - resp, rerr := c.Status(ctx, e) - if rerr != nil { - errc <- rerr - return - } - vs := strings.Split(resp.Version, ".") - maj, min := 0, 0 - if len(vs) >= 2 { - maj, _ = strconv.Atoi(vs[0]) - min, rerr = strconv.Atoi(vs[1]) - } - if maj < 3 || (maj == 3 && min < 2) { - rerr = ErrOldCluster - } - errc <- rerr - }(ep) - } - // wait for success - for i := 0; i < len(c.cfg.Endpoints); i++ { - if err = <-errc; err == nil { - break - } - } - cancel() - wg.Wait() - return err -} - -// ActiveConnection returns the current in-use connection -func (c *Client) ActiveConnection() *grpc.ClientConn { return c.conn } - -// isHaltErr returns true if the given error and context indicate no forward -// progress can be made, even after reconnecting. -func isHaltErr(ctx context.Context, err error) bool { - if ctx != nil && ctx.Err() != nil { - return true - } - if err == nil { - return false - } - ev, _ := status.FromError(err) - // Unavailable codes mean the system will be right back. - // (e.g., can't connect, lost leader) - // Treat Internal codes as if something failed, leaving the - // system in an inconsistent state, but retrying could make progress. - // (e.g., failed in middle of send, corrupted frame) - // TODO: are permanent Internal errors possible from grpc? - return ev.Code() != codes.Unavailable && ev.Code() != codes.Internal -} - -// isUnavailableErr returns true if the given error is an unavailable error -func isUnavailableErr(ctx context.Context, err error) bool { - if ctx != nil && ctx.Err() != nil { - return false - } - if err == nil { - return false - } - ev, _ := status.FromError(err) - // Unavailable codes mean the system will be right back. - // (e.g., can't connect, lost leader) - return ev.Code() == codes.Unavailable -} - -func toErr(ctx context.Context, err error) error { - if err == nil { - return nil - } - err = rpctypes.Error(err) - if _, ok := err.(rpctypes.EtcdError); ok { - return err - } - ev, _ := status.FromError(err) - code := ev.Code() - switch code { - case codes.DeadlineExceeded: - fallthrough - case codes.Canceled: - if ctx.Err() != nil { - err = ctx.Err() - } - case codes.Unavailable: - case codes.FailedPrecondition: - err = grpc.ErrClientConnClosing - } - return err -} - -func canceledByCaller(stopCtx context.Context, err error) bool { - if stopCtx.Err() == nil || err == nil { - return false - } - - return err == context.Canceled || err == context.DeadlineExceeded -} diff --git a/vendor/go.etcd.io/etcd/clientv3/clientv3util/util.go b/vendor/go.etcd.io/etcd/clientv3/clientv3util/util.go deleted file mode 100644 index 3b296343ebb3..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/clientv3util/util.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package clientv3util contains utility functions derived from clientv3. -package clientv3util - -import ( - "github.com/coreos/etcd/clientv3" -) - -// KeyExists returns a comparison operation that evaluates to true iff the given -// key exists. It does this by checking if the key `Version` is greater than 0. -// It is a useful guard in transaction delete operations. -func KeyExists(key string) clientv3.Cmp { - return clientv3.Compare(clientv3.Version(key), ">", 0) -} - -// KeyMissing returns a comparison operation that evaluates to true iff the -// given key does not exist. -func KeyMissing(key string) clientv3.Cmp { - return clientv3.Compare(clientv3.Version(key), "=", 0) -} diff --git a/vendor/go.etcd.io/etcd/clientv3/cluster.go b/vendor/go.etcd.io/etcd/clientv3/cluster.go deleted file mode 100644 index 785672be8ca2..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/cluster.go +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/pkg/types" - - "google.golang.org/grpc" -) - -type ( - Member pb.Member - MemberListResponse pb.MemberListResponse - MemberAddResponse pb.MemberAddResponse - MemberRemoveResponse pb.MemberRemoveResponse - MemberUpdateResponse pb.MemberUpdateResponse -) - -type Cluster interface { - // MemberList lists the current cluster membership. - MemberList(ctx context.Context) (*MemberListResponse, error) - - // MemberAdd adds a new member into the cluster. - MemberAdd(ctx context.Context, peerAddrs []string) (*MemberAddResponse, error) - - // MemberRemove removes an existing member from the cluster. - MemberRemove(ctx context.Context, id uint64) (*MemberRemoveResponse, error) - - // MemberUpdate updates the peer addresses of the member. - MemberUpdate(ctx context.Context, id uint64, peerAddrs []string) (*MemberUpdateResponse, error) -} - -type cluster struct { - remote pb.ClusterClient - callOpts []grpc.CallOption -} - -func NewCluster(c *Client) Cluster { - api := &cluster{remote: RetryClusterClient(c)} - if c != nil { - api.callOpts = c.callOpts - } - return api -} - -func NewClusterFromClusterClient(remote pb.ClusterClient, c *Client) Cluster { - api := &cluster{remote: remote} - if c != nil { - api.callOpts = c.callOpts - } - return api -} - -func (c *cluster) MemberAdd(ctx context.Context, peerAddrs []string) (*MemberAddResponse, error) { - // fail-fast before panic in rafthttp - if _, err := types.NewURLs(peerAddrs); err != nil { - return nil, err - } - - r := &pb.MemberAddRequest{PeerURLs: peerAddrs} - resp, err := c.remote.MemberAdd(ctx, r, c.callOpts...) - if err != nil { - return nil, toErr(ctx, err) - } - return (*MemberAddResponse)(resp), nil -} - -func (c *cluster) MemberRemove(ctx context.Context, id uint64) (*MemberRemoveResponse, error) { - r := &pb.MemberRemoveRequest{ID: id} - resp, err := c.remote.MemberRemove(ctx, r, c.callOpts...) - if err != nil { - return nil, toErr(ctx, err) - } - return (*MemberRemoveResponse)(resp), nil -} - -func (c *cluster) MemberUpdate(ctx context.Context, id uint64, peerAddrs []string) (*MemberUpdateResponse, error) { - // fail-fast before panic in rafthttp - if _, err := types.NewURLs(peerAddrs); err != nil { - return nil, err - } - - // it is safe to retry on update. - r := &pb.MemberUpdateRequest{ID: id, PeerURLs: peerAddrs} - resp, err := c.remote.MemberUpdate(ctx, r, c.callOpts...) - if err == nil { - return (*MemberUpdateResponse)(resp), nil - } - return nil, toErr(ctx, err) -} - -func (c *cluster) MemberList(ctx context.Context) (*MemberListResponse, error) { - // it is safe to retry on list. - resp, err := c.remote.MemberList(ctx, &pb.MemberListRequest{}, c.callOpts...) - if err == nil { - return (*MemberListResponse)(resp), nil - } - return nil, toErr(ctx, err) -} diff --git a/vendor/go.etcd.io/etcd/clientv3/compact_op.go b/vendor/go.etcd.io/etcd/clientv3/compact_op.go deleted file mode 100644 index 41e80c1da5d4..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/compact_op.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -// CompactOp represents a compact operation. -type CompactOp struct { - revision int64 - physical bool -} - -// CompactOption configures compact operation. -type CompactOption func(*CompactOp) - -func (op *CompactOp) applyCompactOpts(opts []CompactOption) { - for _, opt := range opts { - opt(op) - } -} - -// OpCompact wraps slice CompactOption to create a CompactOp. -func OpCompact(rev int64, opts ...CompactOption) CompactOp { - ret := CompactOp{revision: rev} - ret.applyCompactOpts(opts) - return ret -} - -func (op CompactOp) toRequest() *pb.CompactionRequest { - return &pb.CompactionRequest{Revision: op.revision, Physical: op.physical} -} - -// WithCompactPhysical makes Compact wait until all compacted entries are -// removed from the etcd server's storage. -func WithCompactPhysical() CompactOption { - return func(op *CompactOp) { op.physical = true } -} diff --git a/vendor/go.etcd.io/etcd/clientv3/compare.go b/vendor/go.etcd.io/etcd/clientv3/compare.go deleted file mode 100644 index b5f0a255279c..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/compare.go +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -type CompareTarget int -type CompareResult int - -const ( - CompareVersion CompareTarget = iota - CompareCreated - CompareModified - CompareValue -) - -type Cmp pb.Compare - -func Compare(cmp Cmp, result string, v interface{}) Cmp { - var r pb.Compare_CompareResult - - switch result { - case "=": - r = pb.Compare_EQUAL - case "!=": - r = pb.Compare_NOT_EQUAL - case ">": - r = pb.Compare_GREATER - case "<": - r = pb.Compare_LESS - default: - panic("Unknown result op") - } - - cmp.Result = r - switch cmp.Target { - case pb.Compare_VALUE: - val, ok := v.(string) - if !ok { - panic("bad compare value") - } - cmp.TargetUnion = &pb.Compare_Value{Value: []byte(val)} - case pb.Compare_VERSION: - cmp.TargetUnion = &pb.Compare_Version{Version: mustInt64(v)} - case pb.Compare_CREATE: - cmp.TargetUnion = &pb.Compare_CreateRevision{CreateRevision: mustInt64(v)} - case pb.Compare_MOD: - cmp.TargetUnion = &pb.Compare_ModRevision{ModRevision: mustInt64(v)} - case pb.Compare_LEASE: - cmp.TargetUnion = &pb.Compare_Lease{Lease: mustInt64orLeaseID(v)} - default: - panic("Unknown compare type") - } - return cmp -} - -func Value(key string) Cmp { - return Cmp{Key: []byte(key), Target: pb.Compare_VALUE} -} - -func Version(key string) Cmp { - return Cmp{Key: []byte(key), Target: pb.Compare_VERSION} -} - -func CreateRevision(key string) Cmp { - return Cmp{Key: []byte(key), Target: pb.Compare_CREATE} -} - -func ModRevision(key string) Cmp { - return Cmp{Key: []byte(key), Target: pb.Compare_MOD} -} - -// LeaseValue compares a key's LeaseID to a value of your choosing. The empty -// LeaseID is 0, otherwise known as `NoLease`. -func LeaseValue(key string) Cmp { - return Cmp{Key: []byte(key), Target: pb.Compare_LEASE} -} - -// KeyBytes returns the byte slice holding with the comparison key. -func (cmp *Cmp) KeyBytes() []byte { return cmp.Key } - -// WithKeyBytes sets the byte slice for the comparison key. -func (cmp *Cmp) WithKeyBytes(key []byte) { cmp.Key = key } - -// ValueBytes returns the byte slice holding the comparison value, if any. -func (cmp *Cmp) ValueBytes() []byte { - if tu, ok := cmp.TargetUnion.(*pb.Compare_Value); ok { - return tu.Value - } - return nil -} - -// WithValueBytes sets the byte slice for the comparison's value. -func (cmp *Cmp) WithValueBytes(v []byte) { cmp.TargetUnion.(*pb.Compare_Value).Value = v } - -// WithRange sets the comparison to scan the range [key, end). -func (cmp Cmp) WithRange(end string) Cmp { - cmp.RangeEnd = []byte(end) - return cmp -} - -// WithPrefix sets the comparison to scan all keys prefixed by the key. -func (cmp Cmp) WithPrefix() Cmp { - cmp.RangeEnd = getPrefix(cmp.Key) - return cmp -} - -// mustInt64 panics if val isn't an int or int64. It returns an int64 otherwise. -func mustInt64(val interface{}) int64 { - if v, ok := val.(int64); ok { - return v - } - if v, ok := val.(int); ok { - return int64(v) - } - panic("bad value") -} - -// mustInt64orLeaseID panics if val isn't a LeaseID, int or int64. It returns an -// int64 otherwise. -func mustInt64orLeaseID(val interface{}) int64 { - if v, ok := val.(LeaseID); ok { - return int64(v) - } - return mustInt64(val) -} diff --git a/vendor/go.etcd.io/etcd/clientv3/concurrency/doc.go b/vendor/go.etcd.io/etcd/clientv3/concurrency/doc.go deleted file mode 100644 index dcdbf511d1b1..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/concurrency/doc.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package concurrency implements concurrency operations on top of -// etcd such as distributed locks, barriers, and elections. -package concurrency diff --git a/vendor/go.etcd.io/etcd/clientv3/concurrency/election.go b/vendor/go.etcd.io/etcd/clientv3/concurrency/election.go deleted file mode 100644 index e18a0ed4ad92..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/concurrency/election.go +++ /dev/null @@ -1,245 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package concurrency - -import ( - "context" - "errors" - "fmt" - - v3 "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -var ( - ErrElectionNotLeader = errors.New("election: not leader") - ErrElectionNoLeader = errors.New("election: no leader") -) - -type Election struct { - session *Session - - keyPrefix string - - leaderKey string - leaderRev int64 - leaderSession *Session - hdr *pb.ResponseHeader -} - -// NewElection returns a new election on a given key prefix. -func NewElection(s *Session, pfx string) *Election { - return &Election{session: s, keyPrefix: pfx + "/"} -} - -// ResumeElection initializes an election with a known leader. -func ResumeElection(s *Session, pfx string, leaderKey string, leaderRev int64) *Election { - return &Election{ - session: s, - leaderKey: leaderKey, - leaderRev: leaderRev, - leaderSession: s, - } -} - -// Campaign puts a value as eligible for the election. It blocks until -// it is elected, an error occurs, or the context is cancelled. -func (e *Election) Campaign(ctx context.Context, val string) error { - s := e.session - client := e.session.Client() - - k := fmt.Sprintf("%s%x", e.keyPrefix, s.Lease()) - txn := client.Txn(ctx).If(v3.Compare(v3.CreateRevision(k), "=", 0)) - txn = txn.Then(v3.OpPut(k, val, v3.WithLease(s.Lease()))) - txn = txn.Else(v3.OpGet(k)) - resp, err := txn.Commit() - if err != nil { - return err - } - e.leaderKey, e.leaderRev, e.leaderSession = k, resp.Header.Revision, s - if !resp.Succeeded { - kv := resp.Responses[0].GetResponseRange().Kvs[0] - e.leaderRev = kv.CreateRevision - if string(kv.Value) != val { - if err = e.Proclaim(ctx, val); err != nil { - e.Resign(ctx) - return err - } - } - } - - _, err = waitDeletes(ctx, client, e.keyPrefix, e.leaderRev-1) - if err != nil { - // clean up in case of context cancel - select { - case <-ctx.Done(): - e.Resign(client.Ctx()) - default: - e.leaderSession = nil - } - return err - } - e.hdr = resp.Header - - return nil -} - -// Proclaim lets the leader announce a new value without another election. -func (e *Election) Proclaim(ctx context.Context, val string) error { - if e.leaderSession == nil { - return ErrElectionNotLeader - } - client := e.session.Client() - cmp := v3.Compare(v3.CreateRevision(e.leaderKey), "=", e.leaderRev) - txn := client.Txn(ctx).If(cmp) - txn = txn.Then(v3.OpPut(e.leaderKey, val, v3.WithLease(e.leaderSession.Lease()))) - tresp, terr := txn.Commit() - if terr != nil { - return terr - } - if !tresp.Succeeded { - e.leaderKey = "" - return ErrElectionNotLeader - } - - e.hdr = tresp.Header - return nil -} - -// Resign lets a leader start a new election. -func (e *Election) Resign(ctx context.Context) (err error) { - if e.leaderSession == nil { - return nil - } - client := e.session.Client() - cmp := v3.Compare(v3.CreateRevision(e.leaderKey), "=", e.leaderRev) - resp, err := client.Txn(ctx).If(cmp).Then(v3.OpDelete(e.leaderKey)).Commit() - if err == nil { - e.hdr = resp.Header - } - e.leaderKey = "" - e.leaderSession = nil - return err -} - -// Leader returns the leader value for the current election. -func (e *Election) Leader(ctx context.Context) (*v3.GetResponse, error) { - client := e.session.Client() - resp, err := client.Get(ctx, e.keyPrefix, v3.WithFirstCreate()...) - if err != nil { - return nil, err - } else if len(resp.Kvs) == 0 { - // no leader currently elected - return nil, ErrElectionNoLeader - } - return resp, nil -} - -// Observe returns a channel that reliably observes ordered leader proposals -// as GetResponse values on every current elected leader key. It will not -// necessarily fetch all historical leader updates, but will always post the -// most recent leader value. -// -// The channel closes when the context is canceled or the underlying watcher -// is otherwise disrupted. -func (e *Election) Observe(ctx context.Context) <-chan v3.GetResponse { - retc := make(chan v3.GetResponse) - go e.observe(ctx, retc) - return retc -} - -func (e *Election) observe(ctx context.Context, ch chan<- v3.GetResponse) { - client := e.session.Client() - - defer close(ch) - for { - resp, err := client.Get(ctx, e.keyPrefix, v3.WithFirstCreate()...) - if err != nil { - return - } - - var kv *mvccpb.KeyValue - var hdr *pb.ResponseHeader - - if len(resp.Kvs) == 0 { - cctx, cancel := context.WithCancel(ctx) - // wait for first key put on prefix - opts := []v3.OpOption{v3.WithRev(resp.Header.Revision), v3.WithPrefix()} - wch := client.Watch(cctx, e.keyPrefix, opts...) - for kv == nil { - wr, ok := <-wch - if !ok || wr.Err() != nil { - cancel() - return - } - // only accept puts; a delete will make observe() spin - for _, ev := range wr.Events { - if ev.Type == mvccpb.PUT { - hdr, kv = &wr.Header, ev.Kv - // may have multiple revs; hdr.rev = the last rev - // set to kv's rev in case batch has multiple Puts - hdr.Revision = kv.ModRevision - break - } - } - } - cancel() - } else { - hdr, kv = resp.Header, resp.Kvs[0] - } - - select { - case ch <- v3.GetResponse{Header: hdr, Kvs: []*mvccpb.KeyValue{kv}}: - case <-ctx.Done(): - return - } - - cctx, cancel := context.WithCancel(ctx) - wch := client.Watch(cctx, string(kv.Key), v3.WithRev(hdr.Revision+1)) - keyDeleted := false - for !keyDeleted { - wr, ok := <-wch - if !ok { - cancel() - return - } - for _, ev := range wr.Events { - if ev.Type == mvccpb.DELETE { - keyDeleted = true - break - } - resp.Header = &wr.Header - resp.Kvs = []*mvccpb.KeyValue{ev.Kv} - select { - case ch <- *resp: - case <-cctx.Done(): - cancel() - return - } - } - } - cancel() - } -} - -// Key returns the leader key if elected, empty string otherwise. -func (e *Election) Key() string { return e.leaderKey } - -// Rev returns the leader key's creation revision, if elected. -func (e *Election) Rev() int64 { return e.leaderRev } - -// Header is the response header from the last successful election proposal. -func (e *Election) Header() *pb.ResponseHeader { return e.hdr } diff --git a/vendor/go.etcd.io/etcd/clientv3/concurrency/key.go b/vendor/go.etcd.io/etcd/clientv3/concurrency/key.go deleted file mode 100644 index 4b6e399bd4e1..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/concurrency/key.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package concurrency - -import ( - "context" - "fmt" - - v3 "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -func waitDelete(ctx context.Context, client *v3.Client, key string, rev int64) error { - cctx, cancel := context.WithCancel(ctx) - defer cancel() - - var wr v3.WatchResponse - wch := client.Watch(cctx, key, v3.WithRev(rev)) - for wr = range wch { - for _, ev := range wr.Events { - if ev.Type == mvccpb.DELETE { - return nil - } - } - } - if err := wr.Err(); err != nil { - return err - } - if err := ctx.Err(); err != nil { - return err - } - return fmt.Errorf("lost watcher waiting for delete") -} - -// waitDeletes efficiently waits until all keys matching the prefix and no greater -// than the create revision. -func waitDeletes(ctx context.Context, client *v3.Client, pfx string, maxCreateRev int64) (*pb.ResponseHeader, error) { - getOpts := append(v3.WithLastCreate(), v3.WithMaxCreateRev(maxCreateRev)) - for { - resp, err := client.Get(ctx, pfx, getOpts...) - if err != nil { - return nil, err - } - if len(resp.Kvs) == 0 { - return resp.Header, nil - } - lastKey := string(resp.Kvs[0].Key) - if err = waitDelete(ctx, client, lastKey, resp.Header.Revision); err != nil { - return nil, err - } - } -} diff --git a/vendor/go.etcd.io/etcd/clientv3/concurrency/mutex.go b/vendor/go.etcd.io/etcd/clientv3/concurrency/mutex.go deleted file mode 100644 index 77b3582cde52..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/concurrency/mutex.go +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package concurrency - -import ( - "context" - "fmt" - "sync" - - v3 "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -// Mutex implements the sync Locker interface with etcd -type Mutex struct { - s *Session - - pfx string - myKey string - myRev int64 - hdr *pb.ResponseHeader -} - -func NewMutex(s *Session, pfx string) *Mutex { - return &Mutex{s, pfx + "/", "", -1, nil} -} - -// Lock locks the mutex with a cancelable context. If the context is canceled -// while trying to acquire the lock, the mutex tries to clean its stale lock entry. -func (m *Mutex) Lock(ctx context.Context) error { - s := m.s - client := m.s.Client() - - m.myKey = fmt.Sprintf("%s%x", m.pfx, s.Lease()) - cmp := v3.Compare(v3.CreateRevision(m.myKey), "=", 0) - // put self in lock waiters via myKey; oldest waiter holds lock - put := v3.OpPut(m.myKey, "", v3.WithLease(s.Lease())) - // reuse key in case this session already holds the lock - get := v3.OpGet(m.myKey) - // fetch current holder to complete uncontended path with only one RPC - getOwner := v3.OpGet(m.pfx, v3.WithFirstCreate()...) - resp, err := client.Txn(ctx).If(cmp).Then(put, getOwner).Else(get, getOwner).Commit() - if err != nil { - return err - } - m.myRev = resp.Header.Revision - if !resp.Succeeded { - m.myRev = resp.Responses[0].GetResponseRange().Kvs[0].CreateRevision - } - // if no key on prefix / the minimum rev is key, already hold the lock - ownerKey := resp.Responses[1].GetResponseRange().Kvs - if len(ownerKey) == 0 || ownerKey[0].CreateRevision == m.myRev { - m.hdr = resp.Header - return nil - } - - // wait for deletion revisions prior to myKey - hdr, werr := waitDeletes(ctx, client, m.pfx, m.myRev-1) - // release lock key if wait failed - if werr != nil { - m.Unlock(client.Ctx()) - } else { - m.hdr = hdr - } - return werr -} - -func (m *Mutex) Unlock(ctx context.Context) error { - client := m.s.Client() - if _, err := client.Delete(ctx, m.myKey); err != nil { - return err - } - m.myKey = "\x00" - m.myRev = -1 - return nil -} - -func (m *Mutex) IsOwner() v3.Cmp { - return v3.Compare(v3.CreateRevision(m.myKey), "=", m.myRev) -} - -func (m *Mutex) Key() string { return m.myKey } - -// Header is the response header received from etcd on acquiring the lock. -func (m *Mutex) Header() *pb.ResponseHeader { return m.hdr } - -type lockerMutex struct{ *Mutex } - -func (lm *lockerMutex) Lock() { - client := lm.s.Client() - if err := lm.Mutex.Lock(client.Ctx()); err != nil { - panic(err) - } -} -func (lm *lockerMutex) Unlock() { - client := lm.s.Client() - if err := lm.Mutex.Unlock(client.Ctx()); err != nil { - panic(err) - } -} - -// NewLocker creates a sync.Locker backed by an etcd mutex. -func NewLocker(s *Session, pfx string) sync.Locker { - return &lockerMutex{NewMutex(s, pfx)} -} diff --git a/vendor/go.etcd.io/etcd/clientv3/concurrency/session.go b/vendor/go.etcd.io/etcd/clientv3/concurrency/session.go deleted file mode 100644 index c399d64a61db..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/concurrency/session.go +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package concurrency - -import ( - "context" - "time" - - v3 "github.com/coreos/etcd/clientv3" -) - -const defaultSessionTTL = 60 - -// Session represents a lease kept alive for the lifetime of a client. -// Fault-tolerant applications may use sessions to reason about liveness. -type Session struct { - client *v3.Client - opts *sessionOptions - id v3.LeaseID - - cancel context.CancelFunc - donec <-chan struct{} -} - -// NewSession gets the leased session for a client. -func NewSession(client *v3.Client, opts ...SessionOption) (*Session, error) { - ops := &sessionOptions{ttl: defaultSessionTTL, ctx: client.Ctx()} - for _, opt := range opts { - opt(ops) - } - - id := ops.leaseID - if id == v3.NoLease { - resp, err := client.Grant(ops.ctx, int64(ops.ttl)) - if err != nil { - return nil, err - } - id = v3.LeaseID(resp.ID) - } - - ctx, cancel := context.WithCancel(ops.ctx) - keepAlive, err := client.KeepAlive(ctx, id) - if err != nil || keepAlive == nil { - cancel() - return nil, err - } - - donec := make(chan struct{}) - s := &Session{client: client, opts: ops, id: id, cancel: cancel, donec: donec} - - // keep the lease alive until client error or cancelled context - go func() { - defer close(donec) - for range keepAlive { - // eat messages until keep alive channel closes - } - }() - - return s, nil -} - -// Client is the etcd client that is attached to the session. -func (s *Session) Client() *v3.Client { - return s.client -} - -// Lease is the lease ID for keys bound to the session. -func (s *Session) Lease() v3.LeaseID { return s.id } - -// Done returns a channel that closes when the lease is orphaned, expires, or -// is otherwise no longer being refreshed. -func (s *Session) Done() <-chan struct{} { return s.donec } - -// Orphan ends the refresh for the session lease. This is useful -// in case the state of the client connection is indeterminate (revoke -// would fail) or when transferring lease ownership. -func (s *Session) Orphan() { - s.cancel() - <-s.donec -} - -// Close orphans the session and revokes the session lease. -func (s *Session) Close() error { - s.Orphan() - // if revoke takes longer than the ttl, lease is expired anyway - ctx, cancel := context.WithTimeout(s.opts.ctx, time.Duration(s.opts.ttl)*time.Second) - _, err := s.client.Revoke(ctx, s.id) - cancel() - return err -} - -type sessionOptions struct { - ttl int - leaseID v3.LeaseID - ctx context.Context -} - -// SessionOption configures Session. -type SessionOption func(*sessionOptions) - -// WithTTL configures the session's TTL in seconds. -// If TTL is <= 0, the default 60 seconds TTL will be used. -func WithTTL(ttl int) SessionOption { - return func(so *sessionOptions) { - if ttl > 0 { - so.ttl = ttl - } - } -} - -// WithLease specifies the existing leaseID to be used for the session. -// This is useful in process restart scenario, for example, to reclaim -// leadership from an election prior to restart. -func WithLease(leaseID v3.LeaseID) SessionOption { - return func(so *sessionOptions) { - so.leaseID = leaseID - } -} - -// WithContext assigns a context to the session instead of defaulting to -// using the client context. This is useful for canceling NewSession and -// Close operations immediately without having to close the client. If the -// context is canceled before Close() completes, the session's lease will be -// abandoned and left to expire instead of being revoked. -func WithContext(ctx context.Context) SessionOption { - return func(so *sessionOptions) { - so.ctx = ctx - } -} diff --git a/vendor/go.etcd.io/etcd/clientv3/concurrency/stm.go b/vendor/go.etcd.io/etcd/clientv3/concurrency/stm.go deleted file mode 100644 index d11023ebe361..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/concurrency/stm.go +++ /dev/null @@ -1,387 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package concurrency - -import ( - "context" - "math" - - v3 "github.com/coreos/etcd/clientv3" -) - -// STM is an interface for software transactional memory. -type STM interface { - // Get returns the value for a key and inserts the key in the txn's read set. - // If Get fails, it aborts the transaction with an error, never returning. - Get(key ...string) string - // Put adds a value for a key to the write set. - Put(key, val string, opts ...v3.OpOption) - // Rev returns the revision of a key in the read set. - Rev(key string) int64 - // Del deletes a key. - Del(key string) - - // commit attempts to apply the txn's changes to the server. - commit() *v3.TxnResponse - reset() -} - -// Isolation is an enumeration of transactional isolation levels which -// describes how transactions should interfere and conflict. -type Isolation int - -const ( - // SerializableSnapshot provides serializable isolation and also checks - // for write conflicts. - SerializableSnapshot Isolation = iota - // Serializable reads within the same transaction attempt return data - // from the at the revision of the first read. - Serializable - // RepeatableReads reads within the same transaction attempt always - // return the same data. - RepeatableReads - // ReadCommitted reads keys from any committed revision. - ReadCommitted -) - -// stmError safely passes STM errors through panic to the STM error channel. -type stmError struct{ err error } - -type stmOptions struct { - iso Isolation - ctx context.Context - prefetch []string -} - -type stmOption func(*stmOptions) - -// WithIsolation specifies the transaction isolation level. -func WithIsolation(lvl Isolation) stmOption { - return func(so *stmOptions) { so.iso = lvl } -} - -// WithAbortContext specifies the context for permanently aborting the transaction. -func WithAbortContext(ctx context.Context) stmOption { - return func(so *stmOptions) { so.ctx = ctx } -} - -// WithPrefetch is a hint to prefetch a list of keys before trying to apply. -// If an STM transaction will unconditionally fetch a set of keys, prefetching -// those keys will save the round-trip cost from requesting each key one by one -// with Get(). -func WithPrefetch(keys ...string) stmOption { - return func(so *stmOptions) { so.prefetch = append(so.prefetch, keys...) } -} - -// NewSTM initiates a new STM instance, using serializable snapshot isolation by default. -func NewSTM(c *v3.Client, apply func(STM) error, so ...stmOption) (*v3.TxnResponse, error) { - opts := &stmOptions{ctx: c.Ctx()} - for _, f := range so { - f(opts) - } - if len(opts.prefetch) != 0 { - f := apply - apply = func(s STM) error { - s.Get(opts.prefetch...) - return f(s) - } - } - return runSTM(mkSTM(c, opts), apply) -} - -func mkSTM(c *v3.Client, opts *stmOptions) STM { - switch opts.iso { - case SerializableSnapshot: - s := &stmSerializable{ - stm: stm{client: c, ctx: opts.ctx}, - prefetch: make(map[string]*v3.GetResponse), - } - s.conflicts = func() []v3.Cmp { - return append(s.rset.cmps(), s.wset.cmps(s.rset.first()+1)...) - } - return s - case Serializable: - s := &stmSerializable{ - stm: stm{client: c, ctx: opts.ctx}, - prefetch: make(map[string]*v3.GetResponse), - } - s.conflicts = func() []v3.Cmp { return s.rset.cmps() } - return s - case RepeatableReads: - s := &stm{client: c, ctx: opts.ctx, getOpts: []v3.OpOption{v3.WithSerializable()}} - s.conflicts = func() []v3.Cmp { return s.rset.cmps() } - return s - case ReadCommitted: - s := &stm{client: c, ctx: opts.ctx, getOpts: []v3.OpOption{v3.WithSerializable()}} - s.conflicts = func() []v3.Cmp { return nil } - return s - default: - panic("unsupported stm") - } -} - -type stmResponse struct { - resp *v3.TxnResponse - err error -} - -func runSTM(s STM, apply func(STM) error) (*v3.TxnResponse, error) { - outc := make(chan stmResponse, 1) - go func() { - defer func() { - if r := recover(); r != nil { - e, ok := r.(stmError) - if !ok { - // client apply panicked - panic(r) - } - outc <- stmResponse{nil, e.err} - } - }() - var out stmResponse - for { - s.reset() - if out.err = apply(s); out.err != nil { - break - } - if out.resp = s.commit(); out.resp != nil { - break - } - } - outc <- out - }() - r := <-outc - return r.resp, r.err -} - -// stm implements repeatable-read software transactional memory over etcd -type stm struct { - client *v3.Client - ctx context.Context - // rset holds read key values and revisions - rset readSet - // wset holds overwritten keys and their values - wset writeSet - // getOpts are the opts used for gets - getOpts []v3.OpOption - // conflicts computes the current conflicts on the txn - conflicts func() []v3.Cmp -} - -type stmPut struct { - val string - op v3.Op -} - -type readSet map[string]*v3.GetResponse - -func (rs readSet) add(keys []string, txnresp *v3.TxnResponse) { - for i, resp := range txnresp.Responses { - rs[keys[i]] = (*v3.GetResponse)(resp.GetResponseRange()) - } -} - -// first returns the store revision from the first fetch -func (rs readSet) first() int64 { - ret := int64(math.MaxInt64 - 1) - for _, resp := range rs { - if rev := resp.Header.Revision; rev < ret { - ret = rev - } - } - return ret -} - -// cmps guards the txn from updates to read set -func (rs readSet) cmps() []v3.Cmp { - cmps := make([]v3.Cmp, 0, len(rs)) - for k, rk := range rs { - cmps = append(cmps, isKeyCurrent(k, rk)) - } - return cmps -} - -type writeSet map[string]stmPut - -func (ws writeSet) get(keys ...string) *stmPut { - for _, key := range keys { - if wv, ok := ws[key]; ok { - return &wv - } - } - return nil -} - -// cmps returns a cmp list testing no writes have happened past rev -func (ws writeSet) cmps(rev int64) []v3.Cmp { - cmps := make([]v3.Cmp, 0, len(ws)) - for key := range ws { - cmps = append(cmps, v3.Compare(v3.ModRevision(key), "<", rev)) - } - return cmps -} - -// puts is the list of ops for all pending writes -func (ws writeSet) puts() []v3.Op { - puts := make([]v3.Op, 0, len(ws)) - for _, v := range ws { - puts = append(puts, v.op) - } - return puts -} - -func (s *stm) Get(keys ...string) string { - if wv := s.wset.get(keys...); wv != nil { - return wv.val - } - return respToValue(s.fetch(keys...)) -} - -func (s *stm) Put(key, val string, opts ...v3.OpOption) { - s.wset[key] = stmPut{val, v3.OpPut(key, val, opts...)} -} - -func (s *stm) Del(key string) { s.wset[key] = stmPut{"", v3.OpDelete(key)} } - -func (s *stm) Rev(key string) int64 { - if resp := s.fetch(key); resp != nil && len(resp.Kvs) != 0 { - return resp.Kvs[0].ModRevision - } - return 0 -} - -func (s *stm) commit() *v3.TxnResponse { - txnresp, err := s.client.Txn(s.ctx).If(s.conflicts()...).Then(s.wset.puts()...).Commit() - if err != nil { - panic(stmError{err}) - } - if txnresp.Succeeded { - return txnresp - } - return nil -} - -func (s *stm) fetch(keys ...string) *v3.GetResponse { - if len(keys) == 0 { - return nil - } - ops := make([]v3.Op, len(keys)) - for i, key := range keys { - if resp, ok := s.rset[key]; ok { - return resp - } - ops[i] = v3.OpGet(key, s.getOpts...) - } - txnresp, err := s.client.Txn(s.ctx).Then(ops...).Commit() - if err != nil { - panic(stmError{err}) - } - s.rset.add(keys, txnresp) - return (*v3.GetResponse)(txnresp.Responses[0].GetResponseRange()) -} - -func (s *stm) reset() { - s.rset = make(map[string]*v3.GetResponse) - s.wset = make(map[string]stmPut) -} - -type stmSerializable struct { - stm - prefetch map[string]*v3.GetResponse -} - -func (s *stmSerializable) Get(keys ...string) string { - if wv := s.wset.get(keys...); wv != nil { - return wv.val - } - firstRead := len(s.rset) == 0 - for _, key := range keys { - if resp, ok := s.prefetch[key]; ok { - delete(s.prefetch, key) - s.rset[key] = resp - } - } - resp := s.stm.fetch(keys...) - if firstRead { - // txn's base revision is defined by the first read - s.getOpts = []v3.OpOption{ - v3.WithRev(resp.Header.Revision), - v3.WithSerializable(), - } - } - return respToValue(resp) -} - -func (s *stmSerializable) Rev(key string) int64 { - s.Get(key) - return s.stm.Rev(key) -} - -func (s *stmSerializable) gets() ([]string, []v3.Op) { - keys := make([]string, 0, len(s.rset)) - ops := make([]v3.Op, 0, len(s.rset)) - for k := range s.rset { - keys = append(keys, k) - ops = append(ops, v3.OpGet(k)) - } - return keys, ops -} - -func (s *stmSerializable) commit() *v3.TxnResponse { - keys, getops := s.gets() - txn := s.client.Txn(s.ctx).If(s.conflicts()...).Then(s.wset.puts()...) - // use Else to prefetch keys in case of conflict to save a round trip - txnresp, err := txn.Else(getops...).Commit() - if err != nil { - panic(stmError{err}) - } - if txnresp.Succeeded { - return txnresp - } - // load prefetch with Else data - s.rset.add(keys, txnresp) - s.prefetch = s.rset - s.getOpts = nil - return nil -} - -func isKeyCurrent(k string, r *v3.GetResponse) v3.Cmp { - if len(r.Kvs) != 0 { - return v3.Compare(v3.ModRevision(k), "=", r.Kvs[0].ModRevision) - } - return v3.Compare(v3.ModRevision(k), "=", 0) -} - -func respToValue(resp *v3.GetResponse) string { - if resp == nil || len(resp.Kvs) == 0 { - return "" - } - return string(resp.Kvs[0].Value) -} - -// NewSTMRepeatable is deprecated. -func NewSTMRepeatable(ctx context.Context, c *v3.Client, apply func(STM) error) (*v3.TxnResponse, error) { - return NewSTM(c, apply, WithAbortContext(ctx), WithIsolation(RepeatableReads)) -} - -// NewSTMSerializable is deprecated. -func NewSTMSerializable(ctx context.Context, c *v3.Client, apply func(STM) error) (*v3.TxnResponse, error) { - return NewSTM(c, apply, WithAbortContext(ctx), WithIsolation(Serializable)) -} - -// NewSTMReadCommitted is deprecated. -func NewSTMReadCommitted(ctx context.Context, c *v3.Client, apply func(STM) error) (*v3.TxnResponse, error) { - return NewSTM(c, apply, WithAbortContext(ctx), WithIsolation(ReadCommitted)) -} diff --git a/vendor/go.etcd.io/etcd/clientv3/config.go b/vendor/go.etcd.io/etcd/clientv3/config.go deleted file mode 100644 index 79d6e2a984f3..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/config.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - "crypto/tls" - "time" - - "google.golang.org/grpc" -) - -type Config struct { - // Endpoints is a list of URLs. - Endpoints []string `json:"endpoints"` - - // AutoSyncInterval is the interval to update endpoints with its latest members. - // 0 disables auto-sync. By default auto-sync is disabled. - AutoSyncInterval time.Duration `json:"auto-sync-interval"` - - // DialTimeout is the timeout for failing to establish a connection. - DialTimeout time.Duration `json:"dial-timeout"` - - // DialKeepAliveTime is the time after which client pings the server to see if - // transport is alive. - DialKeepAliveTime time.Duration `json:"dial-keep-alive-time"` - - // DialKeepAliveTimeout is the time that the client waits for a response for the - // keep-alive probe. If the response is not received in this time, the connection is closed. - DialKeepAliveTimeout time.Duration `json:"dial-keep-alive-timeout"` - - // MaxCallSendMsgSize is the client-side request send limit in bytes. - // If 0, it defaults to 2.0 MiB (2 * 1024 * 1024). - // Make sure that "MaxCallSendMsgSize" < server-side default send/recv limit. - // ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes"). - MaxCallSendMsgSize int - - // MaxCallRecvMsgSize is the client-side response receive limit. - // If 0, it defaults to "math.MaxInt32", because range response can - // easily exceed request send limits. - // Make sure that "MaxCallRecvMsgSize" >= server-side default send/recv limit. - // ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes"). - MaxCallRecvMsgSize int - - // TLS holds the client secure credentials, if any. - TLS *tls.Config - - // Username is a user name for authentication. - Username string `json:"username"` - - // Password is a password for authentication. - Password string `json:"password"` - - // RejectOldCluster when set will refuse to create a client against an outdated cluster. - RejectOldCluster bool `json:"reject-old-cluster"` - - // DialOptions is a list of dial options for the grpc client (e.g., for interceptors). - DialOptions []grpc.DialOption - - // Context is the default client context; it can be used to cancel grpc dial out and - // other operations that do not have an explicit context. - Context context.Context -} diff --git a/vendor/go.etcd.io/etcd/clientv3/doc.go b/vendor/go.etcd.io/etcd/clientv3/doc.go deleted file mode 100644 index 717fbe435ea5..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/doc.go +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package clientv3 implements the official Go etcd client for v3. -// -// Create client using `clientv3.New`: -// -// // expect dial time-out on ipv4 blackhole -// _, err := clientv3.New(clientv3.Config{ -// Endpoints: []string{"http://254.0.0.1:12345"}, -// DialTimeout: 2 * time.Second -// }) -// -// // etcd clientv3 >= v3.2.10, grpc/grpc-go >= v1.7.3 -// if err == context.DeadlineExceeded { -// // handle errors -// } -// -// // etcd clientv3 <= v3.2.9, grpc/grpc-go <= v1.2.1 -// if err == grpc.ErrClientConnTimeout { -// // handle errors -// } -// -// cli, err := clientv3.New(clientv3.Config{ -// Endpoints: []string{"localhost:2379", "localhost:22379", "localhost:32379"}, -// DialTimeout: 5 * time.Second, -// }) -// if err != nil { -// // handle error! -// } -// defer cli.Close() -// -// Make sure to close the client after using it. If the client is not closed, the -// connection will have leaky goroutines. -// -// To specify a client request timeout, wrap the context with context.WithTimeout: -// -// ctx, cancel := context.WithTimeout(context.Background(), timeout) -// resp, err := kvc.Put(ctx, "sample_key", "sample_value") -// cancel() -// if err != nil { -// // handle error! -// } -// // use the response -// -// The Client has internal state (watchers and leases), so Clients should be reused instead of created as needed. -// Clients are safe for concurrent use by multiple goroutines. -// -// etcd client returns 3 types of errors: -// -// 1. context error: canceled or deadline exceeded. -// 2. gRPC status error: e.g. when clock drifts in server-side before client's context deadline exceeded. -// 3. gRPC error: see https://github.com/coreos/etcd/blob/master/etcdserver/api/v3rpc/rpctypes/error.go -// -// Here is the example code to handle client errors: -// -// resp, err := kvc.Put(ctx, "", "") -// if err != nil { -// if err == context.Canceled { -// // ctx is canceled by another routine -// } else if err == context.DeadlineExceeded { -// // ctx is attached with a deadline and it exceeded -// } else if ev, ok := status.FromError(err); ok { -// code := ev.Code() -// if code == codes.DeadlineExceeded { -// // server-side context might have timed-out first (due to clock skew) -// // while original client-side context is not timed-out yet -// } -// } else if verr, ok := err.(*v3rpc.ErrEmptyKey); ok { -// // process (verr.Errors) -// } else { -// // bad cluster endpoints, which are not etcd servers -// } -// } -// -// go func() { cli.Close() }() -// _, err := kvc.Get(ctx, "a") -// if err != nil { -// if err == context.Canceled { -// // grpc balancer calls 'Get' with an inflight client.Close -// } else if err == grpc.ErrClientConnClosing { -// // grpc balancer calls 'Get' after client.Close. -// } -// } -// -package clientv3 diff --git a/vendor/go.etcd.io/etcd/clientv3/health_balancer.go b/vendor/go.etcd.io/etcd/clientv3/health_balancer.go deleted file mode 100644 index 5918cba84823..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/health_balancer.go +++ /dev/null @@ -1,609 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - "errors" - "net/url" - "strings" - "sync" - "time" - - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - healthpb "google.golang.org/grpc/health/grpc_health_v1" - "google.golang.org/grpc/status" -) - -const ( - minHealthRetryDuration = 3 * time.Second - unknownService = "unknown service grpc.health.v1.Health" -) - -// ErrNoAddrAvilable is returned by Get() when the balancer does not have -// any active connection to endpoints at the time. -// This error is returned only when opts.BlockingWait is true. -var ErrNoAddrAvilable = status.Error(codes.Unavailable, "there is no address available") - -type healthCheckFunc func(ep string) (bool, error) - -type notifyMsg int - -const ( - notifyReset notifyMsg = iota - notifyNext -) - -// healthBalancer does the bare minimum to expose multiple eps -// to the grpc reconnection code path -type healthBalancer struct { - // addrs are the client's endpoint addresses for grpc - addrs []grpc.Address - - // eps holds the raw endpoints from the client - eps []string - - // notifyCh notifies grpc of the set of addresses for connecting - notifyCh chan []grpc.Address - - // readyc closes once the first connection is up - readyc chan struct{} - readyOnce sync.Once - - // healthCheck checks an endpoint's health. - healthCheck healthCheckFunc - healthCheckTimeout time.Duration - - unhealthyMu sync.RWMutex - unhealthyHostPorts map[string]time.Time - - // mu protects all fields below. - mu sync.RWMutex - - // upc closes when pinAddr transitions from empty to non-empty or the balancer closes. - upc chan struct{} - - // downc closes when grpc calls down() on pinAddr - downc chan struct{} - - // stopc is closed to signal updateNotifyLoop should stop. - stopc chan struct{} - stopOnce sync.Once - wg sync.WaitGroup - - // donec closes when all goroutines are exited - donec chan struct{} - - // updateAddrsC notifies updateNotifyLoop to update addrs. - updateAddrsC chan notifyMsg - - // grpc issues TLS cert checks using the string passed into dial so - // that string must be the host. To recover the full scheme://host URL, - // have a map from hosts to the original endpoint. - hostPort2ep map[string]string - - // pinAddr is the currently pinned address; set to the empty string on - // initialization and shutdown. - pinAddr string - - closed bool -} - -func newHealthBalancer(eps []string, timeout time.Duration, hc healthCheckFunc) *healthBalancer { - notifyCh := make(chan []grpc.Address) - addrs := eps2addrs(eps) - hb := &healthBalancer{ - addrs: addrs, - eps: eps, - notifyCh: notifyCh, - readyc: make(chan struct{}), - healthCheck: hc, - unhealthyHostPorts: make(map[string]time.Time), - upc: make(chan struct{}), - stopc: make(chan struct{}), - downc: make(chan struct{}), - donec: make(chan struct{}), - updateAddrsC: make(chan notifyMsg), - hostPort2ep: getHostPort2ep(eps), - } - if timeout < minHealthRetryDuration { - timeout = minHealthRetryDuration - } - hb.healthCheckTimeout = timeout - - close(hb.downc) - go hb.updateNotifyLoop() - hb.wg.Add(1) - go func() { - defer hb.wg.Done() - hb.updateUnhealthy() - }() - return hb -} - -func (b *healthBalancer) Start(target string, config grpc.BalancerConfig) error { return nil } - -func (b *healthBalancer) ConnectNotify() <-chan struct{} { - b.mu.Lock() - defer b.mu.Unlock() - return b.upc -} - -func (b *healthBalancer) ready() <-chan struct{} { return b.readyc } - -func (b *healthBalancer) endpoint(hostPort string) string { - b.mu.RLock() - defer b.mu.RUnlock() - return b.hostPort2ep[hostPort] -} - -func (b *healthBalancer) pinned() string { - b.mu.RLock() - defer b.mu.RUnlock() - return b.pinAddr -} - -func (b *healthBalancer) hostPortError(hostPort string, err error) { - if b.endpoint(hostPort) == "" { - logger.Lvl(4).Infof("clientv3/balancer: %q is stale (skip marking as unhealthy on %q)", hostPort, err.Error()) - return - } - - b.unhealthyMu.Lock() - b.unhealthyHostPorts[hostPort] = time.Now() - b.unhealthyMu.Unlock() - logger.Lvl(4).Infof("clientv3/balancer: %q is marked unhealthy (%q)", hostPort, err.Error()) -} - -func (b *healthBalancer) removeUnhealthy(hostPort, msg string) { - if b.endpoint(hostPort) == "" { - logger.Lvl(4).Infof("clientv3/balancer: %q was not in unhealthy (%q)", hostPort, msg) - return - } - - b.unhealthyMu.Lock() - delete(b.unhealthyHostPorts, hostPort) - b.unhealthyMu.Unlock() - logger.Lvl(4).Infof("clientv3/balancer: %q is removed from unhealthy (%q)", hostPort, msg) -} - -func (b *healthBalancer) countUnhealthy() (count int) { - b.unhealthyMu.RLock() - count = len(b.unhealthyHostPorts) - b.unhealthyMu.RUnlock() - return count -} - -func (b *healthBalancer) isUnhealthy(hostPort string) (unhealthy bool) { - b.unhealthyMu.RLock() - _, unhealthy = b.unhealthyHostPorts[hostPort] - b.unhealthyMu.RUnlock() - return unhealthy -} - -func (b *healthBalancer) cleanupUnhealthy() { - b.unhealthyMu.Lock() - for k, v := range b.unhealthyHostPorts { - if time.Since(v) > b.healthCheckTimeout { - delete(b.unhealthyHostPorts, k) - logger.Lvl(4).Infof("clientv3/balancer: removed %q from unhealthy after %v", k, b.healthCheckTimeout) - } - } - b.unhealthyMu.Unlock() -} - -func (b *healthBalancer) liveAddrs() ([]grpc.Address, map[string]struct{}) { - unhealthyCnt := b.countUnhealthy() - - b.mu.RLock() - defer b.mu.RUnlock() - - hbAddrs := b.addrs - if len(b.addrs) == 1 || unhealthyCnt == 0 || unhealthyCnt == len(b.addrs) { - liveHostPorts := make(map[string]struct{}, len(b.hostPort2ep)) - for k := range b.hostPort2ep { - liveHostPorts[k] = struct{}{} - } - return hbAddrs, liveHostPorts - } - - addrs := make([]grpc.Address, 0, len(b.addrs)-unhealthyCnt) - liveHostPorts := make(map[string]struct{}, len(addrs)) - for _, addr := range b.addrs { - if !b.isUnhealthy(addr.Addr) { - addrs = append(addrs, addr) - liveHostPorts[addr.Addr] = struct{}{} - } - } - return addrs, liveHostPorts -} - -func (b *healthBalancer) updateUnhealthy() { - for { - select { - case <-time.After(b.healthCheckTimeout): - b.cleanupUnhealthy() - pinned := b.pinned() - if pinned == "" || b.isUnhealthy(pinned) { - select { - case b.updateAddrsC <- notifyNext: - case <-b.stopc: - return - } - } - case <-b.stopc: - return - } - } -} - -func (b *healthBalancer) updateAddrs(eps ...string) { - np := getHostPort2ep(eps) - - b.mu.Lock() - defer b.mu.Unlock() - - match := len(np) == len(b.hostPort2ep) - if match { - for k, v := range np { - if b.hostPort2ep[k] != v { - match = false - break - } - } - } - if match { - // same endpoints, so no need to update address - return - } - - b.hostPort2ep = np - b.addrs, b.eps = eps2addrs(eps), eps - - b.unhealthyMu.Lock() - b.unhealthyHostPorts = make(map[string]time.Time) - b.unhealthyMu.Unlock() -} - -func (b *healthBalancer) next() { - b.mu.RLock() - downc := b.downc - b.mu.RUnlock() - select { - case b.updateAddrsC <- notifyNext: - case <-b.stopc: - } - // wait until disconnect so new RPCs are not issued on old connection - select { - case <-downc: - case <-b.stopc: - } -} - -func (b *healthBalancer) updateNotifyLoop() { - defer close(b.donec) - - for { - b.mu.RLock() - upc, downc, addr := b.upc, b.downc, b.pinAddr - b.mu.RUnlock() - // downc or upc should be closed - select { - case <-downc: - downc = nil - default: - } - select { - case <-upc: - upc = nil - default: - } - switch { - case downc == nil && upc == nil: - // stale - select { - case <-b.stopc: - return - default: - } - case downc == nil: - b.notifyAddrs(notifyReset) - select { - case <-upc: - case msg := <-b.updateAddrsC: - b.notifyAddrs(msg) - case <-b.stopc: - return - } - case upc == nil: - select { - // close connections that are not the pinned address - case b.notifyCh <- []grpc.Address{{Addr: addr}}: - case <-downc: - case <-b.stopc: - return - } - select { - case <-downc: - b.notifyAddrs(notifyReset) - case msg := <-b.updateAddrsC: - b.notifyAddrs(msg) - case <-b.stopc: - return - } - } - } -} - -func (b *healthBalancer) notifyAddrs(msg notifyMsg) { - if msg == notifyNext { - select { - case b.notifyCh <- []grpc.Address{}: - case <-b.stopc: - return - } - } - b.mu.RLock() - pinAddr := b.pinAddr - downc := b.downc - b.mu.RUnlock() - addrs, hostPorts := b.liveAddrs() - - var waitDown bool - if pinAddr != "" { - _, ok := hostPorts[pinAddr] - waitDown = !ok - } - - select { - case b.notifyCh <- addrs: - if waitDown { - select { - case <-downc: - case <-b.stopc: - } - } - case <-b.stopc: - } -} - -func (b *healthBalancer) Up(addr grpc.Address) func(error) { - if !b.mayPin(addr) { - return func(err error) {} - } - - b.mu.Lock() - defer b.mu.Unlock() - - // gRPC might call Up after it called Close. We add this check - // to "fix" it up at application layer. Otherwise, will panic - // if b.upc is already closed. - if b.closed { - return func(err error) {} - } - - // gRPC might call Up on a stale address. - // Prevent updating pinAddr with a stale address. - if !hasAddr(b.addrs, addr.Addr) { - return func(err error) {} - } - - if b.pinAddr != "" { - logger.Lvl(4).Infof("clientv3/balancer: %q is up but not pinned (already pinned %q)", addr.Addr, b.pinAddr) - return func(err error) {} - } - - // notify waiting Get()s and pin first connected address - close(b.upc) - b.downc = make(chan struct{}) - b.pinAddr = addr.Addr - logger.Lvl(4).Infof("clientv3/balancer: pin %q", addr.Addr) - - // notify client that a connection is up - b.readyOnce.Do(func() { close(b.readyc) }) - - return func(err error) { - // If connected to a black hole endpoint or a killed server, the gRPC ping - // timeout will induce a network I/O error, and retrying until success; - // finding healthy endpoint on retry could take several timeouts and redials. - // To avoid wasting retries, gray-list unhealthy endpoints. - b.hostPortError(addr.Addr, err) - - b.mu.Lock() - b.upc = make(chan struct{}) - close(b.downc) - b.pinAddr = "" - b.mu.Unlock() - logger.Lvl(4).Infof("clientv3/balancer: unpin %q (%q)", addr.Addr, err.Error()) - } -} - -func (b *healthBalancer) mayPin(addr grpc.Address) bool { - if b.endpoint(addr.Addr) == "" { // stale host:port - return false - } - - b.unhealthyMu.RLock() - unhealthyCnt := len(b.unhealthyHostPorts) - failedTime, bad := b.unhealthyHostPorts[addr.Addr] - b.unhealthyMu.RUnlock() - - b.mu.RLock() - skip := len(b.addrs) == 1 || unhealthyCnt == 0 || len(b.addrs) == unhealthyCnt - b.mu.RUnlock() - if skip || !bad { - return true - } - - // prevent isolated member's endpoint from being infinitely retried, as follows: - // 1. keepalive pings detects GoAway with http2.ErrCodeEnhanceYourCalm - // 2. balancer 'Up' unpins with grpc: failed with network I/O error - // 3. grpc-healthcheck still SERVING, thus retry to pin - // instead, return before grpc-healthcheck if failed within healthcheck timeout - if elapsed := time.Since(failedTime); elapsed < b.healthCheckTimeout { - logger.Lvl(4).Infof("clientv3/balancer: %q is up but not pinned (failed %v ago, require minimum %v after failure)", addr.Addr, elapsed, b.healthCheckTimeout) - return false - } - - if ok, _ := b.healthCheck(addr.Addr); ok { - b.removeUnhealthy(addr.Addr, "health check success") - return true - } - - b.hostPortError(addr.Addr, errors.New("health check failed")) - return false -} - -func (b *healthBalancer) Get(ctx context.Context, opts grpc.BalancerGetOptions) (grpc.Address, func(), error) { - var ( - addr string - closed bool - ) - - // If opts.BlockingWait is false (for fail-fast RPCs), it should return - // an address it has notified via Notify immediately instead of blocking. - if !opts.BlockingWait { - b.mu.RLock() - closed = b.closed - addr = b.pinAddr - b.mu.RUnlock() - if closed { - return grpc.Address{Addr: ""}, nil, grpc.ErrClientConnClosing - } - if addr == "" { - return grpc.Address{Addr: ""}, nil, ErrNoAddrAvilable - } - return grpc.Address{Addr: addr}, func() {}, nil - } - - for { - b.mu.RLock() - ch := b.upc - b.mu.RUnlock() - select { - case <-ch: - case <-b.donec: - return grpc.Address{Addr: ""}, nil, grpc.ErrClientConnClosing - case <-ctx.Done(): - return grpc.Address{Addr: ""}, nil, ctx.Err() - } - b.mu.RLock() - closed = b.closed - addr = b.pinAddr - b.mu.RUnlock() - // Close() which sets b.closed = true can be called before Get(), Get() must exit if balancer is closed. - if closed { - return grpc.Address{Addr: ""}, nil, grpc.ErrClientConnClosing - } - if addr != "" { - break - } - } - return grpc.Address{Addr: addr}, func() {}, nil -} - -func (b *healthBalancer) Notify() <-chan []grpc.Address { return b.notifyCh } - -func (b *healthBalancer) Close() error { - b.mu.Lock() - // In case gRPC calls close twice. TODO: remove the checking - // when we are sure that gRPC wont call close twice. - if b.closed { - b.mu.Unlock() - <-b.donec - return nil - } - b.closed = true - b.stopOnce.Do(func() { close(b.stopc) }) - b.pinAddr = "" - - // In the case of following scenario: - // 1. upc is not closed; no pinned address - // 2. client issues an RPC, calling invoke(), which calls Get(), enters for loop, blocks - // 3. client.conn.Close() calls balancer.Close(); closed = true - // 4. for loop in Get() never exits since ctx is the context passed in by the client and may not be canceled - // we must close upc so Get() exits from blocking on upc - select { - case <-b.upc: - default: - // terminate all waiting Get()s - close(b.upc) - } - - b.mu.Unlock() - b.wg.Wait() - - // wait for updateNotifyLoop to finish - <-b.donec - close(b.notifyCh) - - return nil -} - -func grpcHealthCheck(client *Client, ep string) (bool, error) { - conn, err := client.dial(ep) - if err != nil { - return false, err - } - defer conn.Close() - cli := healthpb.NewHealthClient(conn) - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - resp, err := cli.Check(ctx, &healthpb.HealthCheckRequest{}) - cancel() - if err != nil { - if s, ok := status.FromError(err); ok && s.Code() == codes.Unavailable { - if s.Message() == unknownService { // etcd < v3.3.0 - return true, nil - } - } - return false, err - } - return resp.Status == healthpb.HealthCheckResponse_SERVING, nil -} - -func hasAddr(addrs []grpc.Address, targetAddr string) bool { - for _, addr := range addrs { - if targetAddr == addr.Addr { - return true - } - } - return false -} - -func getHost(ep string) string { - url, uerr := url.Parse(ep) - if uerr != nil || !strings.Contains(ep, "://") { - return ep - } - return url.Host -} - -func eps2addrs(eps []string) []grpc.Address { - addrs := make([]grpc.Address, len(eps)) - for i := range eps { - addrs[i].Addr = getHost(eps[i]) - } - return addrs -} - -func getHostPort2ep(eps []string) map[string]string { - hm := make(map[string]string, len(eps)) - for i := range eps { - _, host, _ := parseEndpoint(eps[i]) - hm[host] = eps[i] - } - return hm -} diff --git a/vendor/go.etcd.io/etcd/clientv3/kv.go b/vendor/go.etcd.io/etcd/clientv3/kv.go deleted file mode 100644 index 5a7469bd4c91..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/kv.go +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" -) - -type ( - CompactResponse pb.CompactionResponse - PutResponse pb.PutResponse - GetResponse pb.RangeResponse - DeleteResponse pb.DeleteRangeResponse - TxnResponse pb.TxnResponse -) - -type KV interface { - // Put puts a key-value pair into etcd. - // Note that key,value can be plain bytes array and string is - // an immutable representation of that bytes array. - // To get a string of bytes, do string([]byte{0x10, 0x20}). - Put(ctx context.Context, key, val string, opts ...OpOption) (*PutResponse, error) - - // Get retrieves keys. - // By default, Get will return the value for "key", if any. - // When passed WithRange(end), Get will return the keys in the range [key, end). - // When passed WithFromKey(), Get returns keys greater than or equal to key. - // When passed WithRev(rev) with rev > 0, Get retrieves keys at the given revision; - // if the required revision is compacted, the request will fail with ErrCompacted . - // When passed WithLimit(limit), the number of returned keys is bounded by limit. - // When passed WithSort(), the keys will be sorted. - Get(ctx context.Context, key string, opts ...OpOption) (*GetResponse, error) - - // Delete deletes a key, or optionally using WithRange(end), [key, end). - Delete(ctx context.Context, key string, opts ...OpOption) (*DeleteResponse, error) - - // Compact compacts etcd KV history before the given rev. - Compact(ctx context.Context, rev int64, opts ...CompactOption) (*CompactResponse, error) - - // Do applies a single Op on KV without a transaction. - // Do is useful when creating arbitrary operations to be issued at a - // later time; the user can range over the operations, calling Do to - // execute them. Get/Put/Delete, on the other hand, are best suited - // for when the operation should be issued at the time of declaration. - Do(ctx context.Context, op Op) (OpResponse, error) - - // Txn creates a transaction. - Txn(ctx context.Context) Txn -} - -type OpResponse struct { - put *PutResponse - get *GetResponse - del *DeleteResponse - txn *TxnResponse -} - -func (op OpResponse) Put() *PutResponse { return op.put } -func (op OpResponse) Get() *GetResponse { return op.get } -func (op OpResponse) Del() *DeleteResponse { return op.del } -func (op OpResponse) Txn() *TxnResponse { return op.txn } - -func (resp *PutResponse) OpResponse() OpResponse { - return OpResponse{put: resp} -} -func (resp *GetResponse) OpResponse() OpResponse { - return OpResponse{get: resp} -} -func (resp *DeleteResponse) OpResponse() OpResponse { - return OpResponse{del: resp} -} -func (resp *TxnResponse) OpResponse() OpResponse { - return OpResponse{txn: resp} -} - -type kv struct { - remote pb.KVClient - callOpts []grpc.CallOption -} - -func NewKV(c *Client) KV { - api := &kv{remote: RetryKVClient(c)} - if c != nil { - api.callOpts = c.callOpts - } - return api -} - -func NewKVFromKVClient(remote pb.KVClient, c *Client) KV { - api := &kv{remote: remote} - if c != nil { - api.callOpts = c.callOpts - } - return api -} - -func (kv *kv) Put(ctx context.Context, key, val string, opts ...OpOption) (*PutResponse, error) { - r, err := kv.Do(ctx, OpPut(key, val, opts...)) - return r.put, toErr(ctx, err) -} - -func (kv *kv) Get(ctx context.Context, key string, opts ...OpOption) (*GetResponse, error) { - r, err := kv.Do(ctx, OpGet(key, opts...)) - return r.get, toErr(ctx, err) -} - -func (kv *kv) Delete(ctx context.Context, key string, opts ...OpOption) (*DeleteResponse, error) { - r, err := kv.Do(ctx, OpDelete(key, opts...)) - return r.del, toErr(ctx, err) -} - -func (kv *kv) Compact(ctx context.Context, rev int64, opts ...CompactOption) (*CompactResponse, error) { - resp, err := kv.remote.Compact(ctx, OpCompact(rev, opts...).toRequest(), kv.callOpts...) - if err != nil { - return nil, toErr(ctx, err) - } - return (*CompactResponse)(resp), err -} - -func (kv *kv) Txn(ctx context.Context) Txn { - return &txn{ - kv: kv, - ctx: ctx, - callOpts: kv.callOpts, - } -} - -func (kv *kv) Do(ctx context.Context, op Op) (OpResponse, error) { - var err error - switch op.t { - case tRange: - var resp *pb.RangeResponse - resp, err = kv.remote.Range(ctx, op.toRangeRequest(), kv.callOpts...) - if err == nil { - return OpResponse{get: (*GetResponse)(resp)}, nil - } - case tPut: - var resp *pb.PutResponse - r := &pb.PutRequest{Key: op.key, Value: op.val, Lease: int64(op.leaseID), PrevKv: op.prevKV, IgnoreValue: op.ignoreValue, IgnoreLease: op.ignoreLease} - resp, err = kv.remote.Put(ctx, r, kv.callOpts...) - if err == nil { - return OpResponse{put: (*PutResponse)(resp)}, nil - } - case tDeleteRange: - var resp *pb.DeleteRangeResponse - r := &pb.DeleteRangeRequest{Key: op.key, RangeEnd: op.end, PrevKv: op.prevKV} - resp, err = kv.remote.DeleteRange(ctx, r, kv.callOpts...) - if err == nil { - return OpResponse{del: (*DeleteResponse)(resp)}, nil - } - case tTxn: - var resp *pb.TxnResponse - resp, err = kv.remote.Txn(ctx, op.toTxnRequest(), kv.callOpts...) - if err == nil { - return OpResponse{txn: (*TxnResponse)(resp)}, nil - } - default: - panic("Unknown op") - } - return OpResponse{}, toErr(ctx, err) -} diff --git a/vendor/go.etcd.io/etcd/clientv3/lease.go b/vendor/go.etcd.io/etcd/clientv3/lease.go deleted file mode 100644 index 3729cf37be04..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/lease.go +++ /dev/null @@ -1,588 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - "sync" - "time" - - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" - "google.golang.org/grpc/metadata" -) - -type ( - LeaseRevokeResponse pb.LeaseRevokeResponse - LeaseID int64 -) - -// LeaseGrantResponse wraps the protobuf message LeaseGrantResponse. -type LeaseGrantResponse struct { - *pb.ResponseHeader - ID LeaseID - TTL int64 - Error string -} - -// LeaseKeepAliveResponse wraps the protobuf message LeaseKeepAliveResponse. -type LeaseKeepAliveResponse struct { - *pb.ResponseHeader - ID LeaseID - TTL int64 -} - -// LeaseTimeToLiveResponse wraps the protobuf message LeaseTimeToLiveResponse. -type LeaseTimeToLiveResponse struct { - *pb.ResponseHeader - ID LeaseID `json:"id"` - - // TTL is the remaining TTL in seconds for the lease; the lease will expire in under TTL+1 seconds. Expired lease will return -1. - TTL int64 `json:"ttl"` - - // GrantedTTL is the initial granted time in seconds upon lease creation/renewal. - GrantedTTL int64 `json:"granted-ttl"` - - // Keys is the list of keys attached to this lease. - Keys [][]byte `json:"keys"` -} - -// LeaseStatus represents a lease status. -type LeaseStatus struct { - ID LeaseID `json:"id"` - // TODO: TTL int64 -} - -// LeaseLeasesResponse wraps the protobuf message LeaseLeasesResponse. -type LeaseLeasesResponse struct { - *pb.ResponseHeader - Leases []LeaseStatus `json:"leases"` -} - -const ( - // defaultTTL is the assumed lease TTL used for the first keepalive - // deadline before the actual TTL is known to the client. - defaultTTL = 5 * time.Second - // NoLease is a lease ID for the absence of a lease. - NoLease LeaseID = 0 - - // retryConnWait is how long to wait before retrying request due to an error - retryConnWait = 500 * time.Millisecond -) - -// LeaseResponseChSize is the size of buffer to store unsent lease responses. -// WARNING: DO NOT UPDATE. -// Only for testing purposes. -var LeaseResponseChSize = 16 - -// ErrKeepAliveHalted is returned if client keep alive loop halts with an unexpected error. -// -// This usually means that automatic lease renewal via KeepAlive is broken, but KeepAliveOnce will still work as expected. -type ErrKeepAliveHalted struct { - Reason error -} - -func (e ErrKeepAliveHalted) Error() string { - s := "etcdclient: leases keep alive halted" - if e.Reason != nil { - s += ": " + e.Reason.Error() - } - return s -} - -type Lease interface { - // Grant creates a new lease. - Grant(ctx context.Context, ttl int64) (*LeaseGrantResponse, error) - - // Revoke revokes the given lease. - Revoke(ctx context.Context, id LeaseID) (*LeaseRevokeResponse, error) - - // TimeToLive retrieves the lease information of the given lease ID. - TimeToLive(ctx context.Context, id LeaseID, opts ...LeaseOption) (*LeaseTimeToLiveResponse, error) - - // Leases retrieves all leases. - Leases(ctx context.Context) (*LeaseLeasesResponse, error) - - // KeepAlive keeps the given lease alive forever. If the keepalive response - // posted to the channel is not consumed immediately, the lease client will - // continue sending keep alive requests to the etcd server at least every - // second until latest response is consumed. - // - // The returned "LeaseKeepAliveResponse" channel closes if underlying keep - // alive stream is interrupted in some way the client cannot handle itself; - // given context "ctx" is canceled or timed out. "LeaseKeepAliveResponse" - // from this closed channel is nil. - // - // If client keep alive loop halts with an unexpected error (e.g. "etcdserver: - // no leader") or canceled by the caller (e.g. context.Canceled), the error - // is returned. Otherwise, it retries. - // - // TODO(v4.0): post errors to last keep alive message before closing - // (see https://github.com/coreos/etcd/pull/7866) - KeepAlive(ctx context.Context, id LeaseID) (<-chan *LeaseKeepAliveResponse, error) - - // KeepAliveOnce renews the lease once. The response corresponds to the - // first message from calling KeepAlive. If the response has a recoverable - // error, KeepAliveOnce will retry the RPC with a new keep alive message. - // - // In most of the cases, Keepalive should be used instead of KeepAliveOnce. - KeepAliveOnce(ctx context.Context, id LeaseID) (*LeaseKeepAliveResponse, error) - - // Close releases all resources Lease keeps for efficient communication - // with the etcd server. - Close() error -} - -type lessor struct { - mu sync.Mutex // guards all fields - - // donec is closed and loopErr is set when recvKeepAliveLoop stops - donec chan struct{} - loopErr error - - remote pb.LeaseClient - - stream pb.Lease_LeaseKeepAliveClient - streamCancel context.CancelFunc - - stopCtx context.Context - stopCancel context.CancelFunc - - keepAlives map[LeaseID]*keepAlive - - // firstKeepAliveTimeout is the timeout for the first keepalive request - // before the actual TTL is known to the lease client - firstKeepAliveTimeout time.Duration - - // firstKeepAliveOnce ensures stream starts after first KeepAlive call. - firstKeepAliveOnce sync.Once - - callOpts []grpc.CallOption -} - -// keepAlive multiplexes a keepalive for a lease over multiple channels -type keepAlive struct { - chs []chan<- *LeaseKeepAliveResponse - ctxs []context.Context - // deadline is the time the keep alive channels close if no response - deadline time.Time - // nextKeepAlive is when to send the next keep alive message - nextKeepAlive time.Time - // donec is closed on lease revoke, expiration, or cancel. - donec chan struct{} -} - -func NewLease(c *Client) Lease { - return NewLeaseFromLeaseClient(RetryLeaseClient(c), c, c.cfg.DialTimeout+time.Second) -} - -func NewLeaseFromLeaseClient(remote pb.LeaseClient, c *Client, keepAliveTimeout time.Duration) Lease { - l := &lessor{ - donec: make(chan struct{}), - keepAlives: make(map[LeaseID]*keepAlive), - remote: remote, - firstKeepAliveTimeout: keepAliveTimeout, - } - if l.firstKeepAliveTimeout == time.Second { - l.firstKeepAliveTimeout = defaultTTL - } - if c != nil { - l.callOpts = c.callOpts - } - reqLeaderCtx := WithRequireLeader(context.Background()) - l.stopCtx, l.stopCancel = context.WithCancel(reqLeaderCtx) - return l -} - -func (l *lessor) Grant(ctx context.Context, ttl int64) (*LeaseGrantResponse, error) { - r := &pb.LeaseGrantRequest{TTL: ttl} - resp, err := l.remote.LeaseGrant(ctx, r, l.callOpts...) - if err == nil { - gresp := &LeaseGrantResponse{ - ResponseHeader: resp.GetHeader(), - ID: LeaseID(resp.ID), - TTL: resp.TTL, - Error: resp.Error, - } - return gresp, nil - } - return nil, toErr(ctx, err) -} - -func (l *lessor) Revoke(ctx context.Context, id LeaseID) (*LeaseRevokeResponse, error) { - r := &pb.LeaseRevokeRequest{ID: int64(id)} - resp, err := l.remote.LeaseRevoke(ctx, r, l.callOpts...) - if err == nil { - return (*LeaseRevokeResponse)(resp), nil - } - return nil, toErr(ctx, err) -} - -func (l *lessor) TimeToLive(ctx context.Context, id LeaseID, opts ...LeaseOption) (*LeaseTimeToLiveResponse, error) { - r := toLeaseTimeToLiveRequest(id, opts...) - resp, err := l.remote.LeaseTimeToLive(ctx, r, l.callOpts...) - if err == nil { - gresp := &LeaseTimeToLiveResponse{ - ResponseHeader: resp.GetHeader(), - ID: LeaseID(resp.ID), - TTL: resp.TTL, - GrantedTTL: resp.GrantedTTL, - Keys: resp.Keys, - } - return gresp, nil - } - return nil, toErr(ctx, err) -} - -func (l *lessor) Leases(ctx context.Context) (*LeaseLeasesResponse, error) { - resp, err := l.remote.LeaseLeases(ctx, &pb.LeaseLeasesRequest{}, l.callOpts...) - if err == nil { - leases := make([]LeaseStatus, len(resp.Leases)) - for i := range resp.Leases { - leases[i] = LeaseStatus{ID: LeaseID(resp.Leases[i].ID)} - } - return &LeaseLeasesResponse{ResponseHeader: resp.GetHeader(), Leases: leases}, nil - } - return nil, toErr(ctx, err) -} - -func (l *lessor) KeepAlive(ctx context.Context, id LeaseID) (<-chan *LeaseKeepAliveResponse, error) { - ch := make(chan *LeaseKeepAliveResponse, LeaseResponseChSize) - - l.mu.Lock() - // ensure that recvKeepAliveLoop is still running - select { - case <-l.donec: - err := l.loopErr - l.mu.Unlock() - close(ch) - return ch, ErrKeepAliveHalted{Reason: err} - default: - } - ka, ok := l.keepAlives[id] - if !ok { - // create fresh keep alive - ka = &keepAlive{ - chs: []chan<- *LeaseKeepAliveResponse{ch}, - ctxs: []context.Context{ctx}, - deadline: time.Now().Add(l.firstKeepAliveTimeout), - nextKeepAlive: time.Now(), - donec: make(chan struct{}), - } - l.keepAlives[id] = ka - } else { - // add channel and context to existing keep alive - ka.ctxs = append(ka.ctxs, ctx) - ka.chs = append(ka.chs, ch) - } - l.mu.Unlock() - - go l.keepAliveCtxCloser(id, ctx, ka.donec) - l.firstKeepAliveOnce.Do(func() { - go l.recvKeepAliveLoop() - go l.deadlineLoop() - }) - - return ch, nil -} - -func (l *lessor) KeepAliveOnce(ctx context.Context, id LeaseID) (*LeaseKeepAliveResponse, error) { - for { - resp, err := l.keepAliveOnce(ctx, id) - if err == nil { - if resp.TTL <= 0 { - err = rpctypes.ErrLeaseNotFound - } - return resp, err - } - if isHaltErr(ctx, err) { - return nil, toErr(ctx, err) - } - } -} - -func (l *lessor) Close() error { - l.stopCancel() - // close for synchronous teardown if stream goroutines never launched - l.firstKeepAliveOnce.Do(func() { close(l.donec) }) - <-l.donec - return nil -} - -func (l *lessor) keepAliveCtxCloser(id LeaseID, ctx context.Context, donec <-chan struct{}) { - select { - case <-donec: - return - case <-l.donec: - return - case <-ctx.Done(): - } - - l.mu.Lock() - defer l.mu.Unlock() - - ka, ok := l.keepAlives[id] - if !ok { - return - } - - // close channel and remove context if still associated with keep alive - for i, c := range ka.ctxs { - if c == ctx { - close(ka.chs[i]) - ka.ctxs = append(ka.ctxs[:i], ka.ctxs[i+1:]...) - ka.chs = append(ka.chs[:i], ka.chs[i+1:]...) - break - } - } - // remove if no one more listeners - if len(ka.chs) == 0 { - delete(l.keepAlives, id) - } -} - -// closeRequireLeader scans keepAlives for ctxs that have require leader -// and closes the associated channels. -func (l *lessor) closeRequireLeader() { - l.mu.Lock() - defer l.mu.Unlock() - for _, ka := range l.keepAlives { - reqIdxs := 0 - // find all required leader channels, close, mark as nil - for i, ctx := range ka.ctxs { - md, ok := metadata.FromOutgoingContext(ctx) - if !ok { - continue - } - ks := md[rpctypes.MetadataRequireLeaderKey] - if len(ks) < 1 || ks[0] != rpctypes.MetadataHasLeader { - continue - } - close(ka.chs[i]) - ka.chs[i] = nil - reqIdxs++ - } - if reqIdxs == 0 { - continue - } - // remove all channels that required a leader from keepalive - newChs := make([]chan<- *LeaseKeepAliveResponse, len(ka.chs)-reqIdxs) - newCtxs := make([]context.Context, len(newChs)) - newIdx := 0 - for i := range ka.chs { - if ka.chs[i] == nil { - continue - } - newChs[newIdx], newCtxs[newIdx] = ka.chs[i], ka.ctxs[newIdx] - newIdx++ - } - ka.chs, ka.ctxs = newChs, newCtxs - } -} - -func (l *lessor) keepAliveOnce(ctx context.Context, id LeaseID) (*LeaseKeepAliveResponse, error) { - cctx, cancel := context.WithCancel(ctx) - defer cancel() - - stream, err := l.remote.LeaseKeepAlive(cctx, l.callOpts...) - if err != nil { - return nil, toErr(ctx, err) - } - - err = stream.Send(&pb.LeaseKeepAliveRequest{ID: int64(id)}) - if err != nil { - return nil, toErr(ctx, err) - } - - resp, rerr := stream.Recv() - if rerr != nil { - return nil, toErr(ctx, rerr) - } - - karesp := &LeaseKeepAliveResponse{ - ResponseHeader: resp.GetHeader(), - ID: LeaseID(resp.ID), - TTL: resp.TTL, - } - return karesp, nil -} - -func (l *lessor) recvKeepAliveLoop() (gerr error) { - defer func() { - l.mu.Lock() - close(l.donec) - l.loopErr = gerr - for _, ka := range l.keepAlives { - ka.close() - } - l.keepAlives = make(map[LeaseID]*keepAlive) - l.mu.Unlock() - }() - - for { - stream, err := l.resetRecv() - if err != nil { - if canceledByCaller(l.stopCtx, err) { - return err - } - } else { - for { - resp, err := stream.Recv() - if err != nil { - if canceledByCaller(l.stopCtx, err) { - return err - } - - if toErr(l.stopCtx, err) == rpctypes.ErrNoLeader { - l.closeRequireLeader() - } - break - } - - l.recvKeepAlive(resp) - } - } - - select { - case <-time.After(retryConnWait): - continue - case <-l.stopCtx.Done(): - return l.stopCtx.Err() - } - } -} - -// resetRecv opens a new lease stream and starts sending keep alive requests. -func (l *lessor) resetRecv() (pb.Lease_LeaseKeepAliveClient, error) { - sctx, cancel := context.WithCancel(l.stopCtx) - stream, err := l.remote.LeaseKeepAlive(sctx, l.callOpts...) - if err != nil { - cancel() - return nil, err - } - - l.mu.Lock() - defer l.mu.Unlock() - if l.stream != nil && l.streamCancel != nil { - l.streamCancel() - } - - l.streamCancel = cancel - l.stream = stream - - go l.sendKeepAliveLoop(stream) - return stream, nil -} - -// recvKeepAlive updates a lease based on its LeaseKeepAliveResponse -func (l *lessor) recvKeepAlive(resp *pb.LeaseKeepAliveResponse) { - karesp := &LeaseKeepAliveResponse{ - ResponseHeader: resp.GetHeader(), - ID: LeaseID(resp.ID), - TTL: resp.TTL, - } - - l.mu.Lock() - defer l.mu.Unlock() - - ka, ok := l.keepAlives[karesp.ID] - if !ok { - return - } - - if karesp.TTL <= 0 { - // lease expired; close all keep alive channels - delete(l.keepAlives, karesp.ID) - ka.close() - return - } - - // send update to all channels - nextKeepAlive := time.Now().Add((time.Duration(karesp.TTL) * time.Second) / 3.0) - ka.deadline = time.Now().Add(time.Duration(karesp.TTL) * time.Second) - for _, ch := range ka.chs { - select { - case ch <- karesp: - default: - } - // still advance in order to rate-limit keep-alive sends - ka.nextKeepAlive = nextKeepAlive - } -} - -// deadlineLoop reaps any keep alive channels that have not received a response -// within the lease TTL -func (l *lessor) deadlineLoop() { - for { - select { - case <-time.After(time.Second): - case <-l.donec: - return - } - now := time.Now() - l.mu.Lock() - for id, ka := range l.keepAlives { - if ka.deadline.Before(now) { - // waited too long for response; lease may be expired - ka.close() - delete(l.keepAlives, id) - } - } - l.mu.Unlock() - } -} - -// sendKeepAliveLoop sends keep alive requests for the lifetime of the given stream. -func (l *lessor) sendKeepAliveLoop(stream pb.Lease_LeaseKeepAliveClient) { - for { - var tosend []LeaseID - - now := time.Now() - l.mu.Lock() - for id, ka := range l.keepAlives { - if ka.nextKeepAlive.Before(now) { - tosend = append(tosend, id) - } - } - l.mu.Unlock() - - for _, id := range tosend { - r := &pb.LeaseKeepAliveRequest{ID: int64(id)} - if err := stream.Send(r); err != nil { - // TODO do something with this error? - return - } - } - - select { - case <-time.After(500 * time.Millisecond): - case <-stream.Context().Done(): - return - case <-l.donec: - return - case <-l.stopCtx.Done(): - return - } - } -} - -func (ka *keepAlive) close() { - close(ka.donec) - for _, ch := range ka.chs { - close(ch) - } -} diff --git a/vendor/go.etcd.io/etcd/clientv3/leasing/cache.go b/vendor/go.etcd.io/etcd/clientv3/leasing/cache.go deleted file mode 100644 index 6903a785c789..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/leasing/cache.go +++ /dev/null @@ -1,306 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package leasing - -import ( - "context" - "strings" - "sync" - "time" - - v3 "github.com/coreos/etcd/clientv3" - v3pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -const revokeBackoff = 2 * time.Second - -type leaseCache struct { - mu sync.RWMutex - entries map[string]*leaseKey - revokes map[string]time.Time - header *v3pb.ResponseHeader -} - -type leaseKey struct { - response *v3.GetResponse - // rev is the leasing key revision. - rev int64 - waitc chan struct{} -} - -func (lc *leaseCache) Rev(key string) int64 { - lc.mu.RLock() - defer lc.mu.RUnlock() - if li := lc.entries[key]; li != nil { - return li.rev - } - return 0 -} - -func (lc *leaseCache) Lock(key string) (chan<- struct{}, int64) { - lc.mu.Lock() - defer lc.mu.Unlock() - if li := lc.entries[key]; li != nil { - li.waitc = make(chan struct{}) - return li.waitc, li.rev - } - return nil, 0 -} - -func (lc *leaseCache) LockRange(begin, end string) (ret []chan<- struct{}) { - lc.mu.Lock() - defer lc.mu.Unlock() - for k, li := range lc.entries { - if inRange(k, begin, end) { - li.waitc = make(chan struct{}) - ret = append(ret, li.waitc) - } - } - return ret -} - -func inRange(k, begin, end string) bool { - if strings.Compare(k, begin) < 0 { - return false - } - if end != "\x00" && strings.Compare(k, end) >= 0 { - return false - } - return true -} - -func (lc *leaseCache) LockWriteOps(ops []v3.Op) (ret []chan<- struct{}) { - for _, op := range ops { - if op.IsGet() { - continue - } - key := string(op.KeyBytes()) - if end := string(op.RangeBytes()); end == "" { - if wc, _ := lc.Lock(key); wc != nil { - ret = append(ret, wc) - } - } else { - for k := range lc.entries { - if !inRange(k, key, end) { - continue - } - if wc, _ := lc.Lock(k); wc != nil { - ret = append(ret, wc) - } - } - } - } - return ret -} - -func (lc *leaseCache) NotifyOps(ops []v3.Op) (wcs []<-chan struct{}) { - for _, op := range ops { - if op.IsGet() { - if _, wc := lc.notify(string(op.KeyBytes())); wc != nil { - wcs = append(wcs, wc) - } - } - } - return wcs -} - -func (lc *leaseCache) MayAcquire(key string) bool { - lc.mu.RLock() - lr, ok := lc.revokes[key] - lc.mu.RUnlock() - return !ok || time.Since(lr) > revokeBackoff -} - -func (lc *leaseCache) Add(key string, resp *v3.GetResponse, op v3.Op) *v3.GetResponse { - lk := &leaseKey{resp, resp.Header.Revision, closedCh} - lc.mu.Lock() - if lc.header == nil || lc.header.Revision < resp.Header.Revision { - lc.header = resp.Header - } - lc.entries[key] = lk - ret := lk.get(op) - lc.mu.Unlock() - return ret -} - -func (lc *leaseCache) Update(key, val []byte, respHeader *v3pb.ResponseHeader) { - li := lc.entries[string(key)] - if li == nil { - return - } - cacheResp := li.response - if len(cacheResp.Kvs) == 0 { - kv := &mvccpb.KeyValue{ - Key: key, - CreateRevision: respHeader.Revision, - } - cacheResp.Kvs = append(cacheResp.Kvs, kv) - cacheResp.Count = 1 - } - cacheResp.Kvs[0].Version++ - if cacheResp.Kvs[0].ModRevision < respHeader.Revision { - cacheResp.Header = respHeader - cacheResp.Kvs[0].ModRevision = respHeader.Revision - cacheResp.Kvs[0].Value = val - } -} - -func (lc *leaseCache) Delete(key string, hdr *v3pb.ResponseHeader) { - lc.mu.Lock() - defer lc.mu.Unlock() - lc.delete(key, hdr) -} - -func (lc *leaseCache) delete(key string, hdr *v3pb.ResponseHeader) { - if li := lc.entries[key]; li != nil && hdr.Revision >= li.response.Header.Revision { - li.response.Kvs = nil - li.response.Header = copyHeader(hdr) - } -} - -func (lc *leaseCache) Evict(key string) (rev int64) { - lc.mu.Lock() - defer lc.mu.Unlock() - if li := lc.entries[key]; li != nil { - rev = li.rev - delete(lc.entries, key) - lc.revokes[key] = time.Now() - } - return rev -} - -func (lc *leaseCache) EvictRange(key, end string) { - lc.mu.Lock() - defer lc.mu.Unlock() - for k := range lc.entries { - if inRange(k, key, end) { - delete(lc.entries, key) - lc.revokes[key] = time.Now() - } - } -} - -func isBadOp(op v3.Op) bool { return op.Rev() > 0 || len(op.RangeBytes()) > 0 } - -func (lc *leaseCache) Get(ctx context.Context, op v3.Op) (*v3.GetResponse, bool) { - if isBadOp(op) { - return nil, false - } - key := string(op.KeyBytes()) - li, wc := lc.notify(key) - if li == nil { - return nil, true - } - select { - case <-wc: - case <-ctx.Done(): - return nil, true - } - lc.mu.RLock() - lk := *li - ret := lk.get(op) - lc.mu.RUnlock() - return ret, true -} - -func (lk *leaseKey) get(op v3.Op) *v3.GetResponse { - ret := *lk.response - ret.Header = copyHeader(ret.Header) - empty := len(ret.Kvs) == 0 || op.IsCountOnly() - empty = empty || (op.MinModRev() > ret.Kvs[0].ModRevision) - empty = empty || (op.MaxModRev() != 0 && op.MaxModRev() < ret.Kvs[0].ModRevision) - empty = empty || (op.MinCreateRev() > ret.Kvs[0].CreateRevision) - empty = empty || (op.MaxCreateRev() != 0 && op.MaxCreateRev() < ret.Kvs[0].CreateRevision) - if empty { - ret.Kvs = nil - } else { - kv := *ret.Kvs[0] - kv.Key = make([]byte, len(kv.Key)) - copy(kv.Key, ret.Kvs[0].Key) - if !op.IsKeysOnly() { - kv.Value = make([]byte, len(kv.Value)) - copy(kv.Value, ret.Kvs[0].Value) - } - ret.Kvs = []*mvccpb.KeyValue{&kv} - } - return &ret -} - -func (lc *leaseCache) notify(key string) (*leaseKey, <-chan struct{}) { - lc.mu.RLock() - defer lc.mu.RUnlock() - if li := lc.entries[key]; li != nil { - return li, li.waitc - } - return nil, nil -} - -func (lc *leaseCache) clearOldRevokes(ctx context.Context) { - for { - select { - case <-ctx.Done(): - return - case <-time.After(time.Second): - lc.mu.Lock() - for k, lr := range lc.revokes { - if time.Now().Sub(lr.Add(revokeBackoff)) > 0 { - delete(lc.revokes, k) - } - } - lc.mu.Unlock() - } - } -} - -func (lc *leaseCache) evalCmp(cmps []v3.Cmp) (cmpVal bool, ok bool) { - for _, cmp := range cmps { - if len(cmp.RangeEnd) > 0 { - return false, false - } - lk := lc.entries[string(cmp.Key)] - if lk == nil { - return false, false - } - if !evalCmp(lk.response, cmp) { - return false, true - } - } - return true, true -} - -func (lc *leaseCache) evalOps(ops []v3.Op) ([]*v3pb.ResponseOp, bool) { - resps := make([]*v3pb.ResponseOp, len(ops)) - for i, op := range ops { - if !op.IsGet() || isBadOp(op) { - // TODO: support read-only Txn - return nil, false - } - lk := lc.entries[string(op.KeyBytes())] - if lk == nil { - return nil, false - } - resp := lk.get(op) - if resp == nil { - return nil, false - } - resps[i] = &v3pb.ResponseOp{ - Response: &v3pb.ResponseOp_ResponseRange{ - (*v3pb.RangeResponse)(resp), - }, - } - } - return resps, true -} diff --git a/vendor/go.etcd.io/etcd/clientv3/leasing/doc.go b/vendor/go.etcd.io/etcd/clientv3/leasing/doc.go deleted file mode 100644 index fc97fc882689..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/leasing/doc.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package leasing serves linearizable reads from a local cache by acquiring -// exclusive write access to keys through a client-side leasing protocol. This -// leasing layer can either directly wrap the etcd client or it can be exposed -// through the etcd grpc proxy server, granting multiple clients write access. -// -// First, create a leasing KV from a clientv3.Client 'cli': -// -// lkv, err := leasing.NewKV(cli, "leasing-prefix") -// if err != nil { -// // handle error -// } -// -// A range request for a key "abc" tries to acquire a leasing key so it can cache the range's -// key locally. On the server, the leasing key is stored to "leasing-prefix/abc": -// -// resp, err := lkv.Get(context.TODO(), "abc") -// -// Future linearized read requests using 'lkv' will be served locally for the lease's lifetime: -// -// resp, err = lkv.Get(context.TODO(), "abc") -// -// If another leasing client writes to a leased key, then the owner relinquishes its exclusive -// access, permitting the writer to modify the key: -// -// lkv2, err := leasing.NewKV(cli, "leasing-prefix") -// if err != nil { -// // handle error -// } -// lkv2.Put(context.TODO(), "abc", "456") -// resp, err = lkv.Get("abc") -// -package leasing diff --git a/vendor/go.etcd.io/etcd/clientv3/leasing/kv.go b/vendor/go.etcd.io/etcd/clientv3/leasing/kv.go deleted file mode 100644 index 5a5e2312b726..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/leasing/kv.go +++ /dev/null @@ -1,479 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package leasing - -import ( - "context" - "strings" - "sync" - "time" - - v3 "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/concurrency" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc/mvccpb" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -type leasingKV struct { - cl *v3.Client - kv v3.KV - pfx string - leases leaseCache - - ctx context.Context - cancel context.CancelFunc - wg sync.WaitGroup - - sessionOpts []concurrency.SessionOption - session *concurrency.Session - sessionc chan struct{} -} - -var closedCh chan struct{} - -func init() { - closedCh = make(chan struct{}) - close(closedCh) -} - -// NewKV wraps a KV instance so that all requests are wired through a leasing protocol. -func NewKV(cl *v3.Client, pfx string, opts ...concurrency.SessionOption) (v3.KV, func(), error) { - cctx, cancel := context.WithCancel(cl.Ctx()) - lkv := &leasingKV{ - cl: cl, - kv: cl.KV, - pfx: pfx, - leases: leaseCache{revokes: make(map[string]time.Time)}, - ctx: cctx, - cancel: cancel, - sessionOpts: opts, - sessionc: make(chan struct{}), - } - lkv.wg.Add(2) - go func() { - defer lkv.wg.Done() - lkv.monitorSession() - }() - go func() { - defer lkv.wg.Done() - lkv.leases.clearOldRevokes(cctx) - }() - return lkv, lkv.Close, lkv.waitSession(cctx) -} - -func (lkv *leasingKV) Close() { - lkv.cancel() - lkv.wg.Wait() -} - -func (lkv *leasingKV) Get(ctx context.Context, key string, opts ...v3.OpOption) (*v3.GetResponse, error) { - return lkv.get(ctx, v3.OpGet(key, opts...)) -} - -func (lkv *leasingKV) Put(ctx context.Context, key, val string, opts ...v3.OpOption) (*v3.PutResponse, error) { - return lkv.put(ctx, v3.OpPut(key, val, opts...)) -} - -func (lkv *leasingKV) Delete(ctx context.Context, key string, opts ...v3.OpOption) (*v3.DeleteResponse, error) { - return lkv.delete(ctx, v3.OpDelete(key, opts...)) -} - -func (lkv *leasingKV) Do(ctx context.Context, op v3.Op) (v3.OpResponse, error) { - switch { - case op.IsGet(): - resp, err := lkv.get(ctx, op) - return resp.OpResponse(), err - case op.IsPut(): - resp, err := lkv.put(ctx, op) - return resp.OpResponse(), err - case op.IsDelete(): - resp, err := lkv.delete(ctx, op) - return resp.OpResponse(), err - case op.IsTxn(): - cmps, thenOps, elseOps := op.Txn() - resp, err := lkv.Txn(ctx).If(cmps...).Then(thenOps...).Else(elseOps...).Commit() - return resp.OpResponse(), err - } - return v3.OpResponse{}, nil -} - -func (lkv *leasingKV) Compact(ctx context.Context, rev int64, opts ...v3.CompactOption) (*v3.CompactResponse, error) { - return lkv.kv.Compact(ctx, rev, opts...) -} - -func (lkv *leasingKV) Txn(ctx context.Context) v3.Txn { - return &txnLeasing{Txn: lkv.kv.Txn(ctx), lkv: lkv, ctx: ctx} -} - -func (lkv *leasingKV) monitorSession() { - for lkv.ctx.Err() == nil { - if lkv.session != nil { - select { - case <-lkv.session.Done(): - case <-lkv.ctx.Done(): - return - } - } - lkv.leases.mu.Lock() - select { - case <-lkv.sessionc: - lkv.sessionc = make(chan struct{}) - default: - } - lkv.leases.entries = make(map[string]*leaseKey) - lkv.leases.mu.Unlock() - - s, err := concurrency.NewSession(lkv.cl, lkv.sessionOpts...) - if err != nil { - continue - } - - lkv.leases.mu.Lock() - lkv.session = s - close(lkv.sessionc) - lkv.leases.mu.Unlock() - } -} - -func (lkv *leasingKV) monitorLease(ctx context.Context, key string, rev int64) { - cctx, cancel := context.WithCancel(lkv.ctx) - defer cancel() - for cctx.Err() == nil { - if rev == 0 { - resp, err := lkv.kv.Get(ctx, lkv.pfx+key) - if err != nil { - continue - } - rev = resp.Header.Revision - if len(resp.Kvs) == 0 || string(resp.Kvs[0].Value) == "REVOKE" { - lkv.rescind(cctx, key, rev) - return - } - } - wch := lkv.cl.Watch(cctx, lkv.pfx+key, v3.WithRev(rev+1)) - for resp := range wch { - for _, ev := range resp.Events { - if string(ev.Kv.Value) != "REVOKE" { - continue - } - if v3.LeaseID(ev.Kv.Lease) == lkv.leaseID() { - lkv.rescind(cctx, key, ev.Kv.ModRevision) - } - return - } - } - rev = 0 - } -} - -// rescind releases a lease from this client. -func (lkv *leasingKV) rescind(ctx context.Context, key string, rev int64) { - if lkv.leases.Evict(key) > rev { - return - } - cmp := v3.Compare(v3.CreateRevision(lkv.pfx+key), "<", rev) - op := v3.OpDelete(lkv.pfx + key) - for ctx.Err() == nil { - if _, err := lkv.kv.Txn(ctx).If(cmp).Then(op).Commit(); err == nil { - return - } - } -} - -func (lkv *leasingKV) waitRescind(ctx context.Context, key string, rev int64) error { - cctx, cancel := context.WithCancel(ctx) - defer cancel() - wch := lkv.cl.Watch(cctx, lkv.pfx+key, v3.WithRev(rev+1)) - for resp := range wch { - for _, ev := range resp.Events { - if ev.Type == v3.EventTypeDelete { - return ctx.Err() - } - } - } - return ctx.Err() -} - -func (lkv *leasingKV) tryModifyOp(ctx context.Context, op v3.Op) (*v3.TxnResponse, chan<- struct{}, error) { - key := string(op.KeyBytes()) - wc, rev := lkv.leases.Lock(key) - cmp := v3.Compare(v3.CreateRevision(lkv.pfx+key), "<", rev+1) - resp, err := lkv.kv.Txn(ctx).If(cmp).Then(op).Commit() - switch { - case err != nil: - lkv.leases.Evict(key) - fallthrough - case !resp.Succeeded: - if wc != nil { - close(wc) - } - return nil, nil, err - } - return resp, wc, nil -} - -func (lkv *leasingKV) put(ctx context.Context, op v3.Op) (pr *v3.PutResponse, err error) { - if err := lkv.waitSession(ctx); err != nil { - return nil, err - } - for ctx.Err() == nil { - resp, wc, err := lkv.tryModifyOp(ctx, op) - if err != nil || wc == nil { - resp, err = lkv.revoke(ctx, string(op.KeyBytes()), op) - } - if err != nil { - return nil, err - } - if resp.Succeeded { - lkv.leases.mu.Lock() - lkv.leases.Update(op.KeyBytes(), op.ValueBytes(), resp.Header) - lkv.leases.mu.Unlock() - pr = (*v3.PutResponse)(resp.Responses[0].GetResponsePut()) - pr.Header = resp.Header - } - if wc != nil { - close(wc) - } - if resp.Succeeded { - return pr, nil - } - } - return nil, ctx.Err() -} - -func (lkv *leasingKV) acquire(ctx context.Context, key string, op v3.Op) (*v3.TxnResponse, error) { - for ctx.Err() == nil { - if err := lkv.waitSession(ctx); err != nil { - return nil, err - } - lcmp := v3.Cmp{Key: []byte(key), Target: pb.Compare_LEASE} - resp, err := lkv.kv.Txn(ctx).If( - v3.Compare(v3.CreateRevision(lkv.pfx+key), "=", 0), - v3.Compare(lcmp, "=", 0)). - Then( - op, - v3.OpPut(lkv.pfx+key, "", v3.WithLease(lkv.leaseID()))). - Else( - op, - v3.OpGet(lkv.pfx+key), - ).Commit() - if err == nil { - if !resp.Succeeded { - kvs := resp.Responses[1].GetResponseRange().Kvs - // if txn failed since already owner, lease is acquired - resp.Succeeded = len(kvs) > 0 && v3.LeaseID(kvs[0].Lease) == lkv.leaseID() - } - return resp, nil - } - // retry if transient error - if _, ok := err.(rpctypes.EtcdError); ok { - return nil, err - } - if ev, _ := status.FromError(err); ev.Code() != codes.Unavailable { - return nil, err - } - } - return nil, ctx.Err() -} - -func (lkv *leasingKV) get(ctx context.Context, op v3.Op) (*v3.GetResponse, error) { - do := func() (*v3.GetResponse, error) { - r, err := lkv.kv.Do(ctx, op) - return r.Get(), err - } - if !lkv.readySession() { - return do() - } - - if resp, ok := lkv.leases.Get(ctx, op); resp != nil { - return resp, nil - } else if !ok || op.IsSerializable() { - // must be handled by server or can skip linearization - return do() - } - - key := string(op.KeyBytes()) - if !lkv.leases.MayAcquire(key) { - resp, err := lkv.kv.Do(ctx, op) - return resp.Get(), err - } - - resp, err := lkv.acquire(ctx, key, v3.OpGet(key)) - if err != nil { - return nil, err - } - getResp := (*v3.GetResponse)(resp.Responses[0].GetResponseRange()) - getResp.Header = resp.Header - if resp.Succeeded { - getResp = lkv.leases.Add(key, getResp, op) - lkv.wg.Add(1) - go func() { - defer lkv.wg.Done() - lkv.monitorLease(ctx, key, resp.Header.Revision) - }() - } - return getResp, nil -} - -func (lkv *leasingKV) deleteRangeRPC(ctx context.Context, maxLeaseRev int64, key, end string) (*v3.DeleteResponse, error) { - lkey, lend := lkv.pfx+key, lkv.pfx+end - resp, err := lkv.kv.Txn(ctx).If( - v3.Compare(v3.CreateRevision(lkey).WithRange(lend), "<", maxLeaseRev+1), - ).Then( - v3.OpGet(key, v3.WithRange(end), v3.WithKeysOnly()), - v3.OpDelete(key, v3.WithRange(end)), - ).Commit() - if err != nil { - lkv.leases.EvictRange(key, end) - return nil, err - } - if !resp.Succeeded { - return nil, nil - } - for _, kv := range resp.Responses[0].GetResponseRange().Kvs { - lkv.leases.Delete(string(kv.Key), resp.Header) - } - delResp := (*v3.DeleteResponse)(resp.Responses[1].GetResponseDeleteRange()) - delResp.Header = resp.Header - return delResp, nil -} - -func (lkv *leasingKV) deleteRange(ctx context.Context, op v3.Op) (*v3.DeleteResponse, error) { - key, end := string(op.KeyBytes()), string(op.RangeBytes()) - for ctx.Err() == nil { - maxLeaseRev, err := lkv.revokeRange(ctx, key, end) - if err != nil { - return nil, err - } - wcs := lkv.leases.LockRange(key, end) - delResp, err := lkv.deleteRangeRPC(ctx, maxLeaseRev, key, end) - closeAll(wcs) - if err != nil || delResp != nil { - return delResp, err - } - } - return nil, ctx.Err() -} - -func (lkv *leasingKV) delete(ctx context.Context, op v3.Op) (dr *v3.DeleteResponse, err error) { - if err := lkv.waitSession(ctx); err != nil { - return nil, err - } - if len(op.RangeBytes()) > 0 { - return lkv.deleteRange(ctx, op) - } - key := string(op.KeyBytes()) - for ctx.Err() == nil { - resp, wc, err := lkv.tryModifyOp(ctx, op) - if err != nil || wc == nil { - resp, err = lkv.revoke(ctx, key, op) - } - if err != nil { - // don't know if delete was processed - lkv.leases.Evict(key) - return nil, err - } - if resp.Succeeded { - dr = (*v3.DeleteResponse)(resp.Responses[0].GetResponseDeleteRange()) - dr.Header = resp.Header - lkv.leases.Delete(key, dr.Header) - } - if wc != nil { - close(wc) - } - if resp.Succeeded { - return dr, nil - } - } - return nil, ctx.Err() -} - -func (lkv *leasingKV) revoke(ctx context.Context, key string, op v3.Op) (*v3.TxnResponse, error) { - rev := lkv.leases.Rev(key) - txn := lkv.kv.Txn(ctx).If(v3.Compare(v3.CreateRevision(lkv.pfx+key), "<", rev+1)).Then(op) - resp, err := txn.Else(v3.OpPut(lkv.pfx+key, "REVOKE", v3.WithIgnoreLease())).Commit() - if err != nil || resp.Succeeded { - return resp, err - } - return resp, lkv.waitRescind(ctx, key, resp.Header.Revision) -} - -func (lkv *leasingKV) revokeRange(ctx context.Context, begin, end string) (int64, error) { - lkey, lend := lkv.pfx+begin, "" - if len(end) > 0 { - lend = lkv.pfx + end - } - leaseKeys, err := lkv.kv.Get(ctx, lkey, v3.WithRange(lend)) - if err != nil { - return 0, err - } - return lkv.revokeLeaseKvs(ctx, leaseKeys.Kvs) -} - -func (lkv *leasingKV) revokeLeaseKvs(ctx context.Context, kvs []*mvccpb.KeyValue) (int64, error) { - maxLeaseRev := int64(0) - for _, kv := range kvs { - if rev := kv.CreateRevision; rev > maxLeaseRev { - maxLeaseRev = rev - } - if v3.LeaseID(kv.Lease) == lkv.leaseID() { - // don't revoke own keys - continue - } - key := strings.TrimPrefix(string(kv.Key), lkv.pfx) - if _, err := lkv.revoke(ctx, key, v3.OpGet(key)); err != nil { - return 0, err - } - } - return maxLeaseRev, nil -} - -func (lkv *leasingKV) waitSession(ctx context.Context) error { - lkv.leases.mu.RLock() - sessionc := lkv.sessionc - lkv.leases.mu.RUnlock() - select { - case <-sessionc: - return nil - case <-lkv.ctx.Done(): - return lkv.ctx.Err() - case <-ctx.Done(): - return ctx.Err() - } -} - -func (lkv *leasingKV) readySession() bool { - lkv.leases.mu.RLock() - defer lkv.leases.mu.RUnlock() - if lkv.session == nil { - return false - } - select { - case <-lkv.session.Done(): - default: - return true - } - return false -} - -func (lkv *leasingKV) leaseID() v3.LeaseID { - lkv.leases.mu.RLock() - defer lkv.leases.mu.RUnlock() - return lkv.session.Lease() -} diff --git a/vendor/go.etcd.io/etcd/clientv3/leasing/txn.go b/vendor/go.etcd.io/etcd/clientv3/leasing/txn.go deleted file mode 100644 index da5b83a8abb9..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/leasing/txn.go +++ /dev/null @@ -1,223 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package leasing - -import ( - "context" - "strings" - - v3 "github.com/coreos/etcd/clientv3" - v3pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -type txnLeasing struct { - v3.Txn - lkv *leasingKV - ctx context.Context - cs []v3.Cmp - opst []v3.Op - opse []v3.Op -} - -func (txn *txnLeasing) If(cs ...v3.Cmp) v3.Txn { - txn.cs = append(txn.cs, cs...) - txn.Txn = txn.Txn.If(cs...) - return txn -} - -func (txn *txnLeasing) Then(ops ...v3.Op) v3.Txn { - txn.opst = append(txn.opst, ops...) - txn.Txn = txn.Txn.Then(ops...) - return txn -} - -func (txn *txnLeasing) Else(ops ...v3.Op) v3.Txn { - txn.opse = append(txn.opse, ops...) - txn.Txn = txn.Txn.Else(ops...) - return txn -} - -func (txn *txnLeasing) Commit() (*v3.TxnResponse, error) { - if resp, err := txn.eval(); resp != nil || err != nil { - return resp, err - } - return txn.serverTxn() -} - -func (txn *txnLeasing) eval() (*v3.TxnResponse, error) { - // TODO: wait on keys in comparisons - thenOps, elseOps := gatherOps(txn.opst), gatherOps(txn.opse) - ops := make([]v3.Op, 0, len(thenOps)+len(elseOps)) - ops = append(ops, thenOps...) - ops = append(ops, elseOps...) - - for _, ch := range txn.lkv.leases.NotifyOps(ops) { - select { - case <-ch: - case <-txn.ctx.Done(): - return nil, txn.ctx.Err() - } - } - - txn.lkv.leases.mu.RLock() - defer txn.lkv.leases.mu.RUnlock() - succeeded, ok := txn.lkv.leases.evalCmp(txn.cs) - if !ok || txn.lkv.leases.header == nil { - return nil, nil - } - if ops = txn.opst; !succeeded { - ops = txn.opse - } - - resps, ok := txn.lkv.leases.evalOps(ops) - if !ok { - return nil, nil - } - return &v3.TxnResponse{copyHeader(txn.lkv.leases.header), succeeded, resps}, nil -} - -// fallback computes the ops to fetch all possible conflicting -// leasing keys for a list of ops. -func (txn *txnLeasing) fallback(ops []v3.Op) (fbOps []v3.Op) { - for _, op := range ops { - if op.IsGet() { - continue - } - lkey, lend := txn.lkv.pfx+string(op.KeyBytes()), "" - if len(op.RangeBytes()) > 0 { - lend = txn.lkv.pfx + string(op.RangeBytes()) - } - fbOps = append(fbOps, v3.OpGet(lkey, v3.WithRange(lend))) - } - return fbOps -} - -func (txn *txnLeasing) guardKeys(ops []v3.Op) (cmps []v3.Cmp) { - seen := make(map[string]bool) - for _, op := range ops { - key := string(op.KeyBytes()) - if op.IsGet() || len(op.RangeBytes()) != 0 || seen[key] { - continue - } - rev := txn.lkv.leases.Rev(key) - cmps = append(cmps, v3.Compare(v3.CreateRevision(txn.lkv.pfx+key), "<", rev+1)) - seen[key] = true - } - return cmps -} - -func (txn *txnLeasing) guardRanges(ops []v3.Op) (cmps []v3.Cmp, err error) { - for _, op := range ops { - if op.IsGet() || len(op.RangeBytes()) == 0 { - continue - } - - key, end := string(op.KeyBytes()), string(op.RangeBytes()) - maxRevLK, err := txn.lkv.revokeRange(txn.ctx, key, end) - if err != nil { - return nil, err - } - - opts := append(v3.WithLastRev(), v3.WithRange(end)) - getResp, err := txn.lkv.kv.Get(txn.ctx, key, opts...) - if err != nil { - return nil, err - } - maxModRev := int64(0) - if len(getResp.Kvs) > 0 { - maxModRev = getResp.Kvs[0].ModRevision - } - - noKeyUpdate := v3.Compare(v3.ModRevision(key).WithRange(end), "<", maxModRev+1) - noLeaseUpdate := v3.Compare( - v3.CreateRevision(txn.lkv.pfx+key).WithRange(txn.lkv.pfx+end), - "<", - maxRevLK+1) - cmps = append(cmps, noKeyUpdate, noLeaseUpdate) - } - return cmps, nil -} - -func (txn *txnLeasing) guard(ops []v3.Op) ([]v3.Cmp, error) { - cmps := txn.guardKeys(ops) - rangeCmps, err := txn.guardRanges(ops) - return append(cmps, rangeCmps...), err -} - -func (txn *txnLeasing) commitToCache(txnResp *v3pb.TxnResponse, userTxn v3.Op) { - ops := gatherResponseOps(txnResp.Responses, []v3.Op{userTxn}) - txn.lkv.leases.mu.Lock() - for _, op := range ops { - key := string(op.KeyBytes()) - if op.IsDelete() && len(op.RangeBytes()) > 0 { - end := string(op.RangeBytes()) - for k := range txn.lkv.leases.entries { - if inRange(k, key, end) { - txn.lkv.leases.delete(k, txnResp.Header) - } - } - } else if op.IsDelete() { - txn.lkv.leases.delete(key, txnResp.Header) - } - if op.IsPut() { - txn.lkv.leases.Update(op.KeyBytes(), op.ValueBytes(), txnResp.Header) - } - } - txn.lkv.leases.mu.Unlock() -} - -func (txn *txnLeasing) revokeFallback(fbResps []*v3pb.ResponseOp) error { - for _, resp := range fbResps { - _, err := txn.lkv.revokeLeaseKvs(txn.ctx, resp.GetResponseRange().Kvs) - if err != nil { - return err - } - } - return nil -} - -func (txn *txnLeasing) serverTxn() (*v3.TxnResponse, error) { - if err := txn.lkv.waitSession(txn.ctx); err != nil { - return nil, err - } - - userOps := gatherOps(append(txn.opst, txn.opse...)) - userTxn := v3.OpTxn(txn.cs, txn.opst, txn.opse) - fbOps := txn.fallback(userOps) - - defer closeAll(txn.lkv.leases.LockWriteOps(userOps)) - for { - cmps, err := txn.guard(userOps) - if err != nil { - return nil, err - } - resp, err := txn.lkv.kv.Txn(txn.ctx).If(cmps...).Then(userTxn).Else(fbOps...).Commit() - if err != nil { - for _, cmp := range cmps { - txn.lkv.leases.Evict(strings.TrimPrefix(string(cmp.Key), txn.lkv.pfx)) - } - return nil, err - } - if resp.Succeeded { - txn.commitToCache((*v3pb.TxnResponse)(resp), userTxn) - userResp := resp.Responses[0].GetResponseTxn() - userResp.Header = resp.Header - return (*v3.TxnResponse)(userResp), nil - } - if err := txn.revokeFallback(resp.Responses); err != nil { - return nil, err - } - } -} diff --git a/vendor/go.etcd.io/etcd/clientv3/leasing/util.go b/vendor/go.etcd.io/etcd/clientv3/leasing/util.go deleted file mode 100644 index 61f6e8c33fc0..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/leasing/util.go +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package leasing - -import ( - "bytes" - - v3 "github.com/coreos/etcd/clientv3" - v3pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -func compareInt64(a, b int64) int { - switch { - case a < b: - return -1 - case a > b: - return 1 - default: - return 0 - } -} - -func evalCmp(resp *v3.GetResponse, tcmp v3.Cmp) bool { - var result int - if len(resp.Kvs) != 0 { - kv := resp.Kvs[0] - switch tcmp.Target { - case v3pb.Compare_VALUE: - if tv, _ := tcmp.TargetUnion.(*v3pb.Compare_Value); tv != nil { - result = bytes.Compare(kv.Value, tv.Value) - } - case v3pb.Compare_CREATE: - if tv, _ := tcmp.TargetUnion.(*v3pb.Compare_CreateRevision); tv != nil { - result = compareInt64(kv.CreateRevision, tv.CreateRevision) - } - case v3pb.Compare_MOD: - if tv, _ := tcmp.TargetUnion.(*v3pb.Compare_ModRevision); tv != nil { - result = compareInt64(kv.ModRevision, tv.ModRevision) - } - case v3pb.Compare_VERSION: - if tv, _ := tcmp.TargetUnion.(*v3pb.Compare_Version); tv != nil { - result = compareInt64(kv.Version, tv.Version) - } - } - } - switch tcmp.Result { - case v3pb.Compare_EQUAL: - return result == 0 - case v3pb.Compare_NOT_EQUAL: - return result != 0 - case v3pb.Compare_GREATER: - return result > 0 - case v3pb.Compare_LESS: - return result < 0 - } - return true -} - -func gatherOps(ops []v3.Op) (ret []v3.Op) { - for _, op := range ops { - if !op.IsTxn() { - ret = append(ret, op) - continue - } - _, thenOps, elseOps := op.Txn() - ret = append(ret, gatherOps(append(thenOps, elseOps...))...) - } - return ret -} - -func gatherResponseOps(resp []*v3pb.ResponseOp, ops []v3.Op) (ret []v3.Op) { - for i, op := range ops { - if !op.IsTxn() { - ret = append(ret, op) - continue - } - _, thenOps, elseOps := op.Txn() - if txnResp := resp[i].GetResponseTxn(); txnResp.Succeeded { - ret = append(ret, gatherResponseOps(txnResp.Responses, thenOps)...) - } else { - ret = append(ret, gatherResponseOps(txnResp.Responses, elseOps)...) - } - } - return ret -} - -func copyHeader(hdr *v3pb.ResponseHeader) *v3pb.ResponseHeader { - h := *hdr - return &h -} - -func closeAll(chs []chan<- struct{}) { - for _, ch := range chs { - close(ch) - } -} diff --git a/vendor/go.etcd.io/etcd/clientv3/logger.go b/vendor/go.etcd.io/etcd/clientv3/logger.go deleted file mode 100644 index 782e313137a6..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/logger.go +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "io/ioutil" - "sync" - - "google.golang.org/grpc/grpclog" -) - -// Logger is the logger used by client library. -// It implements grpclog.LoggerV2 interface. -type Logger interface { - grpclog.LoggerV2 - - // Lvl returns logger if logger's verbosity level >= "lvl". - // Otherwise, logger that discards all logs. - Lvl(lvl int) Logger - - // to satisfy capnslog - - Print(args ...interface{}) - Printf(format string, args ...interface{}) - Println(args ...interface{}) -} - -var ( - loggerMu sync.RWMutex - logger Logger -) - -type settableLogger struct { - l grpclog.LoggerV2 - mu sync.RWMutex -} - -func init() { - // disable client side logs by default - logger = &settableLogger{} - SetLogger(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, ioutil.Discard)) -} - -// SetLogger sets client-side Logger. -func SetLogger(l grpclog.LoggerV2) { - loggerMu.Lock() - logger = NewLogger(l) - // override grpclog so that any changes happen with locking - grpclog.SetLoggerV2(logger) - loggerMu.Unlock() -} - -// GetLogger returns the current logger. -func GetLogger() Logger { - loggerMu.RLock() - l := logger - loggerMu.RUnlock() - return l -} - -// NewLogger returns a new Logger with grpclog.LoggerV2. -func NewLogger(gl grpclog.LoggerV2) Logger { - return &settableLogger{l: gl} -} - -func (s *settableLogger) get() grpclog.LoggerV2 { - s.mu.RLock() - l := s.l - s.mu.RUnlock() - return l -} - -// implement the grpclog.LoggerV2 interface - -func (s *settableLogger) Info(args ...interface{}) { s.get().Info(args...) } -func (s *settableLogger) Infof(format string, args ...interface{}) { s.get().Infof(format, args...) } -func (s *settableLogger) Infoln(args ...interface{}) { s.get().Infoln(args...) } -func (s *settableLogger) Warning(args ...interface{}) { s.get().Warning(args...) } -func (s *settableLogger) Warningf(format string, args ...interface{}) { - s.get().Warningf(format, args...) -} -func (s *settableLogger) Warningln(args ...interface{}) { s.get().Warningln(args...) } -func (s *settableLogger) Error(args ...interface{}) { s.get().Error(args...) } -func (s *settableLogger) Errorf(format string, args ...interface{}) { - s.get().Errorf(format, args...) -} -func (s *settableLogger) Errorln(args ...interface{}) { s.get().Errorln(args...) } -func (s *settableLogger) Fatal(args ...interface{}) { s.get().Fatal(args...) } -func (s *settableLogger) Fatalf(format string, args ...interface{}) { s.get().Fatalf(format, args...) } -func (s *settableLogger) Fatalln(args ...interface{}) { s.get().Fatalln(args...) } -func (s *settableLogger) Print(args ...interface{}) { s.get().Info(args...) } -func (s *settableLogger) Printf(format string, args ...interface{}) { s.get().Infof(format, args...) } -func (s *settableLogger) Println(args ...interface{}) { s.get().Infoln(args...) } -func (s *settableLogger) V(l int) bool { return s.get().V(l) } -func (s *settableLogger) Lvl(lvl int) Logger { - s.mu.RLock() - l := s.l - s.mu.RUnlock() - if l.V(lvl) { - return s - } - return &noLogger{} -} - -type noLogger struct{} - -func (*noLogger) Info(args ...interface{}) {} -func (*noLogger) Infof(format string, args ...interface{}) {} -func (*noLogger) Infoln(args ...interface{}) {} -func (*noLogger) Warning(args ...interface{}) {} -func (*noLogger) Warningf(format string, args ...interface{}) {} -func (*noLogger) Warningln(args ...interface{}) {} -func (*noLogger) Error(args ...interface{}) {} -func (*noLogger) Errorf(format string, args ...interface{}) {} -func (*noLogger) Errorln(args ...interface{}) {} -func (*noLogger) Fatal(args ...interface{}) {} -func (*noLogger) Fatalf(format string, args ...interface{}) {} -func (*noLogger) Fatalln(args ...interface{}) {} -func (*noLogger) Print(args ...interface{}) {} -func (*noLogger) Printf(format string, args ...interface{}) {} -func (*noLogger) Println(args ...interface{}) {} -func (*noLogger) V(l int) bool { return false } -func (ng *noLogger) Lvl(lvl int) Logger { return ng } diff --git a/vendor/go.etcd.io/etcd/clientv3/maintenance.go b/vendor/go.etcd.io/etcd/clientv3/maintenance.go deleted file mode 100644 index f60cfbe47193..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/maintenance.go +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - "io" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" -) - -type ( - DefragmentResponse pb.DefragmentResponse - AlarmResponse pb.AlarmResponse - AlarmMember pb.AlarmMember - StatusResponse pb.StatusResponse - HashKVResponse pb.HashKVResponse - MoveLeaderResponse pb.MoveLeaderResponse -) - -type Maintenance interface { - // AlarmList gets all active alarms. - AlarmList(ctx context.Context) (*AlarmResponse, error) - - // AlarmDisarm disarms a given alarm. - AlarmDisarm(ctx context.Context, m *AlarmMember) (*AlarmResponse, error) - - // Defragment releases wasted space from internal fragmentation on a given etcd member. - // Defragment is only needed when deleting a large number of keys and want to reclaim - // the resources. - // Defragment is an expensive operation. User should avoid defragmenting multiple members - // at the same time. - // To defragment multiple members in the cluster, user need to call defragment multiple - // times with different endpoints. - Defragment(ctx context.Context, endpoint string) (*DefragmentResponse, error) - - // Status gets the status of the endpoint. - Status(ctx context.Context, endpoint string) (*StatusResponse, error) - - // HashKV returns a hash of the KV state at the time of the RPC. - // If revision is zero, the hash is computed on all keys. If the revision - // is non-zero, the hash is computed on all keys at or below the given revision. - HashKV(ctx context.Context, endpoint string, rev int64) (*HashKVResponse, error) - - // Snapshot provides a reader for a point-in-time snapshot of etcd. - Snapshot(ctx context.Context) (io.ReadCloser, error) - - // MoveLeader requests current leader to transfer its leadership to the transferee. - // Request must be made to the leader. - MoveLeader(ctx context.Context, transfereeID uint64) (*MoveLeaderResponse, error) -} - -type maintenance struct { - dial func(endpoint string) (pb.MaintenanceClient, func(), error) - remote pb.MaintenanceClient - callOpts []grpc.CallOption -} - -func NewMaintenance(c *Client) Maintenance { - api := &maintenance{ - dial: func(endpoint string) (pb.MaintenanceClient, func(), error) { - conn, err := c.dial(endpoint) - if err != nil { - return nil, nil, err - } - cancel := func() { conn.Close() } - return RetryMaintenanceClient(c, conn), cancel, nil - }, - remote: RetryMaintenanceClient(c, c.conn), - } - if c != nil { - api.callOpts = c.callOpts - } - return api -} - -func NewMaintenanceFromMaintenanceClient(remote pb.MaintenanceClient, c *Client) Maintenance { - api := &maintenance{ - dial: func(string) (pb.MaintenanceClient, func(), error) { - return remote, func() {}, nil - }, - remote: remote, - } - if c != nil { - api.callOpts = c.callOpts - } - return api -} - -func (m *maintenance) AlarmList(ctx context.Context) (*AlarmResponse, error) { - req := &pb.AlarmRequest{ - Action: pb.AlarmRequest_GET, - MemberID: 0, // all - Alarm: pb.AlarmType_NONE, // all - } - resp, err := m.remote.Alarm(ctx, req, m.callOpts...) - if err == nil { - return (*AlarmResponse)(resp), nil - } - return nil, toErr(ctx, err) -} - -func (m *maintenance) AlarmDisarm(ctx context.Context, am *AlarmMember) (*AlarmResponse, error) { - req := &pb.AlarmRequest{ - Action: pb.AlarmRequest_DEACTIVATE, - MemberID: am.MemberID, - Alarm: am.Alarm, - } - - if req.MemberID == 0 && req.Alarm == pb.AlarmType_NONE { - ar, err := m.AlarmList(ctx) - if err != nil { - return nil, toErr(ctx, err) - } - ret := AlarmResponse{} - for _, am := range ar.Alarms { - dresp, derr := m.AlarmDisarm(ctx, (*AlarmMember)(am)) - if derr != nil { - return nil, toErr(ctx, derr) - } - ret.Alarms = append(ret.Alarms, dresp.Alarms...) - } - return &ret, nil - } - - resp, err := m.remote.Alarm(ctx, req, m.callOpts...) - if err == nil { - return (*AlarmResponse)(resp), nil - } - return nil, toErr(ctx, err) -} - -func (m *maintenance) Defragment(ctx context.Context, endpoint string) (*DefragmentResponse, error) { - remote, cancel, err := m.dial(endpoint) - if err != nil { - return nil, toErr(ctx, err) - } - defer cancel() - resp, err := remote.Defragment(ctx, &pb.DefragmentRequest{}, m.callOpts...) - if err != nil { - return nil, toErr(ctx, err) - } - return (*DefragmentResponse)(resp), nil -} - -func (m *maintenance) Status(ctx context.Context, endpoint string) (*StatusResponse, error) { - remote, cancel, err := m.dial(endpoint) - if err != nil { - return nil, toErr(ctx, err) - } - defer cancel() - resp, err := remote.Status(ctx, &pb.StatusRequest{}, m.callOpts...) - if err != nil { - return nil, toErr(ctx, err) - } - return (*StatusResponse)(resp), nil -} - -func (m *maintenance) HashKV(ctx context.Context, endpoint string, rev int64) (*HashKVResponse, error) { - remote, cancel, err := m.dial(endpoint) - if err != nil { - return nil, toErr(ctx, err) - } - defer cancel() - resp, err := remote.HashKV(ctx, &pb.HashKVRequest{Revision: rev}, m.callOpts...) - if err != nil { - return nil, toErr(ctx, err) - } - return (*HashKVResponse)(resp), nil -} - -func (m *maintenance) Snapshot(ctx context.Context) (io.ReadCloser, error) { - ss, err := m.remote.Snapshot(ctx, &pb.SnapshotRequest{}, m.callOpts...) - if err != nil { - return nil, toErr(ctx, err) - } - - pr, pw := io.Pipe() - go func() { - for { - resp, err := ss.Recv() - if err != nil { - pw.CloseWithError(err) - return - } - if resp == nil && err == nil { - break - } - if _, werr := pw.Write(resp.Blob); werr != nil { - pw.CloseWithError(werr) - return - } - } - pw.Close() - }() - return &snapshotReadCloser{ctx: ctx, ReadCloser: pr}, nil -} - -type snapshotReadCloser struct { - ctx context.Context - io.ReadCloser -} - -func (rc *snapshotReadCloser) Read(p []byte) (n int, err error) { - n, err = rc.ReadCloser.Read(p) - return n, toErr(rc.ctx, err) -} - -func (m *maintenance) MoveLeader(ctx context.Context, transfereeID uint64) (*MoveLeaderResponse, error) { - resp, err := m.remote.MoveLeader(ctx, &pb.MoveLeaderRequest{TargetID: transfereeID}, m.callOpts...) - return (*MoveLeaderResponse)(resp), toErr(ctx, err) -} diff --git a/vendor/go.etcd.io/etcd/clientv3/mirror/syncer.go b/vendor/go.etcd.io/etcd/clientv3/mirror/syncer.go deleted file mode 100644 index b820933227cb..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/mirror/syncer.go +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package mirror implements etcd mirroring operations. -package mirror - -import ( - "context" - - "github.com/coreos/etcd/clientv3" -) - -const ( - batchLimit = 1000 -) - -// Syncer syncs with the key-value state of an etcd cluster. -type Syncer interface { - // SyncBase syncs the base state of the key-value state. - // The key-value state are sent through the returned chan. - SyncBase(ctx context.Context) (<-chan clientv3.GetResponse, chan error) - // SyncUpdates syncs the updates of the key-value state. - // The update events are sent through the returned chan. - SyncUpdates(ctx context.Context) clientv3.WatchChan -} - -// NewSyncer creates a Syncer. -func NewSyncer(c *clientv3.Client, prefix string, rev int64) Syncer { - return &syncer{c: c, prefix: prefix, rev: rev} -} - -type syncer struct { - c *clientv3.Client - rev int64 - prefix string -} - -func (s *syncer) SyncBase(ctx context.Context) (<-chan clientv3.GetResponse, chan error) { - respchan := make(chan clientv3.GetResponse, 1024) - errchan := make(chan error, 1) - - // if rev is not specified, we will choose the most recent revision. - if s.rev == 0 { - resp, err := s.c.Get(ctx, "foo") - if err != nil { - errchan <- err - close(respchan) - close(errchan) - return respchan, errchan - } - s.rev = resp.Header.Revision - } - - go func() { - defer close(respchan) - defer close(errchan) - - var key string - - opts := []clientv3.OpOption{clientv3.WithLimit(batchLimit), clientv3.WithRev(s.rev)} - - if len(s.prefix) == 0 { - // If len(s.prefix) == 0, we will sync the entire key-value space. - // We then range from the smallest key (0x00) to the end. - opts = append(opts, clientv3.WithFromKey()) - key = "\x00" - } else { - // If len(s.prefix) != 0, we will sync key-value space with given prefix. - // We then range from the prefix to the next prefix if exists. Or we will - // range from the prefix to the end if the next prefix does not exists. - opts = append(opts, clientv3.WithRange(clientv3.GetPrefixRangeEnd(s.prefix))) - key = s.prefix - } - - for { - resp, err := s.c.Get(ctx, key, opts...) - if err != nil { - errchan <- err - return - } - - respchan <- (clientv3.GetResponse)(*resp) - - if !resp.More { - return - } - // move to next key - key = string(append(resp.Kvs[len(resp.Kvs)-1].Key, 0)) - } - }() - - return respchan, errchan -} - -func (s *syncer) SyncUpdates(ctx context.Context) clientv3.WatchChan { - if s.rev == 0 { - panic("unexpected revision = 0. Calling SyncUpdates before SyncBase finishes?") - } - return s.c.Watch(ctx, s.prefix, clientv3.WithPrefix(), clientv3.WithRev(s.rev+1)) -} diff --git a/vendor/go.etcd.io/etcd/clientv3/namespace/doc.go b/vendor/go.etcd.io/etcd/clientv3/namespace/doc.go deleted file mode 100644 index 3f883320fcca..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/namespace/doc.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package namespace is a clientv3 wrapper that translates all keys to begin -// with a given prefix. -// -// First, create a client: -// -// cli, err := clientv3.New(clientv3.Config{Endpoints: []string{"localhost:2379"}}) -// if err != nil { -// // handle error! -// } -// -// Next, override the client interfaces: -// -// unprefixedKV := cli.KV -// cli.KV = namespace.NewKV(cli.KV, "my-prefix/") -// cli.Watcher = namespace.NewWatcher(cli.Watcher, "my-prefix/") -// cli.Lease = namespace.NewLease(cli.Lease, "my-prefix/") -// -// Now calls using 'cli' will namespace / prefix all keys with "my-prefix/": -// -// cli.Put(context.TODO(), "abc", "123") -// resp, _ := unprefixedKV.Get(context.TODO(), "my-prefix/abc") -// fmt.Printf("%s\n", resp.Kvs[0].Value) -// // Output: 123 -// unprefixedKV.Put(context.TODO(), "my-prefix/abc", "456") -// resp, _ = cli.Get("abc") -// fmt.Printf("%s\n", resp.Kvs[0].Value) -// // Output: 456 -// -package namespace diff --git a/vendor/go.etcd.io/etcd/clientv3/namespace/kv.go b/vendor/go.etcd.io/etcd/clientv3/namespace/kv.go deleted file mode 100644 index 13dd83a24550..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/namespace/kv.go +++ /dev/null @@ -1,206 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package namespace - -import ( - "context" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -type kvPrefix struct { - clientv3.KV - pfx string -} - -// NewKV wraps a KV instance so that all requests -// are prefixed with a given string. -func NewKV(kv clientv3.KV, prefix string) clientv3.KV { - return &kvPrefix{kv, prefix} -} - -func (kv *kvPrefix) Put(ctx context.Context, key, val string, opts ...clientv3.OpOption) (*clientv3.PutResponse, error) { - if len(key) == 0 { - return nil, rpctypes.ErrEmptyKey - } - op := kv.prefixOp(clientv3.OpPut(key, val, opts...)) - r, err := kv.KV.Do(ctx, op) - if err != nil { - return nil, err - } - put := r.Put() - kv.unprefixPutResponse(put) - return put, nil -} - -func (kv *kvPrefix) Get(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error) { - if len(key) == 0 { - return nil, rpctypes.ErrEmptyKey - } - r, err := kv.KV.Do(ctx, kv.prefixOp(clientv3.OpGet(key, opts...))) - if err != nil { - return nil, err - } - get := r.Get() - kv.unprefixGetResponse(get) - return get, nil -} - -func (kv *kvPrefix) Delete(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.DeleteResponse, error) { - if len(key) == 0 { - return nil, rpctypes.ErrEmptyKey - } - r, err := kv.KV.Do(ctx, kv.prefixOp(clientv3.OpDelete(key, opts...))) - if err != nil { - return nil, err - } - del := r.Del() - kv.unprefixDeleteResponse(del) - return del, nil -} - -func (kv *kvPrefix) Do(ctx context.Context, op clientv3.Op) (clientv3.OpResponse, error) { - if len(op.KeyBytes()) == 0 && !op.IsTxn() { - return clientv3.OpResponse{}, rpctypes.ErrEmptyKey - } - r, err := kv.KV.Do(ctx, kv.prefixOp(op)) - if err != nil { - return r, err - } - switch { - case r.Get() != nil: - kv.unprefixGetResponse(r.Get()) - case r.Put() != nil: - kv.unprefixPutResponse(r.Put()) - case r.Del() != nil: - kv.unprefixDeleteResponse(r.Del()) - case r.Txn() != nil: - kv.unprefixTxnResponse(r.Txn()) - } - return r, nil -} - -type txnPrefix struct { - clientv3.Txn - kv *kvPrefix -} - -func (kv *kvPrefix) Txn(ctx context.Context) clientv3.Txn { - return &txnPrefix{kv.KV.Txn(ctx), kv} -} - -func (txn *txnPrefix) If(cs ...clientv3.Cmp) clientv3.Txn { - txn.Txn = txn.Txn.If(txn.kv.prefixCmps(cs)...) - return txn -} - -func (txn *txnPrefix) Then(ops ...clientv3.Op) clientv3.Txn { - txn.Txn = txn.Txn.Then(txn.kv.prefixOps(ops)...) - return txn -} - -func (txn *txnPrefix) Else(ops ...clientv3.Op) clientv3.Txn { - txn.Txn = txn.Txn.Else(txn.kv.prefixOps(ops)...) - return txn -} - -func (txn *txnPrefix) Commit() (*clientv3.TxnResponse, error) { - resp, err := txn.Txn.Commit() - if err != nil { - return nil, err - } - txn.kv.unprefixTxnResponse(resp) - return resp, nil -} - -func (kv *kvPrefix) prefixOp(op clientv3.Op) clientv3.Op { - if !op.IsTxn() { - begin, end := kv.prefixInterval(op.KeyBytes(), op.RangeBytes()) - op.WithKeyBytes(begin) - op.WithRangeBytes(end) - return op - } - cmps, thenOps, elseOps := op.Txn() - return clientv3.OpTxn(kv.prefixCmps(cmps), kv.prefixOps(thenOps), kv.prefixOps(elseOps)) -} - -func (kv *kvPrefix) unprefixGetResponse(resp *clientv3.GetResponse) { - for i := range resp.Kvs { - resp.Kvs[i].Key = resp.Kvs[i].Key[len(kv.pfx):] - } -} - -func (kv *kvPrefix) unprefixPutResponse(resp *clientv3.PutResponse) { - if resp.PrevKv != nil { - resp.PrevKv.Key = resp.PrevKv.Key[len(kv.pfx):] - } -} - -func (kv *kvPrefix) unprefixDeleteResponse(resp *clientv3.DeleteResponse) { - for i := range resp.PrevKvs { - resp.PrevKvs[i].Key = resp.PrevKvs[i].Key[len(kv.pfx):] - } -} - -func (kv *kvPrefix) unprefixTxnResponse(resp *clientv3.TxnResponse) { - for _, r := range resp.Responses { - switch tv := r.Response.(type) { - case *pb.ResponseOp_ResponseRange: - if tv.ResponseRange != nil { - kv.unprefixGetResponse((*clientv3.GetResponse)(tv.ResponseRange)) - } - case *pb.ResponseOp_ResponsePut: - if tv.ResponsePut != nil { - kv.unprefixPutResponse((*clientv3.PutResponse)(tv.ResponsePut)) - } - case *pb.ResponseOp_ResponseDeleteRange: - if tv.ResponseDeleteRange != nil { - kv.unprefixDeleteResponse((*clientv3.DeleteResponse)(tv.ResponseDeleteRange)) - } - case *pb.ResponseOp_ResponseTxn: - if tv.ResponseTxn != nil { - kv.unprefixTxnResponse((*clientv3.TxnResponse)(tv.ResponseTxn)) - } - default: - } - } -} - -func (kv *kvPrefix) prefixInterval(key, end []byte) (pfxKey []byte, pfxEnd []byte) { - return prefixInterval(kv.pfx, key, end) -} - -func (kv *kvPrefix) prefixCmps(cs []clientv3.Cmp) []clientv3.Cmp { - newCmps := make([]clientv3.Cmp, len(cs)) - for i := range cs { - newCmps[i] = cs[i] - pfxKey, endKey := kv.prefixInterval(cs[i].KeyBytes(), cs[i].RangeEnd) - newCmps[i].WithKeyBytes(pfxKey) - if len(cs[i].RangeEnd) != 0 { - newCmps[i].RangeEnd = endKey - } - } - return newCmps -} - -func (kv *kvPrefix) prefixOps(ops []clientv3.Op) []clientv3.Op { - newOps := make([]clientv3.Op, len(ops)) - for i := range ops { - newOps[i] = kv.prefixOp(ops[i]) - } - return newOps -} diff --git a/vendor/go.etcd.io/etcd/clientv3/namespace/lease.go b/vendor/go.etcd.io/etcd/clientv3/namespace/lease.go deleted file mode 100644 index f092106cbf25..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/namespace/lease.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package namespace - -import ( - "bytes" - "context" - - "github.com/coreos/etcd/clientv3" -) - -type leasePrefix struct { - clientv3.Lease - pfx []byte -} - -// NewLease wraps a Lease interface to filter for only keys with a prefix -// and remove that prefix when fetching attached keys through TimeToLive. -func NewLease(l clientv3.Lease, prefix string) clientv3.Lease { - return &leasePrefix{l, []byte(prefix)} -} - -func (l *leasePrefix) TimeToLive(ctx context.Context, id clientv3.LeaseID, opts ...clientv3.LeaseOption) (*clientv3.LeaseTimeToLiveResponse, error) { - resp, err := l.Lease.TimeToLive(ctx, id, opts...) - if err != nil { - return nil, err - } - if len(resp.Keys) > 0 { - var outKeys [][]byte - for i := range resp.Keys { - if len(resp.Keys[i]) < len(l.pfx) { - // too short - continue - } - if !bytes.Equal(resp.Keys[i][:len(l.pfx)], l.pfx) { - // doesn't match prefix - continue - } - // strip prefix - outKeys = append(outKeys, resp.Keys[i][len(l.pfx):]) - } - resp.Keys = outKeys - } - return resp, nil -} diff --git a/vendor/go.etcd.io/etcd/clientv3/namespace/util.go b/vendor/go.etcd.io/etcd/clientv3/namespace/util.go deleted file mode 100644 index ecf04046c32d..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/namespace/util.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package namespace - -func prefixInterval(pfx string, key, end []byte) (pfxKey []byte, pfxEnd []byte) { - pfxKey = make([]byte, len(pfx)+len(key)) - copy(pfxKey[copy(pfxKey, pfx):], key) - - if len(end) == 1 && end[0] == 0 { - // the edge of the keyspace - pfxEnd = make([]byte, len(pfx)) - copy(pfxEnd, pfx) - ok := false - for i := len(pfxEnd) - 1; i >= 0; i-- { - if pfxEnd[i]++; pfxEnd[i] != 0 { - ok = true - break - } - } - if !ok { - // 0xff..ff => 0x00 - pfxEnd = []byte{0} - } - } else if len(end) >= 1 { - pfxEnd = make([]byte, len(pfx)+len(end)) - copy(pfxEnd[copy(pfxEnd, pfx):], end) - } - - return pfxKey, pfxEnd -} diff --git a/vendor/go.etcd.io/etcd/clientv3/namespace/watch.go b/vendor/go.etcd.io/etcd/clientv3/namespace/watch.go deleted file mode 100644 index 5a9596df5d8f..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/namespace/watch.go +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package namespace - -import ( - "context" - "sync" - - "github.com/coreos/etcd/clientv3" -) - -type watcherPrefix struct { - clientv3.Watcher - pfx string - - wg sync.WaitGroup - stopc chan struct{} - stopOnce sync.Once -} - -// NewWatcher wraps a Watcher instance so that all Watch requests -// are prefixed with a given string and all Watch responses have -// the prefix removed. -func NewWatcher(w clientv3.Watcher, prefix string) clientv3.Watcher { - return &watcherPrefix{Watcher: w, pfx: prefix, stopc: make(chan struct{})} -} - -func (w *watcherPrefix) Watch(ctx context.Context, key string, opts ...clientv3.OpOption) clientv3.WatchChan { - // since OpOption is opaque, determine range for prefixing through an OpGet - op := clientv3.OpGet(key, opts...) - end := op.RangeBytes() - pfxBegin, pfxEnd := prefixInterval(w.pfx, []byte(key), end) - if pfxEnd != nil { - opts = append(opts, clientv3.WithRange(string(pfxEnd))) - } - - wch := w.Watcher.Watch(ctx, string(pfxBegin), opts...) - - // translate watch events from prefixed to unprefixed - pfxWch := make(chan clientv3.WatchResponse) - w.wg.Add(1) - go func() { - defer func() { - close(pfxWch) - w.wg.Done() - }() - for wr := range wch { - for i := range wr.Events { - wr.Events[i].Kv.Key = wr.Events[i].Kv.Key[len(w.pfx):] - if wr.Events[i].PrevKv != nil { - wr.Events[i].PrevKv.Key = wr.Events[i].Kv.Key - } - } - select { - case pfxWch <- wr: - case <-ctx.Done(): - return - case <-w.stopc: - return - } - } - }() - return pfxWch -} - -func (w *watcherPrefix) Close() error { - err := w.Watcher.Close() - w.stopOnce.Do(func() { close(w.stopc) }) - w.wg.Wait() - return err -} diff --git a/vendor/go.etcd.io/etcd/clientv3/naming/doc.go b/vendor/go.etcd.io/etcd/clientv3/naming/doc.go deleted file mode 100644 index 71608cc738bc..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/naming/doc.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package naming provides an etcd-backed gRPC resolver for discovering gRPC services. -// -// To use, first import the packages: -// -// import ( -// "github.com/coreos/etcd/clientv3" -// etcdnaming "github.com/coreos/etcd/clientv3/naming" -// -// "google.golang.org/grpc" -// "google.golang.org/grpc/naming" -// ) -// -// First, register new endpoint addresses for a service: -// -// func etcdAdd(c *clientv3.Client, service, addr string) error { -// r := &etcdnaming.GRPCResolver{Client: c} -// return r.Update(c.Ctx(), service, naming.Update{Op: naming.Add, Addr: addr}) -// } -// -// Dial an RPC service using the etcd gRPC resolver and a gRPC Balancer: -// -// func etcdDial(c *clientv3.Client, service string) (*grpc.ClientConn, error) { -// r := &etcdnaming.GRPCResolver{Client: c} -// b := grpc.RoundRobin(r) -// return grpc.Dial(service, grpc.WithBalancer(b)) -// } -// -// Optionally, force delete an endpoint: -// -// func etcdDelete(c *clientv3, service, addr string) error { -// r := &etcdnaming.GRPCResolver{Client: c} -// return r.Update(c.Ctx(), "my-service", naming.Update{Op: naming.Delete, Addr: "1.2.3.4"}) -// } -// -// Or register an expiring endpoint with a lease: -// -// func etcdLeaseAdd(c *clientv3.Client, lid clientv3.LeaseID, service, addr string) error { -// r := &etcdnaming.GRPCResolver{Client: c} -// return r.Update(c.Ctx(), service, naming.Update{Op: naming.Add, Addr: addr}, clientv3.WithLease(lid)) -// } -// -package naming diff --git a/vendor/go.etcd.io/etcd/clientv3/naming/grpc.go b/vendor/go.etcd.io/etcd/clientv3/naming/grpc.go deleted file mode 100644 index 3c0e8e664bd3..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/naming/grpc.go +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package naming - -import ( - "context" - "encoding/json" - "fmt" - - etcd "github.com/coreos/etcd/clientv3" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc/naming" - "google.golang.org/grpc/status" -) - -var ErrWatcherClosed = fmt.Errorf("naming: watch closed") - -// GRPCResolver creates a grpc.Watcher for a target to track its resolution changes. -type GRPCResolver struct { - // Client is an initialized etcd client. - Client *etcd.Client -} - -func (gr *GRPCResolver) Update(ctx context.Context, target string, nm naming.Update, opts ...etcd.OpOption) (err error) { - switch nm.Op { - case naming.Add: - var v []byte - if v, err = json.Marshal(nm); err != nil { - return status.Error(codes.InvalidArgument, err.Error()) - } - _, err = gr.Client.KV.Put(ctx, target+"/"+nm.Addr, string(v), opts...) - case naming.Delete: - _, err = gr.Client.Delete(ctx, target+"/"+nm.Addr, opts...) - default: - return status.Error(codes.InvalidArgument, "naming: bad naming op") - } - return err -} - -func (gr *GRPCResolver) Resolve(target string) (naming.Watcher, error) { - ctx, cancel := context.WithCancel(context.Background()) - w := &gRPCWatcher{c: gr.Client, target: target + "/", ctx: ctx, cancel: cancel} - return w, nil -} - -type gRPCWatcher struct { - c *etcd.Client - target string - ctx context.Context - cancel context.CancelFunc - wch etcd.WatchChan - err error -} - -// Next gets the next set of updates from the etcd resolver. -// Calls to Next should be serialized; concurrent calls are not safe since -// there is no way to reconcile the update ordering. -func (gw *gRPCWatcher) Next() ([]*naming.Update, error) { - if gw.wch == nil { - // first Next() returns all addresses - return gw.firstNext() - } - if gw.err != nil { - return nil, gw.err - } - - // process new events on target/* - wr, ok := <-gw.wch - if !ok { - gw.err = status.Error(codes.Unavailable, ErrWatcherClosed.Error()) - return nil, gw.err - } - if gw.err = wr.Err(); gw.err != nil { - return nil, gw.err - } - - updates := make([]*naming.Update, 0, len(wr.Events)) - for _, e := range wr.Events { - var jupdate naming.Update - var err error - switch e.Type { - case etcd.EventTypePut: - err = json.Unmarshal(e.Kv.Value, &jupdate) - jupdate.Op = naming.Add - case etcd.EventTypeDelete: - err = json.Unmarshal(e.PrevKv.Value, &jupdate) - jupdate.Op = naming.Delete - } - if err == nil { - updates = append(updates, &jupdate) - } - } - return updates, nil -} - -func (gw *gRPCWatcher) firstNext() ([]*naming.Update, error) { - // Use serialized request so resolution still works if the target etcd - // server is partitioned away from the quorum. - resp, err := gw.c.Get(gw.ctx, gw.target, etcd.WithPrefix(), etcd.WithSerializable()) - if gw.err = err; err != nil { - return nil, err - } - - updates := make([]*naming.Update, 0, len(resp.Kvs)) - for _, kv := range resp.Kvs { - var jupdate naming.Update - if err := json.Unmarshal(kv.Value, &jupdate); err != nil { - continue - } - updates = append(updates, &jupdate) - } - - opts := []etcd.OpOption{etcd.WithRev(resp.Header.Revision + 1), etcd.WithPrefix(), etcd.WithPrevKV()} - gw.wch = gw.c.Watch(gw.ctx, gw.target, opts...) - return updates, nil -} - -func (gw *gRPCWatcher) Close() { gw.cancel() } diff --git a/vendor/go.etcd.io/etcd/clientv3/op.go b/vendor/go.etcd.io/etcd/clientv3/op.go deleted file mode 100644 index c6ec5bf5200c..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/op.go +++ /dev/null @@ -1,513 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - -type opType int - -const ( - // A default Op has opType 0, which is invalid. - tRange opType = iota + 1 - tPut - tDeleteRange - tTxn -) - -var ( - noPrefixEnd = []byte{0} -) - -// Op represents an Operation that kv can execute. -type Op struct { - t opType - key []byte - end []byte - - // for range - limit int64 - sort *SortOption - serializable bool - keysOnly bool - countOnly bool - minModRev int64 - maxModRev int64 - minCreateRev int64 - maxCreateRev int64 - - // for range, watch - rev int64 - - // for watch, put, delete - prevKV bool - - // for put - ignoreValue bool - ignoreLease bool - - // progressNotify is for progress updates. - progressNotify bool - // createdNotify is for created event - createdNotify bool - // filters for watchers - filterPut bool - filterDelete bool - - // for put - val []byte - leaseID LeaseID - - // txn - cmps []Cmp - thenOps []Op - elseOps []Op -} - -// accessors / mutators - -func (op Op) IsTxn() bool { return op.t == tTxn } -func (op Op) Txn() ([]Cmp, []Op, []Op) { return op.cmps, op.thenOps, op.elseOps } - -// KeyBytes returns the byte slice holding the Op's key. -func (op Op) KeyBytes() []byte { return op.key } - -// WithKeyBytes sets the byte slice for the Op's key. -func (op *Op) WithKeyBytes(key []byte) { op.key = key } - -// RangeBytes returns the byte slice holding with the Op's range end, if any. -func (op Op) RangeBytes() []byte { return op.end } - -// Rev returns the requested revision, if any. -func (op Op) Rev() int64 { return op.rev } - -// IsPut returns true iff the operation is a Put. -func (op Op) IsPut() bool { return op.t == tPut } - -// IsGet returns true iff the operation is a Get. -func (op Op) IsGet() bool { return op.t == tRange } - -// IsDelete returns true iff the operation is a Delete. -func (op Op) IsDelete() bool { return op.t == tDeleteRange } - -// IsSerializable returns true if the serializable field is true. -func (op Op) IsSerializable() bool { return op.serializable == true } - -// IsKeysOnly returns whether keysOnly is set. -func (op Op) IsKeysOnly() bool { return op.keysOnly == true } - -// IsCountOnly returns whether countOnly is set. -func (op Op) IsCountOnly() bool { return op.countOnly == true } - -// MinModRev returns the operation's minimum modify revision. -func (op Op) MinModRev() int64 { return op.minModRev } - -// MaxModRev returns the operation's maximum modify revision. -func (op Op) MaxModRev() int64 { return op.maxModRev } - -// MinCreateRev returns the operation's minimum create revision. -func (op Op) MinCreateRev() int64 { return op.minCreateRev } - -// MaxCreateRev returns the operation's maximum create revision. -func (op Op) MaxCreateRev() int64 { return op.maxCreateRev } - -// WithRangeBytes sets the byte slice for the Op's range end. -func (op *Op) WithRangeBytes(end []byte) { op.end = end } - -// ValueBytes returns the byte slice holding the Op's value, if any. -func (op Op) ValueBytes() []byte { return op.val } - -// WithValueBytes sets the byte slice for the Op's value. -func (op *Op) WithValueBytes(v []byte) { op.val = v } - -func (op Op) toRangeRequest() *pb.RangeRequest { - if op.t != tRange { - panic("op.t != tRange") - } - r := &pb.RangeRequest{ - Key: op.key, - RangeEnd: op.end, - Limit: op.limit, - Revision: op.rev, - Serializable: op.serializable, - KeysOnly: op.keysOnly, - CountOnly: op.countOnly, - MinModRevision: op.minModRev, - MaxModRevision: op.maxModRev, - MinCreateRevision: op.minCreateRev, - MaxCreateRevision: op.maxCreateRev, - } - if op.sort != nil { - r.SortOrder = pb.RangeRequest_SortOrder(op.sort.Order) - r.SortTarget = pb.RangeRequest_SortTarget(op.sort.Target) - } - return r -} - -func (op Op) toTxnRequest() *pb.TxnRequest { - thenOps := make([]*pb.RequestOp, len(op.thenOps)) - for i, tOp := range op.thenOps { - thenOps[i] = tOp.toRequestOp() - } - elseOps := make([]*pb.RequestOp, len(op.elseOps)) - for i, eOp := range op.elseOps { - elseOps[i] = eOp.toRequestOp() - } - cmps := make([]*pb.Compare, len(op.cmps)) - for i := range op.cmps { - cmps[i] = (*pb.Compare)(&op.cmps[i]) - } - return &pb.TxnRequest{Compare: cmps, Success: thenOps, Failure: elseOps} -} - -func (op Op) toRequestOp() *pb.RequestOp { - switch op.t { - case tRange: - return &pb.RequestOp{Request: &pb.RequestOp_RequestRange{RequestRange: op.toRangeRequest()}} - case tPut: - r := &pb.PutRequest{Key: op.key, Value: op.val, Lease: int64(op.leaseID), PrevKv: op.prevKV, IgnoreValue: op.ignoreValue, IgnoreLease: op.ignoreLease} - return &pb.RequestOp{Request: &pb.RequestOp_RequestPut{RequestPut: r}} - case tDeleteRange: - r := &pb.DeleteRangeRequest{Key: op.key, RangeEnd: op.end, PrevKv: op.prevKV} - return &pb.RequestOp{Request: &pb.RequestOp_RequestDeleteRange{RequestDeleteRange: r}} - case tTxn: - return &pb.RequestOp{Request: &pb.RequestOp_RequestTxn{RequestTxn: op.toTxnRequest()}} - default: - panic("Unknown Op") - } -} - -func (op Op) isWrite() bool { - if op.t == tTxn { - for _, tOp := range op.thenOps { - if tOp.isWrite() { - return true - } - } - for _, tOp := range op.elseOps { - if tOp.isWrite() { - return true - } - } - return false - } - return op.t != tRange -} - -func OpGet(key string, opts ...OpOption) Op { - ret := Op{t: tRange, key: []byte(key)} - ret.applyOpts(opts) - return ret -} - -func OpDelete(key string, opts ...OpOption) Op { - ret := Op{t: tDeleteRange, key: []byte(key)} - ret.applyOpts(opts) - switch { - case ret.leaseID != 0: - panic("unexpected lease in delete") - case ret.limit != 0: - panic("unexpected limit in delete") - case ret.rev != 0: - panic("unexpected revision in delete") - case ret.sort != nil: - panic("unexpected sort in delete") - case ret.serializable: - panic("unexpected serializable in delete") - case ret.countOnly: - panic("unexpected countOnly in delete") - case ret.minModRev != 0, ret.maxModRev != 0: - panic("unexpected mod revision filter in delete") - case ret.minCreateRev != 0, ret.maxCreateRev != 0: - panic("unexpected create revision filter in delete") - case ret.filterDelete, ret.filterPut: - panic("unexpected filter in delete") - case ret.createdNotify: - panic("unexpected createdNotify in delete") - } - return ret -} - -func OpPut(key, val string, opts ...OpOption) Op { - ret := Op{t: tPut, key: []byte(key), val: []byte(val)} - ret.applyOpts(opts) - switch { - case ret.end != nil: - panic("unexpected range in put") - case ret.limit != 0: - panic("unexpected limit in put") - case ret.rev != 0: - panic("unexpected revision in put") - case ret.sort != nil: - panic("unexpected sort in put") - case ret.serializable: - panic("unexpected serializable in put") - case ret.countOnly: - panic("unexpected countOnly in put") - case ret.minModRev != 0, ret.maxModRev != 0: - panic("unexpected mod revision filter in put") - case ret.minCreateRev != 0, ret.maxCreateRev != 0: - panic("unexpected create revision filter in put") - case ret.filterDelete, ret.filterPut: - panic("unexpected filter in put") - case ret.createdNotify: - panic("unexpected createdNotify in put") - } - return ret -} - -func OpTxn(cmps []Cmp, thenOps []Op, elseOps []Op) Op { - return Op{t: tTxn, cmps: cmps, thenOps: thenOps, elseOps: elseOps} -} - -func opWatch(key string, opts ...OpOption) Op { - ret := Op{t: tRange, key: []byte(key)} - ret.applyOpts(opts) - switch { - case ret.leaseID != 0: - panic("unexpected lease in watch") - case ret.limit != 0: - panic("unexpected limit in watch") - case ret.sort != nil: - panic("unexpected sort in watch") - case ret.serializable: - panic("unexpected serializable in watch") - case ret.countOnly: - panic("unexpected countOnly in watch") - case ret.minModRev != 0, ret.maxModRev != 0: - panic("unexpected mod revision filter in watch") - case ret.minCreateRev != 0, ret.maxCreateRev != 0: - panic("unexpected create revision filter in watch") - } - return ret -} - -func (op *Op) applyOpts(opts []OpOption) { - for _, opt := range opts { - opt(op) - } -} - -// OpOption configures Operations like Get, Put, Delete. -type OpOption func(*Op) - -// WithLease attaches a lease ID to a key in 'Put' request. -func WithLease(leaseID LeaseID) OpOption { - return func(op *Op) { op.leaseID = leaseID } -} - -// WithLimit limits the number of results to return from 'Get' request. -// If WithLimit is given a 0 limit, it is treated as no limit. -func WithLimit(n int64) OpOption { return func(op *Op) { op.limit = n } } - -// WithRev specifies the store revision for 'Get' request. -// Or the start revision of 'Watch' request. -func WithRev(rev int64) OpOption { return func(op *Op) { op.rev = rev } } - -// WithSort specifies the ordering in 'Get' request. It requires -// 'WithRange' and/or 'WithPrefix' to be specified too. -// 'target' specifies the target to sort by: key, version, revisions, value. -// 'order' can be either 'SortNone', 'SortAscend', 'SortDescend'. -func WithSort(target SortTarget, order SortOrder) OpOption { - return func(op *Op) { - if target == SortByKey && order == SortAscend { - // If order != SortNone, server fetches the entire key-space, - // and then applies the sort and limit, if provided. - // Since by default the server returns results sorted by keys - // in lexicographically ascending order, the client should ignore - // SortOrder if the target is SortByKey. - order = SortNone - } - op.sort = &SortOption{target, order} - } -} - -// GetPrefixRangeEnd gets the range end of the prefix. -// 'Get(foo, WithPrefix())' is equal to 'Get(foo, WithRange(GetPrefixRangeEnd(foo))'. -func GetPrefixRangeEnd(prefix string) string { - return string(getPrefix([]byte(prefix))) -} - -func getPrefix(key []byte) []byte { - end := make([]byte, len(key)) - copy(end, key) - for i := len(end) - 1; i >= 0; i-- { - if end[i] < 0xff { - end[i] = end[i] + 1 - end = end[:i+1] - return end - } - } - // next prefix does not exist (e.g., 0xffff); - // default to WithFromKey policy - return noPrefixEnd -} - -// WithPrefix enables 'Get', 'Delete', or 'Watch' requests to operate -// on the keys with matching prefix. For example, 'Get(foo, WithPrefix())' -// can return 'foo1', 'foo2', and so on. -func WithPrefix() OpOption { - return func(op *Op) { - if len(op.key) == 0 { - op.key, op.end = []byte{0}, []byte{0} - return - } - op.end = getPrefix(op.key) - } -} - -// WithRange specifies the range of 'Get', 'Delete', 'Watch' requests. -// For example, 'Get' requests with 'WithRange(end)' returns -// the keys in the range [key, end). -// endKey must be lexicographically greater than start key. -func WithRange(endKey string) OpOption { - return func(op *Op) { op.end = []byte(endKey) } -} - -// WithFromKey specifies the range of 'Get', 'Delete', 'Watch' requests -// to be equal or greater than the key in the argument. -func WithFromKey() OpOption { return WithRange("\x00") } - -// WithSerializable makes 'Get' request serializable. By default, -// it's linearizable. Serializable requests are better for lower latency -// requirement. -func WithSerializable() OpOption { - return func(op *Op) { op.serializable = true } -} - -// WithKeysOnly makes the 'Get' request return only the keys and the corresponding -// values will be omitted. -func WithKeysOnly() OpOption { - return func(op *Op) { op.keysOnly = true } -} - -// WithCountOnly makes the 'Get' request return only the count of keys. -func WithCountOnly() OpOption { - return func(op *Op) { op.countOnly = true } -} - -// WithMinModRev filters out keys for Get with modification revisions less than the given revision. -func WithMinModRev(rev int64) OpOption { return func(op *Op) { op.minModRev = rev } } - -// WithMaxModRev filters out keys for Get with modification revisions greater than the given revision. -func WithMaxModRev(rev int64) OpOption { return func(op *Op) { op.maxModRev = rev } } - -// WithMinCreateRev filters out keys for Get with creation revisions less than the given revision. -func WithMinCreateRev(rev int64) OpOption { return func(op *Op) { op.minCreateRev = rev } } - -// WithMaxCreateRev filters out keys for Get with creation revisions greater than the given revision. -func WithMaxCreateRev(rev int64) OpOption { return func(op *Op) { op.maxCreateRev = rev } } - -// WithFirstCreate gets the key with the oldest creation revision in the request range. -func WithFirstCreate() []OpOption { return withTop(SortByCreateRevision, SortAscend) } - -// WithLastCreate gets the key with the latest creation revision in the request range. -func WithLastCreate() []OpOption { return withTop(SortByCreateRevision, SortDescend) } - -// WithFirstKey gets the lexically first key in the request range. -func WithFirstKey() []OpOption { return withTop(SortByKey, SortAscend) } - -// WithLastKey gets the lexically last key in the request range. -func WithLastKey() []OpOption { return withTop(SortByKey, SortDescend) } - -// WithFirstRev gets the key with the oldest modification revision in the request range. -func WithFirstRev() []OpOption { return withTop(SortByModRevision, SortAscend) } - -// WithLastRev gets the key with the latest modification revision in the request range. -func WithLastRev() []OpOption { return withTop(SortByModRevision, SortDescend) } - -// withTop gets the first key over the get's prefix given a sort order -func withTop(target SortTarget, order SortOrder) []OpOption { - return []OpOption{WithPrefix(), WithSort(target, order), WithLimit(1)} -} - -// WithProgressNotify makes watch server send periodic progress updates -// every 10 minutes when there is no incoming events. -// Progress updates have zero events in WatchResponse. -func WithProgressNotify() OpOption { - return func(op *Op) { - op.progressNotify = true - } -} - -// WithCreatedNotify makes watch server sends the created event. -func WithCreatedNotify() OpOption { - return func(op *Op) { - op.createdNotify = true - } -} - -// WithFilterPut discards PUT events from the watcher. -func WithFilterPut() OpOption { - return func(op *Op) { op.filterPut = true } -} - -// WithFilterDelete discards DELETE events from the watcher. -func WithFilterDelete() OpOption { - return func(op *Op) { op.filterDelete = true } -} - -// WithPrevKV gets the previous key-value pair before the event happens. If the previous KV is already compacted, -// nothing will be returned. -func WithPrevKV() OpOption { - return func(op *Op) { - op.prevKV = true - } -} - -// WithIgnoreValue updates the key using its current value. -// This option can not be combined with non-empty values. -// Returns an error if the key does not exist. -func WithIgnoreValue() OpOption { - return func(op *Op) { - op.ignoreValue = true - } -} - -// WithIgnoreLease updates the key using its current lease. -// This option can not be combined with WithLease. -// Returns an error if the key does not exist. -func WithIgnoreLease() OpOption { - return func(op *Op) { - op.ignoreLease = true - } -} - -// LeaseOp represents an Operation that lease can execute. -type LeaseOp struct { - id LeaseID - - // for TimeToLive - attachedKeys bool -} - -// LeaseOption configures lease operations. -type LeaseOption func(*LeaseOp) - -func (op *LeaseOp) applyOpts(opts []LeaseOption) { - for _, opt := range opts { - opt(op) - } -} - -// WithAttachedKeys makes TimeToLive list the keys attached to the given lease ID. -func WithAttachedKeys() LeaseOption { - return func(op *LeaseOp) { op.attachedKeys = true } -} - -func toLeaseTimeToLiveRequest(id LeaseID, opts ...LeaseOption) *pb.LeaseTimeToLiveRequest { - ret := &LeaseOp{id: id} - ret.applyOpts(opts) - return &pb.LeaseTimeToLiveRequest{ID: int64(id), Keys: ret.attachedKeys} -} diff --git a/vendor/go.etcd.io/etcd/clientv3/options.go b/vendor/go.etcd.io/etcd/clientv3/options.go deleted file mode 100644 index fa25811f3b04..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/options.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "math" - - "google.golang.org/grpc" -) - -var ( - // Disable gRPC internal retrial logic - // TODO: enable when gRPC retry is stable (FailFast=false) - // Reference: - // - https://github.com/grpc/grpc-go/issues/1532 - // - https://github.com/grpc/proposal/blob/master/A6-client-retries.md - defaultFailFast = grpc.FailFast(true) - - // client-side request send limit, gRPC default is math.MaxInt32 - // Make sure that "client-side send limit < server-side default send/recv limit" - // Same value as "embed.DefaultMaxRequestBytes" plus gRPC overhead bytes - defaultMaxCallSendMsgSize = grpc.MaxCallSendMsgSize(2 * 1024 * 1024) - - // client-side response receive limit, gRPC default is 4MB - // Make sure that "client-side receive limit >= server-side default send/recv limit" - // because range response can easily exceed request send limits - // Default to math.MaxInt32; writes exceeding server-side send limit fails anyway - defaultMaxCallRecvMsgSize = grpc.MaxCallRecvMsgSize(math.MaxInt32) -) - -// defaultCallOpts defines a list of default "gRPC.CallOption". -// Some options are exposed to "clientv3.Config". -// Defaults will be overridden by the settings in "clientv3.Config". -var defaultCallOpts = []grpc.CallOption{defaultFailFast, defaultMaxCallSendMsgSize, defaultMaxCallRecvMsgSize} - -// MaxLeaseTTL is the maximum lease TTL value -const MaxLeaseTTL = 9000000000 diff --git a/vendor/go.etcd.io/etcd/clientv3/ordering/doc.go b/vendor/go.etcd.io/etcd/clientv3/ordering/doc.go deleted file mode 100644 index 856f33058011..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/ordering/doc.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package ordering is a clientv3 wrapper that caches response header revisions -// to detect ordering violations from stale responses. Users may define a -// policy on how to handle the ordering violation, but typically the client -// should connect to another endpoint and reissue the request. -// -// The most common situation where an ordering violation happens is a client -// reconnects to a partitioned member and issues a serializable read. Since the -// partitioned member is likely behind the last member, it may return a Get -// response based on a store revision older than the store revision used to -// service a prior Get on the former endpoint. -// -// First, create a client: -// -// cli, err := clientv3.New(clientv3.Config{Endpoints: []string{"localhost:2379"}}) -// if err != nil { -// // handle error! -// } -// -// Next, override the client interface with the ordering wrapper: -// -// vf := func(op clientv3.Op, resp clientv3.OpResponse, prevRev int64) error { -// return fmt.Errorf("ordering: issued %+v, got %+v, expected rev=%v", op, resp, prevRev) -// } -// cli.KV = ordering.NewKV(cli.KV, vf) -// -// Now calls using 'cli' will reject order violations with an error. -// -package ordering diff --git a/vendor/go.etcd.io/etcd/clientv3/ordering/kv.go b/vendor/go.etcd.io/etcd/clientv3/ordering/kv.go deleted file mode 100644 index dc9926ec6c2b..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/ordering/kv.go +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ordering - -import ( - "context" - "sync" - - "github.com/coreos/etcd/clientv3" -) - -// kvOrdering ensures that serialized requests do not return -// get with revisions less than the previous -// returned revision. -type kvOrdering struct { - clientv3.KV - orderViolationFunc OrderViolationFunc - prevRev int64 - revMu sync.RWMutex -} - -func NewKV(kv clientv3.KV, orderViolationFunc OrderViolationFunc) *kvOrdering { - return &kvOrdering{kv, orderViolationFunc, 0, sync.RWMutex{}} -} - -func (kv *kvOrdering) getPrevRev() int64 { - kv.revMu.RLock() - defer kv.revMu.RUnlock() - return kv.prevRev -} - -func (kv *kvOrdering) setPrevRev(currRev int64) { - kv.revMu.Lock() - defer kv.revMu.Unlock() - if currRev > kv.prevRev { - kv.prevRev = currRev - } -} - -func (kv *kvOrdering) Get(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error) { - // prevRev is stored in a local variable in order to record the prevRev - // at the beginning of the Get operation, because concurrent - // access to kvOrdering could change the prevRev field in the - // middle of the Get operation. - prevRev := kv.getPrevRev() - op := clientv3.OpGet(key, opts...) - for { - r, err := kv.KV.Do(ctx, op) - if err != nil { - return nil, err - } - resp := r.Get() - if resp.Header.Revision == prevRev { - return resp, nil - } else if resp.Header.Revision > prevRev { - kv.setPrevRev(resp.Header.Revision) - return resp, nil - } - err = kv.orderViolationFunc(op, r, prevRev) - if err != nil { - return nil, err - } - } -} - -func (kv *kvOrdering) Txn(ctx context.Context) clientv3.Txn { - return &txnOrdering{ - kv.KV.Txn(ctx), - kv, - ctx, - sync.Mutex{}, - []clientv3.Cmp{}, - []clientv3.Op{}, - []clientv3.Op{}, - } -} - -// txnOrdering ensures that serialized requests do not return -// txn responses with revisions less than the previous -// returned revision. -type txnOrdering struct { - clientv3.Txn - *kvOrdering - ctx context.Context - mu sync.Mutex - cmps []clientv3.Cmp - thenOps []clientv3.Op - elseOps []clientv3.Op -} - -func (txn *txnOrdering) If(cs ...clientv3.Cmp) clientv3.Txn { - txn.mu.Lock() - defer txn.mu.Unlock() - txn.cmps = cs - txn.Txn.If(cs...) - return txn -} - -func (txn *txnOrdering) Then(ops ...clientv3.Op) clientv3.Txn { - txn.mu.Lock() - defer txn.mu.Unlock() - txn.thenOps = ops - txn.Txn.Then(ops...) - return txn -} - -func (txn *txnOrdering) Else(ops ...clientv3.Op) clientv3.Txn { - txn.mu.Lock() - defer txn.mu.Unlock() - txn.elseOps = ops - txn.Txn.Else(ops...) - return txn -} - -func (txn *txnOrdering) Commit() (*clientv3.TxnResponse, error) { - // prevRev is stored in a local variable in order to record the prevRev - // at the beginning of the Commit operation, because concurrent - // access to txnOrdering could change the prevRev field in the - // middle of the Commit operation. - prevRev := txn.getPrevRev() - opTxn := clientv3.OpTxn(txn.cmps, txn.thenOps, txn.elseOps) - for { - opResp, err := txn.KV.Do(txn.ctx, opTxn) - if err != nil { - return nil, err - } - txnResp := opResp.Txn() - if txnResp.Header.Revision >= prevRev { - txn.setPrevRev(txnResp.Header.Revision) - return txnResp, nil - } - err = txn.orderViolationFunc(opTxn, opResp, prevRev) - if err != nil { - return nil, err - } - } -} diff --git a/vendor/go.etcd.io/etcd/clientv3/ordering/util.go b/vendor/go.etcd.io/etcd/clientv3/ordering/util.go deleted file mode 100644 index 190a5919a525..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/ordering/util.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ordering - -import ( - "errors" - "sync" - "time" - - "github.com/coreos/etcd/clientv3" -) - -type OrderViolationFunc func(op clientv3.Op, resp clientv3.OpResponse, prevRev int64) error - -var ErrNoGreaterRev = errors.New("etcdclient: no cluster members have a revision higher than the previously received revision") - -func NewOrderViolationSwitchEndpointClosure(c clientv3.Client) OrderViolationFunc { - var mu sync.Mutex - violationCount := 0 - return func(op clientv3.Op, resp clientv3.OpResponse, prevRev int64) error { - if violationCount > len(c.Endpoints()) { - return ErrNoGreaterRev - } - mu.Lock() - defer mu.Unlock() - eps := c.Endpoints() - // force client to connect to given endpoint by limiting to a single endpoint - c.SetEndpoints(eps[violationCount%len(eps)]) - // give enough time for operation - time.Sleep(1 * time.Second) - // set available endpoints back to all endpoints in to ensure - // the client has access to all the endpoints. - c.SetEndpoints(eps...) - violationCount++ - return nil - } -} diff --git a/vendor/go.etcd.io/etcd/clientv3/ready_wait.go b/vendor/go.etcd.io/etcd/clientv3/ready_wait.go deleted file mode 100644 index c6ef585b5b41..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/ready_wait.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import "context" - -// TODO: remove this when "FailFast=false" is fixed. -// See https://github.com/grpc/grpc-go/issues/1532. -func readyWait(rpcCtx, clientCtx context.Context, ready <-chan struct{}) error { - select { - case <-ready: - return nil - case <-rpcCtx.Done(): - return rpcCtx.Err() - case <-clientCtx.Done(): - return clientCtx.Err() - } -} diff --git a/vendor/go.etcd.io/etcd/clientv3/retry.go b/vendor/go.etcd.io/etcd/clientv3/retry.go deleted file mode 100644 index 7f89ba641a44..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/retry.go +++ /dev/null @@ -1,496 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -type retryPolicy uint8 - -const ( - repeatable retryPolicy = iota - nonRepeatable -) - -type rpcFunc func(ctx context.Context) error -type retryRPCFunc func(context.Context, rpcFunc, retryPolicy) error -type retryStopErrFunc func(error) bool - -// immutable requests (e.g. Get) should be retried unless it's -// an obvious server-side error (e.g. rpctypes.ErrRequestTooLarge). -// -// "isRepeatableStopError" returns "true" when an immutable request -// is interrupted by server-side or gRPC-side error and its status -// code is not transient (!= codes.Unavailable). -// -// Returning "true" means retry should stop, since client cannot -// handle itself even with retries. -func isRepeatableStopError(err error) bool { - eErr := rpctypes.Error(err) - // always stop retry on etcd errors - if serverErr, ok := eErr.(rpctypes.EtcdError); ok && serverErr.Code() != codes.Unavailable { - return true - } - // only retry if unavailable - ev, _ := status.FromError(err) - return ev.Code() != codes.Unavailable -} - -// mutable requests (e.g. Put, Delete, Txn) should only be retried -// when the status code is codes.Unavailable when initial connection -// has not been established (no pinned endpoint). -// -// "isNonRepeatableStopError" returns "true" when a mutable request -// is interrupted by non-transient error that client cannot handle itself, -// or transient error while the connection has already been established -// (pinned endpoint exists). -// -// Returning "true" means retry should stop, otherwise it violates -// write-at-most-once semantics. -func isNonRepeatableStopError(err error) bool { - ev, _ := status.FromError(err) - if ev.Code() != codes.Unavailable { - return true - } - desc := rpctypes.ErrorDesc(err) - return desc != "there is no address available" && desc != "there is no connection available" -} - -func (c *Client) newRetryWrapper() retryRPCFunc { - return func(rpcCtx context.Context, f rpcFunc, rp retryPolicy) error { - var isStop retryStopErrFunc - switch rp { - case repeatable: - isStop = isRepeatableStopError - case nonRepeatable: - isStop = isNonRepeatableStopError - } - for { - if err := readyWait(rpcCtx, c.ctx, c.balancer.ConnectNotify()); err != nil { - return err - } - pinned := c.balancer.pinned() - err := f(rpcCtx) - if err == nil { - return nil - } - logger.Lvl(4).Infof("clientv3/retry: error %q on pinned endpoint %q", err.Error(), pinned) - - if s, ok := status.FromError(err); ok && (s.Code() == codes.Unavailable || s.Code() == codes.DeadlineExceeded || s.Code() == codes.Internal) { - // mark this before endpoint switch is triggered - c.balancer.hostPortError(pinned, err) - c.balancer.next() - logger.Lvl(4).Infof("clientv3/retry: switching from %q due to error %q", pinned, err.Error()) - } - - if isStop(err) { - return err - } - } - } -} - -func (c *Client) newAuthRetryWrapper(retryf retryRPCFunc) retryRPCFunc { - return func(rpcCtx context.Context, f rpcFunc, rp retryPolicy) error { - for { - pinned := c.balancer.pinned() - err := retryf(rpcCtx, f, rp) - if err == nil { - return nil - } - logger.Lvl(4).Infof("clientv3/auth-retry: error %q on pinned endpoint %q", err.Error(), pinned) - // always stop retry on etcd errors other than invalid auth token - if rpctypes.Error(err) == rpctypes.ErrInvalidAuthToken { - gterr := c.getToken(rpcCtx) - if gterr != nil { - logger.Lvl(4).Infof("clientv3/auth-retry: cannot retry due to error %q(%q) on pinned endpoint %q", err.Error(), gterr.Error(), pinned) - return err // return the original error for simplicity - } - continue - } - return err - } - } -} - -type retryKVClient struct { - kc pb.KVClient - retryf retryRPCFunc -} - -// RetryKVClient implements a KVClient. -func RetryKVClient(c *Client) pb.KVClient { - return &retryKVClient{ - kc: pb.NewKVClient(c.conn), - retryf: c.newAuthRetryWrapper(c.newRetryWrapper()), - } -} -func (rkv *retryKVClient) Range(ctx context.Context, in *pb.RangeRequest, opts ...grpc.CallOption) (resp *pb.RangeResponse, err error) { - err = rkv.retryf(ctx, func(rctx context.Context) error { - resp, err = rkv.kc.Range(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rkv *retryKVClient) Put(ctx context.Context, in *pb.PutRequest, opts ...grpc.CallOption) (resp *pb.PutResponse, err error) { - err = rkv.retryf(ctx, func(rctx context.Context) error { - resp, err = rkv.kc.Put(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rkv *retryKVClient) DeleteRange(ctx context.Context, in *pb.DeleteRangeRequest, opts ...grpc.CallOption) (resp *pb.DeleteRangeResponse, err error) { - err = rkv.retryf(ctx, func(rctx context.Context) error { - resp, err = rkv.kc.DeleteRange(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rkv *retryKVClient) Txn(ctx context.Context, in *pb.TxnRequest, opts ...grpc.CallOption) (resp *pb.TxnResponse, err error) { - // TODO: "repeatable" for read-only txn - err = rkv.retryf(ctx, func(rctx context.Context) error { - resp, err = rkv.kc.Txn(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rkv *retryKVClient) Compact(ctx context.Context, in *pb.CompactionRequest, opts ...grpc.CallOption) (resp *pb.CompactionResponse, err error) { - err = rkv.retryf(ctx, func(rctx context.Context) error { - resp, err = rkv.kc.Compact(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -type retryLeaseClient struct { - lc pb.LeaseClient - retryf retryRPCFunc -} - -// RetryLeaseClient implements a LeaseClient. -func RetryLeaseClient(c *Client) pb.LeaseClient { - return &retryLeaseClient{ - lc: pb.NewLeaseClient(c.conn), - retryf: c.newAuthRetryWrapper(c.newRetryWrapper()), - } -} - -func (rlc *retryLeaseClient) LeaseTimeToLive(ctx context.Context, in *pb.LeaseTimeToLiveRequest, opts ...grpc.CallOption) (resp *pb.LeaseTimeToLiveResponse, err error) { - err = rlc.retryf(ctx, func(rctx context.Context) error { - resp, err = rlc.lc.LeaseTimeToLive(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rlc *retryLeaseClient) LeaseLeases(ctx context.Context, in *pb.LeaseLeasesRequest, opts ...grpc.CallOption) (resp *pb.LeaseLeasesResponse, err error) { - err = rlc.retryf(ctx, func(rctx context.Context) error { - resp, err = rlc.lc.LeaseLeases(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rlc *retryLeaseClient) LeaseGrant(ctx context.Context, in *pb.LeaseGrantRequest, opts ...grpc.CallOption) (resp *pb.LeaseGrantResponse, err error) { - err = rlc.retryf(ctx, func(rctx context.Context) error { - resp, err = rlc.lc.LeaseGrant(rctx, in, opts...) - return err - }, repeatable) - return resp, err - -} - -func (rlc *retryLeaseClient) LeaseRevoke(ctx context.Context, in *pb.LeaseRevokeRequest, opts ...grpc.CallOption) (resp *pb.LeaseRevokeResponse, err error) { - err = rlc.retryf(ctx, func(rctx context.Context) error { - resp, err = rlc.lc.LeaseRevoke(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rlc *retryLeaseClient) LeaseKeepAlive(ctx context.Context, opts ...grpc.CallOption) (stream pb.Lease_LeaseKeepAliveClient, err error) { - err = rlc.retryf(ctx, func(rctx context.Context) error { - stream, err = rlc.lc.LeaseKeepAlive(rctx, opts...) - return err - }, repeatable) - return stream, err -} - -type retryClusterClient struct { - cc pb.ClusterClient - retryf retryRPCFunc -} - -// RetryClusterClient implements a ClusterClient. -func RetryClusterClient(c *Client) pb.ClusterClient { - return &retryClusterClient{ - cc: pb.NewClusterClient(c.conn), - retryf: c.newRetryWrapper(), - } -} - -func (rcc *retryClusterClient) MemberList(ctx context.Context, in *pb.MemberListRequest, opts ...grpc.CallOption) (resp *pb.MemberListResponse, err error) { - err = rcc.retryf(ctx, func(rctx context.Context) error { - resp, err = rcc.cc.MemberList(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rcc *retryClusterClient) MemberAdd(ctx context.Context, in *pb.MemberAddRequest, opts ...grpc.CallOption) (resp *pb.MemberAddResponse, err error) { - err = rcc.retryf(ctx, func(rctx context.Context) error { - resp, err = rcc.cc.MemberAdd(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rcc *retryClusterClient) MemberRemove(ctx context.Context, in *pb.MemberRemoveRequest, opts ...grpc.CallOption) (resp *pb.MemberRemoveResponse, err error) { - err = rcc.retryf(ctx, func(rctx context.Context) error { - resp, err = rcc.cc.MemberRemove(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rcc *retryClusterClient) MemberUpdate(ctx context.Context, in *pb.MemberUpdateRequest, opts ...grpc.CallOption) (resp *pb.MemberUpdateResponse, err error) { - err = rcc.retryf(ctx, func(rctx context.Context) error { - resp, err = rcc.cc.MemberUpdate(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -type retryMaintenanceClient struct { - mc pb.MaintenanceClient - retryf retryRPCFunc -} - -// RetryMaintenanceClient implements a Maintenance. -func RetryMaintenanceClient(c *Client, conn *grpc.ClientConn) pb.MaintenanceClient { - return &retryMaintenanceClient{ - mc: pb.NewMaintenanceClient(conn), - retryf: c.newRetryWrapper(), - } -} - -func (rmc *retryMaintenanceClient) Alarm(ctx context.Context, in *pb.AlarmRequest, opts ...grpc.CallOption) (resp *pb.AlarmResponse, err error) { - err = rmc.retryf(ctx, func(rctx context.Context) error { - resp, err = rmc.mc.Alarm(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rmc *retryMaintenanceClient) Status(ctx context.Context, in *pb.StatusRequest, opts ...grpc.CallOption) (resp *pb.StatusResponse, err error) { - err = rmc.retryf(ctx, func(rctx context.Context) error { - resp, err = rmc.mc.Status(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rmc *retryMaintenanceClient) Hash(ctx context.Context, in *pb.HashRequest, opts ...grpc.CallOption) (resp *pb.HashResponse, err error) { - err = rmc.retryf(ctx, func(rctx context.Context) error { - resp, err = rmc.mc.Hash(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rmc *retryMaintenanceClient) HashKV(ctx context.Context, in *pb.HashKVRequest, opts ...grpc.CallOption) (resp *pb.HashKVResponse, err error) { - err = rmc.retryf(ctx, func(rctx context.Context) error { - resp, err = rmc.mc.HashKV(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rmc *retryMaintenanceClient) Snapshot(ctx context.Context, in *pb.SnapshotRequest, opts ...grpc.CallOption) (stream pb.Maintenance_SnapshotClient, err error) { - err = rmc.retryf(ctx, func(rctx context.Context) error { - stream, err = rmc.mc.Snapshot(rctx, in, opts...) - return err - }, repeatable) - return stream, err -} - -func (rmc *retryMaintenanceClient) MoveLeader(ctx context.Context, in *pb.MoveLeaderRequest, opts ...grpc.CallOption) (resp *pb.MoveLeaderResponse, err error) { - err = rmc.retryf(ctx, func(rctx context.Context) error { - resp, err = rmc.mc.MoveLeader(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rmc *retryMaintenanceClient) Defragment(ctx context.Context, in *pb.DefragmentRequest, opts ...grpc.CallOption) (resp *pb.DefragmentResponse, err error) { - err = rmc.retryf(ctx, func(rctx context.Context) error { - resp, err = rmc.mc.Defragment(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -type retryAuthClient struct { - ac pb.AuthClient - retryf retryRPCFunc -} - -// RetryAuthClient implements a AuthClient. -func RetryAuthClient(c *Client) pb.AuthClient { - return &retryAuthClient{ - ac: pb.NewAuthClient(c.conn), - retryf: c.newRetryWrapper(), - } -} - -func (rac *retryAuthClient) UserList(ctx context.Context, in *pb.AuthUserListRequest, opts ...grpc.CallOption) (resp *pb.AuthUserListResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.UserList(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rac *retryAuthClient) UserGet(ctx context.Context, in *pb.AuthUserGetRequest, opts ...grpc.CallOption) (resp *pb.AuthUserGetResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.UserGet(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rac *retryAuthClient) RoleGet(ctx context.Context, in *pb.AuthRoleGetRequest, opts ...grpc.CallOption) (resp *pb.AuthRoleGetResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.RoleGet(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rac *retryAuthClient) RoleList(ctx context.Context, in *pb.AuthRoleListRequest, opts ...grpc.CallOption) (resp *pb.AuthRoleListResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.RoleList(rctx, in, opts...) - return err - }, repeatable) - return resp, err -} - -func (rac *retryAuthClient) AuthEnable(ctx context.Context, in *pb.AuthEnableRequest, opts ...grpc.CallOption) (resp *pb.AuthEnableResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.AuthEnable(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) AuthDisable(ctx context.Context, in *pb.AuthDisableRequest, opts ...grpc.CallOption) (resp *pb.AuthDisableResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.AuthDisable(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) UserAdd(ctx context.Context, in *pb.AuthUserAddRequest, opts ...grpc.CallOption) (resp *pb.AuthUserAddResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.UserAdd(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) UserDelete(ctx context.Context, in *pb.AuthUserDeleteRequest, opts ...grpc.CallOption) (resp *pb.AuthUserDeleteResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.UserDelete(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) UserChangePassword(ctx context.Context, in *pb.AuthUserChangePasswordRequest, opts ...grpc.CallOption) (resp *pb.AuthUserChangePasswordResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.UserChangePassword(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) UserGrantRole(ctx context.Context, in *pb.AuthUserGrantRoleRequest, opts ...grpc.CallOption) (resp *pb.AuthUserGrantRoleResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.UserGrantRole(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) UserRevokeRole(ctx context.Context, in *pb.AuthUserRevokeRoleRequest, opts ...grpc.CallOption) (resp *pb.AuthUserRevokeRoleResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.UserRevokeRole(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) RoleAdd(ctx context.Context, in *pb.AuthRoleAddRequest, opts ...grpc.CallOption) (resp *pb.AuthRoleAddResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.RoleAdd(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) RoleDelete(ctx context.Context, in *pb.AuthRoleDeleteRequest, opts ...grpc.CallOption) (resp *pb.AuthRoleDeleteResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.RoleDelete(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) RoleGrantPermission(ctx context.Context, in *pb.AuthRoleGrantPermissionRequest, opts ...grpc.CallOption) (resp *pb.AuthRoleGrantPermissionResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.RoleGrantPermission(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) RoleRevokePermission(ctx context.Context, in *pb.AuthRoleRevokePermissionRequest, opts ...grpc.CallOption) (resp *pb.AuthRoleRevokePermissionResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.RoleRevokePermission(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} - -func (rac *retryAuthClient) Authenticate(ctx context.Context, in *pb.AuthenticateRequest, opts ...grpc.CallOption) (resp *pb.AuthenticateResponse, err error) { - err = rac.retryf(ctx, func(rctx context.Context) error { - resp, err = rac.ac.Authenticate(rctx, in, opts...) - return err - }, nonRepeatable) - return resp, err -} diff --git a/vendor/go.etcd.io/etcd/clientv3/sort.go b/vendor/go.etcd.io/etcd/clientv3/sort.go deleted file mode 100644 index 2bb9d9a13b78..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/sort.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -type SortTarget int -type SortOrder int - -const ( - SortNone SortOrder = iota - SortAscend - SortDescend -) - -const ( - SortByKey SortTarget = iota - SortByVersion - SortByCreateRevision - SortByModRevision - SortByValue -) - -type SortOption struct { - Target SortTarget - Order SortOrder -} diff --git a/vendor/go.etcd.io/etcd/clientv3/txn.go b/vendor/go.etcd.io/etcd/clientv3/txn.go deleted file mode 100644 index c3c2d2485693..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/txn.go +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - "sync" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" -) - -// Txn is the interface that wraps mini-transactions. -// -// Txn(context.TODO()).If( -// Compare(Value(k1), ">", v1), -// Compare(Version(k1), "=", 2) -// ).Then( -// OpPut(k2,v2), OpPut(k3,v3) -// ).Else( -// OpPut(k4,v4), OpPut(k5,v5) -// ).Commit() -// -type Txn interface { - // If takes a list of comparison. If all comparisons passed in succeed, - // the operations passed into Then() will be executed. Or the operations - // passed into Else() will be executed. - If(cs ...Cmp) Txn - - // Then takes a list of operations. The Ops list will be executed, if the - // comparisons passed in If() succeed. - Then(ops ...Op) Txn - - // Else takes a list of operations. The Ops list will be executed, if the - // comparisons passed in If() fail. - Else(ops ...Op) Txn - - // Commit tries to commit the transaction. - Commit() (*TxnResponse, error) -} - -type txn struct { - kv *kv - ctx context.Context - - mu sync.Mutex - cif bool - cthen bool - celse bool - - isWrite bool - - cmps []*pb.Compare - - sus []*pb.RequestOp - fas []*pb.RequestOp - - callOpts []grpc.CallOption -} - -func (txn *txn) If(cs ...Cmp) Txn { - txn.mu.Lock() - defer txn.mu.Unlock() - - if txn.cif { - panic("cannot call If twice!") - } - - if txn.cthen { - panic("cannot call If after Then!") - } - - if txn.celse { - panic("cannot call If after Else!") - } - - txn.cif = true - - for i := range cs { - txn.cmps = append(txn.cmps, (*pb.Compare)(&cs[i])) - } - - return txn -} - -func (txn *txn) Then(ops ...Op) Txn { - txn.mu.Lock() - defer txn.mu.Unlock() - - if txn.cthen { - panic("cannot call Then twice!") - } - if txn.celse { - panic("cannot call Then after Else!") - } - - txn.cthen = true - - for _, op := range ops { - txn.isWrite = txn.isWrite || op.isWrite() - txn.sus = append(txn.sus, op.toRequestOp()) - } - - return txn -} - -func (txn *txn) Else(ops ...Op) Txn { - txn.mu.Lock() - defer txn.mu.Unlock() - - if txn.celse { - panic("cannot call Else twice!") - } - - txn.celse = true - - for _, op := range ops { - txn.isWrite = txn.isWrite || op.isWrite() - txn.fas = append(txn.fas, op.toRequestOp()) - } - - return txn -} - -func (txn *txn) Commit() (*TxnResponse, error) { - txn.mu.Lock() - defer txn.mu.Unlock() - - r := &pb.TxnRequest{Compare: txn.cmps, Success: txn.sus, Failure: txn.fas} - - var resp *pb.TxnResponse - var err error - resp, err = txn.kv.remote.Txn(txn.ctx, r, txn.callOpts...) - if err != nil { - return nil, toErr(txn.ctx, err) - } - return (*TxnResponse)(resp), nil -} diff --git a/vendor/go.etcd.io/etcd/clientv3/watch.go b/vendor/go.etcd.io/etcd/clientv3/watch.go deleted file mode 100644 index d7633850e7c9..000000000000 --- a/vendor/go.etcd.io/etcd/clientv3/watch.go +++ /dev/null @@ -1,828 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientv3 - -import ( - "context" - "fmt" - "sync" - "time" - - v3rpc "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - mvccpb "github.com/coreos/etcd/mvcc/mvccpb" - - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" -) - -const ( - EventTypeDelete = mvccpb.DELETE - EventTypePut = mvccpb.PUT - - closeSendErrTimeout = 250 * time.Millisecond -) - -type Event mvccpb.Event - -type WatchChan <-chan WatchResponse - -type Watcher interface { - // Watch watches on a key or prefix. The watched events will be returned - // through the returned channel. If revisions waiting to be sent over the - // watch are compacted, then the watch will be canceled by the server, the - // client will post a compacted error watch response, and the channel will close. - Watch(ctx context.Context, key string, opts ...OpOption) WatchChan - - // Close closes the watcher and cancels all watch requests. - Close() error -} - -type WatchResponse struct { - Header pb.ResponseHeader - Events []*Event - - // CompactRevision is the minimum revision the watcher may receive. - CompactRevision int64 - - // Canceled is used to indicate watch failure. - // If the watch failed and the stream was about to close, before the channel is closed, - // the channel sends a final response that has Canceled set to true with a non-nil Err(). - Canceled bool - - // Created is used to indicate the creation of the watcher. - Created bool - - closeErr error - - // cancelReason is a reason of canceling watch - cancelReason string -} - -// IsCreate returns true if the event tells that the key is newly created. -func (e *Event) IsCreate() bool { - return e.Type == EventTypePut && e.Kv.CreateRevision == e.Kv.ModRevision -} - -// IsModify returns true if the event tells that a new value is put on existing key. -func (e *Event) IsModify() bool { - return e.Type == EventTypePut && e.Kv.CreateRevision != e.Kv.ModRevision -} - -// Err is the error value if this WatchResponse holds an error. -func (wr *WatchResponse) Err() error { - switch { - case wr.closeErr != nil: - return v3rpc.Error(wr.closeErr) - case wr.CompactRevision != 0: - return v3rpc.ErrCompacted - case wr.Canceled: - if len(wr.cancelReason) != 0 { - return v3rpc.Error(status.Error(codes.FailedPrecondition, wr.cancelReason)) - } - return v3rpc.ErrFutureRev - } - return nil -} - -// IsProgressNotify returns true if the WatchResponse is progress notification. -func (wr *WatchResponse) IsProgressNotify() bool { - return len(wr.Events) == 0 && !wr.Canceled && !wr.Created && wr.CompactRevision == 0 && wr.Header.Revision != 0 -} - -// watcher implements the Watcher interface -type watcher struct { - remote pb.WatchClient - callOpts []grpc.CallOption - - // mu protects the grpc streams map - mu sync.RWMutex - - // streams holds all the active grpc streams keyed by ctx value. - streams map[string]*watchGrpcStream -} - -// watchGrpcStream tracks all watch resources attached to a single grpc stream. -type watchGrpcStream struct { - owner *watcher - remote pb.WatchClient - callOpts []grpc.CallOption - - // ctx controls internal remote.Watch requests - ctx context.Context - // ctxKey is the key used when looking up this stream's context - ctxKey string - cancel context.CancelFunc - - // substreams holds all active watchers on this grpc stream - substreams map[int64]*watcherStream - // resuming holds all resuming watchers on this grpc stream - resuming []*watcherStream - - // reqc sends a watch request from Watch() to the main goroutine - reqc chan *watchRequest - // respc receives data from the watch client - respc chan *pb.WatchResponse - // donec closes to broadcast shutdown - donec chan struct{} - // errc transmits errors from grpc Recv to the watch stream reconnect logic - errc chan error - // closingc gets the watcherStream of closing watchers - closingc chan *watcherStream - // wg is Done when all substream goroutines have exited - wg sync.WaitGroup - - // resumec closes to signal that all substreams should begin resuming - resumec chan struct{} - // closeErr is the error that closed the watch stream - closeErr error -} - -// watchRequest is issued by the subscriber to start a new watcher -type watchRequest struct { - ctx context.Context - key string - end string - rev int64 - // send created notification event if this field is true - createdNotify bool - // progressNotify is for progress updates - progressNotify bool - // filters is the list of events to filter out - filters []pb.WatchCreateRequest_FilterType - // get the previous key-value pair before the event happens - prevKV bool - // retc receives a chan WatchResponse once the watcher is established - retc chan chan WatchResponse -} - -// watcherStream represents a registered watcher -type watcherStream struct { - // initReq is the request that initiated this request - initReq watchRequest - - // outc publishes watch responses to subscriber - outc chan WatchResponse - // recvc buffers watch responses before publishing - recvc chan *WatchResponse - // donec closes when the watcherStream goroutine stops. - donec chan struct{} - // closing is set to true when stream should be scheduled to shutdown. - closing bool - // id is the registered watch id on the grpc stream - id int64 - - // buf holds all events received from etcd but not yet consumed by the client - buf []*WatchResponse -} - -func NewWatcher(c *Client) Watcher { - return NewWatchFromWatchClient(pb.NewWatchClient(c.conn), c) -} - -func NewWatchFromWatchClient(wc pb.WatchClient, c *Client) Watcher { - w := &watcher{ - remote: wc, - streams: make(map[string]*watchGrpcStream), - } - if c != nil { - w.callOpts = c.callOpts - } - return w -} - -// never closes -var valCtxCh = make(chan struct{}) -var zeroTime = time.Unix(0, 0) - -// ctx with only the values; never Done -type valCtx struct{ context.Context } - -func (vc *valCtx) Deadline() (time.Time, bool) { return zeroTime, false } -func (vc *valCtx) Done() <-chan struct{} { return valCtxCh } -func (vc *valCtx) Err() error { return nil } - -func (w *watcher) newWatcherGrpcStream(inctx context.Context) *watchGrpcStream { - ctx, cancel := context.WithCancel(&valCtx{inctx}) - wgs := &watchGrpcStream{ - owner: w, - remote: w.remote, - callOpts: w.callOpts, - ctx: ctx, - ctxKey: streamKeyFromCtx(inctx), - cancel: cancel, - substreams: make(map[int64]*watcherStream), - respc: make(chan *pb.WatchResponse), - reqc: make(chan *watchRequest), - donec: make(chan struct{}), - errc: make(chan error, 1), - closingc: make(chan *watcherStream), - resumec: make(chan struct{}), - } - go wgs.run() - return wgs -} - -// Watch posts a watch request to run() and waits for a new watcher channel -func (w *watcher) Watch(ctx context.Context, key string, opts ...OpOption) WatchChan { - ow := opWatch(key, opts...) - - var filters []pb.WatchCreateRequest_FilterType - if ow.filterPut { - filters = append(filters, pb.WatchCreateRequest_NOPUT) - } - if ow.filterDelete { - filters = append(filters, pb.WatchCreateRequest_NODELETE) - } - - wr := &watchRequest{ - ctx: ctx, - createdNotify: ow.createdNotify, - key: string(ow.key), - end: string(ow.end), - rev: ow.rev, - progressNotify: ow.progressNotify, - filters: filters, - prevKV: ow.prevKV, - retc: make(chan chan WatchResponse, 1), - } - - ok := false - ctxKey := streamKeyFromCtx(ctx) - - // find or allocate appropriate grpc watch stream - w.mu.Lock() - if w.streams == nil { - // closed - w.mu.Unlock() - ch := make(chan WatchResponse) - close(ch) - return ch - } - wgs := w.streams[ctxKey] - if wgs == nil { - wgs = w.newWatcherGrpcStream(ctx) - w.streams[ctxKey] = wgs - } - donec := wgs.donec - reqc := wgs.reqc - w.mu.Unlock() - - // couldn't create channel; return closed channel - closeCh := make(chan WatchResponse, 1) - - // submit request - select { - case reqc <- wr: - ok = true - case <-wr.ctx.Done(): - case <-donec: - if wgs.closeErr != nil { - closeCh <- WatchResponse{closeErr: wgs.closeErr} - break - } - // retry; may have dropped stream from no ctxs - return w.Watch(ctx, key, opts...) - } - - // receive channel - if ok { - select { - case ret := <-wr.retc: - return ret - case <-ctx.Done(): - case <-donec: - if wgs.closeErr != nil { - closeCh <- WatchResponse{closeErr: wgs.closeErr} - break - } - // retry; may have dropped stream from no ctxs - return w.Watch(ctx, key, opts...) - } - } - - close(closeCh) - return closeCh -} - -func (w *watcher) Close() (err error) { - w.mu.Lock() - streams := w.streams - w.streams = nil - w.mu.Unlock() - for _, wgs := range streams { - if werr := wgs.close(); werr != nil { - err = werr - } - } - return err -} - -func (w *watchGrpcStream) close() (err error) { - w.cancel() - <-w.donec - select { - case err = <-w.errc: - default: - } - return toErr(w.ctx, err) -} - -func (w *watcher) closeStream(wgs *watchGrpcStream) { - w.mu.Lock() - close(wgs.donec) - wgs.cancel() - if w.streams != nil { - delete(w.streams, wgs.ctxKey) - } - w.mu.Unlock() -} - -func (w *watchGrpcStream) addSubstream(resp *pb.WatchResponse, ws *watcherStream) { - if resp.WatchId == -1 { - // failed; no channel - close(ws.recvc) - return - } - ws.id = resp.WatchId - w.substreams[ws.id] = ws -} - -func (w *watchGrpcStream) sendCloseSubstream(ws *watcherStream, resp *WatchResponse) { - select { - case ws.outc <- *resp: - case <-ws.initReq.ctx.Done(): - case <-time.After(closeSendErrTimeout): - } - close(ws.outc) -} - -func (w *watchGrpcStream) closeSubstream(ws *watcherStream) { - // send channel response in case stream was never established - select { - case ws.initReq.retc <- ws.outc: - default: - } - // close subscriber's channel - if closeErr := w.closeErr; closeErr != nil && ws.initReq.ctx.Err() == nil { - go w.sendCloseSubstream(ws, &WatchResponse{closeErr: w.closeErr}) - } else if ws.outc != nil { - close(ws.outc) - } - if ws.id != -1 { - delete(w.substreams, ws.id) - return - } - for i := range w.resuming { - if w.resuming[i] == ws { - w.resuming[i] = nil - return - } - } -} - -// run is the root of the goroutines for managing a watcher client -func (w *watchGrpcStream) run() { - var wc pb.Watch_WatchClient - var closeErr error - - // substreams marked to close but goroutine still running; needed for - // avoiding double-closing recvc on grpc stream teardown - closing := make(map[*watcherStream]struct{}) - - defer func() { - w.closeErr = closeErr - // shutdown substreams and resuming substreams - for _, ws := range w.substreams { - if _, ok := closing[ws]; !ok { - close(ws.recvc) - closing[ws] = struct{}{} - } - } - for _, ws := range w.resuming { - if _, ok := closing[ws]; ws != nil && !ok { - close(ws.recvc) - closing[ws] = struct{}{} - } - } - w.joinSubstreams() - for range closing { - w.closeSubstream(<-w.closingc) - } - w.wg.Wait() - w.owner.closeStream(w) - }() - - // start a stream with the etcd grpc server - if wc, closeErr = w.newWatchClient(); closeErr != nil { - return - } - - cancelSet := make(map[int64]struct{}) - - for { - select { - // Watch() requested - case wreq := <-w.reqc: - outc := make(chan WatchResponse, 1) - ws := &watcherStream{ - initReq: *wreq, - id: -1, - outc: outc, - // unbuffered so resumes won't cause repeat events - recvc: make(chan *WatchResponse), - } - - ws.donec = make(chan struct{}) - w.wg.Add(1) - go w.serveSubstream(ws, w.resumec) - - // queue up for watcher creation/resume - w.resuming = append(w.resuming, ws) - if len(w.resuming) == 1 { - // head of resume queue, can register a new watcher - wc.Send(ws.initReq.toPB()) - } - // New events from the watch client - case pbresp := <-w.respc: - switch { - case pbresp.Created: - // response to head of queue creation - if ws := w.resuming[0]; ws != nil { - w.addSubstream(pbresp, ws) - w.dispatchEvent(pbresp) - w.resuming[0] = nil - } - if ws := w.nextResume(); ws != nil { - wc.Send(ws.initReq.toPB()) - } - case pbresp.Canceled && pbresp.CompactRevision == 0: - delete(cancelSet, pbresp.WatchId) - if ws, ok := w.substreams[pbresp.WatchId]; ok { - // signal to stream goroutine to update closingc - close(ws.recvc) - closing[ws] = struct{}{} - } - default: - // dispatch to appropriate watch stream - if ok := w.dispatchEvent(pbresp); ok { - break - } - // watch response on unexpected watch id; cancel id - if _, ok := cancelSet[pbresp.WatchId]; ok { - break - } - cancelSet[pbresp.WatchId] = struct{}{} - cr := &pb.WatchRequest_CancelRequest{ - CancelRequest: &pb.WatchCancelRequest{ - WatchId: pbresp.WatchId, - }, - } - req := &pb.WatchRequest{RequestUnion: cr} - wc.Send(req) - } - // watch client failed on Recv; spawn another if possible - case err := <-w.errc: - if isHaltErr(w.ctx, err) || toErr(w.ctx, err) == v3rpc.ErrNoLeader { - closeErr = err - return - } - if wc, closeErr = w.newWatchClient(); closeErr != nil { - return - } - if ws := w.nextResume(); ws != nil { - wc.Send(ws.initReq.toPB()) - } - cancelSet = make(map[int64]struct{}) - case <-w.ctx.Done(): - return - case ws := <-w.closingc: - w.closeSubstream(ws) - delete(closing, ws) - if len(w.substreams)+len(w.resuming) == 0 { - // no more watchers on this stream, shutdown - return - } - } - } -} - -// nextResume chooses the next resuming to register with the grpc stream. Abandoned -// streams are marked as nil in the queue since the head must wait for its inflight registration. -func (w *watchGrpcStream) nextResume() *watcherStream { - for len(w.resuming) != 0 { - if w.resuming[0] != nil { - return w.resuming[0] - } - w.resuming = w.resuming[1:len(w.resuming)] - } - return nil -} - -// dispatchEvent sends a WatchResponse to the appropriate watcher stream -func (w *watchGrpcStream) dispatchEvent(pbresp *pb.WatchResponse) bool { - events := make([]*Event, len(pbresp.Events)) - for i, ev := range pbresp.Events { - events[i] = (*Event)(ev) - } - wr := &WatchResponse{ - Header: *pbresp.Header, - Events: events, - CompactRevision: pbresp.CompactRevision, - Created: pbresp.Created, - Canceled: pbresp.Canceled, - cancelReason: pbresp.CancelReason, - } - ws, ok := w.substreams[pbresp.WatchId] - if !ok { - return false - } - select { - case ws.recvc <- wr: - case <-ws.donec: - return false - } - return true -} - -// serveWatchClient forwards messages from the grpc stream to run() -func (w *watchGrpcStream) serveWatchClient(wc pb.Watch_WatchClient) { - for { - resp, err := wc.Recv() - if err != nil { - select { - case w.errc <- err: - case <-w.donec: - } - return - } - select { - case w.respc <- resp: - case <-w.donec: - return - } - } -} - -// serveSubstream forwards watch responses from run() to the subscriber -func (w *watchGrpcStream) serveSubstream(ws *watcherStream, resumec chan struct{}) { - if ws.closing { - panic("created substream goroutine but substream is closing") - } - - // nextRev is the minimum expected next revision - nextRev := ws.initReq.rev - resuming := false - defer func() { - if !resuming { - ws.closing = true - } - close(ws.donec) - if !resuming { - w.closingc <- ws - } - w.wg.Done() - }() - - emptyWr := &WatchResponse{} - for { - curWr := emptyWr - outc := ws.outc - - if len(ws.buf) > 0 { - curWr = ws.buf[0] - } else { - outc = nil - } - select { - case outc <- *curWr: - if ws.buf[0].Err() != nil { - return - } - ws.buf[0] = nil - ws.buf = ws.buf[1:] - case wr, ok := <-ws.recvc: - if !ok { - // shutdown from closeSubstream - return - } - - if wr.Created { - if ws.initReq.retc != nil { - ws.initReq.retc <- ws.outc - // to prevent next write from taking the slot in buffered channel - // and posting duplicate create events - ws.initReq.retc = nil - - // send first creation event only if requested - if ws.initReq.createdNotify { - ws.outc <- *wr - } - // once the watch channel is returned, a current revision - // watch must resume at the store revision. This is necessary - // for the following case to work as expected: - // wch := m1.Watch("a") - // m2.Put("a", "b") - // <-wch - // If the revision is only bound on the first observed event, - // if wch is disconnected before the Put is issued, then reconnects - // after it is committed, it'll miss the Put. - if ws.initReq.rev == 0 { - nextRev = wr.Header.Revision - } - } - } else { - // current progress of watch; <= store revision - nextRev = wr.Header.Revision - } - - if len(wr.Events) > 0 { - nextRev = wr.Events[len(wr.Events)-1].Kv.ModRevision + 1 - } - ws.initReq.rev = nextRev - - // created event is already sent above, - // watcher should not post duplicate events - if wr.Created { - continue - } - - // TODO pause channel if buffer gets too large - ws.buf = append(ws.buf, wr) - case <-w.ctx.Done(): - return - case <-ws.initReq.ctx.Done(): - return - case <-resumec: - resuming = true - return - } - } - // lazily send cancel message if events on missing id -} - -func (w *watchGrpcStream) newWatchClient() (pb.Watch_WatchClient, error) { - // mark all substreams as resuming - close(w.resumec) - w.resumec = make(chan struct{}) - w.joinSubstreams() - for _, ws := range w.substreams { - ws.id = -1 - w.resuming = append(w.resuming, ws) - } - // strip out nils, if any - var resuming []*watcherStream - for _, ws := range w.resuming { - if ws != nil { - resuming = append(resuming, ws) - } - } - w.resuming = resuming - w.substreams = make(map[int64]*watcherStream) - - // connect to grpc stream while accepting watcher cancelation - stopc := make(chan struct{}) - donec := w.waitCancelSubstreams(stopc) - wc, err := w.openWatchClient() - close(stopc) - <-donec - - // serve all non-closing streams, even if there's a client error - // so that the teardown path can shutdown the streams as expected. - for _, ws := range w.resuming { - if ws.closing { - continue - } - ws.donec = make(chan struct{}) - w.wg.Add(1) - go w.serveSubstream(ws, w.resumec) - } - - if err != nil { - return nil, v3rpc.Error(err) - } - - // receive data from new grpc stream - go w.serveWatchClient(wc) - return wc, nil -} - -func (w *watchGrpcStream) waitCancelSubstreams(stopc <-chan struct{}) <-chan struct{} { - var wg sync.WaitGroup - wg.Add(len(w.resuming)) - donec := make(chan struct{}) - for i := range w.resuming { - go func(ws *watcherStream) { - defer wg.Done() - if ws.closing { - if ws.initReq.ctx.Err() != nil && ws.outc != nil { - close(ws.outc) - ws.outc = nil - } - return - } - select { - case <-ws.initReq.ctx.Done(): - // closed ws will be removed from resuming - ws.closing = true - close(ws.outc) - ws.outc = nil - w.wg.Add(1) - go func() { - defer w.wg.Done() - w.closingc <- ws - }() - case <-stopc: - } - }(w.resuming[i]) - } - go func() { - defer close(donec) - wg.Wait() - }() - return donec -} - -// joinSubstreams waits for all substream goroutines to complete. -func (w *watchGrpcStream) joinSubstreams() { - for _, ws := range w.substreams { - <-ws.donec - } - for _, ws := range w.resuming { - if ws != nil { - <-ws.donec - } - } -} - -var maxBackoff = 100 * time.Millisecond - -// openWatchClient retries opening a watch client until success or halt. -// manually retry in case "ws==nil && err==nil" -// TODO: remove FailFast=false -func (w *watchGrpcStream) openWatchClient() (ws pb.Watch_WatchClient, err error) { - backoff := time.Millisecond - for { - select { - case <-w.ctx.Done(): - if err == nil { - return nil, w.ctx.Err() - } - return nil, err - default: - } - if ws, err = w.remote.Watch(w.ctx, w.callOpts...); ws != nil && err == nil { - break - } - if isHaltErr(w.ctx, err) { - return nil, v3rpc.Error(err) - } - if isUnavailableErr(w.ctx, err) { - // retry, but backoff - if backoff < maxBackoff { - // 25% backoff factor - backoff = backoff + backoff/4 - if backoff > maxBackoff { - backoff = maxBackoff - } - } - time.Sleep(backoff) - } - } - return ws, nil -} - -// toPB converts an internal watch request structure to its protobuf WatchRequest structure. -func (wr *watchRequest) toPB() *pb.WatchRequest { - req := &pb.WatchCreateRequest{ - StartRevision: wr.rev, - Key: []byte(wr.key), - RangeEnd: []byte(wr.end), - ProgressNotify: wr.progressNotify, - Filters: wr.filters, - PrevKv: wr.prevKV, - } - cr := &pb.WatchRequest_CreateRequest{CreateRequest: req} - return &pb.WatchRequest{RequestUnion: cr} -} - -func streamKeyFromCtx(ctx context.Context) string { - if md, ok := metadata.FromOutgoingContext(ctx); ok { - return fmt.Sprintf("%+v", md) - } - return "" -} diff --git a/vendor/go.etcd.io/etcd/contrib/recipes/barrier.go b/vendor/go.etcd.io/etcd/contrib/recipes/barrier.go deleted file mode 100644 index 6e92817219d1..000000000000 --- a/vendor/go.etcd.io/etcd/contrib/recipes/barrier.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package recipe - -import ( - "context" - - v3 "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -// Barrier creates a key in etcd to block processes, then deletes the key to -// release all blocked processes. -type Barrier struct { - client *v3.Client - ctx context.Context - - key string -} - -func NewBarrier(client *v3.Client, key string) *Barrier { - return &Barrier{client, context.TODO(), key} -} - -// Hold creates the barrier key causing processes to block on Wait. -func (b *Barrier) Hold() error { - _, err := newKey(b.client, b.key, 0) - return err -} - -// Release deletes the barrier key to unblock all waiting processes. -func (b *Barrier) Release() error { - _, err := b.client.Delete(b.ctx, b.key) - return err -} - -// Wait blocks on the barrier key until it is deleted. If there is no key, Wait -// assumes Release has already been called and returns immediately. -func (b *Barrier) Wait() error { - resp, err := b.client.Get(b.ctx, b.key, v3.WithFirstKey()...) - if err != nil { - return err - } - if len(resp.Kvs) == 0 { - // key already removed - return nil - } - _, err = WaitEvents( - b.client, - b.key, - resp.Header.Revision, - []mvccpb.Event_EventType{mvccpb.PUT, mvccpb.DELETE}) - return err -} diff --git a/vendor/go.etcd.io/etcd/contrib/recipes/client.go b/vendor/go.etcd.io/etcd/contrib/recipes/client.go deleted file mode 100644 index 111b0b40c5c0..000000000000 --- a/vendor/go.etcd.io/etcd/contrib/recipes/client.go +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package recipe - -import ( - "context" - "errors" - - v3 "github.com/coreos/etcd/clientv3" - spb "github.com/coreos/etcd/mvcc/mvccpb" -) - -var ( - ErrKeyExists = errors.New("key already exists") - ErrWaitMismatch = errors.New("unexpected wait result") - ErrTooManyClients = errors.New("too many clients") - ErrNoWatcher = errors.New("no watcher channel") -) - -// deleteRevKey deletes a key by revision, returning false if key is missing -func deleteRevKey(kv v3.KV, key string, rev int64) (bool, error) { - cmp := v3.Compare(v3.ModRevision(key), "=", rev) - req := v3.OpDelete(key) - txnresp, err := kv.Txn(context.TODO()).If(cmp).Then(req).Commit() - if err != nil { - return false, err - } else if !txnresp.Succeeded { - return false, nil - } - return true, nil -} - -func claimFirstKey(kv v3.KV, kvs []*spb.KeyValue) (*spb.KeyValue, error) { - for _, k := range kvs { - ok, err := deleteRevKey(kv, string(k.Key), k.ModRevision) - if err != nil { - return nil, err - } else if ok { - return k, nil - } - } - return nil, nil -} diff --git a/vendor/go.etcd.io/etcd/contrib/recipes/doc.go b/vendor/go.etcd.io/etcd/contrib/recipes/doc.go deleted file mode 100644 index 386be975d1a5..000000000000 --- a/vendor/go.etcd.io/etcd/contrib/recipes/doc.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package recipe contains experimental client-side distributed -// synchronization primitives. -package recipe diff --git a/vendor/go.etcd.io/etcd/contrib/recipes/double_barrier.go b/vendor/go.etcd.io/etcd/contrib/recipes/double_barrier.go deleted file mode 100644 index 93cc61b4f8a0..000000000000 --- a/vendor/go.etcd.io/etcd/contrib/recipes/double_barrier.go +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package recipe - -import ( - "context" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/concurrency" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -// DoubleBarrier blocks processes on Enter until an expected count enters, then -// blocks again on Leave until all processes have left. -type DoubleBarrier struct { - s *concurrency.Session - ctx context.Context - - key string // key for the collective barrier - count int - myKey *EphemeralKV // current key for this process on the barrier -} - -func NewDoubleBarrier(s *concurrency.Session, key string, count int) *DoubleBarrier { - return &DoubleBarrier{ - s: s, - ctx: context.TODO(), - key: key, - count: count, - } -} - -// Enter waits for "count" processes to enter the barrier then returns -func (b *DoubleBarrier) Enter() error { - client := b.s.Client() - ek, err := newUniqueEphemeralKey(b.s, b.key+"/waiters") - if err != nil { - return err - } - b.myKey = ek - - resp, err := client.Get(b.ctx, b.key+"/waiters", clientv3.WithPrefix()) - if err != nil { - return err - } - - if len(resp.Kvs) > b.count { - return ErrTooManyClients - } - - if len(resp.Kvs) == b.count { - // unblock waiters - _, err = client.Put(b.ctx, b.key+"/ready", "") - return err - } - - _, err = WaitEvents( - client, - b.key+"/ready", - ek.Revision(), - []mvccpb.Event_EventType{mvccpb.PUT}) - return err -} - -// Leave waits for "count" processes to leave the barrier then returns -func (b *DoubleBarrier) Leave() error { - client := b.s.Client() - resp, err := client.Get(b.ctx, b.key+"/waiters", clientv3.WithPrefix()) - if err != nil { - return err - } - if len(resp.Kvs) == 0 { - return nil - } - - lowest, highest := resp.Kvs[0], resp.Kvs[0] - for _, k := range resp.Kvs { - if k.ModRevision < lowest.ModRevision { - lowest = k - } - if k.ModRevision > highest.ModRevision { - highest = k - } - } - isLowest := string(lowest.Key) == b.myKey.Key() - - if len(resp.Kvs) == 1 { - // this is the only node in the barrier; finish up - if _, err = client.Delete(b.ctx, b.key+"/ready"); err != nil { - return err - } - return b.myKey.Delete() - } - - // this ensures that if a process fails, the ephemeral lease will be - // revoked, its barrier key is removed, and the barrier can resume - - // lowest process in node => wait on highest process - if isLowest { - _, err = WaitEvents( - client, - string(highest.Key), - highest.ModRevision, - []mvccpb.Event_EventType{mvccpb.DELETE}) - if err != nil { - return err - } - return b.Leave() - } - - // delete self and wait on lowest process - if err = b.myKey.Delete(); err != nil { - return err - } - - key := string(lowest.Key) - _, err = WaitEvents( - client, - key, - lowest.ModRevision, - []mvccpb.Event_EventType{mvccpb.DELETE}) - if err != nil { - return err - } - return b.Leave() -} diff --git a/vendor/go.etcd.io/etcd/contrib/recipes/key.go b/vendor/go.etcd.io/etcd/contrib/recipes/key.go deleted file mode 100644 index aea00059aa86..000000000000 --- a/vendor/go.etcd.io/etcd/contrib/recipes/key.go +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package recipe - -import ( - "context" - "fmt" - "strings" - "time" - - v3 "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/concurrency" -) - -// RemoteKV is a key/revision pair created by the client and stored on etcd -type RemoteKV struct { - kv v3.KV - key string - rev int64 - val string -} - -func newKey(kv v3.KV, key string, leaseID v3.LeaseID) (*RemoteKV, error) { - return newKV(kv, key, "", leaseID) -} - -func newKV(kv v3.KV, key, val string, leaseID v3.LeaseID) (*RemoteKV, error) { - rev, err := putNewKV(kv, key, val, leaseID) - if err != nil { - return nil, err - } - return &RemoteKV{kv, key, rev, val}, nil -} - -func newUniqueKV(kv v3.KV, prefix string, val string) (*RemoteKV, error) { - for { - newKey := fmt.Sprintf("%s/%v", prefix, time.Now().UnixNano()) - rev, err := putNewKV(kv, newKey, val, 0) - if err == nil { - return &RemoteKV{kv, newKey, rev, val}, nil - } - if err != ErrKeyExists { - return nil, err - } - } -} - -// putNewKV attempts to create the given key, only succeeding if the key did -// not yet exist. -func putNewKV(kv v3.KV, key, val string, leaseID v3.LeaseID) (int64, error) { - cmp := v3.Compare(v3.Version(key), "=", 0) - req := v3.OpPut(key, val, v3.WithLease(leaseID)) - txnresp, err := kv.Txn(context.TODO()).If(cmp).Then(req).Commit() - if err != nil { - return 0, err - } - if !txnresp.Succeeded { - return 0, ErrKeyExists - } - return txnresp.Header.Revision, nil -} - -// newSequentialKV allocates a new sequential key /nnnnn with a given -// prefix and value. Note: a bookkeeping node __ is also allocated. -func newSequentialKV(kv v3.KV, prefix, val string) (*RemoteKV, error) { - resp, err := kv.Get(context.TODO(), prefix, v3.WithLastKey()...) - if err != nil { - return nil, err - } - - // add 1 to last key, if any - newSeqNum := 0 - if len(resp.Kvs) != 0 { - fields := strings.Split(string(resp.Kvs[0].Key), "/") - _, serr := fmt.Sscanf(fields[len(fields)-1], "%d", &newSeqNum) - if serr != nil { - return nil, serr - } - newSeqNum++ - } - newKey := fmt.Sprintf("%s/%016d", prefix, newSeqNum) - - // base prefix key must be current (i.e., <=) with the server update; - // the base key is important to avoid the following: - // N1: LastKey() == 1, start txn. - // N2: new Key 2, new Key 3, Delete Key 2 - // N1: txn succeeds allocating key 2 when it shouldn't - baseKey := "__" + prefix - - // current revision might contain modification so +1 - cmp := v3.Compare(v3.ModRevision(baseKey), "<", resp.Header.Revision+1) - reqPrefix := v3.OpPut(baseKey, "") - reqnewKey := v3.OpPut(newKey, val) - - txn := kv.Txn(context.TODO()) - txnresp, err := txn.If(cmp).Then(reqPrefix, reqnewKey).Commit() - if err != nil { - return nil, err - } - if !txnresp.Succeeded { - return newSequentialKV(kv, prefix, val) - } - return &RemoteKV{kv, newKey, txnresp.Header.Revision, val}, nil -} - -func (rk *RemoteKV) Key() string { return rk.key } -func (rk *RemoteKV) Revision() int64 { return rk.rev } -func (rk *RemoteKV) Value() string { return rk.val } - -func (rk *RemoteKV) Delete() error { - if rk.kv == nil { - return nil - } - _, err := rk.kv.Delete(context.TODO(), rk.key) - rk.kv = nil - return err -} - -func (rk *RemoteKV) Put(val string) error { - _, err := rk.kv.Put(context.TODO(), rk.key, val) - return err -} - -// EphemeralKV is a new key associated with a session lease -type EphemeralKV struct{ RemoteKV } - -// newEphemeralKV creates a new key/value pair associated with a session lease -func newEphemeralKV(s *concurrency.Session, key, val string) (*EphemeralKV, error) { - k, err := newKV(s.Client(), key, val, s.Lease()) - if err != nil { - return nil, err - } - return &EphemeralKV{*k}, nil -} - -// newUniqueEphemeralKey creates a new unique valueless key associated with a session lease -func newUniqueEphemeralKey(s *concurrency.Session, prefix string) (*EphemeralKV, error) { - return newUniqueEphemeralKV(s, prefix, "") -} - -// newUniqueEphemeralKV creates a new unique key/value pair associated with a session lease -func newUniqueEphemeralKV(s *concurrency.Session, prefix, val string) (ek *EphemeralKV, err error) { - for { - newKey := fmt.Sprintf("%s/%v", prefix, time.Now().UnixNano()) - ek, err = newEphemeralKV(s, newKey, val) - if err == nil || err != ErrKeyExists { - break - } - } - return ek, err -} diff --git a/vendor/go.etcd.io/etcd/contrib/recipes/priority_queue.go b/vendor/go.etcd.io/etcd/contrib/recipes/priority_queue.go deleted file mode 100644 index 2378ce2f89f0..000000000000 --- a/vendor/go.etcd.io/etcd/contrib/recipes/priority_queue.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package recipe - -import ( - "context" - "fmt" - - v3 "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -// PriorityQueue implements a multi-reader, multi-writer distributed queue. -type PriorityQueue struct { - client *v3.Client - ctx context.Context - key string -} - -// NewPriorityQueue creates an etcd priority queue. -func NewPriorityQueue(client *v3.Client, key string) *PriorityQueue { - return &PriorityQueue{client, context.TODO(), key + "/"} -} - -// Enqueue puts a value into a queue with a given priority. -func (q *PriorityQueue) Enqueue(val string, pr uint16) error { - prefix := fmt.Sprintf("%s%05d", q.key, pr) - _, err := newSequentialKV(q.client, prefix, val) - return err -} - -// Dequeue returns Enqueue()'d items in FIFO order. If the -// queue is empty, Dequeue blocks until items are available. -func (q *PriorityQueue) Dequeue() (string, error) { - // TODO: fewer round trips by fetching more than one key - resp, err := q.client.Get(q.ctx, q.key, v3.WithFirstKey()...) - if err != nil { - return "", err - } - - kv, err := claimFirstKey(q.client, resp.Kvs) - if err != nil { - return "", err - } else if kv != nil { - return string(kv.Value), nil - } else if resp.More { - // missed some items, retry to read in more - return q.Dequeue() - } - - // nothing to dequeue; wait on items - ev, err := WaitPrefixEvents( - q.client, - q.key, - resp.Header.Revision, - []mvccpb.Event_EventType{mvccpb.PUT}) - if err != nil { - return "", err - } - - ok, err := deleteRevKey(q.client, string(ev.Kv.Key), ev.Kv.ModRevision) - if err != nil { - return "", err - } else if !ok { - return q.Dequeue() - } - return string(ev.Kv.Value), err -} diff --git a/vendor/go.etcd.io/etcd/contrib/recipes/queue.go b/vendor/go.etcd.io/etcd/contrib/recipes/queue.go deleted file mode 100644 index 5d0423a427e9..000000000000 --- a/vendor/go.etcd.io/etcd/contrib/recipes/queue.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package recipe - -import ( - "context" - - v3 "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -// Queue implements a multi-reader, multi-writer distributed queue. -type Queue struct { - client *v3.Client - ctx context.Context - - keyPrefix string -} - -func NewQueue(client *v3.Client, keyPrefix string) *Queue { - return &Queue{client, context.TODO(), keyPrefix} -} - -func (q *Queue) Enqueue(val string) error { - _, err := newUniqueKV(q.client, q.keyPrefix, val) - return err -} - -// Dequeue returns Enqueue()'d elements in FIFO order. If the -// queue is empty, Dequeue blocks until elements are available. -func (q *Queue) Dequeue() (string, error) { - // TODO: fewer round trips by fetching more than one key - resp, err := q.client.Get(q.ctx, q.keyPrefix, v3.WithFirstRev()...) - if err != nil { - return "", err - } - - kv, err := claimFirstKey(q.client, resp.Kvs) - if err != nil { - return "", err - } else if kv != nil { - return string(kv.Value), nil - } else if resp.More { - // missed some items, retry to read in more - return q.Dequeue() - } - - // nothing yet; wait on elements - ev, err := WaitPrefixEvents( - q.client, - q.keyPrefix, - resp.Header.Revision, - []mvccpb.Event_EventType{mvccpb.PUT}) - if err != nil { - return "", err - } - - ok, err := deleteRevKey(q.client, string(ev.Kv.Key), ev.Kv.ModRevision) - if err != nil { - return "", err - } else if !ok { - return q.Dequeue() - } - return string(ev.Kv.Value), err -} diff --git a/vendor/go.etcd.io/etcd/contrib/recipes/rwmutex.go b/vendor/go.etcd.io/etcd/contrib/recipes/rwmutex.go deleted file mode 100644 index 1213b7e42022..000000000000 --- a/vendor/go.etcd.io/etcd/contrib/recipes/rwmutex.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package recipe - -import ( - "context" - - v3 "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/concurrency" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -type RWMutex struct { - s *concurrency.Session - ctx context.Context - - pfx string - myKey *EphemeralKV -} - -func NewRWMutex(s *concurrency.Session, prefix string) *RWMutex { - return &RWMutex{s, context.TODO(), prefix + "/", nil} -} - -func (rwm *RWMutex) RLock() error { - rk, err := newUniqueEphemeralKey(rwm.s, rwm.pfx+"read") - if err != nil { - return err - } - rwm.myKey = rk - // wait until nodes with "write-" and a lower revision number than myKey are gone - for { - if done, werr := rwm.waitOnLastRev(rwm.pfx + "write"); done || werr != nil { - return werr - } - } -} - -func (rwm *RWMutex) Lock() error { - rk, err := newUniqueEphemeralKey(rwm.s, rwm.pfx+"write") - if err != nil { - return err - } - rwm.myKey = rk - // wait until all keys of lower revision than myKey are gone - for { - if done, werr := rwm.waitOnLastRev(rwm.pfx); done || werr != nil { - return werr - } - // get the new lowest key until this is the only one left - } -} - -// waitOnLowest will wait on the last key with a revision < rwm.myKey.Revision with a -// given prefix. If there are no keys left to wait on, return true. -func (rwm *RWMutex) waitOnLastRev(pfx string) (bool, error) { - client := rwm.s.Client() - // get key that's blocking myKey - opts := append(v3.WithLastRev(), v3.WithMaxModRev(rwm.myKey.Revision()-1)) - lastKey, err := client.Get(rwm.ctx, pfx, opts...) - if err != nil { - return false, err - } - if len(lastKey.Kvs) == 0 { - return true, nil - } - // wait for release on blocking key - _, err = WaitEvents( - client, - string(lastKey.Kvs[0].Key), - rwm.myKey.Revision(), - []mvccpb.Event_EventType{mvccpb.DELETE}) - return false, err -} - -func (rwm *RWMutex) RUnlock() error { return rwm.myKey.Delete() } -func (rwm *RWMutex) Unlock() error { return rwm.myKey.Delete() } diff --git a/vendor/go.etcd.io/etcd/contrib/recipes/watch.go b/vendor/go.etcd.io/etcd/contrib/recipes/watch.go deleted file mode 100644 index 5367872273f3..000000000000 --- a/vendor/go.etcd.io/etcd/contrib/recipes/watch.go +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package recipe - -import ( - "context" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -// WaitEvents waits on a key until it observes the given events and returns the final one. -func WaitEvents(c *clientv3.Client, key string, rev int64, evs []mvccpb.Event_EventType) (*clientv3.Event, error) { - wc := c.Watch(context.Background(), key, clientv3.WithRev(rev)) - if wc == nil { - return nil, ErrNoWatcher - } - return waitEvents(wc, evs), nil -} - -func WaitPrefixEvents(c *clientv3.Client, prefix string, rev int64, evs []mvccpb.Event_EventType) (*clientv3.Event, error) { - wc := c.Watch(context.Background(), prefix, clientv3.WithPrefix(), clientv3.WithRev(rev)) - if wc == nil { - return nil, ErrNoWatcher - } - return waitEvents(wc, evs), nil -} - -func waitEvents(wc clientv3.WatchChan, evs []mvccpb.Event_EventType) *clientv3.Event { - i := 0 - for wresp := range wc { - for _, ev := range wresp.Events { - if ev.Type == evs[i] { - i++ - if i == len(evs) { - return ev - } - } - } - } - return nil -} diff --git a/vendor/go.etcd.io/etcd/embed/config.go b/vendor/go.etcd.io/etcd/embed/config.go deleted file mode 100644 index 835e051a7d62..000000000000 --- a/vendor/go.etcd.io/etcd/embed/config.go +++ /dev/null @@ -1,699 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package embed - -import ( - "crypto/tls" - "fmt" - "io/ioutil" - "net" - "net/http" - "net/url" - "os" - "path/filepath" - "strings" - "time" - - "github.com/coreos/etcd/compactor" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/pkg/cors" - "github.com/coreos/etcd/pkg/netutil" - "github.com/coreos/etcd/pkg/srv" - "github.com/coreos/etcd/pkg/tlsutil" - "github.com/coreos/etcd/pkg/transport" - "github.com/coreos/etcd/pkg/types" - - "github.com/coreos/pkg/capnslog" - "github.com/ghodss/yaml" - "google.golang.org/grpc" - "google.golang.org/grpc/grpclog" -) - -const ( - ClusterStateFlagNew = "new" - ClusterStateFlagExisting = "existing" - - DefaultName = "default" - DefaultMaxSnapshots = 5 - DefaultMaxWALs = 5 - DefaultMaxTxnOps = uint(128) - DefaultMaxRequestBytes = 1.5 * 1024 * 1024 - DefaultGRPCKeepAliveMinTime = 5 * time.Second - DefaultGRPCKeepAliveInterval = 2 * time.Hour - DefaultGRPCKeepAliveTimeout = 20 * time.Second - - DefaultListenPeerURLs = "http://localhost:2380" - DefaultListenClientURLs = "http://localhost:2379" - - DefaultLogOutput = "default" - - // DefaultStrictReconfigCheck is the default value for "--strict-reconfig-check" flag. - // It's enabled by default. - DefaultStrictReconfigCheck = true - // DefaultEnableV2 is the default value for "--enable-v2" flag. - // v2 is enabled by default. - // TODO: disable v2 when deprecated. - DefaultEnableV2 = true - - // maxElectionMs specifies the maximum value of election timeout. - // More details are listed in ../Documentation/tuning.md#time-parameters. - maxElectionMs = 50000 -) - -var ( - ErrConflictBootstrapFlags = fmt.Errorf("multiple discovery or bootstrap flags are set. " + - "Choose one of \"initial-cluster\", \"discovery\" or \"discovery-srv\"") - ErrUnsetAdvertiseClientURLsFlag = fmt.Errorf("--advertise-client-urls is required when --listen-client-urls is set explicitly") - - DefaultInitialAdvertisePeerURLs = "http://localhost:2380" - DefaultAdvertiseClientURLs = "http://localhost:2379" - - defaultHostname string - defaultHostStatus error -) - -func init() { - defaultHostname, defaultHostStatus = netutil.GetDefaultHost() -} - -// Config holds the arguments for configuring an etcd server. -type Config struct { - // member - - CorsInfo *cors.CORSInfo - LPUrls, LCUrls []url.URL - Dir string `json:"data-dir"` - WalDir string `json:"wal-dir"` - MaxSnapFiles uint `json:"max-snapshots"` - MaxWalFiles uint `json:"max-wals"` - Name string `json:"name"` - SnapCount uint64 `json:"snapshot-count"` - - // AutoCompactionMode is either 'periodic' or 'revision'. - AutoCompactionMode string `json:"auto-compaction-mode"` - // AutoCompactionRetention is either duration string with time unit - // (e.g. '5m' for 5-minute), or revision unit (e.g. '5000'). - // If no time unit is provided and compaction mode is 'periodic', - // the unit defaults to hour. For example, '5' translates into 5-hour. - AutoCompactionRetention string `json:"auto-compaction-retention"` - - // TickMs is the number of milliseconds between heartbeat ticks. - // TODO: decouple tickMs and heartbeat tick (current heartbeat tick = 1). - // make ticks a cluster wide configuration. - TickMs uint `json:"heartbeat-interval"` - ElectionMs uint `json:"election-timeout"` - - // InitialElectionTickAdvance is true, then local member fast-forwards - // election ticks to speed up "initial" leader election trigger. This - // benefits the case of larger election ticks. For instance, cross - // datacenter deployment may require longer election timeout of 10-second. - // If true, local node does not need wait up to 10-second. Instead, - // forwards its election ticks to 8-second, and have only 2-second left - // before leader election. - // - // Major assumptions are that: - // - cluster has no active leader thus advancing ticks enables faster - // leader election, or - // - cluster already has an established leader, and rejoining follower - // is likely to receive heartbeats from the leader after tick advance - // and before election timeout. - // - // However, when network from leader to rejoining follower is congested, - // and the follower does not receive leader heartbeat within left election - // ticks, disruptive election has to happen thus affecting cluster - // availabilities. - // - // Disabling this would slow down initial bootstrap process for cross - // datacenter deployments. Make your own tradeoffs by configuring - // --initial-election-tick-advance at the cost of slow initial bootstrap. - // - // If single-node, it advances ticks regardless. - // - // See https://github.com/coreos/etcd/issues/9333 for more detail. - InitialElectionTickAdvance bool `json:"initial-election-tick-advance"` - - QuotaBackendBytes int64 `json:"quota-backend-bytes"` - MaxTxnOps uint `json:"max-txn-ops"` - MaxRequestBytes uint `json:"max-request-bytes"` - - // gRPC server options - - // GRPCKeepAliveMinTime is the minimum interval that a client should - // wait before pinging server. When client pings "too fast", server - // sends goaway and closes the connection (errors: too_many_pings, - // http2.ErrCodeEnhanceYourCalm). When too slow, nothing happens. - // Server expects client pings only when there is any active streams - // (PermitWithoutStream is set false). - GRPCKeepAliveMinTime time.Duration `json:"grpc-keepalive-min-time"` - // GRPCKeepAliveInterval is the frequency of server-to-client ping - // to check if a connection is alive. Close a non-responsive connection - // after an additional duration of Timeout. 0 to disable. - GRPCKeepAliveInterval time.Duration `json:"grpc-keepalive-interval"` - // GRPCKeepAliveTimeout is the additional duration of wait - // before closing a non-responsive connection. 0 to disable. - GRPCKeepAliveTimeout time.Duration `json:"grpc-keepalive-timeout"` - - // clustering - - APUrls, ACUrls []url.URL - ClusterState string `json:"initial-cluster-state"` - DNSCluster string `json:"discovery-srv"` - Dproxy string `json:"discovery-proxy"` - Durl string `json:"discovery"` - InitialCluster string `json:"initial-cluster"` - InitialClusterToken string `json:"initial-cluster-token"` - StrictReconfigCheck bool `json:"strict-reconfig-check"` - EnableV2 bool `json:"enable-v2"` - - // security - - ClientTLSInfo transport.TLSInfo - ClientAutoTLS bool - PeerTLSInfo transport.TLSInfo - PeerAutoTLS bool - - // CipherSuites is a list of supported TLS cipher suites between - // client/server and peers. If empty, Go auto-populates the list. - // Note that cipher suites are prioritized in the given order. - CipherSuites []string `json:"cipher-suites"` - - // debug - - Debug bool `json:"debug"` - LogPkgLevels string `json:"log-package-levels"` - LogOutput string `json:"log-output"` - EnablePprof bool `json:"enable-pprof"` - Metrics string `json:"metrics"` - ListenMetricsUrls []url.URL - ListenMetricsUrlsJSON string `json:"listen-metrics-urls"` - - // ForceNewCluster starts a new cluster even if previously started; unsafe. - ForceNewCluster bool `json:"force-new-cluster"` - - // UserHandlers is for registering users handlers and only used for - // embedding etcd into other applications. - // The map key is the route path for the handler, and - // you must ensure it can't be conflicted with etcd's. - UserHandlers map[string]http.Handler `json:"-"` - // ServiceRegister is for registering users' gRPC services. A simple usage example: - // cfg := embed.NewConfig() - // cfg.ServerRegister = func(s *grpc.Server) { - // pb.RegisterFooServer(s, &fooServer{}) - // pb.RegisterBarServer(s, &barServer{}) - // } - // embed.StartEtcd(cfg) - ServiceRegister func(*grpc.Server) `json:"-"` - - // auth - - AuthToken string `json:"auth-token"` - - // Experimental flags - - ExperimentalInitialCorruptCheck bool `json:"experimental-initial-corrupt-check"` - ExperimentalCorruptCheckTime time.Duration `json:"experimental-corrupt-check-time"` - ExperimentalEnableV2V3 string `json:"experimental-enable-v2v3"` -} - -// configYAML holds the config suitable for yaml parsing -type configYAML struct { - Config - configJSON -} - -// configJSON has file options that are translated into Config options -type configJSON struct { - LPUrlsJSON string `json:"listen-peer-urls"` - LCUrlsJSON string `json:"listen-client-urls"` - CorsJSON string `json:"cors"` - APUrlsJSON string `json:"initial-advertise-peer-urls"` - ACUrlsJSON string `json:"advertise-client-urls"` - ClientSecurityJSON securityConfig `json:"client-transport-security"` - PeerSecurityJSON securityConfig `json:"peer-transport-security"` -} - -type securityConfig struct { - CAFile string `json:"ca-file"` - CertFile string `json:"cert-file"` - KeyFile string `json:"key-file"` - CertAuth bool `json:"client-cert-auth"` - TrustedCAFile string `json:"trusted-ca-file"` - AutoTLS bool `json:"auto-tls"` -} - -// NewConfig creates a new Config populated with default values. -func NewConfig() *Config { - lpurl, _ := url.Parse(DefaultListenPeerURLs) - apurl, _ := url.Parse(DefaultInitialAdvertisePeerURLs) - lcurl, _ := url.Parse(DefaultListenClientURLs) - acurl, _ := url.Parse(DefaultAdvertiseClientURLs) - cfg := &Config{ - CorsInfo: &cors.CORSInfo{}, - MaxSnapFiles: DefaultMaxSnapshots, - MaxWalFiles: DefaultMaxWALs, - Name: DefaultName, - SnapCount: etcdserver.DefaultSnapCount, - MaxTxnOps: DefaultMaxTxnOps, - MaxRequestBytes: DefaultMaxRequestBytes, - GRPCKeepAliveMinTime: DefaultGRPCKeepAliveMinTime, - GRPCKeepAliveInterval: DefaultGRPCKeepAliveInterval, - GRPCKeepAliveTimeout: DefaultGRPCKeepAliveTimeout, - TickMs: 100, - ElectionMs: 1000, - InitialElectionTickAdvance: true, - LPUrls: []url.URL{*lpurl}, - LCUrls: []url.URL{*lcurl}, - APUrls: []url.URL{*apurl}, - ACUrls: []url.URL{*acurl}, - ClusterState: ClusterStateFlagNew, - InitialClusterToken: "etcd-cluster", - StrictReconfigCheck: DefaultStrictReconfigCheck, - LogOutput: DefaultLogOutput, - Metrics: "basic", - EnableV2: DefaultEnableV2, - AuthToken: "simple", - } - cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name) - return cfg -} - -func logTLSHandshakeFailure(conn *tls.Conn, err error) { - state := conn.ConnectionState() - remoteAddr := conn.RemoteAddr().String() - serverName := state.ServerName - if len(state.PeerCertificates) > 0 { - cert := state.PeerCertificates[0] - ips, dns := cert.IPAddresses, cert.DNSNames - plog.Infof("rejected connection from %q (error %q, ServerName %q, IPAddresses %q, DNSNames %q)", remoteAddr, err.Error(), serverName, ips, dns) - } else { - plog.Infof("rejected connection from %q (error %q, ServerName %q)", remoteAddr, err.Error(), serverName) - } -} - -// SetupLogging initializes etcd logging. -// Must be called after flag parsing. -func (cfg *Config) SetupLogging() { - cfg.ClientTLSInfo.HandshakeFailure = logTLSHandshakeFailure - cfg.PeerTLSInfo.HandshakeFailure = logTLSHandshakeFailure - - capnslog.SetGlobalLogLevel(capnslog.INFO) - if cfg.Debug { - capnslog.SetGlobalLogLevel(capnslog.DEBUG) - grpc.EnableTracing = true - // enable info, warning, error - grpclog.SetLoggerV2(grpclog.NewLoggerV2(os.Stderr, os.Stderr, os.Stderr)) - } else { - // only discard info - grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, os.Stderr, os.Stderr)) - } - if cfg.LogPkgLevels != "" { - repoLog := capnslog.MustRepoLogger("github.com/coreos/etcd") - settings, err := repoLog.ParseLogLevelConfig(cfg.LogPkgLevels) - if err != nil { - plog.Warningf("couldn't parse log level string: %s, continuing with default levels", err.Error()) - return - } - repoLog.SetLogLevel(settings) - } - - // capnslog initially SetFormatter(NewDefaultFormatter(os.Stderr)) - // where NewDefaultFormatter returns NewJournaldFormatter when syscall.Getppid() == 1 - // specify 'stdout' or 'stderr' to skip journald logging even when running under systemd - switch cfg.LogOutput { - case "stdout": - capnslog.SetFormatter(capnslog.NewPrettyFormatter(os.Stdout, cfg.Debug)) - case "stderr": - capnslog.SetFormatter(capnslog.NewPrettyFormatter(os.Stderr, cfg.Debug)) - case DefaultLogOutput: - default: - plog.Panicf(`unknown log-output %q (only supports %q, "stdout", "stderr")`, cfg.LogOutput, DefaultLogOutput) - } -} - -func ConfigFromFile(path string) (*Config, error) { - cfg := &configYAML{Config: *NewConfig()} - if err := cfg.configFromFile(path); err != nil { - return nil, err - } - return &cfg.Config, nil -} - -func (cfg *configYAML) configFromFile(path string) error { - b, err := ioutil.ReadFile(path) - if err != nil { - return err - } - - defaultInitialCluster := cfg.InitialCluster - - err = yaml.Unmarshal(b, cfg) - if err != nil { - return err - } - - if cfg.LPUrlsJSON != "" { - u, err := types.NewURLs(strings.Split(cfg.LPUrlsJSON, ",")) - if err != nil { - plog.Fatalf("unexpected error setting up listen-peer-urls: %v", err) - } - cfg.LPUrls = []url.URL(u) - } - - if cfg.LCUrlsJSON != "" { - u, err := types.NewURLs(strings.Split(cfg.LCUrlsJSON, ",")) - if err != nil { - plog.Fatalf("unexpected error setting up listen-client-urls: %v", err) - } - cfg.LCUrls = []url.URL(u) - } - - if cfg.CorsJSON != "" { - if err := cfg.CorsInfo.Set(cfg.CorsJSON); err != nil { - plog.Panicf("unexpected error setting up cors: %v", err) - } - } - - if cfg.APUrlsJSON != "" { - u, err := types.NewURLs(strings.Split(cfg.APUrlsJSON, ",")) - if err != nil { - plog.Fatalf("unexpected error setting up initial-advertise-peer-urls: %v", err) - } - cfg.APUrls = []url.URL(u) - } - - if cfg.ACUrlsJSON != "" { - u, err := types.NewURLs(strings.Split(cfg.ACUrlsJSON, ",")) - if err != nil { - plog.Fatalf("unexpected error setting up advertise-peer-urls: %v", err) - } - cfg.ACUrls = []url.URL(u) - } - - if cfg.ListenMetricsUrlsJSON != "" { - u, err := types.NewURLs(strings.Split(cfg.ListenMetricsUrlsJSON, ",")) - if err != nil { - plog.Fatalf("unexpected error setting up listen-metrics-urls: %v", err) - } - cfg.ListenMetricsUrls = []url.URL(u) - } - - // If a discovery flag is set, clear default initial cluster set by InitialClusterFromName - if (cfg.Durl != "" || cfg.DNSCluster != "") && cfg.InitialCluster == defaultInitialCluster { - cfg.InitialCluster = "" - } - if cfg.ClusterState == "" { - cfg.ClusterState = ClusterStateFlagNew - } - - copySecurityDetails := func(tls *transport.TLSInfo, ysc *securityConfig) { - tls.CAFile = ysc.CAFile - tls.CertFile = ysc.CertFile - tls.KeyFile = ysc.KeyFile - tls.ClientCertAuth = ysc.CertAuth - tls.TrustedCAFile = ysc.TrustedCAFile - } - copySecurityDetails(&cfg.ClientTLSInfo, &cfg.ClientSecurityJSON) - copySecurityDetails(&cfg.PeerTLSInfo, &cfg.PeerSecurityJSON) - cfg.ClientAutoTLS = cfg.ClientSecurityJSON.AutoTLS - cfg.PeerAutoTLS = cfg.PeerSecurityJSON.AutoTLS - - return cfg.Validate() -} - -func updateCipherSuites(tls *transport.TLSInfo, ss []string) error { - if len(tls.CipherSuites) > 0 && len(ss) > 0 { - return fmt.Errorf("TLSInfo.CipherSuites is already specified (given %v)", ss) - } - if len(ss) > 0 { - cs := make([]uint16, len(ss)) - for i, s := range ss { - var ok bool - cs[i], ok = tlsutil.GetCipherSuite(s) - if !ok { - return fmt.Errorf("unexpected TLS cipher suite %q", s) - } - } - tls.CipherSuites = cs - } - return nil -} - -// Validate ensures that '*embed.Config' fields are properly configured. -func (cfg *Config) Validate() error { - if err := checkBindURLs(cfg.LPUrls); err != nil { - return err - } - if err := checkBindURLs(cfg.LCUrls); err != nil { - return err - } - if err := checkBindURLs(cfg.ListenMetricsUrls); err != nil { - return err - } - if err := checkHostURLs(cfg.APUrls); err != nil { - // TODO: return err in v3.4 - addrs := make([]string, len(cfg.APUrls)) - for i := range cfg.APUrls { - addrs[i] = cfg.APUrls[i].String() - } - plog.Warningf("advertise-peer-urls %q is deprecated (%v)", strings.Join(addrs, ","), err) - } - if err := checkHostURLs(cfg.ACUrls); err != nil { - // TODO: return err in v3.4 - addrs := make([]string, len(cfg.ACUrls)) - for i := range cfg.ACUrls { - addrs[i] = cfg.ACUrls[i].String() - } - plog.Warningf("advertise-client-urls %q is deprecated (%v)", strings.Join(addrs, ","), err) - } - - // Check if conflicting flags are passed. - nSet := 0 - for _, v := range []bool{cfg.Durl != "", cfg.InitialCluster != "", cfg.DNSCluster != ""} { - if v { - nSet++ - } - } - - if cfg.ClusterState != ClusterStateFlagNew && cfg.ClusterState != ClusterStateFlagExisting { - return fmt.Errorf("unexpected clusterState %q", cfg.ClusterState) - } - - if nSet > 1 { - return ErrConflictBootstrapFlags - } - - if cfg.TickMs <= 0 { - return fmt.Errorf("--heartbeat-interval must be >0 (set to %dms)", cfg.TickMs) - } - if cfg.ElectionMs <= 0 { - return fmt.Errorf("--election-timeout must be >0 (set to %dms)", cfg.ElectionMs) - } - if 5*cfg.TickMs > cfg.ElectionMs { - return fmt.Errorf("--election-timeout[%vms] should be at least as 5 times as --heartbeat-interval[%vms]", cfg.ElectionMs, cfg.TickMs) - } - if cfg.ElectionMs > maxElectionMs { - return fmt.Errorf("--election-timeout[%vms] is too long, and should be set less than %vms", cfg.ElectionMs, maxElectionMs) - } - - // check this last since proxying in etcdmain may make this OK - if cfg.LCUrls != nil && cfg.ACUrls == nil { - return ErrUnsetAdvertiseClientURLsFlag - } - - switch cfg.AutoCompactionMode { - case "": - case compactor.ModeRevision, compactor.ModePeriodic: - default: - return fmt.Errorf("unknown auto-compaction-mode %q", cfg.AutoCompactionMode) - } - - return nil -} - -// PeerURLsMapAndToken sets up an initial peer URLsMap and cluster token for bootstrap or discovery. -func (cfg *Config) PeerURLsMapAndToken(which string) (urlsmap types.URLsMap, token string, err error) { - token = cfg.InitialClusterToken - switch { - case cfg.Durl != "": - urlsmap = types.URLsMap{} - // If using discovery, generate a temporary cluster based on - // self's advertised peer URLs - urlsmap[cfg.Name] = cfg.APUrls - token = cfg.Durl - case cfg.DNSCluster != "": - clusterStrs, cerr := srv.GetCluster("etcd-server", cfg.Name, cfg.DNSCluster, cfg.APUrls) - if cerr != nil { - plog.Errorf("couldn't resolve during SRV discovery (%v)", cerr) - return nil, "", cerr - } - for _, s := range clusterStrs { - plog.Noticef("got bootstrap from DNS for etcd-server at %s", s) - } - clusterStr := strings.Join(clusterStrs, ",") - if strings.Contains(clusterStr, "https://") && cfg.PeerTLSInfo.CAFile == "" { - cfg.PeerTLSInfo.ServerName = cfg.DNSCluster - } - urlsmap, err = types.NewURLsMap(clusterStr) - // only etcd member must belong to the discovered cluster. - // proxy does not need to belong to the discovered cluster. - if which == "etcd" { - if _, ok := urlsmap[cfg.Name]; !ok { - return nil, "", fmt.Errorf("cannot find local etcd member %q in SRV records", cfg.Name) - } - } - default: - // We're statically configured, and cluster has appropriately been set. - urlsmap, err = types.NewURLsMap(cfg.InitialCluster) - } - return urlsmap, token, err -} - -func (cfg Config) InitialClusterFromName(name string) (ret string) { - if len(cfg.APUrls) == 0 { - return "" - } - n := name - if name == "" { - n = DefaultName - } - for i := range cfg.APUrls { - ret = ret + "," + n + "=" + cfg.APUrls[i].String() - } - return ret[1:] -} - -func (cfg Config) IsNewCluster() bool { return cfg.ClusterState == ClusterStateFlagNew } -func (cfg Config) ElectionTicks() int { return int(cfg.ElectionMs / cfg.TickMs) } - -func (cfg Config) defaultPeerHost() bool { - return len(cfg.APUrls) == 1 && cfg.APUrls[0].String() == DefaultInitialAdvertisePeerURLs -} - -func (cfg Config) defaultClientHost() bool { - return len(cfg.ACUrls) == 1 && cfg.ACUrls[0].String() == DefaultAdvertiseClientURLs -} - -func (cfg *Config) ClientSelfCert() (err error) { - if !cfg.ClientAutoTLS { - return nil - } - if !cfg.ClientTLSInfo.Empty() { - plog.Warningf("ignoring client auto TLS since certs given") - return nil - } - chosts := make([]string, len(cfg.LCUrls)) - for i, u := range cfg.LCUrls { - chosts[i] = u.Host - } - cfg.ClientTLSInfo, err = transport.SelfCert(filepath.Join(cfg.Dir, "fixtures", "client"), chosts) - if err != nil { - return err - } - return updateCipherSuites(&cfg.ClientTLSInfo, cfg.CipherSuites) -} - -func (cfg *Config) PeerSelfCert() (err error) { - if !cfg.PeerAutoTLS { - return nil - } - if !cfg.PeerTLSInfo.Empty() { - plog.Warningf("ignoring peer auto TLS since certs given") - return nil - } - phosts := make([]string, len(cfg.LPUrls)) - for i, u := range cfg.LPUrls { - phosts[i] = u.Host - } - cfg.PeerTLSInfo, err = transport.SelfCert(filepath.Join(cfg.Dir, "fixtures", "peer"), phosts) - if err != nil { - return err - } - return updateCipherSuites(&cfg.PeerTLSInfo, cfg.CipherSuites) -} - -// UpdateDefaultClusterFromName updates cluster advertise URLs with, if available, default host, -// if advertise URLs are default values(localhost:2379,2380) AND if listen URL is 0.0.0.0. -// e.g. advertise peer URL localhost:2380 or listen peer URL 0.0.0.0:2380 -// then the advertise peer host would be updated with machine's default host, -// while keeping the listen URL's port. -// User can work around this by explicitly setting URL with 127.0.0.1. -// It returns the default hostname, if used, and the error, if any, from getting the machine's default host. -// TODO: check whether fields are set instead of whether fields have default value -func (cfg *Config) UpdateDefaultClusterFromName(defaultInitialCluster string) (string, error) { - if defaultHostname == "" || defaultHostStatus != nil { - // update 'initial-cluster' when only the name is specified (e.g. 'etcd --name=abc') - if cfg.Name != DefaultName && cfg.InitialCluster == defaultInitialCluster { - cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name) - } - return "", defaultHostStatus - } - - used := false - pip, pport := cfg.LPUrls[0].Hostname(), cfg.LPUrls[0].Port() - if cfg.defaultPeerHost() && pip == "0.0.0.0" { - cfg.APUrls[0] = url.URL{Scheme: cfg.APUrls[0].Scheme, Host: fmt.Sprintf("%s:%s", defaultHostname, pport)} - used = true - } - // update 'initial-cluster' when only the name is specified (e.g. 'etcd --name=abc') - if cfg.Name != DefaultName && cfg.InitialCluster == defaultInitialCluster { - cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name) - } - - cip, cport := cfg.LCUrls[0].Hostname(), cfg.LCUrls[0].Port() - if cfg.defaultClientHost() && cip == "0.0.0.0" { - cfg.ACUrls[0] = url.URL{Scheme: cfg.ACUrls[0].Scheme, Host: fmt.Sprintf("%s:%s", defaultHostname, cport)} - used = true - } - dhost := defaultHostname - if !used { - dhost = "" - } - return dhost, defaultHostStatus -} - -// checkBindURLs returns an error if any URL uses a domain name. -func checkBindURLs(urls []url.URL) error { - for _, url := range urls { - if url.Scheme == "unix" || url.Scheme == "unixs" { - continue - } - host, _, err := net.SplitHostPort(url.Host) - if err != nil { - return err - } - if host == "localhost" { - // special case for local address - // TODO: support /etc/hosts ? - continue - } - if net.ParseIP(host) == nil { - return fmt.Errorf("expected IP in URL for binding (%s)", url.String()) - } - } - return nil -} - -func checkHostURLs(urls []url.URL) error { - for _, url := range urls { - host, _, err := net.SplitHostPort(url.Host) - if err != nil { - return err - } - if host == "" { - return fmt.Errorf("unexpected empty host (%s)", url.String()) - } - } - return nil -} diff --git a/vendor/go.etcd.io/etcd/embed/doc.go b/vendor/go.etcd.io/etcd/embed/doc.go deleted file mode 100644 index c555aa58ebac..000000000000 --- a/vendor/go.etcd.io/etcd/embed/doc.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package embed provides bindings for embedding an etcd server in a program. - -Launch an embedded etcd server using the configuration defaults: - - import ( - "log" - "time" - - "github.com/coreos/etcd/embed" - ) - - func main() { - cfg := embed.NewConfig() - cfg.Dir = "default.etcd" - e, err := embed.StartEtcd(cfg) - if err != nil { - log.Fatal(err) - } - defer e.Close() - select { - case <-e.Server.ReadyNotify(): - log.Printf("Server is ready!") - case <-time.After(60 * time.Second): - e.Server.Stop() // trigger a shutdown - log.Printf("Server took too long to start!") - } - log.Fatal(<-e.Err()) - } -*/ -package embed diff --git a/vendor/go.etcd.io/etcd/embed/etcd.go b/vendor/go.etcd.io/etcd/embed/etcd.go deleted file mode 100644 index bd848a7137e3..000000000000 --- a/vendor/go.etcd.io/etcd/embed/etcd.go +++ /dev/null @@ -1,582 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package embed - -import ( - "context" - "crypto/tls" - "fmt" - "io/ioutil" - defaultLog "log" - "net" - "net/http" - "net/url" - "strconv" - "sync" - "time" - - "github.com/coreos/etcd/compactor" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/etcdhttp" - "github.com/coreos/etcd/etcdserver/api/v2http" - "github.com/coreos/etcd/etcdserver/api/v2v3" - "github.com/coreos/etcd/etcdserver/api/v3client" - "github.com/coreos/etcd/etcdserver/api/v3rpc" - "github.com/coreos/etcd/pkg/cors" - "github.com/coreos/etcd/pkg/debugutil" - runtimeutil "github.com/coreos/etcd/pkg/runtime" - "github.com/coreos/etcd/pkg/transport" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/rafthttp" - - "github.com/coreos/pkg/capnslog" - grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" - "github.com/soheilhy/cmux" - "google.golang.org/grpc" - "google.golang.org/grpc/keepalive" -) - -var plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "embed") - -const ( - // internal fd usage includes disk usage and transport usage. - // To read/write snapshot, snap pkg needs 1. In normal case, wal pkg needs - // at most 2 to read/lock/write WALs. One case that it needs to 2 is to - // read all logs after some snapshot index, which locates at the end of - // the second last and the head of the last. For purging, it needs to read - // directory, so it needs 1. For fd monitor, it needs 1. - // For transport, rafthttp builds two long-polling connections and at most - // four temporary connections with each member. There are at most 9 members - // in a cluster, so it should reserve 96. - // For the safety, we set the total reserved number to 150. - reservedInternalFDNum = 150 -) - -// Etcd contains a running etcd server and its listeners. -type Etcd struct { - Peers []*peerListener - Clients []net.Listener - // a map of contexts for the servers that serves client requests. - sctxs map[string]*serveCtx - metricsListeners []net.Listener - - Server *etcdserver.EtcdServer - - cfg Config - stopc chan struct{} - errc chan error - - closeOnce sync.Once -} - -type peerListener struct { - net.Listener - serve func() error - close func(context.Context) error -} - -// StartEtcd launches the etcd server and HTTP handlers for client/server communication. -// The returned Etcd.Server is not guaranteed to have joined the cluster. Wait -// on the Etcd.Server.ReadyNotify() channel to know when it completes and is ready for use. -func StartEtcd(inCfg *Config) (e *Etcd, err error) { - if err = inCfg.Validate(); err != nil { - return nil, err - } - serving := false - e = &Etcd{cfg: *inCfg, stopc: make(chan struct{})} - cfg := &e.cfg - defer func() { - if e == nil || err == nil { - return - } - if !serving { - // errored before starting gRPC server for serveCtx.serversC - for _, sctx := range e.sctxs { - close(sctx.serversC) - } - } - e.Close() - e = nil - }() - - if e.Peers, err = startPeerListeners(cfg); err != nil { - return e, err - } - if e.sctxs, err = startClientListeners(cfg); err != nil { - return e, err - } - for _, sctx := range e.sctxs { - e.Clients = append(e.Clients, sctx.l) - } - - var ( - urlsmap types.URLsMap - token string - ) - - memberInitialized := true - if !isMemberInitialized(cfg) { - memberInitialized = false - urlsmap, token, err = cfg.PeerURLsMapAndToken("etcd") - if err != nil { - return e, fmt.Errorf("error setting up initial cluster: %v", err) - } - } - - // AutoCompactionRetention defaults to "0" if not set. - if len(cfg.AutoCompactionRetention) == 0 { - cfg.AutoCompactionRetention = "0" - } - autoCompactionRetention, err := parseCompactionRetention(cfg.AutoCompactionMode, cfg.AutoCompactionRetention) - if err != nil { - return e, err - } - - srvcfg := etcdserver.ServerConfig{ - Name: cfg.Name, - ClientURLs: cfg.ACUrls, - PeerURLs: cfg.APUrls, - DataDir: cfg.Dir, - DedicatedWALDir: cfg.WalDir, - SnapCount: cfg.SnapCount, - MaxSnapFiles: cfg.MaxSnapFiles, - MaxWALFiles: cfg.MaxWalFiles, - InitialPeerURLsMap: urlsmap, - InitialClusterToken: token, - DiscoveryURL: cfg.Durl, - DiscoveryProxy: cfg.Dproxy, - NewCluster: cfg.IsNewCluster(), - ForceNewCluster: cfg.ForceNewCluster, - PeerTLSInfo: cfg.PeerTLSInfo, - TickMs: cfg.TickMs, - ElectionTicks: cfg.ElectionTicks(), - InitialElectionTickAdvance: cfg.InitialElectionTickAdvance, - AutoCompactionRetention: autoCompactionRetention, - AutoCompactionMode: cfg.AutoCompactionMode, - QuotaBackendBytes: cfg.QuotaBackendBytes, - MaxTxnOps: cfg.MaxTxnOps, - MaxRequestBytes: cfg.MaxRequestBytes, - StrictReconfigCheck: cfg.StrictReconfigCheck, - ClientCertAuthEnabled: cfg.ClientTLSInfo.ClientCertAuth, - AuthToken: cfg.AuthToken, - InitialCorruptCheck: cfg.ExperimentalInitialCorruptCheck, - CorruptCheckTime: cfg.ExperimentalCorruptCheckTime, - Debug: cfg.Debug, - } - - if e.Server, err = etcdserver.NewServer(srvcfg); err != nil { - return e, err - } - - // buffer channel so goroutines on closed connections won't wait forever - e.errc = make(chan error, len(e.Peers)+len(e.Clients)+2*len(e.sctxs)) - - // newly started member ("memberInitialized==false") - // does not need corruption check - if memberInitialized { - if err = e.Server.CheckInitialHashKV(); err != nil { - // set "EtcdServer" to nil, so that it does not block on "EtcdServer.Close()" - // (nothing to close since rafthttp transports have not been started) - e.Server = nil - return e, err - } - } - e.Server.Start() - - if err = e.servePeers(); err != nil { - return e, err - } - if err = e.serveClients(); err != nil { - return e, err - } - if err = e.serveMetrics(); err != nil { - return e, err - } - - serving = true - return e, nil -} - -// Config returns the current configuration. -func (e *Etcd) Config() Config { - return e.cfg -} - -// Close gracefully shuts down all servers/listeners. -// Client requests will be terminated with request timeout. -// After timeout, enforce remaning requests be closed immediately. -func (e *Etcd) Close() { - e.closeOnce.Do(func() { close(e.stopc) }) - - // close client requests with request timeout - timeout := 2 * time.Second - if e.Server != nil { - timeout = e.Server.Cfg.ReqTimeout() - } - for _, sctx := range e.sctxs { - for ss := range sctx.serversC { - ctx, cancel := context.WithTimeout(context.Background(), timeout) - stopServers(ctx, ss) - cancel() - } - } - - for _, sctx := range e.sctxs { - sctx.cancel() - } - - for i := range e.Clients { - if e.Clients[i] != nil { - e.Clients[i].Close() - } - } - - for i := range e.metricsListeners { - e.metricsListeners[i].Close() - } - - // close rafthttp transports - if e.Server != nil { - e.Server.Stop() - } - - // close all idle connections in peer handler (wait up to 1-second) - for i := range e.Peers { - if e.Peers[i] != nil && e.Peers[i].close != nil { - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - e.Peers[i].close(ctx) - cancel() - } - } -} - -func stopServers(ctx context.Context, ss *servers) { - shutdownNow := func() { - // first, close the http.Server - ss.http.Shutdown(ctx) - // then close grpc.Server; cancels all active RPCs - ss.grpc.Stop() - } - - // do not grpc.Server.GracefulStop with TLS enabled etcd server - // See https://github.com/grpc/grpc-go/issues/1384#issuecomment-317124531 - // and https://github.com/coreos/etcd/issues/8916 - if ss.secure { - shutdownNow() - return - } - - ch := make(chan struct{}) - go func() { - defer close(ch) - // close listeners to stop accepting new connections, - // will block on any existing transports - ss.grpc.GracefulStop() - }() - - // wait until all pending RPCs are finished - select { - case <-ch: - case <-ctx.Done(): - // took too long, manually close open transports - // e.g. watch streams - shutdownNow() - - // concurrent GracefulStop should be interrupted - <-ch - } -} - -func (e *Etcd) Err() <-chan error { return e.errc } - -func startPeerListeners(cfg *Config) (peers []*peerListener, err error) { - if err = updateCipherSuites(&cfg.PeerTLSInfo, cfg.CipherSuites); err != nil { - return nil, err - } - if err = cfg.PeerSelfCert(); err != nil { - plog.Fatalf("could not get certs (%v)", err) - } - if !cfg.PeerTLSInfo.Empty() { - plog.Infof("peerTLS: %s", cfg.PeerTLSInfo) - } - - peers = make([]*peerListener, len(cfg.LPUrls)) - defer func() { - if err == nil { - return - } - for i := range peers { - if peers[i] != nil && peers[i].close != nil { - plog.Info("stopping listening for peers on ", cfg.LPUrls[i].String()) - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - peers[i].close(ctx) - cancel() - } - } - }() - - for i, u := range cfg.LPUrls { - if u.Scheme == "http" { - if !cfg.PeerTLSInfo.Empty() { - plog.Warningf("The scheme of peer url %s is HTTP while peer key/cert files are presented. Ignored peer key/cert files.", u.String()) - } - if cfg.PeerTLSInfo.ClientCertAuth { - plog.Warningf("The scheme of peer url %s is HTTP while client cert auth (--peer-client-cert-auth) is enabled. Ignored client cert auth for this url.", u.String()) - } - } - peers[i] = &peerListener{close: func(context.Context) error { return nil }} - peers[i].Listener, err = rafthttp.NewListener(u, &cfg.PeerTLSInfo) - if err != nil { - return nil, err - } - // once serve, overwrite with 'http.Server.Shutdown' - peers[i].close = func(context.Context) error { - return peers[i].Listener.Close() - } - plog.Info("listening for peers on ", u.String()) - } - return peers, nil -} - -// configure peer handlers after rafthttp.Transport started -func (e *Etcd) servePeers() (err error) { - ph := etcdhttp.NewPeerHandler(e.Server) - var peerTLScfg *tls.Config - if !e.cfg.PeerTLSInfo.Empty() { - if peerTLScfg, err = e.cfg.PeerTLSInfo.ServerConfig(); err != nil { - return err - } - } - - for _, p := range e.Peers { - gs := v3rpc.Server(e.Server, peerTLScfg) - m := cmux.New(p.Listener) - go gs.Serve(m.Match(cmux.HTTP2())) - srv := &http.Server{ - Handler: grpcHandlerFunc(gs, ph), - ReadTimeout: 5 * time.Minute, - ErrorLog: defaultLog.New(ioutil.Discard, "", 0), // do not log user error - } - go srv.Serve(m.Match(cmux.Any())) - p.serve = func() error { return m.Serve() } - p.close = func(ctx context.Context) error { - // gracefully shutdown http.Server - // close open listeners, idle connections - // until context cancel or time-out - stopServers(ctx, &servers{secure: peerTLScfg != nil, grpc: gs, http: srv}) - return nil - } - } - - // start peer servers in a goroutine - for _, pl := range e.Peers { - go func(l *peerListener) { - e.errHandler(l.serve()) - }(pl) - } - return nil -} - -func startClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err error) { - if err = updateCipherSuites(&cfg.ClientTLSInfo, cfg.CipherSuites); err != nil { - return nil, err - } - if err = cfg.ClientSelfCert(); err != nil { - plog.Fatalf("could not get certs (%v)", err) - } - if cfg.EnablePprof { - plog.Infof("pprof is enabled under %s", debugutil.HTTPPrefixPProf) - } - - sctxs = make(map[string]*serveCtx) - for _, u := range cfg.LCUrls { - sctx := newServeCtx() - - if u.Scheme == "http" || u.Scheme == "unix" { - if !cfg.ClientTLSInfo.Empty() { - plog.Warningf("The scheme of client url %s is HTTP while peer key/cert files are presented. Ignored key/cert files.", u.String()) - } - if cfg.ClientTLSInfo.ClientCertAuth { - plog.Warningf("The scheme of client url %s is HTTP while client cert auth (--client-cert-auth) is enabled. Ignored client cert auth for this url.", u.String()) - } - } - if (u.Scheme == "https" || u.Scheme == "unixs") && cfg.ClientTLSInfo.Empty() { - return nil, fmt.Errorf("TLS key/cert (--cert-file, --key-file) must be provided for client url %s with HTTPs scheme", u.String()) - } - - proto := "tcp" - addr := u.Host - if u.Scheme == "unix" || u.Scheme == "unixs" { - proto = "unix" - addr = u.Host + u.Path - } - - sctx.secure = u.Scheme == "https" || u.Scheme == "unixs" - sctx.insecure = !sctx.secure - if oldctx := sctxs[addr]; oldctx != nil { - oldctx.secure = oldctx.secure || sctx.secure - oldctx.insecure = oldctx.insecure || sctx.insecure - continue - } - - if sctx.l, err = net.Listen(proto, addr); err != nil { - return nil, err - } - // net.Listener will rewrite ipv4 0.0.0.0 to ipv6 [::], breaking - // hosts that disable ipv6. So, use the address given by the user. - sctx.addr = addr - - if fdLimit, fderr := runtimeutil.FDLimit(); fderr == nil { - if fdLimit <= reservedInternalFDNum { - plog.Fatalf("file descriptor limit[%d] of etcd process is too low, and should be set higher than %d to ensure internal usage", fdLimit, reservedInternalFDNum) - } - sctx.l = transport.LimitListener(sctx.l, int(fdLimit-reservedInternalFDNum)) - } - - if proto == "tcp" { - if sctx.l, err = transport.NewKeepAliveListener(sctx.l, "tcp", nil); err != nil { - return nil, err - } - } - - plog.Info("listening for client requests on ", u.Host) - defer func() { - if err != nil { - sctx.l.Close() - plog.Info("stopping listening for client requests on ", u.Host) - } - }() - for k := range cfg.UserHandlers { - sctx.userHandlers[k] = cfg.UserHandlers[k] - } - sctx.serviceRegister = cfg.ServiceRegister - if cfg.EnablePprof || cfg.Debug { - sctx.registerPprof() - } - if cfg.Debug { - sctx.registerTrace() - } - sctxs[addr] = sctx - } - return sctxs, nil -} - -func (e *Etcd) serveClients() (err error) { - if !e.cfg.ClientTLSInfo.Empty() { - plog.Infof("ClientTLS: %s", e.cfg.ClientTLSInfo) - } - - if e.cfg.CorsInfo.String() != "" { - plog.Infof("cors = %s", e.cfg.CorsInfo) - } - - // Start a client server goroutine for each listen address - var h http.Handler - if e.Config().EnableV2 { - if len(e.Config().ExperimentalEnableV2V3) > 0 { - srv := v2v3.NewServer(v3client.New(e.Server), e.cfg.ExperimentalEnableV2V3) - h = v2http.NewClientHandler(srv, e.Server.Cfg.ReqTimeout()) - } else { - h = v2http.NewClientHandler(e.Server, e.Server.Cfg.ReqTimeout()) - } - } else { - mux := http.NewServeMux() - etcdhttp.HandleBasic(mux, e.Server) - h = mux - } - h = http.Handler(&cors.CORSHandler{Handler: h, Info: e.cfg.CorsInfo}) - - gopts := []grpc.ServerOption{} - if e.cfg.GRPCKeepAliveMinTime > time.Duration(0) { - gopts = append(gopts, grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{ - MinTime: e.cfg.GRPCKeepAliveMinTime, - PermitWithoutStream: false, - })) - } - if e.cfg.GRPCKeepAliveInterval > time.Duration(0) && - e.cfg.GRPCKeepAliveTimeout > time.Duration(0) { - gopts = append(gopts, grpc.KeepaliveParams(keepalive.ServerParameters{ - Time: e.cfg.GRPCKeepAliveInterval, - Timeout: e.cfg.GRPCKeepAliveTimeout, - })) - } - - // start client servers in a goroutine - for _, sctx := range e.sctxs { - go func(s *serveCtx) { - e.errHandler(s.serve(e.Server, &e.cfg.ClientTLSInfo, h, e.errHandler, gopts...)) - }(sctx) - } - return nil -} - -func (e *Etcd) serveMetrics() (err error) { - if e.cfg.Metrics == "extensive" { - grpc_prometheus.EnableHandlingTimeHistogram() - } - - if len(e.cfg.ListenMetricsUrls) > 0 { - metricsMux := http.NewServeMux() - etcdhttp.HandleMetricsHealth(metricsMux, e.Server) - - for _, murl := range e.cfg.ListenMetricsUrls { - tlsInfo := &e.cfg.ClientTLSInfo - if murl.Scheme == "http" { - tlsInfo = nil - } - ml, err := transport.NewListener(murl.Host, murl.Scheme, tlsInfo) - if err != nil { - return err - } - e.metricsListeners = append(e.metricsListeners, ml) - go func(u url.URL, ln net.Listener) { - plog.Info("listening for metrics on ", u.String()) - e.errHandler(http.Serve(ln, metricsMux)) - }(murl, ml) - } - } - return nil -} - -func (e *Etcd) errHandler(err error) { - select { - case <-e.stopc: - return - default: - } - select { - case <-e.stopc: - case e.errc <- err: - } -} - -func parseCompactionRetention(mode, retention string) (ret time.Duration, err error) { - h, err := strconv.Atoi(retention) - if err == nil { - switch mode { - case compactor.ModeRevision: - ret = time.Duration(int64(h)) - case compactor.ModePeriodic: - ret = time.Duration(int64(h)) * time.Hour - } - } else { - // periodic compaction - ret, err = time.ParseDuration(retention) - if err != nil { - return 0, fmt.Errorf("error parsing CompactionRetention: %v", err) - } - } - return ret, nil -} diff --git a/vendor/go.etcd.io/etcd/embed/serve.go b/vendor/go.etcd.io/etcd/embed/serve.go deleted file mode 100644 index 62b8b57805b6..000000000000 --- a/vendor/go.etcd.io/etcd/embed/serve.go +++ /dev/null @@ -1,285 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package embed - -import ( - "context" - "io/ioutil" - defaultLog "log" - "net" - "net/http" - "strings" - - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/v3client" - "github.com/coreos/etcd/etcdserver/api/v3election" - "github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb" - v3electiongw "github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb/gw" - "github.com/coreos/etcd/etcdserver/api/v3lock" - "github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb" - v3lockgw "github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb/gw" - "github.com/coreos/etcd/etcdserver/api/v3rpc" - etcdservergw "github.com/coreos/etcd/etcdserver/etcdserverpb/gw" - "github.com/coreos/etcd/pkg/debugutil" - "github.com/coreos/etcd/pkg/transport" - - gw "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/soheilhy/cmux" - "github.com/tmc/grpc-websocket-proxy/wsproxy" - "golang.org/x/net/trace" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials" -) - -type serveCtx struct { - l net.Listener - addr string - secure bool - insecure bool - - ctx context.Context - cancel context.CancelFunc - - userHandlers map[string]http.Handler - serviceRegister func(*grpc.Server) - serversC chan *servers -} - -type servers struct { - secure bool - grpc *grpc.Server - http *http.Server -} - -func newServeCtx() *serveCtx { - ctx, cancel := context.WithCancel(context.Background()) - return &serveCtx{ctx: ctx, cancel: cancel, userHandlers: make(map[string]http.Handler), - serversC: make(chan *servers, 2), // in case sctx.insecure,sctx.secure true - } -} - -// serve accepts incoming connections on the listener l, -// creating a new service goroutine for each. The service goroutines -// read requests and then call handler to reply to them. -func (sctx *serveCtx) serve( - s *etcdserver.EtcdServer, - tlsinfo *transport.TLSInfo, - handler http.Handler, - errHandler func(error), - gopts ...grpc.ServerOption) (err error) { - logger := defaultLog.New(ioutil.Discard, "etcdhttp", 0) - <-s.ReadyNotify() - plog.Info("ready to serve client requests") - - m := cmux.New(sctx.l) - v3c := v3client.New(s) - servElection := v3election.NewElectionServer(v3c) - servLock := v3lock.NewLockServer(v3c) - - var gs *grpc.Server - defer func() { - if err != nil && gs != nil { - gs.Stop() - } - }() - - if sctx.insecure { - gs = v3rpc.Server(s, nil, gopts...) - v3electionpb.RegisterElectionServer(gs, servElection) - v3lockpb.RegisterLockServer(gs, servLock) - if sctx.serviceRegister != nil { - sctx.serviceRegister(gs) - } - grpcl := m.Match(cmux.HTTP2()) - go func() { errHandler(gs.Serve(grpcl)) }() - - var gwmux *gw.ServeMux - gwmux, err = sctx.registerGateway([]grpc.DialOption{grpc.WithInsecure()}) - if err != nil { - return err - } - - httpmux := sctx.createMux(gwmux, handler) - - srvhttp := &http.Server{ - Handler: wrapMux(httpmux), - ErrorLog: logger, // do not log user error - } - httpl := m.Match(cmux.HTTP1()) - go func() { errHandler(srvhttp.Serve(httpl)) }() - - sctx.serversC <- &servers{grpc: gs, http: srvhttp} - plog.Noticef("serving insecure client requests on %s, this is strongly discouraged!", sctx.l.Addr().String()) - } - - if sctx.secure { - tlscfg, tlsErr := tlsinfo.ServerConfig() - if tlsErr != nil { - return tlsErr - } - gs = v3rpc.Server(s, tlscfg, gopts...) - v3electionpb.RegisterElectionServer(gs, servElection) - v3lockpb.RegisterLockServer(gs, servLock) - if sctx.serviceRegister != nil { - sctx.serviceRegister(gs) - } - handler = grpcHandlerFunc(gs, handler) - - dtls := tlscfg.Clone() - // trust local server - dtls.InsecureSkipVerify = true - creds := credentials.NewTLS(dtls) - opts := []grpc.DialOption{grpc.WithTransportCredentials(creds)} - var gwmux *gw.ServeMux - gwmux, err = sctx.registerGateway(opts) - if err != nil { - return err - } - - var tlsl net.Listener - tlsl, err = transport.NewTLSListener(m.Match(cmux.Any()), tlsinfo) - if err != nil { - return err - } - // TODO: add debug flag; enable logging when debug flag is set - httpmux := sctx.createMux(gwmux, handler) - - srv := &http.Server{ - Handler: wrapMux(httpmux), - TLSConfig: tlscfg, - ErrorLog: logger, // do not log user error - } - go func() { errHandler(srv.Serve(tlsl)) }() - - sctx.serversC <- &servers{secure: true, grpc: gs, http: srv} - plog.Infof("serving client requests on %s", sctx.l.Addr().String()) - } - - close(sctx.serversC) - return m.Serve() -} - -// grpcHandlerFunc returns an http.Handler that delegates to grpcServer on incoming gRPC -// connections or otherHandler otherwise. Given in gRPC docs. -func grpcHandlerFunc(grpcServer *grpc.Server, otherHandler http.Handler) http.Handler { - if otherHandler == nil { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - grpcServer.ServeHTTP(w, r) - }) - } - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") { - grpcServer.ServeHTTP(w, r) - } else { - otherHandler.ServeHTTP(w, r) - } - }) -} - -type registerHandlerFunc func(context.Context, *gw.ServeMux, *grpc.ClientConn) error - -func (sctx *serveCtx) registerGateway(opts []grpc.DialOption) (*gw.ServeMux, error) { - ctx := sctx.ctx - conn, err := grpc.DialContext(ctx, sctx.addr, opts...) - if err != nil { - return nil, err - } - gwmux := gw.NewServeMux() - - handlers := []registerHandlerFunc{ - etcdservergw.RegisterKVHandler, - etcdservergw.RegisterWatchHandler, - etcdservergw.RegisterLeaseHandler, - etcdservergw.RegisterClusterHandler, - etcdservergw.RegisterMaintenanceHandler, - etcdservergw.RegisterAuthHandler, - v3lockgw.RegisterLockHandler, - v3electiongw.RegisterElectionHandler, - } - for _, h := range handlers { - if err := h(ctx, gwmux, conn); err != nil { - return nil, err - } - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - plog.Warningf("failed to close conn to %s: %v", sctx.l.Addr().String(), cerr) - } - }() - - return gwmux, nil -} - -func (sctx *serveCtx) createMux(gwmux *gw.ServeMux, handler http.Handler) *http.ServeMux { - httpmux := http.NewServeMux() - for path, h := range sctx.userHandlers { - httpmux.Handle(path, h) - } - - httpmux.Handle( - "/v3beta/", - wsproxy.WebsocketProxy( - gwmux, - wsproxy.WithRequestMutator( - // Default to the POST method for streams - func(incoming *http.Request, outgoing *http.Request) *http.Request { - outgoing.Method = "POST" - return outgoing - }, - ), - ), - ) - if handler != nil { - httpmux.Handle("/", handler) - } - return httpmux -} - -// wraps HTTP multiplexer to mute requests to /v3alpha -// TODO: deprecate this in 3.4 release -func wrapMux(mux *http.ServeMux) http.Handler { return &v3alphaMutator{mux: mux} } - -type v3alphaMutator struct { - mux *http.ServeMux -} - -func (m *v3alphaMutator) ServeHTTP(rw http.ResponseWriter, req *http.Request) { - if req != nil && req.URL != nil && strings.HasPrefix(req.URL.Path, "/v3alpha/") { - req.URL.Path = strings.Replace(req.URL.Path, "/v3alpha/", "/v3beta/", 1) - } - m.mux.ServeHTTP(rw, req) -} - -func (sctx *serveCtx) registerUserHandler(s string, h http.Handler) { - if sctx.userHandlers[s] != nil { - plog.Warningf("path %s already registered by user handler", s) - return - } - sctx.userHandlers[s] = h -} - -func (sctx *serveCtx) registerPprof() { - for p, h := range debugutil.PProfHandlers() { - sctx.registerUserHandler(p, h) - } -} - -func (sctx *serveCtx) registerTrace() { - reqf := func(w http.ResponseWriter, r *http.Request) { trace.Render(w, r, true) } - sctx.registerUserHandler("/debug/requests", http.HandlerFunc(reqf)) - evf := func(w http.ResponseWriter, r *http.Request) { trace.RenderEvents(w, r, true) } - sctx.registerUserHandler("/debug/events", http.HandlerFunc(evf)) -} diff --git a/vendor/go.etcd.io/etcd/embed/util.go b/vendor/go.etcd.io/etcd/embed/util.go deleted file mode 100644 index 168e031389d7..000000000000 --- a/vendor/go.etcd.io/etcd/embed/util.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package embed - -import ( - "path/filepath" - - "github.com/coreos/etcd/wal" -) - -func isMemberInitialized(cfg *Config) bool { - waldir := cfg.WalDir - if waldir == "" { - waldir = filepath.Join(cfg.Dir, "member", "wal") - } - - return wal.Exist(waldir) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/auth_commands.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/auth_commands.go deleted file mode 100644 index 96a17738fc9e..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/auth_commands.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "os" - "strings" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -func NewAuthCommands() cli.Command { - return cli.Command{ - Name: "auth", - Usage: "overall auth controls", - Subcommands: []cli.Command{ - { - Name: "enable", - Usage: "enable auth access controls", - ArgsUsage: " ", - Action: actionAuthEnable, - }, - { - Name: "disable", - Usage: "disable auth access controls", - ArgsUsage: " ", - Action: actionAuthDisable, - }, - }, - } -} - -func actionAuthEnable(c *cli.Context) error { - authEnableDisable(c, true) - return nil -} - -func actionAuthDisable(c *cli.Context) error { - authEnableDisable(c, false) - return nil -} - -func mustNewAuthAPI(c *cli.Context) client.AuthAPI { - hc := mustNewClient(c) - - if c.GlobalBool("debug") { - fmt.Fprintf(os.Stderr, "Cluster-Endpoints: %s\n", strings.Join(hc.Endpoints(), ", ")) - } - - return client.NewAuthAPI(hc) -} - -func authEnableDisable(c *cli.Context, enable bool) { - if len(c.Args()) != 0 { - fmt.Fprintln(os.Stderr, "No arguments accepted") - os.Exit(1) - } - s := mustNewAuthAPI(c) - ctx, cancel := contextWithTotalTimeout(c) - var err error - if enable { - err = s.Enable(ctx) - } else { - err = s.Disable(ctx) - } - cancel() - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - if enable { - fmt.Println("Authentication Enabled") - } else { - fmt.Println("Authentication Disabled") - } -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/backup_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/backup_command.go deleted file mode 100644 index 82e61d8ab291..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/backup_command.go +++ /dev/null @@ -1,256 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "encoding/binary" - "log" - "os" - "path" - "path/filepath" - "regexp" - "time" - - "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/pkg/fileutil" - "github.com/coreos/etcd/pkg/idutil" - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/snap" - "github.com/coreos/etcd/wal" - "github.com/coreos/etcd/wal/walpb" - - bolt "github.com/coreos/bbolt" - "github.com/urfave/cli" -) - -func NewBackupCommand() cli.Command { - return cli.Command{ - Name: "backup", - Usage: "backup an etcd directory", - ArgsUsage: " ", - Flags: []cli.Flag{ - cli.StringFlag{Name: "data-dir", Value: "", Usage: "Path to the etcd data dir"}, - cli.StringFlag{Name: "wal-dir", Value: "", Usage: "Path to the etcd wal dir"}, - cli.StringFlag{Name: "backup-dir", Value: "", Usage: "Path to the backup dir"}, - cli.StringFlag{Name: "backup-wal-dir", Value: "", Usage: "Path to the backup wal dir"}, - cli.BoolFlag{Name: "with-v3", Usage: "Backup v3 backend data"}, - }, - Action: handleBackup, - } -} - -// handleBackup handles a request that intends to do a backup. -func handleBackup(c *cli.Context) error { - var srcWAL string - var destWAL string - - withV3 := c.Bool("with-v3") - srcSnap := filepath.Join(c.String("data-dir"), "member", "snap") - destSnap := filepath.Join(c.String("backup-dir"), "member", "snap") - - if c.String("wal-dir") != "" { - srcWAL = c.String("wal-dir") - } else { - srcWAL = filepath.Join(c.String("data-dir"), "member", "wal") - } - - if c.String("backup-wal-dir") != "" { - destWAL = c.String("backup-wal-dir") - } else { - destWAL = filepath.Join(c.String("backup-dir"), "member", "wal") - } - - if err := fileutil.CreateDirAll(destSnap); err != nil { - log.Fatalf("failed creating backup snapshot dir %v: %v", destSnap, err) - } - - walsnap := saveSnap(destSnap, srcSnap) - metadata, state, ents := loadWAL(srcWAL, walsnap, withV3) - saveDB(filepath.Join(destSnap, "db"), filepath.Join(srcSnap, "db"), state.Commit, withV3) - - idgen := idutil.NewGenerator(0, time.Now()) - metadata.NodeID = idgen.Next() - metadata.ClusterID = idgen.Next() - - neww, err := wal.Create(destWAL, pbutil.MustMarshal(&metadata)) - if err != nil { - log.Fatal(err) - } - defer neww.Close() - if err := neww.Save(state, ents); err != nil { - log.Fatal(err) - } - if err := neww.SaveSnapshot(walsnap); err != nil { - log.Fatal(err) - } - - return nil -} - -func saveSnap(destSnap, srcSnap string) (walsnap walpb.Snapshot) { - ss := snap.New(srcSnap) - snapshot, err := ss.Load() - if err != nil && err != snap.ErrNoSnapshot { - log.Fatal(err) - } - if snapshot != nil { - walsnap.Index, walsnap.Term = snapshot.Metadata.Index, snapshot.Metadata.Term - newss := snap.New(destSnap) - if err = newss.SaveSnap(*snapshot); err != nil { - log.Fatal(err) - } - } - return walsnap -} - -func loadWAL(srcWAL string, walsnap walpb.Snapshot, v3 bool) (etcdserverpb.Metadata, raftpb.HardState, []raftpb.Entry) { - w, err := wal.OpenForRead(srcWAL, walsnap) - if err != nil { - log.Fatal(err) - } - defer w.Close() - wmetadata, state, ents, err := w.ReadAll() - switch err { - case nil: - case wal.ErrSnapshotNotFound: - log.Printf("Failed to find the match snapshot record %+v in wal %v.", walsnap, srcWAL) - log.Printf("etcdctl will add it back. Start auto fixing...") - default: - log.Fatal(err) - } - - re := path.Join(membership.StoreMembersPrefix, "[[:xdigit:]]{1,16}", "attributes") - memberAttrRE := regexp.MustCompile(re) - - removed := uint64(0) - i := 0 - remove := func() { - ents = append(ents[:i], ents[i+1:]...) - removed++ - i-- - } - for i = 0; i < len(ents); i++ { - ents[i].Index -= removed - if ents[i].Type == raftpb.EntryConfChange { - log.Println("ignoring EntryConfChange raft entry") - remove() - continue - } - - var raftReq etcdserverpb.InternalRaftRequest - var v2Req *etcdserverpb.Request - if pbutil.MaybeUnmarshal(&raftReq, ents[i].Data) { - v2Req = raftReq.V2 - } else { - v2Req = &etcdserverpb.Request{} - pbutil.MustUnmarshal(v2Req, ents[i].Data) - } - - if v2Req != nil && v2Req.Method == "PUT" && memberAttrRE.MatchString(v2Req.Path) { - log.Println("ignoring member attribute update on", v2Req.Path) - remove() - continue - } - - if v2Req != nil { - continue - } - - if v3 || raftReq.Header == nil { - continue - } - log.Println("ignoring v3 raft entry") - remove() - } - state.Commit -= removed - var metadata etcdserverpb.Metadata - pbutil.MustUnmarshal(&metadata, wmetadata) - return metadata, state, ents -} - -// saveDB copies the v3 backend and strips cluster information. -func saveDB(destDB, srcDB string, idx uint64, v3 bool) { - // open src db to safely copy db state - if v3 { - var src *bolt.DB - ch := make(chan *bolt.DB, 1) - go func() { - src, err := bolt.Open(srcDB, 0444, &bolt.Options{ReadOnly: true}) - if err != nil { - log.Fatal(err) - } - ch <- src - }() - select { - case src = <-ch: - case <-time.After(time.Second): - log.Println("waiting to acquire lock on", srcDB) - src = <-ch - } - defer src.Close() - - tx, err := src.Begin(false) - if err != nil { - log.Fatal(err) - } - - // copy srcDB to destDB - dest, err := os.Create(destDB) - if err != nil { - log.Fatal(err) - } - if _, err := tx.WriteTo(dest); err != nil { - log.Fatal(err) - } - dest.Close() - if err := tx.Rollback(); err != nil { - log.Fatal(err) - } - } - - db, err := bolt.Open(destDB, 0644, &bolt.Options{}) - if err != nil { - log.Fatal(err) - } - tx, err := db.Begin(true) - if err != nil { - log.Fatal(err) - } - - // remove membership information; should be clobbered by --force-new-cluster - for _, bucket := range []string{"members", "members_removed", "cluster"} { - tx.DeleteBucket([]byte(bucket)) - } - - // update consistent index to match hard state - if !v3 { - idxBytes := make([]byte, 8) - binary.BigEndian.PutUint64(idxBytes, idx) - b, err := tx.CreateBucketIfNotExists([]byte("meta")) - if err != nil { - log.Fatal(err) - } - b.Put([]byte("consistent_index"), idxBytes) - } - - if err := tx.Commit(); err != nil { - log.Fatal(err) - } - if err := db.Close(); err != nil { - log.Fatal(err) - } -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/cluster_health.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/cluster_health.go deleted file mode 100644 index ec0bb241de41..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/cluster_health.go +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "os" - "os/signal" - "time" - - "github.com/coreos/etcd/client" - - "github.com/urfave/cli" -) - -func NewClusterHealthCommand() cli.Command { - return cli.Command{ - Name: "cluster-health", - Usage: "check the health of the etcd cluster", - ArgsUsage: " ", - Flags: []cli.Flag{ - cli.BoolFlag{Name: "forever, f", Usage: "forever check the health every 10 second until CTRL+C"}, - }, - Action: handleClusterHealth, - } -} - -func handleClusterHealth(c *cli.Context) error { - forever := c.Bool("forever") - if forever { - sigch := make(chan os.Signal, 1) - signal.Notify(sigch, os.Interrupt) - - go func() { - <-sigch - os.Exit(0) - }() - } - - tr, err := getTransport(c) - if err != nil { - handleError(c, ExitServerError, err) - } - - hc := http.Client{ - Transport: tr, - } - - cln := mustNewClientNoSync(c) - mi := client.NewMembersAPI(cln) - ms, err := mi.List(context.TODO()) - if err != nil { - fmt.Println("cluster may be unhealthy: failed to list members") - handleError(c, ExitServerError, err) - } - - for { - healthyMembers := 0 - for _, m := range ms { - if len(m.ClientURLs) == 0 { - fmt.Printf("member %s is unreachable: no available published client urls\n", m.ID) - continue - } - - checked := false - for _, url := range m.ClientURLs { - resp, err := hc.Get(url + "/health") - if err != nil { - fmt.Printf("failed to check the health of member %s on %s: %v\n", m.ID, url, err) - continue - } - - result := struct{ Health string }{} - nresult := struct{ Health bool }{} - bytes, err := ioutil.ReadAll(resp.Body) - if err != nil { - fmt.Printf("failed to check the health of member %s on %s: %v\n", m.ID, url, err) - continue - } - resp.Body.Close() - - err = json.Unmarshal(bytes, &result) - if err != nil { - err = json.Unmarshal(bytes, &nresult) - } - if err != nil { - fmt.Printf("failed to check the health of member %s on %s: %v\n", m.ID, url, err) - continue - } - - checked = true - if result.Health == "true" || nresult.Health { - fmt.Printf("member %s is healthy: got healthy result from %s\n", m.ID, url) - healthyMembers++ - } else { - fmt.Printf("member %s is unhealthy: got unhealthy result from %s\n", m.ID, url) - } - break - } - if !checked { - fmt.Printf("member %s is unreachable: %v are all unreachable\n", m.ID, m.ClientURLs) - } - } - switch healthyMembers { - case len(ms): - fmt.Println("cluster is healthy") - case 0: - fmt.Println("cluster is unavailable") - default: - fmt.Println("cluster is degraded") - } - - if !forever { - if healthyMembers == len(ms) { - os.Exit(ExitSuccess) - } - os.Exit(ExitClusterNotHealthy) - } - - fmt.Printf("\nnext check after 10 second...\n\n") - time.Sleep(10 * time.Second) - } -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/doc.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/doc.go deleted file mode 100644 index cedf3f762f62..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package command is a set of libraries for etcdctl commands. -package command diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/error.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/error.go deleted file mode 100644 index e673fa39cf1d..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/error.go +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "encoding/json" - "fmt" - "os" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -const ( - ExitSuccess = iota - ExitBadArgs - ExitBadConnection - ExitBadAuth - ExitServerError - ExitClusterNotHealthy -) - -func handleError(c *cli.Context, code int, err error) { - if c.GlobalString("output") == "json" { - if err, ok := err.(*client.Error); ok { - b, err := json.Marshal(err) - if err != nil { - panic(err) - } - fmt.Fprintln(os.Stderr, string(b)) - os.Exit(code) - } - } - - fmt.Fprintln(os.Stderr, "Error: ", err) - if cerr, ok := err.(*client.ClusterError); ok { - fmt.Fprintln(os.Stderr, cerr.Detail()) - } - os.Exit(code) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/exec_watch_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/exec_watch_command.go deleted file mode 100644 index cc3478cc32f1..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/exec_watch_command.go +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "errors" - "fmt" - "os" - "os/exec" - "os/signal" - - "github.com/coreos/etcd/client" - - "github.com/urfave/cli" -) - -// NewExecWatchCommand returns the CLI command for "exec-watch". -func NewExecWatchCommand() cli.Command { - return cli.Command{ - Name: "exec-watch", - Usage: "watch a key for changes and exec an executable", - ArgsUsage: " [args...]", - Flags: []cli.Flag{ - cli.IntFlag{Name: "after-index", Value: 0, Usage: "watch after the given index"}, - cli.BoolFlag{Name: "recursive, r", Usage: "watch all values for key and child keys"}, - }, - Action: func(c *cli.Context) error { - execWatchCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// execWatchCommandFunc executes the "exec-watch" command. -func execWatchCommandFunc(c *cli.Context, ki client.KeysAPI) { - args := c.Args() - argslen := len(args) - - if argslen < 2 { - handleError(c, ExitBadArgs, errors.New("key and command to exec required")) - } - - var ( - key string - cmdArgs []string - ) - - foundSep := false - for i := range args { - if args[i] == "--" && i != 0 { - foundSep = true - break - } - } - - if foundSep { - key = args[0] - cmdArgs = args[2:] - } else { - // If no flag is parsed, the order of key and cmdArgs will be switched and - // args will not contain `--`. - key = args[argslen-1] - cmdArgs = args[:argslen-1] - } - - index := 0 - if c.Int("after-index") != 0 { - index = c.Int("after-index") - } - - recursive := c.Bool("recursive") - - sigch := make(chan os.Signal, 1) - signal.Notify(sigch, os.Interrupt) - - go func() { - <-sigch - os.Exit(0) - }() - - w := ki.Watcher(key, &client.WatcherOptions{AfterIndex: uint64(index), Recursive: recursive}) - - for { - resp, err := w.Next(context.TODO()) - if err != nil { - handleError(c, ExitServerError, err) - } - if resp.Node.Dir { - fmt.Fprintf(os.Stderr, "Ignored dir %s change\n", resp.Node.Key) - continue - } - - cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...) - cmd.Env = environResponse(resp, os.Environ()) - - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - - go func() { - err := cmd.Start() - if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) - os.Exit(1) - } - cmd.Wait() - }() - } -} - -func environResponse(resp *client.Response, env []string) []string { - env = append(env, "ETCD_WATCH_ACTION="+resp.Action) - env = append(env, "ETCD_WATCH_MODIFIED_INDEX="+fmt.Sprintf("%d", resp.Node.ModifiedIndex)) - env = append(env, "ETCD_WATCH_KEY="+resp.Node.Key) - env = append(env, "ETCD_WATCH_VALUE="+resp.Node.Value) - return env -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/format.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/format.go deleted file mode 100644 index 4a5d4a6a4404..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/format.go +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "encoding/json" - "fmt" - "os" - - "github.com/coreos/etcd/client" -) - -// printResponseKey only supports to print key correctly. -func printResponseKey(resp *client.Response, format string) { - // Format the result. - switch format { - case "simple": - if resp.Action != "delete" { - fmt.Println(resp.Node.Value) - } else { - fmt.Println("PrevNode.Value:", resp.PrevNode.Value) - } - case "extended": - // Extended prints in a rfc2822 style format - fmt.Println("Key:", resp.Node.Key) - fmt.Println("Created-Index:", resp.Node.CreatedIndex) - fmt.Println("Modified-Index:", resp.Node.ModifiedIndex) - - if resp.PrevNode != nil { - fmt.Println("PrevNode.Value:", resp.PrevNode.Value) - } - - fmt.Println("TTL:", resp.Node.TTL) - fmt.Println("Index:", resp.Index) - if resp.Action != "delete" { - fmt.Println("") - fmt.Println(resp.Node.Value) - } - case "json": - b, err := json.Marshal(resp) - if err != nil { - panic(err) - } - fmt.Println(string(b)) - default: - fmt.Fprintln(os.Stderr, "Unsupported output format:", format) - } -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/get_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/get_command.go deleted file mode 100644 index 7f1fc4db1a26..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/get_command.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "errors" - "fmt" - "os" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -// NewGetCommand returns the CLI command for "get". -func NewGetCommand() cli.Command { - return cli.Command{ - Name: "get", - Usage: "retrieve the value of a key", - ArgsUsage: "", - Flags: []cli.Flag{ - cli.BoolFlag{Name: "sort", Usage: "returns result in sorted order"}, - cli.BoolFlag{Name: "quorum, q", Usage: "require quorum for get request"}, - }, - Action: func(c *cli.Context) error { - getCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// getCommandFunc executes the "get" command. -func getCommandFunc(c *cli.Context, ki client.KeysAPI) { - if len(c.Args()) == 0 { - handleError(c, ExitBadArgs, errors.New("key required")) - } - - key := c.Args()[0] - sorted := c.Bool("sort") - quorum := c.Bool("quorum") - - ctx, cancel := contextWithTotalTimeout(c) - resp, err := ki.Get(ctx, key, &client.GetOptions{Sort: sorted, Quorum: quorum}) - cancel() - if err != nil { - handleError(c, ExitServerError, err) - } - - if resp.Node.Dir { - fmt.Fprintln(os.Stderr, fmt.Sprintf("%s: is a directory", resp.Node.Key)) - os.Exit(1) - } - - printResponseKey(resp, c.GlobalString("output")) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/ls_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/ls_command.go deleted file mode 100644 index b2e94fb938e6..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/ls_command.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -func NewLsCommand() cli.Command { - return cli.Command{ - Name: "ls", - Usage: "retrieve a directory", - ArgsUsage: "[key]", - Flags: []cli.Flag{ - cli.BoolFlag{Name: "sort", Usage: "returns result in sorted order"}, - cli.BoolFlag{Name: "recursive, r", Usage: "returns all key names recursively for the given path"}, - cli.BoolFlag{Name: "p", Usage: "append slash (/) to directories"}, - cli.BoolFlag{Name: "quorum, q", Usage: "require quorum for get request"}, - }, - Action: func(c *cli.Context) error { - lsCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// lsCommandFunc executes the "ls" command. -func lsCommandFunc(c *cli.Context, ki client.KeysAPI) { - key := "/" - if len(c.Args()) != 0 { - key = c.Args()[0] - } - - sort := c.Bool("sort") - recursive := c.Bool("recursive") - quorum := c.Bool("quorum") - - ctx, cancel := contextWithTotalTimeout(c) - resp, err := ki.Get(ctx, key, &client.GetOptions{Sort: sort, Recursive: recursive, Quorum: quorum}) - cancel() - if err != nil { - handleError(c, ExitServerError, err) - } - - printLs(c, resp) -} - -// printLs writes a response out in a manner similar to the `ls` command in unix. -// Non-empty directories list their contents and files list their name. -func printLs(c *cli.Context, resp *client.Response) { - if c.GlobalString("output") == "simple" { - if !resp.Node.Dir { - fmt.Println(resp.Node.Key) - } - for _, node := range resp.Node.Nodes { - rPrint(c, node) - } - } else { - // user wants JSON or extended output - printResponseKey(resp, c.GlobalString("output")) - } -} - -// rPrint recursively prints out the nodes in the node structure. -func rPrint(c *cli.Context, n *client.Node) { - if n.Dir && c.Bool("p") { - fmt.Println(fmt.Sprintf("%v/", n.Key)) - } else { - fmt.Println(n.Key) - } - - for _, node := range n.Nodes { - rPrint(c, node) - } -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/member_commands.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/member_commands.go deleted file mode 100644 index 84747873b635..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/member_commands.go +++ /dev/null @@ -1,207 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "os" - "strings" - - "github.com/urfave/cli" -) - -func NewMemberCommand() cli.Command { - return cli.Command{ - Name: "member", - Usage: "member add, remove and list subcommands", - Subcommands: []cli.Command{ - { - Name: "list", - Usage: "enumerate existing cluster members", - ArgsUsage: " ", - Action: actionMemberList, - }, - { - Name: "add", - Usage: "add a new member to the etcd cluster", - ArgsUsage: " ", - Action: actionMemberAdd, - }, - { - Name: "remove", - Usage: "remove an existing member from the etcd cluster", - ArgsUsage: "", - Action: actionMemberRemove, - }, - { - Name: "update", - Usage: "update an existing member in the etcd cluster", - ArgsUsage: " ", - Action: actionMemberUpdate, - }, - }, - } -} - -func actionMemberList(c *cli.Context) error { - if len(c.Args()) != 0 { - fmt.Fprintln(os.Stderr, "No arguments accepted") - os.Exit(1) - } - mAPI := mustNewMembersAPI(c) - ctx, cancel := contextWithTotalTimeout(c) - defer cancel() - - members, err := mAPI.List(ctx) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - leader, err := mAPI.Leader(ctx) - if err != nil { - fmt.Fprintln(os.Stderr, "Failed to get leader: ", err) - os.Exit(1) - } - - for _, m := range members { - isLeader := false - if m.ID == leader.ID { - isLeader = true - } - if len(m.Name) == 0 { - fmt.Printf("%s[unstarted]: peerURLs=%s\n", m.ID, strings.Join(m.PeerURLs, ",")) - } else { - fmt.Printf("%s: name=%s peerURLs=%s clientURLs=%s isLeader=%v\n", m.ID, m.Name, strings.Join(m.PeerURLs, ","), strings.Join(m.ClientURLs, ","), isLeader) - } - } - - return nil -} - -func actionMemberAdd(c *cli.Context) error { - args := c.Args() - if len(args) != 2 { - fmt.Fprintln(os.Stderr, "Provide a name and a single member peerURL") - os.Exit(1) - } - - mAPI := mustNewMembersAPI(c) - - url := args[1] - ctx, cancel := contextWithTotalTimeout(c) - defer cancel() - - m, err := mAPI.Add(ctx, url) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - newID := m.ID - newName := args[0] - fmt.Printf("Added member named %s with ID %s to cluster\n", newName, newID) - - members, err := mAPI.List(ctx) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - conf := []string{} - for _, memb := range members { - for _, u := range memb.PeerURLs { - n := memb.Name - if memb.ID == newID { - n = newName - } - conf = append(conf, fmt.Sprintf("%s=%s", n, u)) - } - } - - fmt.Print("\n") - fmt.Printf("ETCD_NAME=%q\n", newName) - fmt.Printf("ETCD_INITIAL_CLUSTER=%q\n", strings.Join(conf, ",")) - fmt.Printf("ETCD_INITIAL_CLUSTER_STATE=\"existing\"\n") - return nil -} - -func actionMemberRemove(c *cli.Context) error { - args := c.Args() - if len(args) != 1 { - fmt.Fprintln(os.Stderr, "Provide a single member ID") - os.Exit(1) - } - removalID := args[0] - - mAPI := mustNewMembersAPI(c) - - ctx, cancel := contextWithTotalTimeout(c) - defer cancel() - // Get the list of members. - members, err := mAPI.List(ctx) - if err != nil { - fmt.Fprintln(os.Stderr, "Error while verifying ID against known members:", err.Error()) - os.Exit(1) - } - // Sanity check the input. - foundID := false - for _, m := range members { - if m.ID == removalID { - foundID = true - } - if m.Name == removalID { - // Note that, so long as it's not ambiguous, we *could* do the right thing by name here. - fmt.Fprintf(os.Stderr, "Found a member named %s; if this is correct, please use its ID, eg:\n\tetcdctl member remove %s\n", m.Name, m.ID) - fmt.Fprintf(os.Stderr, "For more details, read the documentation at https://github.com/coreos/etcd/blob/master/Documentation/runtime-configuration.md#remove-a-member\n\n") - } - } - if !foundID { - fmt.Fprintf(os.Stderr, "Couldn't find a member in the cluster with an ID of %s.\n", removalID) - os.Exit(1) - } - - // Actually attempt to remove the member. - err = mAPI.Remove(ctx, removalID) - if err != nil { - fmt.Fprintf(os.Stderr, "Received an error trying to remove member %s: %s", removalID, err.Error()) - os.Exit(1) - } - - fmt.Printf("Removed member %s from cluster\n", removalID) - return nil -} - -func actionMemberUpdate(c *cli.Context) error { - args := c.Args() - if len(args) != 2 { - fmt.Fprintln(os.Stderr, "Provide an ID and a list of comma separated peerURL (0xabcd http://example.com,http://example1.com)") - os.Exit(1) - } - - mAPI := mustNewMembersAPI(c) - - mid := args[0] - urls := args[1] - ctx, cancel := contextWithTotalTimeout(c) - err := mAPI.Update(ctx, mid, strings.Split(urls, ",")) - cancel() - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - fmt.Printf("Updated member with ID %s in cluster\n", mid) - return nil -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/mk_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/mk_command.go deleted file mode 100644 index f62415350e11..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/mk_command.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "errors" - "os" - "time" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -// NewMakeCommand returns the CLI command for "mk". -func NewMakeCommand() cli.Command { - return cli.Command{ - Name: "mk", - Usage: "make a new key with a given value", - ArgsUsage: " ", - Flags: []cli.Flag{ - cli.BoolFlag{Name: "in-order", Usage: "create in-order key under directory "}, - cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live in seconds"}, - }, - Action: func(c *cli.Context) error { - mkCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// mkCommandFunc executes the "mk" command. -func mkCommandFunc(c *cli.Context, ki client.KeysAPI) { - if len(c.Args()) == 0 { - handleError(c, ExitBadArgs, errors.New("key required")) - } - key := c.Args()[0] - value, err := argOrStdin(c.Args(), os.Stdin, 1) - if err != nil { - handleError(c, ExitBadArgs, errors.New("value required")) - } - - ttl := c.Int("ttl") - inorder := c.Bool("in-order") - - var resp *client.Response - ctx, cancel := contextWithTotalTimeout(c) - if !inorder { - // Since PrevNoExist means that the Node must not exist previously, - // this Set method always creates a new key. Therefore, mk command - // succeeds only if the key did not previously exist, and the command - // prevents one from overwriting values accidentally. - resp, err = ki.Set(ctx, key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevNoExist}) - } else { - // If in-order flag is specified then create an inorder key under - // the directory identified by the key argument. - resp, err = ki.CreateInOrder(ctx, key, value, &client.CreateInOrderOptions{TTL: time.Duration(ttl) * time.Second}) - } - cancel() - if err != nil { - handleError(c, ExitServerError, err) - } - - printResponseKey(resp, c.GlobalString("output")) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/mkdir_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/mkdir_command.go deleted file mode 100644 index 1d17b7b91031..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/mkdir_command.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "errors" - "time" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -// NewMakeDirCommand returns the CLI command for "mkdir". -func NewMakeDirCommand() cli.Command { - return cli.Command{ - Name: "mkdir", - Usage: "make a new directory", - ArgsUsage: "", - Flags: []cli.Flag{ - cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live in seconds"}, - }, - Action: func(c *cli.Context) error { - mkdirCommandFunc(c, mustNewKeyAPI(c), client.PrevNoExist) - return nil - }, - } -} - -// mkdirCommandFunc executes the "mkdir" command. -func mkdirCommandFunc(c *cli.Context, ki client.KeysAPI, prevExist client.PrevExistType) { - if len(c.Args()) == 0 { - handleError(c, ExitBadArgs, errors.New("key required")) - } - - key := c.Args()[0] - ttl := c.Int("ttl") - - ctx, cancel := contextWithTotalTimeout(c) - resp, err := ki.Set(ctx, key, "", &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: prevExist}) - cancel() - if err != nil { - handleError(c, ExitServerError, err) - } - if c.GlobalString("output") != "simple" { - printResponseKey(resp, c.GlobalString("output")) - } -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/rm_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/rm_command.go deleted file mode 100644 index c6f173be776a..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/rm_command.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "errors" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -// NewRemoveCommand returns the CLI command for "rm". -func NewRemoveCommand() cli.Command { - return cli.Command{ - Name: "rm", - Usage: "remove a key or a directory", - ArgsUsage: "", - Flags: []cli.Flag{ - cli.BoolFlag{Name: "dir", Usage: "removes the key if it is an empty directory or a key-value pair"}, - cli.BoolFlag{Name: "recursive, r", Usage: "removes the key and all child keys(if it is a directory)"}, - cli.StringFlag{Name: "with-value", Value: "", Usage: "previous value"}, - cli.IntFlag{Name: "with-index", Value: 0, Usage: "previous index"}, - }, - Action: func(c *cli.Context) error { - rmCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// rmCommandFunc executes the "rm" command. -func rmCommandFunc(c *cli.Context, ki client.KeysAPI) { - if len(c.Args()) == 0 { - handleError(c, ExitBadArgs, errors.New("key required")) - } - key := c.Args()[0] - recursive := c.Bool("recursive") - dir := c.Bool("dir") - prevValue := c.String("with-value") - prevIndex := c.Int("with-index") - - ctx, cancel := contextWithTotalTimeout(c) - resp, err := ki.Delete(ctx, key, &client.DeleteOptions{PrevIndex: uint64(prevIndex), PrevValue: prevValue, Dir: dir, Recursive: recursive}) - cancel() - if err != nil { - handleError(c, ExitServerError, err) - } - if !resp.Node.Dir || c.GlobalString("output") != "simple" { - printResponseKey(resp, c.GlobalString("output")) - } -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/rmdir_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/rmdir_command.go deleted file mode 100644 index cb3089548f07..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/rmdir_command.go +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "errors" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -// NewRemoveDirCommand returns the CLI command for "rmdir". -func NewRemoveDirCommand() cli.Command { - return cli.Command{ - Name: "rmdir", - Usage: "removes the key if it is an empty directory or a key-value pair", - ArgsUsage: "", - Action: func(c *cli.Context) error { - rmdirCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// rmdirCommandFunc executes the "rmdir" command. -func rmdirCommandFunc(c *cli.Context, ki client.KeysAPI) { - if len(c.Args()) == 0 { - handleError(c, ExitBadArgs, errors.New("key required")) - } - key := c.Args()[0] - - ctx, cancel := contextWithTotalTimeout(c) - resp, err := ki.Delete(ctx, key, &client.DeleteOptions{Dir: true}) - cancel() - if err != nil { - handleError(c, ExitServerError, err) - } - - if !resp.Node.Dir || c.GlobalString("output") != "simple" { - printResponseKey(resp, c.GlobalString("output")) - } -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/role_commands.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/role_commands.go deleted file mode 100644 index 838b040623e1..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/role_commands.go +++ /dev/null @@ -1,255 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "os" - "reflect" - "strings" - - "github.com/coreos/etcd/client" - "github.com/coreos/etcd/pkg/pathutil" - "github.com/urfave/cli" -) - -func NewRoleCommands() cli.Command { - return cli.Command{ - Name: "role", - Usage: "role add, grant and revoke subcommands", - Subcommands: []cli.Command{ - { - Name: "add", - Usage: "add a new role for the etcd cluster", - ArgsUsage: " ", - Action: actionRoleAdd, - }, - { - Name: "get", - Usage: "get details for a role", - ArgsUsage: "", - Action: actionRoleGet, - }, - { - Name: "list", - Usage: "list all roles", - ArgsUsage: " ", - Action: actionRoleList, - }, - { - Name: "remove", - Usage: "remove a role from the etcd cluster", - ArgsUsage: "", - Action: actionRoleRemove, - }, - { - Name: "grant", - Usage: "grant path matches to an etcd role", - ArgsUsage: "", - Flags: []cli.Flag{ - cli.StringFlag{Name: "path", Value: "", Usage: "Path granted for the role to access"}, - cli.BoolFlag{Name: "read", Usage: "Grant read-only access"}, - cli.BoolFlag{Name: "write", Usage: "Grant write-only access"}, - cli.BoolFlag{Name: "readwrite, rw", Usage: "Grant read-write access"}, - }, - Action: actionRoleGrant, - }, - { - Name: "revoke", - Usage: "revoke path matches for an etcd role", - ArgsUsage: "", - Flags: []cli.Flag{ - cli.StringFlag{Name: "path", Value: "", Usage: "Path revoked for the role to access"}, - cli.BoolFlag{Name: "read", Usage: "Revoke read access"}, - cli.BoolFlag{Name: "write", Usage: "Revoke write access"}, - cli.BoolFlag{Name: "readwrite, rw", Usage: "Revoke read-write access"}, - }, - Action: actionRoleRevoke, - }, - }, - } -} - -func mustNewAuthRoleAPI(c *cli.Context) client.AuthRoleAPI { - hc := mustNewClient(c) - - if c.GlobalBool("debug") { - fmt.Fprintf(os.Stderr, "Cluster-Endpoints: %s\n", strings.Join(hc.Endpoints(), ", ")) - } - - return client.NewAuthRoleAPI(hc) -} - -func actionRoleList(c *cli.Context) error { - if len(c.Args()) != 0 { - fmt.Fprintln(os.Stderr, "No arguments accepted") - os.Exit(1) - } - r := mustNewAuthRoleAPI(c) - ctx, cancel := contextWithTotalTimeout(c) - roles, err := r.ListRoles(ctx) - cancel() - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - for _, role := range roles { - fmt.Printf("%s\n", role) - } - - return nil -} - -func actionRoleAdd(c *cli.Context) error { - api, role := mustRoleAPIAndName(c) - ctx, cancel := contextWithTotalTimeout(c) - defer cancel() - currentRole, _ := api.GetRole(ctx, role) - if currentRole != nil { - fmt.Fprintf(os.Stderr, "Role %s already exists\n", role) - os.Exit(1) - } - - err := api.AddRole(ctx, role) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - fmt.Printf("Role %s created\n", role) - return nil -} - -func actionRoleRemove(c *cli.Context) error { - api, role := mustRoleAPIAndName(c) - ctx, cancel := contextWithTotalTimeout(c) - err := api.RemoveRole(ctx, role) - cancel() - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - fmt.Printf("Role %s removed\n", role) - return nil -} - -func actionRoleGrant(c *cli.Context) error { - roleGrantRevoke(c, true) - return nil -} - -func actionRoleRevoke(c *cli.Context) error { - roleGrantRevoke(c, false) - return nil -} - -func roleGrantRevoke(c *cli.Context, grant bool) { - path := c.String("path") - if path == "" { - fmt.Fprintln(os.Stderr, "No path specified; please use `--path`") - os.Exit(1) - } - if pathutil.CanonicalURLPath(path) != path { - fmt.Fprintf(os.Stderr, "Not canonical path; please use `--path=%s`\n", pathutil.CanonicalURLPath(path)) - os.Exit(1) - } - - read := c.Bool("read") - write := c.Bool("write") - rw := c.Bool("readwrite") - permcount := 0 - for _, v := range []bool{read, write, rw} { - if v { - permcount++ - } - } - if permcount != 1 { - fmt.Fprintln(os.Stderr, "Please specify exactly one of --read, --write or --readwrite") - os.Exit(1) - } - var permType client.PermissionType - switch { - case read: - permType = client.ReadPermission - case write: - permType = client.WritePermission - case rw: - permType = client.ReadWritePermission - } - - api, role := mustRoleAPIAndName(c) - ctx, cancel := contextWithTotalTimeout(c) - defer cancel() - currentRole, err := api.GetRole(ctx, role) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - var newRole *client.Role - if grant { - newRole, err = api.GrantRoleKV(ctx, role, []string{path}, permType) - } else { - newRole, err = api.RevokeRoleKV(ctx, role, []string{path}, permType) - } - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - if reflect.DeepEqual(newRole, currentRole) { - if grant { - fmt.Printf("Role unchanged; already granted") - } else { - fmt.Printf("Role unchanged; already revoked") - } - } - - fmt.Printf("Role %s updated\n", role) -} - -func actionRoleGet(c *cli.Context) error { - api, rolename := mustRoleAPIAndName(c) - - ctx, cancel := contextWithTotalTimeout(c) - role, err := api.GetRole(ctx, rolename) - cancel() - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - fmt.Printf("Role: %s\n", role.Role) - fmt.Printf("KV Read:\n") - for _, v := range role.Permissions.KV.Read { - fmt.Printf("\t%s\n", v) - } - fmt.Printf("KV Write:\n") - for _, v := range role.Permissions.KV.Write { - fmt.Printf("\t%s\n", v) - } - return nil -} - -func mustRoleAPIAndName(c *cli.Context) (client.AuthRoleAPI, string) { - args := c.Args() - if len(args) != 1 { - fmt.Fprintln(os.Stderr, "Please provide a role name") - os.Exit(1) - } - - name := args[0] - api := mustNewAuthRoleAPI(c) - return api, name -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/set_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/set_command.go deleted file mode 100644 index f7bb6bd537d4..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/set_command.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "errors" - "os" - "time" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -// NewSetCommand returns the CLI command for "set". -func NewSetCommand() cli.Command { - return cli.Command{ - Name: "set", - Usage: "set the value of a key", - ArgsUsage: " ", - Description: `Set sets the value of a key. - - When begins with '-', is interpreted as a flag. - Insert '--' for workaround: - - $ set -- `, - Flags: []cli.Flag{ - cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live in seconds"}, - cli.StringFlag{Name: "swap-with-value", Value: "", Usage: "previous value"}, - cli.IntFlag{Name: "swap-with-index", Value: 0, Usage: "previous index"}, - }, - Action: func(c *cli.Context) error { - setCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// setCommandFunc executes the "set" command. -func setCommandFunc(c *cli.Context, ki client.KeysAPI) { - if len(c.Args()) == 0 { - handleError(c, ExitBadArgs, errors.New("key required")) - } - key := c.Args()[0] - value, err := argOrStdin(c.Args(), os.Stdin, 1) - if err != nil { - handleError(c, ExitBadArgs, errors.New("value required")) - } - - ttl := c.Int("ttl") - prevValue := c.String("swap-with-value") - prevIndex := c.Int("swap-with-index") - - ctx, cancel := contextWithTotalTimeout(c) - resp, err := ki.Set(ctx, key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevIndex: uint64(prevIndex), PrevValue: prevValue}) - cancel() - if err != nil { - handleError(c, ExitServerError, err) - } - - printResponseKey(resp, c.GlobalString("output")) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/set_dir_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/set_dir_command.go deleted file mode 100644 index aba66b089381..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/set_dir_command.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -// NewSetDirCommand returns the CLI command for "setDir". -func NewSetDirCommand() cli.Command { - return cli.Command{ - Name: "setdir", - Usage: "create a new directory or update an existing directory TTL", - ArgsUsage: "", - Flags: []cli.Flag{ - cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live in seconds"}, - }, - Action: func(c *cli.Context) error { - mkdirCommandFunc(c, mustNewKeyAPI(c), client.PrevIgnore) - return nil - }, - } -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/update_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/update_command.go deleted file mode 100644 index ed4224892de3..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/update_command.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "errors" - "os" - "time" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -// NewUpdateCommand returns the CLI command for "update". -func NewUpdateCommand() cli.Command { - return cli.Command{ - Name: "update", - Usage: "update an existing key with a given value", - ArgsUsage: " ", - Flags: []cli.Flag{ - cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live in seconds"}, - }, - Action: func(c *cli.Context) error { - updateCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// updateCommandFunc executes the "update" command. -func updateCommandFunc(c *cli.Context, ki client.KeysAPI) { - if len(c.Args()) == 0 { - handleError(c, ExitBadArgs, errors.New("key required")) - } - key := c.Args()[0] - value, err := argOrStdin(c.Args(), os.Stdin, 1) - if err != nil { - handleError(c, ExitBadArgs, errors.New("value required")) - } - - ttl := c.Int("ttl") - - ctx, cancel := contextWithTotalTimeout(c) - resp, err := ki.Set(ctx, key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevExist}) - cancel() - if err != nil { - handleError(c, ExitServerError, err) - } - - printResponseKey(resp, c.GlobalString("output")) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/update_dir_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/update_dir_command.go deleted file mode 100644 index 72411dfba1dc..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/update_dir_command.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "errors" - "time" - - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -// NewUpdateDirCommand returns the CLI command for "updatedir". -func NewUpdateDirCommand() cli.Command { - return cli.Command{ - Name: "updatedir", - Usage: "update an existing directory", - ArgsUsage: " ", - Flags: []cli.Flag{ - cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live in seconds"}, - }, - Action: func(c *cli.Context) error { - updatedirCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// updatedirCommandFunc executes the "updatedir" command. -func updatedirCommandFunc(c *cli.Context, ki client.KeysAPI) { - if len(c.Args()) == 0 { - handleError(c, ExitBadArgs, errors.New("key required")) - } - key := c.Args()[0] - ttl := c.Int("ttl") - ctx, cancel := contextWithTotalTimeout(c) - resp, err := ki.Set(ctx, key, "", &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: client.PrevExist}) - cancel() - if err != nil { - handleError(c, ExitServerError, err) - } - if c.GlobalString("output") != "simple" { - printResponseKey(resp, c.GlobalString("output")) - } -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/user_commands.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/user_commands.go deleted file mode 100644 index c0fb900b247a..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/user_commands.go +++ /dev/null @@ -1,225 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "os" - "strings" - - "github.com/bgentry/speakeasy" - "github.com/coreos/etcd/client" - "github.com/urfave/cli" -) - -func NewUserCommands() cli.Command { - return cli.Command{ - Name: "user", - Usage: "user add, grant and revoke subcommands", - Subcommands: []cli.Command{ - { - Name: "add", - Usage: "add a new user for the etcd cluster", - ArgsUsage: "", - Action: actionUserAdd, - }, - { - Name: "get", - Usage: "get details for a user", - ArgsUsage: "", - Action: actionUserGet, - }, - { - Name: "list", - Usage: "list all current users", - ArgsUsage: "", - Action: actionUserList, - }, - { - Name: "remove", - Usage: "remove a user for the etcd cluster", - ArgsUsage: "", - Action: actionUserRemove, - }, - { - Name: "grant", - Usage: "grant roles to an etcd user", - ArgsUsage: "", - Flags: []cli.Flag{cli.StringSliceFlag{Name: "roles", Value: new(cli.StringSlice), Usage: "List of roles to grant or revoke"}}, - Action: actionUserGrant, - }, - { - Name: "revoke", - Usage: "revoke roles for an etcd user", - ArgsUsage: "", - Flags: []cli.Flag{cli.StringSliceFlag{Name: "roles", Value: new(cli.StringSlice), Usage: "List of roles to grant or revoke"}}, - Action: actionUserRevoke, - }, - { - Name: "passwd", - Usage: "change password for a user", - ArgsUsage: "", - Action: actionUserPasswd, - }, - }, - } -} - -func mustNewAuthUserAPI(c *cli.Context) client.AuthUserAPI { - hc := mustNewClient(c) - - if c.GlobalBool("debug") { - fmt.Fprintf(os.Stderr, "Cluster-Endpoints: %s\n", strings.Join(hc.Endpoints(), ", ")) - } - - return client.NewAuthUserAPI(hc) -} - -func actionUserList(c *cli.Context) error { - if len(c.Args()) != 0 { - fmt.Fprintln(os.Stderr, "No arguments accepted") - os.Exit(1) - } - u := mustNewAuthUserAPI(c) - ctx, cancel := contextWithTotalTimeout(c) - users, err := u.ListUsers(ctx) - cancel() - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - for _, user := range users { - fmt.Printf("%s\n", user) - } - return nil -} - -func actionUserAdd(c *cli.Context) error { - api, userarg := mustUserAPIAndName(c) - ctx, cancel := contextWithTotalTimeout(c) - defer cancel() - user, _, _ := getUsernamePassword("", userarg+":") - - _, pass, err := getUsernamePassword("New password: ", userarg) - if err != nil { - fmt.Fprintln(os.Stderr, "Error reading password:", err) - os.Exit(1) - } - err = api.AddUser(ctx, user, pass) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - fmt.Printf("User %s created\n", user) - return nil -} - -func actionUserRemove(c *cli.Context) error { - api, user := mustUserAPIAndName(c) - ctx, cancel := contextWithTotalTimeout(c) - err := api.RemoveUser(ctx, user) - cancel() - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - fmt.Printf("User %s removed\n", user) - return nil -} - -func actionUserPasswd(c *cli.Context) error { - api, user := mustUserAPIAndName(c) - ctx, cancel := contextWithTotalTimeout(c) - defer cancel() - pass, err := speakeasy.Ask("New password: ") - if err != nil { - fmt.Fprintln(os.Stderr, "Error reading password:", err) - os.Exit(1) - } - - _, err = api.ChangePassword(ctx, user, pass) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - fmt.Printf("Password updated\n") - return nil -} - -func actionUserGrant(c *cli.Context) error { - userGrantRevoke(c, true) - return nil -} - -func actionUserRevoke(c *cli.Context) error { - userGrantRevoke(c, false) - return nil -} - -func userGrantRevoke(c *cli.Context, grant bool) { - roles := c.StringSlice("roles") - if len(roles) == 0 { - fmt.Fprintln(os.Stderr, "No roles specified; please use `--roles`") - os.Exit(1) - } - - ctx, cancel := contextWithTotalTimeout(c) - defer cancel() - - api, user := mustUserAPIAndName(c) - var err error - if grant { - _, err = api.GrantUser(ctx, user, roles) - } else { - _, err = api.RevokeUser(ctx, user, roles) - } - - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - fmt.Printf("User %s updated\n", user) -} - -func actionUserGet(c *cli.Context) error { - api, username := mustUserAPIAndName(c) - ctx, cancel := contextWithTotalTimeout(c) - user, err := api.GetUser(ctx, username) - cancel() - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - fmt.Printf("User: %s\n", user.User) - fmt.Printf("Roles: %s\n", strings.Join(user.Roles, " ")) - return nil -} - -func mustUserAPIAndName(c *cli.Context) (client.AuthUserAPI, string) { - args := c.Args() - if len(args) != 1 { - fmt.Fprintln(os.Stderr, "Please provide a username") - os.Exit(1) - } - - api := mustNewAuthUserAPI(c) - username := args[0] - return api, username -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/util.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/util.go deleted file mode 100644 index 4f3d2df69666..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/util.go +++ /dev/null @@ -1,337 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "errors" - "fmt" - "io" - "io/ioutil" - "net" - "net/http" - "net/url" - "os" - "strings" - "syscall" - "time" - - "github.com/coreos/etcd/client" - "github.com/coreos/etcd/pkg/transport" - - "github.com/bgentry/speakeasy" - "github.com/urfave/cli" -) - -var ( - ErrNoAvailSrc = errors.New("no available argument and stdin") - - // the maximum amount of time a dial will wait for a connection to setup. - // 30s is long enough for most of the network conditions. - defaultDialTimeout = 30 * time.Second -) - -func argOrStdin(args []string, stdin io.Reader, i int) (string, error) { - if i < len(args) { - return args[i], nil - } - bytes, err := ioutil.ReadAll(stdin) - if string(bytes) == "" || err != nil { - return "", ErrNoAvailSrc - } - return string(bytes), nil -} - -func getPeersFlagValue(c *cli.Context) []string { - peerstr := c.GlobalString("endpoints") - - if peerstr == "" { - peerstr = os.Getenv("ETCDCTL_ENDPOINTS") - } - - if peerstr == "" { - peerstr = c.GlobalString("endpoint") - } - - if peerstr == "" { - peerstr = os.Getenv("ETCDCTL_ENDPOINT") - } - - if peerstr == "" { - peerstr = c.GlobalString("peers") - } - - if peerstr == "" { - peerstr = os.Getenv("ETCDCTL_PEERS") - } - - // If we still don't have peers, use a default - if peerstr == "" { - peerstr = "http://127.0.0.1:2379,http://127.0.0.1:4001" - } - - return strings.Split(peerstr, ",") -} - -func getDomainDiscoveryFlagValue(c *cli.Context) ([]string, error) { - domainstr, insecure := getDiscoveryDomain(c) - - // If we still don't have domain discovery, return nothing - if domainstr == "" { - return []string{}, nil - } - - discoverer := client.NewSRVDiscover() - eps, err := discoverer.Discover(domainstr) - if err != nil { - return nil, err - } - if insecure { - return eps, err - } - // strip insecure connections - ret := []string{} - for _, ep := range eps { - if strings.HasPrefix(ep, "http://") { - fmt.Fprintf(os.Stderr, "ignoring discovered insecure endpoint %q\n", ep) - continue - } - ret = append(ret, ep) - } - return ret, err -} - -func getDiscoveryDomain(c *cli.Context) (domainstr string, insecure bool) { - domainstr = c.GlobalString("discovery-srv") - // Use an environment variable if nothing was supplied on the - // command line - if domainstr == "" { - domainstr = os.Getenv("ETCDCTL_DISCOVERY_SRV") - } - insecure = c.GlobalBool("insecure-discovery") || (os.Getenv("ETCDCTL_INSECURE_DISCOVERY") != "") - return domainstr, insecure -} - -func getEndpoints(c *cli.Context) ([]string, error) { - eps, err := getDomainDiscoveryFlagValue(c) - if err != nil { - return nil, err - } - - // If domain discovery returns no endpoints, check peer flag - if len(eps) == 0 { - eps = getPeersFlagValue(c) - } - - for i, ep := range eps { - u, err := url.Parse(ep) - if err != nil { - return nil, err - } - - if u.Scheme == "" { - u.Scheme = "http" - } - - eps[i] = u.String() - } - - return eps, nil -} - -func getTransport(c *cli.Context) (*http.Transport, error) { - cafile := c.GlobalString("ca-file") - certfile := c.GlobalString("cert-file") - keyfile := c.GlobalString("key-file") - - // Use an environment variable if nothing was supplied on the - // command line - if cafile == "" { - cafile = os.Getenv("ETCDCTL_CA_FILE") - } - if certfile == "" { - certfile = os.Getenv("ETCDCTL_CERT_FILE") - } - if keyfile == "" { - keyfile = os.Getenv("ETCDCTL_KEY_FILE") - } - - discoveryDomain, insecure := getDiscoveryDomain(c) - if insecure { - discoveryDomain = "" - } - tls := transport.TLSInfo{ - CAFile: cafile, - CertFile: certfile, - KeyFile: keyfile, - ServerName: discoveryDomain, - } - - dialTimeout := defaultDialTimeout - totalTimeout := c.GlobalDuration("total-timeout") - if totalTimeout != 0 && totalTimeout < dialTimeout { - dialTimeout = totalTimeout - } - return transport.NewTransport(tls, dialTimeout) -} - -func getUsernamePasswordFromFlag(usernameFlag string) (username string, password string, err error) { - return getUsernamePassword("Password: ", usernameFlag) -} - -func getUsernamePassword(prompt, usernameFlag string) (username string, password string, err error) { - colon := strings.Index(usernameFlag, ":") - if colon == -1 { - username = usernameFlag - // Prompt for the password. - password, err = speakeasy.Ask(prompt) - if err != nil { - return "", "", err - } - } else { - username = usernameFlag[:colon] - password = usernameFlag[colon+1:] - } - return username, password, nil -} - -func mustNewKeyAPI(c *cli.Context) client.KeysAPI { - return client.NewKeysAPI(mustNewClient(c)) -} - -func mustNewMembersAPI(c *cli.Context) client.MembersAPI { - return client.NewMembersAPI(mustNewClient(c)) -} - -func mustNewClient(c *cli.Context) client.Client { - hc, err := newClient(c) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - debug := c.GlobalBool("debug") - if debug { - client.EnablecURLDebug() - } - - if !c.GlobalBool("no-sync") { - if debug { - fmt.Fprintf(os.Stderr, "start to sync cluster using endpoints(%s)\n", strings.Join(hc.Endpoints(), ",")) - } - ctx, cancel := contextWithTotalTimeout(c) - err := hc.Sync(ctx) - cancel() - if err != nil { - if err == client.ErrNoEndpoints { - fmt.Fprintf(os.Stderr, "etcd cluster has no published client endpoints.\n") - fmt.Fprintf(os.Stderr, "Try '--no-sync' if you want to access non-published client endpoints(%s).\n", strings.Join(hc.Endpoints(), ",")) - handleError(c, ExitServerError, err) - } - if isConnectionError(err) { - handleError(c, ExitBadConnection, err) - } - } - if debug { - fmt.Fprintf(os.Stderr, "got endpoints(%s) after sync\n", strings.Join(hc.Endpoints(), ",")) - } - } - - if debug { - fmt.Fprintf(os.Stderr, "Cluster-Endpoints: %s\n", strings.Join(hc.Endpoints(), ", ")) - } - - return hc -} - -func isConnectionError(err error) bool { - switch t := err.(type) { - case *client.ClusterError: - for _, cerr := range t.Errors { - if !isConnectionError(cerr) { - return false - } - } - return true - case *net.OpError: - if t.Op == "dial" || t.Op == "read" { - return true - } - return isConnectionError(t.Err) - case net.Error: - if t.Timeout() { - return true - } - case syscall.Errno: - if t == syscall.ECONNREFUSED { - return true - } - } - return false -} - -func mustNewClientNoSync(c *cli.Context) client.Client { - hc, err := newClient(c) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - if c.GlobalBool("debug") { - fmt.Fprintf(os.Stderr, "Cluster-Endpoints: %s\n", strings.Join(hc.Endpoints(), ", ")) - client.EnablecURLDebug() - } - - return hc -} - -func newClient(c *cli.Context) (client.Client, error) { - eps, err := getEndpoints(c) - if err != nil { - return nil, err - } - - tr, err := getTransport(c) - if err != nil { - return nil, err - } - - cfg := client.Config{ - Transport: tr, - Endpoints: eps, - HeaderTimeoutPerRequest: c.GlobalDuration("timeout"), - } - - uFlag := c.GlobalString("username") - - if uFlag == "" { - uFlag = os.Getenv("ETCDCTL_USERNAME") - } - - if uFlag != "" { - username, password, err := getUsernamePasswordFromFlag(uFlag) - if err != nil { - return nil, err - } - cfg.Username = username - cfg.Password = password - } - - return client.New(cfg) -} - -func contextWithTotalTimeout(c *cli.Context) (context.Context, context.CancelFunc) { - return context.WithTimeout(context.Background(), c.GlobalDuration("total-timeout")) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/watch_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/watch_command.go deleted file mode 100644 index eac63b04078a..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/command/watch_command.go +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "errors" - "fmt" - "os" - "os/signal" - - "github.com/coreos/etcd/client" - - "github.com/urfave/cli" -) - -// NewWatchCommand returns the CLI command for "watch". -func NewWatchCommand() cli.Command { - return cli.Command{ - Name: "watch", - Usage: "watch a key for changes", - ArgsUsage: "", - Flags: []cli.Flag{ - cli.BoolFlag{Name: "forever, f", Usage: "forever watch a key until CTRL+C"}, - cli.IntFlag{Name: "after-index", Value: 0, Usage: "watch after the given index"}, - cli.BoolFlag{Name: "recursive, r", Usage: "returns all values for key and child keys"}, - }, - Action: func(c *cli.Context) error { - watchCommandFunc(c, mustNewKeyAPI(c)) - return nil - }, - } -} - -// watchCommandFunc executes the "watch" command. -func watchCommandFunc(c *cli.Context, ki client.KeysAPI) { - if len(c.Args()) == 0 { - handleError(c, ExitBadArgs, errors.New("key required")) - } - key := c.Args()[0] - recursive := c.Bool("recursive") - forever := c.Bool("forever") - index := c.Int("after-index") - - stop := false - w := ki.Watcher(key, &client.WatcherOptions{AfterIndex: uint64(index), Recursive: recursive}) - - sigch := make(chan os.Signal, 1) - signal.Notify(sigch, os.Interrupt) - - go func() { - <-sigch - os.Exit(0) - }() - - for !stop { - resp, err := w.Next(context.TODO()) - if err != nil { - handleError(c, ExitServerError, err) - } - if resp.Node.Dir { - continue - } - if recursive { - fmt.Printf("[%s] %s\n", resp.Action, resp.Node.Key) - } - - printResponseKey(resp, c.GlobalString("output")) - - if !forever { - stop = true - } - } -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/ctl.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/ctl.go deleted file mode 100644 index e949b06f09ca..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/ctl.go +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package ctlv2 contains the main entry point for the etcdctl for v2 API. -package ctlv2 - -import ( - "fmt" - "os" - "time" - - "github.com/coreos/etcd/etcdctl/ctlv2/command" - "github.com/coreos/etcd/version" - "github.com/urfave/cli" -) - -func Start(apiv string) { - app := cli.NewApp() - app.Name = "etcdctl" - app.Version = version.Version - cli.VersionPrinter = func(c *cli.Context) { - fmt.Fprintf(c.App.Writer, "etcdctl version: %v\n", c.App.Version) - fmt.Fprintln(c.App.Writer, "API version: 2") - } - app.Usage = "A simple command line client for etcd." - - if apiv == "" { - app.Usage += "\n\n" + - "WARNING:\n" + - " Environment variable ETCDCTL_API is not set; defaults to etcdctl v2.\n" + - " Set environment variable ETCDCTL_API=3 to use v3 API or ETCDCTL_API=2 to use v2 API." - } - - app.Flags = []cli.Flag{ - cli.BoolFlag{Name: "debug", Usage: "output cURL commands which can be used to reproduce the request"}, - cli.BoolFlag{Name: "no-sync", Usage: "don't synchronize cluster information before sending request"}, - cli.StringFlag{Name: "output, o", Value: "simple", Usage: "output response in the given format (`simple`, `extended` or `json`)"}, - cli.StringFlag{Name: "discovery-srv, D", Usage: "domain name to query for SRV records describing cluster endpoints"}, - cli.BoolFlag{Name: "insecure-discovery", Usage: "accept insecure SRV records describing cluster endpoints"}, - cli.StringFlag{Name: "peers, C", Value: "", Usage: "DEPRECATED - \"--endpoints\" should be used instead"}, - cli.StringFlag{Name: "endpoint", Value: "", Usage: "DEPRECATED - \"--endpoints\" should be used instead"}, - cli.StringFlag{Name: "endpoints", Value: "", Usage: "a comma-delimited list of machine addresses in the cluster (default: \"http://127.0.0.1:2379,http://127.0.0.1:4001\")"}, - cli.StringFlag{Name: "cert-file", Value: "", Usage: "identify HTTPS client using this SSL certificate file"}, - cli.StringFlag{Name: "key-file", Value: "", Usage: "identify HTTPS client using this SSL key file"}, - cli.StringFlag{Name: "ca-file", Value: "", Usage: "verify certificates of HTTPS-enabled servers using this CA bundle"}, - cli.StringFlag{Name: "username, u", Value: "", Usage: "provide username[:password] and prompt if password is not supplied."}, - cli.DurationFlag{Name: "timeout", Value: 2 * time.Second, Usage: "connection timeout per request"}, - cli.DurationFlag{Name: "total-timeout", Value: 5 * time.Second, Usage: "timeout for the command execution (except watch)"}, - } - app.Commands = []cli.Command{ - command.NewBackupCommand(), - command.NewClusterHealthCommand(), - command.NewMakeCommand(), - command.NewMakeDirCommand(), - command.NewRemoveCommand(), - command.NewRemoveDirCommand(), - command.NewGetCommand(), - command.NewLsCommand(), - command.NewSetCommand(), - command.NewSetDirCommand(), - command.NewUpdateCommand(), - command.NewUpdateDirCommand(), - command.NewWatchCommand(), - command.NewExecWatchCommand(), - command.NewMemberCommand(), - command.NewUserCommands(), - command.NewRoleCommands(), - command.NewAuthCommands(), - } - - err := runCtlV2(app) - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/ctl_cov.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/ctl_cov.go deleted file mode 100644 index e9f22f25d848..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/ctl_cov.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build cov - -package ctlv2 - -import ( - "os" - "strings" - - "github.com/urfave/cli" -) - -func runCtlV2(app *cli.App) error { - return app.Run(strings.Split(os.Getenv("ETCDCTL_ARGS"), "\xe7\xcd")) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/ctl_nocov.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv2/ctl_nocov.go deleted file mode 100644 index 1591360e58a4..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv2/ctl_nocov.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !cov - -package ctlv2 - -import ( - "os" - - "github.com/urfave/cli" -) - -func runCtlV2(app *cli.App) error { - return app.Run(os.Args) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/alarm_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/alarm_command.go deleted file mode 100644 index 2befbc2aa064..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/alarm_command.go +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - - v3 "github.com/coreos/etcd/clientv3" - "github.com/spf13/cobra" -) - -// NewAlarmCommand returns the cobra command for "alarm". -func NewAlarmCommand() *cobra.Command { - ac := &cobra.Command{ - Use: "alarm ", - Short: "Alarm related commands", - } - - ac.AddCommand(NewAlarmDisarmCommand()) - ac.AddCommand(NewAlarmListCommand()) - - return ac -} - -func NewAlarmDisarmCommand() *cobra.Command { - cmd := cobra.Command{ - Use: "disarm", - Short: "Disarms all alarms", - Run: alarmDisarmCommandFunc, - } - return &cmd -} - -// alarmDisarmCommandFunc executes the "alarm disarm" command. -func alarmDisarmCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("alarm disarm command accepts no arguments")) - } - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).AlarmDisarm(ctx, &v3.AlarmMember{}) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - display.Alarm(*resp) -} - -func NewAlarmListCommand() *cobra.Command { - cmd := cobra.Command{ - Use: "list", - Short: "Lists all alarms", - Run: alarmListCommandFunc, - } - return &cmd -} - -// alarmListCommandFunc executes the "alarm list" command. -func alarmListCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("alarm list command accepts no arguments")) - } - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).AlarmList(ctx) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - display.Alarm(*resp) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/auth_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/auth_command.go deleted file mode 100644 index f9a909049728..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/auth_command.go +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - "github.com/spf13/cobra" -) - -// NewAuthCommand returns the cobra command for "auth". -func NewAuthCommand() *cobra.Command { - ac := &cobra.Command{ - Use: "auth ", - Short: "Enable or disable authentication", - } - - ac.AddCommand(newAuthEnableCommand()) - ac.AddCommand(newAuthDisableCommand()) - - return ac -} - -func newAuthEnableCommand() *cobra.Command { - return &cobra.Command{ - Use: "enable", - Short: "Enables authentication", - Run: authEnableCommandFunc, - } -} - -// authEnableCommandFunc executes the "auth enable" command. -func authEnableCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("auth enable command does not accept any arguments.")) - } - - ctx, cancel := commandCtx(cmd) - cli := mustClientFromCmd(cmd) - var err error - for err == nil { - if _, err = cli.AuthEnable(ctx); err == nil { - break - } - if err == rpctypes.ErrRootRoleNotExist { - if _, err = cli.RoleAdd(ctx, "root"); err != nil { - break - } - if _, err = cli.UserGrantRole(ctx, "root", "root"); err != nil { - break - } - } - } - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - - fmt.Println("Authentication Enabled") -} - -func newAuthDisableCommand() *cobra.Command { - return &cobra.Command{ - Use: "disable", - Short: "Disables authentication", - Run: authDisableCommandFunc, - } -} - -// authDisableCommandFunc executes the "auth disable" command. -func authDisableCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("auth disable command does not accept any arguments.")) - } - - ctx, cancel := commandCtx(cmd) - _, err := mustClientFromCmd(cmd).Auth.AuthDisable(ctx) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - - fmt.Println("Authentication Disabled") -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/check.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/check.go deleted file mode 100644 index 2ad568217a07..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/check.go +++ /dev/null @@ -1,218 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "encoding/binary" - "fmt" - "math" - "math/rand" - "os" - "sync" - "time" - - v3 "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/pkg/report" - - "github.com/spf13/cobra" - "golang.org/x/time/rate" - "gopkg.in/cheggaaa/pb.v1" -) - -var ( - checkPerfLoad string - checkPerfPrefix string -) - -type checkPerfCfg struct { - limit int - clients int - duration int -} - -var checkPerfCfgMap = map[string]checkPerfCfg{ - // TODO: support read limit - "s": { - limit: 150, - clients: 50, - duration: 60, - }, - "m": { - limit: 1000, - clients: 200, - duration: 60, - }, - "l": { - limit: 8000, - clients: 500, - duration: 60, - }, - "xl": { - limit: 15000, - clients: 1000, - duration: 60, - }, -} - -// NewCheckCommand returns the cobra command for "check". -func NewCheckCommand() *cobra.Command { - cc := &cobra.Command{ - Use: "check ", - Short: "commands for checking properties of the etcd cluster", - } - - cc.AddCommand(NewCheckPerfCommand()) - - return cc -} - -// NewCheckPerfCommand returns the cobra command for "check perf". -func NewCheckPerfCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "perf [options]", - Short: "Check the performance of the etcd cluster", - Run: newCheckPerfCommand, - } - - // TODO: support customized configuration - cmd.Flags().StringVar(&checkPerfLoad, "load", "s", "The performance check's workload model. Accepted workloads: s(small), m(medium), l(large), xl(xLarge)") - cmd.Flags().StringVar(&checkPerfPrefix, "prefix", "/etcdctl-check-perf/", "The prefix for writing the performance check's keys.") - - return cmd -} - -// newCheckPerfCommand executes the "check perf" command. -func newCheckPerfCommand(cmd *cobra.Command, args []string) { - var checkPerfAlias = map[string]string{ - "s": "s", "small": "s", - "m": "m", "medium": "m", - "l": "l", "large": "l", - "xl": "xl", "xLarge": "xl", - } - - model, ok := checkPerfAlias[checkPerfLoad] - if !ok { - ExitWithError(ExitBadFeature, fmt.Errorf("unknown load option %v", checkPerfLoad)) - } - cfg := checkPerfCfgMap[model] - - requests := make(chan v3.Op, cfg.clients) - limit := rate.NewLimiter(rate.Limit(cfg.limit), 1) - - cc := clientConfigFromCmd(cmd) - clients := make([]*v3.Client, cfg.clients) - for i := 0; i < cfg.clients; i++ { - clients[i] = cc.mustClient() - } - - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(cfg.duration)*time.Second) - resp, err := clients[0].Get(ctx, checkPerfPrefix, v3.WithPrefix(), v3.WithLimit(1)) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - if len(resp.Kvs) > 0 { - ExitWithError(ExitInvalidInput, fmt.Errorf("prefix %q has keys. Delete with etcdctl del --prefix %s first.", checkPerfPrefix, checkPerfPrefix)) - } - - ksize, vsize := 256, 1024 - k, v := make([]byte, ksize), string(make([]byte, vsize)) - - bar := pb.New(cfg.duration) - bar.Format("Bom !") - bar.Start() - - r := report.NewReport("%4.4f") - var wg sync.WaitGroup - - wg.Add(len(clients)) - for i := range clients { - go func(c *v3.Client) { - defer wg.Done() - for op := range requests { - st := time.Now() - _, derr := c.Do(context.Background(), op) - r.Results() <- report.Result{Err: derr, Start: st, End: time.Now()} - } - }(clients[i]) - } - - go func() { - cctx, ccancel := context.WithTimeout(context.Background(), time.Duration(cfg.duration)*time.Second) - defer ccancel() - for limit.Wait(cctx) == nil { - binary.PutVarint(k, int64(rand.Int63n(math.MaxInt64))) - requests <- v3.OpPut(checkPerfPrefix+string(k), v) - } - close(requests) - }() - - go func() { - for i := 0; i < cfg.duration; i++ { - time.Sleep(time.Second) - bar.Add(1) - } - bar.Finish() - }() - - sc := r.Stats() - wg.Wait() - close(r.Results()) - - s := <-sc - - ctx, cancel = context.WithTimeout(context.Background(), 30*time.Second) - _, err = clients[0].Delete(ctx, checkPerfPrefix, v3.WithPrefix()) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - - ok = true - if len(s.ErrorDist) != 0 { - fmt.Println("FAIL: too many errors") - for k, v := range s.ErrorDist { - fmt.Printf("FAIL: ERROR(%v) -> %d\n", k, v) - } - ok = false - } - - if s.RPS/float64(cfg.limit) <= 0.9 { - fmt.Printf("FAIL: Throughput too low: %d writes/s\n", int(s.RPS)+1) - ok = false - } else { - fmt.Printf("PASS: Throughput is %d writes/s\n", int(s.RPS)+1) - } - if s.Slowest > 0.5 { // slowest request > 500ms - fmt.Printf("Slowest request took too long: %fs\n", s.Slowest) - ok = false - } else { - fmt.Printf("PASS: Slowest request took %fs\n", s.Slowest) - } - if s.Stddev > 0.1 { // stddev > 100ms - fmt.Printf("Stddev too high: %fs\n", s.Stddev) - ok = false - } else { - fmt.Printf("PASS: Stddev is %fs\n", s.Stddev) - } - - if ok { - fmt.Println("PASS") - } else { - fmt.Println("FAIL") - os.Exit(ExitError) - } -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/compaction_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/compaction_command.go deleted file mode 100644 index 59e8990fb70a..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/compaction_command.go +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "strconv" - - "github.com/coreos/etcd/clientv3" - "github.com/spf13/cobra" -) - -var compactPhysical bool - -// NewCompactionCommand returns the cobra command for "compaction". -func NewCompactionCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "compaction [options] ", - Short: "Compacts the event history in etcd", - Run: compactionCommandFunc, - } - cmd.Flags().BoolVar(&compactPhysical, "physical", false, "'true' to wait for compaction to physically remove all old revisions") - return cmd -} - -// compactionCommandFunc executes the "compaction" command. -func compactionCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("compaction command needs 1 argument.")) - } - - rev, err := strconv.ParseInt(args[0], 10, 64) - if err != nil { - ExitWithError(ExitError, err) - } - - var opts []clientv3.CompactOption - if compactPhysical { - opts = append(opts, clientv3.WithCompactPhysical()) - } - - c := mustClientFromCmd(cmd) - ctx, cancel := commandCtx(cmd) - _, cerr := c.Compact(ctx, rev, opts...) - cancel() - if cerr != nil { - ExitWithError(ExitError, cerr) - } - fmt.Println("compacted revision", rev) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/defrag_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/defrag_command.go deleted file mode 100644 index a7e6f76f3cad..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/defrag_command.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "os" - "path/filepath" - "time" - - "github.com/coreos/etcd/mvcc/backend" - "github.com/spf13/cobra" -) - -var ( - defragDataDir string -) - -// NewDefragCommand returns the cobra command for "Defrag". -func NewDefragCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "defrag", - Short: "Defragments the storage of the etcd members with given endpoints", - Run: defragCommandFunc, - } - cmd.Flags().StringVar(&defragDataDir, "data-dir", "", "Optional. If present, defragments a data directory not in use by etcd.") - return cmd -} - -func defragCommandFunc(cmd *cobra.Command, args []string) { - if len(defragDataDir) > 0 { - err := defragData(defragDataDir) - if err != nil { - fmt.Fprintf(os.Stderr, "Failed to defragment etcd data[%s] (%v)\n", defragDataDir, err) - os.Exit(ExitError) - } - return - } - - failures := 0 - c := mustClientFromCmd(cmd) - for _, ep := range c.Endpoints() { - ctx, cancel := commandCtx(cmd) - _, err := c.Defragment(ctx, ep) - cancel() - if err != nil { - fmt.Fprintf(os.Stderr, "Failed to defragment etcd member[%s] (%v)\n", ep, err) - failures++ - } else { - fmt.Printf("Finished defragmenting etcd member[%s]\n", ep) - } - } - - if failures != 0 { - os.Exit(ExitError) - } -} - -func defragData(dataDir string) error { - var be backend.Backend - - bch := make(chan struct{}) - dbDir := filepath.Join(dataDir, "member", "snap", "db") - go func() { - defer close(bch) - be = backend.NewDefaultBackend(dbDir) - - }() - select { - case <-bch: - case <-time.After(time.Second): - fmt.Fprintf(os.Stderr, "waiting for etcd to close and release its lock on %q. "+ - "To defrag a running etcd instance, omit --data-dir.\n", dbDir) - <-bch - } - return be.Defrag() -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/del_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/del_command.go deleted file mode 100644 index bb0663024aa3..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/del_command.go +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - - "github.com/coreos/etcd/clientv3" - "github.com/spf13/cobra" -) - -var ( - delPrefix bool - delPrevKV bool - delFromKey bool -) - -// NewDelCommand returns the cobra command for "del". -func NewDelCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "del [options] [range_end]", - Short: "Removes the specified key or range of keys [key, range_end)", - Run: delCommandFunc, - } - - cmd.Flags().BoolVar(&delPrefix, "prefix", false, "delete keys with matching prefix") - cmd.Flags().BoolVar(&delPrevKV, "prev-kv", false, "return deleted key-value pairs") - cmd.Flags().BoolVar(&delFromKey, "from-key", false, "delete keys that are greater than or equal to the given key using byte compare") - return cmd -} - -// delCommandFunc executes the "del" command. -func delCommandFunc(cmd *cobra.Command, args []string) { - key, opts := getDelOp(cmd, args) - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).Delete(ctx, key, opts...) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - display.Del(*resp) -} - -func getDelOp(cmd *cobra.Command, args []string) (string, []clientv3.OpOption) { - if len(args) == 0 || len(args) > 2 { - ExitWithError(ExitBadArgs, fmt.Errorf("del command needs one argument as key and an optional argument as range_end.")) - } - - if delPrefix && delFromKey { - ExitWithError(ExitBadArgs, fmt.Errorf("`--prefix` and `--from-key` cannot be set at the same time, choose one.")) - } - - opts := []clientv3.OpOption{} - key := args[0] - if len(args) > 1 { - if delPrefix || delFromKey { - ExitWithError(ExitBadArgs, fmt.Errorf("too many arguments, only accept one argument when `--prefix` or `--from-key` is set.")) - } - opts = append(opts, clientv3.WithRange(args[1])) - } - - if delPrefix { - if len(key) == 0 { - key = "\x00" - opts = append(opts, clientv3.WithFromKey()) - } else { - opts = append(opts, clientv3.WithPrefix()) - } - } - if delPrevKV { - opts = append(opts, clientv3.WithPrevKV()) - } - - if delFromKey { - if len(key) == 0 { - key = "\x00" - } - opts = append(opts, clientv3.WithFromKey()) - } - - return key, opts -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/doc.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/doc.go deleted file mode 100644 index 2e5636c29daa..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package command is a set of libraries for etcd v3 commands. -package command diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/elect_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/elect_command.go deleted file mode 100644 index ace4f1197b82..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/elect_command.go +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "errors" - "os" - "os/signal" - "syscall" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/concurrency" - - "github.com/spf13/cobra" -) - -var ( - electListen bool -) - -// NewElectCommand returns the cobra command for "elect". -func NewElectCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "elect [proposal]", - Short: "Observes and participates in leader election", - Run: electCommandFunc, - } - cmd.Flags().BoolVarP(&electListen, "listen", "l", false, "observation mode") - return cmd -} - -func electCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 && len(args) != 2 { - ExitWithError(ExitBadArgs, errors.New("elect takes one election name argument and an optional proposal argument.")) - } - c := mustClientFromCmd(cmd) - - var err error - if len(args) == 1 { - if !electListen { - ExitWithError(ExitBadArgs, errors.New("no proposal argument but -l not set")) - } - err = observe(c, args[0]) - } else { - if electListen { - ExitWithError(ExitBadArgs, errors.New("proposal given but -l is set")) - } - err = campaign(c, args[0], args[1]) - } - if err != nil { - ExitWithError(ExitError, err) - } -} - -func observe(c *clientv3.Client, election string) error { - s, err := concurrency.NewSession(c) - if err != nil { - return err - } - e := concurrency.NewElection(s, election) - ctx, cancel := context.WithCancel(context.TODO()) - - donec := make(chan struct{}) - sigc := make(chan os.Signal, 1) - signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM) - go func() { - <-sigc - cancel() - }() - - go func() { - for resp := range e.Observe(ctx) { - display.Get(resp) - } - close(donec) - }() - - <-donec - - select { - case <-ctx.Done(): - default: - return errors.New("elect: observer lost") - } - - return nil -} - -func campaign(c *clientv3.Client, election string, prop string) error { - s, err := concurrency.NewSession(c) - if err != nil { - return err - } - e := concurrency.NewElection(s, election) - ctx, cancel := context.WithCancel(context.TODO()) - - donec := make(chan struct{}) - sigc := make(chan os.Signal, 1) - signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM) - go func() { - <-sigc - cancel() - close(donec) - }() - - if err = e.Campaign(ctx, prop); err != nil { - return err - } - - // print key since elected - resp, err := c.Get(ctx, e.Key()) - if err != nil { - return err - } - display.Get(*resp) - - select { - case <-donec: - case <-s.Done(): - return errors.New("elect: session expired") - } - - return e.Resign(context.TODO()) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/ep_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/ep_command.go deleted file mode 100644 index 88f0199fec12..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/ep_command.go +++ /dev/null @@ -1,241 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "os" - "sync" - "time" - - v3 "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - "github.com/coreos/etcd/pkg/flags" - - "github.com/spf13/cobra" -) - -var epClusterEndpoints bool -var epHashKVRev int64 - -// NewEndpointCommand returns the cobra command for "endpoint". -func NewEndpointCommand() *cobra.Command { - ec := &cobra.Command{ - Use: "endpoint ", - Short: "Endpoint related commands", - } - - ec.PersistentFlags().BoolVar(&epClusterEndpoints, "cluster", false, "use all endpoints from the cluster member list") - ec.AddCommand(newEpHealthCommand()) - ec.AddCommand(newEpStatusCommand()) - ec.AddCommand(newEpHashKVCommand()) - - return ec -} - -func newEpHealthCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "health", - Short: "Checks the healthiness of endpoints specified in `--endpoints` flag", - Run: epHealthCommandFunc, - } - - return cmd -} - -func newEpStatusCommand() *cobra.Command { - return &cobra.Command{ - Use: "status", - Short: "Prints out the status of endpoints specified in `--endpoints` flag", - Long: `When --write-out is set to simple, this command prints out comma-separated status lists for each endpoint. -The items in the lists are endpoint, ID, version, db size, is leader, raft term, raft index. -`, - Run: epStatusCommandFunc, - } -} - -func newEpHashKVCommand() *cobra.Command { - hc := &cobra.Command{ - Use: "hashkv", - Short: "Prints the KV history hash for each endpoint in --endpoints", - Run: epHashKVCommandFunc, - } - hc.PersistentFlags().Int64Var(&epHashKVRev, "rev", 0, "maximum revision to hash (default: all revisions)") - return hc -} - -// epHealthCommandFunc executes the "endpoint-health" command. -func epHealthCommandFunc(cmd *cobra.Command, args []string) { - flags.SetPflagsFromEnv("ETCDCTL", cmd.InheritedFlags()) - - sec := secureCfgFromCmd(cmd) - dt := dialTimeoutFromCmd(cmd) - ka := keepAliveTimeFromCmd(cmd) - kat := keepAliveTimeoutFromCmd(cmd) - auth := authCfgFromCmd(cmd) - cfgs := []*v3.Config{} - for _, ep := range endpointsFromCluster(cmd) { - cfg, err := newClientCfg([]string{ep}, dt, ka, kat, sec, auth) - if err != nil { - ExitWithError(ExitBadArgs, err) - } - cfgs = append(cfgs, cfg) - } - - var wg sync.WaitGroup - errc := make(chan error, len(cfgs)) - for _, cfg := range cfgs { - wg.Add(1) - go func(cfg *v3.Config) { - defer wg.Done() - ep := cfg.Endpoints[0] - cli, err := v3.New(*cfg) - if err != nil { - errc <- fmt.Errorf("%s is unhealthy: failed to connect: %v", ep, err) - return - } - st := time.Now() - // get a random key. As long as we can get the response without an error, the - // endpoint is health. - ctx, cancel := commandCtx(cmd) - _, err = cli.Get(ctx, "health") - cancel() - // permission denied is OK since proposal goes through consensus to get it - if err == nil || err == rpctypes.ErrPermissionDenied { - fmt.Printf("%s is healthy: successfully committed proposal: took = %v\n", ep, time.Since(st)) - } else { - errc <- fmt.Errorf("%s is unhealthy: failed to commit proposal: %v", ep, err) - } - }(cfg) - } - - wg.Wait() - close(errc) - - errs := false - for err := range errc { - if err != nil { - errs = true - fmt.Fprintln(os.Stderr, err) - } - } - if errs { - ExitWithError(ExitError, fmt.Errorf("unhealthy cluster")) - } -} - -type epStatus struct { - Ep string `json:"Endpoint"` - Resp *v3.StatusResponse `json:"Status"` -} - -func epStatusCommandFunc(cmd *cobra.Command, args []string) { - c := mustClientFromCmd(cmd) - - statusList := []epStatus{} - var err error - for _, ep := range endpointsFromCluster(cmd) { - ctx, cancel := commandCtx(cmd) - resp, serr := c.Status(ctx, ep) - cancel() - if serr != nil { - err = serr - fmt.Fprintf(os.Stderr, "Failed to get the status of endpoint %s (%v)\n", ep, serr) - continue - } - statusList = append(statusList, epStatus{Ep: ep, Resp: resp}) - } - - display.EndpointStatus(statusList) - - if err != nil { - os.Exit(ExitError) - } -} - -type epHashKV struct { - Ep string `json:"Endpoint"` - Resp *v3.HashKVResponse `json:"HashKV"` -} - -func epHashKVCommandFunc(cmd *cobra.Command, args []string) { - c := mustClientFromCmd(cmd) - - hashList := []epHashKV{} - var err error - for _, ep := range endpointsFromCluster(cmd) { - ctx, cancel := commandCtx(cmd) - resp, serr := c.HashKV(ctx, ep, epHashKVRev) - cancel() - if serr != nil { - err = serr - fmt.Fprintf(os.Stderr, "Failed to get the hash of endpoint %s (%v)\n", ep, serr) - continue - } - hashList = append(hashList, epHashKV{Ep: ep, Resp: resp}) - } - - display.EndpointHashKV(hashList) - - if err != nil { - ExitWithError(ExitError, err) - } -} - -func endpointsFromCluster(cmd *cobra.Command) []string { - if !epClusterEndpoints { - endpoints, err := cmd.Flags().GetStringSlice("endpoints") - if err != nil { - ExitWithError(ExitError, err) - } - return endpoints - } - - sec := secureCfgFromCmd(cmd) - dt := dialTimeoutFromCmd(cmd) - ka := keepAliveTimeFromCmd(cmd) - kat := keepAliveTimeoutFromCmd(cmd) - eps, err := endpointsFromCmd(cmd) - if err != nil { - ExitWithError(ExitError, err) - } - // exclude auth for not asking needless password (MemberList() doesn't need authentication) - - cfg, err := newClientCfg(eps, dt, ka, kat, sec, nil) - if err != nil { - ExitWithError(ExitError, err) - } - c, err := v3.New(*cfg) - if err != nil { - ExitWithError(ExitError, err) - } - - ctx, cancel := commandCtx(cmd) - defer func() { - c.Close() - cancel() - }() - membs, err := c.MemberList(ctx) - if err != nil { - err = fmt.Errorf("failed to fetch endpoints from etcd cluster member list: %v", err) - ExitWithError(ExitError, err) - } - - ret := []string{} - for _, m := range membs.Members { - ret = append(ret, m.ClientURLs...) - } - return ret -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/error.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/error.go deleted file mode 100644 index 314b07f0525e..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/error.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "os" - - "github.com/coreos/etcd/client" -) - -const ( - // http://tldp.org/LDP/abs/html/exitcodes.html - ExitSuccess = iota - ExitError - ExitBadConnection - ExitInvalidInput // for txn, watch command - ExitBadFeature // provided a valid flag with an unsupported value - ExitInterrupted - ExitIO - ExitBadArgs = 128 -) - -func ExitWithError(code int, err error) { - fmt.Fprintln(os.Stderr, "Error:", err) - if cerr, ok := err.(*client.ClusterError); ok { - fmt.Fprintln(os.Stderr, cerr.Detail()) - } - os.Exit(code) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/get_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/get_command.go deleted file mode 100644 index 5f9c74f3c552..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/get_command.go +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "strings" - - "github.com/coreos/etcd/clientv3" - "github.com/spf13/cobra" -) - -var ( - getConsistency string - getLimit int64 - getSortOrder string - getSortTarget string - getPrefix bool - getFromKey bool - getRev int64 - getKeysOnly bool - printValueOnly bool -) - -// NewGetCommand returns the cobra command for "get". -func NewGetCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "get [options] [range_end]", - Short: "Gets the key or a range of keys", - Run: getCommandFunc, - } - - cmd.Flags().StringVar(&getConsistency, "consistency", "l", "Linearizable(l) or Serializable(s)") - cmd.Flags().StringVar(&getSortOrder, "order", "", "Order of results; ASCEND or DESCEND (ASCEND by default)") - cmd.Flags().StringVar(&getSortTarget, "sort-by", "", "Sort target; CREATE, KEY, MODIFY, VALUE, or VERSION") - cmd.Flags().Int64Var(&getLimit, "limit", 0, "Maximum number of results") - cmd.Flags().BoolVar(&getPrefix, "prefix", false, "Get keys with matching prefix") - cmd.Flags().BoolVar(&getFromKey, "from-key", false, "Get keys that are greater than or equal to the given key using byte compare") - cmd.Flags().Int64Var(&getRev, "rev", 0, "Specify the kv revision") - cmd.Flags().BoolVar(&getKeysOnly, "keys-only", false, "Get only the keys") - cmd.Flags().BoolVar(&printValueOnly, "print-value-only", false, `Only write values when using the "simple" output format`) - return cmd -} - -// getCommandFunc executes the "get" command. -func getCommandFunc(cmd *cobra.Command, args []string) { - key, opts := getGetOp(cmd, args) - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).Get(ctx, key, opts...) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - - if printValueOnly { - dp, simple := (display).(*simplePrinter) - if !simple { - ExitWithError(ExitBadArgs, fmt.Errorf("print-value-only is only for `--write-out=simple`.")) - } - dp.valueOnly = true - } - display.Get(*resp) -} - -func getGetOp(cmd *cobra.Command, args []string) (string, []clientv3.OpOption) { - if len(args) == 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("range command needs arguments.")) - } - - if getPrefix && getFromKey { - ExitWithError(ExitBadArgs, fmt.Errorf("`--prefix` and `--from-key` cannot be set at the same time, choose one.")) - } - - opts := []clientv3.OpOption{} - switch getConsistency { - case "s": - opts = append(opts, clientv3.WithSerializable()) - case "l": - default: - ExitWithError(ExitBadFeature, fmt.Errorf("unknown consistency flag %q", getConsistency)) - } - - key := args[0] - if len(args) > 1 { - if getPrefix || getFromKey { - ExitWithError(ExitBadArgs, fmt.Errorf("too many arguments, only accept one argument when `--prefix` or `--from-key` is set.")) - } - opts = append(opts, clientv3.WithRange(args[1])) - } - - opts = append(opts, clientv3.WithLimit(getLimit)) - if getRev > 0 { - opts = append(opts, clientv3.WithRev(getRev)) - } - - sortByOrder := clientv3.SortNone - sortOrder := strings.ToUpper(getSortOrder) - switch { - case sortOrder == "ASCEND": - sortByOrder = clientv3.SortAscend - case sortOrder == "DESCEND": - sortByOrder = clientv3.SortDescend - case sortOrder == "": - // nothing - default: - ExitWithError(ExitBadFeature, fmt.Errorf("bad sort order %v", getSortOrder)) - } - - sortByTarget := clientv3.SortByKey - sortTarget := strings.ToUpper(getSortTarget) - switch { - case sortTarget == "CREATE": - sortByTarget = clientv3.SortByCreateRevision - case sortTarget == "KEY": - sortByTarget = clientv3.SortByKey - case sortTarget == "MODIFY": - sortByTarget = clientv3.SortByModRevision - case sortTarget == "VALUE": - sortByTarget = clientv3.SortByValue - case sortTarget == "VERSION": - sortByTarget = clientv3.SortByVersion - case sortTarget == "": - // nothing - default: - ExitWithError(ExitBadFeature, fmt.Errorf("bad sort target %v", getSortTarget)) - } - - opts = append(opts, clientv3.WithSort(sortByTarget, sortByOrder)) - - if getPrefix { - if len(key) == 0 { - key = "\x00" - opts = append(opts, clientv3.WithFromKey()) - } else { - opts = append(opts, clientv3.WithPrefix()) - } - } - - if getFromKey { - if len(key) == 0 { - key = "\x00" - } - opts = append(opts, clientv3.WithFromKey()) - } - - if getKeysOnly { - opts = append(opts, clientv3.WithKeysOnly()) - } - - return key, opts -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/global.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/global.go deleted file mode 100644 index c20c940f02ce..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/global.go +++ /dev/null @@ -1,412 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "crypto/tls" - "errors" - "fmt" - "io" - "io/ioutil" - "os" - "strings" - "time" - - "github.com/bgentry/speakeasy" - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/pkg/flags" - "github.com/coreos/etcd/pkg/srv" - "github.com/coreos/etcd/pkg/transport" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "google.golang.org/grpc/grpclog" -) - -// GlobalFlags are flags that defined globally -// and are inherited to all sub-commands. -type GlobalFlags struct { - Insecure bool - InsecureSkipVerify bool - InsecureDiscovery bool - Endpoints []string - DialTimeout time.Duration - CommandTimeOut time.Duration - KeepAliveTime time.Duration - KeepAliveTimeout time.Duration - - TLS transport.TLSInfo - - OutputFormat string - IsHex bool - - User string - - Debug bool -} - -type secureCfg struct { - cert string - key string - cacert string - serverName string - - insecureTransport bool - insecureSkipVerify bool -} - -type authCfg struct { - username string - password string -} - -type discoveryCfg struct { - domain string - insecure bool -} - -var display printer = &simplePrinter{} - -func initDisplayFromCmd(cmd *cobra.Command) { - isHex, err := cmd.Flags().GetBool("hex") - if err != nil { - ExitWithError(ExitError, err) - } - outputType, err := cmd.Flags().GetString("write-out") - if err != nil { - ExitWithError(ExitError, err) - } - if display = NewPrinter(outputType, isHex); display == nil { - ExitWithError(ExitBadFeature, errors.New("unsupported output format")) - } -} - -type clientConfig struct { - endpoints []string - dialTimeout time.Duration - keepAliveTime time.Duration - keepAliveTimeout time.Duration - scfg *secureCfg - acfg *authCfg -} - -type discardValue struct{} - -func (*discardValue) String() string { return "" } -func (*discardValue) Set(string) error { return nil } -func (*discardValue) Type() string { return "" } - -func clientConfigFromCmd(cmd *cobra.Command) *clientConfig { - fs := cmd.InheritedFlags() - if strings.HasPrefix(cmd.Use, "watch") { - // silence "pkg/flags: unrecognized environment variable ETCDCTL_WATCH_KEY=foo" warnings - // silence "pkg/flags: unrecognized environment variable ETCDCTL_WATCH_RANGE_END=bar" warnings - fs.AddFlag(&pflag.Flag{Name: "watch-key", Value: &discardValue{}}) - fs.AddFlag(&pflag.Flag{Name: "watch-range-end", Value: &discardValue{}}) - } - flags.SetPflagsFromEnv("ETCDCTL", fs) - - debug, err := cmd.Flags().GetBool("debug") - if err != nil { - ExitWithError(ExitError, err) - } - if debug { - clientv3.SetLogger(grpclog.NewLoggerV2WithVerbosity(os.Stderr, os.Stderr, os.Stderr, 4)) - fs.VisitAll(func(f *pflag.Flag) { - fmt.Fprintf(os.Stderr, "%s=%v\n", flags.FlagToEnv("ETCDCTL", f.Name), f.Value) - }) - } else { - clientv3.SetLogger(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, ioutil.Discard)) - } - - cfg := &clientConfig{} - cfg.endpoints, err = endpointsFromCmd(cmd) - if err != nil { - ExitWithError(ExitError, err) - } - - cfg.dialTimeout = dialTimeoutFromCmd(cmd) - cfg.keepAliveTime = keepAliveTimeFromCmd(cmd) - cfg.keepAliveTimeout = keepAliveTimeoutFromCmd(cmd) - - cfg.scfg = secureCfgFromCmd(cmd) - cfg.acfg = authCfgFromCmd(cmd) - - initDisplayFromCmd(cmd) - return cfg -} - -func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client { - cfg := clientConfigFromCmd(cmd) - return cfg.mustClient() -} - -func (cc *clientConfig) mustClient() *clientv3.Client { - cfg, err := newClientCfg(cc.endpoints, cc.dialTimeout, cc.keepAliveTime, cc.keepAliveTimeout, cc.scfg, cc.acfg) - if err != nil { - ExitWithError(ExitBadArgs, err) - } - - client, err := clientv3.New(*cfg) - if err != nil { - ExitWithError(ExitBadConnection, err) - } - - return client -} - -func newClientCfg(endpoints []string, dialTimeout, keepAliveTime, keepAliveTimeout time.Duration, scfg *secureCfg, acfg *authCfg) (*clientv3.Config, error) { - // set tls if any one tls option set - var cfgtls *transport.TLSInfo - tlsinfo := transport.TLSInfo{} - if scfg.cert != "" { - tlsinfo.CertFile = scfg.cert - cfgtls = &tlsinfo - } - - if scfg.key != "" { - tlsinfo.KeyFile = scfg.key - cfgtls = &tlsinfo - } - - if scfg.cacert != "" { - tlsinfo.CAFile = scfg.cacert - cfgtls = &tlsinfo - } - - if scfg.serverName != "" { - tlsinfo.ServerName = scfg.serverName - cfgtls = &tlsinfo - } - - cfg := &clientv3.Config{ - Endpoints: endpoints, - DialTimeout: dialTimeout, - DialKeepAliveTime: keepAliveTime, - DialKeepAliveTimeout: keepAliveTimeout, - } - - if cfgtls != nil { - clientTLS, err := cfgtls.ClientConfig() - if err != nil { - return nil, err - } - cfg.TLS = clientTLS - } - - // if key/cert is not given but user wants secure connection, we - // should still setup an empty tls configuration for gRPC to setup - // secure connection. - if cfg.TLS == nil && !scfg.insecureTransport { - cfg.TLS = &tls.Config{} - } - - // If the user wants to skip TLS verification then we should set - // the InsecureSkipVerify flag in tls configuration. - if scfg.insecureSkipVerify && cfg.TLS != nil { - cfg.TLS.InsecureSkipVerify = true - } - - if acfg != nil { - cfg.Username = acfg.username - cfg.Password = acfg.password - } - - return cfg, nil -} - -func argOrStdin(args []string, stdin io.Reader, i int) (string, error) { - if i < len(args) { - return args[i], nil - } - bytes, err := ioutil.ReadAll(stdin) - if string(bytes) == "" || err != nil { - return "", errors.New("no available argument and stdin") - } - return string(bytes), nil -} - -func dialTimeoutFromCmd(cmd *cobra.Command) time.Duration { - dialTimeout, err := cmd.Flags().GetDuration("dial-timeout") - if err != nil { - ExitWithError(ExitError, err) - } - return dialTimeout -} - -func keepAliveTimeFromCmd(cmd *cobra.Command) time.Duration { - keepAliveTime, err := cmd.Flags().GetDuration("keepalive-time") - if err != nil { - ExitWithError(ExitError, err) - } - return keepAliveTime -} - -func keepAliveTimeoutFromCmd(cmd *cobra.Command) time.Duration { - keepAliveTimeout, err := cmd.Flags().GetDuration("keepalive-timeout") - if err != nil { - ExitWithError(ExitError, err) - } - return keepAliveTimeout -} - -func secureCfgFromCmd(cmd *cobra.Command) *secureCfg { - cert, key, cacert := keyAndCertFromCmd(cmd) - insecureTr := insecureTransportFromCmd(cmd) - skipVerify := insecureSkipVerifyFromCmd(cmd) - discoveryCfg := discoveryCfgFromCmd(cmd) - - if discoveryCfg.insecure { - discoveryCfg.domain = "" - } - - return &secureCfg{ - cert: cert, - key: key, - cacert: cacert, - serverName: discoveryCfg.domain, - - insecureTransport: insecureTr, - insecureSkipVerify: skipVerify, - } -} - -func insecureTransportFromCmd(cmd *cobra.Command) bool { - insecureTr, err := cmd.Flags().GetBool("insecure-transport") - if err != nil { - ExitWithError(ExitError, err) - } - return insecureTr -} - -func insecureSkipVerifyFromCmd(cmd *cobra.Command) bool { - skipVerify, err := cmd.Flags().GetBool("insecure-skip-tls-verify") - if err != nil { - ExitWithError(ExitError, err) - } - return skipVerify -} - -func keyAndCertFromCmd(cmd *cobra.Command) (cert, key, cacert string) { - var err error - if cert, err = cmd.Flags().GetString("cert"); err != nil { - ExitWithError(ExitBadArgs, err) - } else if cert == "" && cmd.Flags().Changed("cert") { - ExitWithError(ExitBadArgs, errors.New("empty string is passed to --cert option")) - } - - if key, err = cmd.Flags().GetString("key"); err != nil { - ExitWithError(ExitBadArgs, err) - } else if key == "" && cmd.Flags().Changed("key") { - ExitWithError(ExitBadArgs, errors.New("empty string is passed to --key option")) - } - - if cacert, err = cmd.Flags().GetString("cacert"); err != nil { - ExitWithError(ExitBadArgs, err) - } else if cacert == "" && cmd.Flags().Changed("cacert") { - ExitWithError(ExitBadArgs, errors.New("empty string is passed to --cacert option")) - } - - return cert, key, cacert -} - -func authCfgFromCmd(cmd *cobra.Command) *authCfg { - userFlag, err := cmd.Flags().GetString("user") - if err != nil { - ExitWithError(ExitBadArgs, err) - } - - if userFlag == "" { - return nil - } - - var cfg authCfg - - splitted := strings.SplitN(userFlag, ":", 2) - if len(splitted) < 2 { - cfg.username = userFlag - cfg.password, err = speakeasy.Ask("Password: ") - if err != nil { - ExitWithError(ExitError, err) - } - } else { - cfg.username = splitted[0] - cfg.password = splitted[1] - } - - return &cfg -} - -func insecureDiscoveryFromCmd(cmd *cobra.Command) bool { - discovery, err := cmd.Flags().GetBool("insecure-discovery") - if err != nil { - ExitWithError(ExitError, err) - } - return discovery -} - -func discoverySrvFromCmd(cmd *cobra.Command) string { - domainStr, err := cmd.Flags().GetString("discovery-srv") - if err != nil { - ExitWithError(ExitBadArgs, err) - } - return domainStr -} - -func discoveryCfgFromCmd(cmd *cobra.Command) *discoveryCfg { - return &discoveryCfg{ - domain: discoverySrvFromCmd(cmd), - insecure: insecureDiscoveryFromCmd(cmd), - } -} - -func endpointsFromCmd(cmd *cobra.Command) ([]string, error) { - eps, err := endpointsFromFlagValue(cmd) - if err != nil { - return nil, err - } - // If domain discovery returns no endpoints, check endpoints flag - if len(eps) == 0 { - eps, err = cmd.Flags().GetStringSlice("endpoints") - } - return eps, err -} - -func endpointsFromFlagValue(cmd *cobra.Command) ([]string, error) { - discoveryCfg := discoveryCfgFromCmd(cmd) - - // If we still don't have domain discovery, return nothing - if discoveryCfg.domain == "" { - return []string{}, nil - } - - srvs, err := srv.GetClient("etcd-client", discoveryCfg.domain) - if err != nil { - return nil, err - } - eps := srvs.Endpoints - if discoveryCfg.insecure { - return eps, err - } - // strip insecure connections - ret := []string{} - for _, ep := range eps { - if strings.HasPrefix(ep, "http://") { - fmt.Fprintf(os.Stderr, "ignoring discovered insecure endpoint %q\n", ep) - continue - } - ret = append(ret, ep) - } - return ret, err -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/lease_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/lease_command.go deleted file mode 100644 index ecfe3a6fb638..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/lease_command.go +++ /dev/null @@ -1,207 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "fmt" - "strconv" - - v3 "github.com/coreos/etcd/clientv3" - - "github.com/spf13/cobra" -) - -// NewLeaseCommand returns the cobra command for "lease". -func NewLeaseCommand() *cobra.Command { - lc := &cobra.Command{ - Use: "lease ", - Short: "Lease related commands", - } - - lc.AddCommand(NewLeaseGrantCommand()) - lc.AddCommand(NewLeaseRevokeCommand()) - lc.AddCommand(NewLeaseTimeToLiveCommand()) - lc.AddCommand(NewLeaseListCommand()) - lc.AddCommand(NewLeaseKeepAliveCommand()) - - return lc -} - -// NewLeaseGrantCommand returns the cobra command for "lease grant". -func NewLeaseGrantCommand() *cobra.Command { - lc := &cobra.Command{ - Use: "grant ", - Short: "Creates leases", - - Run: leaseGrantCommandFunc, - } - - return lc -} - -// leaseGrantCommandFunc executes the "lease grant" command. -func leaseGrantCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("lease grant command needs TTL argument.")) - } - - ttl, err := strconv.ParseInt(args[0], 10, 64) - if err != nil { - ExitWithError(ExitBadArgs, fmt.Errorf("bad TTL (%v)", err)) - } - - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).Grant(ctx, ttl) - cancel() - if err != nil { - ExitWithError(ExitError, fmt.Errorf("failed to grant lease (%v)\n", err)) - } - display.Grant(*resp) -} - -// NewLeaseRevokeCommand returns the cobra command for "lease revoke". -func NewLeaseRevokeCommand() *cobra.Command { - lc := &cobra.Command{ - Use: "revoke ", - Short: "Revokes leases", - - Run: leaseRevokeCommandFunc, - } - - return lc -} - -// leaseRevokeCommandFunc executes the "lease grant" command. -func leaseRevokeCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("lease revoke command needs 1 argument")) - } - - id := leaseFromArgs(args[0]) - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).Revoke(ctx, id) - cancel() - if err != nil { - ExitWithError(ExitError, fmt.Errorf("failed to revoke lease (%v)\n", err)) - } - display.Revoke(id, *resp) -} - -var timeToLiveKeys bool - -// NewLeaseTimeToLiveCommand returns the cobra command for "lease timetolive". -func NewLeaseTimeToLiveCommand() *cobra.Command { - lc := &cobra.Command{ - Use: "timetolive [options]", - Short: "Get lease information", - - Run: leaseTimeToLiveCommandFunc, - } - lc.Flags().BoolVar(&timeToLiveKeys, "keys", false, "Get keys attached to this lease") - - return lc -} - -// leaseTimeToLiveCommandFunc executes the "lease timetolive" command. -func leaseTimeToLiveCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("lease timetolive command needs lease ID as argument")) - } - var opts []v3.LeaseOption - if timeToLiveKeys { - opts = append(opts, v3.WithAttachedKeys()) - } - resp, rerr := mustClientFromCmd(cmd).TimeToLive(context.TODO(), leaseFromArgs(args[0]), opts...) - if rerr != nil { - ExitWithError(ExitBadConnection, rerr) - } - display.TimeToLive(*resp, timeToLiveKeys) -} - -// NewLeaseListCommand returns the cobra command for "lease list". -func NewLeaseListCommand() *cobra.Command { - lc := &cobra.Command{ - Use: "list", - Short: "List all active leases", - Run: leaseListCommandFunc, - } - return lc -} - -// leaseListCommandFunc executes the "lease list" command. -func leaseListCommandFunc(cmd *cobra.Command, args []string) { - resp, rerr := mustClientFromCmd(cmd).Leases(context.TODO()) - if rerr != nil { - ExitWithError(ExitBadConnection, rerr) - } - display.Leases(*resp) -} - -var ( - leaseKeepAliveOnce bool -) - -// NewLeaseKeepAliveCommand returns the cobra command for "lease keep-alive". -func NewLeaseKeepAliveCommand() *cobra.Command { - lc := &cobra.Command{ - Use: "keep-alive [options] ", - Short: "Keeps leases alive (renew)", - - Run: leaseKeepAliveCommandFunc, - } - - lc.Flags().BoolVar(&leaseKeepAliveOnce, "once", false, "Resets the keep-alive time to its original value and exits immediately") - - return lc -} - -// leaseKeepAliveCommandFunc executes the "lease keep-alive" command. -func leaseKeepAliveCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("lease keep-alive command needs lease ID as argument")) - } - - id := leaseFromArgs(args[0]) - - if leaseKeepAliveOnce { - respc, kerr := mustClientFromCmd(cmd).KeepAliveOnce(context.TODO(), id) - if kerr != nil { - ExitWithError(ExitBadConnection, kerr) - } - display.KeepAlive(*respc) - return - } - - respc, kerr := mustClientFromCmd(cmd).KeepAlive(context.TODO(), id) - if kerr != nil { - ExitWithError(ExitBadConnection, kerr) - } - for resp := range respc { - display.KeepAlive(*resp) - } - - if _, ok := (display).(*simplePrinter); ok { - fmt.Printf("lease %016x expired or revoked.\n", id) - } -} - -func leaseFromArgs(arg string) v3.LeaseID { - id, err := strconv.ParseInt(arg, 16, 64) - if err != nil { - ExitWithError(ExitBadArgs, fmt.Errorf("bad lease ID arg (%v), expecting ID in Hex", err)) - } - return v3.LeaseID(id) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/lock_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/lock_command.go deleted file mode 100644 index 74ebac81e340..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/lock_command.go +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "errors" - "fmt" - "os" - "os/exec" - "os/signal" - "syscall" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/concurrency" - - "github.com/spf13/cobra" -) - -var lockTTL = 10 - -// NewLockCommand returns the cobra command for "lock". -func NewLockCommand() *cobra.Command { - c := &cobra.Command{ - Use: "lock [exec-command arg1 arg2 ...]", - Short: "Acquires a named lock", - Run: lockCommandFunc, - } - c.Flags().IntVarP(&lockTTL, "ttl", "", lockTTL, "timeout for session") - return c -} - -func lockCommandFunc(cmd *cobra.Command, args []string) { - if len(args) == 0 { - ExitWithError(ExitBadArgs, errors.New("lock takes a lock name argument and an optional command to execute.")) - } - c := mustClientFromCmd(cmd) - if err := lockUntilSignal(c, args[0], args[1:]); err != nil { - ExitWithError(ExitError, err) - } -} - -func lockUntilSignal(c *clientv3.Client, lockname string, cmdArgs []string) error { - s, err := concurrency.NewSession(c, concurrency.WithTTL(lockTTL)) - if err != nil { - return err - } - - m := concurrency.NewMutex(s, lockname) - ctx, cancel := context.WithCancel(context.TODO()) - - // unlock in case of ordinary shutdown - donec := make(chan struct{}) - sigc := make(chan os.Signal, 1) - signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM) - go func() { - <-sigc - cancel() - close(donec) - }() - - if err := m.Lock(ctx); err != nil { - return err - } - - if len(cmdArgs) > 0 { - cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...) - cmd.Env = append(environLockResponse(m), os.Environ()...) - cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr - err := cmd.Run() - unlockErr := m.Unlock(context.TODO()) - if err != nil { - return err - } - return unlockErr - } - - k, kerr := c.Get(ctx, m.Key()) - if kerr != nil { - return kerr - } - if len(k.Kvs) == 0 { - return errors.New("lock lost on init") - } - display.Get(*k) - - select { - case <-donec: - return m.Unlock(context.TODO()) - case <-s.Done(): - } - - return errors.New("session expired") -} - -func environLockResponse(m *concurrency.Mutex) []string { - return []string{ - "ETCD_LOCK_KEY=" + m.Key(), - fmt.Sprintf("ETCD_LOCK_REV=%d", m.Header().Revision), - } -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/make_mirror_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/make_mirror_command.go deleted file mode 100644 index 8afa479d49bf..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/make_mirror_command.go +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "errors" - "fmt" - "strings" - "sync/atomic" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/mirror" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - "github.com/coreos/etcd/mvcc/mvccpb" - - "github.com/spf13/cobra" -) - -var ( - mminsecureTr bool - mmcert string - mmkey string - mmcacert string - mmprefix string - mmdestprefix string - mmnodestprefix bool -) - -// NewMakeMirrorCommand returns the cobra command for "makeMirror". -func NewMakeMirrorCommand() *cobra.Command { - c := &cobra.Command{ - Use: "make-mirror [options] ", - Short: "Makes a mirror at the destination etcd cluster", - Run: makeMirrorCommandFunc, - } - - c.Flags().StringVar(&mmprefix, "prefix", "", "Key-value prefix to mirror") - c.Flags().StringVar(&mmdestprefix, "dest-prefix", "", "destination prefix to mirror a prefix to a different prefix in the destination cluster") - c.Flags().BoolVar(&mmnodestprefix, "no-dest-prefix", false, "mirror key-values to the root of the destination cluster") - c.Flags().StringVar(&mmcert, "dest-cert", "", "Identify secure client using this TLS certificate file for the destination cluster") - c.Flags().StringVar(&mmkey, "dest-key", "", "Identify secure client using this TLS key file") - c.Flags().StringVar(&mmcacert, "dest-cacert", "", "Verify certificates of TLS enabled secure servers using this CA bundle") - // TODO: secure by default when etcd enables secure gRPC by default. - c.Flags().BoolVar(&mminsecureTr, "dest-insecure-transport", true, "Disable transport security for client connections") - - return c -} - -func makeMirrorCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, errors.New("make-mirror takes one destination argument.")) - } - - dialTimeout := dialTimeoutFromCmd(cmd) - keepAliveTime := keepAliveTimeFromCmd(cmd) - keepAliveTimeout := keepAliveTimeoutFromCmd(cmd) - sec := &secureCfg{ - cert: mmcert, - key: mmkey, - cacert: mmcacert, - insecureTransport: mminsecureTr, - } - - cc := &clientConfig{ - endpoints: []string{args[0]}, - dialTimeout: dialTimeout, - keepAliveTime: keepAliveTime, - keepAliveTimeout: keepAliveTimeout, - scfg: sec, - acfg: nil, - } - dc := cc.mustClient() - c := mustClientFromCmd(cmd) - - err := makeMirror(context.TODO(), c, dc) - ExitWithError(ExitError, err) -} - -func makeMirror(ctx context.Context, c *clientv3.Client, dc *clientv3.Client) error { - total := int64(0) - - go func() { - for { - time.Sleep(30 * time.Second) - fmt.Println(atomic.LoadInt64(&total)) - } - }() - - s := mirror.NewSyncer(c, mmprefix, 0) - - rc, errc := s.SyncBase(ctx) - - // if destination prefix is specified and remove destination prefix is true return error - if mmnodestprefix && len(mmdestprefix) > 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("`--dest-prefix` and `--no-dest-prefix` cannot be set at the same time, choose one.")) - } - - // if remove destination prefix is false and destination prefix is empty set the value of destination prefix same as prefix - if !mmnodestprefix && len(mmdestprefix) == 0 { - mmdestprefix = mmprefix - } - - for r := range rc { - for _, kv := range r.Kvs { - _, err := dc.Put(ctx, modifyPrefix(string(kv.Key)), string(kv.Value)) - if err != nil { - return err - } - atomic.AddInt64(&total, 1) - } - } - - err := <-errc - if err != nil { - return err - } - - wc := s.SyncUpdates(ctx) - - for wr := range wc { - if wr.CompactRevision != 0 { - return rpctypes.ErrCompacted - } - - var lastRev int64 - ops := []clientv3.Op{} - - for _, ev := range wr.Events { - nextRev := ev.Kv.ModRevision - if lastRev != 0 && nextRev > lastRev { - _, err := dc.Txn(ctx).Then(ops...).Commit() - if err != nil { - return err - } - ops = []clientv3.Op{} - } - lastRev = nextRev - switch ev.Type { - case mvccpb.PUT: - ops = append(ops, clientv3.OpPut(modifyPrefix(string(ev.Kv.Key)), string(ev.Kv.Value))) - atomic.AddInt64(&total, 1) - case mvccpb.DELETE: - ops = append(ops, clientv3.OpDelete(modifyPrefix(string(ev.Kv.Key)))) - atomic.AddInt64(&total, 1) - default: - panic("unexpected event type") - } - } - - if len(ops) != 0 { - _, err := dc.Txn(ctx).Then(ops...).Commit() - if err != nil { - return err - } - } - } - - return nil -} - -func modifyPrefix(key string) string { - return strings.Replace(key, mmprefix, mmdestprefix, 1) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/member_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/member_command.go deleted file mode 100644 index cb4e9d582f9f..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/member_command.go +++ /dev/null @@ -1,217 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "strconv" - "strings" - - "github.com/spf13/cobra" -) - -var memberPeerURLs string - -// NewMemberCommand returns the cobra command for "member". -func NewMemberCommand() *cobra.Command { - mc := &cobra.Command{ - Use: "member ", - Short: "Membership related commands", - } - - mc.AddCommand(NewMemberAddCommand()) - mc.AddCommand(NewMemberRemoveCommand()) - mc.AddCommand(NewMemberUpdateCommand()) - mc.AddCommand(NewMemberListCommand()) - - return mc -} - -// NewMemberAddCommand returns the cobra command for "member add". -func NewMemberAddCommand() *cobra.Command { - cc := &cobra.Command{ - Use: "add [options]", - Short: "Adds a member into the cluster", - - Run: memberAddCommandFunc, - } - - cc.Flags().StringVar(&memberPeerURLs, "peer-urls", "", "comma separated peer URLs for the new member.") - - return cc -} - -// NewMemberRemoveCommand returns the cobra command for "member remove". -func NewMemberRemoveCommand() *cobra.Command { - cc := &cobra.Command{ - Use: "remove ", - Short: "Removes a member from the cluster", - - Run: memberRemoveCommandFunc, - } - - return cc -} - -// NewMemberUpdateCommand returns the cobra command for "member update". -func NewMemberUpdateCommand() *cobra.Command { - cc := &cobra.Command{ - Use: "update [options]", - Short: "Updates a member in the cluster", - - Run: memberUpdateCommandFunc, - } - - cc.Flags().StringVar(&memberPeerURLs, "peer-urls", "", "comma separated peer URLs for the updated member.") - - return cc -} - -// NewMemberListCommand returns the cobra command for "member list". -func NewMemberListCommand() *cobra.Command { - cc := &cobra.Command{ - Use: "list", - Short: "Lists all members in the cluster", - Long: `When --write-out is set to simple, this command prints out comma-separated member lists for each endpoint. -The items in the lists are ID, Status, Name, Peer Addrs, Client Addrs. -`, - - Run: memberListCommandFunc, - } - - return cc -} - -// memberAddCommandFunc executes the "member add" command. -func memberAddCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("member name not provided.")) - } - newMemberName := args[0] - - if len(memberPeerURLs) == 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("member peer urls not provided.")) - } - - urls := strings.Split(memberPeerURLs, ",") - ctx, cancel := commandCtx(cmd) - cli := mustClientFromCmd(cmd) - resp, err := cli.MemberAdd(ctx, urls) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - newID := resp.Member.ID - - display.MemberAdd(*resp) - - if _, ok := (display).(*simplePrinter); ok { - ctx, cancel = commandCtx(cmd) - listResp, err := cli.MemberList(ctx) - // get latest member list; if there's failover new member might have outdated list - for { - if err != nil { - ExitWithError(ExitError, err) - } - if listResp.Header.MemberId == resp.Header.MemberId { - break - } - // quorum get to sync cluster list - gresp, gerr := cli.Get(ctx, "_") - if gerr != nil { - ExitWithError(ExitError, err) - } - resp.Header.MemberId = gresp.Header.MemberId - listResp, err = cli.MemberList(ctx) - } - cancel() - - conf := []string{} - for _, memb := range listResp.Members { - for _, u := range memb.PeerURLs { - n := memb.Name - if memb.ID == newID { - n = newMemberName - } - conf = append(conf, fmt.Sprintf("%s=%s", n, u)) - } - } - - fmt.Print("\n") - fmt.Printf("ETCD_NAME=%q\n", newMemberName) - fmt.Printf("ETCD_INITIAL_CLUSTER=%q\n", strings.Join(conf, ",")) - fmt.Printf("ETCD_INITIAL_ADVERTISE_PEER_URLS=%q\n", memberPeerURLs) - fmt.Printf("ETCD_INITIAL_CLUSTER_STATE=\"existing\"\n") - } -} - -// memberRemoveCommandFunc executes the "member remove" command. -func memberRemoveCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("member ID is not provided")) - } - - id, err := strconv.ParseUint(args[0], 16, 64) - if err != nil { - ExitWithError(ExitBadArgs, fmt.Errorf("bad member ID arg (%v), expecting ID in Hex", err)) - } - - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).MemberRemove(ctx, id) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - display.MemberRemove(id, *resp) -} - -// memberUpdateCommandFunc executes the "member update" command. -func memberUpdateCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("member ID is not provided")) - } - - id, err := strconv.ParseUint(args[0], 16, 64) - if err != nil { - ExitWithError(ExitBadArgs, fmt.Errorf("bad member ID arg (%v), expecting ID in Hex", err)) - } - - if len(memberPeerURLs) == 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("member peer urls not provided.")) - } - - urls := strings.Split(memberPeerURLs, ",") - - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).MemberUpdate(ctx, id, urls) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - - display.MemberUpdate(id, *resp) -} - -// memberListCommandFunc executes the "member list" command. -func memberListCommandFunc(cmd *cobra.Command, args []string) { - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).MemberList(ctx) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - - display.MemberList(*resp) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/migrate_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/migrate_command.go deleted file mode 100644 index 48c17c8ab4a2..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/migrate_command.go +++ /dev/null @@ -1,402 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "encoding/binary" - "encoding/json" - "fmt" - "io" - "os" - "os/exec" - "path/filepath" - "time" - - "github.com/coreos/etcd/client" - etcdErr "github.com/coreos/etcd/error" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/mvcc/mvccpb" - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/snap" - "github.com/coreos/etcd/store" - "github.com/coreos/etcd/wal" - "github.com/coreos/etcd/wal/walpb" - "github.com/gogo/protobuf/proto" - "github.com/spf13/cobra" -) - -var ( - migrateExcludeTTLKey bool - migrateDatadir string - migrateWALdir string - migrateTransformer string -) - -// NewMigrateCommand returns the cobra command for "migrate". -func NewMigrateCommand() *cobra.Command { - mc := &cobra.Command{ - Use: "migrate", - Short: "Migrates keys in a v2 store to a mvcc store", - Run: migrateCommandFunc, - } - - mc.Flags().BoolVar(&migrateExcludeTTLKey, "no-ttl", false, "Do not convert TTL keys") - mc.Flags().StringVar(&migrateDatadir, "data-dir", "", "Path to the data directory") - mc.Flags().StringVar(&migrateWALdir, "wal-dir", "", "Path to the WAL directory") - mc.Flags().StringVar(&migrateTransformer, "transformer", "", "Path to the user-provided transformer program") - return mc -} - -func migrateCommandFunc(cmd *cobra.Command, args []string) { - var ( - writer io.WriteCloser - reader io.ReadCloser - errc chan error - ) - if migrateTransformer != "" { - writer, reader, errc = startTransformer() - } else { - fmt.Println("using default transformer") - writer, reader, errc = defaultTransformer() - } - - st, index := rebuildStoreV2() - be := prepareBackend() - defer be.Close() - - go func() { - writeStore(writer, st) - writer.Close() - }() - - readKeys(reader, be) - mvcc.UpdateConsistentIndex(be, index) - err := <-errc - if err != nil { - fmt.Println("failed to transform keys") - ExitWithError(ExitError, err) - } - - fmt.Println("finished transforming keys") -} - -func prepareBackend() backend.Backend { - var be backend.Backend - - bch := make(chan struct{}) - dbpath := filepath.Join(migrateDatadir, "member", "snap", "db") - go func() { - defer close(bch) - be = backend.NewDefaultBackend(dbpath) - - }() - select { - case <-bch: - case <-time.After(time.Second): - fmt.Fprintf(os.Stderr, "waiting for etcd to close and release its lock on %q\n", dbpath) - <-bch - } - - tx := be.BatchTx() - tx.Lock() - tx.UnsafeCreateBucket([]byte("key")) - tx.UnsafeCreateBucket([]byte("meta")) - tx.Unlock() - return be -} - -func rebuildStoreV2() (store.Store, uint64) { - var index uint64 - cl := membership.NewCluster("") - - waldir := migrateWALdir - if len(waldir) == 0 { - waldir = filepath.Join(migrateDatadir, "member", "wal") - } - snapdir := filepath.Join(migrateDatadir, "member", "snap") - - ss := snap.New(snapdir) - snapshot, err := ss.Load() - if err != nil && err != snap.ErrNoSnapshot { - ExitWithError(ExitError, err) - } - - var walsnap walpb.Snapshot - if snapshot != nil { - walsnap.Index, walsnap.Term = snapshot.Metadata.Index, snapshot.Metadata.Term - index = snapshot.Metadata.Index - } - - w, err := wal.OpenForRead(waldir, walsnap) - if err != nil { - ExitWithError(ExitError, err) - } - defer w.Close() - - _, _, ents, err := w.ReadAll() - if err != nil { - ExitWithError(ExitError, err) - } - - st := store.New() - if snapshot != nil { - err := st.Recovery(snapshot.Data) - if err != nil { - ExitWithError(ExitError, err) - } - } - - cl.SetStore(st) - cl.Recover(api.UpdateCapability) - - applier := etcdserver.NewApplierV2(st, cl) - for _, ent := range ents { - if ent.Type == raftpb.EntryConfChange { - var cc raftpb.ConfChange - pbutil.MustUnmarshal(&cc, ent.Data) - applyConf(cc, cl) - continue - } - - var raftReq pb.InternalRaftRequest - if !pbutil.MaybeUnmarshal(&raftReq, ent.Data) { // backward compatible - var r pb.Request - pbutil.MustUnmarshal(&r, ent.Data) - applyRequest(&r, applier) - } else { - if raftReq.V2 != nil { - req := raftReq.V2 - applyRequest(req, applier) - } - } - if ent.Index > index { - index = ent.Index - } - } - - return st, index -} - -func applyConf(cc raftpb.ConfChange, cl *membership.RaftCluster) { - if err := cl.ValidateConfigurationChange(cc); err != nil { - return - } - switch cc.Type { - case raftpb.ConfChangeAddNode: - m := new(membership.Member) - if err := json.Unmarshal(cc.Context, m); err != nil { - panic(err) - } - cl.AddMember(m) - case raftpb.ConfChangeRemoveNode: - cl.RemoveMember(types.ID(cc.NodeID)) - case raftpb.ConfChangeUpdateNode: - m := new(membership.Member) - if err := json.Unmarshal(cc.Context, m); err != nil { - panic(err) - } - cl.UpdateRaftAttributes(m.ID, m.RaftAttributes) - } -} - -func applyRequest(req *pb.Request, applyV2 etcdserver.ApplierV2) { - r := (*etcdserver.RequestV2)(req) - r.TTLOptions() - switch r.Method { - case "POST": - applyV2.Post(r) - case "PUT": - applyV2.Put(r) - case "DELETE": - applyV2.Delete(r) - case "QGET": - applyV2.QGet(r) - case "SYNC": - applyV2.Sync(r) - default: - panic("unknown command") - } -} - -func writeStore(w io.Writer, st store.Store) uint64 { - all, err := st.Get("/1", true, true) - if err != nil { - if eerr, ok := err.(*etcdErr.Error); ok && eerr.ErrorCode == etcdErr.EcodeKeyNotFound { - fmt.Println("no v2 keys to migrate") - os.Exit(0) - } - ExitWithError(ExitError, err) - } - return writeKeys(w, all.Node) -} - -func writeKeys(w io.Writer, n *store.NodeExtern) uint64 { - maxIndex := n.ModifiedIndex - - nodes := n.Nodes - // remove store v2 bucket prefix - n.Key = n.Key[2:] - if n.Key == "" { - n.Key = "/" - } - if n.Dir { - n.Nodes = nil - } - if !migrateExcludeTTLKey || n.TTL == 0 { - b, err := json.Marshal(n) - if err != nil { - ExitWithError(ExitError, err) - } - fmt.Fprint(w, string(b)) - } - for _, nn := range nodes { - max := writeKeys(w, nn) - if max > maxIndex { - maxIndex = max - } - } - return maxIndex -} - -func readKeys(r io.Reader, be backend.Backend) error { - for { - length64, err := readInt64(r) - if err != nil { - if err == io.EOF { - return nil - } - return err - } - - buf := make([]byte, int(length64)) - if _, err = io.ReadFull(r, buf); err != nil { - return err - } - - var kv mvccpb.KeyValue - err = proto.Unmarshal(buf, &kv) - if err != nil { - return err - } - - mvcc.WriteKV(be, kv) - } -} - -func readInt64(r io.Reader) (int64, error) { - var n int64 - err := binary.Read(r, binary.LittleEndian, &n) - return n, err -} - -func startTransformer() (io.WriteCloser, io.ReadCloser, chan error) { - cmd := exec.Command(migrateTransformer) - cmd.Stderr = os.Stderr - - writer, err := cmd.StdinPipe() - if err != nil { - ExitWithError(ExitError, err) - } - - reader, rerr := cmd.StdoutPipe() - if rerr != nil { - ExitWithError(ExitError, rerr) - } - - if err := cmd.Start(); err != nil { - ExitWithError(ExitError, err) - } - - errc := make(chan error, 1) - - go func() { - errc <- cmd.Wait() - }() - - return writer, reader, errc -} - -func defaultTransformer() (io.WriteCloser, io.ReadCloser, chan error) { - // transformer decodes v2 keys from sr - sr, sw := io.Pipe() - // transformer encodes v3 keys into dw - dr, dw := io.Pipe() - - decoder := json.NewDecoder(sr) - - errc := make(chan error, 1) - - go func() { - defer func() { - sr.Close() - dw.Close() - }() - - for decoder.More() { - node := &client.Node{} - if err := decoder.Decode(node); err != nil { - errc <- err - return - } - - kv := transform(node) - if kv == nil { - continue - } - - data, err := proto.Marshal(kv) - if err != nil { - errc <- err - return - } - buf := make([]byte, 8) - binary.LittleEndian.PutUint64(buf, uint64(len(data))) - if _, err := dw.Write(buf); err != nil { - errc <- err - return - } - if _, err := dw.Write(data); err != nil { - errc <- err - return - } - } - - errc <- nil - }() - - return sw, dr, errc -} - -func transform(n *client.Node) *mvccpb.KeyValue { - const unKnownVersion = 1 - if n.Dir { - return nil - } - kv := &mvccpb.KeyValue{ - Key: []byte(n.Key), - Value: []byte(n.Value), - CreateRevision: int64(n.CreatedIndex), - ModRevision: int64(n.ModifiedIndex), - Version: unKnownVersion, - } - return kv -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/move_leader_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/move_leader_command.go deleted file mode 100644 index 5fdecf95a817..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/move_leader_command.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "strconv" - - "github.com/coreos/etcd/clientv3" - "github.com/spf13/cobra" -) - -// NewMoveLeaderCommand returns the cobra command for "move-leader". -func NewMoveLeaderCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "move-leader ", - Short: "Transfers leadership to another etcd cluster member.", - Run: transferLeadershipCommandFunc, - } - return cmd -} - -// transferLeadershipCommandFunc executes the "compaction" command. -func transferLeadershipCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("move-leader command needs 1 argument")) - } - target, err := strconv.ParseUint(args[0], 16, 64) - if err != nil { - ExitWithError(ExitBadArgs, err) - } - - c := mustClientFromCmd(cmd) - eps := c.Endpoints() - c.Close() - - ctx, cancel := commandCtx(cmd) - - // find current leader - var leaderCli *clientv3.Client - var leaderID uint64 - for _, ep := range eps { - cfg := clientConfigFromCmd(cmd) - cfg.endpoints = []string{ep} - cli := cfg.mustClient() - resp, serr := cli.Status(ctx, ep) - if serr != nil { - ExitWithError(ExitError, serr) - } - - if resp.Header.GetMemberId() == resp.Leader { - leaderCli = cli - leaderID = resp.Leader - break - } - cli.Close() - } - if leaderCli == nil { - ExitWithError(ExitBadArgs, fmt.Errorf("no leader endpoint given at %v", eps)) - } - - var resp *clientv3.MoveLeaderResponse - resp, err = leaderCli.MoveLeader(ctx, target) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - - display.MoveLeader(leaderID, target, *resp) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer.go deleted file mode 100644 index b0c2d6cad652..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer.go +++ /dev/null @@ -1,211 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "errors" - "fmt" - "strings" - - v3 "github.com/coreos/etcd/clientv3" - "github.com/dustin/go-humanize" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -type printer interface { - Del(v3.DeleteResponse) - Get(v3.GetResponse) - Put(v3.PutResponse) - Txn(v3.TxnResponse) - Watch(v3.WatchResponse) - - Grant(r v3.LeaseGrantResponse) - Revoke(id v3.LeaseID, r v3.LeaseRevokeResponse) - KeepAlive(r v3.LeaseKeepAliveResponse) - TimeToLive(r v3.LeaseTimeToLiveResponse, keys bool) - Leases(r v3.LeaseLeasesResponse) - - MemberAdd(v3.MemberAddResponse) - MemberRemove(id uint64, r v3.MemberRemoveResponse) - MemberUpdate(id uint64, r v3.MemberUpdateResponse) - MemberList(v3.MemberListResponse) - - EndpointStatus([]epStatus) - EndpointHashKV([]epHashKV) - MoveLeader(leader, target uint64, r v3.MoveLeaderResponse) - - Alarm(v3.AlarmResponse) - DBStatus(dbstatus) - - RoleAdd(role string, r v3.AuthRoleAddResponse) - RoleGet(role string, r v3.AuthRoleGetResponse) - RoleDelete(role string, r v3.AuthRoleDeleteResponse) - RoleList(v3.AuthRoleListResponse) - RoleGrantPermission(role string, r v3.AuthRoleGrantPermissionResponse) - RoleRevokePermission(role string, key string, end string, r v3.AuthRoleRevokePermissionResponse) - - UserAdd(user string, r v3.AuthUserAddResponse) - UserGet(user string, r v3.AuthUserGetResponse) - UserList(r v3.AuthUserListResponse) - UserChangePassword(v3.AuthUserChangePasswordResponse) - UserGrantRole(user string, role string, r v3.AuthUserGrantRoleResponse) - UserRevokeRole(user string, role string, r v3.AuthUserRevokeRoleResponse) - UserDelete(user string, r v3.AuthUserDeleteResponse) -} - -func NewPrinter(printerType string, isHex bool) printer { - switch printerType { - case "simple": - return &simplePrinter{isHex: isHex} - case "fields": - return &fieldsPrinter{newPrinterUnsupported("fields")} - case "json": - return newJSONPrinter() - case "protobuf": - return newPBPrinter() - case "table": - return &tablePrinter{newPrinterUnsupported("table")} - } - return nil -} - -type printerRPC struct { - printer - p func(interface{}) -} - -func (p *printerRPC) Del(r v3.DeleteResponse) { p.p((*pb.DeleteRangeResponse)(&r)) } -func (p *printerRPC) Get(r v3.GetResponse) { p.p((*pb.RangeResponse)(&r)) } -func (p *printerRPC) Put(r v3.PutResponse) { p.p((*pb.PutResponse)(&r)) } -func (p *printerRPC) Txn(r v3.TxnResponse) { p.p((*pb.TxnResponse)(&r)) } -func (p *printerRPC) Watch(r v3.WatchResponse) { p.p(&r) } - -func (p *printerRPC) Grant(r v3.LeaseGrantResponse) { p.p(r) } -func (p *printerRPC) Revoke(id v3.LeaseID, r v3.LeaseRevokeResponse) { p.p(r) } -func (p *printerRPC) KeepAlive(r v3.LeaseKeepAliveResponse) { p.p(r) } -func (p *printerRPC) TimeToLive(r v3.LeaseTimeToLiveResponse, keys bool) { p.p(&r) } -func (p *printerRPC) Leases(r v3.LeaseLeasesResponse) { p.p(&r) } - -func (p *printerRPC) MemberAdd(r v3.MemberAddResponse) { p.p((*pb.MemberAddResponse)(&r)) } -func (p *printerRPC) MemberRemove(id uint64, r v3.MemberRemoveResponse) { - p.p((*pb.MemberRemoveResponse)(&r)) -} -func (p *printerRPC) MemberUpdate(id uint64, r v3.MemberUpdateResponse) { - p.p((*pb.MemberUpdateResponse)(&r)) -} -func (p *printerRPC) MemberList(r v3.MemberListResponse) { p.p((*pb.MemberListResponse)(&r)) } -func (p *printerRPC) Alarm(r v3.AlarmResponse) { p.p((*pb.AlarmResponse)(&r)) } -func (p *printerRPC) MoveLeader(leader, target uint64, r v3.MoveLeaderResponse) { - p.p((*pb.MoveLeaderResponse)(&r)) -} -func (p *printerRPC) RoleAdd(_ string, r v3.AuthRoleAddResponse) { p.p((*pb.AuthRoleAddResponse)(&r)) } -func (p *printerRPC) RoleGet(_ string, r v3.AuthRoleGetResponse) { p.p((*pb.AuthRoleGetResponse)(&r)) } -func (p *printerRPC) RoleDelete(_ string, r v3.AuthRoleDeleteResponse) { - p.p((*pb.AuthRoleDeleteResponse)(&r)) -} -func (p *printerRPC) RoleList(r v3.AuthRoleListResponse) { p.p((*pb.AuthRoleListResponse)(&r)) } -func (p *printerRPC) RoleGrantPermission(_ string, r v3.AuthRoleGrantPermissionResponse) { - p.p((*pb.AuthRoleGrantPermissionResponse)(&r)) -} -func (p *printerRPC) RoleRevokePermission(_ string, _ string, _ string, r v3.AuthRoleRevokePermissionResponse) { - p.p((*pb.AuthRoleRevokePermissionResponse)(&r)) -} -func (p *printerRPC) UserAdd(_ string, r v3.AuthUserAddResponse) { p.p((*pb.AuthUserAddResponse)(&r)) } -func (p *printerRPC) UserGet(_ string, r v3.AuthUserGetResponse) { p.p((*pb.AuthUserGetResponse)(&r)) } -func (p *printerRPC) UserList(r v3.AuthUserListResponse) { p.p((*pb.AuthUserListResponse)(&r)) } -func (p *printerRPC) UserChangePassword(r v3.AuthUserChangePasswordResponse) { - p.p((*pb.AuthUserChangePasswordResponse)(&r)) -} -func (p *printerRPC) UserGrantRole(_ string, _ string, r v3.AuthUserGrantRoleResponse) { - p.p((*pb.AuthUserGrantRoleResponse)(&r)) -} -func (p *printerRPC) UserRevokeRole(_ string, _ string, r v3.AuthUserRevokeRoleResponse) { - p.p((*pb.AuthUserRevokeRoleResponse)(&r)) -} -func (p *printerRPC) UserDelete(_ string, r v3.AuthUserDeleteResponse) { - p.p((*pb.AuthUserDeleteResponse)(&r)) -} - -type printerUnsupported struct{ printerRPC } - -func newPrinterUnsupported(n string) printer { - f := func(interface{}) { - ExitWithError(ExitBadFeature, errors.New(n+" not supported as output format")) - } - return &printerUnsupported{printerRPC{nil, f}} -} - -func (p *printerUnsupported) EndpointStatus([]epStatus) { p.p(nil) } -func (p *printerUnsupported) EndpointHashKV([]epHashKV) { p.p(nil) } -func (p *printerUnsupported) DBStatus(dbstatus) { p.p(nil) } - -func (p *printerUnsupported) MoveLeader(leader, target uint64, r v3.MoveLeaderResponse) { p.p(nil) } - -func makeMemberListTable(r v3.MemberListResponse) (hdr []string, rows [][]string) { - hdr = []string{"ID", "Status", "Name", "Peer Addrs", "Client Addrs"} - for _, m := range r.Members { - status := "started" - if len(m.Name) == 0 { - status = "unstarted" - } - rows = append(rows, []string{ - fmt.Sprintf("%x", m.ID), - status, - m.Name, - strings.Join(m.PeerURLs, ","), - strings.Join(m.ClientURLs, ","), - }) - } - return hdr, rows -} - -func makeEndpointStatusTable(statusList []epStatus) (hdr []string, rows [][]string) { - hdr = []string{"endpoint", "ID", "version", "db size", "is leader", "raft term", "raft index"} - for _, status := range statusList { - rows = append(rows, []string{ - status.Ep, - fmt.Sprintf("%x", status.Resp.Header.MemberId), - status.Resp.Version, - humanize.Bytes(uint64(status.Resp.DbSize)), - fmt.Sprint(status.Resp.Leader == status.Resp.Header.MemberId), - fmt.Sprint(status.Resp.RaftTerm), - fmt.Sprint(status.Resp.RaftIndex), - }) - } - return hdr, rows -} - -func makeEndpointHashKVTable(hashList []epHashKV) (hdr []string, rows [][]string) { - hdr = []string{"endpoint", "hash"} - for _, h := range hashList { - rows = append(rows, []string{ - h.Ep, - fmt.Sprint(h.Resp.Hash), - }) - } - return hdr, rows -} - -func makeDBStatusTable(ds dbstatus) (hdr []string, rows [][]string) { - hdr = []string{"hash", "revision", "total keys", "total size"} - rows = append(rows, []string{ - fmt.Sprintf("%x", ds.Hash), - fmt.Sprint(ds.Revision), - fmt.Sprint(ds.TotalKey), - humanize.Bytes(uint64(ds.TotalSize)), - }) - return hdr, rows -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_fields.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_fields.go deleted file mode 100644 index 24ff283a8cac..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_fields.go +++ /dev/null @@ -1,213 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - - v3 "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - spb "github.com/coreos/etcd/mvcc/mvccpb" -) - -type fieldsPrinter struct{ printer } - -func (p *fieldsPrinter) kv(pfx string, kv *spb.KeyValue) { - fmt.Printf("\"%sKey\" : %q\n", pfx, string(kv.Key)) - fmt.Printf("\"%sCreateRevision\" : %d\n", pfx, kv.CreateRevision) - fmt.Printf("\"%sModRevision\" : %d\n", pfx, kv.ModRevision) - fmt.Printf("\"%sVersion\" : %d\n", pfx, kv.Version) - fmt.Printf("\"%sValue\" : %q\n", pfx, string(kv.Value)) - fmt.Printf("\"%sLease\" : %d\n", pfx, kv.Lease) -} - -func (p *fieldsPrinter) hdr(h *pb.ResponseHeader) { - fmt.Println(`"ClusterID" :`, h.ClusterId) - fmt.Println(`"MemberID" :`, h.MemberId) - fmt.Println(`"Revision" :`, h.Revision) - fmt.Println(`"RaftTerm" :`, h.RaftTerm) -} - -func (p *fieldsPrinter) Del(r v3.DeleteResponse) { - p.hdr(r.Header) - fmt.Println(`"Deleted" :`, r.Deleted) - for _, kv := range r.PrevKvs { - p.kv("Prev", kv) - } -} - -func (p *fieldsPrinter) Get(r v3.GetResponse) { - p.hdr(r.Header) - for _, kv := range r.Kvs { - p.kv("", kv) - } - fmt.Println(`"More" :`, r.More) - fmt.Println(`"Count" :`, r.Count) -} - -func (p *fieldsPrinter) Put(r v3.PutResponse) { - p.hdr(r.Header) - if r.PrevKv != nil { - p.kv("Prev", r.PrevKv) - } -} - -func (p *fieldsPrinter) Txn(r v3.TxnResponse) { - p.hdr(r.Header) - fmt.Println(`"Succeeded" :`, r.Succeeded) - for _, resp := range r.Responses { - switch v := resp.Response.(type) { - case *pb.ResponseOp_ResponseDeleteRange: - p.Del((v3.DeleteResponse)(*v.ResponseDeleteRange)) - case *pb.ResponseOp_ResponsePut: - p.Put((v3.PutResponse)(*v.ResponsePut)) - case *pb.ResponseOp_ResponseRange: - p.Get((v3.GetResponse)(*v.ResponseRange)) - default: - fmt.Printf("\"Unknown\" : %q\n", fmt.Sprintf("%+v", v)) - } - } -} - -func (p *fieldsPrinter) Watch(resp v3.WatchResponse) { - p.hdr(&resp.Header) - for _, e := range resp.Events { - fmt.Println(`"Type" :`, e.Type) - if e.PrevKv != nil { - p.kv("Prev", e.PrevKv) - } - p.kv("", e.Kv) - } -} - -func (p *fieldsPrinter) Grant(r v3.LeaseGrantResponse) { - p.hdr(r.ResponseHeader) - fmt.Println(`"ID" :`, r.ID) - fmt.Println(`"TTL" :`, r.TTL) -} - -func (p *fieldsPrinter) Revoke(id v3.LeaseID, r v3.LeaseRevokeResponse) { - p.hdr(r.Header) -} - -func (p *fieldsPrinter) KeepAlive(r v3.LeaseKeepAliveResponse) { - p.hdr(r.ResponseHeader) - fmt.Println(`"ID" :`, r.ID) - fmt.Println(`"TTL" :`, r.TTL) -} - -func (p *fieldsPrinter) TimeToLive(r v3.LeaseTimeToLiveResponse, keys bool) { - p.hdr(r.ResponseHeader) - fmt.Println(`"ID" :`, r.ID) - fmt.Println(`"TTL" :`, r.TTL) - fmt.Println(`"GrantedTTL" :`, r.GrantedTTL) - for _, k := range r.Keys { - fmt.Printf("\"Key\" : %q\n", string(k)) - } -} - -func (p *fieldsPrinter) Leases(r v3.LeaseLeasesResponse) { - p.hdr(r.ResponseHeader) - for _, item := range r.Leases { - fmt.Println(`"ID" :`, item.ID) - } -} - -func (p *fieldsPrinter) MemberList(r v3.MemberListResponse) { - p.hdr(r.Header) - for _, m := range r.Members { - fmt.Println(`"ID" :`, m.ID) - fmt.Printf("\"Name\" : %q\n", m.Name) - for _, u := range m.PeerURLs { - fmt.Printf("\"PeerURL\" : %q\n", u) - } - for _, u := range m.ClientURLs { - fmt.Printf("\"ClientURL\" : %q\n", u) - } - fmt.Println() - } -} - -func (p *fieldsPrinter) EndpointStatus(eps []epStatus) { - for _, ep := range eps { - p.hdr(ep.Resp.Header) - fmt.Printf("\"Version\" : %q\n", ep.Resp.Version) - fmt.Println(`"DBSize" :`, ep.Resp.DbSize) - fmt.Println(`"Leader" :`, ep.Resp.Leader) - fmt.Println(`"RaftIndex" :`, ep.Resp.RaftIndex) - fmt.Println(`"RaftTerm" :`, ep.Resp.RaftTerm) - fmt.Printf("\"Endpoint\" : %q\n", ep.Ep) - fmt.Println() - } -} - -func (p *fieldsPrinter) EndpointHashKV(hs []epHashKV) { - for _, h := range hs { - p.hdr(h.Resp.Header) - fmt.Printf("\"Endpoint\" : %q\n", h.Ep) - fmt.Println(`"Hash" :`, h.Resp.Hash) - fmt.Println() - } -} - -func (p *fieldsPrinter) Alarm(r v3.AlarmResponse) { - p.hdr(r.Header) - for _, a := range r.Alarms { - fmt.Println(`"MemberID" :`, a.MemberID) - fmt.Println(`"AlarmType" :`, a.Alarm) - fmt.Println() - } -} - -func (p *fieldsPrinter) DBStatus(r dbstatus) { - fmt.Println(`"Hash" :`, r.Hash) - fmt.Println(`"Revision" :`, r.Revision) - fmt.Println(`"Keys" :`, r.TotalKey) - fmt.Println(`"Size" :`, r.TotalSize) -} - -func (p *fieldsPrinter) RoleAdd(role string, r v3.AuthRoleAddResponse) { p.hdr(r.Header) } -func (p *fieldsPrinter) RoleGet(role string, r v3.AuthRoleGetResponse) { - p.hdr(r.Header) - for _, p := range r.Perm { - fmt.Println(`"PermType" : `, p.PermType.String()) - fmt.Printf("\"Key\" : %q\n", string(p.Key)) - fmt.Printf("\"RangeEnd\" : %q\n", string(p.RangeEnd)) - } -} -func (p *fieldsPrinter) RoleDelete(role string, r v3.AuthRoleDeleteResponse) { p.hdr(r.Header) } -func (p *fieldsPrinter) RoleList(r v3.AuthRoleListResponse) { - p.hdr(r.Header) - fmt.Printf(`"Roles" :`) - for _, r := range r.Roles { - fmt.Printf(" %q", r) - } - fmt.Println() -} -func (p *fieldsPrinter) RoleGrantPermission(role string, r v3.AuthRoleGrantPermissionResponse) { - p.hdr(r.Header) -} -func (p *fieldsPrinter) RoleRevokePermission(role string, key string, end string, r v3.AuthRoleRevokePermissionResponse) { - p.hdr(r.Header) -} -func (p *fieldsPrinter) UserAdd(user string, r v3.AuthUserAddResponse) { p.hdr(r.Header) } -func (p *fieldsPrinter) UserChangePassword(r v3.AuthUserChangePasswordResponse) { p.hdr(r.Header) } -func (p *fieldsPrinter) UserGrantRole(user string, role string, r v3.AuthUserGrantRoleResponse) { - p.hdr(r.Header) -} -func (p *fieldsPrinter) UserRevokeRole(user string, role string, r v3.AuthUserRevokeRoleResponse) { - p.hdr(r.Header) -} -func (p *fieldsPrinter) UserDelete(user string, r v3.AuthUserDeleteResponse) { p.hdr(r.Header) } diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_json.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_json.go deleted file mode 100644 index 19b3a5e688bc..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_json.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "encoding/json" - "fmt" - "os" -) - -type jsonPrinter struct{ printer } - -func newJSONPrinter() printer { - return &jsonPrinter{ - &printerRPC{newPrinterUnsupported("json"), printJSON}, - } -} - -func (p *jsonPrinter) EndpointStatus(r []epStatus) { printJSON(r) } -func (p *jsonPrinter) EndpointHashKV(r []epHashKV) { printJSON(r) } -func (p *jsonPrinter) DBStatus(r dbstatus) { printJSON(r) } - -func printJSON(v interface{}) { - b, err := json.Marshal(v) - if err != nil { - fmt.Fprintf(os.Stderr, "%v\n", err) - return - } - fmt.Println(string(b)) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_protobuf.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_protobuf.go deleted file mode 100644 index c5109c5c2eef..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_protobuf.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "os" - - v3 "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - mvccpb "github.com/coreos/etcd/mvcc/mvccpb" -) - -type pbPrinter struct{ printer } - -type pbMarshal interface { - Marshal() ([]byte, error) -} - -func newPBPrinter() printer { - return &pbPrinter{ - &printerRPC{newPrinterUnsupported("protobuf"), printPB}, - } -} - -func (p *pbPrinter) Watch(r v3.WatchResponse) { - evs := make([]*mvccpb.Event, len(r.Events)) - for i, ev := range r.Events { - evs[i] = (*mvccpb.Event)(ev) - } - wr := pb.WatchResponse{ - Header: &r.Header, - Events: evs, - CompactRevision: r.CompactRevision, - Canceled: r.Canceled, - Created: r.Created, - } - printPB(&wr) -} - -func printPB(v interface{}) { - m, ok := v.(pbMarshal) - if !ok { - ExitWithError(ExitBadFeature, fmt.Errorf("marshal unsupported for type %T (%v)", v, v)) - } - b, err := m.Marshal() - if err != nil { - fmt.Fprintf(os.Stderr, "%v\n", err) - return - } - fmt.Print(string(b)) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_simple.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_simple.go deleted file mode 100644 index 2f4f53201c80..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_simple.go +++ /dev/null @@ -1,271 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "strings" - - v3 "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/pkg/types" -) - -type simplePrinter struct { - isHex bool - valueOnly bool -} - -func (s *simplePrinter) Del(resp v3.DeleteResponse) { - fmt.Println(resp.Deleted) - for _, kv := range resp.PrevKvs { - printKV(s.isHex, s.valueOnly, kv) - } -} - -func (s *simplePrinter) Get(resp v3.GetResponse) { - for _, kv := range resp.Kvs { - printKV(s.isHex, s.valueOnly, kv) - } -} - -func (s *simplePrinter) Put(r v3.PutResponse) { - fmt.Println("OK") - if r.PrevKv != nil { - printKV(s.isHex, s.valueOnly, r.PrevKv) - } -} - -func (s *simplePrinter) Txn(resp v3.TxnResponse) { - if resp.Succeeded { - fmt.Println("SUCCESS") - } else { - fmt.Println("FAILURE") - } - - for _, r := range resp.Responses { - fmt.Println("") - switch v := r.Response.(type) { - case *pb.ResponseOp_ResponseDeleteRange: - s.Del((v3.DeleteResponse)(*v.ResponseDeleteRange)) - case *pb.ResponseOp_ResponsePut: - s.Put((v3.PutResponse)(*v.ResponsePut)) - case *pb.ResponseOp_ResponseRange: - s.Get(((v3.GetResponse)(*v.ResponseRange))) - default: - fmt.Printf("unexpected response %+v\n", r) - } - } -} - -func (s *simplePrinter) Watch(resp v3.WatchResponse) { - for _, e := range resp.Events { - fmt.Println(e.Type) - if e.PrevKv != nil { - printKV(s.isHex, s.valueOnly, e.PrevKv) - } - printKV(s.isHex, s.valueOnly, e.Kv) - } -} - -func (s *simplePrinter) Grant(resp v3.LeaseGrantResponse) { - fmt.Printf("lease %016x granted with TTL(%ds)\n", resp.ID, resp.TTL) -} - -func (p *simplePrinter) Revoke(id v3.LeaseID, r v3.LeaseRevokeResponse) { - fmt.Printf("lease %016x revoked\n", id) -} - -func (p *simplePrinter) KeepAlive(resp v3.LeaseKeepAliveResponse) { - fmt.Printf("lease %016x keepalived with TTL(%d)\n", resp.ID, resp.TTL) -} - -func (s *simplePrinter) TimeToLive(resp v3.LeaseTimeToLiveResponse, keys bool) { - if resp.GrantedTTL == 0 && resp.TTL == -1 { - fmt.Printf("lease %016x already expired\n", resp.ID) - return - } - - txt := fmt.Sprintf("lease %016x granted with TTL(%ds), remaining(%ds)", resp.ID, resp.GrantedTTL, resp.TTL) - if keys { - ks := make([]string, len(resp.Keys)) - for i := range resp.Keys { - ks[i] = string(resp.Keys[i]) - } - txt += fmt.Sprintf(", attached keys(%v)", ks) - } - fmt.Println(txt) -} - -func (s *simplePrinter) Leases(resp v3.LeaseLeasesResponse) { - fmt.Printf("found %d leases\n", len(resp.Leases)) - for _, item := range resp.Leases { - fmt.Printf("%016x\n", item.ID) - } -} - -func (s *simplePrinter) Alarm(resp v3.AlarmResponse) { - for _, e := range resp.Alarms { - fmt.Printf("%+v\n", e) - } -} - -func (s *simplePrinter) MemberAdd(r v3.MemberAddResponse) { - fmt.Printf("Member %16x added to cluster %16x\n", r.Member.ID, r.Header.ClusterId) -} - -func (s *simplePrinter) MemberRemove(id uint64, r v3.MemberRemoveResponse) { - fmt.Printf("Member %16x removed from cluster %16x\n", id, r.Header.ClusterId) -} - -func (s *simplePrinter) MemberUpdate(id uint64, r v3.MemberUpdateResponse) { - fmt.Printf("Member %16x updated in cluster %16x\n", id, r.Header.ClusterId) -} - -func (s *simplePrinter) MemberList(resp v3.MemberListResponse) { - _, rows := makeMemberListTable(resp) - for _, row := range rows { - fmt.Println(strings.Join(row, ", ")) - } -} - -func (s *simplePrinter) EndpointStatus(statusList []epStatus) { - _, rows := makeEndpointStatusTable(statusList) - for _, row := range rows { - fmt.Println(strings.Join(row, ", ")) - } -} - -func (s *simplePrinter) EndpointHashKV(hashList []epHashKV) { - _, rows := makeEndpointHashKVTable(hashList) - for _, row := range rows { - fmt.Println(strings.Join(row, ", ")) - } -} - -func (s *simplePrinter) DBStatus(ds dbstatus) { - _, rows := makeDBStatusTable(ds) - for _, row := range rows { - fmt.Println(strings.Join(row, ", ")) - } -} - -func (s *simplePrinter) MoveLeader(leader, target uint64, r v3.MoveLeaderResponse) { - fmt.Printf("Leadership transferred from %s to %s\n", types.ID(leader), types.ID(target)) -} - -func (s *simplePrinter) RoleAdd(role string, r v3.AuthRoleAddResponse) { - fmt.Printf("Role %s created\n", role) -} - -func (s *simplePrinter) RoleGet(role string, r v3.AuthRoleGetResponse) { - fmt.Printf("Role %s\n", role) - fmt.Println("KV Read:") - - printRange := func(perm *v3.Permission) { - sKey := string(perm.Key) - sRangeEnd := string(perm.RangeEnd) - if strings.Compare(sRangeEnd, "\x00") != 0 { - fmt.Printf("\t[%s, %s)", sKey, sRangeEnd) - } else { - fmt.Printf("\t[%s, ", sKey) - } - if strings.Compare(v3.GetPrefixRangeEnd(sKey), sRangeEnd) == 0 { - fmt.Printf(" (prefix %s)", sKey) - } - fmt.Printf("\n") - } - - for _, perm := range r.Perm { - if perm.PermType == v3.PermRead || perm.PermType == v3.PermReadWrite { - if len(perm.RangeEnd) == 0 { - fmt.Printf("\t%s\n", string(perm.Key)) - } else { - printRange((*v3.Permission)(perm)) - } - } - } - fmt.Println("KV Write:") - for _, perm := range r.Perm { - if perm.PermType == v3.PermWrite || perm.PermType == v3.PermReadWrite { - if len(perm.RangeEnd) == 0 { - fmt.Printf("\t%s\n", string(perm.Key)) - } else { - printRange((*v3.Permission)(perm)) - } - } - } -} - -func (s *simplePrinter) RoleList(r v3.AuthRoleListResponse) { - for _, role := range r.Roles { - fmt.Printf("%s\n", role) - } -} - -func (s *simplePrinter) RoleDelete(role string, r v3.AuthRoleDeleteResponse) { - fmt.Printf("Role %s deleted\n", role) -} - -func (s *simplePrinter) RoleGrantPermission(role string, r v3.AuthRoleGrantPermissionResponse) { - fmt.Printf("Role %s updated\n", role) -} - -func (s *simplePrinter) RoleRevokePermission(role string, key string, end string, r v3.AuthRoleRevokePermissionResponse) { - if len(end) == 0 { - fmt.Printf("Permission of key %s is revoked from role %s\n", key, role) - return - } - if strings.Compare(end, "\x00") != 0 { - fmt.Printf("Permission of range [%s, %s) is revoked from role %s\n", key, end, role) - } else { - fmt.Printf("Permission of range [%s, is revoked from role %s\n", key, role) - } -} - -func (s *simplePrinter) UserAdd(name string, r v3.AuthUserAddResponse) { - fmt.Printf("User %s created\n", name) -} - -func (s *simplePrinter) UserGet(name string, r v3.AuthUserGetResponse) { - fmt.Printf("User: %s\n", name) - fmt.Printf("Roles:") - for _, role := range r.Roles { - fmt.Printf(" %s", role) - } - fmt.Printf("\n") -} - -func (s *simplePrinter) UserChangePassword(v3.AuthUserChangePasswordResponse) { - fmt.Println("Password updated") -} - -func (s *simplePrinter) UserGrantRole(user string, role string, r v3.AuthUserGrantRoleResponse) { - fmt.Printf("Role %s is granted to user %s\n", role, user) -} - -func (s *simplePrinter) UserRevokeRole(user string, role string, r v3.AuthUserRevokeRoleResponse) { - fmt.Printf("Role %s is revoked from user %s\n", role, user) -} - -func (s *simplePrinter) UserDelete(user string, r v3.AuthUserDeleteResponse) { - fmt.Printf("User %s deleted\n", user) -} - -func (s *simplePrinter) UserList(r v3.AuthUserListResponse) { - for _, user := range r.Users { - fmt.Printf("%s\n", user) - } -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_table.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_table.go deleted file mode 100644 index 1aea61a8456f..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/printer_table.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "os" - - "github.com/olekukonko/tablewriter" - - v3 "github.com/coreos/etcd/clientv3" -) - -type tablePrinter struct{ printer } - -func (tp *tablePrinter) MemberList(r v3.MemberListResponse) { - hdr, rows := makeMemberListTable(r) - table := tablewriter.NewWriter(os.Stdout) - table.SetHeader(hdr) - for _, row := range rows { - table.Append(row) - } - table.SetAlignment(tablewriter.ALIGN_RIGHT) - table.Render() -} -func (tp *tablePrinter) EndpointStatus(r []epStatus) { - hdr, rows := makeEndpointStatusTable(r) - table := tablewriter.NewWriter(os.Stdout) - table.SetHeader(hdr) - for _, row := range rows { - table.Append(row) - } - table.SetAlignment(tablewriter.ALIGN_RIGHT) - table.Render() -} -func (tp *tablePrinter) EndpointHashKV(r []epHashKV) { - hdr, rows := makeEndpointHashKVTable(r) - table := tablewriter.NewWriter(os.Stdout) - table.SetHeader(hdr) - for _, row := range rows { - table.Append(row) - } - table.SetAlignment(tablewriter.ALIGN_RIGHT) - table.Render() -} -func (tp *tablePrinter) DBStatus(r dbstatus) { - hdr, rows := makeDBStatusTable(r) - table := tablewriter.NewWriter(os.Stdout) - table.SetHeader(hdr) - for _, row := range rows { - table.Append(row) - } - table.SetAlignment(tablewriter.ALIGN_RIGHT) - table.Render() -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/put_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/put_command.go deleted file mode 100644 index a72f0c4dcf57..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/put_command.go +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - "os" - "strconv" - - "github.com/coreos/etcd/clientv3" - "github.com/spf13/cobra" -) - -var ( - leaseStr string - putPrevKV bool - putIgnoreVal bool - putIgnoreLease bool -) - -// NewPutCommand returns the cobra command for "put". -func NewPutCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "put [options] ( can also be given from stdin)", - Short: "Puts the given key into the store", - Long: ` -Puts the given key into the store. - -When begins with '-', is interpreted as a flag. -Insert '--' for workaround: - -$ put -- -$ put -- - -If isn't given as a command line argument and '--ignore-value' is not specified, -this command tries to read the value from standard input. - -If isn't given as a command line argument and '--ignore-lease' is not specified, -this command tries to read the value from standard input. - -For example, -$ cat file | put -will store the content of the file to . -`, - Run: putCommandFunc, - } - cmd.Flags().StringVar(&leaseStr, "lease", "0", "lease ID (in hexadecimal) to attach to the key") - cmd.Flags().BoolVar(&putPrevKV, "prev-kv", false, "return the previous key-value pair before modification") - cmd.Flags().BoolVar(&putIgnoreVal, "ignore-value", false, "updates the key using its current value") - cmd.Flags().BoolVar(&putIgnoreLease, "ignore-lease", false, "updates the key using its current lease") - return cmd -} - -// putCommandFunc executes the "put" command. -func putCommandFunc(cmd *cobra.Command, args []string) { - key, value, opts := getPutOp(cmd, args) - - ctx, cancel := commandCtx(cmd) - resp, err := mustClientFromCmd(cmd).Put(ctx, key, value, opts...) - cancel() - if err != nil { - ExitWithError(ExitError, err) - } - display.Put(*resp) -} - -func getPutOp(cmd *cobra.Command, args []string) (string, string, []clientv3.OpOption) { - if len(args) == 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("put command needs 1 argument and input from stdin or 2 arguments.")) - } - - key := args[0] - if putIgnoreVal && len(args) > 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("put command needs only 1 argument when 'ignore-value' is set.")) - } - - var value string - var err error - if !putIgnoreVal { - value, err = argOrStdin(args, os.Stdin, 1) - if err != nil { - ExitWithError(ExitBadArgs, fmt.Errorf("put command needs 1 argument and input from stdin or 2 arguments.")) - } - } - - id, err := strconv.ParseInt(leaseStr, 16, 64) - if err != nil { - ExitWithError(ExitBadArgs, fmt.Errorf("bad lease ID (%v), expecting ID in Hex", err)) - } - - opts := []clientv3.OpOption{} - if id != 0 { - opts = append(opts, clientv3.WithLease(clientv3.LeaseID(id))) - } - if putPrevKV { - opts = append(opts, clientv3.WithPrevKV()) - } - if putIgnoreVal { - opts = append(opts, clientv3.WithIgnoreValue()) - } - if putIgnoreLease { - opts = append(opts, clientv3.WithIgnoreLease()) - } - - return key, value, opts -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/role_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/role_command.go deleted file mode 100644 index 39c52d313a14..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/role_command.go +++ /dev/null @@ -1,244 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "fmt" - - "github.com/coreos/etcd/clientv3" - "github.com/spf13/cobra" -) - -var ( - rolePermPrefix bool - rolePermFromKey bool -) - -// NewRoleCommand returns the cobra command for "role". -func NewRoleCommand() *cobra.Command { - ac := &cobra.Command{ - Use: "role ", - Short: "Role related commands", - } - - ac.AddCommand(newRoleAddCommand()) - ac.AddCommand(newRoleDeleteCommand()) - ac.AddCommand(newRoleGetCommand()) - ac.AddCommand(newRoleListCommand()) - ac.AddCommand(newRoleGrantPermissionCommand()) - ac.AddCommand(newRoleRevokePermissionCommand()) - - return ac -} - -func newRoleAddCommand() *cobra.Command { - return &cobra.Command{ - Use: "add ", - Short: "Adds a new role", - Run: roleAddCommandFunc, - } -} - -func newRoleDeleteCommand() *cobra.Command { - return &cobra.Command{ - Use: "delete ", - Short: "Deletes a role", - Run: roleDeleteCommandFunc, - } -} - -func newRoleGetCommand() *cobra.Command { - return &cobra.Command{ - Use: "get ", - Short: "Gets detailed information of a role", - Run: roleGetCommandFunc, - } -} - -func newRoleListCommand() *cobra.Command { - return &cobra.Command{ - Use: "list", - Short: "Lists all roles", - Run: roleListCommandFunc, - } -} - -func newRoleGrantPermissionCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "grant-permission [options] [endkey]", - Short: "Grants a key to a role", - Run: roleGrantPermissionCommandFunc, - } - - cmd.Flags().BoolVar(&rolePermPrefix, "prefix", false, "grant a prefix permission") - cmd.Flags().BoolVar(&rolePermFromKey, "from-key", false, "grant a permission of keys that are greater than or equal to the given key using byte compare") - - return cmd -} - -func newRoleRevokePermissionCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "revoke-permission [endkey]", - Short: "Revokes a key from a role", - Run: roleRevokePermissionCommandFunc, - } - - cmd.Flags().BoolVar(&rolePermPrefix, "prefix", false, "revoke a prefix permission") - cmd.Flags().BoolVar(&rolePermFromKey, "from-key", false, "revoke a permission of keys that are greater than or equal to the given key using byte compare") - - return cmd -} - -// roleAddCommandFunc executes the "role add" command. -func roleAddCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("role add command requires role name as its argument.")) - } - - resp, err := mustClientFromCmd(cmd).Auth.RoleAdd(context.TODO(), args[0]) - if err != nil { - ExitWithError(ExitError, err) - } - - display.RoleAdd(args[0], *resp) -} - -// roleDeleteCommandFunc executes the "role delete" command. -func roleDeleteCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("role delete command requires role name as its argument.")) - } - - resp, err := mustClientFromCmd(cmd).Auth.RoleDelete(context.TODO(), args[0]) - if err != nil { - ExitWithError(ExitError, err) - } - - display.RoleDelete(args[0], *resp) -} - -// roleGetCommandFunc executes the "role get" command. -func roleGetCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("role get command requires role name as its argument.")) - } - - name := args[0] - resp, err := mustClientFromCmd(cmd).Auth.RoleGet(context.TODO(), name) - if err != nil { - ExitWithError(ExitError, err) - } - - display.RoleGet(name, *resp) -} - -// roleListCommandFunc executes the "role list" command. -func roleListCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("role list command requires no arguments.")) - } - - resp, err := mustClientFromCmd(cmd).Auth.RoleList(context.TODO()) - if err != nil { - ExitWithError(ExitError, err) - } - - display.RoleList(*resp) -} - -// roleGrantPermissionCommandFunc executes the "role grant-permission" command. -func roleGrantPermissionCommandFunc(cmd *cobra.Command, args []string) { - if len(args) < 3 { - ExitWithError(ExitBadArgs, fmt.Errorf("role grant command requires role name, permission type, and key [endkey] as its argument.")) - } - - perm, err := clientv3.StrToPermissionType(args[1]) - if err != nil { - ExitWithError(ExitBadArgs, err) - } - - key, rangeEnd := permRange(args[2:]) - resp, err := mustClientFromCmd(cmd).Auth.RoleGrantPermission(context.TODO(), args[0], key, rangeEnd, perm) - if err != nil { - ExitWithError(ExitError, err) - } - - display.RoleGrantPermission(args[0], *resp) -} - -// roleRevokePermissionCommandFunc executes the "role revoke-permission" command. -func roleRevokePermissionCommandFunc(cmd *cobra.Command, args []string) { - if len(args) < 2 { - ExitWithError(ExitBadArgs, fmt.Errorf("role revoke-permission command requires role name and key [endkey] as its argument.")) - } - - key, rangeEnd := permRange(args[1:]) - resp, err := mustClientFromCmd(cmd).Auth.RoleRevokePermission(context.TODO(), args[0], key, rangeEnd) - if err != nil { - ExitWithError(ExitError, err) - } - display.RoleRevokePermission(args[0], args[1], rangeEnd, *resp) -} - -func permRange(args []string) (string, string) { - key := args[0] - var rangeEnd string - if len(key) == 0 { - if rolePermPrefix && rolePermFromKey { - ExitWithError(ExitBadArgs, fmt.Errorf("--from-key and --prefix flags are mutually exclusive")) - } - - // Range permission is expressed as adt.BytesAffineInterval, - // so the empty prefix which should be matched with every key must be like this ["\x00", ). - key = "\x00" - if rolePermPrefix || rolePermFromKey { - // For the both cases of prefix and from-key, a permission with an empty key - // should allow access to the entire key space. - // 0x00 will be treated as open ended in server side. - rangeEnd = "\x00" - } - } else { - var err error - rangeEnd, err = rangeEndFromPermFlags(args[0:]) - if err != nil { - ExitWithError(ExitBadArgs, err) - } - } - return key, rangeEnd -} - -func rangeEndFromPermFlags(args []string) (string, error) { - if len(args) == 1 { - if rolePermPrefix { - if rolePermFromKey { - return "", fmt.Errorf("--from-key and --prefix flags are mutually exclusive") - } - return clientv3.GetPrefixRangeEnd(args[0]), nil - } - if rolePermFromKey { - return "\x00", nil - } - // single key case - return "", nil - } - if rolePermPrefix { - return "", fmt.Errorf("unexpected endkey argument with --prefix flag") - } - if rolePermFromKey { - return "", fmt.Errorf("unexpected endkey argument with --from-key flag") - } - return args[1], nil -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/snapshot_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/snapshot_command.go deleted file mode 100644 index 297c9c0b93c2..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/snapshot_command.go +++ /dev/null @@ -1,475 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "crypto/sha256" - "encoding/binary" - "encoding/json" - "fmt" - "hash/crc32" - "io" - "math" - "os" - "path/filepath" - "reflect" - "strings" - - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/pkg/fileutil" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/snap" - "github.com/coreos/etcd/store" - "github.com/coreos/etcd/wal" - "github.com/coreos/etcd/wal/walpb" - - bolt "github.com/coreos/bbolt" - "github.com/spf13/cobra" -) - -const ( - defaultName = "default" - defaultInitialAdvertisePeerURLs = "http://localhost:2380" -) - -var ( - restoreCluster string - restoreClusterToken string - restoreDataDir string - restoreWalDir string - restorePeerURLs string - restoreName string - skipHashCheck bool -) - -// NewSnapshotCommand returns the cobra command for "snapshot". -func NewSnapshotCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "snapshot ", - Short: "Manages etcd node snapshots", - } - cmd.AddCommand(NewSnapshotSaveCommand()) - cmd.AddCommand(NewSnapshotRestoreCommand()) - cmd.AddCommand(newSnapshotStatusCommand()) - return cmd -} - -func NewSnapshotSaveCommand() *cobra.Command { - return &cobra.Command{ - Use: "save ", - Short: "Stores an etcd node backend snapshot to a given file", - Run: snapshotSaveCommandFunc, - } -} - -func newSnapshotStatusCommand() *cobra.Command { - return &cobra.Command{ - Use: "status ", - Short: "Gets backend snapshot status of a given file", - Long: `When --write-out is set to simple, this command prints out comma-separated status lists for each endpoint. -The items in the lists are hash, revision, total keys, total size. -`, - Run: snapshotStatusCommandFunc, - } -} - -func NewSnapshotRestoreCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "restore [options]", - Short: "Restores an etcd member snapshot to an etcd directory", - Run: snapshotRestoreCommandFunc, - } - cmd.Flags().StringVar(&restoreDataDir, "data-dir", "", "Path to the data directory") - cmd.Flags().StringVar(&restoreWalDir, "wal-dir", "", "Path to the WAL directory (use --data-dir if none given)") - cmd.Flags().StringVar(&restoreCluster, "initial-cluster", initialClusterFromName(defaultName), "Initial cluster configuration for restore bootstrap") - cmd.Flags().StringVar(&restoreClusterToken, "initial-cluster-token", "etcd-cluster", "Initial cluster token for the etcd cluster during restore bootstrap") - cmd.Flags().StringVar(&restorePeerURLs, "initial-advertise-peer-urls", defaultInitialAdvertisePeerURLs, "List of this member's peer URLs to advertise to the rest of the cluster") - cmd.Flags().StringVar(&restoreName, "name", defaultName, "Human-readable name for this member") - cmd.Flags().BoolVar(&skipHashCheck, "skip-hash-check", false, "Ignore snapshot integrity hash value (required if copied from data directory)") - - return cmd -} - -func snapshotSaveCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - err := fmt.Errorf("snapshot save expects one argument") - ExitWithError(ExitBadArgs, err) - } - - path := args[0] - - partpath := path + ".part" - f, err := os.Create(partpath) - - if err != nil { - exiterr := fmt.Errorf("could not open %s (%v)", partpath, err) - ExitWithError(ExitBadArgs, exiterr) - } - - c := mustClientFromCmd(cmd) - r, serr := c.Snapshot(context.TODO()) - if serr != nil { - os.RemoveAll(partpath) - ExitWithError(ExitInterrupted, serr) - } - if _, rerr := io.Copy(f, r); rerr != nil { - os.RemoveAll(partpath) - ExitWithError(ExitInterrupted, rerr) - } - - fileutil.Fsync(f) - - f.Close() - - if rerr := os.Rename(partpath, path); rerr != nil { - exiterr := fmt.Errorf("could not rename %s to %s (%v)", partpath, path, rerr) - ExitWithError(ExitIO, exiterr) - } - fmt.Printf("Snapshot saved at %s\n", path) -} - -func snapshotStatusCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - err := fmt.Errorf("snapshot status requires exactly one argument") - ExitWithError(ExitBadArgs, err) - } - initDisplayFromCmd(cmd) - ds := dbStatus(args[0]) - display.DBStatus(ds) -} - -func snapshotRestoreCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - err := fmt.Errorf("snapshot restore requires exactly one argument") - ExitWithError(ExitBadArgs, err) - } - - urlmap, uerr := types.NewURLsMap(restoreCluster) - if uerr != nil { - ExitWithError(ExitBadArgs, uerr) - } - - cfg := etcdserver.ServerConfig{ - InitialClusterToken: restoreClusterToken, - InitialPeerURLsMap: urlmap, - PeerURLs: types.MustNewURLs(strings.Split(restorePeerURLs, ",")), - Name: restoreName, - } - if err := cfg.VerifyBootstrap(); err != nil { - ExitWithError(ExitBadArgs, err) - } - - cl, cerr := membership.NewClusterFromURLsMap(restoreClusterToken, urlmap) - if cerr != nil { - ExitWithError(ExitBadArgs, cerr) - } - - basedir := restoreDataDir - if basedir == "" { - basedir = restoreName + ".etcd" - } - - waldir := restoreWalDir - if waldir == "" { - waldir = filepath.Join(basedir, "member", "wal") - } - snapdir := filepath.Join(basedir, "member", "snap") - - if _, err := os.Stat(basedir); err == nil { - ExitWithError(ExitInvalidInput, fmt.Errorf("data-dir %q exists", basedir)) - } - - makeDB(snapdir, args[0], len(cl.Members())) - makeWALAndSnap(waldir, snapdir, cl) -} - -func initialClusterFromName(name string) string { - n := name - if name == "" { - n = defaultName - } - return fmt.Sprintf("%s=http://localhost:2380", n) -} - -// makeWAL creates a WAL for the initial cluster -func makeWALAndSnap(waldir, snapdir string, cl *membership.RaftCluster) { - if err := fileutil.CreateDirAll(waldir); err != nil { - ExitWithError(ExitIO, err) - } - - // add members again to persist them to the store we create. - st := store.New(etcdserver.StoreClusterPrefix, etcdserver.StoreKeysPrefix) - cl.SetStore(st) - for _, m := range cl.Members() { - cl.AddMember(m) - } - - m := cl.MemberByName(restoreName) - md := &etcdserverpb.Metadata{NodeID: uint64(m.ID), ClusterID: uint64(cl.ID())} - metadata, merr := md.Marshal() - if merr != nil { - ExitWithError(ExitInvalidInput, merr) - } - - w, walerr := wal.Create(waldir, metadata) - if walerr != nil { - ExitWithError(ExitIO, walerr) - } - defer w.Close() - - peers := make([]raft.Peer, len(cl.MemberIDs())) - for i, id := range cl.MemberIDs() { - ctx, err := json.Marshal((*cl).Member(id)) - if err != nil { - ExitWithError(ExitInvalidInput, err) - } - peers[i] = raft.Peer{ID: uint64(id), Context: ctx} - } - - ents := make([]raftpb.Entry, len(peers)) - nodeIDs := make([]uint64, len(peers)) - for i, p := range peers { - nodeIDs[i] = p.ID - cc := raftpb.ConfChange{ - Type: raftpb.ConfChangeAddNode, - NodeID: p.ID, - Context: p.Context} - d, err := cc.Marshal() - if err != nil { - ExitWithError(ExitInvalidInput, err) - } - e := raftpb.Entry{ - Type: raftpb.EntryConfChange, - Term: 1, - Index: uint64(i + 1), - Data: d, - } - ents[i] = e - } - - commit, term := uint64(len(ents)), uint64(1) - - if err := w.Save(raftpb.HardState{ - Term: term, - Vote: peers[0].ID, - Commit: commit}, ents); err != nil { - ExitWithError(ExitIO, err) - } - - b, berr := st.Save() - if berr != nil { - ExitWithError(ExitError, berr) - } - - raftSnap := raftpb.Snapshot{ - Data: b, - Metadata: raftpb.SnapshotMetadata{ - Index: commit, - Term: term, - ConfState: raftpb.ConfState{ - Nodes: nodeIDs, - }, - }, - } - snapshotter := snap.New(snapdir) - if err := snapshotter.SaveSnap(raftSnap); err != nil { - panic(err) - } - - if err := w.SaveSnapshot(walpb.Snapshot{Index: commit, Term: term}); err != nil { - ExitWithError(ExitIO, err) - } -} - -// initIndex implements ConsistentIndexGetter so the snapshot won't block -// the new raft instance by waiting for a future raft index. -type initIndex int - -func (i *initIndex) ConsistentIndex() uint64 { return uint64(*i) } - -// makeDB copies the database snapshot to the snapshot directory -func makeDB(snapdir, dbfile string, commit int) { - f, ferr := os.OpenFile(dbfile, os.O_RDONLY, 0600) - if ferr != nil { - ExitWithError(ExitInvalidInput, ferr) - } - defer f.Close() - - // get snapshot integrity hash - if _, err := f.Seek(-sha256.Size, io.SeekEnd); err != nil { - ExitWithError(ExitIO, err) - } - sha := make([]byte, sha256.Size) - if _, err := f.Read(sha); err != nil { - ExitWithError(ExitIO, err) - } - if _, err := f.Seek(0, io.SeekStart); err != nil { - ExitWithError(ExitIO, err) - } - - if err := fileutil.CreateDirAll(snapdir); err != nil { - ExitWithError(ExitIO, err) - } - - dbpath := filepath.Join(snapdir, "db") - db, dberr := os.OpenFile(dbpath, os.O_RDWR|os.O_CREATE, 0600) - if dberr != nil { - ExitWithError(ExitIO, dberr) - } - if _, err := io.Copy(db, f); err != nil { - ExitWithError(ExitIO, err) - } - - // truncate away integrity hash, if any. - off, serr := db.Seek(0, io.SeekEnd) - if serr != nil { - ExitWithError(ExitIO, serr) - } - hasHash := (off % 512) == sha256.Size - if hasHash { - if err := db.Truncate(off - sha256.Size); err != nil { - ExitWithError(ExitIO, err) - } - } - - if !hasHash && !skipHashCheck { - err := fmt.Errorf("snapshot missing hash but --skip-hash-check=false") - ExitWithError(ExitBadArgs, err) - } - - if hasHash && !skipHashCheck { - // check for match - if _, err := db.Seek(0, io.SeekStart); err != nil { - ExitWithError(ExitIO, err) - } - h := sha256.New() - if _, err := io.Copy(h, db); err != nil { - ExitWithError(ExitIO, err) - } - dbsha := h.Sum(nil) - if !reflect.DeepEqual(sha, dbsha) { - err := fmt.Errorf("expected sha256 %v, got %v", sha, dbsha) - ExitWithError(ExitInvalidInput, err) - } - } - - // db hash is OK, can now modify DB so it can be part of a new cluster - db.Close() - - // update consistentIndex so applies go through on etcdserver despite - // having a new raft instance - be := backend.NewDefaultBackend(dbpath) - // a lessor never timeouts leases - lessor := lease.NewLessor(be, math.MaxInt64) - s := mvcc.NewStore(be, lessor, (*initIndex)(&commit)) - txn := s.Write() - btx := be.BatchTx() - del := func(k, v []byte) error { - txn.DeleteRange(k, nil) - return nil - } - - // delete stored members from old cluster since using new members - btx.UnsafeForEach([]byte("members"), del) - // todo: add back new members when we start to deprecate old snap file. - btx.UnsafeForEach([]byte("members_removed"), del) - // trigger write-out of new consistent index - txn.End() - s.Commit() - s.Close() - be.Close() -} - -type dbstatus struct { - Hash uint32 `json:"hash"` - Revision int64 `json:"revision"` - TotalKey int `json:"totalKey"` - TotalSize int64 `json:"totalSize"` -} - -func dbStatus(p string) dbstatus { - if _, err := os.Stat(p); err != nil { - ExitWithError(ExitError, err) - } - - ds := dbstatus{} - - db, err := bolt.Open(p, 0400, &bolt.Options{ReadOnly: true}) - if err != nil { - ExitWithError(ExitError, err) - } - defer db.Close() - - h := crc32.New(crc32.MakeTable(crc32.Castagnoli)) - - err = db.View(func(tx *bolt.Tx) error { - // check snapshot file integrity first - var dbErrStrings []string - for dbErr := range tx.Check() { - dbErrStrings = append(dbErrStrings, dbErr.Error()) - } - if len(dbErrStrings) > 0 { - return fmt.Errorf("snapshot file integrity check failed. %d errors found.\n"+strings.Join(dbErrStrings, "\n"), len(dbErrStrings)) - } - ds.TotalSize = tx.Size() - c := tx.Cursor() - for next, _ := c.First(); next != nil; next, _ = c.Next() { - b := tx.Bucket(next) - if b == nil { - return fmt.Errorf("cannot get hash of bucket %s", string(next)) - } - h.Write(next) - iskeyb := (string(next) == "key") - b.ForEach(func(k, v []byte) error { - h.Write(k) - h.Write(v) - if iskeyb { - rev := bytesToRev(k) - ds.Revision = rev.main - } - ds.TotalKey++ - return nil - }) - } - return nil - }) - - if err != nil { - ExitWithError(ExitError, err) - } - - ds.Hash = h.Sum32() - return ds -} - -type revision struct { - main int64 - sub int64 -} - -func bytesToRev(bytes []byte) revision { - return revision{ - main: int64(binary.BigEndian.Uint64(bytes[0:8])), - sub: int64(binary.BigEndian.Uint64(bytes[9:])), - } -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/txn_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/txn_command.go deleted file mode 100644 index eec1e0916c30..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/txn_command.go +++ /dev/null @@ -1,209 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "bufio" - "context" - "fmt" - "os" - "strconv" - "strings" - - "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "github.com/spf13/cobra" -) - -var ( - txnInteractive bool -) - -// NewTxnCommand returns the cobra command for "txn". -func NewTxnCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "txn [options]", - Short: "Txn processes all the requests in one transaction", - Run: txnCommandFunc, - } - cmd.Flags().BoolVarP(&txnInteractive, "interactive", "i", false, "Input transaction in interactive mode") - return cmd -} - -// txnCommandFunc executes the "txn" command. -func txnCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("txn command does not accept argument.")) - } - - reader := bufio.NewReader(os.Stdin) - - txn := mustClientFromCmd(cmd).Txn(context.Background()) - promptInteractive("compares:") - txn.If(readCompares(reader)...) - promptInteractive("success requests (get, put, del):") - txn.Then(readOps(reader)...) - promptInteractive("failure requests (get, put, del):") - txn.Else(readOps(reader)...) - - resp, err := txn.Commit() - if err != nil { - ExitWithError(ExitError, err) - } - - display.Txn(*resp) -} - -func promptInteractive(s string) { - if txnInteractive { - fmt.Println(s) - } -} - -func readCompares(r *bufio.Reader) (cmps []clientv3.Cmp) { - for { - line, err := r.ReadString('\n') - if err != nil { - ExitWithError(ExitInvalidInput, err) - } - - // remove space from the line - line = strings.TrimSpace(line) - if len(line) == 0 { - break - } - - cmp, err := parseCompare(line) - if err != nil { - ExitWithError(ExitInvalidInput, err) - } - cmps = append(cmps, *cmp) - } - - return cmps -} - -func readOps(r *bufio.Reader) (ops []clientv3.Op) { - for { - line, err := r.ReadString('\n') - if err != nil { - ExitWithError(ExitInvalidInput, err) - } - - // remove space from the line - line = strings.TrimSpace(line) - if len(line) == 0 { - break - } - - op, err := parseRequestUnion(line) - if err != nil { - ExitWithError(ExitInvalidInput, err) - } - ops = append(ops, *op) - } - - return ops -} - -func parseRequestUnion(line string) (*clientv3.Op, error) { - args := argify(line) - if len(args) < 2 { - return nil, fmt.Errorf("invalid txn compare request: %s", line) - } - - opc := make(chan clientv3.Op, 1) - - put := NewPutCommand() - put.Run = func(cmd *cobra.Command, args []string) { - key, value, opts := getPutOp(cmd, args) - opc <- clientv3.OpPut(key, value, opts...) - } - get := NewGetCommand() - get.Run = func(cmd *cobra.Command, args []string) { - key, opts := getGetOp(cmd, args) - opc <- clientv3.OpGet(key, opts...) - } - del := NewDelCommand() - del.Run = func(cmd *cobra.Command, args []string) { - key, opts := getDelOp(cmd, args) - opc <- clientv3.OpDelete(key, opts...) - } - cmds := &cobra.Command{SilenceErrors: true} - cmds.AddCommand(put, get, del) - - cmds.SetArgs(args) - if err := cmds.Execute(); err != nil { - return nil, fmt.Errorf("invalid txn request: %s", line) - } - - op := <-opc - return &op, nil -} - -func parseCompare(line string) (*clientv3.Cmp, error) { - var ( - key string - op string - val string - ) - - lparenSplit := strings.SplitN(line, "(", 2) - if len(lparenSplit) != 2 { - return nil, fmt.Errorf("malformed comparison: %s", line) - } - - target := lparenSplit[0] - n, serr := fmt.Sscanf(lparenSplit[1], "%q) %s %q", &key, &op, &val) - if n != 3 { - return nil, fmt.Errorf("malformed comparison: %s; got %s(%q) %s %q", line, target, key, op, val) - } - if serr != nil { - return nil, fmt.Errorf("malformed comparison: %s (%v)", line, serr) - } - - var ( - v int64 - err error - cmp clientv3.Cmp - ) - switch target { - case "ver", "version": - if v, err = strconv.ParseInt(val, 10, 64); err == nil { - cmp = clientv3.Compare(clientv3.Version(key), op, v) - } - case "c", "create": - if v, err = strconv.ParseInt(val, 10, 64); err == nil { - cmp = clientv3.Compare(clientv3.CreateRevision(key), op, v) - } - case "m", "mod": - if v, err = strconv.ParseInt(val, 10, 64); err == nil { - cmp = clientv3.Compare(clientv3.ModRevision(key), op, v) - } - case "val", "value": - cmp = clientv3.Compare(clientv3.Value(key), op, val) - case "lease": - cmp = clientv3.Compare(clientv3.Cmp{Target: pb.Compare_LEASE}, op, val) - default: - return nil, fmt.Errorf("malformed comparison: %s (unknown target %s)", line, target) - } - - if err != nil { - return nil, fmt.Errorf("invalid txn compare request: %s", line) - } - - return &cmp, nil -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/user_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/user_command.go deleted file mode 100644 index 4df56f720a19..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/user_command.go +++ /dev/null @@ -1,280 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "fmt" - "strings" - - "github.com/bgentry/speakeasy" - "github.com/spf13/cobra" -) - -var ( - userShowDetail bool -) - -// NewUserCommand returns the cobra command for "user". -func NewUserCommand() *cobra.Command { - ac := &cobra.Command{ - Use: "user ", - Short: "User related commands", - } - - ac.AddCommand(newUserAddCommand()) - ac.AddCommand(newUserDeleteCommand()) - ac.AddCommand(newUserGetCommand()) - ac.AddCommand(newUserListCommand()) - ac.AddCommand(newUserChangePasswordCommand()) - ac.AddCommand(newUserGrantRoleCommand()) - ac.AddCommand(newUserRevokeRoleCommand()) - - return ac -} - -var ( - passwordInteractive bool -) - -func newUserAddCommand() *cobra.Command { - cmd := cobra.Command{ - Use: "add [options]", - Short: "Adds a new user", - Run: userAddCommandFunc, - } - - cmd.Flags().BoolVar(&passwordInteractive, "interactive", true, "Read password from stdin instead of interactive terminal") - - return &cmd -} - -func newUserDeleteCommand() *cobra.Command { - return &cobra.Command{ - Use: "delete ", - Short: "Deletes a user", - Run: userDeleteCommandFunc, - } -} - -func newUserGetCommand() *cobra.Command { - cmd := cobra.Command{ - Use: "get [options]", - Short: "Gets detailed information of a user", - Run: userGetCommandFunc, - } - - cmd.Flags().BoolVar(&userShowDetail, "detail", false, "Show permissions of roles granted to the user") - - return &cmd -} - -func newUserListCommand() *cobra.Command { - return &cobra.Command{ - Use: "list", - Short: "Lists all users", - Run: userListCommandFunc, - } -} - -func newUserChangePasswordCommand() *cobra.Command { - cmd := cobra.Command{ - Use: "passwd [options]", - Short: "Changes password of user", - Run: userChangePasswordCommandFunc, - } - - cmd.Flags().BoolVar(&passwordInteractive, "interactive", true, "If true, read password from stdin instead of interactive terminal") - - return &cmd -} - -func newUserGrantRoleCommand() *cobra.Command { - return &cobra.Command{ - Use: "grant-role ", - Short: "Grants a role to a user", - Run: userGrantRoleCommandFunc, - } -} - -func newUserRevokeRoleCommand() *cobra.Command { - return &cobra.Command{ - Use: "revoke-role ", - Short: "Revokes a role from a user", - Run: userRevokeRoleCommandFunc, - } -} - -// userAddCommandFunc executes the "user add" command. -func userAddCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("user add command requires user name as its argument.")) - } - - var password string - var user string - - splitted := strings.SplitN(args[0], ":", 2) - if len(splitted) < 2 { - user = args[0] - if !passwordInteractive { - fmt.Scanf("%s", &password) - } else { - password = readPasswordInteractive(args[0]) - } - } else { - user = splitted[0] - password = splitted[1] - if len(user) == 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("empty user name is not allowed.")) - } - } - - resp, err := mustClientFromCmd(cmd).Auth.UserAdd(context.TODO(), user, password) - if err != nil { - ExitWithError(ExitError, err) - } - - display.UserAdd(user, *resp) -} - -// userDeleteCommandFunc executes the "user delete" command. -func userDeleteCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("user delete command requires user name as its argument.")) - } - - resp, err := mustClientFromCmd(cmd).Auth.UserDelete(context.TODO(), args[0]) - if err != nil { - ExitWithError(ExitError, err) - } - display.UserDelete(args[0], *resp) -} - -// userGetCommandFunc executes the "user get" command. -func userGetCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("user get command requires user name as its argument.")) - } - - name := args[0] - client := mustClientFromCmd(cmd) - resp, err := client.Auth.UserGet(context.TODO(), name) - if err != nil { - ExitWithError(ExitError, err) - } - - if userShowDetail { - fmt.Printf("User: %s\n", name) - for _, role := range resp.Roles { - fmt.Printf("\n") - roleResp, err := client.Auth.RoleGet(context.TODO(), role) - if err != nil { - ExitWithError(ExitError, err) - } - display.RoleGet(role, *roleResp) - } - } else { - display.UserGet(name, *resp) - } -} - -// userListCommandFunc executes the "user list" command. -func userListCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("user list command requires no arguments.")) - } - - resp, err := mustClientFromCmd(cmd).Auth.UserList(context.TODO()) - if err != nil { - ExitWithError(ExitError, err) - } - - display.UserList(*resp) -} - -// userChangePasswordCommandFunc executes the "user passwd" command. -func userChangePasswordCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ExitWithError(ExitBadArgs, fmt.Errorf("user passwd command requires user name as its argument.")) - } - - var password string - - if !passwordInteractive { - fmt.Scanf("%s", &password) - } else { - password = readPasswordInteractive(args[0]) - } - - resp, err := mustClientFromCmd(cmd).Auth.UserChangePassword(context.TODO(), args[0], password) - if err != nil { - ExitWithError(ExitError, err) - } - - display.UserChangePassword(*resp) -} - -// userGrantRoleCommandFunc executes the "user grant-role" command. -func userGrantRoleCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 2 { - ExitWithError(ExitBadArgs, fmt.Errorf("user grant command requires user name and role name as its argument.")) - } - - resp, err := mustClientFromCmd(cmd).Auth.UserGrantRole(context.TODO(), args[0], args[1]) - if err != nil { - ExitWithError(ExitError, err) - } - - display.UserGrantRole(args[0], args[1], *resp) -} - -// userRevokeRoleCommandFunc executes the "user revoke-role" command. -func userRevokeRoleCommandFunc(cmd *cobra.Command, args []string) { - if len(args) != 2 { - ExitWithError(ExitBadArgs, fmt.Errorf("user revoke-role requires user name and role name as its argument.")) - } - - resp, err := mustClientFromCmd(cmd).Auth.UserRevokeRole(context.TODO(), args[0], args[1]) - if err != nil { - ExitWithError(ExitError, err) - } - - display.UserRevokeRole(args[0], args[1], *resp) -} - -func readPasswordInteractive(name string) string { - prompt1 := fmt.Sprintf("Password of %s: ", name) - password1, err1 := speakeasy.Ask(prompt1) - if err1 != nil { - ExitWithError(ExitBadArgs, fmt.Errorf("failed to ask password: %s.", err1)) - } - - if len(password1) == 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("empty password")) - } - - prompt2 := fmt.Sprintf("Type password of %s again for confirmation: ", name) - password2, err2 := speakeasy.Ask(prompt2) - if err2 != nil { - ExitWithError(ExitBadArgs, fmt.Errorf("failed to ask password: %s.", err2)) - } - - if strings.Compare(password1, password2) != 0 { - ExitWithError(ExitBadArgs, fmt.Errorf("given passwords are different.")) - } - - return password1 -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/util.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/util.go deleted file mode 100644 index addd023db08f..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/util.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "context" - "encoding/hex" - "fmt" - "regexp" - - pb "github.com/coreos/etcd/mvcc/mvccpb" - - "github.com/spf13/cobra" -) - -func printKV(isHex bool, valueOnly bool, kv *pb.KeyValue) { - k, v := string(kv.Key), string(kv.Value) - if isHex { - k = addHexPrefix(hex.EncodeToString(kv.Key)) - v = addHexPrefix(hex.EncodeToString(kv.Value)) - } - if !valueOnly { - fmt.Println(k) - } - fmt.Println(v) -} - -func addHexPrefix(s string) string { - ns := make([]byte, len(s)*2) - for i := 0; i < len(s); i += 2 { - ns[i*2] = '\\' - ns[i*2+1] = 'x' - ns[i*2+2] = s[i] - ns[i*2+3] = s[i+1] - } - return string(ns) -} - -func argify(s string) []string { - r := regexp.MustCompile(`"(?:[^"\\]|\\.)*"|'[^']*'|[^'"\s]\S*[^'"\s]?`) - args := r.FindAllString(s, -1) - for i := range args { - if len(args[i]) == 0 { - continue - } - if args[i][0] == '\'' { - // 'single-quoted string' - args[i] = args[i][1 : len(args)-1] - } else if args[i][0] == '"' { - // "double quoted string" - if _, err := fmt.Sscanf(args[i], "%q", &args[i]); err != nil { - ExitWithError(ExitInvalidInput, err) - } - } - } - return args -} - -func commandCtx(cmd *cobra.Command) (context.Context, context.CancelFunc) { - timeOut, err := cmd.Flags().GetDuration("command-timeout") - if err != nil { - ExitWithError(ExitError, err) - } - return context.WithTimeout(context.Background(), timeOut) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/version_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/version_command.go deleted file mode 100644 index 9fa990f1f4c1..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/version_command.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "fmt" - - "github.com/coreos/etcd/version" - "github.com/spf13/cobra" -) - -// NewVersionCommand prints out the version of etcd. -func NewVersionCommand() *cobra.Command { - return &cobra.Command{ - Use: "version", - Short: "Prints the version of etcdctl", - Run: versionCommandFunc, - } -} - -func versionCommandFunc(cmd *cobra.Command, args []string) { - fmt.Println("etcdctl version:", version.Version) - fmt.Println("API version:", version.APIVersion) -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/watch_command.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/watch_command.go deleted file mode 100644 index 1a2cc4213f5b..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/command/watch_command.go +++ /dev/null @@ -1,347 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package command - -import ( - "bufio" - "context" - "errors" - "fmt" - "os" - "os/exec" - "strings" - - "github.com/coreos/etcd/clientv3" - - "github.com/spf13/cobra" -) - -var ( - errBadArgsNum = errors.New("bad number of arguments") - errBadArgsNumConflictEnv = errors.New("bad number of arguments (found conflicting environment key)") - errBadArgsNumSeparator = errors.New("bad number of arguments (found separator --, but no commands)") - errBadArgsInteractiveWatch = errors.New("args[0] must be 'watch' for interactive calls") -) - -var ( - watchRev int64 - watchPrefix bool - watchInteractive bool - watchPrevKey bool -) - -// NewWatchCommand returns the cobra command for "watch". -func NewWatchCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "watch [options] [key or prefix] [range_end] [--] [exec-command arg1 arg2 ...]", - Short: "Watches events stream on keys or prefixes", - Run: watchCommandFunc, - } - - cmd.Flags().BoolVarP(&watchInteractive, "interactive", "i", false, "Interactive mode") - cmd.Flags().BoolVar(&watchPrefix, "prefix", false, "Watch on a prefix if prefix is set") - cmd.Flags().Int64Var(&watchRev, "rev", 0, "Revision to start watching") - cmd.Flags().BoolVar(&watchPrevKey, "prev-kv", false, "get the previous key-value pair before the event happens") - - return cmd -} - -// watchCommandFunc executes the "watch" command. -func watchCommandFunc(cmd *cobra.Command, args []string) { - envKey, envRange := os.Getenv("ETCDCTL_WATCH_KEY"), os.Getenv("ETCDCTL_WATCH_RANGE_END") - if envKey == "" && envRange != "" { - ExitWithError(ExitBadArgs, fmt.Errorf("ETCDCTL_WATCH_KEY is empty but got ETCDCTL_WATCH_RANGE_END=%q", envRange)) - } - - if watchInteractive { - watchInteractiveFunc(cmd, os.Args, envKey, envRange) - return - } - - watchArgs, execArgs, err := parseWatchArgs(os.Args, args, envKey, envRange, false) - if err != nil { - ExitWithError(ExitBadArgs, err) - } - - c := mustClientFromCmd(cmd) - wc, err := getWatchChan(c, watchArgs) - if err != nil { - ExitWithError(ExitBadArgs, err) - } - - printWatchCh(c, wc, execArgs) - if err = c.Close(); err != nil { - ExitWithError(ExitBadConnection, err) - } - ExitWithError(ExitInterrupted, fmt.Errorf("watch is canceled by the server")) -} - -func watchInteractiveFunc(cmd *cobra.Command, osArgs []string, envKey, envRange string) { - c := mustClientFromCmd(cmd) - - reader := bufio.NewReader(os.Stdin) - - for { - l, err := reader.ReadString('\n') - if err != nil { - ExitWithError(ExitInvalidInput, fmt.Errorf("Error reading watch request line: %v", err)) - } - l = strings.TrimSuffix(l, "\n") - - args := argify(l) - if len(args) < 2 && envKey == "" { - fmt.Fprintf(os.Stderr, "Invalid command %s (command type or key is not provided)\n", l) - continue - } - - if args[0] != "watch" { - fmt.Fprintf(os.Stderr, "Invalid command %s (only support watch)\n", l) - continue - } - - watchArgs, execArgs, perr := parseWatchArgs(osArgs, args, envKey, envRange, true) - if perr != nil { - ExitWithError(ExitBadArgs, perr) - } - - ch, err := getWatchChan(c, watchArgs) - if err != nil { - fmt.Fprintf(os.Stderr, "Invalid command %s (%v)\n", l, err) - continue - } - go printWatchCh(c, ch, execArgs) - } -} - -func getWatchChan(c *clientv3.Client, args []string) (clientv3.WatchChan, error) { - if len(args) < 1 { - return nil, errBadArgsNum - } - - key := args[0] - opts := []clientv3.OpOption{clientv3.WithRev(watchRev)} - if len(args) == 2 { - if watchPrefix { - return nil, fmt.Errorf("`range_end` and `--prefix` are mutually exclusive") - } - opts = append(opts, clientv3.WithRange(args[1])) - } - if watchPrefix { - opts = append(opts, clientv3.WithPrefix()) - } - if watchPrevKey { - opts = append(opts, clientv3.WithPrevKV()) - } - return c.Watch(clientv3.WithRequireLeader(context.Background()), key, opts...), nil -} - -func printWatchCh(c *clientv3.Client, ch clientv3.WatchChan, execArgs []string) { - for resp := range ch { - if resp.Canceled { - fmt.Fprintf(os.Stderr, "watch was canceled (%v)\n", resp.Err()) - } - display.Watch(resp) - - if len(execArgs) > 0 { - for _, ev := range resp.Events { - cmd := exec.CommandContext(c.Ctx(), execArgs[0], execArgs[1:]...) - cmd.Env = os.Environ() - cmd.Env = append(cmd.Env, fmt.Sprintf("ETCD_WATCH_REVISION=%d", resp.Header.Revision)) - cmd.Env = append(cmd.Env, fmt.Sprintf("ETCD_WATCH_EVENT_TYPE=%q", ev.Type)) - cmd.Env = append(cmd.Env, fmt.Sprintf("ETCD_WATCH_KEY=%q", ev.Kv.Key)) - cmd.Env = append(cmd.Env, fmt.Sprintf("ETCD_WATCH_VALUE=%q", ev.Kv.Value)) - cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr - if err := cmd.Run(); err != nil { - fmt.Fprintf(os.Stderr, "command %q error (%v)\n", execArgs, err) - os.Exit(1) - } - } - } - } -} - -// "commandArgs" is the command arguments after "spf13/cobra" parses -// all "watch" command flags, strips out special characters (e.g. "--"). -// "orArgs" is the raw arguments passed to "watch" command -// (e.g. ./bin/etcdctl watch foo --rev 1 bar). -// "--" characters are invalid arguments for "spf13/cobra" library, -// so no need to handle such cases. -func parseWatchArgs(osArgs, commandArgs []string, envKey, envRange string, interactive bool) (watchArgs []string, execArgs []string, err error) { - rawArgs := make([]string, len(osArgs)) - copy(rawArgs, osArgs) - watchArgs = make([]string, len(commandArgs)) - copy(watchArgs, commandArgs) - - // remove preceding commands (e.g. ./bin/etcdctl watch) - // handle "./bin/etcdctl watch foo -- echo watch event" - for idx := range rawArgs { - if rawArgs[idx] == "watch" { - rawArgs = rawArgs[idx+1:] - break - } - } - - // remove preceding commands (e.g. "watch foo bar" in interactive mode) - // handle "./bin/etcdctl watch foo -- echo watch event" - if interactive { - if watchArgs[0] != "watch" { - // "watch" not found - watchPrefix, watchRev, watchPrevKey = false, 0, false - return nil, nil, errBadArgsInteractiveWatch - } - watchArgs = watchArgs[1:] - } - - execIdx, execExist := 0, false - if !interactive { - for execIdx = range rawArgs { - if rawArgs[execIdx] == "--" { - execExist = true - break - } - } - if execExist && execIdx == len(rawArgs)-1 { - // "watch foo bar --" should error - return nil, nil, errBadArgsNumSeparator - } - // "watch" with no argument should error - if !execExist && len(rawArgs) < 1 && envKey == "" { - return nil, nil, errBadArgsNum - } - if execExist && envKey != "" { - // "ETCDCTL_WATCH_KEY=foo watch foo -- echo 1" should error - // (watchArgs==["foo","echo","1"]) - widx, ridx := len(watchArgs)-1, len(rawArgs)-1 - for ; widx >= 0; widx-- { - if watchArgs[widx] == rawArgs[ridx] { - ridx-- - continue - } - // watchArgs has extra: - // ETCDCTL_WATCH_KEY=foo watch foo -- echo 1 - // watchArgs: foo echo 1 - if ridx == execIdx { - return nil, nil, errBadArgsNumConflictEnv - } - } - } - // check conflicting arguments - // e.g. "watch --rev 1 -- echo Hello World" has no conflict - if !execExist && len(watchArgs) > 0 && envKey != "" { - // "ETCDCTL_WATCH_KEY=foo watch foo" should error - // (watchArgs==["foo"]) - return nil, nil, errBadArgsNumConflictEnv - } - } else { - for execIdx = range watchArgs { - if watchArgs[execIdx] == "--" { - execExist = true - break - } - } - if execExist && execIdx == len(watchArgs)-1 { - // "watch foo bar --" should error - watchPrefix, watchRev, watchPrevKey = false, 0, false - return nil, nil, errBadArgsNumSeparator - } - - flagset := NewWatchCommand().Flags() - if err := flagset.Parse(watchArgs); err != nil { - watchPrefix, watchRev, watchPrevKey = false, 0, false - return nil, nil, err - } - pArgs := flagset.Args() - - // "watch" with no argument should error - if !execExist && envKey == "" && len(pArgs) < 1 { - watchPrefix, watchRev, watchPrevKey = false, 0, false - return nil, nil, errBadArgsNum - } - // check conflicting arguments - // e.g. "watch --rev 1 -- echo Hello World" has no conflict - if !execExist && len(pArgs) > 0 && envKey != "" { - // "ETCDCTL_WATCH_KEY=foo watch foo" should error - // (watchArgs==["foo"]) - watchPrefix, watchRev, watchPrevKey = false, 0, false - return nil, nil, errBadArgsNumConflictEnv - } - } - - argsWithSep := rawArgs - if interactive { - // interactive mode directly passes "--" to the command args - argsWithSep = watchArgs - } - - idx, foundSep := 0, false - for idx = range argsWithSep { - if argsWithSep[idx] == "--" { - foundSep = true - break - } - } - if foundSep { - execArgs = argsWithSep[idx+1:] - } - - if interactive { - flagset := NewWatchCommand().Flags() - if err := flagset.Parse(argsWithSep); err != nil { - return nil, nil, err - } - watchArgs = flagset.Args() - - watchPrefix, err = flagset.GetBool("prefix") - if err != nil { - return nil, nil, err - } - watchRev, err = flagset.GetInt64("rev") - if err != nil { - return nil, nil, err - } - watchPrevKey, err = flagset.GetBool("prev-kv") - if err != nil { - return nil, nil, err - } - } - - // "ETCDCTL_WATCH_KEY=foo watch -- echo hello" - // should translate "watch foo -- echo hello" - // (watchArgs=["echo","hello"] should be ["foo","echo","hello"]) - if envKey != "" { - ranges := []string{envKey} - if envRange != "" { - ranges = append(ranges, envRange) - } - watchArgs = append(ranges, watchArgs...) - } - - if !foundSep { - return watchArgs, nil, nil - } - - // "watch foo bar --rev 1 -- echo hello" or "watch foo --rev 1 bar -- echo hello", - // then "watchArgs" is "foo bar echo hello" - // so need ignore args after "argsWithSep[idx]", which is "--" - endIdx := 0 - for endIdx = len(watchArgs) - 1; endIdx >= 0; endIdx-- { - if watchArgs[endIdx] == argsWithSep[idx+1] { - break - } - } - watchArgs = watchArgs[:endIdx] - - return watchArgs, execArgs, nil -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/ctl.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/ctl.go deleted file mode 100644 index 8692084cfcdf..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/ctl.go +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package ctlv3 contains the main entry point for the etcdctl for v3 API. -package ctlv3 - -import ( - "time" - - "github.com/coreos/etcd/etcdctl/ctlv3/command" - "github.com/spf13/cobra" -) - -const ( - cliName = "etcdctl" - cliDescription = "A simple command line client for etcd3." - - defaultDialTimeout = 2 * time.Second - defaultCommandTimeOut = 5 * time.Second - defaultKeepAliveTime = 2 * time.Second - defaultKeepAliveTimeOut = 6 * time.Second -) - -var ( - globalFlags = command.GlobalFlags{} -) - -var ( - rootCmd = &cobra.Command{ - Use: cliName, - Short: cliDescription, - SuggestFor: []string{"etcdctl"}, - } -) - -func init() { - rootCmd.PersistentFlags().StringSliceVar(&globalFlags.Endpoints, "endpoints", []string{"127.0.0.1:2379"}, "gRPC endpoints") - rootCmd.PersistentFlags().BoolVar(&globalFlags.Debug, "debug", false, "enable client-side debug logging") - - rootCmd.PersistentFlags().StringVarP(&globalFlags.OutputFormat, "write-out", "w", "simple", "set the output format (fields, json, protobuf, simple, table)") - rootCmd.PersistentFlags().BoolVar(&globalFlags.IsHex, "hex", false, "print byte strings as hex encoded strings") - - rootCmd.PersistentFlags().DurationVar(&globalFlags.DialTimeout, "dial-timeout", defaultDialTimeout, "dial timeout for client connections") - rootCmd.PersistentFlags().DurationVar(&globalFlags.CommandTimeOut, "command-timeout", defaultCommandTimeOut, "timeout for short running command (excluding dial timeout)") - rootCmd.PersistentFlags().DurationVar(&globalFlags.KeepAliveTime, "keepalive-time", defaultKeepAliveTime, "keepalive time for client connections") - rootCmd.PersistentFlags().DurationVar(&globalFlags.KeepAliveTimeout, "keepalive-timeout", defaultKeepAliveTimeOut, "keepalive timeout for client connections") - - // TODO: secure by default when etcd enables secure gRPC by default. - rootCmd.PersistentFlags().BoolVar(&globalFlags.Insecure, "insecure-transport", true, "disable transport security for client connections") - rootCmd.PersistentFlags().BoolVar(&globalFlags.InsecureDiscovery, "insecure-discovery", true, "accept insecure SRV records describing cluster endpoints") - rootCmd.PersistentFlags().BoolVar(&globalFlags.InsecureSkipVerify, "insecure-skip-tls-verify", false, "skip server certificate verification") - rootCmd.PersistentFlags().StringVar(&globalFlags.TLS.CertFile, "cert", "", "identify secure client using this TLS certificate file") - rootCmd.PersistentFlags().StringVar(&globalFlags.TLS.KeyFile, "key", "", "identify secure client using this TLS key file") - rootCmd.PersistentFlags().StringVar(&globalFlags.TLS.CAFile, "cacert", "", "verify certificates of TLS-enabled secure servers using this CA bundle") - rootCmd.PersistentFlags().StringVar(&globalFlags.User, "user", "", "username[:password] for authentication (prompt if password is not supplied)") - rootCmd.PersistentFlags().StringVarP(&globalFlags.TLS.ServerName, "discovery-srv", "d", "", "domain name to query for SRV records describing cluster endpoints") - - rootCmd.AddCommand( - command.NewGetCommand(), - command.NewPutCommand(), - command.NewDelCommand(), - command.NewTxnCommand(), - command.NewCompactionCommand(), - command.NewAlarmCommand(), - command.NewDefragCommand(), - command.NewEndpointCommand(), - command.NewMoveLeaderCommand(), - command.NewWatchCommand(), - command.NewVersionCommand(), - command.NewLeaseCommand(), - command.NewMemberCommand(), - command.NewSnapshotCommand(), - command.NewMakeMirrorCommand(), - command.NewMigrateCommand(), - command.NewLockCommand(), - command.NewElectCommand(), - command.NewAuthCommand(), - command.NewUserCommand(), - command.NewRoleCommand(), - command.NewCheckCommand(), - ) -} - -func init() { - cobra.EnablePrefixMatching = true -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/ctl_cov.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/ctl_cov.go deleted file mode 100644 index 6908113a7a9f..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/ctl_cov.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build cov - -package ctlv3 - -import ( - "os" - "strings" - - "github.com/coreos/etcd/etcdctl/ctlv3/command" -) - -func Start() { - // ETCDCTL_ARGS=etcdctl_test arg1 arg2... - // SetArgs() takes arg1 arg2... - rootCmd.SetArgs(strings.Split(os.Getenv("ETCDCTL_ARGS"), "\xe7\xcd")[1:]) - os.Unsetenv("ETCDCTL_ARGS") - if err := rootCmd.Execute(); err != nil { - command.ExitWithError(command.ExitError, err) - } -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/ctl_nocov.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/ctl_nocov.go deleted file mode 100644 index 52751feec3e2..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/ctl_nocov.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !cov - -package ctlv3 - -import "github.com/coreos/etcd/etcdctl/ctlv3/command" - -func Start() { - rootCmd.SetUsageFunc(usageFunc) - // Make help just show the usage - rootCmd.SetHelpTemplate(`{{.UsageString}}`) - if err := rootCmd.Execute(); err != nil { - command.ExitWithError(command.ExitError, err) - } -} diff --git a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/help.go b/vendor/go.etcd.io/etcd/etcdctl/ctlv3/help.go deleted file mode 100644 index 1315a03cb250..000000000000 --- a/vendor/go.etcd.io/etcd/etcdctl/ctlv3/help.go +++ /dev/null @@ -1,174 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// copied from https://github.com/rkt/rkt/blob/master/rkt/help.go - -package ctlv3 - -import ( - "bytes" - "fmt" - "io" - "os" - "strings" - "text/tabwriter" - "text/template" - - "github.com/coreos/etcd/version" - "github.com/spf13/cobra" - "github.com/spf13/pflag" -) - -var ( - commandUsageTemplate *template.Template - templFuncs = template.FuncMap{ - "descToLines": func(s string) []string { - // trim leading/trailing whitespace and split into slice of lines - return strings.Split(strings.Trim(s, "\n\t "), "\n") - }, - "cmdName": func(cmd *cobra.Command, startCmd *cobra.Command) string { - parts := []string{cmd.Name()} - for cmd.HasParent() && cmd.Parent().Name() != startCmd.Name() { - cmd = cmd.Parent() - parts = append([]string{cmd.Name()}, parts...) - } - return strings.Join(parts, " ") - }, - } -) - -func init() { - commandUsage := ` -{{ $cmd := .Cmd }}\ -{{ $cmdname := cmdName .Cmd .Cmd.Root }}\ -NAME: -{{ if not .Cmd.HasParent }}\ -{{printf "\t%s - %s" .Cmd.Name .Cmd.Short}} -{{else}}\ -{{printf "\t%s - %s" $cmdname .Cmd.Short}} -{{end}}\ - -USAGE: -{{printf "\t%s" .Cmd.UseLine}} -{{ if not .Cmd.HasParent }}\ - -VERSION: -{{printf "\t%s" .Version}} -{{end}}\ -{{if .Cmd.HasSubCommands}}\ - -API VERSION: -{{printf "\t%s" .APIVersion}} -{{end}}\ -{{if .Cmd.HasSubCommands}}\ - - -COMMANDS: -{{range .SubCommands}}\ -{{ $cmdname := cmdName . $cmd }}\ -{{ if .Runnable }}\ -{{printf "\t%s\t%s" $cmdname .Short}} -{{end}}\ -{{end}}\ -{{end}}\ -{{ if .Cmd.Long }}\ - -DESCRIPTION: -{{range $line := descToLines .Cmd.Long}}{{printf "\t%s" $line}} -{{end}}\ -{{end}}\ -{{if .Cmd.HasLocalFlags}}\ - -OPTIONS: -{{.LocalFlags}}\ -{{end}}\ -{{if .Cmd.HasInheritedFlags}}\ - -GLOBAL OPTIONS: -{{.GlobalFlags}}\ -{{end}} -`[1:] - - commandUsageTemplate = template.Must(template.New("command_usage").Funcs(templFuncs).Parse(strings.Replace(commandUsage, "\\\n", "", -1))) -} - -func etcdFlagUsages(flagSet *pflag.FlagSet) string { - x := new(bytes.Buffer) - - flagSet.VisitAll(func(flag *pflag.Flag) { - if len(flag.Deprecated) > 0 { - return - } - var format string - if len(flag.Shorthand) > 0 { - format = " -%s, --%s" - } else { - format = " %s --%s" - } - if len(flag.NoOptDefVal) > 0 { - format = format + "[" - } - if flag.Value.Type() == "string" { - // put quotes on the value - format = format + "=%q" - } else { - format = format + "=%s" - } - if len(flag.NoOptDefVal) > 0 { - format = format + "]" - } - format = format + "\t%s\n" - shorthand := flag.Shorthand - fmt.Fprintf(x, format, shorthand, flag.Name, flag.DefValue, flag.Usage) - }) - - return x.String() -} - -func getSubCommands(cmd *cobra.Command) []*cobra.Command { - var subCommands []*cobra.Command - for _, subCmd := range cmd.Commands() { - subCommands = append(subCommands, subCmd) - subCommands = append(subCommands, getSubCommands(subCmd)...) - } - return subCommands -} - -func usageFunc(cmd *cobra.Command) error { - subCommands := getSubCommands(cmd) - tabOut := getTabOutWithWriter(os.Stdout) - commandUsageTemplate.Execute(tabOut, struct { - Cmd *cobra.Command - LocalFlags string - GlobalFlags string - SubCommands []*cobra.Command - Version string - APIVersion string - }{ - cmd, - etcdFlagUsages(cmd.LocalFlags()), - etcdFlagUsages(cmd.InheritedFlags()), - subCommands, - version.Version, - version.APIVersion, - }) - tabOut.Flush() - return nil -} - -func getTabOutWithWriter(writer io.Writer) *tabwriter.Writer { - aTabOut := new(tabwriter.Writer) - aTabOut.Init(writer, 0, 8, 1, '\t', 0) - return aTabOut -} diff --git a/vendor/go.etcd.io/etcd/etcdmain/config.go b/vendor/go.etcd.io/etcd/etcdmain/config.go deleted file mode 100644 index 2a5faa746c9a..000000000000 --- a/vendor/go.etcd.io/etcd/etcdmain/config.go +++ /dev/null @@ -1,346 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Every change should be reflected on help.go as well. - -package etcdmain - -import ( - "flag" - "fmt" - "io/ioutil" - "net/url" - "os" - "runtime" - "strings" - - "github.com/coreos/etcd/embed" - "github.com/coreos/etcd/pkg/flags" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/version" - - "github.com/ghodss/yaml" -) - -var ( - proxyFlagOff = "off" - proxyFlagReadonly = "readonly" - proxyFlagOn = "on" - - fallbackFlagExit = "exit" - fallbackFlagProxy = "proxy" - - ignored = []string{ - "cluster-active-size", - "cluster-remove-delay", - "cluster-sync-interval", - "config", - "force", - "max-result-buffer", - "max-retry-attempts", - "peer-heartbeat-interval", - "peer-election-timeout", - "retry-interval", - "snapshot", - "v", - "vv", - // for coverage testing - "test.coverprofile", - "test.outputdir", - } -) - -type configProxy struct { - ProxyFailureWaitMs uint `json:"proxy-failure-wait"` - ProxyRefreshIntervalMs uint `json:"proxy-refresh-interval"` - ProxyDialTimeoutMs uint `json:"proxy-dial-timeout"` - ProxyWriteTimeoutMs uint `json:"proxy-write-timeout"` - ProxyReadTimeoutMs uint `json:"proxy-read-timeout"` - Fallback string - Proxy string - ProxyJSON string `json:"proxy"` - FallbackJSON string `json:"discovery-fallback"` -} - -// config holds the config for a command line invocation of etcd -type config struct { - ec embed.Config - cp configProxy - cf configFlags - configFile string - printVersion bool - ignored []string -} - -// configFlags has the set of flags used for command line parsing a Config -type configFlags struct { - flagSet *flag.FlagSet - clusterState *flags.StringsFlag - fallback *flags.StringsFlag - proxy *flags.StringsFlag -} - -func newConfig() *config { - cfg := &config{ - ec: *embed.NewConfig(), - cp: configProxy{ - Proxy: proxyFlagOff, - ProxyFailureWaitMs: 5000, - ProxyRefreshIntervalMs: 30000, - ProxyDialTimeoutMs: 1000, - ProxyWriteTimeoutMs: 5000, - }, - ignored: ignored, - } - cfg.cf = configFlags{ - flagSet: flag.NewFlagSet("etcd", flag.ContinueOnError), - clusterState: flags.NewStringsFlag( - embed.ClusterStateFlagNew, - embed.ClusterStateFlagExisting, - ), - fallback: flags.NewStringsFlag( - fallbackFlagProxy, - fallbackFlagExit, - ), - proxy: flags.NewStringsFlag( - proxyFlagOff, - proxyFlagReadonly, - proxyFlagOn, - ), - } - - fs := cfg.cf.flagSet - fs.Usage = func() { - fmt.Fprintln(os.Stderr, usageline) - } - - fs.StringVar(&cfg.configFile, "config-file", "", "Path to the server configuration file") - - // member - fs.Var(cfg.ec.CorsInfo, "cors", "Comma-separated white list of origins for CORS (cross-origin resource sharing).") - fs.StringVar(&cfg.ec.Dir, "data-dir", cfg.ec.Dir, "Path to the data directory.") - fs.StringVar(&cfg.ec.WalDir, "wal-dir", cfg.ec.WalDir, "Path to the dedicated wal directory.") - fs.Var(flags.NewURLsValue(embed.DefaultListenPeerURLs), "listen-peer-urls", "List of URLs to listen on for peer traffic.") - fs.Var(flags.NewURLsValue(embed.DefaultListenClientURLs), "listen-client-urls", "List of URLs to listen on for client traffic.") - fs.StringVar(&cfg.ec.ListenMetricsUrlsJSON, "listen-metrics-urls", "", "List of URLs to listen on for metrics.") - fs.UintVar(&cfg.ec.MaxSnapFiles, "max-snapshots", cfg.ec.MaxSnapFiles, "Maximum number of snapshot files to retain (0 is unlimited).") - fs.UintVar(&cfg.ec.MaxWalFiles, "max-wals", cfg.ec.MaxWalFiles, "Maximum number of wal files to retain (0 is unlimited).") - fs.StringVar(&cfg.ec.Name, "name", cfg.ec.Name, "Human-readable name for this member.") - fs.Uint64Var(&cfg.ec.SnapCount, "snapshot-count", cfg.ec.SnapCount, "Number of committed transactions to trigger a snapshot to disk.") - fs.UintVar(&cfg.ec.TickMs, "heartbeat-interval", cfg.ec.TickMs, "Time (in milliseconds) of a heartbeat interval.") - fs.UintVar(&cfg.ec.ElectionMs, "election-timeout", cfg.ec.ElectionMs, "Time (in milliseconds) for an election to timeout.") - fs.BoolVar(&cfg.ec.InitialElectionTickAdvance, "initial-election-tick-advance", cfg.ec.InitialElectionTickAdvance, "Whether to fast-forward initial election ticks on boot for faster election.") - fs.Int64Var(&cfg.ec.QuotaBackendBytes, "quota-backend-bytes", cfg.ec.QuotaBackendBytes, "Raise alarms when backend size exceeds the given quota. 0 means use the default quota.") - fs.UintVar(&cfg.ec.MaxTxnOps, "max-txn-ops", cfg.ec.MaxTxnOps, "Maximum number of operations permitted in a transaction.") - fs.UintVar(&cfg.ec.MaxRequestBytes, "max-request-bytes", cfg.ec.MaxRequestBytes, "Maximum client request size in bytes the server will accept.") - fs.DurationVar(&cfg.ec.GRPCKeepAliveMinTime, "grpc-keepalive-min-time", cfg.ec.GRPCKeepAliveMinTime, "Minimum interval duration that a client should wait before pinging server.") - fs.DurationVar(&cfg.ec.GRPCKeepAliveInterval, "grpc-keepalive-interval", cfg.ec.GRPCKeepAliveInterval, "Frequency duration of server-to-client ping to check if a connection is alive (0 to disable).") - fs.DurationVar(&cfg.ec.GRPCKeepAliveTimeout, "grpc-keepalive-timeout", cfg.ec.GRPCKeepAliveTimeout, "Additional duration of wait before closing a non-responsive connection (0 to disable).") - - // clustering - fs.Var(flags.NewURLsValue(embed.DefaultInitialAdvertisePeerURLs), "initial-advertise-peer-urls", "List of this member's peer URLs to advertise to the rest of the cluster.") - fs.Var(flags.NewURLsValue(embed.DefaultAdvertiseClientURLs), "advertise-client-urls", "List of this member's client URLs to advertise to the public.") - fs.StringVar(&cfg.ec.Durl, "discovery", cfg.ec.Durl, "Discovery URL used to bootstrap the cluster.") - fs.Var(cfg.cf.fallback, "discovery-fallback", fmt.Sprintf("Valid values include %s", strings.Join(cfg.cf.fallback.Values, ", "))) - - fs.StringVar(&cfg.ec.Dproxy, "discovery-proxy", cfg.ec.Dproxy, "HTTP proxy to use for traffic to discovery service.") - fs.StringVar(&cfg.ec.DNSCluster, "discovery-srv", cfg.ec.DNSCluster, "DNS domain used to bootstrap initial cluster.") - fs.StringVar(&cfg.ec.InitialCluster, "initial-cluster", cfg.ec.InitialCluster, "Initial cluster configuration for bootstrapping.") - fs.StringVar(&cfg.ec.InitialClusterToken, "initial-cluster-token", cfg.ec.InitialClusterToken, "Initial cluster token for the etcd cluster during bootstrap.") - fs.Var(cfg.cf.clusterState, "initial-cluster-state", "Initial cluster state ('new' or 'existing').") - - fs.BoolVar(&cfg.ec.StrictReconfigCheck, "strict-reconfig-check", cfg.ec.StrictReconfigCheck, "Reject reconfiguration requests that would cause quorum loss.") - fs.BoolVar(&cfg.ec.EnableV2, "enable-v2", cfg.ec.EnableV2, "Accept etcd V2 client requests.") - fs.StringVar(&cfg.ec.ExperimentalEnableV2V3, "experimental-enable-v2v3", cfg.ec.ExperimentalEnableV2V3, "v3 prefix for serving emulated v2 state.") - - // proxy - fs.Var(cfg.cf.proxy, "proxy", fmt.Sprintf("Valid values include %s", strings.Join(cfg.cf.proxy.Values, ", "))) - - fs.UintVar(&cfg.cp.ProxyFailureWaitMs, "proxy-failure-wait", cfg.cp.ProxyFailureWaitMs, "Time (in milliseconds) an endpoint will be held in a failed state.") - fs.UintVar(&cfg.cp.ProxyRefreshIntervalMs, "proxy-refresh-interval", cfg.cp.ProxyRefreshIntervalMs, "Time (in milliseconds) of the endpoints refresh interval.") - fs.UintVar(&cfg.cp.ProxyDialTimeoutMs, "proxy-dial-timeout", cfg.cp.ProxyDialTimeoutMs, "Time (in milliseconds) for a dial to timeout.") - fs.UintVar(&cfg.cp.ProxyWriteTimeoutMs, "proxy-write-timeout", cfg.cp.ProxyWriteTimeoutMs, "Time (in milliseconds) for a write to timeout.") - fs.UintVar(&cfg.cp.ProxyReadTimeoutMs, "proxy-read-timeout", cfg.cp.ProxyReadTimeoutMs, "Time (in milliseconds) for a read to timeout.") - - // security - fs.StringVar(&cfg.ec.ClientTLSInfo.CAFile, "ca-file", "", "DEPRECATED: Path to the client server TLS CA file.") - fs.StringVar(&cfg.ec.ClientTLSInfo.CertFile, "cert-file", "", "Path to the client server TLS cert file.") - fs.StringVar(&cfg.ec.ClientTLSInfo.KeyFile, "key-file", "", "Path to the client server TLS key file.") - fs.BoolVar(&cfg.ec.ClientTLSInfo.ClientCertAuth, "client-cert-auth", false, "Enable client cert authentication.") - fs.StringVar(&cfg.ec.ClientTLSInfo.CRLFile, "client-crl-file", "", "Path to the client certificate revocation list file.") - fs.StringVar(&cfg.ec.ClientTLSInfo.TrustedCAFile, "trusted-ca-file", "", "Path to the client server TLS trusted CA cert file.") - fs.BoolVar(&cfg.ec.ClientAutoTLS, "auto-tls", false, "Client TLS using generated certificates") - fs.StringVar(&cfg.ec.PeerTLSInfo.CAFile, "peer-ca-file", "", "DEPRECATED: Path to the peer server TLS CA file.") - fs.StringVar(&cfg.ec.PeerTLSInfo.CertFile, "peer-cert-file", "", "Path to the peer server TLS cert file.") - fs.StringVar(&cfg.ec.PeerTLSInfo.KeyFile, "peer-key-file", "", "Path to the peer server TLS key file.") - fs.BoolVar(&cfg.ec.PeerTLSInfo.ClientCertAuth, "peer-client-cert-auth", false, "Enable peer client cert authentication.") - fs.StringVar(&cfg.ec.PeerTLSInfo.TrustedCAFile, "peer-trusted-ca-file", "", "Path to the peer server TLS trusted CA file.") - fs.BoolVar(&cfg.ec.PeerAutoTLS, "peer-auto-tls", false, "Peer TLS using generated certificates") - fs.StringVar(&cfg.ec.PeerTLSInfo.CRLFile, "peer-crl-file", "", "Path to the peer certificate revocation list file.") - fs.StringVar(&cfg.ec.PeerTLSInfo.AllowedCN, "peer-cert-allowed-cn", "", "Allowed CN for inter peer authentication.") - - fs.Var(flags.NewStringsValueV2(""), "cipher-suites", "Comma-separated list of supported TLS cipher suites between client/server and peers (empty will be auto-populated by Go).") - - // logging - fs.BoolVar(&cfg.ec.Debug, "debug", false, "Enable debug-level logging for etcd.") - fs.StringVar(&cfg.ec.LogPkgLevels, "log-package-levels", "", "Specify a particular log level for each etcd package (eg: 'etcdmain=CRITICAL,etcdserver=DEBUG').") - fs.StringVar(&cfg.ec.LogOutput, "log-output", embed.DefaultLogOutput, "Specify 'stdout' or 'stderr' to skip journald logging even when running under systemd.") - - // unsafe - fs.BoolVar(&cfg.ec.ForceNewCluster, "force-new-cluster", false, "Force to create a new one member cluster.") - - // version - fs.BoolVar(&cfg.printVersion, "version", false, "Print the version and exit.") - - fs.StringVar(&cfg.ec.AutoCompactionRetention, "auto-compaction-retention", "0", "Auto compaction retention for mvcc key value store. 0 means disable auto compaction.") - fs.StringVar(&cfg.ec.AutoCompactionMode, "auto-compaction-mode", "periodic", "interpret 'auto-compaction-retention' one of: periodic|revision. 'periodic' for duration based retention, defaulting to hours if no time unit is provided (e.g. '5m'). 'revision' for revision number based retention.") - - // pprof profiler via HTTP - fs.BoolVar(&cfg.ec.EnablePprof, "enable-pprof", false, "Enable runtime profiling data via HTTP server. Address is at client URL + \"/debug/pprof/\"") - - // additional metrics - fs.StringVar(&cfg.ec.Metrics, "metrics", cfg.ec.Metrics, "Set level of detail for exported metrics, specify 'extensive' to include histogram metrics") - - // auth - fs.StringVar(&cfg.ec.AuthToken, "auth-token", cfg.ec.AuthToken, "Specify auth token specific options.") - - // experimental - fs.BoolVar(&cfg.ec.ExperimentalInitialCorruptCheck, "experimental-initial-corrupt-check", cfg.ec.ExperimentalInitialCorruptCheck, "Enable to check data corruption before serving any client/peer traffic.") - fs.DurationVar(&cfg.ec.ExperimentalCorruptCheckTime, "experimental-corrupt-check-time", cfg.ec.ExperimentalCorruptCheckTime, "Duration of time between cluster corruption check passes.") - - // ignored - for _, f := range cfg.ignored { - fs.Var(&flags.IgnoredFlag{Name: f}, f, "") - } - return cfg -} - -func (cfg *config) parse(arguments []string) error { - perr := cfg.cf.flagSet.Parse(arguments) - switch perr { - case nil: - case flag.ErrHelp: - fmt.Println(flagsline) - os.Exit(0) - default: - os.Exit(2) - } - if len(cfg.cf.flagSet.Args()) != 0 { - return fmt.Errorf("'%s' is not a valid flag", cfg.cf.flagSet.Arg(0)) - } - - if cfg.printVersion { - fmt.Printf("etcd Version: %s\n", version.Version) - fmt.Printf("Git SHA: %s\n", version.GitSHA) - fmt.Printf("Go Version: %s\n", runtime.Version()) - fmt.Printf("Go OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH) - os.Exit(0) - } - - var err error - if cfg.configFile != "" { - plog.Infof("Loading server configuration from %q", cfg.configFile) - err = cfg.configFromFile(cfg.configFile) - } else { - err = cfg.configFromCmdLine() - } - return err -} - -func (cfg *config) configFromCmdLine() error { - err := flags.SetFlagsFromEnv("ETCD", cfg.cf.flagSet) - if err != nil { - plog.Fatalf("%v", err) - } - - cfg.ec.LPUrls = flags.URLsFromFlag(cfg.cf.flagSet, "listen-peer-urls") - cfg.ec.APUrls = flags.URLsFromFlag(cfg.cf.flagSet, "initial-advertise-peer-urls") - cfg.ec.LCUrls = flags.URLsFromFlag(cfg.cf.flagSet, "listen-client-urls") - cfg.ec.ACUrls = flags.URLsFromFlag(cfg.cf.flagSet, "advertise-client-urls") - - if len(cfg.ec.ListenMetricsUrlsJSON) > 0 { - u, err := types.NewURLs(strings.Split(cfg.ec.ListenMetricsUrlsJSON, ",")) - if err != nil { - plog.Fatalf("unexpected error setting up listen-metrics-urls: %v", err) - } - cfg.ec.ListenMetricsUrls = []url.URL(u) - } - - cfg.ec.CipherSuites = flags.StringsFromFlagV2(cfg.cf.flagSet, "cipher-suites") - - cfg.ec.ClusterState = cfg.cf.clusterState.String() - cfg.cp.Fallback = cfg.cf.fallback.String() - cfg.cp.Proxy = cfg.cf.proxy.String() - - // disable default advertise-client-urls if lcurls is set - missingAC := flags.IsSet(cfg.cf.flagSet, "listen-client-urls") && !flags.IsSet(cfg.cf.flagSet, "advertise-client-urls") - if !cfg.mayBeProxy() && missingAC { - cfg.ec.ACUrls = nil - } - - // disable default initial-cluster if discovery is set - if (cfg.ec.Durl != "" || cfg.ec.DNSCluster != "") && !flags.IsSet(cfg.cf.flagSet, "initial-cluster") { - cfg.ec.InitialCluster = "" - } - - return cfg.validate() -} - -func (cfg *config) configFromFile(path string) error { - eCfg, err := embed.ConfigFromFile(path) - if err != nil { - return err - } - cfg.ec = *eCfg - - // load extra config information - b, rerr := ioutil.ReadFile(path) - if rerr != nil { - return rerr - } - if yerr := yaml.Unmarshal(b, &cfg.cp); yerr != nil { - return yerr - } - if cfg.cp.FallbackJSON != "" { - if err := cfg.cf.fallback.Set(cfg.cp.FallbackJSON); err != nil { - plog.Panicf("unexpected error setting up discovery-fallback flag: %v", err) - } - cfg.cp.Fallback = cfg.cf.fallback.String() - } - if cfg.cp.ProxyJSON != "" { - if err := cfg.cf.proxy.Set(cfg.cp.ProxyJSON); err != nil { - plog.Panicf("unexpected error setting up proxyFlag: %v", err) - } - cfg.cp.Proxy = cfg.cf.proxy.String() - } - return nil -} - -func (cfg *config) mayBeProxy() bool { - mayFallbackToProxy := cfg.ec.Durl != "" && cfg.cp.Fallback == fallbackFlagProxy - return cfg.cp.Proxy != proxyFlagOff || mayFallbackToProxy -} - -func (cfg *config) validate() error { - err := cfg.ec.Validate() - // TODO(yichengq): check this for joining through discovery service case - if err == embed.ErrUnsetAdvertiseClientURLsFlag && cfg.mayBeProxy() { - return nil - } - return err -} - -func (cfg config) isProxy() bool { return cfg.cf.proxy.String() != proxyFlagOff } -func (cfg config) isReadonlyProxy() bool { return cfg.cf.proxy.String() == proxyFlagReadonly } -func (cfg config) shouldFallbackToProxy() bool { return cfg.cf.fallback.String() == fallbackFlagProxy } diff --git a/vendor/go.etcd.io/etcd/etcdmain/doc.go b/vendor/go.etcd.io/etcd/etcdmain/doc.go deleted file mode 100644 index ff281aabc8de..000000000000 --- a/vendor/go.etcd.io/etcd/etcdmain/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package etcdmain contains the main entry point for the etcd binary. -package etcdmain diff --git a/vendor/go.etcd.io/etcd/etcdmain/etcd.go b/vendor/go.etcd.io/etcd/etcdmain/etcd.go deleted file mode 100644 index 87e9b25bb0ff..000000000000 --- a/vendor/go.etcd.io/etcd/etcdmain/etcd.go +++ /dev/null @@ -1,399 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdmain - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "os" - "path/filepath" - "reflect" - "runtime" - "strings" - "time" - - "github.com/coreos/etcd/discovery" - "github.com/coreos/etcd/embed" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/etcdhttp" - "github.com/coreos/etcd/pkg/cors" - "github.com/coreos/etcd/pkg/fileutil" - pkgioutil "github.com/coreos/etcd/pkg/ioutil" - "github.com/coreos/etcd/pkg/osutil" - "github.com/coreos/etcd/pkg/transport" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/proxy/httpproxy" - "github.com/coreos/etcd/version" - - "github.com/coreos/pkg/capnslog" - "google.golang.org/grpc" -) - -type dirType string - -var plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdmain") - -var ( - dirMember = dirType("member") - dirProxy = dirType("proxy") - dirEmpty = dirType("empty") -) - -func startEtcdOrProxyV2() { - grpc.EnableTracing = false - - cfg := newConfig() - defaultInitialCluster := cfg.ec.InitialCluster - - err := cfg.parse(os.Args[1:]) - if err != nil { - plog.Errorf("error verifying flags, %v. See 'etcd --help'.", err) - switch err { - case embed.ErrUnsetAdvertiseClientURLsFlag: - plog.Errorf("When listening on specific address(es), this etcd process must advertise accessible url(s) to each connected client.") - } - os.Exit(1) - } - cfg.ec.SetupLogging() - - var stopped <-chan struct{} - var errc <-chan error - - plog.Infof("etcd Version: %s\n", version.Version) - plog.Infof("Git SHA: %s\n", version.GitSHA) - plog.Infof("Go Version: %s\n", runtime.Version()) - plog.Infof("Go OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH) - - GoMaxProcs := runtime.GOMAXPROCS(0) - plog.Infof("setting maximum number of CPUs to %d, total number of available CPUs is %d", GoMaxProcs, runtime.NumCPU()) - - defaultHost, dhErr := (&cfg.ec).UpdateDefaultClusterFromName(defaultInitialCluster) - if defaultHost != "" { - plog.Infof("advertising using detected default host %q", defaultHost) - } - if dhErr != nil { - plog.Noticef("failed to detect default host (%v)", dhErr) - } - - if cfg.ec.Dir == "" { - cfg.ec.Dir = fmt.Sprintf("%v.etcd", cfg.ec.Name) - plog.Warningf("no data-dir provided, using default data-dir ./%s", cfg.ec.Dir) - } - - which := identifyDataDirOrDie(cfg.ec.Dir) - if which != dirEmpty { - plog.Noticef("the server is already initialized as %v before, starting as etcd %v...", which, which) - switch which { - case dirMember: - stopped, errc, err = startEtcd(&cfg.ec) - case dirProxy: - err = startProxy(cfg) - default: - plog.Panicf("unhandled dir type %v", which) - } - } else { - shouldProxy := cfg.isProxy() - if !shouldProxy { - stopped, errc, err = startEtcd(&cfg.ec) - if derr, ok := err.(*etcdserver.DiscoveryError); ok && derr.Err == discovery.ErrFullCluster { - if cfg.shouldFallbackToProxy() { - plog.Noticef("discovery cluster full, falling back to %s", fallbackFlagProxy) - shouldProxy = true - } - } - } - if shouldProxy { - err = startProxy(cfg) - } - } - - if err != nil { - if derr, ok := err.(*etcdserver.DiscoveryError); ok { - switch derr.Err { - case discovery.ErrDuplicateID: - plog.Errorf("member %q has previously registered with discovery service token (%s).", cfg.ec.Name, cfg.ec.Durl) - plog.Errorf("But etcd could not find valid cluster configuration in the given data dir (%s).", cfg.ec.Dir) - plog.Infof("Please check the given data dir path if the previous bootstrap succeeded") - plog.Infof("or use a new discovery token if the previous bootstrap failed.") - case discovery.ErrDuplicateName: - plog.Errorf("member with duplicated name has registered with discovery service token(%s).", cfg.ec.Durl) - plog.Errorf("please check (cURL) the discovery token for more information.") - plog.Errorf("please do not reuse the discovery token and generate a new one to bootstrap the cluster.") - default: - plog.Errorf("%v", err) - plog.Infof("discovery token %s was used, but failed to bootstrap the cluster.", cfg.ec.Durl) - plog.Infof("please generate a new discovery token and try to bootstrap again.") - } - os.Exit(1) - } - - if strings.Contains(err.Error(), "include") && strings.Contains(err.Error(), "--initial-cluster") { - plog.Infof("%v", err) - if cfg.ec.InitialCluster == cfg.ec.InitialClusterFromName(cfg.ec.Name) { - plog.Infof("forgot to set --initial-cluster flag?") - } - if types.URLs(cfg.ec.APUrls).String() == embed.DefaultInitialAdvertisePeerURLs { - plog.Infof("forgot to set --initial-advertise-peer-urls flag?") - } - if cfg.ec.InitialCluster == cfg.ec.InitialClusterFromName(cfg.ec.Name) && len(cfg.ec.Durl) == 0 { - plog.Infof("if you want to use discovery service, please set --discovery flag.") - } - os.Exit(1) - } - plog.Fatalf("%v", err) - } - - osutil.HandleInterrupts() - - // At this point, the initialization of etcd is done. - // The listeners are listening on the TCP ports and ready - // for accepting connections. The etcd instance should be - // joined with the cluster and ready to serve incoming - // connections. - notifySystemd() - - select { - case lerr := <-errc: - // fatal out on listener errors - plog.Fatal(lerr) - case <-stopped: - } - - osutil.Exit(0) -} - -// startEtcd runs StartEtcd in addition to hooks needed for standalone etcd. -func startEtcd(cfg *embed.Config) (<-chan struct{}, <-chan error, error) { - e, err := embed.StartEtcd(cfg) - if err != nil { - return nil, nil, err - } - osutil.RegisterInterruptHandler(e.Close) - select { - case <-e.Server.ReadyNotify(): // wait for e.Server to join the cluster - case <-e.Server.StopNotify(): // publish aborted from 'ErrStopped' - } - return e.Server.StopNotify(), e.Err(), nil -} - -// startProxy launches an HTTP proxy for client communication which proxies to other etcd nodes. -func startProxy(cfg *config) error { - plog.Notice("proxy: this proxy supports v2 API only!") - - clientTLSInfo := cfg.ec.ClientTLSInfo - if clientTLSInfo.Empty() { - // Support old proxy behavior of defaulting to PeerTLSInfo - // for both client and peer connections. - clientTLSInfo = cfg.ec.PeerTLSInfo - } - clientTLSInfo.InsecureSkipVerify = cfg.ec.ClientAutoTLS - cfg.ec.PeerTLSInfo.InsecureSkipVerify = cfg.ec.PeerAutoTLS - - pt, err := transport.NewTimeoutTransport(clientTLSInfo, time.Duration(cfg.cp.ProxyDialTimeoutMs)*time.Millisecond, time.Duration(cfg.cp.ProxyReadTimeoutMs)*time.Millisecond, time.Duration(cfg.cp.ProxyWriteTimeoutMs)*time.Millisecond) - if err != nil { - return err - } - pt.MaxIdleConnsPerHost = httpproxy.DefaultMaxIdleConnsPerHost - - if err = cfg.ec.PeerSelfCert(); err != nil { - plog.Fatalf("could not get certs (%v)", err) - } - tr, err := transport.NewTimeoutTransport(cfg.ec.PeerTLSInfo, time.Duration(cfg.cp.ProxyDialTimeoutMs)*time.Millisecond, time.Duration(cfg.cp.ProxyReadTimeoutMs)*time.Millisecond, time.Duration(cfg.cp.ProxyWriteTimeoutMs)*time.Millisecond) - if err != nil { - return err - } - - cfg.ec.Dir = filepath.Join(cfg.ec.Dir, "proxy") - err = os.MkdirAll(cfg.ec.Dir, fileutil.PrivateDirMode) - if err != nil { - return err - } - - var peerURLs []string - clusterfile := filepath.Join(cfg.ec.Dir, "cluster") - - b, err := ioutil.ReadFile(clusterfile) - switch { - case err == nil: - if cfg.ec.Durl != "" { - plog.Warningf("discovery token ignored since the proxy has already been initialized. Valid cluster file found at %q", clusterfile) - } - if cfg.ec.DNSCluster != "" { - plog.Warningf("DNS SRV discovery ignored since the proxy has already been initialized. Valid cluster file found at %q", clusterfile) - } - urls := struct{ PeerURLs []string }{} - err = json.Unmarshal(b, &urls) - if err != nil { - return err - } - peerURLs = urls.PeerURLs - plog.Infof("proxy: using peer urls %v from cluster file %q", peerURLs, clusterfile) - case os.IsNotExist(err): - var urlsmap types.URLsMap - urlsmap, _, err = cfg.ec.PeerURLsMapAndToken("proxy") - if err != nil { - return fmt.Errorf("error setting up initial cluster: %v", err) - } - - if cfg.ec.Durl != "" { - var s string - s, err = discovery.GetCluster(cfg.ec.Durl, cfg.ec.Dproxy) - if err != nil { - return err - } - if urlsmap, err = types.NewURLsMap(s); err != nil { - return err - } - } - peerURLs = urlsmap.URLs() - plog.Infof("proxy: using peer urls %v ", peerURLs) - default: - return err - } - - clientURLs := []string{} - uf := func() []string { - gcls, gerr := etcdserver.GetClusterFromRemotePeers(peerURLs, tr) - - if gerr != nil { - plog.Warningf("proxy: %v", gerr) - return []string{} - } - - clientURLs = gcls.ClientURLs() - - urls := struct{ PeerURLs []string }{gcls.PeerURLs()} - b, jerr := json.Marshal(urls) - if jerr != nil { - plog.Warningf("proxy: error on marshal peer urls %s", jerr) - return clientURLs - } - - err = pkgioutil.WriteAndSyncFile(clusterfile+".bak", b, 0600) - if err != nil { - plog.Warningf("proxy: error on writing urls %s", err) - return clientURLs - } - err = os.Rename(clusterfile+".bak", clusterfile) - if err != nil { - plog.Warningf("proxy: error on updating clusterfile %s", err) - return clientURLs - } - if !reflect.DeepEqual(gcls.PeerURLs(), peerURLs) { - plog.Noticef("proxy: updated peer urls in cluster file from %v to %v", peerURLs, gcls.PeerURLs()) - } - peerURLs = gcls.PeerURLs() - - return clientURLs - } - ph := httpproxy.NewHandler(pt, uf, time.Duration(cfg.cp.ProxyFailureWaitMs)*time.Millisecond, time.Duration(cfg.cp.ProxyRefreshIntervalMs)*time.Millisecond) - ph = &cors.CORSHandler{ - Handler: ph, - Info: cfg.ec.CorsInfo, - } - - if cfg.isReadonlyProxy() { - ph = httpproxy.NewReadonlyHandler(ph) - } - - // setup self signed certs when serving https - cHosts, cTLS := []string{}, false - for _, u := range cfg.ec.LCUrls { - cHosts = append(cHosts, u.Host) - cTLS = cTLS || u.Scheme == "https" - } - for _, u := range cfg.ec.ACUrls { - cHosts = append(cHosts, u.Host) - cTLS = cTLS || u.Scheme == "https" - } - listenerTLS := cfg.ec.ClientTLSInfo - if cfg.ec.ClientAutoTLS && cTLS { - listenerTLS, err = transport.SelfCert(filepath.Join(cfg.ec.Dir, "clientCerts"), cHosts) - if err != nil { - plog.Fatalf("proxy: could not initialize self-signed client certs (%v)", err) - } - } - - // Start a proxy server goroutine for each listen address - for _, u := range cfg.ec.LCUrls { - l, err := transport.NewListener(u.Host, u.Scheme, &listenerTLS) - if err != nil { - return err - } - - host := u.String() - go func() { - plog.Info("proxy: listening for client requests on ", host) - mux := http.NewServeMux() - etcdhttp.HandlePrometheus(mux) // v2 proxy just uses the same port - mux.Handle("/", ph) - plog.Fatal(http.Serve(l, mux)) - }() - } - return nil -} - -// identifyDataDirOrDie returns the type of the data dir. -// Dies if the datadir is invalid. -func identifyDataDirOrDie(dir string) dirType { - names, err := fileutil.ReadDir(dir) - if err != nil { - if os.IsNotExist(err) { - return dirEmpty - } - plog.Fatalf("error listing data dir: %s", dir) - } - - var m, p bool - for _, name := range names { - switch dirType(name) { - case dirMember: - m = true - case dirProxy: - p = true - default: - plog.Warningf("found invalid file/dir %s under data dir %s (Ignore this if you are upgrading etcd)", name, dir) - } - } - - if m && p { - plog.Fatal("invalid datadir. Both member and proxy directories exist.") - } - if m { - return dirMember - } - if p { - return dirProxy - } - return dirEmpty -} - -func checkSupportArch() { - // TODO qualify arm64 - if runtime.GOARCH == "amd64" || runtime.GOARCH == "ppc64le" { - return - } - // unsupported arch only configured via environment variable - // so unset here to not parse through flag - defer os.Unsetenv("ETCD_UNSUPPORTED_ARCH") - if env, ok := os.LookupEnv("ETCD_UNSUPPORTED_ARCH"); ok && env == runtime.GOARCH { - plog.Warningf("running etcd on unsupported architecture %q since ETCD_UNSUPPORTED_ARCH is set", env) - return - } - plog.Errorf("etcd on unsupported platform without ETCD_UNSUPPORTED_ARCH=%s set.", runtime.GOARCH) - os.Exit(1) -} diff --git a/vendor/go.etcd.io/etcd/etcdmain/gateway.go b/vendor/go.etcd.io/etcd/etcdmain/gateway.go deleted file mode 100644 index 5487414ebd58..000000000000 --- a/vendor/go.etcd.io/etcd/etcdmain/gateway.go +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdmain - -import ( - "fmt" - "net" - "net/url" - "os" - "time" - - "github.com/coreos/etcd/proxy/tcpproxy" - - "github.com/spf13/cobra" -) - -var ( - gatewayListenAddr string - gatewayEndpoints []string - gatewayDNSCluster string - gatewayInsecureDiscovery bool - getewayRetryDelay time.Duration - gatewayCA string -) - -var ( - rootCmd = &cobra.Command{ - Use: "etcd", - Short: "etcd server", - SuggestFor: []string{"etcd"}, - } -) - -func init() { - rootCmd.AddCommand(newGatewayCommand()) -} - -// newGatewayCommand returns the cobra command for "gateway". -func newGatewayCommand() *cobra.Command { - lpc := &cobra.Command{ - Use: "gateway ", - Short: "gateway related command", - } - lpc.AddCommand(newGatewayStartCommand()) - - return lpc -} - -func newGatewayStartCommand() *cobra.Command { - cmd := cobra.Command{ - Use: "start", - Short: "start the gateway", - Run: startGateway, - } - - cmd.Flags().StringVar(&gatewayListenAddr, "listen-addr", "127.0.0.1:23790", "listen address") - cmd.Flags().StringVar(&gatewayDNSCluster, "discovery-srv", "", "DNS domain used to bootstrap initial cluster") - cmd.Flags().BoolVar(&gatewayInsecureDiscovery, "insecure-discovery", false, "accept insecure SRV records") - cmd.Flags().StringVar(&gatewayCA, "trusted-ca-file", "", "path to the client server TLS CA file.") - - cmd.Flags().StringSliceVar(&gatewayEndpoints, "endpoints", []string{"127.0.0.1:2379"}, "comma separated etcd cluster endpoints") - - cmd.Flags().DurationVar(&getewayRetryDelay, "retry-delay", time.Minute, "duration of delay before retrying failed endpoints") - - return &cmd -} - -func stripSchema(eps []string) []string { - var endpoints []string - - for _, ep := range eps { - - if u, err := url.Parse(ep); err == nil && u.Host != "" { - ep = u.Host - } - - endpoints = append(endpoints, ep) - } - - return endpoints -} - -func startGateway(cmd *cobra.Command, args []string) { - srvs := discoverEndpoints(gatewayDNSCluster, gatewayCA, gatewayInsecureDiscovery) - if len(srvs.Endpoints) == 0 { - // no endpoints discovered, fall back to provided endpoints - srvs.Endpoints = gatewayEndpoints - } - // Strip the schema from the endpoints because we start just a TCP proxy - srvs.Endpoints = stripSchema(srvs.Endpoints) - if len(srvs.SRVs) == 0 { - for _, ep := range srvs.Endpoints { - h, p, err := net.SplitHostPort(ep) - if err != nil { - plog.Fatalf("error parsing endpoint %q", ep) - } - var port uint16 - fmt.Sscanf(p, "%d", &port) - srvs.SRVs = append(srvs.SRVs, &net.SRV{Target: h, Port: port}) - } - } - - if len(srvs.Endpoints) == 0 { - plog.Fatalf("no endpoints found") - } - - l, err := net.Listen("tcp", gatewayListenAddr) - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - - tp := tcpproxy.TCPProxy{ - Listener: l, - Endpoints: srvs.SRVs, - MonitorInterval: getewayRetryDelay, - } - - // At this point, etcd gateway listener is initialized - notifySystemd() - - tp.Run() -} diff --git a/vendor/go.etcd.io/etcd/etcdmain/grpc_proxy.go b/vendor/go.etcd.io/etcd/etcdmain/grpc_proxy.go deleted file mode 100644 index 16246bc1ebdc..000000000000 --- a/vendor/go.etcd.io/etcd/etcdmain/grpc_proxy.go +++ /dev/null @@ -1,436 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdmain - -import ( - "context" - "crypto/tls" - "crypto/x509" - "fmt" - "io/ioutil" - "math" - "net" - "net/http" - "net/url" - "os" - "path/filepath" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/leasing" - "github.com/coreos/etcd/clientv3/namespace" - "github.com/coreos/etcd/clientv3/ordering" - "github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb" - "github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/pkg/debugutil" - "github.com/coreos/etcd/pkg/transport" - "github.com/coreos/etcd/proxy/grpcproxy" - - "github.com/coreos/pkg/capnslog" - grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" - "github.com/soheilhy/cmux" - "github.com/spf13/cobra" - "google.golang.org/grpc" - "google.golang.org/grpc/grpclog" -) - -var ( - grpcProxyListenAddr string - grpcProxyMetricsListenAddr string - grpcProxyEndpoints []string - grpcProxyDNSCluster string - grpcProxyInsecureDiscovery bool - grpcProxyDataDir string - grpcMaxCallSendMsgSize int - grpcMaxCallRecvMsgSize int - - // tls for connecting to etcd - - grpcProxyCA string - grpcProxyCert string - grpcProxyKey string - grpcProxyInsecureSkipTLSVerify bool - - // tls for clients connecting to proxy - - grpcProxyListenCA string - grpcProxyListenCert string - grpcProxyListenKey string - grpcProxyListenAutoTLS bool - grpcProxyListenCRL string - - grpcProxyAdvertiseClientURL string - grpcProxyResolverPrefix string - grpcProxyResolverTTL int - - grpcProxyNamespace string - grpcProxyLeasing string - - grpcProxyEnablePprof bool - grpcProxyEnableOrdering bool - - grpcProxyDebug bool -) - -const defaultGRPCMaxCallSendMsgSize = 1.5 * 1024 * 1024 - -func init() { - rootCmd.AddCommand(newGRPCProxyCommand()) -} - -// newGRPCProxyCommand returns the cobra command for "grpc-proxy". -func newGRPCProxyCommand() *cobra.Command { - lpc := &cobra.Command{ - Use: "grpc-proxy ", - Short: "grpc-proxy related command", - } - lpc.AddCommand(newGRPCProxyStartCommand()) - - return lpc -} - -func newGRPCProxyStartCommand() *cobra.Command { - cmd := cobra.Command{ - Use: "start", - Short: "start the grpc proxy", - Run: startGRPCProxy, - } - - cmd.Flags().StringVar(&grpcProxyListenAddr, "listen-addr", "127.0.0.1:23790", "listen address") - cmd.Flags().StringVar(&grpcProxyDNSCluster, "discovery-srv", "", "DNS domain used to bootstrap initial cluster") - cmd.Flags().StringVar(&grpcProxyMetricsListenAddr, "metrics-addr", "", "listen for endpoint /metrics requests on an additional interface") - cmd.Flags().BoolVar(&grpcProxyInsecureDiscovery, "insecure-discovery", false, "accept insecure SRV records") - cmd.Flags().StringSliceVar(&grpcProxyEndpoints, "endpoints", []string{"127.0.0.1:2379"}, "comma separated etcd cluster endpoints") - cmd.Flags().StringVar(&grpcProxyAdvertiseClientURL, "advertise-client-url", "127.0.0.1:23790", "advertise address to register (must be reachable by client)") - cmd.Flags().StringVar(&grpcProxyResolverPrefix, "resolver-prefix", "", "prefix to use for registering proxy (must be shared with other grpc-proxy members)") - cmd.Flags().IntVar(&grpcProxyResolverTTL, "resolver-ttl", 0, "specify TTL, in seconds, when registering proxy endpoints") - cmd.Flags().StringVar(&grpcProxyNamespace, "namespace", "", "string to prefix to all keys for namespacing requests") - cmd.Flags().BoolVar(&grpcProxyEnablePprof, "enable-pprof", false, `Enable runtime profiling data via HTTP server. Address is at client URL + "/debug/pprof/"`) - cmd.Flags().StringVar(&grpcProxyDataDir, "data-dir", "default.proxy", "Data directory for persistent data") - cmd.Flags().IntVar(&grpcMaxCallSendMsgSize, "max-send-bytes", defaultGRPCMaxCallSendMsgSize, "message send limits in bytes (default value is 1.5 MiB)") - cmd.Flags().IntVar(&grpcMaxCallRecvMsgSize, "max-recv-bytes", math.MaxInt32, "message receive limits in bytes (default value is math.MaxInt32)") - - // client TLS for connecting to server - cmd.Flags().StringVar(&grpcProxyCert, "cert", "", "identify secure connections with etcd servers using this TLS certificate file") - cmd.Flags().StringVar(&grpcProxyKey, "key", "", "identify secure connections with etcd servers using this TLS key file") - cmd.Flags().StringVar(&grpcProxyCA, "cacert", "", "verify certificates of TLS-enabled secure etcd servers using this CA bundle") - cmd.Flags().BoolVar(&grpcProxyInsecureSkipTLSVerify, "insecure-skip-tls-verify", false, "skip authentication of etcd server TLS certificates") - - // client TLS for connecting to proxy - cmd.Flags().StringVar(&grpcProxyListenCert, "cert-file", "", "identify secure connections to the proxy using this TLS certificate file") - cmd.Flags().StringVar(&grpcProxyListenKey, "key-file", "", "identify secure connections to the proxy using this TLS key file") - cmd.Flags().StringVar(&grpcProxyListenCA, "trusted-ca-file", "", "verify certificates of TLS-enabled secure proxy using this CA bundle") - cmd.Flags().BoolVar(&grpcProxyListenAutoTLS, "auto-tls", false, "proxy TLS using generated certificates") - cmd.Flags().StringVar(&grpcProxyListenCRL, "client-crl-file", "", "proxy client certificate revocation list file.") - - // experimental flags - cmd.Flags().BoolVar(&grpcProxyEnableOrdering, "experimental-serializable-ordering", false, "Ensure serializable reads have monotonically increasing store revisions across endpoints.") - cmd.Flags().StringVar(&grpcProxyLeasing, "experimental-leasing-prefix", "", "leasing metadata prefix for disconnected linearized reads.") - - cmd.Flags().BoolVar(&grpcProxyDebug, "debug", false, "Enable debug-level logging for grpc-proxy.") - - return &cmd -} - -func startGRPCProxy(cmd *cobra.Command, args []string) { - checkArgs() - - capnslog.SetGlobalLogLevel(capnslog.INFO) - if grpcProxyDebug { - capnslog.SetGlobalLogLevel(capnslog.DEBUG) - grpc.EnableTracing = true - // enable info, warning, error - grpclog.SetLoggerV2(grpclog.NewLoggerV2(os.Stderr, os.Stderr, os.Stderr)) - } else { - // only discard info - grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, os.Stderr, os.Stderr)) - } - - tlsinfo := newTLS(grpcProxyListenCA, grpcProxyListenCert, grpcProxyListenKey) - if tlsinfo == nil && grpcProxyListenAutoTLS { - host := []string{"https://" + grpcProxyListenAddr} - dir := filepath.Join(grpcProxyDataDir, "fixtures", "proxy") - autoTLS, err := transport.SelfCert(dir, host) - if err != nil { - plog.Fatal(err) - } - tlsinfo = &autoTLS - } - if tlsinfo != nil { - plog.Infof("ServerTLS: %s", tlsinfo) - } - m := mustListenCMux(tlsinfo) - - grpcl := m.Match(cmux.HTTP2()) - defer func() { - grpcl.Close() - plog.Infof("stopping listening for grpc-proxy client requests on %s", grpcProxyListenAddr) - }() - - client := mustNewClient() - httpClient := mustNewHTTPClient() - - srvhttp, httpl := mustHTTPListener(m, tlsinfo, client) - errc := make(chan error) - go func() { errc <- newGRPCProxyServer(client).Serve(grpcl) }() - go func() { errc <- srvhttp.Serve(httpl) }() - go func() { errc <- m.Serve() }() - if len(grpcProxyMetricsListenAddr) > 0 { - mhttpl := mustMetricsListener(tlsinfo) - go func() { - mux := http.NewServeMux() - grpcproxy.HandleMetrics(mux, httpClient, client.Endpoints()) - grpcproxy.HandleHealth(mux, client) - plog.Fatal(http.Serve(mhttpl, mux)) - }() - } - - // grpc-proxy is initialized, ready to serve - notifySystemd() - - fmt.Fprintln(os.Stderr, <-errc) - os.Exit(1) -} - -func checkArgs() { - if grpcProxyResolverPrefix != "" && grpcProxyResolverTTL < 1 { - fmt.Fprintln(os.Stderr, fmt.Errorf("invalid resolver-ttl %d", grpcProxyResolverTTL)) - os.Exit(1) - } - if grpcProxyResolverPrefix == "" && grpcProxyResolverTTL > 0 { - fmt.Fprintln(os.Stderr, fmt.Errorf("invalid resolver-prefix %q", grpcProxyResolverPrefix)) - os.Exit(1) - } - if grpcProxyResolverPrefix != "" && grpcProxyResolverTTL > 0 && grpcProxyAdvertiseClientURL == "" { - fmt.Fprintln(os.Stderr, fmt.Errorf("invalid advertise-client-url %q", grpcProxyAdvertiseClientURL)) - os.Exit(1) - } -} - -func mustNewClient() *clientv3.Client { - srvs := discoverEndpoints(grpcProxyDNSCluster, grpcProxyCA, grpcProxyInsecureDiscovery) - eps := srvs.Endpoints - if len(eps) == 0 { - eps = grpcProxyEndpoints - } - cfg, err := newClientCfg(eps) - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - cfg.DialOptions = append(cfg.DialOptions, - grpc.WithUnaryInterceptor(grpcproxy.AuthUnaryClientInterceptor)) - cfg.DialOptions = append(cfg.DialOptions, - grpc.WithStreamInterceptor(grpcproxy.AuthStreamClientInterceptor)) - client, err := clientv3.New(*cfg) - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - return client -} - -func newClientCfg(eps []string) (*clientv3.Config, error) { - // set tls if any one tls option set - cfg := clientv3.Config{ - Endpoints: eps, - DialTimeout: 5 * time.Second, - } - - if grpcMaxCallSendMsgSize > 0 { - cfg.MaxCallSendMsgSize = grpcMaxCallSendMsgSize - } - if grpcMaxCallRecvMsgSize > 0 { - cfg.MaxCallRecvMsgSize = grpcMaxCallRecvMsgSize - } - - tls := newTLS(grpcProxyCA, grpcProxyCert, grpcProxyKey) - if tls == nil && grpcProxyInsecureSkipTLSVerify { - tls = &transport.TLSInfo{} - } - if tls != nil { - clientTLS, err := tls.ClientConfig() - if err != nil { - return nil, err - } - clientTLS.InsecureSkipVerify = grpcProxyInsecureSkipTLSVerify - cfg.TLS = clientTLS - plog.Infof("ClientTLS: %s", tls) - } - return &cfg, nil -} - -func newTLS(ca, cert, key string) *transport.TLSInfo { - if ca == "" && cert == "" && key == "" { - return nil - } - return &transport.TLSInfo{CAFile: ca, CertFile: cert, KeyFile: key} -} - -func mustListenCMux(tlsinfo *transport.TLSInfo) cmux.CMux { - l, err := net.Listen("tcp", grpcProxyListenAddr) - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - - if l, err = transport.NewKeepAliveListener(l, "tcp", nil); err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - if tlsinfo != nil { - tlsinfo.CRLFile = grpcProxyListenCRL - if l, err = transport.NewTLSListener(l, tlsinfo); err != nil { - plog.Fatal(err) - } - } - - plog.Infof("listening for grpc-proxy client requests on %s", grpcProxyListenAddr) - return cmux.New(l) -} - -func newGRPCProxyServer(client *clientv3.Client) *grpc.Server { - if grpcProxyEnableOrdering { - vf := ordering.NewOrderViolationSwitchEndpointClosure(*client) - client.KV = ordering.NewKV(client.KV, vf) - plog.Infof("waiting for linearized read from cluster to recover ordering") - for { - _, err := client.KV.Get(context.TODO(), "_", clientv3.WithKeysOnly()) - if err == nil { - break - } - plog.Warningf("ordering recovery failed, retrying in 1s (%v)", err) - time.Sleep(time.Second) - } - } - - if len(grpcProxyNamespace) > 0 { - client.KV = namespace.NewKV(client.KV, grpcProxyNamespace) - client.Watcher = namespace.NewWatcher(client.Watcher, grpcProxyNamespace) - client.Lease = namespace.NewLease(client.Lease, grpcProxyNamespace) - } - - if len(grpcProxyLeasing) > 0 { - client.KV, _, _ = leasing.NewKV(client, grpcProxyLeasing) - } - - kvp, _ := grpcproxy.NewKvProxy(client) - watchp, _ := grpcproxy.NewWatchProxy(client) - if grpcProxyResolverPrefix != "" { - grpcproxy.Register(client, grpcProxyResolverPrefix, grpcProxyAdvertiseClientURL, grpcProxyResolverTTL) - } - clusterp, _ := grpcproxy.NewClusterProxy(client, grpcProxyAdvertiseClientURL, grpcProxyResolverPrefix) - leasep, _ := grpcproxy.NewLeaseProxy(client) - mainp := grpcproxy.NewMaintenanceProxy(client) - authp := grpcproxy.NewAuthProxy(client) - electionp := grpcproxy.NewElectionProxy(client) - lockp := grpcproxy.NewLockProxy(client) - - server := grpc.NewServer( - grpc.StreamInterceptor(grpc_prometheus.StreamServerInterceptor), - grpc.UnaryInterceptor(grpc_prometheus.UnaryServerInterceptor), - grpc.MaxConcurrentStreams(math.MaxUint32), - ) - - pb.RegisterKVServer(server, kvp) - pb.RegisterWatchServer(server, watchp) - pb.RegisterClusterServer(server, clusterp) - pb.RegisterLeaseServer(server, leasep) - pb.RegisterMaintenanceServer(server, mainp) - pb.RegisterAuthServer(server, authp) - v3electionpb.RegisterElectionServer(server, electionp) - v3lockpb.RegisterLockServer(server, lockp) - - return server -} - -func mustHTTPListener(m cmux.CMux, tlsinfo *transport.TLSInfo, c *clientv3.Client) (*http.Server, net.Listener) { - httpClient := mustNewHTTPClient() - httpmux := http.NewServeMux() - httpmux.HandleFunc("/", http.NotFound) - grpcproxy.HandleMetrics(httpmux, httpClient, c.Endpoints()) - grpcproxy.HandleHealth(httpmux, c) - if grpcProxyEnablePprof { - for p, h := range debugutil.PProfHandlers() { - httpmux.Handle(p, h) - } - plog.Infof("pprof is enabled under %s", debugutil.HTTPPrefixPProf) - } - srvhttp := &http.Server{Handler: httpmux} - - if tlsinfo == nil { - return srvhttp, m.Match(cmux.HTTP1()) - } - - srvTLS, err := tlsinfo.ServerConfig() - if err != nil { - plog.Fatalf("could not setup TLS (%v)", err) - } - srvhttp.TLSConfig = srvTLS - return srvhttp, m.Match(cmux.Any()) -} - -func mustNewHTTPClient() *http.Client { - transport, err := newHTTPTransport(grpcProxyCA, grpcProxyCert, grpcProxyKey) - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - return &http.Client{Transport: transport} -} - -func newHTTPTransport(ca, cert, key string) (*http.Transport, error) { - tr := &http.Transport{} - - if ca != "" && cert != "" && key != "" { - caCert, err := ioutil.ReadFile(ca) - if err != nil { - return nil, err - } - keyPair, err := tls.LoadX509KeyPair(cert, key) - if err != nil { - return nil, err - } - caPool := x509.NewCertPool() - caPool.AppendCertsFromPEM(caCert) - - tlsConfig := &tls.Config{ - Certificates: []tls.Certificate{keyPair}, - RootCAs: caPool, - } - tlsConfig.BuildNameToCertificate() - tr.TLSClientConfig = tlsConfig - } else if grpcProxyInsecureSkipTLSVerify { - tlsConfig := &tls.Config{InsecureSkipVerify: grpcProxyInsecureSkipTLSVerify} - tr.TLSClientConfig = tlsConfig - } - return tr, nil -} - -func mustMetricsListener(tlsinfo *transport.TLSInfo) net.Listener { - murl, err := url.Parse(grpcProxyMetricsListenAddr) - if err != nil { - fmt.Fprintf(os.Stderr, "cannot parse %q", grpcProxyMetricsListenAddr) - os.Exit(1) - } - ml, err := transport.NewListener(murl.Host, murl.Scheme, tlsinfo) - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - plog.Info("grpc-proxy: listening for metrics on ", murl.String()) - return ml -} diff --git a/vendor/go.etcd.io/etcd/etcdmain/help.go b/vendor/go.etcd.io/etcd/etcdmain/help.go deleted file mode 100644 index c64dab3bcda0..000000000000 --- a/vendor/go.etcd.io/etcd/etcdmain/help.go +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdmain - -import ( - "strconv" - - "github.com/coreos/etcd/embed" -) - -var ( - usageline = `usage: etcd [flags] - start an etcd server - - etcd --version - show the version of etcd - - etcd -h | --help - show the help information about etcd - - etcd --config-file - path to the server configuration file - - etcd gateway - run the stateless pass-through etcd TCP connection forwarding proxy - - etcd grpc-proxy - run the stateless etcd v3 gRPC L7 reverse proxy - ` - flagsline = ` -member flags: - - --name 'default' - human-readable name for this member. - --data-dir '${name}.etcd' - path to the data directory. - --wal-dir '' - path to the dedicated wal directory. - --snapshot-count '100000' - number of committed transactions to trigger a snapshot to disk. - --heartbeat-interval '100' - time (in milliseconds) of a heartbeat interval. - --election-timeout '1000' - time (in milliseconds) for an election to timeout. See tuning documentation for details. - --initial-election-tick-advance 'true' - whether to fast-forward initial election ticks on boot for faster election. - --listen-peer-urls 'http://localhost:2380' - list of URLs to listen on for peer traffic. - --listen-client-urls 'http://localhost:2379' - list of URLs to listen on for client traffic. - --max-snapshots '` + strconv.Itoa(embed.DefaultMaxSnapshots) + `' - maximum number of snapshot files to retain (0 is unlimited). - --max-wals '` + strconv.Itoa(embed.DefaultMaxWALs) + `' - maximum number of wal files to retain (0 is unlimited). - --cors '' - comma-separated whitelist of origins for CORS (cross-origin resource sharing). - --quota-backend-bytes '0' - raise alarms when backend size exceeds the given quota (0 defaults to low space quota). - --max-txn-ops '128' - maximum number of operations permitted in a transaction. - --max-request-bytes '1572864' - maximum client request size in bytes the server will accept. - --grpc-keepalive-min-time '5s' - minimum duration interval that a client should wait before pinging server. - --grpc-keepalive-interval '2h' - frequency duration of server-to-client ping to check if a connection is alive (0 to disable). - --grpc-keepalive-timeout '20s' - additional duration of wait before closing a non-responsive connection (0 to disable). - -clustering flags: - - --initial-advertise-peer-urls 'http://localhost:2380' - list of this member's peer URLs to advertise to the rest of the cluster. - --initial-cluster 'default=http://localhost:2380' - initial cluster configuration for bootstrapping. - --initial-cluster-state 'new' - initial cluster state ('new' or 'existing'). - --initial-cluster-token 'etcd-cluster' - initial cluster token for the etcd cluster during bootstrap. - Specifying this can protect you from unintended cross-cluster interaction when running multiple clusters. - --advertise-client-urls 'http://localhost:2379' - list of this member's client URLs to advertise to the public. - The client URLs advertised should be accessible to machines that talk to etcd cluster. etcd client libraries parse these URLs to connect to the cluster. - --discovery '' - discovery URL used to bootstrap the cluster. - --discovery-fallback 'proxy' - expected behavior ('exit' or 'proxy') when discovery services fails. - "proxy" supports v2 API only. - --discovery-proxy '' - HTTP proxy to use for traffic to discovery service. - --discovery-srv '' - dns srv domain used to bootstrap the cluster. - --strict-reconfig-check '` + strconv.FormatBool(embed.DefaultStrictReconfigCheck) + `' - reject reconfiguration requests that would cause quorum loss. - --auto-compaction-retention '0' - auto compaction retention length. 0 means disable auto compaction. - --auto-compaction-mode 'periodic' - interpret 'auto-compaction-retention' one of: periodic|revision. 'periodic' for duration based retention, defaulting to hours if no time unit is provided (e.g. '5m'). 'revision' for revision number based retention. - --enable-v2 '` + strconv.FormatBool(embed.DefaultEnableV2) + `' - Accept etcd V2 client requests. - -proxy flags: - "proxy" supports v2 API only. - - --proxy 'off' - proxy mode setting ('off', 'readonly' or 'on'). - --proxy-failure-wait 5000 - time (in milliseconds) an endpoint will be held in a failed state. - --proxy-refresh-interval 30000 - time (in milliseconds) of the endpoints refresh interval. - --proxy-dial-timeout 1000 - time (in milliseconds) for a dial to timeout. - --proxy-write-timeout 5000 - time (in milliseconds) for a write to timeout. - --proxy-read-timeout 0 - time (in milliseconds) for a read to timeout. - - -security flags: - - --ca-file '' [DEPRECATED] - path to the client server TLS CA file. '-ca-file ca.crt' could be replaced by '-trusted-ca-file ca.crt -client-cert-auth' and etcd will perform the same. - --cert-file '' - path to the client server TLS cert file. - --key-file '' - path to the client server TLS key file. - --client-cert-auth 'false' - enable client cert authentication. - --client-crl-file '' - path to the client certificate revocation list file. - --trusted-ca-file '' - path to the client server TLS trusted CA cert file. - --auto-tls 'false' - client TLS using generated certificates. - --peer-ca-file '' [DEPRECATED] - path to the peer server TLS CA file. '-peer-ca-file ca.crt' could be replaced by '-peer-trusted-ca-file ca.crt -peer-client-cert-auth' and etcd will perform the same. - --peer-cert-file '' - path to the peer server TLS cert file. - --peer-key-file '' - path to the peer server TLS key file. - --peer-client-cert-auth 'false' - enable peer client cert authentication. - --peer-trusted-ca-file '' - path to the peer server TLS trusted CA file. - --peer-cert-allowed-cn '' - Required CN for client certs connecting to the peer endpoint. - --peer-auto-tls 'false' - peer TLS using self-generated certificates if --peer-key-file and --peer-cert-file are not provided. - --peer-crl-file '' - path to the peer certificate revocation list file. - --cipher-suites '' - comma-separated list of supported TLS cipher suites between client/server and peers (empty will be auto-populated by Go). - -logging flags - - --debug 'false' - enable debug-level logging for etcd. - --log-package-levels '' - specify a particular log level for each etcd package (eg: 'etcdmain=CRITICAL,etcdserver=DEBUG'). - --log-output 'default' - specify 'stdout' or 'stderr' to skip journald logging even when running under systemd. - -unsafe flags: - -Please be CAUTIOUS when using unsafe flags because it will break the guarantees -given by the consensus protocol. - - --force-new-cluster 'false' - force to create a new one-member cluster. - -profiling flags: - --enable-pprof 'false' - Enable runtime profiling data via HTTP server. Address is at client URL + "/debug/pprof/" - --metrics 'basic' - Set level of detail for exported metrics, specify 'extensive' to include histogram metrics. - --listen-metrics-urls '' - List of URLs to listen on for metrics. - -auth flags: - --auth-token 'simple' - Specify a v3 authentication token type and its options ('simple' or 'jwt'). - -experimental flags: - --experimental-initial-corrupt-check 'false' - enable to check data corruption before serving any client/peer traffic. - --experimental-corrupt-check-time '0s' - duration of time between cluster corruption check passes. - --experimental-enable-v2v3 '' - serve v2 requests through the v3 backend under a given prefix. -` -) diff --git a/vendor/go.etcd.io/etcd/etcdmain/main.go b/vendor/go.etcd.io/etcd/etcdmain/main.go deleted file mode 100644 index 06bbae56b8d1..000000000000 --- a/vendor/go.etcd.io/etcd/etcdmain/main.go +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdmain - -import ( - "fmt" - "os" - "strings" - - "github.com/coreos/go-systemd/daemon" - systemdutil "github.com/coreos/go-systemd/util" -) - -func Main() { - checkSupportArch() - - if len(os.Args) > 1 { - cmd := os.Args[1] - if covArgs := os.Getenv("ETCDCOV_ARGS"); len(covArgs) > 0 { - args := strings.Split(os.Getenv("ETCDCOV_ARGS"), "\xe7\xcd")[1:] - rootCmd.SetArgs(args) - cmd = "grpc-proxy" - } - switch cmd { - case "gateway", "grpc-proxy": - if err := rootCmd.Execute(); err != nil { - fmt.Fprint(os.Stderr, err) - os.Exit(1) - } - return - } - } - - startEtcdOrProxyV2() -} - -func notifySystemd() { - if !systemdutil.IsRunningSystemd() { - return - } - sent, err := daemon.SdNotify(false, "READY=1") - if err != nil { - plog.Errorf("failed to notify systemd for readiness: %v", err) - } - if !sent { - plog.Errorf("forgot to set Type=notify in systemd service file?") - } -} diff --git a/vendor/go.etcd.io/etcd/etcdmain/util.go b/vendor/go.etcd.io/etcd/etcdmain/util.go deleted file mode 100644 index 9657271d53a5..000000000000 --- a/vendor/go.etcd.io/etcd/etcdmain/util.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdmain - -import ( - "fmt" - "os" - - "github.com/coreos/etcd/pkg/srv" - "github.com/coreos/etcd/pkg/transport" -) - -func discoverEndpoints(dns string, ca string, insecure bool) (s srv.SRVClients) { - if dns == "" { - return s - } - srvs, err := srv.GetClient("etcd-client", dns) - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - endpoints := srvs.Endpoints - plog.Infof("discovered the cluster %s from %s", endpoints, dns) - if insecure { - return *srvs - } - // confirm TLS connections are good - tlsInfo := transport.TLSInfo{ - TrustedCAFile: ca, - ServerName: dns, - } - plog.Infof("validating discovered endpoints %v", endpoints) - endpoints, err = transport.ValidateSecureEndpoints(tlsInfo, endpoints) - if err != nil { - plog.Warningf("%v", err) - } - plog.Infof("using discovered endpoints %v", endpoints) - - // map endpoints back to SRVClients struct with SRV data - eps := make(map[string]struct{}) - for _, ep := range endpoints { - eps[ep] = struct{}{} - } - for i := range srvs.Endpoints { - if _, ok := eps[srvs.Endpoints[i]]; !ok { - continue - } - s.Endpoints = append(s.Endpoints, srvs.Endpoints[i]) - s.SRVs = append(s.SRVs, srvs.SRVs[i]) - } - - return s -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/capability.go b/vendor/go.etcd.io/etcd/etcdserver/api/capability.go deleted file mode 100644 index eb34383d7f97..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/capability.go +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package api - -import ( - "sync" - - "github.com/coreos/etcd/version" - "github.com/coreos/go-semver/semver" - "github.com/coreos/pkg/capnslog" -) - -type Capability string - -const ( - AuthCapability Capability = "auth" - V3rpcCapability Capability = "v3rpc" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdserver/api") - - // capabilityMaps is a static map of version to capability map. - capabilityMaps = map[string]map[Capability]bool{ - "3.0.0": {AuthCapability: true, V3rpcCapability: true}, - "3.1.0": {AuthCapability: true, V3rpcCapability: true}, - "3.2.0": {AuthCapability: true, V3rpcCapability: true}, - "3.3.0": {AuthCapability: true, V3rpcCapability: true}, - } - - enableMapMu sync.RWMutex - // enabledMap points to a map in capabilityMaps - enabledMap map[Capability]bool - - curVersion *semver.Version -) - -func init() { - enabledMap = map[Capability]bool{ - AuthCapability: true, - V3rpcCapability: true, - } -} - -// UpdateCapability updates the enabledMap when the cluster version increases. -func UpdateCapability(v *semver.Version) { - if v == nil { - // if recovered but version was never set by cluster - return - } - enableMapMu.Lock() - if curVersion != nil && !curVersion.LessThan(*v) { - enableMapMu.Unlock() - return - } - curVersion = v - enabledMap = capabilityMaps[curVersion.String()] - enableMapMu.Unlock() - plog.Infof("enabled capabilities for version %s", version.Cluster(v.String())) -} - -func IsCapabilityEnabled(c Capability) bool { - enableMapMu.RLock() - defer enableMapMu.RUnlock() - if enabledMap == nil { - return false - } - return enabledMap[c] -} - -func EnableCapability(c Capability) { - enableMapMu.Lock() - defer enableMapMu.Unlock() - enabledMap[c] = true -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/cluster.go b/vendor/go.etcd.io/etcd/etcdserver/api/cluster.go deleted file mode 100644 index 654c25804cec..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/cluster.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package api - -import ( - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/pkg/types" - - "github.com/coreos/go-semver/semver" -) - -// Cluster is an interface representing a collection of members in one etcd cluster. -type Cluster interface { - // ID returns the cluster ID - ID() types.ID - // ClientURLs returns an aggregate set of all URLs on which this - // cluster is listening for client requests - ClientURLs() []string - // Members returns a slice of members sorted by their ID - Members() []*membership.Member - // Member retrieves a particular member based on ID, or nil if the - // member does not exist in the cluster - Member(id types.ID) *membership.Member - // Version is the cluster-wide minimum major.minor version. - Version() *semver.Version -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/doc.go b/vendor/go.etcd.io/etcd/etcdserver/api/doc.go deleted file mode 100644 index f44881be663e..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package api manages the capabilities and features that are exposed to clients by the etcd cluster. -package api diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/etcdhttp/base.go b/vendor/go.etcd.io/etcd/etcdserver/api/etcdhttp/base.go deleted file mode 100644 index f0d3b0bd3d2a..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/etcdhttp/base.go +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdhttp - -import ( - "encoding/json" - "expvar" - "fmt" - "net/http" - "strings" - - etcdErr "github.com/coreos/etcd/error" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api" - "github.com/coreos/etcd/etcdserver/api/v2http/httptypes" - "github.com/coreos/etcd/pkg/logutil" - "github.com/coreos/etcd/version" - "github.com/coreos/pkg/capnslog" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdserver/api/etcdhttp") - mlog = logutil.NewMergeLogger(plog) -) - -const ( - configPath = "/config" - varsPath = "/debug/vars" - versionPath = "/version" -) - -// HandleBasic adds handlers to a mux for serving JSON etcd client requests -// that do not access the v2 store. -func HandleBasic(mux *http.ServeMux, server etcdserver.ServerPeer) { - mux.HandleFunc(varsPath, serveVars) - mux.HandleFunc(configPath+"/local/log", logHandleFunc) - HandleMetricsHealth(mux, server) - mux.HandleFunc(versionPath, versionHandler(server.Cluster(), serveVersion)) -} - -func versionHandler(c api.Cluster, fn func(http.ResponseWriter, *http.Request, string)) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - v := c.Version() - if v != nil { - fn(w, r, v.String()) - } else { - fn(w, r, "not_decided") - } - } -} - -func serveVersion(w http.ResponseWriter, r *http.Request, clusterV string) { - if !allowMethod(w, r, "GET") { - return - } - vs := version.Versions{ - Server: version.Version, - Cluster: clusterV, - } - - w.Header().Set("Content-Type", "application/json") - b, err := json.Marshal(&vs) - if err != nil { - plog.Panicf("cannot marshal versions to json (%v)", err) - } - w.Write(b) -} - -func logHandleFunc(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r, "PUT") { - return - } - - in := struct{ Level string }{} - - d := json.NewDecoder(r.Body) - if err := d.Decode(&in); err != nil { - WriteError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Invalid json body")) - return - } - - logl, err := capnslog.ParseLevel(strings.ToUpper(in.Level)) - if err != nil { - WriteError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Invalid log level "+in.Level)) - return - } - - plog.Noticef("globalLogLevel set to %q", logl.String()) - capnslog.SetGlobalLogLevel(logl) - w.WriteHeader(http.StatusNoContent) -} - -func serveVars(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r, "GET") { - return - } - - w.Header().Set("Content-Type", "application/json; charset=utf-8") - fmt.Fprintf(w, "{\n") - first := true - expvar.Do(func(kv expvar.KeyValue) { - if !first { - fmt.Fprintf(w, ",\n") - } - first = false - fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value) - }) - fmt.Fprintf(w, "\n}\n") -} - -func allowMethod(w http.ResponseWriter, r *http.Request, m string) bool { - if m == r.Method { - return true - } - w.Header().Set("Allow", m) - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return false -} - -// WriteError logs and writes the given Error to the ResponseWriter -// If Error is an etcdErr, it is rendered to the ResponseWriter -// Otherwise, it is assumed to be a StatusInternalServerError -func WriteError(w http.ResponseWriter, r *http.Request, err error) { - if err == nil { - return - } - switch e := err.(type) { - case *etcdErr.Error: - e.WriteTo(w) - case *httptypes.HTTPError: - if et := e.WriteTo(w); et != nil { - plog.Debugf("error writing HTTPError (%v) to %s", et, r.RemoteAddr) - } - default: - switch err { - case etcdserver.ErrTimeoutDueToLeaderFail, etcdserver.ErrTimeoutDueToConnectionLost, etcdserver.ErrNotEnoughStartedMembers, etcdserver.ErrUnhealthy: - mlog.MergeError(err) - default: - mlog.MergeErrorf("got unexpected response error (%v)", err) - } - herr := httptypes.NewHTTPError(http.StatusInternalServerError, "Internal Server Error") - if et := herr.WriteTo(w); et != nil { - plog.Debugf("error writing HTTPError (%v) to %s", et, r.RemoteAddr) - } - } -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/etcdhttp/doc.go b/vendor/go.etcd.io/etcd/etcdserver/api/etcdhttp/doc.go deleted file mode 100644 index a03b626204f7..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/etcdhttp/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package etcdhttp implements HTTP transportation layer for etcdserver. -package etcdhttp diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/etcdhttp/metrics.go b/vendor/go.etcd.io/etcd/etcdserver/api/etcdhttp/metrics.go deleted file mode 100644 index e947abfdd0d1..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/etcdhttp/metrics.go +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdhttp - -import ( - "context" - "encoding/json" - "net/http" - "time" - - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/raft" - - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promhttp" -) - -const ( - PathMetrics = "/metrics" - PathHealth = "/health" -) - -// HandleMetricsHealth registers metrics and health handlers. -func HandleMetricsHealth(mux *http.ServeMux, srv etcdserver.ServerV2) { - mux.Handle(PathMetrics, promhttp.Handler()) - mux.Handle(PathHealth, NewHealthHandler(func() Health { return checkHealth(srv) })) -} - -// HandlePrometheus registers prometheus handler on '/metrics'. -func HandlePrometheus(mux *http.ServeMux) { - mux.Handle(PathMetrics, promhttp.Handler()) -} - -// NewHealthHandler handles '/health' requests. -func NewHealthHandler(hfunc func() Health) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - if r.Method != http.MethodGet { - w.Header().Set("Allow", http.MethodGet) - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return - } - h := hfunc() - d, _ := json.Marshal(h) - if h.Health != "true" { - http.Error(w, string(d), http.StatusServiceUnavailable) - return - } - w.WriteHeader(http.StatusOK) - w.Write(d) - } -} - -var ( - healthSuccess = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "health_success", - Help: "The total number of successful health checks", - }) - healthFailed = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "health_failures", - Help: "The total number of failed health checks", - }) -) - -func init() { - prometheus.MustRegister(healthSuccess) - prometheus.MustRegister(healthFailed) -} - -// Health defines etcd server health status. -// TODO: remove manual parsing in etcdctl cluster-health -type Health struct { - Health string `json:"health"` -} - -// TODO: server NOSPACE, etcdserver.ErrNoLeader in health API - -func checkHealth(srv etcdserver.ServerV2) Health { - h := Health{Health: "true"} - - as := srv.Alarms() - if len(as) > 0 { - h.Health = "false" - } - - if h.Health == "true" { - if uint64(srv.Leader()) == raft.None { - h.Health = "false" - } - } - - if h.Health == "true" { - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - _, err := srv.Do(ctx, etcdserverpb.Request{Method: "QGET"}) - cancel() - if err != nil { - h.Health = "false" - } - } - - if h.Health == "true" { - healthSuccess.Inc() - } else { - healthFailed.Inc() - } - return h -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/etcdhttp/peer.go b/vendor/go.etcd.io/etcd/etcdserver/api/etcdhttp/peer.go deleted file mode 100644 index 0a9213b01a9b..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/etcdhttp/peer.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdhttp - -import ( - "encoding/json" - "net/http" - - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api" - "github.com/coreos/etcd/lease/leasehttp" - "github.com/coreos/etcd/rafthttp" -) - -const ( - peerMembersPrefix = "/members" -) - -// NewPeerHandler generates an http.Handler to handle etcd peer requests. -func NewPeerHandler(s etcdserver.ServerPeer) http.Handler { - return newPeerHandler(s.Cluster(), s.RaftHandler(), s.LeaseHandler()) -} - -func newPeerHandler(cluster api.Cluster, raftHandler http.Handler, leaseHandler http.Handler) http.Handler { - mh := &peerMembersHandler{ - cluster: cluster, - } - - mux := http.NewServeMux() - mux.HandleFunc("/", http.NotFound) - mux.Handle(rafthttp.RaftPrefix, raftHandler) - mux.Handle(rafthttp.RaftPrefix+"/", raftHandler) - mux.Handle(peerMembersPrefix, mh) - if leaseHandler != nil { - mux.Handle(leasehttp.LeasePrefix, leaseHandler) - mux.Handle(leasehttp.LeaseInternalPrefix, leaseHandler) - } - mux.HandleFunc(versionPath, versionHandler(cluster, serveVersion)) - return mux -} - -type peerMembersHandler struct { - cluster api.Cluster -} - -func (h *peerMembersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r, "GET") { - return - } - w.Header().Set("X-Etcd-Cluster-ID", h.cluster.ID().String()) - - if r.URL.Path != peerMembersPrefix { - http.Error(w, "bad path", http.StatusBadRequest) - return - } - ms := h.cluster.Members() - w.Header().Set("Content-Type", "application/json") - if err := json.NewEncoder(w).Encode(ms); err != nil { - plog.Warningf("failed to encode members response (%v)", err) - } -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v2http/capability.go b/vendor/go.etcd.io/etcd/etcdserver/api/v2http/capability.go deleted file mode 100644 index fa0bcca5e846..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v2http/capability.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2http - -import ( - "fmt" - "net/http" - - "github.com/coreos/etcd/etcdserver/api" - "github.com/coreos/etcd/etcdserver/api/v2http/httptypes" -) - -func capabilityHandler(c api.Capability, fn func(http.ResponseWriter, *http.Request)) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - if !api.IsCapabilityEnabled(c) { - notCapable(w, r, c) - return - } - fn(w, r) - } -} - -func notCapable(w http.ResponseWriter, r *http.Request, c api.Capability) { - herr := httptypes.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Not capable of accessing %s feature during rolling upgrades.", c)) - if err := herr.WriteTo(w); err != nil { - plog.Debugf("error writing HTTPError (%v) to %s", err, r.RemoteAddr) - } -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v2http/client.go b/vendor/go.etcd.io/etcd/etcdserver/api/v2http/client.go deleted file mode 100644 index 6aaf3db360be..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v2http/client.go +++ /dev/null @@ -1,719 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2http - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "net/http" - "net/url" - "path" - "strconv" - "strings" - "time" - - etcdErr "github.com/coreos/etcd/error" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api" - "github.com/coreos/etcd/etcdserver/api/etcdhttp" - "github.com/coreos/etcd/etcdserver/api/v2http/httptypes" - "github.com/coreos/etcd/etcdserver/auth" - "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/etcdserver/stats" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/store" - - "github.com/jonboulle/clockwork" -) - -const ( - authPrefix = "/v2/auth" - keysPrefix = "/v2/keys" - machinesPrefix = "/v2/machines" - membersPrefix = "/v2/members" - statsPrefix = "/v2/stats" -) - -// NewClientHandler generates a muxed http.Handler with the given parameters to serve etcd client requests. -func NewClientHandler(server etcdserver.ServerPeer, timeout time.Duration) http.Handler { - mux := http.NewServeMux() - etcdhttp.HandleBasic(mux, server) - handleV2(mux, server, timeout) - return requestLogger(mux) -} - -func handleV2(mux *http.ServeMux, server etcdserver.ServerV2, timeout time.Duration) { - sec := auth.NewStore(server, timeout) - kh := &keysHandler{ - sec: sec, - server: server, - cluster: server.Cluster(), - timeout: timeout, - clientCertAuthEnabled: server.ClientCertAuthEnabled(), - } - - sh := &statsHandler{ - stats: server, - } - - mh := &membersHandler{ - sec: sec, - server: server, - cluster: server.Cluster(), - timeout: timeout, - clock: clockwork.NewRealClock(), - clientCertAuthEnabled: server.ClientCertAuthEnabled(), - } - - mah := &machinesHandler{cluster: server.Cluster()} - - sech := &authHandler{ - sec: sec, - cluster: server.Cluster(), - clientCertAuthEnabled: server.ClientCertAuthEnabled(), - } - mux.HandleFunc("/", http.NotFound) - mux.Handle(keysPrefix, kh) - mux.Handle(keysPrefix+"/", kh) - mux.HandleFunc(statsPrefix+"/store", sh.serveStore) - mux.HandleFunc(statsPrefix+"/self", sh.serveSelf) - mux.HandleFunc(statsPrefix+"/leader", sh.serveLeader) - mux.Handle(membersPrefix, mh) - mux.Handle(membersPrefix+"/", mh) - mux.Handle(machinesPrefix, mah) - handleAuth(mux, sech) -} - -type keysHandler struct { - sec auth.Store - server etcdserver.ServerV2 - cluster api.Cluster - timeout time.Duration - clientCertAuthEnabled bool -} - -func (h *keysHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "HEAD", "GET", "PUT", "POST", "DELETE") { - return - } - - w.Header().Set("X-Etcd-Cluster-ID", h.cluster.ID().String()) - - ctx, cancel := context.WithTimeout(context.Background(), h.timeout) - defer cancel() - clock := clockwork.NewRealClock() - startTime := clock.Now() - rr, noValueOnSuccess, err := parseKeyRequest(r, clock) - if err != nil { - writeKeyError(w, err) - return - } - // The path must be valid at this point (we've parsed the request successfully). - if !hasKeyPrefixAccess(h.sec, r, r.URL.Path[len(keysPrefix):], rr.Recursive, h.clientCertAuthEnabled) { - writeKeyNoAuth(w) - return - } - if !rr.Wait { - reportRequestReceived(rr) - } - resp, err := h.server.Do(ctx, rr) - if err != nil { - err = trimErrorPrefix(err, etcdserver.StoreKeysPrefix) - writeKeyError(w, err) - reportRequestFailed(rr, err) - return - } - switch { - case resp.Event != nil: - if err := writeKeyEvent(w, resp, noValueOnSuccess); err != nil { - // Should never be reached - plog.Errorf("error writing event (%v)", err) - } - reportRequestCompleted(rr, resp, startTime) - case resp.Watcher != nil: - ctx, cancel := context.WithTimeout(context.Background(), defaultWatchTimeout) - defer cancel() - handleKeyWatch(ctx, w, resp, rr.Stream) - default: - writeKeyError(w, errors.New("received response with no Event/Watcher!")) - } -} - -type machinesHandler struct { - cluster api.Cluster -} - -func (h *machinesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET", "HEAD") { - return - } - endpoints := h.cluster.ClientURLs() - w.Write([]byte(strings.Join(endpoints, ", "))) -} - -type membersHandler struct { - sec auth.Store - server etcdserver.ServerV2 - cluster api.Cluster - timeout time.Duration - clock clockwork.Clock - clientCertAuthEnabled bool -} - -func (h *membersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET", "POST", "DELETE", "PUT") { - return - } - if !hasWriteRootAccess(h.sec, r, h.clientCertAuthEnabled) { - writeNoAuth(w, r) - return - } - w.Header().Set("X-Etcd-Cluster-ID", h.cluster.ID().String()) - - ctx, cancel := context.WithTimeout(context.Background(), h.timeout) - defer cancel() - - switch r.Method { - case "GET": - switch trimPrefix(r.URL.Path, membersPrefix) { - case "": - mc := newMemberCollection(h.cluster.Members()) - w.Header().Set("Content-Type", "application/json") - if err := json.NewEncoder(w).Encode(mc); err != nil { - plog.Warningf("failed to encode members response (%v)", err) - } - case "leader": - id := h.server.Leader() - if id == 0 { - writeError(w, r, httptypes.NewHTTPError(http.StatusServiceUnavailable, "During election")) - return - } - m := newMember(h.cluster.Member(id)) - w.Header().Set("Content-Type", "application/json") - if err := json.NewEncoder(w).Encode(m); err != nil { - plog.Warningf("failed to encode members response (%v)", err) - } - default: - writeError(w, r, httptypes.NewHTTPError(http.StatusNotFound, "Not found")) - } - case "POST": - req := httptypes.MemberCreateRequest{} - if ok := unmarshalRequest(r, &req, w); !ok { - return - } - now := h.clock.Now() - m := membership.NewMember("", req.PeerURLs, "", &now) - _, err := h.server.AddMember(ctx, *m) - switch { - case err == membership.ErrIDExists || err == membership.ErrPeerURLexists: - writeError(w, r, httptypes.NewHTTPError(http.StatusConflict, err.Error())) - return - case err != nil: - plog.Errorf("error adding member %s (%v)", m.ID, err) - writeError(w, r, err) - return - } - res := newMember(m) - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusCreated) - if err := json.NewEncoder(w).Encode(res); err != nil { - plog.Warningf("failed to encode members response (%v)", err) - } - case "DELETE": - id, ok := getID(r.URL.Path, w) - if !ok { - return - } - _, err := h.server.RemoveMember(ctx, uint64(id)) - switch { - case err == membership.ErrIDRemoved: - writeError(w, r, httptypes.NewHTTPError(http.StatusGone, fmt.Sprintf("Member permanently removed: %s", id))) - case err == membership.ErrIDNotFound: - writeError(w, r, httptypes.NewHTTPError(http.StatusNotFound, fmt.Sprintf("No such member: %s", id))) - case err != nil: - plog.Errorf("error removing member %s (%v)", id, err) - writeError(w, r, err) - default: - w.WriteHeader(http.StatusNoContent) - } - case "PUT": - id, ok := getID(r.URL.Path, w) - if !ok { - return - } - req := httptypes.MemberUpdateRequest{} - if ok := unmarshalRequest(r, &req, w); !ok { - return - } - m := membership.Member{ - ID: id, - RaftAttributes: membership.RaftAttributes{PeerURLs: req.PeerURLs.StringSlice()}, - } - _, err := h.server.UpdateMember(ctx, m) - switch { - case err == membership.ErrPeerURLexists: - writeError(w, r, httptypes.NewHTTPError(http.StatusConflict, err.Error())) - case err == membership.ErrIDNotFound: - writeError(w, r, httptypes.NewHTTPError(http.StatusNotFound, fmt.Sprintf("No such member: %s", id))) - case err != nil: - plog.Errorf("error updating member %s (%v)", m.ID, err) - writeError(w, r, err) - default: - w.WriteHeader(http.StatusNoContent) - } - } -} - -type statsHandler struct { - stats stats.Stats -} - -func (h *statsHandler) serveStore(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET") { - return - } - w.Header().Set("Content-Type", "application/json") - w.Write(h.stats.StoreStats()) -} - -func (h *statsHandler) serveSelf(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET") { - return - } - w.Header().Set("Content-Type", "application/json") - w.Write(h.stats.SelfStats()) -} - -func (h *statsHandler) serveLeader(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET") { - return - } - stats := h.stats.LeaderStats() - if stats == nil { - etcdhttp.WriteError(w, r, httptypes.NewHTTPError(http.StatusForbidden, "not current leader")) - return - } - w.Header().Set("Content-Type", "application/json") - w.Write(stats) -} - -// parseKeyRequest converts a received http.Request on keysPrefix to -// a server Request, performing validation of supplied fields as appropriate. -// If any validation fails, an empty Request and non-nil error is returned. -func parseKeyRequest(r *http.Request, clock clockwork.Clock) (etcdserverpb.Request, bool, error) { - var noValueOnSuccess bool - emptyReq := etcdserverpb.Request{} - - err := r.ParseForm() - if err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidForm, - err.Error(), - ) - } - - if !strings.HasPrefix(r.URL.Path, keysPrefix) { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidForm, - "incorrect key prefix", - ) - } - p := path.Join(etcdserver.StoreKeysPrefix, r.URL.Path[len(keysPrefix):]) - - var pIdx, wIdx uint64 - if pIdx, err = getUint64(r.Form, "prevIndex"); err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeIndexNaN, - `invalid value for "prevIndex"`, - ) - } - if wIdx, err = getUint64(r.Form, "waitIndex"); err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeIndexNaN, - `invalid value for "waitIndex"`, - ) - } - - var rec, sort, wait, dir, quorum, stream bool - if rec, err = getBool(r.Form, "recursive"); err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - `invalid value for "recursive"`, - ) - } - if sort, err = getBool(r.Form, "sorted"); err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - `invalid value for "sorted"`, - ) - } - if wait, err = getBool(r.Form, "wait"); err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - `invalid value for "wait"`, - ) - } - // TODO(jonboulle): define what parameters dir is/isn't compatible with? - if dir, err = getBool(r.Form, "dir"); err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - `invalid value for "dir"`, - ) - } - if quorum, err = getBool(r.Form, "quorum"); err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - `invalid value for "quorum"`, - ) - } - if stream, err = getBool(r.Form, "stream"); err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - `invalid value for "stream"`, - ) - } - - if wait && r.Method != "GET" { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - `"wait" can only be used with GET requests`, - ) - } - - pV := r.FormValue("prevValue") - if _, ok := r.Form["prevValue"]; ok && pV == "" { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodePrevValueRequired, - `"prevValue" cannot be empty`, - ) - } - - if noValueOnSuccess, err = getBool(r.Form, "noValueOnSuccess"); err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - `invalid value for "noValueOnSuccess"`, - ) - } - - // TTL is nullable, so leave it null if not specified - // or an empty string - var ttl *uint64 - if len(r.FormValue("ttl")) > 0 { - i, err := getUint64(r.Form, "ttl") - if err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeTTLNaN, - `invalid value for "ttl"`, - ) - } - ttl = &i - } - - // prevExist is nullable, so leave it null if not specified - var pe *bool - if _, ok := r.Form["prevExist"]; ok { - bv, err := getBool(r.Form, "prevExist") - if err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - "invalid value for prevExist", - ) - } - pe = &bv - } - - // refresh is nullable, so leave it null if not specified - var refresh *bool - if _, ok := r.Form["refresh"]; ok { - bv, err := getBool(r.Form, "refresh") - if err != nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeInvalidField, - "invalid value for refresh", - ) - } - refresh = &bv - if refresh != nil && *refresh { - val := r.FormValue("value") - if _, ok := r.Form["value"]; ok && val != "" { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeRefreshValue, - `A value was provided on a refresh`, - ) - } - if ttl == nil { - return emptyReq, false, etcdErr.NewRequestError( - etcdErr.EcodeRefreshTTLRequired, - `No TTL value set`, - ) - } - } - } - - rr := etcdserverpb.Request{ - Method: r.Method, - Path: p, - Val: r.FormValue("value"), - Dir: dir, - PrevValue: pV, - PrevIndex: pIdx, - PrevExist: pe, - Wait: wait, - Since: wIdx, - Recursive: rec, - Sorted: sort, - Quorum: quorum, - Stream: stream, - } - - if pe != nil { - rr.PrevExist = pe - } - - if refresh != nil { - rr.Refresh = refresh - } - - // Null TTL is equivalent to unset Expiration - if ttl != nil { - expr := time.Duration(*ttl) * time.Second - rr.Expiration = clock.Now().Add(expr).UnixNano() - } - - return rr, noValueOnSuccess, nil -} - -// writeKeyEvent trims the prefix of key path in a single Event under -// StoreKeysPrefix, serializes it and writes the resulting JSON to the given -// ResponseWriter, along with the appropriate headers. -func writeKeyEvent(w http.ResponseWriter, resp etcdserver.Response, noValueOnSuccess bool) error { - ev := resp.Event - if ev == nil { - return errors.New("cannot write empty Event!") - } - w.Header().Set("Content-Type", "application/json") - w.Header().Set("X-Etcd-Index", fmt.Sprint(ev.EtcdIndex)) - w.Header().Set("X-Raft-Index", fmt.Sprint(resp.Index)) - w.Header().Set("X-Raft-Term", fmt.Sprint(resp.Term)) - - if ev.IsCreated() { - w.WriteHeader(http.StatusCreated) - } - - ev = trimEventPrefix(ev, etcdserver.StoreKeysPrefix) - if noValueOnSuccess && - (ev.Action == store.Set || ev.Action == store.CompareAndSwap || - ev.Action == store.Create || ev.Action == store.Update) { - ev.Node = nil - ev.PrevNode = nil - } - return json.NewEncoder(w).Encode(ev) -} - -func writeKeyNoAuth(w http.ResponseWriter) { - e := etcdErr.NewError(etcdErr.EcodeUnauthorized, "Insufficient credentials", 0) - e.WriteTo(w) -} - -// writeKeyError logs and writes the given Error to the ResponseWriter. -// If Error is not an etcdErr, the error will be converted to an etcd error. -func writeKeyError(w http.ResponseWriter, err error) { - if err == nil { - return - } - switch e := err.(type) { - case *etcdErr.Error: - e.WriteTo(w) - default: - switch err { - case etcdserver.ErrTimeoutDueToLeaderFail, etcdserver.ErrTimeoutDueToConnectionLost: - mlog.MergeError(err) - default: - mlog.MergeErrorf("got unexpected response error (%v)", err) - } - ee := etcdErr.NewError(etcdErr.EcodeRaftInternal, err.Error(), 0) - ee.WriteTo(w) - } -} - -func handleKeyWatch(ctx context.Context, w http.ResponseWriter, resp etcdserver.Response, stream bool) { - wa := resp.Watcher - defer wa.Remove() - ech := wa.EventChan() - var nch <-chan bool - if x, ok := w.(http.CloseNotifier); ok { - nch = x.CloseNotify() - } - - w.Header().Set("Content-Type", "application/json") - w.Header().Set("X-Etcd-Index", fmt.Sprint(wa.StartIndex())) - w.Header().Set("X-Raft-Index", fmt.Sprint(resp.Index)) - w.Header().Set("X-Raft-Term", fmt.Sprint(resp.Term)) - w.WriteHeader(http.StatusOK) - - // Ensure headers are flushed early, in case of long polling - w.(http.Flusher).Flush() - - for { - select { - case <-nch: - // Client closed connection. Nothing to do. - return - case <-ctx.Done(): - // Timed out. net/http will close the connection for us, so nothing to do. - return - case ev, ok := <-ech: - if !ok { - // If the channel is closed this may be an indication of - // that notifications are much more than we are able to - // send to the client in time. Then we simply end streaming. - return - } - ev = trimEventPrefix(ev, etcdserver.StoreKeysPrefix) - if err := json.NewEncoder(w).Encode(ev); err != nil { - // Should never be reached - plog.Warningf("error writing event (%v)", err) - return - } - if !stream { - return - } - w.(http.Flusher).Flush() - } - } -} - -func trimEventPrefix(ev *store.Event, prefix string) *store.Event { - if ev == nil { - return nil - } - // Since the *Event may reference one in the store history - // history, we must copy it before modifying - e := ev.Clone() - trimNodeExternPrefix(e.Node, prefix) - trimNodeExternPrefix(e.PrevNode, prefix) - return e -} - -func trimNodeExternPrefix(n *store.NodeExtern, prefix string) { - if n == nil { - return - } - n.Key = strings.TrimPrefix(n.Key, prefix) - for _, nn := range n.Nodes { - trimNodeExternPrefix(nn, prefix) - } -} - -func trimErrorPrefix(err error, prefix string) error { - if e, ok := err.(*etcdErr.Error); ok { - e.Cause = strings.TrimPrefix(e.Cause, prefix) - } - return err -} - -func unmarshalRequest(r *http.Request, req json.Unmarshaler, w http.ResponseWriter) bool { - ctype := r.Header.Get("Content-Type") - semicolonPosition := strings.Index(ctype, ";") - if semicolonPosition != -1 { - ctype = strings.TrimSpace(strings.ToLower(ctype[0:semicolonPosition])) - } - if ctype != "application/json" { - writeError(w, r, httptypes.NewHTTPError(http.StatusUnsupportedMediaType, fmt.Sprintf("Bad Content-Type %s, accept application/json", ctype))) - return false - } - b, err := ioutil.ReadAll(r.Body) - if err != nil { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, err.Error())) - return false - } - if err := req.UnmarshalJSON(b); err != nil { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, err.Error())) - return false - } - return true -} - -func getID(p string, w http.ResponseWriter) (types.ID, bool) { - idStr := trimPrefix(p, membersPrefix) - if idStr == "" { - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return 0, false - } - id, err := types.IDFromString(idStr) - if err != nil { - writeError(w, nil, httptypes.NewHTTPError(http.StatusNotFound, fmt.Sprintf("No such member: %s", idStr))) - return 0, false - } - return id, true -} - -// getUint64 extracts a uint64 by the given key from a Form. If the key does -// not exist in the form, 0 is returned. If the key exists but the value is -// badly formed, an error is returned. If multiple values are present only the -// first is considered. -func getUint64(form url.Values, key string) (i uint64, err error) { - if vals, ok := form[key]; ok { - i, err = strconv.ParseUint(vals[0], 10, 64) - } - return -} - -// getBool extracts a bool by the given key from a Form. If the key does not -// exist in the form, false is returned. If the key exists but the value is -// badly formed, an error is returned. If multiple values are present only the -// first is considered. -func getBool(form url.Values, key string) (b bool, err error) { - if vals, ok := form[key]; ok { - b, err = strconv.ParseBool(vals[0]) - } - return -} - -// trimPrefix removes a given prefix and any slash following the prefix -// e.g.: trimPrefix("foo", "foo") == trimPrefix("foo/", "foo") == "" -func trimPrefix(p, prefix string) (s string) { - s = strings.TrimPrefix(p, prefix) - s = strings.TrimPrefix(s, "/") - return -} - -func newMemberCollection(ms []*membership.Member) *httptypes.MemberCollection { - c := httptypes.MemberCollection(make([]httptypes.Member, len(ms))) - - for i, m := range ms { - c[i] = newMember(m) - } - - return &c -} - -func newMember(m *membership.Member) httptypes.Member { - tm := httptypes.Member{ - ID: m.ID.String(), - Name: m.Name, - PeerURLs: make([]string, len(m.PeerURLs)), - ClientURLs: make([]string, len(m.ClientURLs)), - } - - copy(tm.PeerURLs, m.PeerURLs) - copy(tm.ClientURLs, m.ClientURLs) - - return tm -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v2http/client_auth.go b/vendor/go.etcd.io/etcd/etcdserver/api/v2http/client_auth.go deleted file mode 100644 index 606e2e00b3ed..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v2http/client_auth.go +++ /dev/null @@ -1,543 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2http - -import ( - "encoding/json" - "net/http" - "path" - "strings" - - "github.com/coreos/etcd/etcdserver/api" - "github.com/coreos/etcd/etcdserver/api/v2http/httptypes" - "github.com/coreos/etcd/etcdserver/auth" -) - -type authHandler struct { - sec auth.Store - cluster api.Cluster - clientCertAuthEnabled bool -} - -func hasWriteRootAccess(sec auth.Store, r *http.Request, clientCertAuthEnabled bool) bool { - if r.Method == "GET" || r.Method == "HEAD" { - return true - } - return hasRootAccess(sec, r, clientCertAuthEnabled) -} - -func userFromBasicAuth(sec auth.Store, r *http.Request) *auth.User { - username, password, ok := r.BasicAuth() - if !ok { - plog.Warningf("auth: malformed basic auth encoding") - return nil - } - user, err := sec.GetUser(username) - if err != nil { - return nil - } - - ok = sec.CheckPassword(user, password) - if !ok { - plog.Warningf("auth: incorrect password for user: %s", username) - return nil - } - return &user -} - -func userFromClientCertificate(sec auth.Store, r *http.Request) *auth.User { - if r.TLS == nil { - return nil - } - - for _, chains := range r.TLS.VerifiedChains { - for _, chain := range chains { - plog.Debugf("auth: found common name %s.\n", chain.Subject.CommonName) - user, err := sec.GetUser(chain.Subject.CommonName) - if err == nil { - plog.Debugf("auth: authenticated user %s by cert common name.", user.User) - return &user - } - } - } - return nil -} - -func hasRootAccess(sec auth.Store, r *http.Request, clientCertAuthEnabled bool) bool { - if sec == nil { - // No store means no auth available, eg, tests. - return true - } - if !sec.AuthEnabled() { - return true - } - - var rootUser *auth.User - if r.Header.Get("Authorization") == "" && clientCertAuthEnabled { - rootUser = userFromClientCertificate(sec, r) - if rootUser == nil { - return false - } - } else { - rootUser = userFromBasicAuth(sec, r) - if rootUser == nil { - return false - } - } - - for _, role := range rootUser.Roles { - if role == auth.RootRoleName { - return true - } - } - plog.Warningf("auth: user %s does not have the %s role for resource %s.", rootUser.User, auth.RootRoleName, r.URL.Path) - return false -} - -func hasKeyPrefixAccess(sec auth.Store, r *http.Request, key string, recursive, clientCertAuthEnabled bool) bool { - if sec == nil { - // No store means no auth available, eg, tests. - return true - } - if !sec.AuthEnabled() { - return true - } - - var user *auth.User - if r.Header.Get("Authorization") == "" { - if clientCertAuthEnabled { - user = userFromClientCertificate(sec, r) - } - if user == nil { - return hasGuestAccess(sec, r, key) - } - } else { - user = userFromBasicAuth(sec, r) - if user == nil { - return false - } - } - - writeAccess := r.Method != "GET" && r.Method != "HEAD" - for _, roleName := range user.Roles { - role, err := sec.GetRole(roleName) - if err != nil { - continue - } - if recursive { - if role.HasRecursiveAccess(key, writeAccess) { - return true - } - } else if role.HasKeyAccess(key, writeAccess) { - return true - } - } - plog.Warningf("auth: invalid access for user %s on key %s.", user.User, key) - return false -} - -func hasGuestAccess(sec auth.Store, r *http.Request, key string) bool { - writeAccess := r.Method != "GET" && r.Method != "HEAD" - role, err := sec.GetRole(auth.GuestRoleName) - if err != nil { - return false - } - if role.HasKeyAccess(key, writeAccess) { - return true - } - plog.Warningf("auth: invalid access for unauthenticated user on resource %s.", key) - return false -} - -func writeNoAuth(w http.ResponseWriter, r *http.Request) { - herr := httptypes.NewHTTPError(http.StatusUnauthorized, "Insufficient credentials") - if err := herr.WriteTo(w); err != nil { - plog.Debugf("error writing HTTPError (%v) to %s", err, r.RemoteAddr) - } -} - -func handleAuth(mux *http.ServeMux, sh *authHandler) { - mux.HandleFunc(authPrefix+"/roles", capabilityHandler(api.AuthCapability, sh.baseRoles)) - mux.HandleFunc(authPrefix+"/roles/", capabilityHandler(api.AuthCapability, sh.handleRoles)) - mux.HandleFunc(authPrefix+"/users", capabilityHandler(api.AuthCapability, sh.baseUsers)) - mux.HandleFunc(authPrefix+"/users/", capabilityHandler(api.AuthCapability, sh.handleUsers)) - mux.HandleFunc(authPrefix+"/enable", capabilityHandler(api.AuthCapability, sh.enableDisable)) -} - -func (sh *authHandler) baseRoles(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET") { - return - } - if !hasRootAccess(sh.sec, r, sh.clientCertAuthEnabled) { - writeNoAuth(w, r) - return - } - - w.Header().Set("X-Etcd-Cluster-ID", sh.cluster.ID().String()) - w.Header().Set("Content-Type", "application/json") - - roles, err := sh.sec.AllRoles() - if err != nil { - writeError(w, r, err) - return - } - if roles == nil { - roles = make([]string, 0) - } - - err = r.ParseForm() - if err != nil { - writeError(w, r, err) - return - } - - var rolesCollections struct { - Roles []auth.Role `json:"roles"` - } - for _, roleName := range roles { - var role auth.Role - role, err = sh.sec.GetRole(roleName) - if err != nil { - writeError(w, r, err) - return - } - rolesCollections.Roles = append(rolesCollections.Roles, role) - } - err = json.NewEncoder(w).Encode(rolesCollections) - - if err != nil { - plog.Warningf("baseRoles error encoding on %s", r.URL) - writeError(w, r, err) - return - } -} - -func (sh *authHandler) handleRoles(w http.ResponseWriter, r *http.Request) { - subpath := path.Clean(r.URL.Path[len(authPrefix):]) - // Split "/roles/rolename/command". - // First item is an empty string, second is "roles" - pieces := strings.Split(subpath, "/") - if len(pieces) == 2 { - sh.baseRoles(w, r) - return - } - if len(pieces) != 3 { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Invalid path")) - return - } - sh.forRole(w, r, pieces[2]) -} - -func (sh *authHandler) forRole(w http.ResponseWriter, r *http.Request, role string) { - if !allowMethod(w, r.Method, "GET", "PUT", "DELETE") { - return - } - if !hasRootAccess(sh.sec, r, sh.clientCertAuthEnabled) { - writeNoAuth(w, r) - return - } - w.Header().Set("X-Etcd-Cluster-ID", sh.cluster.ID().String()) - w.Header().Set("Content-Type", "application/json") - - switch r.Method { - case "GET": - data, err := sh.sec.GetRole(role) - if err != nil { - writeError(w, r, err) - return - } - err = json.NewEncoder(w).Encode(data) - if err != nil { - plog.Warningf("forRole error encoding on %s", r.URL) - return - } - return - case "PUT": - var in auth.Role - err := json.NewDecoder(r.Body).Decode(&in) - if err != nil { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Invalid JSON in request body.")) - return - } - if in.Role != role { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Role JSON name does not match the name in the URL")) - return - } - - var out auth.Role - - // create - if in.Grant.IsEmpty() && in.Revoke.IsEmpty() { - err = sh.sec.CreateRole(in) - if err != nil { - writeError(w, r, err) - return - } - w.WriteHeader(http.StatusCreated) - out = in - } else { - if !in.Permissions.IsEmpty() { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Role JSON contains both permissions and grant/revoke")) - return - } - out, err = sh.sec.UpdateRole(in) - if err != nil { - writeError(w, r, err) - return - } - w.WriteHeader(http.StatusOK) - } - - err = json.NewEncoder(w).Encode(out) - if err != nil { - plog.Warningf("forRole error encoding on %s", r.URL) - return - } - return - case "DELETE": - err := sh.sec.DeleteRole(role) - if err != nil { - writeError(w, r, err) - return - } - } -} - -type userWithRoles struct { - User string `json:"user"` - Roles []auth.Role `json:"roles,omitempty"` -} - -type usersCollections struct { - Users []userWithRoles `json:"users"` -} - -func (sh *authHandler) baseUsers(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET") { - return - } - if !hasRootAccess(sh.sec, r, sh.clientCertAuthEnabled) { - writeNoAuth(w, r) - return - } - w.Header().Set("X-Etcd-Cluster-ID", sh.cluster.ID().String()) - w.Header().Set("Content-Type", "application/json") - - users, err := sh.sec.AllUsers() - if err != nil { - writeError(w, r, err) - return - } - if users == nil { - users = make([]string, 0) - } - - err = r.ParseForm() - if err != nil { - writeError(w, r, err) - return - } - - ucs := usersCollections{} - for _, userName := range users { - var user auth.User - user, err = sh.sec.GetUser(userName) - if err != nil { - writeError(w, r, err) - return - } - - uwr := userWithRoles{User: user.User} - for _, roleName := range user.Roles { - var role auth.Role - role, err = sh.sec.GetRole(roleName) - if err != nil { - continue - } - uwr.Roles = append(uwr.Roles, role) - } - - ucs.Users = append(ucs.Users, uwr) - } - err = json.NewEncoder(w).Encode(ucs) - - if err != nil { - plog.Warningf("baseUsers error encoding on %s", r.URL) - writeError(w, r, err) - return - } -} - -func (sh *authHandler) handleUsers(w http.ResponseWriter, r *http.Request) { - subpath := path.Clean(r.URL.Path[len(authPrefix):]) - // Split "/users/username". - // First item is an empty string, second is "users" - pieces := strings.Split(subpath, "/") - if len(pieces) == 2 { - sh.baseUsers(w, r) - return - } - if len(pieces) != 3 { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Invalid path")) - return - } - sh.forUser(w, r, pieces[2]) -} - -func (sh *authHandler) forUser(w http.ResponseWriter, r *http.Request, user string) { - if !allowMethod(w, r.Method, "GET", "PUT", "DELETE") { - return - } - if !hasRootAccess(sh.sec, r, sh.clientCertAuthEnabled) { - writeNoAuth(w, r) - return - } - w.Header().Set("X-Etcd-Cluster-ID", sh.cluster.ID().String()) - w.Header().Set("Content-Type", "application/json") - - switch r.Method { - case "GET": - u, err := sh.sec.GetUser(user) - if err != nil { - writeError(w, r, err) - return - } - - err = r.ParseForm() - if err != nil { - writeError(w, r, err) - return - } - - uwr := userWithRoles{User: u.User} - for _, roleName := range u.Roles { - var role auth.Role - role, err = sh.sec.GetRole(roleName) - if err != nil { - writeError(w, r, err) - return - } - uwr.Roles = append(uwr.Roles, role) - } - err = json.NewEncoder(w).Encode(uwr) - - if err != nil { - plog.Warningf("forUser error encoding on %s", r.URL) - return - } - return - case "PUT": - var u auth.User - err := json.NewDecoder(r.Body).Decode(&u) - if err != nil { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Invalid JSON in request body.")) - return - } - if u.User != user { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "User JSON name does not match the name in the URL")) - return - } - - var ( - out auth.User - created bool - ) - - if len(u.Grant) == 0 && len(u.Revoke) == 0 { - // create or update - if len(u.Roles) != 0 { - out, err = sh.sec.CreateUser(u) - } else { - // if user passes in both password and roles, we are unsure about his/her - // intention. - out, created, err = sh.sec.CreateOrUpdateUser(u) - } - - if err != nil { - writeError(w, r, err) - return - } - } else { - // update case - if len(u.Roles) != 0 { - writeError(w, r, httptypes.NewHTTPError(http.StatusBadRequest, "User JSON contains both roles and grant/revoke")) - return - } - out, err = sh.sec.UpdateUser(u) - if err != nil { - writeError(w, r, err) - return - } - } - - if created { - w.WriteHeader(http.StatusCreated) - } else { - w.WriteHeader(http.StatusOK) - } - - out.Password = "" - - err = json.NewEncoder(w).Encode(out) - if err != nil { - plog.Warningf("forUser error encoding on %s", r.URL) - return - } - return - case "DELETE": - err := sh.sec.DeleteUser(user) - if err != nil { - writeError(w, r, err) - return - } - } -} - -type enabled struct { - Enabled bool `json:"enabled"` -} - -func (sh *authHandler) enableDisable(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET", "PUT", "DELETE") { - return - } - if !hasWriteRootAccess(sh.sec, r, sh.clientCertAuthEnabled) { - writeNoAuth(w, r) - return - } - w.Header().Set("X-Etcd-Cluster-ID", sh.cluster.ID().String()) - w.Header().Set("Content-Type", "application/json") - isEnabled := sh.sec.AuthEnabled() - switch r.Method { - case "GET": - jsonDict := enabled{isEnabled} - err := json.NewEncoder(w).Encode(jsonDict) - if err != nil { - plog.Warningf("error encoding auth state on %s", r.URL) - } - case "PUT": - err := sh.sec.EnableAuth() - if err != nil { - writeError(w, r, err) - return - } - case "DELETE": - err := sh.sec.DisableAuth() - if err != nil { - writeError(w, r, err) - return - } - } -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v2http/doc.go b/vendor/go.etcd.io/etcd/etcdserver/api/v2http/doc.go deleted file mode 100644 index 475c4b1f95a3..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v2http/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v2http provides etcd client and server implementations. -package v2http diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v2http/http.go b/vendor/go.etcd.io/etcd/etcdserver/api/v2http/http.go deleted file mode 100644 index 589c172dbbb4..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v2http/http.go +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2http - -import ( - "math" - "net/http" - "strings" - "time" - - "github.com/coreos/etcd/etcdserver/api/etcdhttp" - "github.com/coreos/etcd/etcdserver/api/v2http/httptypes" - "github.com/coreos/etcd/etcdserver/auth" - "github.com/coreos/etcd/pkg/logutil" - - "github.com/coreos/pkg/capnslog" -) - -const ( - // time to wait for a Watch request - defaultWatchTimeout = time.Duration(math.MaxInt64) -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdserver/api/v2http") - mlog = logutil.NewMergeLogger(plog) -) - -func writeError(w http.ResponseWriter, r *http.Request, err error) { - if err == nil { - return - } - if e, ok := err.(auth.Error); ok { - herr := httptypes.NewHTTPError(e.HTTPStatus(), e.Error()) - if et := herr.WriteTo(w); et != nil { - plog.Debugf("error writing HTTPError (%v) to %s", et, r.RemoteAddr) - } - return - } - etcdhttp.WriteError(w, r, err) -} - -// allowMethod verifies that the given method is one of the allowed methods, -// and if not, it writes an error to w. A boolean is returned indicating -// whether or not the method is allowed. -func allowMethod(w http.ResponseWriter, m string, ms ...string) bool { - for _, meth := range ms { - if m == meth { - return true - } - } - w.Header().Set("Allow", strings.Join(ms, ",")) - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return false -} - -func requestLogger(handler http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - plog.Debugf("[%s] %s remote:%s", r.Method, r.RequestURI, r.RemoteAddr) - handler.ServeHTTP(w, r) - }) -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v2http/httptypes/errors.go b/vendor/go.etcd.io/etcd/etcdserver/api/v2http/httptypes/errors.go deleted file mode 100644 index 0657604ca976..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v2http/httptypes/errors.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package httptypes - -import ( - "encoding/json" - "net/http" - - "github.com/coreos/pkg/capnslog" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdserver/api/v2http/httptypes") -) - -type HTTPError struct { - Message string `json:"message"` - // Code is the HTTP status code - Code int `json:"-"` -} - -func (e HTTPError) Error() string { - return e.Message -} - -func (e HTTPError) WriteTo(w http.ResponseWriter) error { - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(e.Code) - b, err := json.Marshal(e) - if err != nil { - plog.Panicf("marshal HTTPError should never fail (%v)", err) - } - if _, err := w.Write(b); err != nil { - return err - } - return nil -} - -func NewHTTPError(code int, m string) *HTTPError { - return &HTTPError{ - Message: m, - Code: code, - } -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v2http/httptypes/member.go b/vendor/go.etcd.io/etcd/etcdserver/api/v2http/httptypes/member.go deleted file mode 100644 index 738d74432f84..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v2http/httptypes/member.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package httptypes defines how etcd's HTTP API entities are serialized to and -// deserialized from JSON. -package httptypes - -import ( - "encoding/json" - - "github.com/coreos/etcd/pkg/types" -) - -type Member struct { - ID string `json:"id"` - Name string `json:"name"` - PeerURLs []string `json:"peerURLs"` - ClientURLs []string `json:"clientURLs"` -} - -type MemberCreateRequest struct { - PeerURLs types.URLs -} - -type MemberUpdateRequest struct { - MemberCreateRequest -} - -func (m *MemberCreateRequest) UnmarshalJSON(data []byte) error { - s := struct { - PeerURLs []string `json:"peerURLs"` - }{} - - err := json.Unmarshal(data, &s) - if err != nil { - return err - } - - urls, err := types.NewURLs(s.PeerURLs) - if err != nil { - return err - } - - m.PeerURLs = urls - return nil -} - -type MemberCollection []Member - -func (c *MemberCollection) MarshalJSON() ([]byte, error) { - d := struct { - Members []Member `json:"members"` - }{ - Members: []Member(*c), - } - - return json.Marshal(d) -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v2http/metrics.go b/vendor/go.etcd.io/etcd/etcdserver/api/v2http/metrics.go deleted file mode 100644 index fdfb0c6070f9..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v2http/metrics.go +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2http - -import ( - "strconv" - "time" - - "net/http" - - etcdErr "github.com/coreos/etcd/error" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/v2http/httptypes" - "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/prometheus/client_golang/prometheus" -) - -var ( - incomingEvents = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "http", - Name: "received_total", - Help: "Counter of requests received into the system (successfully parsed and authd).", - }, []string{"method"}) - - failedEvents = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "http", - Name: "failed_total", - Help: "Counter of handle failures of requests (non-watches), by method (GET/PUT etc.) and code (400, 500 etc.).", - }, []string{"method", "code"}) - - successfulEventsHandlingTime = prometheus.NewHistogramVec( - prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "http", - Name: "successful_duration_seconds", - Help: "Bucketed histogram of processing time (s) of successfully handled requests (non-watches), by method (GET/PUT etc.).", - Buckets: prometheus.ExponentialBuckets(0.0005, 2, 13), - }, []string{"method"}) -) - -func init() { - prometheus.MustRegister(incomingEvents) - prometheus.MustRegister(failedEvents) - prometheus.MustRegister(successfulEventsHandlingTime) -} - -func reportRequestReceived(request etcdserverpb.Request) { - incomingEvents.WithLabelValues(methodFromRequest(request)).Inc() -} - -func reportRequestCompleted(request etcdserverpb.Request, response etcdserver.Response, startTime time.Time) { - method := methodFromRequest(request) - successfulEventsHandlingTime.WithLabelValues(method).Observe(time.Since(startTime).Seconds()) -} - -func reportRequestFailed(request etcdserverpb.Request, err error) { - method := methodFromRequest(request) - failedEvents.WithLabelValues(method, strconv.Itoa(codeFromError(err))).Inc() -} - -func methodFromRequest(request etcdserverpb.Request) string { - if request.Method == "GET" && request.Quorum { - return "QGET" - } - return request.Method -} - -func codeFromError(err error) int { - if err == nil { - return http.StatusInternalServerError - } - switch e := err.(type) { - case *etcdErr.Error: - return (*etcdErr.Error)(e).StatusCode() - case *httptypes.HTTPError: - return (*httptypes.HTTPError)(e).Code - default: - return http.StatusInternalServerError - } -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v2v3/cluster.go b/vendor/go.etcd.io/etcd/etcdserver/api/v2v3/cluster.go deleted file mode 100644 index b53e6d7c8b55..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v2v3/cluster.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2v3 - -import ( - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/pkg/types" - - "github.com/coreos/go-semver/semver" -) - -func (s *v2v3Server) ID() types.ID { - // TODO: use an actual member ID - return types.ID(0xe7cd2f00d) -} -func (s *v2v3Server) ClientURLs() []string { panic("STUB") } -func (s *v2v3Server) Members() []*membership.Member { panic("STUB") } -func (s *v2v3Server) Member(id types.ID) *membership.Member { panic("STUB") } -func (s *v2v3Server) Version() *semver.Version { panic("STUB") } diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v2v3/doc.go b/vendor/go.etcd.io/etcd/etcdserver/api/v2v3/doc.go deleted file mode 100644 index 2ff372f18760..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v2v3/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v2v3 provides a ServerV2 implementation backed by clientv3.Client. -package v2v3 diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v2v3/server.go b/vendor/go.etcd.io/etcd/etcdserver/api/v2v3/server.go deleted file mode 100644 index 2ef63ce68444..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v2v3/server.go +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2v3 - -import ( - "context" - "net/http" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/pkg/types" - - "github.com/coreos/go-semver/semver" -) - -type fakeStats struct{} - -func (s *fakeStats) SelfStats() []byte { return nil } -func (s *fakeStats) LeaderStats() []byte { return nil } -func (s *fakeStats) StoreStats() []byte { return nil } - -type v2v3Server struct { - c *clientv3.Client - store *v2v3Store - fakeStats -} - -func NewServer(c *clientv3.Client, pfx string) etcdserver.ServerPeer { - return &v2v3Server{c: c, store: newStore(c, pfx)} -} - -func (s *v2v3Server) ClientCertAuthEnabled() bool { return false } - -func (s *v2v3Server) LeaseHandler() http.Handler { panic("STUB: lease handler") } -func (s *v2v3Server) RaftHandler() http.Handler { panic("STUB: raft handler") } - -func (s *v2v3Server) Leader() types.ID { - ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second) - defer cancel() - resp, err := s.c.Status(ctx, s.c.Endpoints()[0]) - if err != nil { - return 0 - } - return types.ID(resp.Leader) -} - -func (s *v2v3Server) AddMember(ctx context.Context, memb membership.Member) ([]*membership.Member, error) { - resp, err := s.c.MemberAdd(ctx, memb.PeerURLs) - if err != nil { - return nil, err - } - return v3MembersToMembership(resp.Members), nil -} - -func (s *v2v3Server) RemoveMember(ctx context.Context, id uint64) ([]*membership.Member, error) { - resp, err := s.c.MemberRemove(ctx, id) - if err != nil { - return nil, err - } - return v3MembersToMembership(resp.Members), nil -} - -func (s *v2v3Server) UpdateMember(ctx context.Context, m membership.Member) ([]*membership.Member, error) { - resp, err := s.c.MemberUpdate(ctx, uint64(m.ID), m.PeerURLs) - if err != nil { - return nil, err - } - return v3MembersToMembership(resp.Members), nil -} - -func v3MembersToMembership(v3membs []*pb.Member) []*membership.Member { - membs := make([]*membership.Member, len(v3membs)) - for i, m := range v3membs { - membs[i] = &membership.Member{ - ID: types.ID(m.ID), - RaftAttributes: membership.RaftAttributes{ - PeerURLs: m.PeerURLs, - }, - Attributes: membership.Attributes{ - Name: m.Name, - ClientURLs: m.ClientURLs, - }, - } - } - return membs -} - -func (s *v2v3Server) ClusterVersion() *semver.Version { return s.Version() } -func (s *v2v3Server) Cluster() api.Cluster { return s } -func (s *v2v3Server) Alarms() []*pb.AlarmMember { return nil } - -func (s *v2v3Server) Do(ctx context.Context, r pb.Request) (etcdserver.Response, error) { - applier := etcdserver.NewApplierV2(s.store, nil) - reqHandler := etcdserver.NewStoreRequestV2Handler(s.store, applier) - req := (*etcdserver.RequestV2)(&r) - resp, err := req.Handle(ctx, reqHandler) - if resp.Err != nil { - return resp, resp.Err - } - return resp, err -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v2v3/store.go b/vendor/go.etcd.io/etcd/etcdserver/api/v2v3/store.go deleted file mode 100644 index 444f93f3a8e7..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v2v3/store.go +++ /dev/null @@ -1,620 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2v3 - -import ( - "context" - "fmt" - "path" - "strings" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/concurrency" - etcdErr "github.com/coreos/etcd/error" - "github.com/coreos/etcd/mvcc/mvccpb" - "github.com/coreos/etcd/store" -) - -// store implements the Store interface for V2 using -// a v3 client. -type v2v3Store struct { - c *clientv3.Client - // pfx is the v3 prefix where keys should be stored. - pfx string - ctx context.Context -} - -const maxPathDepth = 63 - -var errUnsupported = fmt.Errorf("TTLs are unsupported") - -func NewStore(c *clientv3.Client, pfx string) store.Store { return newStore(c, pfx) } - -func newStore(c *clientv3.Client, pfx string) *v2v3Store { return &v2v3Store{c, pfx, c.Ctx()} } - -func (s *v2v3Store) Index() uint64 { panic("STUB") } - -func (s *v2v3Store) Get(nodePath string, recursive, sorted bool) (*store.Event, error) { - key := s.mkPath(nodePath) - resp, err := s.c.Txn(s.ctx).Then( - clientv3.OpGet(key+"/"), - clientv3.OpGet(key), - ).Commit() - if err != nil { - return nil, err - } - - if kvs := resp.Responses[0].GetResponseRange().Kvs; len(kvs) != 0 || isRoot(nodePath) { - nodes, err := s.getDir(nodePath, recursive, sorted, resp.Header.Revision) - if err != nil { - return nil, err - } - cidx, midx := uint64(0), uint64(0) - if len(kvs) > 0 { - cidx, midx = mkV2Rev(kvs[0].CreateRevision), mkV2Rev(kvs[0].ModRevision) - } - return &store.Event{ - Action: store.Get, - Node: &store.NodeExtern{ - Key: nodePath, - Dir: true, - Nodes: nodes, - CreatedIndex: cidx, - ModifiedIndex: midx, - }, - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil - } - - kvs := resp.Responses[1].GetResponseRange().Kvs - if len(kvs) == 0 { - return nil, etcdErr.NewError(etcdErr.EcodeKeyNotFound, nodePath, mkV2Rev(resp.Header.Revision)) - } - - return &store.Event{ - Action: store.Get, - Node: s.mkV2Node(kvs[0]), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) getDir(nodePath string, recursive, sorted bool, rev int64) ([]*store.NodeExtern, error) { - rootNodes, err := s.getDirDepth(nodePath, 1, rev) - if err != nil || !recursive { - return rootNodes, err - } - nextNodes := rootNodes - nodes := make(map[string]*store.NodeExtern) - // Breadth walk the subdirectories - for i := 2; len(nextNodes) > 0; i++ { - for _, n := range nextNodes { - nodes[n.Key] = n - if parent := nodes[path.Dir(n.Key)]; parent != nil { - parent.Nodes = append(parent.Nodes, n) - } - } - if nextNodes, err = s.getDirDepth(nodePath, i, rev); err != nil { - return nil, err - } - } - return rootNodes, nil -} - -func (s *v2v3Store) getDirDepth(nodePath string, depth int, rev int64) ([]*store.NodeExtern, error) { - pd := s.mkPathDepth(nodePath, depth) - resp, err := s.c.Get(s.ctx, pd, clientv3.WithPrefix(), clientv3.WithRev(rev)) - if err != nil { - return nil, err - } - - nodes := make([]*store.NodeExtern, len(resp.Kvs)) - for i, kv := range resp.Kvs { - nodes[i] = s.mkV2Node(kv) - } - return nodes, nil -} - -func (s *v2v3Store) Set( - nodePath string, - dir bool, - value string, - expireOpts store.TTLOptionSet, -) (*store.Event, error) { - if expireOpts.Refresh || !expireOpts.ExpireTime.IsZero() { - return nil, errUnsupported - } - - if isRoot(nodePath) { - return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, nodePath, 0) - } - - ecode := 0 - applyf := func(stm concurrency.STM) error { - parent := path.Dir(nodePath) - if !isRoot(parent) && stm.Rev(s.mkPath(parent)+"/") == 0 { - ecode = etcdErr.EcodeKeyNotFound - return nil - } - - key := s.mkPath(nodePath) - if dir { - if stm.Rev(key) != 0 { - // exists as non-dir - ecode = etcdErr.EcodeNotDir - return nil - } - key = key + "/" - } else if stm.Rev(key+"/") != 0 { - ecode = etcdErr.EcodeNotFile - return nil - } - stm.Put(key, value, clientv3.WithPrevKV()) - stm.Put(s.mkActionKey(), store.Set) - return nil - } - - resp, err := s.newSTM(applyf) - if err != nil { - return nil, err - } - if ecode != 0 { - return nil, etcdErr.NewError(ecode, nodePath, mkV2Rev(resp.Header.Revision)) - } - - createRev := resp.Header.Revision - var pn *store.NodeExtern - if pkv := prevKeyFromPuts(resp); pkv != nil { - pn = s.mkV2Node(pkv) - createRev = pkv.CreateRevision - } - - vp := &value - if dir { - vp = nil - } - return &store.Event{ - Action: store.Set, - Node: &store.NodeExtern{ - Key: nodePath, - Value: vp, - Dir: dir, - ModifiedIndex: mkV2Rev(resp.Header.Revision), - CreatedIndex: mkV2Rev(createRev), - }, - PrevNode: pn, - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) Update(nodePath, newValue string, expireOpts store.TTLOptionSet) (*store.Event, error) { - if isRoot(nodePath) { - return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, nodePath, 0) - } - - if expireOpts.Refresh || !expireOpts.ExpireTime.IsZero() { - return nil, errUnsupported - } - - key := s.mkPath(nodePath) - ecode := 0 - applyf := func(stm concurrency.STM) error { - if rev := stm.Rev(key + "/"); rev != 0 { - ecode = etcdErr.EcodeNotFile - return nil - } - if rev := stm.Rev(key); rev == 0 { - ecode = etcdErr.EcodeKeyNotFound - return nil - } - stm.Put(key, newValue, clientv3.WithPrevKV()) - stm.Put(s.mkActionKey(), store.Update) - return nil - } - - resp, err := s.newSTM(applyf) - if err != nil { - return nil, err - } - if ecode != 0 { - return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, mkV2Rev(resp.Header.Revision)) - } - - pkv := prevKeyFromPuts(resp) - return &store.Event{ - Action: store.Update, - Node: &store.NodeExtern{ - Key: nodePath, - Value: &newValue, - ModifiedIndex: mkV2Rev(resp.Header.Revision), - CreatedIndex: mkV2Rev(pkv.CreateRevision), - }, - PrevNode: s.mkV2Node(pkv), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) Create( - nodePath string, - dir bool, - value string, - unique bool, - expireOpts store.TTLOptionSet, -) (*store.Event, error) { - if isRoot(nodePath) { - return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, nodePath, 0) - } - if expireOpts.Refresh || !expireOpts.ExpireTime.IsZero() { - return nil, errUnsupported - } - ecode := 0 - applyf := func(stm concurrency.STM) error { - ecode = 0 - key := s.mkPath(nodePath) - if unique { - // append unique item under the node path - for { - key = nodePath + "/" + fmt.Sprintf("%020s", time.Now()) - key = path.Clean(path.Join("/", key)) - key = s.mkPath(key) - if stm.Rev(key) == 0 { - break - } - } - } - if stm.Rev(key) > 0 || stm.Rev(key+"/") > 0 { - ecode = etcdErr.EcodeNodeExist - return nil - } - // build path if any directories in path do not exist - dirs := []string{} - for p := path.Dir(nodePath); !isRoot(p); p = path.Dir(p) { - pp := s.mkPath(p) - if stm.Rev(pp) > 0 { - ecode = etcdErr.EcodeNotDir - return nil - } - if stm.Rev(pp+"/") == 0 { - dirs = append(dirs, pp+"/") - } - } - for _, d := range dirs { - stm.Put(d, "") - } - - if dir { - // directories marked with extra slash in key name - key += "/" - } - stm.Put(key, value) - stm.Put(s.mkActionKey(), store.Create) - return nil - } - - resp, err := s.newSTM(applyf) - if err != nil { - return nil, err - } - if ecode != 0 { - return nil, etcdErr.NewError(ecode, nodePath, mkV2Rev(resp.Header.Revision)) - } - - var v *string - if !dir { - v = &value - } - - return &store.Event{ - Action: store.Create, - Node: &store.NodeExtern{ - Key: nodePath, - Value: v, - Dir: dir, - ModifiedIndex: mkV2Rev(resp.Header.Revision), - CreatedIndex: mkV2Rev(resp.Header.Revision), - }, - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) CompareAndSwap( - nodePath string, - prevValue string, - prevIndex uint64, - value string, - expireOpts store.TTLOptionSet, -) (*store.Event, error) { - if isRoot(nodePath) { - return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, nodePath, 0) - } - if expireOpts.Refresh || !expireOpts.ExpireTime.IsZero() { - return nil, errUnsupported - } - - key := s.mkPath(nodePath) - resp, err := s.c.Txn(s.ctx).If( - s.mkCompare(nodePath, prevValue, prevIndex)..., - ).Then( - clientv3.OpPut(key, value, clientv3.WithPrevKV()), - clientv3.OpPut(s.mkActionKey(), store.CompareAndSwap), - ).Else( - clientv3.OpGet(key), - clientv3.OpGet(key+"/"), - ).Commit() - - if err != nil { - return nil, err - } - if !resp.Succeeded { - return nil, compareFail(nodePath, prevValue, prevIndex, resp) - } - - pkv := resp.Responses[0].GetResponsePut().PrevKv - return &store.Event{ - Action: store.CompareAndSwap, - Node: &store.NodeExtern{ - Key: nodePath, - Value: &value, - CreatedIndex: mkV2Rev(pkv.CreateRevision), - ModifiedIndex: mkV2Rev(resp.Header.Revision), - }, - PrevNode: s.mkV2Node(pkv), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) Delete(nodePath string, dir, recursive bool) (*store.Event, error) { - if isRoot(nodePath) { - return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, nodePath, 0) - } - if !dir && !recursive { - return s.deleteNode(nodePath) - } - if !recursive { - return s.deleteEmptyDir(nodePath) - } - - dels := make([]clientv3.Op, maxPathDepth+1) - dels[0] = clientv3.OpDelete(s.mkPath(nodePath)+"/", clientv3.WithPrevKV()) - for i := 1; i < maxPathDepth; i++ { - dels[i] = clientv3.OpDelete(s.mkPathDepth(nodePath, i), clientv3.WithPrefix()) - } - dels[maxPathDepth] = clientv3.OpPut(s.mkActionKey(), store.Delete) - - resp, err := s.c.Txn(s.ctx).If( - clientv3.Compare(clientv3.Version(s.mkPath(nodePath)+"/"), ">", 0), - clientv3.Compare(clientv3.Version(s.mkPathDepth(nodePath, maxPathDepth)+"/"), "=", 0), - ).Then( - dels..., - ).Commit() - if err != nil { - return nil, err - } - if !resp.Succeeded { - return nil, etcdErr.NewError(etcdErr.EcodeNodeExist, nodePath, mkV2Rev(resp.Header.Revision)) - } - dresp := resp.Responses[0].GetResponseDeleteRange() - return &store.Event{ - Action: store.Delete, - PrevNode: s.mkV2Node(dresp.PrevKvs[0]), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) deleteEmptyDir(nodePath string) (*store.Event, error) { - resp, err := s.c.Txn(s.ctx).If( - clientv3.Compare(clientv3.Version(s.mkPathDepth(nodePath, 1)), "=", 0).WithPrefix(), - ).Then( - clientv3.OpDelete(s.mkPath(nodePath)+"/", clientv3.WithPrevKV()), - clientv3.OpPut(s.mkActionKey(), store.Delete), - ).Commit() - if err != nil { - return nil, err - } - if !resp.Succeeded { - return nil, etcdErr.NewError(etcdErr.EcodeDirNotEmpty, nodePath, mkV2Rev(resp.Header.Revision)) - } - dresp := resp.Responses[0].GetResponseDeleteRange() - if len(dresp.PrevKvs) == 0 { - return nil, etcdErr.NewError(etcdErr.EcodeNodeExist, nodePath, mkV2Rev(resp.Header.Revision)) - } - return &store.Event{ - Action: store.Delete, - PrevNode: s.mkV2Node(dresp.PrevKvs[0]), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) deleteNode(nodePath string) (*store.Event, error) { - resp, err := s.c.Txn(s.ctx).If( - clientv3.Compare(clientv3.Version(s.mkPath(nodePath)+"/"), "=", 0), - ).Then( - clientv3.OpDelete(s.mkPath(nodePath), clientv3.WithPrevKV()), - clientv3.OpPut(s.mkActionKey(), store.Delete), - ).Commit() - if err != nil { - return nil, err - } - if !resp.Succeeded { - return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, mkV2Rev(resp.Header.Revision)) - } - pkvs := resp.Responses[0].GetResponseDeleteRange().PrevKvs - if len(pkvs) == 0 { - return nil, etcdErr.NewError(etcdErr.EcodeKeyNotFound, nodePath, mkV2Rev(resp.Header.Revision)) - } - pkv := pkvs[0] - return &store.Event{ - Action: store.Delete, - Node: &store.NodeExtern{ - Key: nodePath, - CreatedIndex: mkV2Rev(pkv.CreateRevision), - ModifiedIndex: mkV2Rev(resp.Header.Revision), - }, - PrevNode: s.mkV2Node(pkv), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) CompareAndDelete(nodePath, prevValue string, prevIndex uint64) (*store.Event, error) { - if isRoot(nodePath) { - return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, nodePath, 0) - } - - key := s.mkPath(nodePath) - resp, err := s.c.Txn(s.ctx).If( - s.mkCompare(nodePath, prevValue, prevIndex)..., - ).Then( - clientv3.OpDelete(key, clientv3.WithPrevKV()), - clientv3.OpPut(s.mkActionKey(), store.CompareAndDelete), - ).Else( - clientv3.OpGet(key), - clientv3.OpGet(key+"/"), - ).Commit() - - if err != nil { - return nil, err - } - if !resp.Succeeded { - return nil, compareFail(nodePath, prevValue, prevIndex, resp) - } - - // len(pkvs) > 1 since txn only succeeds when key exists - pkv := resp.Responses[0].GetResponseDeleteRange().PrevKvs[0] - return &store.Event{ - Action: store.CompareAndDelete, - Node: &store.NodeExtern{ - Key: nodePath, - CreatedIndex: mkV2Rev(pkv.CreateRevision), - ModifiedIndex: mkV2Rev(resp.Header.Revision), - }, - PrevNode: s.mkV2Node(pkv), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func compareFail(nodePath, prevValue string, prevIndex uint64, resp *clientv3.TxnResponse) error { - if dkvs := resp.Responses[1].GetResponseRange().Kvs; len(dkvs) > 0 { - return etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, mkV2Rev(resp.Header.Revision)) - } - kvs := resp.Responses[0].GetResponseRange().Kvs - if len(kvs) == 0 { - return etcdErr.NewError(etcdErr.EcodeKeyNotFound, nodePath, mkV2Rev(resp.Header.Revision)) - } - kv := kvs[0] - indexMatch := (prevIndex == 0 || kv.ModRevision == int64(prevIndex)) - valueMatch := (prevValue == "" || string(kv.Value) == prevValue) - var cause string - switch { - case indexMatch && !valueMatch: - cause = fmt.Sprintf("[%v != %v]", prevValue, string(kv.Value)) - case valueMatch && !indexMatch: - cause = fmt.Sprintf("[%v != %v]", prevIndex, kv.ModRevision) - default: - cause = fmt.Sprintf("[%v != %v] [%v != %v]", prevValue, string(kv.Value), prevIndex, kv.ModRevision) - } - return etcdErr.NewError(etcdErr.EcodeTestFailed, cause, mkV2Rev(resp.Header.Revision)) -} - -func (s *v2v3Store) mkCompare(nodePath, prevValue string, prevIndex uint64) []clientv3.Cmp { - key := s.mkPath(nodePath) - cmps := []clientv3.Cmp{clientv3.Compare(clientv3.Version(key), ">", 0)} - if prevIndex != 0 { - cmps = append(cmps, clientv3.Compare(clientv3.ModRevision(key), "=", mkV3Rev(prevIndex))) - } - if prevValue != "" { - cmps = append(cmps, clientv3.Compare(clientv3.Value(key), "=", prevValue)) - } - return cmps -} - -func (s *v2v3Store) JsonStats() []byte { panic("STUB") } -func (s *v2v3Store) DeleteExpiredKeys(cutoff time.Time) { panic("STUB") } - -func (s *v2v3Store) Version() int { return 2 } - -// TODO: move this out of the Store interface? - -func (s *v2v3Store) Save() ([]byte, error) { panic("STUB") } -func (s *v2v3Store) Recovery(state []byte) error { panic("STUB") } -func (s *v2v3Store) Clone() store.Store { panic("STUB") } -func (s *v2v3Store) SaveNoCopy() ([]byte, error) { panic("STUB") } -func (s *v2v3Store) HasTTLKeys() bool { panic("STUB") } - -func (s *v2v3Store) mkPath(nodePath string) string { return s.mkPathDepth(nodePath, 0) } - -func (s *v2v3Store) mkNodePath(p string) string { - return path.Clean(p[len(s.pfx)+len("/k/000/"):]) -} - -// mkPathDepth makes a path to a key that encodes its directory depth -// for fast directory listing. If a depth is provided, it is added -// to the computed depth. -func (s *v2v3Store) mkPathDepth(nodePath string, depth int) string { - normalForm := path.Clean(path.Join("/", nodePath)) - n := strings.Count(normalForm, "/") + depth - return fmt.Sprintf("%s/%03d/k/%s", s.pfx, n, normalForm) -} - -func (s *v2v3Store) mkActionKey() string { return s.pfx + "/act" } - -func isRoot(s string) bool { return len(s) == 0 || s == "/" || s == "/0" || s == "/1" } - -func mkV2Rev(v3Rev int64) uint64 { - if v3Rev == 0 { - return 0 - } - return uint64(v3Rev - 1) -} - -func mkV3Rev(v2Rev uint64) int64 { - if v2Rev == 0 { - return 0 - } - return int64(v2Rev + 1) -} - -// mkV2Node creates a V2 NodeExtern from a V3 KeyValue -func (s *v2v3Store) mkV2Node(kv *mvccpb.KeyValue) *store.NodeExtern { - if kv == nil { - return nil - } - n := &store.NodeExtern{ - Key: string(s.mkNodePath(string(kv.Key))), - Dir: kv.Key[len(kv.Key)-1] == '/', - CreatedIndex: mkV2Rev(kv.CreateRevision), - ModifiedIndex: mkV2Rev(kv.ModRevision), - } - if !n.Dir { - v := string(kv.Value) - n.Value = &v - } - return n -} - -// prevKeyFromPuts gets the prev key that is being put; ignores -// the put action response. -func prevKeyFromPuts(resp *clientv3.TxnResponse) *mvccpb.KeyValue { - for _, r := range resp.Responses { - pkv := r.GetResponsePut().PrevKv - if pkv != nil && pkv.CreateRevision > 0 { - return pkv - } - } - return nil -} - -func (s *v2v3Store) newSTM(applyf func(concurrency.STM) error) (*clientv3.TxnResponse, error) { - return concurrency.NewSTM(s.c, applyf, concurrency.WithIsolation(concurrency.Serializable)) -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v2v3/watcher.go b/vendor/go.etcd.io/etcd/etcdserver/api/v2v3/watcher.go deleted file mode 100644 index 1c2680e744a1..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v2v3/watcher.go +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2v3 - -import ( - "context" - "strings" - - "github.com/coreos/etcd/clientv3" - etcdErr "github.com/coreos/etcd/error" - "github.com/coreos/etcd/store" -) - -func (s *v2v3Store) Watch(prefix string, recursive, stream bool, sinceIndex uint64) (store.Watcher, error) { - ctx, cancel := context.WithCancel(s.ctx) - wch := s.c.Watch( - ctx, - // TODO: very pricey; use a single store-wide watch in future - s.pfx, - clientv3.WithPrefix(), - clientv3.WithRev(int64(sinceIndex)), - clientv3.WithCreatedNotify(), - clientv3.WithPrevKV()) - resp, ok := <-wch - if err := resp.Err(); err != nil || !ok { - cancel() - return nil, etcdErr.NewError(etcdErr.EcodeRaftInternal, prefix, 0) - } - - evc, donec := make(chan *store.Event), make(chan struct{}) - go func() { - defer func() { - close(evc) - close(donec) - }() - for resp := range wch { - for _, ev := range s.mkV2Events(resp) { - k := ev.Node.Key - if recursive { - if !strings.HasPrefix(k, prefix) { - continue - } - // accept events on hidden keys given in prefix - k = strings.Replace(k, prefix, "/", 1) - // ignore hidden keys deeper than prefix - if strings.Contains(k, "/_") { - continue - } - } - if !recursive && k != prefix { - continue - } - select { - case evc <- ev: - case <-ctx.Done(): - return - } - if !stream { - return - } - } - } - }() - - return &v2v3Watcher{ - startRev: resp.Header.Revision, - evc: evc, - donec: donec, - cancel: cancel, - }, nil -} - -func (s *v2v3Store) mkV2Events(wr clientv3.WatchResponse) (evs []*store.Event) { - ak := s.mkActionKey() - for _, rev := range mkRevs(wr) { - var act, key *clientv3.Event - for _, ev := range rev { - if string(ev.Kv.Key) == ak { - act = ev - } else if key != nil && len(key.Kv.Key) < len(ev.Kv.Key) { - // use longest key to ignore intermediate new - // directories from Create. - key = ev - } else if key == nil { - key = ev - } - } - v2ev := &store.Event{ - Action: string(act.Kv.Value), - Node: s.mkV2Node(key.Kv), - PrevNode: s.mkV2Node(key.PrevKv), - EtcdIndex: mkV2Rev(wr.Header.Revision), - } - evs = append(evs, v2ev) - } - return evs -} - -func mkRevs(wr clientv3.WatchResponse) (revs [][]*clientv3.Event) { - var curRev []*clientv3.Event - for _, ev := range wr.Events { - if curRev != nil && ev.Kv.ModRevision != curRev[0].Kv.ModRevision { - revs = append(revs, curRev) - curRev = nil - } - curRev = append(curRev, ev) - } - if curRev != nil { - revs = append(revs, curRev) - } - return revs -} - -type v2v3Watcher struct { - startRev int64 - evc chan *store.Event - donec chan struct{} - cancel context.CancelFunc -} - -func (w *v2v3Watcher) StartIndex() uint64 { return mkV2Rev(w.startRev) } - -func (w *v2v3Watcher) Remove() { - w.cancel() - <-w.donec -} - -func (w *v2v3Watcher) EventChan() chan *store.Event { return w.evc } diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3client/doc.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3client/doc.go deleted file mode 100644 index 310715f5cd74..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3client/doc.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v3client provides clientv3 interfaces from an etcdserver. -// -// Use v3client by creating an EtcdServer instance, then wrapping it with v3client.New: -// -// import ( -// "context" -// -// "github.com/coreos/etcd/embed" -// "github.com/coreos/etcd/etcdserver/api/v3client" -// ) -// -// ... -// -// // create an embedded EtcdServer from the default configuration -// cfg := embed.NewConfig() -// cfg.Dir = "default.etcd" -// e, err := embed.StartEtcd(cfg) -// if err != nil { -// // handle error! -// } -// -// // wrap the EtcdServer with v3client -// cli := v3client.New(e.Server) -// -// // use like an ordinary clientv3 -// resp, err := cli.Put(context.TODO(), "some-key", "it works!") -// if err != nil { -// // handle error! -// } -// -package v3client diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3client/v3client.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3client/v3client.go deleted file mode 100644 index ab48ea75b91b..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3client/v3client.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3client - -import ( - "context" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/v3rpc" - "github.com/coreos/etcd/proxy/grpcproxy/adapter" -) - -// New creates a clientv3 client that wraps an in-process EtcdServer. Instead -// of making gRPC calls through sockets, the client makes direct function calls -// to the etcd server through its api/v3rpc function interfaces. -func New(s *etcdserver.EtcdServer) *clientv3.Client { - c := clientv3.NewCtxClient(context.Background()) - - kvc := adapter.KvServerToKvClient(v3rpc.NewQuotaKVServer(s)) - c.KV = clientv3.NewKVFromKVClient(kvc, c) - - lc := adapter.LeaseServerToLeaseClient(v3rpc.NewQuotaLeaseServer(s)) - c.Lease = clientv3.NewLeaseFromLeaseClient(lc, c, time.Second) - - wc := adapter.WatchServerToWatchClient(v3rpc.NewWatchServer(s)) - c.Watcher = &watchWrapper{clientv3.NewWatchFromWatchClient(wc, c)} - - mc := adapter.MaintenanceServerToMaintenanceClient(v3rpc.NewMaintenanceServer(s)) - c.Maintenance = clientv3.NewMaintenanceFromMaintenanceClient(mc, c) - - clc := adapter.ClusterServerToClusterClient(v3rpc.NewClusterServer(s)) - c.Cluster = clientv3.NewClusterFromClusterClient(clc, c) - - // TODO: implement clientv3.Auth interface? - - return c -} - -// BlankContext implements Stringer on a context so the ctx string doesn't -// depend on the context's WithValue data, which tends to be unsynchronized -// (e.g., x/net/trace), causing ctx.String() to throw data races. -type blankContext struct{ context.Context } - -func (*blankContext) String() string { return "(blankCtx)" } - -// watchWrapper wraps clientv3 watch calls to blank out the context -// to avoid races on trace data. -type watchWrapper struct{ clientv3.Watcher } - -func (ww *watchWrapper) Watch(ctx context.Context, key string, opts ...clientv3.OpOption) clientv3.WatchChan { - return ww.Watcher.Watch(&blankContext{ctx}, key, opts...) -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3election/doc.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3election/doc.go deleted file mode 100644 index d6fefd741500..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3election/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v3election provides a v3 election service from an etcdserver. -package v3election diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3election/election.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3election/election.go deleted file mode 100644 index c66d7a38290d..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3election/election.go +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3election - -import ( - "context" - "errors" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/concurrency" - epb "github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb" -) - -// ErrMissingLeaderKey is returned when election API request -// is missing the "leader" field. -var ErrMissingLeaderKey = errors.New(`"leader" field must be provided`) - -type electionServer struct { - c *clientv3.Client -} - -func NewElectionServer(c *clientv3.Client) epb.ElectionServer { - return &electionServer{c} -} - -func (es *electionServer) Campaign(ctx context.Context, req *epb.CampaignRequest) (*epb.CampaignResponse, error) { - s, err := es.session(ctx, req.Lease) - if err != nil { - return nil, err - } - e := concurrency.NewElection(s, string(req.Name)) - if err = e.Campaign(ctx, string(req.Value)); err != nil { - return nil, err - } - return &epb.CampaignResponse{ - Header: e.Header(), - Leader: &epb.LeaderKey{ - Name: req.Name, - Key: []byte(e.Key()), - Rev: e.Rev(), - Lease: int64(s.Lease()), - }, - }, nil -} - -func (es *electionServer) Proclaim(ctx context.Context, req *epb.ProclaimRequest) (*epb.ProclaimResponse, error) { - if req.Leader == nil { - return nil, ErrMissingLeaderKey - } - s, err := es.session(ctx, req.Leader.Lease) - if err != nil { - return nil, err - } - e := concurrency.ResumeElection(s, string(req.Leader.Name), string(req.Leader.Key), req.Leader.Rev) - if err := e.Proclaim(ctx, string(req.Value)); err != nil { - return nil, err - } - return &epb.ProclaimResponse{Header: e.Header()}, nil -} - -func (es *electionServer) Observe(req *epb.LeaderRequest, stream epb.Election_ObserveServer) error { - s, err := es.session(stream.Context(), -1) - if err != nil { - return err - } - e := concurrency.NewElection(s, string(req.Name)) - ch := e.Observe(stream.Context()) - for stream.Context().Err() == nil { - select { - case <-stream.Context().Done(): - case resp, ok := <-ch: - if !ok { - return nil - } - lresp := &epb.LeaderResponse{Header: resp.Header, Kv: resp.Kvs[0]} - if err := stream.Send(lresp); err != nil { - return err - } - } - } - return stream.Context().Err() -} - -func (es *electionServer) Leader(ctx context.Context, req *epb.LeaderRequest) (*epb.LeaderResponse, error) { - s, err := es.session(ctx, -1) - if err != nil { - return nil, err - } - l, lerr := concurrency.NewElection(s, string(req.Name)).Leader(ctx) - if lerr != nil { - return nil, lerr - } - return &epb.LeaderResponse{Header: l.Header, Kv: l.Kvs[0]}, nil -} - -func (es *electionServer) Resign(ctx context.Context, req *epb.ResignRequest) (*epb.ResignResponse, error) { - if req.Leader == nil { - return nil, ErrMissingLeaderKey - } - s, err := es.session(ctx, req.Leader.Lease) - if err != nil { - return nil, err - } - e := concurrency.ResumeElection(s, string(req.Leader.Name), string(req.Leader.Key), req.Leader.Rev) - if err := e.Resign(ctx); err != nil { - return nil, err - } - return &epb.ResignResponse{Header: e.Header()}, nil -} - -func (es *electionServer) session(ctx context.Context, lease int64) (*concurrency.Session, error) { - s, err := concurrency.NewSession( - es.c, - concurrency.WithLease(clientv3.LeaseID(lease)), - concurrency.WithContext(ctx), - ) - if err != nil { - return nil, err - } - s.Orphan() - return s, nil -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3election/v3electionpb/gw/v3election.pb.gw.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3election/v3electionpb/gw/v3election.pb.gw.go deleted file mode 100644 index 58368bbfb30c..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3election/v3electionpb/gw/v3election.pb.gw.go +++ /dev/null @@ -1,313 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: etcdserver/api/v3election/v3electionpb/v3election.proto - -/* -Package v3electionpb is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package gw - -import ( - "github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb" - "io" - "net/http" - - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "golang.org/x/net/context" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/status" -) - -var _ codes.Code -var _ io.Reader -var _ status.Status -var _ = runtime.String -var _ = utilities.NewDoubleArray - -func request_Election_Campaign_0(ctx context.Context, marshaler runtime.Marshaler, client v3electionpb.ElectionClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3electionpb.CampaignRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Campaign(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Election_Proclaim_0(ctx context.Context, marshaler runtime.Marshaler, client v3electionpb.ElectionClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3electionpb.ProclaimRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Proclaim(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Election_Leader_0(ctx context.Context, marshaler runtime.Marshaler, client v3electionpb.ElectionClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3electionpb.LeaderRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Leader(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Election_Observe_0(ctx context.Context, marshaler runtime.Marshaler, client v3electionpb.ElectionClient, req *http.Request, pathParams map[string]string) (v3electionpb.Election_ObserveClient, runtime.ServerMetadata, error) { - var protoReq v3electionpb.LeaderRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - stream, err := client.Observe(ctx, &protoReq) - if err != nil { - return nil, metadata, err - } - header, err := stream.Header() - if err != nil { - return nil, metadata, err - } - metadata.HeaderMD = header - return stream, metadata, nil - -} - -func request_Election_Resign_0(ctx context.Context, marshaler runtime.Marshaler, client v3electionpb.ElectionClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3electionpb.ResignRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Resign(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -// RegisterElectionHandlerFromEndpoint is same as RegisterElectionHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterElectionHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterElectionHandler(ctx, mux, conn) -} - -// RegisterElectionHandler registers the http handlers for service Election to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterElectionHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterElectionHandlerClient(ctx, mux, v3electionpb.NewElectionClient(conn)) -} - -// RegisterElectionHandler registers the http handlers for service Election to "mux". -// The handlers forward requests to the grpc endpoint over the given implementation of "ElectionClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "ElectionClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "ElectionClient" to call the correct interceptors. -func RegisterElectionHandlerClient(ctx context.Context, mux *runtime.ServeMux, client v3electionpb.ElectionClient) error { - - mux.Handle("POST", pattern_Election_Campaign_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Election_Campaign_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Election_Campaign_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Election_Proclaim_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Election_Proclaim_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Election_Proclaim_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Election_Leader_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Election_Leader_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Election_Leader_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Election_Observe_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Election_Observe_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Election_Observe_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Election_Resign_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Election_Resign_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Election_Resign_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Election_Campaign_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "election", "campaign"}, "")) - - pattern_Election_Proclaim_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "election", "proclaim"}, "")) - - pattern_Election_Leader_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "election", "leader"}, "")) - - pattern_Election_Observe_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "election", "observe"}, "")) - - pattern_Election_Resign_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "election", "resign"}, "")) -) - -var ( - forward_Election_Campaign_0 = runtime.ForwardResponseMessage - - forward_Election_Proclaim_0 = runtime.ForwardResponseMessage - - forward_Election_Leader_0 = runtime.ForwardResponseMessage - - forward_Election_Observe_0 = runtime.ForwardResponseStream - - forward_Election_Resign_0 = runtime.ForwardResponseMessage -) diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3election/v3electionpb/v3election.pb.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3election/v3electionpb/v3election.pb.go deleted file mode 100644 index e298e452119d..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3election/v3electionpb/v3election.pb.go +++ /dev/null @@ -1,2079 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: v3election.proto - -/* - Package v3electionpb is a generated protocol buffer package. - - It is generated from these files: - v3election.proto - - It has these top-level messages: - CampaignRequest - CampaignResponse - LeaderKey - LeaderRequest - LeaderResponse - ResignRequest - ResignResponse - ProclaimRequest - ProclaimResponse -*/ -package v3electionpb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - etcdserverpb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - mvccpb "github.com/coreos/etcd/mvcc/mvccpb" - - context "golang.org/x/net/context" - - grpc "google.golang.org/grpc" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type CampaignRequest struct { - // name is the election's identifier for the campaign. - Name []byte `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - // lease is the ID of the lease attached to leadership of the election. If the - // lease expires or is revoked before resigning leadership, then the - // leadership is transferred to the next campaigner, if any. - Lease int64 `protobuf:"varint,2,opt,name=lease,proto3" json:"lease,omitempty"` - // value is the initial proclaimed value set when the campaigner wins the - // election. - Value []byte `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty"` -} - -func (m *CampaignRequest) Reset() { *m = CampaignRequest{} } -func (m *CampaignRequest) String() string { return proto.CompactTextString(m) } -func (*CampaignRequest) ProtoMessage() {} -func (*CampaignRequest) Descriptor() ([]byte, []int) { return fileDescriptorV3Election, []int{0} } - -func (m *CampaignRequest) GetName() []byte { - if m != nil { - return m.Name - } - return nil -} - -func (m *CampaignRequest) GetLease() int64 { - if m != nil { - return m.Lease - } - return 0 -} - -func (m *CampaignRequest) GetValue() []byte { - if m != nil { - return m.Value - } - return nil -} - -type CampaignResponse struct { - Header *etcdserverpb.ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // leader describes the resources used for holding leadereship of the election. - Leader *LeaderKey `protobuf:"bytes,2,opt,name=leader" json:"leader,omitempty"` -} - -func (m *CampaignResponse) Reset() { *m = CampaignResponse{} } -func (m *CampaignResponse) String() string { return proto.CompactTextString(m) } -func (*CampaignResponse) ProtoMessage() {} -func (*CampaignResponse) Descriptor() ([]byte, []int) { return fileDescriptorV3Election, []int{1} } - -func (m *CampaignResponse) GetHeader() *etcdserverpb.ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *CampaignResponse) GetLeader() *LeaderKey { - if m != nil { - return m.Leader - } - return nil -} - -type LeaderKey struct { - // name is the election identifier that correponds to the leadership key. - Name []byte `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - // key is an opaque key representing the ownership of the election. If the key - // is deleted, then leadership is lost. - Key []byte `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` - // rev is the creation revision of the key. It can be used to test for ownership - // of an election during transactions by testing the key's creation revision - // matches rev. - Rev int64 `protobuf:"varint,3,opt,name=rev,proto3" json:"rev,omitempty"` - // lease is the lease ID of the election leader. - Lease int64 `protobuf:"varint,4,opt,name=lease,proto3" json:"lease,omitempty"` -} - -func (m *LeaderKey) Reset() { *m = LeaderKey{} } -func (m *LeaderKey) String() string { return proto.CompactTextString(m) } -func (*LeaderKey) ProtoMessage() {} -func (*LeaderKey) Descriptor() ([]byte, []int) { return fileDescriptorV3Election, []int{2} } - -func (m *LeaderKey) GetName() []byte { - if m != nil { - return m.Name - } - return nil -} - -func (m *LeaderKey) GetKey() []byte { - if m != nil { - return m.Key - } - return nil -} - -func (m *LeaderKey) GetRev() int64 { - if m != nil { - return m.Rev - } - return 0 -} - -func (m *LeaderKey) GetLease() int64 { - if m != nil { - return m.Lease - } - return 0 -} - -type LeaderRequest struct { - // name is the election identifier for the leadership information. - Name []byte `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` -} - -func (m *LeaderRequest) Reset() { *m = LeaderRequest{} } -func (m *LeaderRequest) String() string { return proto.CompactTextString(m) } -func (*LeaderRequest) ProtoMessage() {} -func (*LeaderRequest) Descriptor() ([]byte, []int) { return fileDescriptorV3Election, []int{3} } - -func (m *LeaderRequest) GetName() []byte { - if m != nil { - return m.Name - } - return nil -} - -type LeaderResponse struct { - Header *etcdserverpb.ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // kv is the key-value pair representing the latest leader update. - Kv *mvccpb.KeyValue `protobuf:"bytes,2,opt,name=kv" json:"kv,omitempty"` -} - -func (m *LeaderResponse) Reset() { *m = LeaderResponse{} } -func (m *LeaderResponse) String() string { return proto.CompactTextString(m) } -func (*LeaderResponse) ProtoMessage() {} -func (*LeaderResponse) Descriptor() ([]byte, []int) { return fileDescriptorV3Election, []int{4} } - -func (m *LeaderResponse) GetHeader() *etcdserverpb.ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *LeaderResponse) GetKv() *mvccpb.KeyValue { - if m != nil { - return m.Kv - } - return nil -} - -type ResignRequest struct { - // leader is the leadership to relinquish by resignation. - Leader *LeaderKey `protobuf:"bytes,1,opt,name=leader" json:"leader,omitempty"` -} - -func (m *ResignRequest) Reset() { *m = ResignRequest{} } -func (m *ResignRequest) String() string { return proto.CompactTextString(m) } -func (*ResignRequest) ProtoMessage() {} -func (*ResignRequest) Descriptor() ([]byte, []int) { return fileDescriptorV3Election, []int{5} } - -func (m *ResignRequest) GetLeader() *LeaderKey { - if m != nil { - return m.Leader - } - return nil -} - -type ResignResponse struct { - Header *etcdserverpb.ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *ResignResponse) Reset() { *m = ResignResponse{} } -func (m *ResignResponse) String() string { return proto.CompactTextString(m) } -func (*ResignResponse) ProtoMessage() {} -func (*ResignResponse) Descriptor() ([]byte, []int) { return fileDescriptorV3Election, []int{6} } - -func (m *ResignResponse) GetHeader() *etcdserverpb.ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type ProclaimRequest struct { - // leader is the leadership hold on the election. - Leader *LeaderKey `protobuf:"bytes,1,opt,name=leader" json:"leader,omitempty"` - // value is an update meant to overwrite the leader's current value. - Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` -} - -func (m *ProclaimRequest) Reset() { *m = ProclaimRequest{} } -func (m *ProclaimRequest) String() string { return proto.CompactTextString(m) } -func (*ProclaimRequest) ProtoMessage() {} -func (*ProclaimRequest) Descriptor() ([]byte, []int) { return fileDescriptorV3Election, []int{7} } - -func (m *ProclaimRequest) GetLeader() *LeaderKey { - if m != nil { - return m.Leader - } - return nil -} - -func (m *ProclaimRequest) GetValue() []byte { - if m != nil { - return m.Value - } - return nil -} - -type ProclaimResponse struct { - Header *etcdserverpb.ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *ProclaimResponse) Reset() { *m = ProclaimResponse{} } -func (m *ProclaimResponse) String() string { return proto.CompactTextString(m) } -func (*ProclaimResponse) ProtoMessage() {} -func (*ProclaimResponse) Descriptor() ([]byte, []int) { return fileDescriptorV3Election, []int{8} } - -func (m *ProclaimResponse) GetHeader() *etcdserverpb.ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func init() { - proto.RegisterType((*CampaignRequest)(nil), "v3electionpb.CampaignRequest") - proto.RegisterType((*CampaignResponse)(nil), "v3electionpb.CampaignResponse") - proto.RegisterType((*LeaderKey)(nil), "v3electionpb.LeaderKey") - proto.RegisterType((*LeaderRequest)(nil), "v3electionpb.LeaderRequest") - proto.RegisterType((*LeaderResponse)(nil), "v3electionpb.LeaderResponse") - proto.RegisterType((*ResignRequest)(nil), "v3electionpb.ResignRequest") - proto.RegisterType((*ResignResponse)(nil), "v3electionpb.ResignResponse") - proto.RegisterType((*ProclaimRequest)(nil), "v3electionpb.ProclaimRequest") - proto.RegisterType((*ProclaimResponse)(nil), "v3electionpb.ProclaimResponse") -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// Client API for Election service - -type ElectionClient interface { - // Campaign waits to acquire leadership in an election, returning a LeaderKey - // representing the leadership if successful. The LeaderKey can then be used - // to issue new values on the election, transactionally guard API requests on - // leadership still being held, and resign from the election. - Campaign(ctx context.Context, in *CampaignRequest, opts ...grpc.CallOption) (*CampaignResponse, error) - // Proclaim updates the leader's posted value with a new value. - Proclaim(ctx context.Context, in *ProclaimRequest, opts ...grpc.CallOption) (*ProclaimResponse, error) - // Leader returns the current election proclamation, if any. - Leader(ctx context.Context, in *LeaderRequest, opts ...grpc.CallOption) (*LeaderResponse, error) - // Observe streams election proclamations in-order as made by the election's - // elected leaders. - Observe(ctx context.Context, in *LeaderRequest, opts ...grpc.CallOption) (Election_ObserveClient, error) - // Resign releases election leadership so other campaigners may acquire - // leadership on the election. - Resign(ctx context.Context, in *ResignRequest, opts ...grpc.CallOption) (*ResignResponse, error) -} - -type electionClient struct { - cc *grpc.ClientConn -} - -func NewElectionClient(cc *grpc.ClientConn) ElectionClient { - return &electionClient{cc} -} - -func (c *electionClient) Campaign(ctx context.Context, in *CampaignRequest, opts ...grpc.CallOption) (*CampaignResponse, error) { - out := new(CampaignResponse) - err := grpc.Invoke(ctx, "/v3electionpb.Election/Campaign", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *electionClient) Proclaim(ctx context.Context, in *ProclaimRequest, opts ...grpc.CallOption) (*ProclaimResponse, error) { - out := new(ProclaimResponse) - err := grpc.Invoke(ctx, "/v3electionpb.Election/Proclaim", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *electionClient) Leader(ctx context.Context, in *LeaderRequest, opts ...grpc.CallOption) (*LeaderResponse, error) { - out := new(LeaderResponse) - err := grpc.Invoke(ctx, "/v3electionpb.Election/Leader", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *electionClient) Observe(ctx context.Context, in *LeaderRequest, opts ...grpc.CallOption) (Election_ObserveClient, error) { - stream, err := grpc.NewClientStream(ctx, &_Election_serviceDesc.Streams[0], c.cc, "/v3electionpb.Election/Observe", opts...) - if err != nil { - return nil, err - } - x := &electionObserveClient{stream} - if err := x.ClientStream.SendMsg(in); err != nil { - return nil, err - } - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - return x, nil -} - -type Election_ObserveClient interface { - Recv() (*LeaderResponse, error) - grpc.ClientStream -} - -type electionObserveClient struct { - grpc.ClientStream -} - -func (x *electionObserveClient) Recv() (*LeaderResponse, error) { - m := new(LeaderResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *electionClient) Resign(ctx context.Context, in *ResignRequest, opts ...grpc.CallOption) (*ResignResponse, error) { - out := new(ResignResponse) - err := grpc.Invoke(ctx, "/v3electionpb.Election/Resign", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for Election service - -type ElectionServer interface { - // Campaign waits to acquire leadership in an election, returning a LeaderKey - // representing the leadership if successful. The LeaderKey can then be used - // to issue new values on the election, transactionally guard API requests on - // leadership still being held, and resign from the election. - Campaign(context.Context, *CampaignRequest) (*CampaignResponse, error) - // Proclaim updates the leader's posted value with a new value. - Proclaim(context.Context, *ProclaimRequest) (*ProclaimResponse, error) - // Leader returns the current election proclamation, if any. - Leader(context.Context, *LeaderRequest) (*LeaderResponse, error) - // Observe streams election proclamations in-order as made by the election's - // elected leaders. - Observe(*LeaderRequest, Election_ObserveServer) error - // Resign releases election leadership so other campaigners may acquire - // leadership on the election. - Resign(context.Context, *ResignRequest) (*ResignResponse, error) -} - -func RegisterElectionServer(s *grpc.Server, srv ElectionServer) { - s.RegisterService(&_Election_serviceDesc, srv) -} - -func _Election_Campaign_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(CampaignRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ElectionServer).Campaign(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/v3electionpb.Election/Campaign", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ElectionServer).Campaign(ctx, req.(*CampaignRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Election_Proclaim_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ProclaimRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ElectionServer).Proclaim(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/v3electionpb.Election/Proclaim", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ElectionServer).Proclaim(ctx, req.(*ProclaimRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Election_Leader_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(LeaderRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ElectionServer).Leader(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/v3electionpb.Election/Leader", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ElectionServer).Leader(ctx, req.(*LeaderRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Election_Observe_Handler(srv interface{}, stream grpc.ServerStream) error { - m := new(LeaderRequest) - if err := stream.RecvMsg(m); err != nil { - return err - } - return srv.(ElectionServer).Observe(m, &electionObserveServer{stream}) -} - -type Election_ObserveServer interface { - Send(*LeaderResponse) error - grpc.ServerStream -} - -type electionObserveServer struct { - grpc.ServerStream -} - -func (x *electionObserveServer) Send(m *LeaderResponse) error { - return x.ServerStream.SendMsg(m) -} - -func _Election_Resign_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ResignRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ElectionServer).Resign(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/v3electionpb.Election/Resign", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ElectionServer).Resign(ctx, req.(*ResignRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Election_serviceDesc = grpc.ServiceDesc{ - ServiceName: "v3electionpb.Election", - HandlerType: (*ElectionServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Campaign", - Handler: _Election_Campaign_Handler, - }, - { - MethodName: "Proclaim", - Handler: _Election_Proclaim_Handler, - }, - { - MethodName: "Leader", - Handler: _Election_Leader_Handler, - }, - { - MethodName: "Resign", - Handler: _Election_Resign_Handler, - }, - }, - Streams: []grpc.StreamDesc{ - { - StreamName: "Observe", - Handler: _Election_Observe_Handler, - ServerStreams: true, - }, - }, - Metadata: "v3election.proto", -} - -func (m *CampaignRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *CampaignRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Election(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if m.Lease != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Lease)) - } - if len(m.Value) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintV3Election(dAtA, i, uint64(len(m.Value))) - i += copy(dAtA[i:], m.Value) - } - return i, nil -} - -func (m *CampaignResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *CampaignResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Header.Size())) - n1, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - } - if m.Leader != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Leader.Size())) - n2, err := m.Leader.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - } - return i, nil -} - -func (m *LeaderKey) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaderKey) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Election(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.Key) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintV3Election(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - if m.Rev != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Rev)) - } - if m.Lease != 0 { - dAtA[i] = 0x20 - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Lease)) - } - return i, nil -} - -func (m *LeaderRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaderRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Election(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - return i, nil -} - -func (m *LeaderResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaderResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Header.Size())) - n3, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n3 - } - if m.Kv != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Kv.Size())) - n4, err := m.Kv.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n4 - } - return i, nil -} - -func (m *ResignRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ResignRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Leader != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Leader.Size())) - n5, err := m.Leader.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n5 - } - return i, nil -} - -func (m *ResignResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ResignResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Header.Size())) - n6, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n6 - } - return i, nil -} - -func (m *ProclaimRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ProclaimRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Leader != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Leader.Size())) - n7, err := m.Leader.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n7 - } - if len(m.Value) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintV3Election(dAtA, i, uint64(len(m.Value))) - i += copy(dAtA[i:], m.Value) - } - return i, nil -} - -func (m *ProclaimResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ProclaimResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Election(dAtA, i, uint64(m.Header.Size())) - n8, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n8 - } - return i, nil -} - -func encodeVarintV3Election(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *CampaignRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovV3Election(uint64(l)) - } - if m.Lease != 0 { - n += 1 + sovV3Election(uint64(m.Lease)) - } - l = len(m.Value) - if l > 0 { - n += 1 + l + sovV3Election(uint64(l)) - } - return n -} - -func (m *CampaignResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - if m.Leader != nil { - l = m.Leader.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - return n -} - -func (m *LeaderKey) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovV3Election(uint64(l)) - } - l = len(m.Key) - if l > 0 { - n += 1 + l + sovV3Election(uint64(l)) - } - if m.Rev != 0 { - n += 1 + sovV3Election(uint64(m.Rev)) - } - if m.Lease != 0 { - n += 1 + sovV3Election(uint64(m.Lease)) - } - return n -} - -func (m *LeaderRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovV3Election(uint64(l)) - } - return n -} - -func (m *LeaderResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - if m.Kv != nil { - l = m.Kv.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - return n -} - -func (m *ResignRequest) Size() (n int) { - var l int - _ = l - if m.Leader != nil { - l = m.Leader.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - return n -} - -func (m *ResignResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - return n -} - -func (m *ProclaimRequest) Size() (n int) { - var l int - _ = l - if m.Leader != nil { - l = m.Leader.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - l = len(m.Value) - if l > 0 { - n += 1 + l + sovV3Election(uint64(l)) - } - return n -} - -func (m *ProclaimResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - return n -} - -func sovV3Election(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozV3Election(x uint64) (n int) { - return sovV3Election(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *CampaignRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: CampaignRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: CampaignRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = append(m.Name[:0], dAtA[iNdEx:postIndex]...) - if m.Name == nil { - m.Name = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Lease", wireType) - } - m.Lease = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Lease |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...) - if m.Value == nil { - m.Value = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *CampaignResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: CampaignResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: CampaignResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &etcdserverpb.ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Leader", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Leader == nil { - m.Leader = &LeaderKey{} - } - if err := m.Leader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaderKey) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaderKey: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaderKey: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = append(m.Name[:0], dAtA[iNdEx:postIndex]...) - if m.Name == nil { - m.Name = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Rev", wireType) - } - m.Rev = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Rev |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Lease", wireType) - } - m.Lease = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Lease |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaderRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaderRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaderRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = append(m.Name[:0], dAtA[iNdEx:postIndex]...) - if m.Name == nil { - m.Name = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaderResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaderResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaderResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &etcdserverpb.ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Kv", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Kv == nil { - m.Kv = &mvccpb.KeyValue{} - } - if err := m.Kv.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ResignRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ResignRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ResignRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Leader", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Leader == nil { - m.Leader = &LeaderKey{} - } - if err := m.Leader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ResignResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ResignResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ResignResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &etcdserverpb.ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ProclaimRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ProclaimRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ProclaimRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Leader", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Leader == nil { - m.Leader = &LeaderKey{} - } - if err := m.Leader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...) - if m.Value == nil { - m.Value = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ProclaimResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ProclaimResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ProclaimResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &etcdserverpb.ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipV3Election(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Election - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Election - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Election - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthV3Election - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Election - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipV3Election(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthV3Election = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowV3Election = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("v3election.proto", fileDescriptorV3Election) } - -var fileDescriptorV3Election = []byte{ - // 538 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0x65, 0x9d, 0x10, 0xca, 0x90, 0xb6, 0x96, 0x55, 0xa9, 0x69, 0x48, 0xad, 0x68, 0x8b, 0x50, - 0x95, 0x83, 0x17, 0x35, 0x9c, 0x72, 0x42, 0x20, 0x50, 0xa5, 0x22, 0x01, 0x3e, 0x20, 0x38, 0xae, - 0xdd, 0x91, 0x1b, 0xc5, 0xf1, 0x1a, 0xdb, 0xb5, 0x94, 0x2b, 0xbf, 0xc0, 0x85, 0x7f, 0xe0, 0x47, - 0x38, 0x22, 0xf1, 0x03, 0x28, 0xf0, 0x21, 0x68, 0x77, 0x6d, 0xec, 0xb8, 0x21, 0x42, 0xe4, 0x62, - 0x8d, 0x67, 0x9e, 0xe7, 0xcd, 0x7b, 0x3b, 0x6b, 0x30, 0xf3, 0x31, 0x86, 0xe8, 0x67, 0x53, 0x11, - 0x39, 0x71, 0x22, 0x32, 0x61, 0x75, 0xab, 0x4c, 0xec, 0xf5, 0x0f, 0x02, 0x11, 0x08, 0x55, 0x60, - 0x32, 0xd2, 0x98, 0xfe, 0x43, 0xcc, 0xfc, 0x4b, 0x26, 0x1f, 0x29, 0x26, 0x39, 0x26, 0xb5, 0x30, - 0xf6, 0x58, 0x12, 0xfb, 0x05, 0xee, 0x48, 0xe1, 0xe6, 0xb9, 0xef, 0xab, 0x47, 0xec, 0xb1, 0x59, - 0x5e, 0x94, 0x06, 0x81, 0x10, 0x41, 0x88, 0x8c, 0xc7, 0x53, 0xc6, 0xa3, 0x48, 0x64, 0x5c, 0x32, - 0xa6, 0xba, 0x4a, 0xdf, 0xc0, 0xfe, 0x33, 0x3e, 0x8f, 0xf9, 0x34, 0x88, 0x5c, 0xfc, 0x70, 0x8d, - 0x69, 0x66, 0x59, 0xd0, 0x8e, 0xf8, 0x1c, 0x7b, 0x64, 0x48, 0x4e, 0xbb, 0xae, 0x8a, 0xad, 0x03, - 0xb8, 0x1d, 0x22, 0x4f, 0xb1, 0x67, 0x0c, 0xc9, 0x69, 0xcb, 0xd5, 0x2f, 0x32, 0x9b, 0xf3, 0xf0, - 0x1a, 0x7b, 0x2d, 0x05, 0xd5, 0x2f, 0x74, 0x01, 0x66, 0xd5, 0x32, 0x8d, 0x45, 0x94, 0xa2, 0xf5, - 0x18, 0x3a, 0x57, 0xc8, 0x2f, 0x31, 0x51, 0x5d, 0xef, 0x9d, 0x0d, 0x9c, 0xba, 0x10, 0xa7, 0xc4, - 0x9d, 0x2b, 0x8c, 0x5b, 0x60, 0x2d, 0x06, 0x9d, 0x50, 0x7f, 0x65, 0xa8, 0xaf, 0x0e, 0x9d, 0xba, - 0x65, 0xce, 0x4b, 0x55, 0xbb, 0xc0, 0x85, 0x5b, 0xc0, 0xe8, 0x7b, 0xb8, 0xfb, 0x27, 0xb9, 0x56, - 0x87, 0x09, 0xad, 0x19, 0x2e, 0x54, 0xbb, 0xae, 0x2b, 0x43, 0x99, 0x49, 0x30, 0x57, 0x0a, 0x5a, - 0xae, 0x0c, 0x2b, 0xad, 0xed, 0x9a, 0x56, 0x7a, 0x02, 0xbb, 0xba, 0xf5, 0x06, 0x9b, 0xe8, 0x15, - 0xec, 0x95, 0xa0, 0xad, 0x84, 0x0f, 0xc1, 0x98, 0xe5, 0x85, 0x68, 0xd3, 0xd1, 0x27, 0xea, 0x5c, - 0xe0, 0xe2, 0xad, 0x34, 0xd8, 0x35, 0x66, 0x39, 0x7d, 0x02, 0xbb, 0x2e, 0xa6, 0xb5, 0x53, 0xab, - 0xbc, 0x22, 0xff, 0xe6, 0xd5, 0x0b, 0xd8, 0x2b, 0x3b, 0x6c, 0x33, 0x2b, 0x7d, 0x07, 0xfb, 0xaf, - 0x13, 0xe1, 0x87, 0x7c, 0x3a, 0xff, 0xdf, 0x59, 0xaa, 0x45, 0x32, 0xea, 0x8b, 0x74, 0x0e, 0x66, - 0xd5, 0x79, 0x9b, 0x19, 0xcf, 0xbe, 0xb4, 0x61, 0xe7, 0x79, 0x31, 0x80, 0x25, 0x60, 0xa7, 0xdc, - 0x4f, 0xeb, 0x78, 0x75, 0xb2, 0xc6, 0x55, 0xe8, 0xdb, 0x7f, 0x2b, 0x6b, 0x16, 0xfa, 0xe0, 0xe3, - 0xf7, 0x5f, 0x9f, 0x0c, 0x9b, 0x1e, 0xb1, 0x7c, 0xec, 0x61, 0xc6, 0x59, 0x09, 0x66, 0x7e, 0x01, - 0x9d, 0x90, 0x91, 0x24, 0x2c, 0x75, 0x34, 0x09, 0x1b, 0xce, 0x35, 0x09, 0x9b, 0xf2, 0x37, 0x10, - 0xc6, 0x05, 0x54, 0x12, 0x06, 0xd0, 0xd1, 0x1e, 0x5b, 0xf7, 0xd7, 0x39, 0x5f, 0x92, 0x0d, 0xd6, - 0x17, 0x0b, 0x2a, 0xaa, 0xa8, 0x06, 0xf4, 0xf0, 0x06, 0x95, 0x3e, 0x34, 0x49, 0x34, 0x83, 0x3b, - 0xaf, 0x3c, 0x65, 0xfe, 0x36, 0x4c, 0x27, 0x8a, 0xe9, 0x98, 0xf6, 0x6e, 0x30, 0x09, 0xdd, 0x7c, - 0x42, 0x46, 0x8f, 0x88, 0x54, 0xa5, 0x17, 0xb6, 0xc9, 0xb5, 0x72, 0x11, 0x9a, 0x5c, 0xab, 0x3b, - 0xbe, 0x41, 0x55, 0xa2, 0x80, 0x13, 0x32, 0x7a, 0x6a, 0x7e, 0x5d, 0xda, 0xe4, 0xdb, 0xd2, 0x26, - 0x3f, 0x96, 0x36, 0xf9, 0xfc, 0xd3, 0xbe, 0xe5, 0x75, 0xd4, 0xcf, 0x72, 0xfc, 0x3b, 0x00, 0x00, - 0xff, 0xff, 0xdc, 0xa9, 0x0e, 0xdf, 0xc5, 0x05, 0x00, 0x00, -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3lock/doc.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3lock/doc.go deleted file mode 100644 index e0a1008abc9e..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3lock/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v3lock provides a v3 locking service from an etcdserver. -package v3lock diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3lock/lock.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3lock/lock.go deleted file mode 100644 index a5efcbab5b56..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3lock/lock.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3lock - -import ( - "context" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/concurrency" - "github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb" -) - -type lockServer struct { - c *clientv3.Client -} - -func NewLockServer(c *clientv3.Client) v3lockpb.LockServer { - return &lockServer{c} -} - -func (ls *lockServer) Lock(ctx context.Context, req *v3lockpb.LockRequest) (*v3lockpb.LockResponse, error) { - s, err := concurrency.NewSession( - ls.c, - concurrency.WithLease(clientv3.LeaseID(req.Lease)), - concurrency.WithContext(ctx), - ) - if err != nil { - return nil, err - } - s.Orphan() - m := concurrency.NewMutex(s, string(req.Name)) - if err = m.Lock(ctx); err != nil { - return nil, err - } - return &v3lockpb.LockResponse{Header: m.Header(), Key: []byte(m.Key())}, nil -} - -func (ls *lockServer) Unlock(ctx context.Context, req *v3lockpb.UnlockRequest) (*v3lockpb.UnlockResponse, error) { - resp, err := ls.c.Delete(ctx, string(req.Key)) - if err != nil { - return nil, err - } - return &v3lockpb.UnlockResponse{Header: resp.Header}, nil -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3lock/v3lockpb/gw/v3lock.pb.gw.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3lock/v3lockpb/gw/v3lock.pb.gw.go deleted file mode 100644 index efecc45dba36..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3lock/v3lockpb/gw/v3lock.pb.gw.go +++ /dev/null @@ -1,167 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: etcdserver/api/v3lock/v3lockpb/v3lock.proto - -/* -Package v3lockpb is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package gw - -import ( - "github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb" - "io" - "net/http" - - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "golang.org/x/net/context" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/status" -) - -var _ codes.Code -var _ io.Reader -var _ status.Status -var _ = runtime.String -var _ = utilities.NewDoubleArray - -func request_Lock_Lock_0(ctx context.Context, marshaler runtime.Marshaler, client v3lockpb.LockClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3lockpb.LockRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Lock(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Lock_Unlock_0(ctx context.Context, marshaler runtime.Marshaler, client v3lockpb.LockClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3lockpb.UnlockRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Unlock(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -// RegisterLockHandlerFromEndpoint is same as RegisterLockHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterLockHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterLockHandler(ctx, mux, conn) -} - -// RegisterLockHandler registers the http handlers for service Lock to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterLockHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterLockHandlerClient(ctx, mux, v3lockpb.NewLockClient(conn)) -} - -// RegisterLockHandler registers the http handlers for service Lock to "mux". -// The handlers forward requests to the grpc endpoint over the given implementation of "LockClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "LockClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "LockClient" to call the correct interceptors. -func RegisterLockHandlerClient(ctx context.Context, mux *runtime.ServeMux, client v3lockpb.LockClient) error { - - mux.Handle("POST", pattern_Lock_Lock_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lock_Lock_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lock_Lock_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lock_Unlock_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lock_Unlock_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lock_Unlock_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Lock_Lock_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 1}, []string{"v3beta", "lock"}, "")) - - pattern_Lock_Unlock_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "lock", "unlock"}, "")) -) - -var ( - forward_Lock_Lock_0 = runtime.ForwardResponseMessage - - forward_Lock_Unlock_0 = runtime.ForwardResponseMessage -) diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3lock/v3lockpb/v3lock.pb.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3lock/v3lockpb/v3lock.pb.go deleted file mode 100644 index 071d0ae242b2..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3lock/v3lockpb/v3lock.pb.go +++ /dev/null @@ -1,959 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: v3lock.proto - -/* - Package v3lockpb is a generated protocol buffer package. - - It is generated from these files: - v3lock.proto - - It has these top-level messages: - LockRequest - LockResponse - UnlockRequest - UnlockResponse -*/ -package v3lockpb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - etcdserverpb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - context "golang.org/x/net/context" - - grpc "google.golang.org/grpc" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type LockRequest struct { - // name is the identifier for the distributed shared lock to be acquired. - Name []byte `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - // lease is the ID of the lease that will be attached to ownership of the - // lock. If the lease expires or is revoked and currently holds the lock, - // the lock is automatically released. Calls to Lock with the same lease will - // be treated as a single acquistion; locking twice with the same lease is a - // no-op. - Lease int64 `protobuf:"varint,2,opt,name=lease,proto3" json:"lease,omitempty"` -} - -func (m *LockRequest) Reset() { *m = LockRequest{} } -func (m *LockRequest) String() string { return proto.CompactTextString(m) } -func (*LockRequest) ProtoMessage() {} -func (*LockRequest) Descriptor() ([]byte, []int) { return fileDescriptorV3Lock, []int{0} } - -func (m *LockRequest) GetName() []byte { - if m != nil { - return m.Name - } - return nil -} - -func (m *LockRequest) GetLease() int64 { - if m != nil { - return m.Lease - } - return 0 -} - -type LockResponse struct { - Header *etcdserverpb.ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // key is a key that will exist on etcd for the duration that the Lock caller - // owns the lock. Users should not modify this key or the lock may exhibit - // undefined behavior. - Key []byte `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` -} - -func (m *LockResponse) Reset() { *m = LockResponse{} } -func (m *LockResponse) String() string { return proto.CompactTextString(m) } -func (*LockResponse) ProtoMessage() {} -func (*LockResponse) Descriptor() ([]byte, []int) { return fileDescriptorV3Lock, []int{1} } - -func (m *LockResponse) GetHeader() *etcdserverpb.ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *LockResponse) GetKey() []byte { - if m != nil { - return m.Key - } - return nil -} - -type UnlockRequest struct { - // key is the lock ownership key granted by Lock. - Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` -} - -func (m *UnlockRequest) Reset() { *m = UnlockRequest{} } -func (m *UnlockRequest) String() string { return proto.CompactTextString(m) } -func (*UnlockRequest) ProtoMessage() {} -func (*UnlockRequest) Descriptor() ([]byte, []int) { return fileDescriptorV3Lock, []int{2} } - -func (m *UnlockRequest) GetKey() []byte { - if m != nil { - return m.Key - } - return nil -} - -type UnlockResponse struct { - Header *etcdserverpb.ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *UnlockResponse) Reset() { *m = UnlockResponse{} } -func (m *UnlockResponse) String() string { return proto.CompactTextString(m) } -func (*UnlockResponse) ProtoMessage() {} -func (*UnlockResponse) Descriptor() ([]byte, []int) { return fileDescriptorV3Lock, []int{3} } - -func (m *UnlockResponse) GetHeader() *etcdserverpb.ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func init() { - proto.RegisterType((*LockRequest)(nil), "v3lockpb.LockRequest") - proto.RegisterType((*LockResponse)(nil), "v3lockpb.LockResponse") - proto.RegisterType((*UnlockRequest)(nil), "v3lockpb.UnlockRequest") - proto.RegisterType((*UnlockResponse)(nil), "v3lockpb.UnlockResponse") -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// Client API for Lock service - -type LockClient interface { - // Lock acquires a distributed shared lock on a given named lock. - // On success, it will return a unique key that exists so long as the - // lock is held by the caller. This key can be used in conjunction with - // transactions to safely ensure updates to etcd only occur while holding - // lock ownership. The lock is held until Unlock is called on the key or the - // lease associate with the owner expires. - Lock(ctx context.Context, in *LockRequest, opts ...grpc.CallOption) (*LockResponse, error) - // Unlock takes a key returned by Lock and releases the hold on lock. The - // next Lock caller waiting for the lock will then be woken up and given - // ownership of the lock. - Unlock(ctx context.Context, in *UnlockRequest, opts ...grpc.CallOption) (*UnlockResponse, error) -} - -type lockClient struct { - cc *grpc.ClientConn -} - -func NewLockClient(cc *grpc.ClientConn) LockClient { - return &lockClient{cc} -} - -func (c *lockClient) Lock(ctx context.Context, in *LockRequest, opts ...grpc.CallOption) (*LockResponse, error) { - out := new(LockResponse) - err := grpc.Invoke(ctx, "/v3lockpb.Lock/Lock", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *lockClient) Unlock(ctx context.Context, in *UnlockRequest, opts ...grpc.CallOption) (*UnlockResponse, error) { - out := new(UnlockResponse) - err := grpc.Invoke(ctx, "/v3lockpb.Lock/Unlock", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for Lock service - -type LockServer interface { - // Lock acquires a distributed shared lock on a given named lock. - // On success, it will return a unique key that exists so long as the - // lock is held by the caller. This key can be used in conjunction with - // transactions to safely ensure updates to etcd only occur while holding - // lock ownership. The lock is held until Unlock is called on the key or the - // lease associate with the owner expires. - Lock(context.Context, *LockRequest) (*LockResponse, error) - // Unlock takes a key returned by Lock and releases the hold on lock. The - // next Lock caller waiting for the lock will then be woken up and given - // ownership of the lock. - Unlock(context.Context, *UnlockRequest) (*UnlockResponse, error) -} - -func RegisterLockServer(s *grpc.Server, srv LockServer) { - s.RegisterService(&_Lock_serviceDesc, srv) -} - -func _Lock_Lock_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(LockRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(LockServer).Lock(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/v3lockpb.Lock/Lock", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(LockServer).Lock(ctx, req.(*LockRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Lock_Unlock_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(UnlockRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(LockServer).Unlock(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/v3lockpb.Lock/Unlock", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(LockServer).Unlock(ctx, req.(*UnlockRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Lock_serviceDesc = grpc.ServiceDesc{ - ServiceName: "v3lockpb.Lock", - HandlerType: (*LockServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Lock", - Handler: _Lock_Lock_Handler, - }, - { - MethodName: "Unlock", - Handler: _Lock_Unlock_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "v3lock.proto", -} - -func (m *LockRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LockRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Lock(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if m.Lease != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintV3Lock(dAtA, i, uint64(m.Lease)) - } - return i, nil -} - -func (m *LockResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LockResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Lock(dAtA, i, uint64(m.Header.Size())) - n1, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - } - if len(m.Key) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintV3Lock(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - return i, nil -} - -func (m *UnlockRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *UnlockRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Key) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Lock(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - return i, nil -} - -func (m *UnlockResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *UnlockResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintV3Lock(dAtA, i, uint64(m.Header.Size())) - n2, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - } - return i, nil -} - -func encodeVarintV3Lock(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *LockRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovV3Lock(uint64(l)) - } - if m.Lease != 0 { - n += 1 + sovV3Lock(uint64(m.Lease)) - } - return n -} - -func (m *LockResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovV3Lock(uint64(l)) - } - l = len(m.Key) - if l > 0 { - n += 1 + l + sovV3Lock(uint64(l)) - } - return n -} - -func (m *UnlockRequest) Size() (n int) { - var l int - _ = l - l = len(m.Key) - if l > 0 { - n += 1 + l + sovV3Lock(uint64(l)) - } - return n -} - -func (m *UnlockResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovV3Lock(uint64(l)) - } - return n -} - -func sovV3Lock(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozV3Lock(x uint64) (n int) { - return sovV3Lock(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *LockRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LockRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LockRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Lock - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = append(m.Name[:0], dAtA[iNdEx:postIndex]...) - if m.Name == nil { - m.Name = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Lease", wireType) - } - m.Lease = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Lease |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipV3Lock(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Lock - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LockResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LockResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LockResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Lock - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &etcdserverpb.ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Lock - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Lock(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Lock - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *UnlockRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: UnlockRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: UnlockRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Lock - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Lock(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Lock - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *UnlockResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: UnlockResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: UnlockResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Lock - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &etcdserverpb.ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Lock(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthV3Lock - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipV3Lock(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Lock - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Lock - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Lock - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthV3Lock - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Lock - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipV3Lock(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthV3Lock = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowV3Lock = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("v3lock.proto", fileDescriptorV3Lock) } - -var fileDescriptorV3Lock = []byte{ - // 335 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x29, 0x33, 0xce, 0xc9, - 0x4f, 0xce, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x80, 0xf0, 0x0a, 0x92, 0xa4, 0x44, - 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x82, 0xfa, 0x20, 0x16, 0x44, 0x5e, 0x4a, 0x2d, 0xb5, 0x24, 0x39, - 0x45, 0x1f, 0x44, 0x14, 0xa7, 0x16, 0x95, 0xa5, 0x16, 0x21, 0x31, 0x0b, 0x92, 0xf4, 0x8b, 0x0a, - 0x92, 0xa1, 0xea, 0x64, 0xd2, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0x13, 0x0b, 0x32, 0xf5, 0x13, - 0xf3, 0xf2, 0xf2, 0x4b, 0x12, 0x4b, 0x32, 0xf3, 0xf3, 0x8a, 0x21, 0xb2, 0x4a, 0xe6, 0x5c, 0xdc, - 0x3e, 0xf9, 0xc9, 0xd9, 0x41, 0xa9, 0x85, 0xa5, 0xa9, 0xc5, 0x25, 0x42, 0x42, 0x5c, 0x2c, 0x79, - 0x89, 0xb9, 0xa9, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x3c, 0x41, 0x60, 0xb6, 0x90, 0x08, 0x17, 0x6b, - 0x4e, 0x6a, 0x62, 0x71, 0xaa, 0x04, 0x93, 0x02, 0xa3, 0x06, 0x73, 0x10, 0x84, 0xa3, 0x14, 0xc6, - 0xc5, 0x03, 0xd1, 0x58, 0x5c, 0x90, 0x9f, 0x57, 0x9c, 0x2a, 0x64, 0xc2, 0xc5, 0x96, 0x91, 0x9a, - 0x98, 0x92, 0x5a, 0x04, 0xd6, 0xcb, 0x6d, 0x24, 0xa3, 0x87, 0xec, 0x1e, 0x3d, 0x98, 0x3a, 0x0f, - 0xb0, 0x9a, 0x20, 0xa8, 0x5a, 0x21, 0x01, 0x2e, 0xe6, 0xec, 0xd4, 0x4a, 0xb0, 0xc9, 0x3c, 0x41, - 0x20, 0xa6, 0x92, 0x22, 0x17, 0x6f, 0x68, 0x5e, 0x0e, 0x92, 0x93, 0xa0, 0x4a, 0x18, 0x11, 0x4a, - 0xdc, 0xb8, 0xf8, 0x60, 0x4a, 0x28, 0xb1, 0xdc, 0x68, 0x07, 0x23, 0x17, 0x0b, 0xc8, 0x0f, 0x42, - 0xc1, 0x50, 0x5a, 0x54, 0x0f, 0x16, 0xe6, 0x7a, 0x48, 0x81, 0x22, 0x25, 0x86, 0x2e, 0x0c, 0x31, - 0x4d, 0x49, 0xa6, 0xe9, 0xf2, 0x93, 0xc9, 0x4c, 0x62, 0x4a, 0x82, 0xfa, 0x65, 0xc6, 0x49, 0xa9, - 0x25, 0x89, 0xfa, 0x20, 0x45, 0x60, 0xc2, 0x8a, 0x51, 0x4b, 0x28, 0x9a, 0x8b, 0x0d, 0xe2, 0x4a, - 0x21, 0x71, 0x84, 0x7e, 0x14, 0xaf, 0x49, 0x49, 0x60, 0x4a, 0x40, 0x8d, 0x96, 0x03, 0x1b, 0x2d, - 0xa1, 0x24, 0x8c, 0x62, 0x74, 0x69, 0x1e, 0xd4, 0x70, 0x27, 0x81, 0x13, 0x8f, 0xe4, 0x18, 0x2f, - 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc6, 0x63, 0x39, 0x86, 0x24, 0x36, 0x70, 0x7c, - 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x10, 0x82, 0x89, 0xf0, 0x45, 0x02, 0x00, 0x00, -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/auth.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/auth.go deleted file mode 100644 index ca8e53ad0498..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/auth.go +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - - "github.com/coreos/etcd/etcdserver" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -type AuthServer struct { - authenticator etcdserver.Authenticator -} - -func NewAuthServer(s *etcdserver.EtcdServer) *AuthServer { - return &AuthServer{authenticator: s} -} - -func (as *AuthServer) AuthEnable(ctx context.Context, r *pb.AuthEnableRequest) (*pb.AuthEnableResponse, error) { - resp, err := as.authenticator.AuthEnable(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) AuthDisable(ctx context.Context, r *pb.AuthDisableRequest) (*pb.AuthDisableResponse, error) { - resp, err := as.authenticator.AuthDisable(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) Authenticate(ctx context.Context, r *pb.AuthenticateRequest) (*pb.AuthenticateResponse, error) { - resp, err := as.authenticator.Authenticate(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) RoleAdd(ctx context.Context, r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) { - resp, err := as.authenticator.RoleAdd(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) RoleDelete(ctx context.Context, r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) { - resp, err := as.authenticator.RoleDelete(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) RoleGet(ctx context.Context, r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) { - resp, err := as.authenticator.RoleGet(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) RoleList(ctx context.Context, r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) { - resp, err := as.authenticator.RoleList(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) RoleRevokePermission(ctx context.Context, r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) { - resp, err := as.authenticator.RoleRevokePermission(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) RoleGrantPermission(ctx context.Context, r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) { - resp, err := as.authenticator.RoleGrantPermission(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserAdd(ctx context.Context, r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) { - resp, err := as.authenticator.UserAdd(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserDelete(ctx context.Context, r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) { - resp, err := as.authenticator.UserDelete(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserGet(ctx context.Context, r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) { - resp, err := as.authenticator.UserGet(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserList(ctx context.Context, r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) { - resp, err := as.authenticator.UserList(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserGrantRole(ctx context.Context, r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) { - resp, err := as.authenticator.UserGrantRole(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserRevokeRole(ctx context.Context, r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) { - resp, err := as.authenticator.UserRevokeRole(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserChangePassword(ctx context.Context, r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) { - resp, err := as.authenticator.UserChangePassword(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/codec.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/codec.go deleted file mode 100644 index 17a2c87ae61d..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/codec.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import "github.com/gogo/protobuf/proto" - -type codec struct{} - -func (c *codec) Marshal(v interface{}) ([]byte, error) { - b, err := proto.Marshal(v.(proto.Message)) - sentBytes.Add(float64(len(b))) - return b, err -} - -func (c *codec) Unmarshal(data []byte, v interface{}) error { - receivedBytes.Add(float64(len(data))) - return proto.Unmarshal(data, v.(proto.Message)) -} - -func (c *codec) String() string { - return "proto" -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/grpc.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/grpc.go deleted file mode 100644 index c97e7466215a..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/grpc.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "crypto/tls" - "math" - - "github.com/coreos/etcd/etcdserver" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "github.com/grpc-ecosystem/go-grpc-middleware" - "github.com/grpc-ecosystem/go-grpc-prometheus" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials" - "google.golang.org/grpc/health" - healthpb "google.golang.org/grpc/health/grpc_health_v1" -) - -const ( - grpcOverheadBytes = 512 * 1024 - maxStreams = math.MaxUint32 - maxSendBytes = math.MaxInt32 -) - -func Server(s *etcdserver.EtcdServer, tls *tls.Config, gopts ...grpc.ServerOption) *grpc.Server { - var opts []grpc.ServerOption - opts = append(opts, grpc.CustomCodec(&codec{})) - if tls != nil { - opts = append(opts, grpc.Creds(credentials.NewTLS(tls))) - } - opts = append(opts, grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer( - newLogUnaryInterceptor(s), - newUnaryInterceptor(s), - grpc_prometheus.UnaryServerInterceptor, - ))) - opts = append(opts, grpc.StreamInterceptor(grpc_middleware.ChainStreamServer( - newStreamInterceptor(s), - grpc_prometheus.StreamServerInterceptor, - ))) - opts = append(opts, grpc.MaxRecvMsgSize(int(s.Cfg.MaxRequestBytes+grpcOverheadBytes))) - opts = append(opts, grpc.MaxSendMsgSize(maxSendBytes)) - opts = append(opts, grpc.MaxConcurrentStreams(maxStreams)) - grpcServer := grpc.NewServer(append(opts, gopts...)...) - - pb.RegisterKVServer(grpcServer, NewQuotaKVServer(s)) - pb.RegisterWatchServer(grpcServer, NewWatchServer(s)) - pb.RegisterLeaseServer(grpcServer, NewQuotaLeaseServer(s)) - pb.RegisterClusterServer(grpcServer, NewClusterServer(s)) - pb.RegisterAuthServer(grpcServer, NewAuthServer(s)) - pb.RegisterMaintenanceServer(grpcServer, NewMaintenanceServer(s)) - - // server should register all the services manually - // use empty service name for all etcd services' health status, - // see https://github.com/grpc/grpc/blob/master/doc/health-checking.md for more - hsrv := health.NewServer() - hsrv.SetServingStatus("", healthpb.HealthCheckResponse_SERVING) - healthpb.RegisterHealthServer(grpcServer, hsrv) - - // set zero values for metrics registered for this grpc server - grpc_prometheus.Register(grpcServer) - - return grpcServer -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/header.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/header.go deleted file mode 100644 index 75da52fb8d16..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/header.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "github.com/coreos/etcd/etcdserver" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -type header struct { - clusterID int64 - memberID int64 - raftTimer etcdserver.RaftTimer - rev func() int64 -} - -func newHeader(s *etcdserver.EtcdServer) header { - return header{ - clusterID: int64(s.Cluster().ID()), - memberID: int64(s.ID()), - raftTimer: s, - rev: func() int64 { return s.KV().Rev() }, - } -} - -// fill populates pb.ResponseHeader using etcdserver information -func (h *header) fill(rh *pb.ResponseHeader) { - if rh == nil { - plog.Panic("unexpected nil resp.Header") - } - rh.ClusterId = uint64(h.clusterID) - rh.MemberId = uint64(h.memberID) - rh.RaftTerm = h.raftTimer.Term() - if rh.Revision == 0 { - rh.Revision = h.rev() - } -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/interceptor.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/interceptor.go deleted file mode 100644 index d594ae7f154c..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/interceptor.go +++ /dev/null @@ -1,263 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - "sync" - "time" - - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "go.uber.org/zap" - "google.golang.org/grpc" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/peer" -) - -const ( - maxNoLeaderCnt = 3 -) - -type streamsMap struct { - mu sync.Mutex - streams map[grpc.ServerStream]struct{} -} - -func newUnaryInterceptor(s *etcdserver.EtcdServer) grpc.UnaryServerInterceptor { - return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - if !api.IsCapabilityEnabled(api.V3rpcCapability) { - return nil, rpctypes.ErrGRPCNotCapable - } - - md, ok := metadata.FromIncomingContext(ctx) - if ok { - if ks := md[rpctypes.MetadataRequireLeaderKey]; len(ks) > 0 && ks[0] == rpctypes.MetadataHasLeader { - if s.Leader() == types.ID(raft.None) { - return nil, rpctypes.ErrGRPCNoLeader - } - } - } - - return handler(ctx, req) - } -} - -func newLogUnaryInterceptor(s *etcdserver.EtcdServer) grpc.UnaryServerInterceptor { - return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - startTime := time.Now() - resp, err := handler(ctx, req) - defer logUnaryRequestStats(ctx, nil, info, startTime, req, resp) - return resp, err - } -} - -func logUnaryRequestStats(ctx context.Context, lg *zap.Logger, info *grpc.UnaryServerInfo, startTime time.Time, req interface{}, resp interface{}) { - duration := time.Since(startTime) - remote := "No remote client info." - peerInfo, ok := peer.FromContext(ctx) - if ok { - remote = peerInfo.Addr.String() - } - var responseType string = info.FullMethod - var reqCount, respCount int64 - var reqSize, respSize int - var reqContent string - switch _resp := resp.(type) { - case *pb.RangeResponse: - _req, ok := req.(*pb.RangeRequest) - if ok { - reqCount = 0 - reqSize = _req.Size() - reqContent = _req.String() - } - if _resp != nil { - respCount = _resp.GetCount() - respSize = _resp.Size() - } - case *pb.PutResponse: - _req, ok := req.(*pb.PutRequest) - if ok { - reqCount = 1 - reqSize = _req.Size() - reqContent = pb.NewLoggablePutRequest(_req).String() - // redact value field from request content, see PR #9821 - } - if _resp != nil { - respCount = 0 - respSize = _resp.Size() - } - case *pb.DeleteRangeResponse: - _req, ok := req.(*pb.DeleteRangeRequest) - if ok { - reqCount = 0 - reqSize = _req.Size() - reqContent = _req.String() - } - if _resp != nil { - respCount = _resp.GetDeleted() - respSize = _resp.Size() - } - case *pb.TxnResponse: - _req, ok := req.(*pb.TxnRequest) - if ok && _resp != nil { - if _resp.GetSucceeded() { // determine the 'actual' count and size of request based on success or failure - reqCount = int64(len(_req.GetSuccess())) - reqSize = 0 - for _, r := range _req.GetSuccess() { - reqSize += r.Size() - } - } else { - reqCount = int64(len(_req.GetFailure())) - reqSize = 0 - for _, r := range _req.GetFailure() { - reqSize += r.Size() - } - } - reqContent = pb.NewLoggableTxnRequest(_req).String() - // redact value field from request content, see PR #9821 - } - if _resp != nil { - respCount = 0 - respSize = _resp.Size() - } - default: - reqCount = -1 - reqSize = -1 - respCount = -1 - respSize = -1 - } - - logGenericRequestStats(lg, startTime, duration, remote, responseType, reqCount, reqSize, respCount, respSize, reqContent) -} - -func logGenericRequestStats(lg *zap.Logger, startTime time.Time, duration time.Duration, remote string, responseType string, - reqCount int64, reqSize int, respCount int64, respSize int, reqContent string) { - if lg == nil { - plog.Debugf("start time = %v, "+ - "time spent = %v, "+ - "remote = %s, "+ - "response type = %s, "+ - "request count = %d, "+ - "request size = %d, "+ - "response count = %d, "+ - "response size = %d, "+ - "request content = %s", - startTime, duration, remote, responseType, reqCount, reqSize, respCount, respSize, reqContent, - ) - } else { - lg.Debug("request stats", - zap.Time("start time", startTime), - zap.Duration("time spent", duration), - zap.String("remote", remote), - zap.String("response type", responseType), - zap.Int64("request count", reqCount), - zap.Int("request size", reqSize), - zap.Int64("response count", respCount), - zap.Int("response size", respSize), - zap.String("request content", reqContent), - ) - } -} - -func newStreamInterceptor(s *etcdserver.EtcdServer) grpc.StreamServerInterceptor { - smap := monitorLeader(s) - - return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { - if !api.IsCapabilityEnabled(api.V3rpcCapability) { - return rpctypes.ErrGRPCNotCapable - } - - md, ok := metadata.FromIncomingContext(ss.Context()) - if ok { - if ks := md[rpctypes.MetadataRequireLeaderKey]; len(ks) > 0 && ks[0] == rpctypes.MetadataHasLeader { - if s.Leader() == types.ID(raft.None) { - return rpctypes.ErrGRPCNoLeader - } - - cctx, cancel := context.WithCancel(ss.Context()) - ss = serverStreamWithCtx{ctx: cctx, cancel: &cancel, ServerStream: ss} - - smap.mu.Lock() - smap.streams[ss] = struct{}{} - smap.mu.Unlock() - - defer func() { - smap.mu.Lock() - delete(smap.streams, ss) - smap.mu.Unlock() - cancel() - }() - - } - } - - return handler(srv, ss) - } -} - -type serverStreamWithCtx struct { - grpc.ServerStream - ctx context.Context - cancel *context.CancelFunc -} - -func (ssc serverStreamWithCtx) Context() context.Context { return ssc.ctx } - -func monitorLeader(s *etcdserver.EtcdServer) *streamsMap { - smap := &streamsMap{ - streams: make(map[grpc.ServerStream]struct{}), - } - - go func() { - election := time.Duration(s.Cfg.TickMs) * time.Duration(s.Cfg.ElectionTicks) * time.Millisecond - noLeaderCnt := 0 - - for { - select { - case <-s.StopNotify(): - return - case <-time.After(election): - if s.Leader() == types.ID(raft.None) { - noLeaderCnt++ - } else { - noLeaderCnt = 0 - } - - // We are more conservative on canceling existing streams. Reconnecting streams - // cost much more than just rejecting new requests. So we wait until the member - // cannot find a leader for maxNoLeaderCnt election timeouts to cancel existing streams. - if noLeaderCnt >= maxNoLeaderCnt { - smap.mu.Lock() - for ss := range smap.streams { - if ssWithCtx, ok := ss.(serverStreamWithCtx); ok { - (*ssWithCtx.cancel)() - <-ss.Context().Done() - } - } - smap.streams = make(map[grpc.ServerStream]struct{}) - smap.mu.Unlock() - } - } - } - }() - - return smap -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/key.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/key.go deleted file mode 100644 index 9781bddda9c1..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/key.go +++ /dev/null @@ -1,277 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v3rpc implements etcd v3 RPC system based on gRPC. -package v3rpc - -import ( - "context" - - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/pkg/adt" - - "github.com/coreos/pkg/capnslog" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdserver/api/v3rpc") -) - -type kvServer struct { - hdr header - kv etcdserver.RaftKV - // maxTxnOps is the max operations per txn. - // e.g suppose maxTxnOps = 128. - // Txn.Success can have at most 128 operations, - // and Txn.Failure can have at most 128 operations. - maxTxnOps uint -} - -func NewKVServer(s *etcdserver.EtcdServer) pb.KVServer { - return &kvServer{hdr: newHeader(s), kv: s, maxTxnOps: s.Cfg.MaxTxnOps} -} - -func (s *kvServer) Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, error) { - if err := checkRangeRequest(r); err != nil { - return nil, err - } - - resp, err := s.kv.Range(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - - s.hdr.fill(resp.Header) - return resp, nil -} - -func (s *kvServer) Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error) { - if err := checkPutRequest(r); err != nil { - return nil, err - } - - resp, err := s.kv.Put(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - - s.hdr.fill(resp.Header) - return resp, nil -} - -func (s *kvServer) DeleteRange(ctx context.Context, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) { - if err := checkDeleteRequest(r); err != nil { - return nil, err - } - - resp, err := s.kv.DeleteRange(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - - s.hdr.fill(resp.Header) - return resp, nil -} - -func (s *kvServer) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error) { - if err := checkTxnRequest(r, int(s.maxTxnOps)); err != nil { - return nil, err - } - // check for forbidden put/del overlaps after checking request to avoid quadratic blowup - if _, _, err := checkIntervals(r.Success); err != nil { - return nil, err - } - if _, _, err := checkIntervals(r.Failure); err != nil { - return nil, err - } - - resp, err := s.kv.Txn(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - - s.hdr.fill(resp.Header) - return resp, nil -} - -func (s *kvServer) Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error) { - resp, err := s.kv.Compact(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - - s.hdr.fill(resp.Header) - return resp, nil -} - -func checkRangeRequest(r *pb.RangeRequest) error { - if len(r.Key) == 0 { - return rpctypes.ErrGRPCEmptyKey - } - return nil -} - -func checkPutRequest(r *pb.PutRequest) error { - if len(r.Key) == 0 { - return rpctypes.ErrGRPCEmptyKey - } - if r.IgnoreValue && len(r.Value) != 0 { - return rpctypes.ErrGRPCValueProvided - } - if r.IgnoreLease && r.Lease != 0 { - return rpctypes.ErrGRPCLeaseProvided - } - return nil -} - -func checkDeleteRequest(r *pb.DeleteRangeRequest) error { - if len(r.Key) == 0 { - return rpctypes.ErrGRPCEmptyKey - } - return nil -} - -func checkTxnRequest(r *pb.TxnRequest, maxTxnOps int) error { - opc := len(r.Compare) - if opc < len(r.Success) { - opc = len(r.Success) - } - if opc < len(r.Failure) { - opc = len(r.Failure) - } - if opc > maxTxnOps { - return rpctypes.ErrGRPCTooManyOps - } - - for _, c := range r.Compare { - if len(c.Key) == 0 { - return rpctypes.ErrGRPCEmptyKey - } - } - for _, u := range r.Success { - if err := checkRequestOp(u, maxTxnOps-opc); err != nil { - return err - } - } - for _, u := range r.Failure { - if err := checkRequestOp(u, maxTxnOps-opc); err != nil { - return err - } - } - - return nil -} - -// checkIntervals tests whether puts and deletes overlap for a list of ops. If -// there is an overlap, returns an error. If no overlap, return put and delete -// sets for recursive evaluation. -func checkIntervals(reqs []*pb.RequestOp) (map[string]struct{}, adt.IntervalTree, error) { - var dels adt.IntervalTree - - // collect deletes from this level; build first to check lower level overlapped puts - for _, req := range reqs { - tv, ok := req.Request.(*pb.RequestOp_RequestDeleteRange) - if !ok { - continue - } - dreq := tv.RequestDeleteRange - if dreq == nil { - continue - } - var iv adt.Interval - if len(dreq.RangeEnd) != 0 { - iv = adt.NewStringAffineInterval(string(dreq.Key), string(dreq.RangeEnd)) - } else { - iv = adt.NewStringAffinePoint(string(dreq.Key)) - } - dels.Insert(iv, struct{}{}) - } - - // collect children puts/deletes - puts := make(map[string]struct{}) - for _, req := range reqs { - tv, ok := req.Request.(*pb.RequestOp_RequestTxn) - if !ok { - continue - } - putsThen, delsThen, err := checkIntervals(tv.RequestTxn.Success) - if err != nil { - return nil, dels, err - } - putsElse, delsElse, err := checkIntervals(tv.RequestTxn.Failure) - if err != nil { - return nil, dels, err - } - for k := range putsThen { - if _, ok := puts[k]; ok { - return nil, dels, rpctypes.ErrGRPCDuplicateKey - } - if dels.Intersects(adt.NewStringAffinePoint(k)) { - return nil, dels, rpctypes.ErrGRPCDuplicateKey - } - puts[k] = struct{}{} - } - for k := range putsElse { - if _, ok := puts[k]; ok { - // if key is from putsThen, overlap is OK since - // either then/else are mutually exclusive - if _, isSafe := putsThen[k]; !isSafe { - return nil, dels, rpctypes.ErrGRPCDuplicateKey - } - } - if dels.Intersects(adt.NewStringAffinePoint(k)) { - return nil, dels, rpctypes.ErrGRPCDuplicateKey - } - puts[k] = struct{}{} - } - dels.Union(delsThen, adt.NewStringAffineInterval("\x00", "")) - dels.Union(delsElse, adt.NewStringAffineInterval("\x00", "")) - } - - // collect and check this level's puts - for _, req := range reqs { - tv, ok := req.Request.(*pb.RequestOp_RequestPut) - if !ok || tv.RequestPut == nil { - continue - } - k := string(tv.RequestPut.Key) - if _, ok := puts[k]; ok { - return nil, dels, rpctypes.ErrGRPCDuplicateKey - } - if dels.Intersects(adt.NewStringAffinePoint(k)) { - return nil, dels, rpctypes.ErrGRPCDuplicateKey - } - puts[k] = struct{}{} - } - return puts, dels, nil -} - -func checkRequestOp(u *pb.RequestOp, maxTxnOps int) error { - // TODO: ensure only one of the field is set. - switch uv := u.Request.(type) { - case *pb.RequestOp_RequestRange: - return checkRangeRequest(uv.RequestRange) - case *pb.RequestOp_RequestPut: - return checkPutRequest(uv.RequestPut) - case *pb.RequestOp_RequestDeleteRange: - return checkDeleteRequest(uv.RequestDeleteRange) - case *pb.RequestOp_RequestTxn: - return checkTxnRequest(uv.RequestTxn, maxTxnOps) - default: - // empty op / nil entry - return rpctypes.ErrGRPCKeyNotFound - } -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/lease.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/lease.go deleted file mode 100644 index 5b4f2b142281..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/lease.go +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - "io" - - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/lease" -) - -type LeaseServer struct { - hdr header - le etcdserver.Lessor -} - -func NewLeaseServer(s *etcdserver.EtcdServer) pb.LeaseServer { - return &LeaseServer{le: s, hdr: newHeader(s)} -} - -func (ls *LeaseServer) LeaseGrant(ctx context.Context, cr *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - resp, err := ls.le.LeaseGrant(ctx, cr) - - if err != nil { - return nil, togRPCError(err) - } - ls.hdr.fill(resp.Header) - return resp, nil -} - -func (ls *LeaseServer) LeaseRevoke(ctx context.Context, rr *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) { - resp, err := ls.le.LeaseRevoke(ctx, rr) - if err != nil { - return nil, togRPCError(err) - } - ls.hdr.fill(resp.Header) - return resp, nil -} - -func (ls *LeaseServer) LeaseTimeToLive(ctx context.Context, rr *pb.LeaseTimeToLiveRequest) (*pb.LeaseTimeToLiveResponse, error) { - resp, err := ls.le.LeaseTimeToLive(ctx, rr) - if err != nil && err != lease.ErrLeaseNotFound { - return nil, togRPCError(err) - } - if err == lease.ErrLeaseNotFound { - resp = &pb.LeaseTimeToLiveResponse{ - Header: &pb.ResponseHeader{}, - ID: rr.ID, - TTL: -1, - } - } - ls.hdr.fill(resp.Header) - return resp, nil -} - -func (ls *LeaseServer) LeaseLeases(ctx context.Context, rr *pb.LeaseLeasesRequest) (*pb.LeaseLeasesResponse, error) { - resp, err := ls.le.LeaseLeases(ctx, rr) - if err != nil && err != lease.ErrLeaseNotFound { - return nil, togRPCError(err) - } - if err == lease.ErrLeaseNotFound { - resp = &pb.LeaseLeasesResponse{ - Header: &pb.ResponseHeader{}, - Leases: []*pb.LeaseStatus{}, - } - } - ls.hdr.fill(resp.Header) - return resp, nil -} - -func (ls *LeaseServer) LeaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) (err error) { - errc := make(chan error, 1) - go func() { - errc <- ls.leaseKeepAlive(stream) - }() - select { - case err = <-errc: - case <-stream.Context().Done(): - // the only server-side cancellation is noleader for now. - err = stream.Context().Err() - if err == context.Canceled { - err = rpctypes.ErrGRPCNoLeader - } - } - return err -} - -func (ls *LeaseServer) leaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) error { - for { - req, err := stream.Recv() - if err == io.EOF { - return nil - } - if err != nil { - if isClientCtxErr(stream.Context().Err(), err) { - plog.Debugf("failed to receive lease keepalive request from gRPC stream (%q)", err.Error()) - } else { - plog.Warningf("failed to receive lease keepalive request from gRPC stream (%q)", err.Error()) - } - return err - } - - // Create header before we sent out the renew request. - // This can make sure that the revision is strictly smaller or equal to - // when the keepalive happened at the local server (when the local server is the leader) - // or remote leader. - // Without this, a lease might be revoked at rev 3 but client can see the keepalive succeeded - // at rev 4. - resp := &pb.LeaseKeepAliveResponse{ID: req.ID, Header: &pb.ResponseHeader{}} - ls.hdr.fill(resp.Header) - - ttl, err := ls.le.LeaseRenew(stream.Context(), lease.LeaseID(req.ID)) - if err == lease.ErrLeaseNotFound { - err = nil - ttl = 0 - } - - if err != nil { - return togRPCError(err) - } - - resp.TTL = ttl - err = stream.Send(resp) - if err != nil { - if isClientCtxErr(stream.Context().Err(), err) { - plog.Debugf("failed to send lease keepalive response to gRPC stream (%q)", err.Error()) - } else { - plog.Warningf("failed to send lease keepalive response to gRPC stream (%q)", err.Error()) - } - return err - } - } -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/maintenance.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/maintenance.go deleted file mode 100644 index c9df1800db28..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/maintenance.go +++ /dev/null @@ -1,229 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - "crypto/sha256" - "io" - - "github.com/coreos/etcd/auth" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/version" -) - -type KVGetter interface { - KV() mvcc.ConsistentWatchableKV -} - -type BackendGetter interface { - Backend() backend.Backend -} - -type Alarmer interface { - Alarm(ctx context.Context, ar *pb.AlarmRequest) (*pb.AlarmResponse, error) -} - -type LeaderTransferrer interface { - MoveLeader(ctx context.Context, lead, target uint64) error -} - -type RaftStatusGetter interface { - etcdserver.RaftTimer - ID() types.ID - Leader() types.ID -} - -type AuthGetter interface { - AuthInfoFromCtx(ctx context.Context) (*auth.AuthInfo, error) - AuthStore() auth.AuthStore -} - -type maintenanceServer struct { - rg RaftStatusGetter - kg KVGetter - bg BackendGetter - a Alarmer - lt LeaderTransferrer - hdr header -} - -func NewMaintenanceServer(s *etcdserver.EtcdServer) pb.MaintenanceServer { - srv := &maintenanceServer{rg: s, kg: s, bg: s, a: s, lt: s, hdr: newHeader(s)} - return &authMaintenanceServer{srv, s} -} - -func (ms *maintenanceServer) Defragment(ctx context.Context, sr *pb.DefragmentRequest) (*pb.DefragmentResponse, error) { - plog.Noticef("starting to defragment the storage backend...") - err := ms.bg.Backend().Defrag() - if err != nil { - plog.Errorf("failed to defragment the storage backend (%v)", err) - return nil, err - } - plog.Noticef("finished defragmenting the storage backend") - return &pb.DefragmentResponse{}, nil -} - -func (ms *maintenanceServer) Snapshot(sr *pb.SnapshotRequest, srv pb.Maintenance_SnapshotServer) error { - snap := ms.bg.Backend().Snapshot() - pr, pw := io.Pipe() - - defer pr.Close() - - go func() { - snap.WriteTo(pw) - if err := snap.Close(); err != nil { - plog.Errorf("error closing snapshot (%v)", err) - } - pw.Close() - }() - - // send file data - h := sha256.New() - br := int64(0) - buf := make([]byte, 32*1024) - sz := snap.Size() - for br < sz { - n, err := io.ReadFull(pr, buf) - if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF { - return togRPCError(err) - } - br += int64(n) - resp := &pb.SnapshotResponse{ - RemainingBytes: uint64(sz - br), - Blob: buf[:n], - } - if err = srv.Send(resp); err != nil { - return togRPCError(err) - } - h.Write(buf[:n]) - } - - // send sha - sha := h.Sum(nil) - hresp := &pb.SnapshotResponse{RemainingBytes: 0, Blob: sha} - if err := srv.Send(hresp); err != nil { - return togRPCError(err) - } - - return nil -} - -func (ms *maintenanceServer) Hash(ctx context.Context, r *pb.HashRequest) (*pb.HashResponse, error) { - h, rev, err := ms.kg.KV().Hash() - if err != nil { - return nil, togRPCError(err) - } - resp := &pb.HashResponse{Header: &pb.ResponseHeader{Revision: rev}, Hash: h} - ms.hdr.fill(resp.Header) - return resp, nil -} - -func (ms *maintenanceServer) HashKV(ctx context.Context, r *pb.HashKVRequest) (*pb.HashKVResponse, error) { - h, rev, compactRev, err := ms.kg.KV().HashByRev(r.Revision) - if err != nil { - return nil, togRPCError(err) - } - - resp := &pb.HashKVResponse{Header: &pb.ResponseHeader{Revision: rev}, Hash: h, CompactRevision: compactRev} - ms.hdr.fill(resp.Header) - return resp, nil -} - -func (ms *maintenanceServer) Alarm(ctx context.Context, ar *pb.AlarmRequest) (*pb.AlarmResponse, error) { - return ms.a.Alarm(ctx, ar) -} - -func (ms *maintenanceServer) Status(ctx context.Context, ar *pb.StatusRequest) (*pb.StatusResponse, error) { - resp := &pb.StatusResponse{ - Header: &pb.ResponseHeader{Revision: ms.hdr.rev()}, - Version: version.Version, - DbSize: ms.bg.Backend().Size(), - Leader: uint64(ms.rg.Leader()), - RaftIndex: ms.rg.Index(), - RaftTerm: ms.rg.Term(), - } - ms.hdr.fill(resp.Header) - return resp, nil -} - -func (ms *maintenanceServer) MoveLeader(ctx context.Context, tr *pb.MoveLeaderRequest) (*pb.MoveLeaderResponse, error) { - if ms.rg.ID() != ms.rg.Leader() { - return nil, rpctypes.ErrGRPCNotLeader - } - - if err := ms.lt.MoveLeader(ctx, uint64(ms.rg.Leader()), tr.TargetID); err != nil { - return nil, togRPCError(err) - } - return &pb.MoveLeaderResponse{}, nil -} - -type authMaintenanceServer struct { - *maintenanceServer - ag AuthGetter -} - -func (ams *authMaintenanceServer) isAuthenticated(ctx context.Context) error { - authInfo, err := ams.ag.AuthInfoFromCtx(ctx) - if err != nil { - return err - } - - return ams.ag.AuthStore().IsAdminPermitted(authInfo) -} - -func (ams *authMaintenanceServer) Defragment(ctx context.Context, sr *pb.DefragmentRequest) (*pb.DefragmentResponse, error) { - if err := ams.isAuthenticated(ctx); err != nil { - return nil, err - } - - return ams.maintenanceServer.Defragment(ctx, sr) -} - -func (ams *authMaintenanceServer) Snapshot(sr *pb.SnapshotRequest, srv pb.Maintenance_SnapshotServer) error { - if err := ams.isAuthenticated(srv.Context()); err != nil { - return err - } - - return ams.maintenanceServer.Snapshot(sr, srv) -} - -func (ams *authMaintenanceServer) Hash(ctx context.Context, r *pb.HashRequest) (*pb.HashResponse, error) { - if err := ams.isAuthenticated(ctx); err != nil { - return nil, err - } - - return ams.maintenanceServer.Hash(ctx, r) -} - -func (ams *authMaintenanceServer) HashKV(ctx context.Context, r *pb.HashKVRequest) (*pb.HashKVResponse, error) { - if err := ams.isAuthenticated(ctx); err != nil { - return nil, err - } - return ams.maintenanceServer.HashKV(ctx, r) -} - -func (ams *authMaintenanceServer) Status(ctx context.Context, ar *pb.StatusRequest) (*pb.StatusResponse, error) { - return ams.maintenanceServer.Status(ctx, ar) -} - -func (ams *authMaintenanceServer) MoveLeader(ctx context.Context, tr *pb.MoveLeaderRequest) (*pb.MoveLeaderResponse, error) { - return ams.maintenanceServer.MoveLeader(ctx, tr) -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/member.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/member.go deleted file mode 100644 index cbe7b470ab93..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/member.go +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - "time" - - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/pkg/types" -) - -type ClusterServer struct { - cluster api.Cluster - server etcdserver.ServerV3 -} - -func NewClusterServer(s etcdserver.ServerV3) *ClusterServer { - return &ClusterServer{ - cluster: s.Cluster(), - server: s, - } -} - -func (cs *ClusterServer) MemberAdd(ctx context.Context, r *pb.MemberAddRequest) (*pb.MemberAddResponse, error) { - urls, err := types.NewURLs(r.PeerURLs) - if err != nil { - return nil, rpctypes.ErrGRPCMemberBadURLs - } - - now := time.Now() - m := membership.NewMember("", urls, "", &now) - membs, merr := cs.server.AddMember(ctx, *m) - if merr != nil { - return nil, togRPCError(merr) - } - - return &pb.MemberAddResponse{ - Header: cs.header(), - Member: &pb.Member{ID: uint64(m.ID), PeerURLs: m.PeerURLs}, - Members: membersToProtoMembers(membs), - }, nil -} - -func (cs *ClusterServer) MemberRemove(ctx context.Context, r *pb.MemberRemoveRequest) (*pb.MemberRemoveResponse, error) { - membs, err := cs.server.RemoveMember(ctx, r.ID) - if err != nil { - return nil, togRPCError(err) - } - return &pb.MemberRemoveResponse{Header: cs.header(), Members: membersToProtoMembers(membs)}, nil -} - -func (cs *ClusterServer) MemberUpdate(ctx context.Context, r *pb.MemberUpdateRequest) (*pb.MemberUpdateResponse, error) { - m := membership.Member{ - ID: types.ID(r.ID), - RaftAttributes: membership.RaftAttributes{PeerURLs: r.PeerURLs}, - } - membs, err := cs.server.UpdateMember(ctx, m) - if err != nil { - return nil, togRPCError(err) - } - return &pb.MemberUpdateResponse{Header: cs.header(), Members: membersToProtoMembers(membs)}, nil -} - -func (cs *ClusterServer) MemberList(ctx context.Context, r *pb.MemberListRequest) (*pb.MemberListResponse, error) { - membs := membersToProtoMembers(cs.cluster.Members()) - return &pb.MemberListResponse{Header: cs.header(), Members: membs}, nil -} - -func (cs *ClusterServer) header() *pb.ResponseHeader { - return &pb.ResponseHeader{ClusterId: uint64(cs.cluster.ID()), MemberId: uint64(cs.server.ID()), RaftTerm: cs.server.Term()} -} - -func membersToProtoMembers(membs []*membership.Member) []*pb.Member { - protoMembs := make([]*pb.Member, len(membs)) - for i := range membs { - protoMembs[i] = &pb.Member{ - Name: membs[i].Name, - ID: uint64(membs[i].ID), - PeerURLs: membs[i].PeerURLs, - ClientURLs: membs[i].ClientURLs, - } - } - return protoMembs -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/metrics.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/metrics.go deleted file mode 100644 index 6cb41a61e565..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/metrics.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import "github.com/prometheus/client_golang/prometheus" - -var ( - sentBytes = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "client_grpc_sent_bytes_total", - Help: "The total number of bytes sent to grpc clients.", - }) - - receivedBytes = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "client_grpc_received_bytes_total", - Help: "The total number of bytes received from grpc clients.", - }) -) - -func init() { - prometheus.MustRegister(sentBytes) - prometheus.MustRegister(receivedBytes) -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/quota.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/quota.go deleted file mode 100644 index 02d99609d885..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/quota.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/pkg/types" -) - -type quotaKVServer struct { - pb.KVServer - qa quotaAlarmer -} - -type quotaAlarmer struct { - q etcdserver.Quota - a Alarmer - id types.ID -} - -// check whether request satisfies the quota. If there is not enough space, -// ignore request and raise the free space alarm. -func (qa *quotaAlarmer) check(ctx context.Context, r interface{}) error { - if qa.q.Available(r) { - return nil - } - req := &pb.AlarmRequest{ - MemberID: uint64(qa.id), - Action: pb.AlarmRequest_ACTIVATE, - Alarm: pb.AlarmType_NOSPACE, - } - qa.a.Alarm(ctx, req) - return rpctypes.ErrGRPCNoSpace -} - -func NewQuotaKVServer(s *etcdserver.EtcdServer) pb.KVServer { - return "aKVServer{ - NewKVServer(s), - quotaAlarmer{etcdserver.NewBackendQuota(s), s, s.ID()}, - } -} - -func (s *quotaKVServer) Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error) { - if err := s.qa.check(ctx, r); err != nil { - return nil, err - } - return s.KVServer.Put(ctx, r) -} - -func (s *quotaKVServer) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error) { - if err := s.qa.check(ctx, r); err != nil { - return nil, err - } - return s.KVServer.Txn(ctx, r) -} - -type quotaLeaseServer struct { - pb.LeaseServer - qa quotaAlarmer -} - -func (s *quotaLeaseServer) LeaseGrant(ctx context.Context, cr *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - if err := s.qa.check(ctx, cr); err != nil { - return nil, err - } - return s.LeaseServer.LeaseGrant(ctx, cr) -} - -func NewQuotaLeaseServer(s *etcdserver.EtcdServer) pb.LeaseServer { - return "aLeaseServer{ - NewLeaseServer(s), - quotaAlarmer{etcdserver.NewBackendQuota(s), s, s.ID()}, - } -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes/doc.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes/doc.go deleted file mode 100644 index f72c6a644f33..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package rpctypes has types and values shared by the etcd server and client for v3 RPC interaction. -package rpctypes diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes/error.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes/error.go deleted file mode 100644 index 55eab38ef17b..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes/error.go +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rpctypes - -import ( - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -// server-side error -var ( - ErrGRPCEmptyKey = status.New(codes.InvalidArgument, "etcdserver: key is not provided").Err() - ErrGRPCKeyNotFound = status.New(codes.InvalidArgument, "etcdserver: key not found").Err() - ErrGRPCValueProvided = status.New(codes.InvalidArgument, "etcdserver: value is provided").Err() - ErrGRPCLeaseProvided = status.New(codes.InvalidArgument, "etcdserver: lease is provided").Err() - ErrGRPCTooManyOps = status.New(codes.InvalidArgument, "etcdserver: too many operations in txn request").Err() - ErrGRPCDuplicateKey = status.New(codes.InvalidArgument, "etcdserver: duplicate key given in txn request").Err() - ErrGRPCCompacted = status.New(codes.OutOfRange, "etcdserver: mvcc: required revision has been compacted").Err() - ErrGRPCFutureRev = status.New(codes.OutOfRange, "etcdserver: mvcc: required revision is a future revision").Err() - ErrGRPCNoSpace = status.New(codes.ResourceExhausted, "etcdserver: mvcc: database space exceeded").Err() - - ErrGRPCLeaseNotFound = status.New(codes.NotFound, "etcdserver: requested lease not found").Err() - ErrGRPCLeaseExist = status.New(codes.FailedPrecondition, "etcdserver: lease already exists").Err() - ErrGRPCLeaseTTLTooLarge = status.New(codes.OutOfRange, "etcdserver: too large lease TTL").Err() - - ErrGRPCMemberExist = status.New(codes.FailedPrecondition, "etcdserver: member ID already exist").Err() - ErrGRPCPeerURLExist = status.New(codes.FailedPrecondition, "etcdserver: Peer URLs already exists").Err() - ErrGRPCMemberNotEnoughStarted = status.New(codes.FailedPrecondition, "etcdserver: re-configuration failed due to not enough started members").Err() - ErrGRPCMemberBadURLs = status.New(codes.InvalidArgument, "etcdserver: given member URLs are invalid").Err() - ErrGRPCMemberNotFound = status.New(codes.NotFound, "etcdserver: member not found").Err() - - ErrGRPCRequestTooLarge = status.New(codes.InvalidArgument, "etcdserver: request is too large").Err() - ErrGRPCRequestTooManyRequests = status.New(codes.ResourceExhausted, "etcdserver: too many requests").Err() - - ErrGRPCRootUserNotExist = status.New(codes.FailedPrecondition, "etcdserver: root user does not exist").Err() - ErrGRPCRootRoleNotExist = status.New(codes.FailedPrecondition, "etcdserver: root user does not have root role").Err() - ErrGRPCUserAlreadyExist = status.New(codes.FailedPrecondition, "etcdserver: user name already exists").Err() - ErrGRPCUserEmpty = status.New(codes.InvalidArgument, "etcdserver: user name is empty").Err() - ErrGRPCUserNotFound = status.New(codes.FailedPrecondition, "etcdserver: user name not found").Err() - ErrGRPCRoleAlreadyExist = status.New(codes.FailedPrecondition, "etcdserver: role name already exists").Err() - ErrGRPCRoleNotFound = status.New(codes.FailedPrecondition, "etcdserver: role name not found").Err() - ErrGRPCAuthFailed = status.New(codes.InvalidArgument, "etcdserver: authentication failed, invalid user ID or password").Err() - ErrGRPCPermissionDenied = status.New(codes.PermissionDenied, "etcdserver: permission denied").Err() - ErrGRPCRoleNotGranted = status.New(codes.FailedPrecondition, "etcdserver: role is not granted to the user").Err() - ErrGRPCPermissionNotGranted = status.New(codes.FailedPrecondition, "etcdserver: permission is not granted to the role").Err() - ErrGRPCAuthNotEnabled = status.New(codes.FailedPrecondition, "etcdserver: authentication is not enabled").Err() - ErrGRPCInvalidAuthToken = status.New(codes.Unauthenticated, "etcdserver: invalid auth token").Err() - ErrGRPCInvalidAuthMgmt = status.New(codes.InvalidArgument, "etcdserver: invalid auth management").Err() - - ErrGRPCNoLeader = status.New(codes.Unavailable, "etcdserver: no leader").Err() - ErrGRPCNotLeader = status.New(codes.FailedPrecondition, "etcdserver: not leader").Err() - ErrGRPCNotCapable = status.New(codes.Unavailable, "etcdserver: not capable").Err() - ErrGRPCStopped = status.New(codes.Unavailable, "etcdserver: server stopped").Err() - ErrGRPCTimeout = status.New(codes.Unavailable, "etcdserver: request timed out").Err() - ErrGRPCTimeoutDueToLeaderFail = status.New(codes.Unavailable, "etcdserver: request timed out, possibly due to previous leader failure").Err() - ErrGRPCTimeoutDueToConnectionLost = status.New(codes.Unavailable, "etcdserver: request timed out, possibly due to connection lost").Err() - ErrGRPCUnhealthy = status.New(codes.Unavailable, "etcdserver: unhealthy cluster").Err() - ErrGRPCCorrupt = status.New(codes.DataLoss, "etcdserver: corrupt cluster").Err() - - errStringToError = map[string]error{ - ErrorDesc(ErrGRPCEmptyKey): ErrGRPCEmptyKey, - ErrorDesc(ErrGRPCKeyNotFound): ErrGRPCKeyNotFound, - ErrorDesc(ErrGRPCValueProvided): ErrGRPCValueProvided, - ErrorDesc(ErrGRPCLeaseProvided): ErrGRPCLeaseProvided, - - ErrorDesc(ErrGRPCTooManyOps): ErrGRPCTooManyOps, - ErrorDesc(ErrGRPCDuplicateKey): ErrGRPCDuplicateKey, - ErrorDesc(ErrGRPCCompacted): ErrGRPCCompacted, - ErrorDesc(ErrGRPCFutureRev): ErrGRPCFutureRev, - ErrorDesc(ErrGRPCNoSpace): ErrGRPCNoSpace, - - ErrorDesc(ErrGRPCLeaseNotFound): ErrGRPCLeaseNotFound, - ErrorDesc(ErrGRPCLeaseExist): ErrGRPCLeaseExist, - ErrorDesc(ErrGRPCLeaseTTLTooLarge): ErrGRPCLeaseTTLTooLarge, - - ErrorDesc(ErrGRPCMemberExist): ErrGRPCMemberExist, - ErrorDesc(ErrGRPCPeerURLExist): ErrGRPCPeerURLExist, - ErrorDesc(ErrGRPCMemberNotEnoughStarted): ErrGRPCMemberNotEnoughStarted, - ErrorDesc(ErrGRPCMemberBadURLs): ErrGRPCMemberBadURLs, - ErrorDesc(ErrGRPCMemberNotFound): ErrGRPCMemberNotFound, - - ErrorDesc(ErrGRPCRequestTooLarge): ErrGRPCRequestTooLarge, - ErrorDesc(ErrGRPCRequestTooManyRequests): ErrGRPCRequestTooManyRequests, - - ErrorDesc(ErrGRPCRootUserNotExist): ErrGRPCRootUserNotExist, - ErrorDesc(ErrGRPCRootRoleNotExist): ErrGRPCRootRoleNotExist, - ErrorDesc(ErrGRPCUserAlreadyExist): ErrGRPCUserAlreadyExist, - ErrorDesc(ErrGRPCUserEmpty): ErrGRPCUserEmpty, - ErrorDesc(ErrGRPCUserNotFound): ErrGRPCUserNotFound, - ErrorDesc(ErrGRPCRoleAlreadyExist): ErrGRPCRoleAlreadyExist, - ErrorDesc(ErrGRPCRoleNotFound): ErrGRPCRoleNotFound, - ErrorDesc(ErrGRPCAuthFailed): ErrGRPCAuthFailed, - ErrorDesc(ErrGRPCPermissionDenied): ErrGRPCPermissionDenied, - ErrorDesc(ErrGRPCRoleNotGranted): ErrGRPCRoleNotGranted, - ErrorDesc(ErrGRPCPermissionNotGranted): ErrGRPCPermissionNotGranted, - ErrorDesc(ErrGRPCAuthNotEnabled): ErrGRPCAuthNotEnabled, - ErrorDesc(ErrGRPCInvalidAuthToken): ErrGRPCInvalidAuthToken, - ErrorDesc(ErrGRPCInvalidAuthMgmt): ErrGRPCInvalidAuthMgmt, - - ErrorDesc(ErrGRPCNoLeader): ErrGRPCNoLeader, - ErrorDesc(ErrGRPCNotLeader): ErrGRPCNotLeader, - ErrorDesc(ErrGRPCNotCapable): ErrGRPCNotCapable, - ErrorDesc(ErrGRPCStopped): ErrGRPCStopped, - ErrorDesc(ErrGRPCTimeout): ErrGRPCTimeout, - ErrorDesc(ErrGRPCTimeoutDueToLeaderFail): ErrGRPCTimeoutDueToLeaderFail, - ErrorDesc(ErrGRPCTimeoutDueToConnectionLost): ErrGRPCTimeoutDueToConnectionLost, - ErrorDesc(ErrGRPCUnhealthy): ErrGRPCUnhealthy, - ErrorDesc(ErrGRPCCorrupt): ErrGRPCCorrupt, - } -) - -// client-side error -var ( - ErrEmptyKey = Error(ErrGRPCEmptyKey) - ErrKeyNotFound = Error(ErrGRPCKeyNotFound) - ErrValueProvided = Error(ErrGRPCValueProvided) - ErrLeaseProvided = Error(ErrGRPCLeaseProvided) - ErrTooManyOps = Error(ErrGRPCTooManyOps) - ErrDuplicateKey = Error(ErrGRPCDuplicateKey) - ErrCompacted = Error(ErrGRPCCompacted) - ErrFutureRev = Error(ErrGRPCFutureRev) - ErrNoSpace = Error(ErrGRPCNoSpace) - - ErrLeaseNotFound = Error(ErrGRPCLeaseNotFound) - ErrLeaseExist = Error(ErrGRPCLeaseExist) - ErrLeaseTTLTooLarge = Error(ErrGRPCLeaseTTLTooLarge) - - ErrMemberExist = Error(ErrGRPCMemberExist) - ErrPeerURLExist = Error(ErrGRPCPeerURLExist) - ErrMemberNotEnoughStarted = Error(ErrGRPCMemberNotEnoughStarted) - ErrMemberBadURLs = Error(ErrGRPCMemberBadURLs) - ErrMemberNotFound = Error(ErrGRPCMemberNotFound) - - ErrRequestTooLarge = Error(ErrGRPCRequestTooLarge) - ErrTooManyRequests = Error(ErrGRPCRequestTooManyRequests) - - ErrRootUserNotExist = Error(ErrGRPCRootUserNotExist) - ErrRootRoleNotExist = Error(ErrGRPCRootRoleNotExist) - ErrUserAlreadyExist = Error(ErrGRPCUserAlreadyExist) - ErrUserEmpty = Error(ErrGRPCUserEmpty) - ErrUserNotFound = Error(ErrGRPCUserNotFound) - ErrRoleAlreadyExist = Error(ErrGRPCRoleAlreadyExist) - ErrRoleNotFound = Error(ErrGRPCRoleNotFound) - ErrAuthFailed = Error(ErrGRPCAuthFailed) - ErrPermissionDenied = Error(ErrGRPCPermissionDenied) - ErrRoleNotGranted = Error(ErrGRPCRoleNotGranted) - ErrPermissionNotGranted = Error(ErrGRPCPermissionNotGranted) - ErrAuthNotEnabled = Error(ErrGRPCAuthNotEnabled) - ErrInvalidAuthToken = Error(ErrGRPCInvalidAuthToken) - ErrInvalidAuthMgmt = Error(ErrGRPCInvalidAuthMgmt) - - ErrNoLeader = Error(ErrGRPCNoLeader) - ErrNotLeader = Error(ErrGRPCNotLeader) - ErrNotCapable = Error(ErrGRPCNotCapable) - ErrStopped = Error(ErrGRPCStopped) - ErrTimeout = Error(ErrGRPCTimeout) - ErrTimeoutDueToLeaderFail = Error(ErrGRPCTimeoutDueToLeaderFail) - ErrTimeoutDueToConnectionLost = Error(ErrGRPCTimeoutDueToConnectionLost) - ErrUnhealthy = Error(ErrGRPCUnhealthy) - ErrCorrupt = Error(ErrGRPCCorrupt) -) - -// EtcdError defines gRPC server errors. -// (https://github.com/grpc/grpc-go/blob/master/rpc_util.go#L319-L323) -type EtcdError struct { - code codes.Code - desc string -} - -// Code returns grpc/codes.Code. -// TODO: define clientv3/codes.Code. -func (e EtcdError) Code() codes.Code { - return e.code -} - -func (e EtcdError) Error() string { - return e.desc -} - -func Error(err error) error { - if err == nil { - return nil - } - verr, ok := errStringToError[ErrorDesc(err)] - if !ok { // not gRPC error - return err - } - ev, ok := status.FromError(verr) - var desc string - if ok { - desc = ev.Message() - } else { - desc = verr.Error() - } - return EtcdError{code: ev.Code(), desc: desc} -} - -func ErrorDesc(err error) string { - if s, ok := status.FromError(err); ok { - return s.Message() - } - return err.Error() -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes/md.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes/md.go deleted file mode 100644 index 5c590e1aec99..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes/md.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rpctypes - -var ( - MetadataRequireLeaderKey = "hasleader" - MetadataHasLeader = "true" -) diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/util.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/util.go deleted file mode 100644 index 799c1197d8dd..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/util.go +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - "strings" - - "github.com/coreos/etcd/auth" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/mvcc" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -var toGRPCErrorMap = map[error]error{ - membership.ErrIDRemoved: rpctypes.ErrGRPCMemberNotFound, - membership.ErrIDNotFound: rpctypes.ErrGRPCMemberNotFound, - membership.ErrIDExists: rpctypes.ErrGRPCMemberExist, - membership.ErrPeerURLexists: rpctypes.ErrGRPCPeerURLExist, - etcdserver.ErrNotEnoughStartedMembers: rpctypes.ErrMemberNotEnoughStarted, - - mvcc.ErrCompacted: rpctypes.ErrGRPCCompacted, - mvcc.ErrFutureRev: rpctypes.ErrGRPCFutureRev, - etcdserver.ErrRequestTooLarge: rpctypes.ErrGRPCRequestTooLarge, - etcdserver.ErrNoSpace: rpctypes.ErrGRPCNoSpace, - etcdserver.ErrTooManyRequests: rpctypes.ErrTooManyRequests, - - etcdserver.ErrNoLeader: rpctypes.ErrGRPCNoLeader, - etcdserver.ErrNotLeader: rpctypes.ErrGRPCNotLeader, - etcdserver.ErrStopped: rpctypes.ErrGRPCStopped, - etcdserver.ErrTimeout: rpctypes.ErrGRPCTimeout, - etcdserver.ErrTimeoutDueToLeaderFail: rpctypes.ErrGRPCTimeoutDueToLeaderFail, - etcdserver.ErrTimeoutDueToConnectionLost: rpctypes.ErrGRPCTimeoutDueToConnectionLost, - etcdserver.ErrUnhealthy: rpctypes.ErrGRPCUnhealthy, - etcdserver.ErrKeyNotFound: rpctypes.ErrGRPCKeyNotFound, - etcdserver.ErrCorrupt: rpctypes.ErrGRPCCorrupt, - - lease.ErrLeaseNotFound: rpctypes.ErrGRPCLeaseNotFound, - lease.ErrLeaseExists: rpctypes.ErrGRPCLeaseExist, - lease.ErrLeaseTTLTooLarge: rpctypes.ErrGRPCLeaseTTLTooLarge, - - auth.ErrRootUserNotExist: rpctypes.ErrGRPCRootUserNotExist, - auth.ErrRootRoleNotExist: rpctypes.ErrGRPCRootRoleNotExist, - auth.ErrUserAlreadyExist: rpctypes.ErrGRPCUserAlreadyExist, - auth.ErrUserEmpty: rpctypes.ErrGRPCUserEmpty, - auth.ErrUserNotFound: rpctypes.ErrGRPCUserNotFound, - auth.ErrRoleAlreadyExist: rpctypes.ErrGRPCRoleAlreadyExist, - auth.ErrRoleNotFound: rpctypes.ErrGRPCRoleNotFound, - auth.ErrAuthFailed: rpctypes.ErrGRPCAuthFailed, - auth.ErrPermissionDenied: rpctypes.ErrGRPCPermissionDenied, - auth.ErrRoleNotGranted: rpctypes.ErrGRPCRoleNotGranted, - auth.ErrPermissionNotGranted: rpctypes.ErrGRPCPermissionNotGranted, - auth.ErrAuthNotEnabled: rpctypes.ErrGRPCAuthNotEnabled, - auth.ErrInvalidAuthToken: rpctypes.ErrGRPCInvalidAuthToken, - auth.ErrInvalidAuthMgmt: rpctypes.ErrGRPCInvalidAuthMgmt, -} - -func togRPCError(err error) error { - // let gRPC server convert to codes.Canceled, codes.DeadlineExceeded - if err == context.Canceled || err == context.DeadlineExceeded { - return err - } - grpcErr, ok := toGRPCErrorMap[err] - if !ok { - return status.Error(codes.Unknown, err.Error()) - } - return grpcErr -} - -func isClientCtxErr(ctxErr error, err error) bool { - if ctxErr != nil { - return true - } - - ev, ok := status.FromError(err) - if !ok { - return false - } - - switch ev.Code() { - case codes.Canceled, codes.DeadlineExceeded: - // client-side context cancel or deadline exceeded - // "rpc error: code = Canceled desc = context canceled" - // "rpc error: code = DeadlineExceeded desc = context deadline exceeded" - return true - case codes.Unavailable: - msg := ev.Message() - // client-side context cancel or deadline exceeded with TLS ("http2.errClientDisconnected") - // "rpc error: code = Unavailable desc = client disconnected" - if msg == "client disconnected" { - return true - } - // "grpc/transport.ClientTransport.CloseStream" on canceled streams - // "rpc error: code = Unavailable desc = stream error: stream ID 21; CANCEL") - if strings.HasPrefix(msg, "stream error: ") && strings.HasSuffix(msg, "; CANCEL") { - return true - } - } - return false -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/watch.go b/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/watch.go deleted file mode 100644 index dd4f329515d1..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v3rpc/watch.go +++ /dev/null @@ -1,447 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - "io" - "sync" - "time" - - "github.com/coreos/etcd/auth" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -type watchServer struct { - clusterID int64 - memberID int64 - raftTimer etcdserver.RaftTimer - watchable mvcc.WatchableKV - - ag AuthGetter -} - -func NewWatchServer(s *etcdserver.EtcdServer) pb.WatchServer { - return &watchServer{ - clusterID: int64(s.Cluster().ID()), - memberID: int64(s.ID()), - raftTimer: s, - watchable: s.Watchable(), - ag: s, - } -} - -var ( - // External test can read this with GetProgressReportInterval() - // and change this to a small value to finish fast with - // SetProgressReportInterval(). - progressReportInterval = 10 * time.Minute - progressReportIntervalMu sync.RWMutex -) - -func GetProgressReportInterval() time.Duration { - progressReportIntervalMu.RLock() - defer progressReportIntervalMu.RUnlock() - return progressReportInterval -} - -func SetProgressReportInterval(newTimeout time.Duration) { - progressReportIntervalMu.Lock() - defer progressReportIntervalMu.Unlock() - progressReportInterval = newTimeout -} - -const ( - // We send ctrl response inside the read loop. We do not want - // send to block read, but we still want ctrl response we sent to - // be serialized. Thus we use a buffered chan to solve the problem. - // A small buffer should be OK for most cases, since we expect the - // ctrl requests are infrequent. - ctrlStreamBufLen = 16 -) - -// serverWatchStream is an etcd server side stream. It receives requests -// from client side gRPC stream. It receives watch events from mvcc.WatchStream, -// and creates responses that forwarded to gRPC stream. -// It also forwards control message like watch created and canceled. -type serverWatchStream struct { - clusterID int64 - memberID int64 - raftTimer etcdserver.RaftTimer - - watchable mvcc.WatchableKV - - gRPCStream pb.Watch_WatchServer - watchStream mvcc.WatchStream - ctrlStream chan *pb.WatchResponse - - // mu protects progress, prevKV - mu sync.Mutex - // progress tracks the watchID that stream might need to send - // progress to. - // TODO: combine progress and prevKV into a single struct? - progress map[mvcc.WatchID]bool - prevKV map[mvcc.WatchID]bool - - // closec indicates the stream is closed. - closec chan struct{} - - // wg waits for the send loop to complete - wg sync.WaitGroup - - ag AuthGetter -} - -func (ws *watchServer) Watch(stream pb.Watch_WatchServer) (err error) { - sws := serverWatchStream{ - clusterID: ws.clusterID, - memberID: ws.memberID, - raftTimer: ws.raftTimer, - - watchable: ws.watchable, - - gRPCStream: stream, - watchStream: ws.watchable.NewWatchStream(), - // chan for sending control response like watcher created and canceled. - ctrlStream: make(chan *pb.WatchResponse, ctrlStreamBufLen), - progress: make(map[mvcc.WatchID]bool), - prevKV: make(map[mvcc.WatchID]bool), - closec: make(chan struct{}), - - ag: ws.ag, - } - - sws.wg.Add(1) - go func() { - sws.sendLoop() - sws.wg.Done() - }() - - errc := make(chan error, 1) - // Ideally recvLoop would also use sws.wg to signal its completion - // but when stream.Context().Done() is closed, the stream's recv - // may continue to block since it uses a different context, leading to - // deadlock when calling sws.close(). - go func() { - if rerr := sws.recvLoop(); rerr != nil { - if isClientCtxErr(stream.Context().Err(), rerr) { - plog.Debugf("failed to receive watch request from gRPC stream (%q)", rerr.Error()) - } else { - plog.Warningf("failed to receive watch request from gRPC stream (%q)", rerr.Error()) - } - errc <- rerr - } - }() - select { - case err = <-errc: - close(sws.ctrlStream) - case <-stream.Context().Done(): - err = stream.Context().Err() - // the only server-side cancellation is noleader for now. - if err == context.Canceled { - err = rpctypes.ErrGRPCNoLeader - } - } - sws.close() - return err -} - -func (sws *serverWatchStream) isWatchPermitted(wcr *pb.WatchCreateRequest) bool { - authInfo, err := sws.ag.AuthInfoFromCtx(sws.gRPCStream.Context()) - if err != nil { - return false - } - if authInfo == nil { - // if auth is enabled, IsRangePermitted() can cause an error - authInfo = &auth.AuthInfo{} - } - - return sws.ag.AuthStore().IsRangePermitted(authInfo, wcr.Key, wcr.RangeEnd) == nil -} - -func (sws *serverWatchStream) recvLoop() error { - for { - req, err := sws.gRPCStream.Recv() - if err == io.EOF { - return nil - } - if err != nil { - return err - } - - switch uv := req.RequestUnion.(type) { - case *pb.WatchRequest_CreateRequest: - if uv.CreateRequest == nil { - break - } - - creq := uv.CreateRequest - if len(creq.Key) == 0 { - // \x00 is the smallest key - creq.Key = []byte{0} - } - if len(creq.RangeEnd) == 0 { - // force nil since watchstream.Watch distinguishes - // between nil and []byte{} for single key / >= - creq.RangeEnd = nil - } - if len(creq.RangeEnd) == 1 && creq.RangeEnd[0] == 0 { - // support >= key queries - creq.RangeEnd = []byte{} - } - - if !sws.isWatchPermitted(creq) { - wr := &pb.WatchResponse{ - Header: sws.newResponseHeader(sws.watchStream.Rev()), - WatchId: -1, - Canceled: true, - Created: true, - CancelReason: rpctypes.ErrGRPCPermissionDenied.Error(), - } - - select { - case sws.ctrlStream <- wr: - case <-sws.closec: - } - return nil - } - - filters := FiltersFromRequest(creq) - - wsrev := sws.watchStream.Rev() - rev := creq.StartRevision - if rev == 0 { - rev = wsrev + 1 - } - id := sws.watchStream.Watch(creq.Key, creq.RangeEnd, rev, filters...) - if id != -1 { - sws.mu.Lock() - if creq.ProgressNotify { - sws.progress[id] = true - } - if creq.PrevKv { - sws.prevKV[id] = true - } - sws.mu.Unlock() - } - wr := &pb.WatchResponse{ - Header: sws.newResponseHeader(wsrev), - WatchId: int64(id), - Created: true, - Canceled: id == -1, - } - select { - case sws.ctrlStream <- wr: - case <-sws.closec: - return nil - } - case *pb.WatchRequest_CancelRequest: - if uv.CancelRequest != nil { - id := uv.CancelRequest.WatchId - err := sws.watchStream.Cancel(mvcc.WatchID(id)) - if err == nil { - sws.ctrlStream <- &pb.WatchResponse{ - Header: sws.newResponseHeader(sws.watchStream.Rev()), - WatchId: id, - Canceled: true, - } - sws.mu.Lock() - delete(sws.progress, mvcc.WatchID(id)) - delete(sws.prevKV, mvcc.WatchID(id)) - sws.mu.Unlock() - } - } - default: - // we probably should not shutdown the entire stream when - // receive an valid command. - // so just do nothing instead. - continue - } - } -} - -func (sws *serverWatchStream) sendLoop() { - // watch ids that are currently active - ids := make(map[mvcc.WatchID]struct{}) - // watch responses pending on a watch id creation message - pending := make(map[mvcc.WatchID][]*pb.WatchResponse) - - interval := GetProgressReportInterval() - progressTicker := time.NewTicker(interval) - - defer func() { - progressTicker.Stop() - // drain the chan to clean up pending events - for ws := range sws.watchStream.Chan() { - mvcc.ReportEventReceived(len(ws.Events)) - } - for _, wrs := range pending { - for _, ws := range wrs { - mvcc.ReportEventReceived(len(ws.Events)) - } - } - }() - - for { - select { - case wresp, ok := <-sws.watchStream.Chan(): - if !ok { - return - } - - // TODO: evs is []mvccpb.Event type - // either return []*mvccpb.Event from the mvcc package - // or define protocol buffer with []mvccpb.Event. - evs := wresp.Events - events := make([]*mvccpb.Event, len(evs)) - sws.mu.Lock() - needPrevKV := sws.prevKV[wresp.WatchID] - sws.mu.Unlock() - for i := range evs { - events[i] = &evs[i] - - if needPrevKV { - opt := mvcc.RangeOptions{Rev: evs[i].Kv.ModRevision - 1} - r, err := sws.watchable.Range(evs[i].Kv.Key, nil, opt) - if err == nil && len(r.KVs) != 0 { - events[i].PrevKv = &(r.KVs[0]) - } - } - } - - canceled := wresp.CompactRevision != 0 - wr := &pb.WatchResponse{ - Header: sws.newResponseHeader(wresp.Revision), - WatchId: int64(wresp.WatchID), - Events: events, - CompactRevision: wresp.CompactRevision, - Canceled: canceled, - } - - if _, hasId := ids[wresp.WatchID]; !hasId { - // buffer if id not yet announced - wrs := append(pending[wresp.WatchID], wr) - pending[wresp.WatchID] = wrs - continue - } - - mvcc.ReportEventReceived(len(evs)) - if err := sws.gRPCStream.Send(wr); err != nil { - if isClientCtxErr(sws.gRPCStream.Context().Err(), err) { - plog.Debugf("failed to send watch response to gRPC stream (%q)", err.Error()) - } else { - plog.Warningf("failed to send watch response to gRPC stream (%q)", err.Error()) - } - return - } - - sws.mu.Lock() - if len(evs) > 0 && sws.progress[wresp.WatchID] { - // elide next progress update if sent a key update - sws.progress[wresp.WatchID] = false - } - sws.mu.Unlock() - - case c, ok := <-sws.ctrlStream: - if !ok { - return - } - - if err := sws.gRPCStream.Send(c); err != nil { - if isClientCtxErr(sws.gRPCStream.Context().Err(), err) { - plog.Debugf("failed to send watch control response to gRPC stream (%q)", err.Error()) - } else { - plog.Warningf("failed to send watch control response to gRPC stream (%q)", err.Error()) - } - return - } - - // track id creation - wid := mvcc.WatchID(c.WatchId) - if c.Canceled { - delete(ids, wid) - continue - } - if c.Created { - // flush buffered events - ids[wid] = struct{}{} - for _, v := range pending[wid] { - mvcc.ReportEventReceived(len(v.Events)) - if err := sws.gRPCStream.Send(v); err != nil { - if isClientCtxErr(sws.gRPCStream.Context().Err(), err) { - plog.Debugf("failed to send pending watch response to gRPC stream (%q)", err.Error()) - } else { - plog.Warningf("failed to send pending watch response to gRPC stream (%q)", err.Error()) - } - return - } - } - delete(pending, wid) - } - case <-progressTicker.C: - sws.mu.Lock() - for id, ok := range sws.progress { - if ok { - sws.watchStream.RequestProgress(id) - } - sws.progress[id] = true - } - sws.mu.Unlock() - case <-sws.closec: - return - } - } -} - -func (sws *serverWatchStream) close() { - sws.watchStream.Close() - close(sws.closec) - sws.wg.Wait() -} - -func (sws *serverWatchStream) newResponseHeader(rev int64) *pb.ResponseHeader { - return &pb.ResponseHeader{ - ClusterId: uint64(sws.clusterID), - MemberId: uint64(sws.memberID), - Revision: rev, - RaftTerm: sws.raftTimer.Term(), - } -} - -func filterNoDelete(e mvccpb.Event) bool { - return e.Type == mvccpb.DELETE -} - -func filterNoPut(e mvccpb.Event) bool { - return e.Type == mvccpb.PUT -} - -func FiltersFromRequest(creq *pb.WatchCreateRequest) []mvcc.FilterFunc { - filters := make([]mvcc.FilterFunc, 0, len(creq.Filters)) - for _, ft := range creq.Filters { - switch ft { - case pb.WatchCreateRequest_NOPUT: - filters = append(filters, filterNoPut) - case pb.WatchCreateRequest_NODELETE: - filters = append(filters, filterNoDelete) - default: - } - } - return filters -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/apply.go b/vendor/go.etcd.io/etcd/etcdserver/apply.go deleted file mode 100644 index 93e78e390c80..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/apply.go +++ /dev/null @@ -1,972 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "bytes" - "context" - "sort" - "time" - - "github.com/coreos/etcd/auth" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/mvcc/mvccpb" - "github.com/coreos/etcd/pkg/types" - - "github.com/gogo/protobuf/proto" -) - -const ( - warnApplyDuration = 100 * time.Millisecond -) - -type applyResult struct { - resp proto.Message - err error - // physc signals the physical effect of the request has completed in addition - // to being logically reflected by the node. Currently only used for - // Compaction requests. - physc <-chan struct{} -} - -// applierV3 is the interface for processing V3 raft messages -type applierV3 interface { - Apply(r *pb.InternalRaftRequest) *applyResult - - Put(txn mvcc.TxnWrite, p *pb.PutRequest) (*pb.PutResponse, error) - Range(txn mvcc.TxnRead, r *pb.RangeRequest) (*pb.RangeResponse, error) - DeleteRange(txn mvcc.TxnWrite, dr *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) - Txn(rt *pb.TxnRequest) (*pb.TxnResponse, error) - Compaction(compaction *pb.CompactionRequest) (*pb.CompactionResponse, <-chan struct{}, error) - - LeaseGrant(lc *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) - LeaseRevoke(lc *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) - - Alarm(*pb.AlarmRequest) (*pb.AlarmResponse, error) - - Authenticate(r *pb.InternalAuthenticateRequest) (*pb.AuthenticateResponse, error) - - AuthEnable() (*pb.AuthEnableResponse, error) - AuthDisable() (*pb.AuthDisableResponse, error) - - UserAdd(ua *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) - UserDelete(ua *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) - UserChangePassword(ua *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) - UserGrantRole(ua *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) - UserGet(ua *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) - UserRevokeRole(ua *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) - RoleAdd(ua *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) - RoleGrantPermission(ua *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) - RoleGet(ua *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) - RoleRevokePermission(ua *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) - RoleDelete(ua *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) - UserList(ua *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) - RoleList(ua *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) -} - -type checkReqFunc func(mvcc.ReadView, *pb.RequestOp) error - -type applierV3backend struct { - s *EtcdServer - - checkPut checkReqFunc - checkRange checkReqFunc -} - -func (s *EtcdServer) newApplierV3Backend() applierV3 { - base := &applierV3backend{s: s} - base.checkPut = func(rv mvcc.ReadView, req *pb.RequestOp) error { - return base.checkRequestPut(rv, req) - } - base.checkRange = func(rv mvcc.ReadView, req *pb.RequestOp) error { - return base.checkRequestRange(rv, req) - } - return base -} - -func (s *EtcdServer) newApplierV3() applierV3 { - return newAuthApplierV3( - s.AuthStore(), - newQuotaApplierV3(s, s.newApplierV3Backend()), - s.lessor, - ) -} - -func (a *applierV3backend) Apply(r *pb.InternalRaftRequest) *applyResult { - ar := &applyResult{} - defer func(start time.Time) { - warnOfExpensiveRequest(start, &pb.InternalRaftStringer{Request: r}, ar.resp, ar.err) - }(time.Now()) - - // call into a.s.applyV3.F instead of a.F so upper appliers can check individual calls - switch { - case r.Range != nil: - ar.resp, ar.err = a.s.applyV3.Range(nil, r.Range) - case r.Put != nil: - ar.resp, ar.err = a.s.applyV3.Put(nil, r.Put) - case r.DeleteRange != nil: - ar.resp, ar.err = a.s.applyV3.DeleteRange(nil, r.DeleteRange) - case r.Txn != nil: - ar.resp, ar.err = a.s.applyV3.Txn(r.Txn) - case r.Compaction != nil: - ar.resp, ar.physc, ar.err = a.s.applyV3.Compaction(r.Compaction) - case r.LeaseGrant != nil: - ar.resp, ar.err = a.s.applyV3.LeaseGrant(r.LeaseGrant) - case r.LeaseRevoke != nil: - ar.resp, ar.err = a.s.applyV3.LeaseRevoke(r.LeaseRevoke) - case r.Alarm != nil: - ar.resp, ar.err = a.s.applyV3.Alarm(r.Alarm) - case r.Authenticate != nil: - ar.resp, ar.err = a.s.applyV3.Authenticate(r.Authenticate) - case r.AuthEnable != nil: - ar.resp, ar.err = a.s.applyV3.AuthEnable() - case r.AuthDisable != nil: - ar.resp, ar.err = a.s.applyV3.AuthDisable() - case r.AuthUserAdd != nil: - ar.resp, ar.err = a.s.applyV3.UserAdd(r.AuthUserAdd) - case r.AuthUserDelete != nil: - ar.resp, ar.err = a.s.applyV3.UserDelete(r.AuthUserDelete) - case r.AuthUserChangePassword != nil: - ar.resp, ar.err = a.s.applyV3.UserChangePassword(r.AuthUserChangePassword) - case r.AuthUserGrantRole != nil: - ar.resp, ar.err = a.s.applyV3.UserGrantRole(r.AuthUserGrantRole) - case r.AuthUserGet != nil: - ar.resp, ar.err = a.s.applyV3.UserGet(r.AuthUserGet) - case r.AuthUserRevokeRole != nil: - ar.resp, ar.err = a.s.applyV3.UserRevokeRole(r.AuthUserRevokeRole) - case r.AuthRoleAdd != nil: - ar.resp, ar.err = a.s.applyV3.RoleAdd(r.AuthRoleAdd) - case r.AuthRoleGrantPermission != nil: - ar.resp, ar.err = a.s.applyV3.RoleGrantPermission(r.AuthRoleGrantPermission) - case r.AuthRoleGet != nil: - ar.resp, ar.err = a.s.applyV3.RoleGet(r.AuthRoleGet) - case r.AuthRoleRevokePermission != nil: - ar.resp, ar.err = a.s.applyV3.RoleRevokePermission(r.AuthRoleRevokePermission) - case r.AuthRoleDelete != nil: - ar.resp, ar.err = a.s.applyV3.RoleDelete(r.AuthRoleDelete) - case r.AuthUserList != nil: - ar.resp, ar.err = a.s.applyV3.UserList(r.AuthUserList) - case r.AuthRoleList != nil: - ar.resp, ar.err = a.s.applyV3.RoleList(r.AuthRoleList) - default: - panic("not implemented") - } - return ar -} - -func (a *applierV3backend) Put(txn mvcc.TxnWrite, p *pb.PutRequest) (resp *pb.PutResponse, err error) { - resp = &pb.PutResponse{} - resp.Header = &pb.ResponseHeader{} - - val, leaseID := p.Value, lease.LeaseID(p.Lease) - if txn == nil { - if leaseID != lease.NoLease { - if l := a.s.lessor.Lookup(leaseID); l == nil { - return nil, lease.ErrLeaseNotFound - } - } - txn = a.s.KV().Write() - defer txn.End() - } - - var rr *mvcc.RangeResult - if p.IgnoreValue || p.IgnoreLease || p.PrevKv { - rr, err = txn.Range(p.Key, nil, mvcc.RangeOptions{}) - if err != nil { - return nil, err - } - } - if p.IgnoreValue || p.IgnoreLease { - if rr == nil || len(rr.KVs) == 0 { - // ignore_{lease,value} flag expects previous key-value pair - return nil, ErrKeyNotFound - } - } - if p.IgnoreValue { - val = rr.KVs[0].Value - } - if p.IgnoreLease { - leaseID = lease.LeaseID(rr.KVs[0].Lease) - } - if p.PrevKv { - if rr != nil && len(rr.KVs) != 0 { - resp.PrevKv = &rr.KVs[0] - } - } - - resp.Header.Revision = txn.Put(p.Key, val, leaseID) - return resp, nil -} - -func (a *applierV3backend) DeleteRange(txn mvcc.TxnWrite, dr *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) { - resp := &pb.DeleteRangeResponse{} - resp.Header = &pb.ResponseHeader{} - end := mkGteRange(dr.RangeEnd) - - if txn == nil { - txn = a.s.kv.Write() - defer txn.End() - } - - if dr.PrevKv { - rr, err := txn.Range(dr.Key, end, mvcc.RangeOptions{}) - if err != nil { - return nil, err - } - if rr != nil { - resp.PrevKvs = make([]*mvccpb.KeyValue, len(rr.KVs)) - for i := range rr.KVs { - resp.PrevKvs[i] = &rr.KVs[i] - } - } - } - - resp.Deleted, resp.Header.Revision = txn.DeleteRange(dr.Key, end) - return resp, nil -} - -func (a *applierV3backend) Range(txn mvcc.TxnRead, r *pb.RangeRequest) (*pb.RangeResponse, error) { - resp := &pb.RangeResponse{} - resp.Header = &pb.ResponseHeader{} - - if txn == nil { - txn = a.s.kv.Read() - defer txn.End() - } - - limit := r.Limit - if r.SortOrder != pb.RangeRequest_NONE || - r.MinModRevision != 0 || r.MaxModRevision != 0 || - r.MinCreateRevision != 0 || r.MaxCreateRevision != 0 { - // fetch everything; sort and truncate afterwards - limit = 0 - } - if limit > 0 { - // fetch one extra for 'more' flag - limit = limit + 1 - } - - ro := mvcc.RangeOptions{ - Limit: limit, - Rev: r.Revision, - Count: r.CountOnly, - } - - rr, err := txn.Range(r.Key, mkGteRange(r.RangeEnd), ro) - if err != nil { - return nil, err - } - - if r.MaxModRevision != 0 { - f := func(kv *mvccpb.KeyValue) bool { return kv.ModRevision > r.MaxModRevision } - pruneKVs(rr, f) - } - if r.MinModRevision != 0 { - f := func(kv *mvccpb.KeyValue) bool { return kv.ModRevision < r.MinModRevision } - pruneKVs(rr, f) - } - if r.MaxCreateRevision != 0 { - f := func(kv *mvccpb.KeyValue) bool { return kv.CreateRevision > r.MaxCreateRevision } - pruneKVs(rr, f) - } - if r.MinCreateRevision != 0 { - f := func(kv *mvccpb.KeyValue) bool { return kv.CreateRevision < r.MinCreateRevision } - pruneKVs(rr, f) - } - - sortOrder := r.SortOrder - if r.SortTarget != pb.RangeRequest_KEY && sortOrder == pb.RangeRequest_NONE { - // Since current mvcc.Range implementation returns results - // sorted by keys in lexiographically ascending order, - // sort ASCEND by default only when target is not 'KEY' - sortOrder = pb.RangeRequest_ASCEND - } - if sortOrder != pb.RangeRequest_NONE { - var sorter sort.Interface - switch { - case r.SortTarget == pb.RangeRequest_KEY: - sorter = &kvSortByKey{&kvSort{rr.KVs}} - case r.SortTarget == pb.RangeRequest_VERSION: - sorter = &kvSortByVersion{&kvSort{rr.KVs}} - case r.SortTarget == pb.RangeRequest_CREATE: - sorter = &kvSortByCreate{&kvSort{rr.KVs}} - case r.SortTarget == pb.RangeRequest_MOD: - sorter = &kvSortByMod{&kvSort{rr.KVs}} - case r.SortTarget == pb.RangeRequest_VALUE: - sorter = &kvSortByValue{&kvSort{rr.KVs}} - } - switch { - case sortOrder == pb.RangeRequest_ASCEND: - sort.Sort(sorter) - case sortOrder == pb.RangeRequest_DESCEND: - sort.Sort(sort.Reverse(sorter)) - } - } - - if r.Limit > 0 && len(rr.KVs) > int(r.Limit) { - rr.KVs = rr.KVs[:r.Limit] - resp.More = true - } - - resp.Header.Revision = rr.Rev - resp.Count = int64(rr.Count) - resp.Kvs = make([]*mvccpb.KeyValue, len(rr.KVs)) - for i := range rr.KVs { - if r.KeysOnly { - rr.KVs[i].Value = nil - } - resp.Kvs[i] = &rr.KVs[i] - } - return resp, nil -} - -func (a *applierV3backend) Txn(rt *pb.TxnRequest) (*pb.TxnResponse, error) { - isWrite := !isTxnReadonly(rt) - txn := mvcc.NewReadOnlyTxnWrite(a.s.KV().Read()) - - txnPath := compareToPath(txn, rt) - if isWrite { - if _, err := checkRequests(txn, rt, txnPath, a.checkPut); err != nil { - txn.End() - return nil, err - } - } - if _, err := checkRequests(txn, rt, txnPath, a.checkRange); err != nil { - txn.End() - return nil, err - } - - txnResp, _ := newTxnResp(rt, txnPath) - - // When executing mutable txn ops, etcd must hold the txn lock so - // readers do not see any intermediate results. Since writes are - // serialized on the raft loop, the revision in the read view will - // be the revision of the write txn. - if isWrite { - txn.End() - txn = a.s.KV().Write() - } - a.applyTxn(txn, rt, txnPath, txnResp) - rev := txn.Rev() - if len(txn.Changes()) != 0 { - rev++ - } - txn.End() - - txnResp.Header.Revision = rev - return txnResp, nil -} - -// newTxnResp allocates a txn response for a txn request given a path. -func newTxnResp(rt *pb.TxnRequest, txnPath []bool) (txnResp *pb.TxnResponse, txnCount int) { - reqs := rt.Success - if !txnPath[0] { - reqs = rt.Failure - } - resps := make([]*pb.ResponseOp, len(reqs)) - txnResp = &pb.TxnResponse{ - Responses: resps, - Succeeded: txnPath[0], - Header: &pb.ResponseHeader{}, - } - for i, req := range reqs { - switch tv := req.Request.(type) { - case *pb.RequestOp_RequestRange: - resps[i] = &pb.ResponseOp{Response: &pb.ResponseOp_ResponseRange{}} - case *pb.RequestOp_RequestPut: - resps[i] = &pb.ResponseOp{Response: &pb.ResponseOp_ResponsePut{}} - case *pb.RequestOp_RequestDeleteRange: - resps[i] = &pb.ResponseOp{Response: &pb.ResponseOp_ResponseDeleteRange{}} - case *pb.RequestOp_RequestTxn: - resp, txns := newTxnResp(tv.RequestTxn, txnPath[1:]) - resps[i] = &pb.ResponseOp{Response: &pb.ResponseOp_ResponseTxn{ResponseTxn: resp}} - txnPath = txnPath[1+txns:] - txnCount += txns + 1 - default: - } - } - return txnResp, txnCount -} - -func compareToPath(rv mvcc.ReadView, rt *pb.TxnRequest) []bool { - txnPath := make([]bool, 1) - ops := rt.Success - if txnPath[0] = applyCompares(rv, rt.Compare); !txnPath[0] { - ops = rt.Failure - } - for _, op := range ops { - tv, ok := op.Request.(*pb.RequestOp_RequestTxn) - if !ok || tv.RequestTxn == nil { - continue - } - txnPath = append(txnPath, compareToPath(rv, tv.RequestTxn)...) - } - return txnPath -} - -func applyCompares(rv mvcc.ReadView, cmps []*pb.Compare) bool { - for _, c := range cmps { - if !applyCompare(rv, c) { - return false - } - } - return true -} - -// applyCompare applies the compare request. -// If the comparison succeeds, it returns true. Otherwise, returns false. -func applyCompare(rv mvcc.ReadView, c *pb.Compare) bool { - // TODO: possible optimizations - // * chunk reads for large ranges to conserve memory - // * rewrite rules for common patterns: - // ex. "[a, b) createrev > 0" => "limit 1 /\ kvs > 0" - // * caching - rr, err := rv.Range(c.Key, mkGteRange(c.RangeEnd), mvcc.RangeOptions{}) - if err != nil { - return false - } - if len(rr.KVs) == 0 { - if c.Target == pb.Compare_VALUE { - // Always fail if comparing a value on a key/keys that doesn't exist; - // nil == empty string in grpc; no way to represent missing value - return false - } - return compareKV(c, mvccpb.KeyValue{}) - } - for _, kv := range rr.KVs { - if !compareKV(c, kv) { - return false - } - } - return true -} - -func compareKV(c *pb.Compare, ckv mvccpb.KeyValue) bool { - var result int - rev := int64(0) - switch c.Target { - case pb.Compare_VALUE: - v := []byte{} - if tv, _ := c.TargetUnion.(*pb.Compare_Value); tv != nil { - v = tv.Value - } - result = bytes.Compare(ckv.Value, v) - case pb.Compare_CREATE: - if tv, _ := c.TargetUnion.(*pb.Compare_CreateRevision); tv != nil { - rev = tv.CreateRevision - } - result = compareInt64(ckv.CreateRevision, rev) - case pb.Compare_MOD: - if tv, _ := c.TargetUnion.(*pb.Compare_ModRevision); tv != nil { - rev = tv.ModRevision - } - result = compareInt64(ckv.ModRevision, rev) - case pb.Compare_VERSION: - if tv, _ := c.TargetUnion.(*pb.Compare_Version); tv != nil { - rev = tv.Version - } - result = compareInt64(ckv.Version, rev) - case pb.Compare_LEASE: - if tv, _ := c.TargetUnion.(*pb.Compare_Lease); tv != nil { - rev = tv.Lease - } - result = compareInt64(ckv.Lease, rev) - } - switch c.Result { - case pb.Compare_EQUAL: - return result == 0 - case pb.Compare_NOT_EQUAL: - return result != 0 - case pb.Compare_GREATER: - return result > 0 - case pb.Compare_LESS: - return result < 0 - } - return true -} - -func (a *applierV3backend) applyTxn(txn mvcc.TxnWrite, rt *pb.TxnRequest, txnPath []bool, tresp *pb.TxnResponse) (txns int) { - reqs := rt.Success - if !txnPath[0] { - reqs = rt.Failure - } - for i, req := range reqs { - respi := tresp.Responses[i].Response - switch tv := req.Request.(type) { - case *pb.RequestOp_RequestRange: - resp, err := a.Range(txn, tv.RequestRange) - if err != nil { - plog.Panicf("unexpected error during txn: %v", err) - } - respi.(*pb.ResponseOp_ResponseRange).ResponseRange = resp - case *pb.RequestOp_RequestPut: - resp, err := a.Put(txn, tv.RequestPut) - if err != nil { - plog.Panicf("unexpected error during txn: %v", err) - } - respi.(*pb.ResponseOp_ResponsePut).ResponsePut = resp - case *pb.RequestOp_RequestDeleteRange: - resp, err := a.DeleteRange(txn, tv.RequestDeleteRange) - if err != nil { - plog.Panicf("unexpected error during txn: %v", err) - } - respi.(*pb.ResponseOp_ResponseDeleteRange).ResponseDeleteRange = resp - case *pb.RequestOp_RequestTxn: - resp := respi.(*pb.ResponseOp_ResponseTxn).ResponseTxn - applyTxns := a.applyTxn(txn, tv.RequestTxn, txnPath[1:], resp) - txns += applyTxns + 1 - txnPath = txnPath[applyTxns+1:] - default: - // empty union - } - } - return txns -} - -func (a *applierV3backend) Compaction(compaction *pb.CompactionRequest) (*pb.CompactionResponse, <-chan struct{}, error) { - resp := &pb.CompactionResponse{} - resp.Header = &pb.ResponseHeader{} - ch, err := a.s.KV().Compact(compaction.Revision) - if err != nil { - return nil, ch, err - } - // get the current revision. which key to get is not important. - rr, _ := a.s.KV().Range([]byte("compaction"), nil, mvcc.RangeOptions{}) - resp.Header.Revision = rr.Rev - return resp, ch, err -} - -func (a *applierV3backend) LeaseGrant(lc *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - l, err := a.s.lessor.Grant(lease.LeaseID(lc.ID), lc.TTL) - resp := &pb.LeaseGrantResponse{} - if err == nil { - resp.ID = int64(l.ID) - resp.TTL = l.TTL() - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) LeaseRevoke(lc *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) { - err := a.s.lessor.Revoke(lease.LeaseID(lc.ID)) - return &pb.LeaseRevokeResponse{Header: newHeader(a.s)}, err -} - -func (a *applierV3backend) Alarm(ar *pb.AlarmRequest) (*pb.AlarmResponse, error) { - resp := &pb.AlarmResponse{} - oldCount := len(a.s.alarmStore.Get(ar.Alarm)) - - switch ar.Action { - case pb.AlarmRequest_GET: - resp.Alarms = a.s.alarmStore.Get(ar.Alarm) - case pb.AlarmRequest_ACTIVATE: - m := a.s.alarmStore.Activate(types.ID(ar.MemberID), ar.Alarm) - if m == nil { - break - } - resp.Alarms = append(resp.Alarms, m) - activated := oldCount == 0 && len(a.s.alarmStore.Get(m.Alarm)) == 1 - if !activated { - break - } - - plog.Warningf("alarm %v raised by peer %s", m.Alarm, types.ID(m.MemberID)) - switch m.Alarm { - case pb.AlarmType_CORRUPT: - a.s.applyV3 = newApplierV3Corrupt(a) - case pb.AlarmType_NOSPACE: - a.s.applyV3 = newApplierV3Capped(a) - default: - plog.Errorf("unimplemented alarm activation (%+v)", m) - } - case pb.AlarmRequest_DEACTIVATE: - m := a.s.alarmStore.Deactivate(types.ID(ar.MemberID), ar.Alarm) - if m == nil { - break - } - resp.Alarms = append(resp.Alarms, m) - deactivated := oldCount > 0 && len(a.s.alarmStore.Get(ar.Alarm)) == 0 - if !deactivated { - break - } - - switch m.Alarm { - case pb.AlarmType_NOSPACE, pb.AlarmType_CORRUPT: - // TODO: check kv hash before deactivating CORRUPT? - plog.Infof("alarm disarmed %+v", ar) - a.s.applyV3 = a.s.newApplierV3() - default: - plog.Errorf("unimplemented alarm deactivation (%+v)", m) - } - default: - return nil, nil - } - return resp, nil -} - -type applierV3Capped struct { - applierV3 - q backendQuota -} - -// newApplierV3Capped creates an applyV3 that will reject Puts and transactions -// with Puts so that the number of keys in the store is capped. -func newApplierV3Capped(base applierV3) applierV3 { return &applierV3Capped{applierV3: base} } - -func (a *applierV3Capped) Put(txn mvcc.TxnWrite, p *pb.PutRequest) (*pb.PutResponse, error) { - return nil, ErrNoSpace -} - -func (a *applierV3Capped) Txn(r *pb.TxnRequest) (*pb.TxnResponse, error) { - if a.q.Cost(r) > 0 { - return nil, ErrNoSpace - } - return a.applierV3.Txn(r) -} - -func (a *applierV3Capped) LeaseGrant(lc *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - return nil, ErrNoSpace -} - -func (a *applierV3backend) AuthEnable() (*pb.AuthEnableResponse, error) { - err := a.s.AuthStore().AuthEnable() - if err != nil { - return nil, err - } - return &pb.AuthEnableResponse{Header: newHeader(a.s)}, nil -} - -func (a *applierV3backend) AuthDisable() (*pb.AuthDisableResponse, error) { - a.s.AuthStore().AuthDisable() - return &pb.AuthDisableResponse{Header: newHeader(a.s)}, nil -} - -func (a *applierV3backend) Authenticate(r *pb.InternalAuthenticateRequest) (*pb.AuthenticateResponse, error) { - ctx := context.WithValue(context.WithValue(a.s.ctx, auth.AuthenticateParamIndex{}, a.s.consistIndex.ConsistentIndex()), auth.AuthenticateParamSimpleTokenPrefix{}, r.SimpleToken) - resp, err := a.s.AuthStore().Authenticate(ctx, r.Name, r.Password) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserAdd(r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) { - resp, err := a.s.AuthStore().UserAdd(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserDelete(r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) { - resp, err := a.s.AuthStore().UserDelete(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserChangePassword(r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) { - resp, err := a.s.AuthStore().UserChangePassword(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserGrantRole(r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) { - resp, err := a.s.AuthStore().UserGrantRole(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserGet(r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) { - resp, err := a.s.AuthStore().UserGet(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserRevokeRole(r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) { - resp, err := a.s.AuthStore().UserRevokeRole(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) RoleAdd(r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) { - resp, err := a.s.AuthStore().RoleAdd(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) RoleGrantPermission(r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) { - resp, err := a.s.AuthStore().RoleGrantPermission(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) RoleGet(r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) { - resp, err := a.s.AuthStore().RoleGet(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) RoleRevokePermission(r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) { - resp, err := a.s.AuthStore().RoleRevokePermission(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) RoleDelete(r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) { - resp, err := a.s.AuthStore().RoleDelete(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserList(r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) { - resp, err := a.s.AuthStore().UserList(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) RoleList(r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) { - resp, err := a.s.AuthStore().RoleList(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -type quotaApplierV3 struct { - applierV3 - q Quota -} - -func newQuotaApplierV3(s *EtcdServer, app applierV3) applierV3 { - return "aApplierV3{app, NewBackendQuota(s)} -} - -func (a *quotaApplierV3) Put(txn mvcc.TxnWrite, p *pb.PutRequest) (*pb.PutResponse, error) { - ok := a.q.Available(p) - resp, err := a.applierV3.Put(txn, p) - if err == nil && !ok { - err = ErrNoSpace - } - return resp, err -} - -func (a *quotaApplierV3) Txn(rt *pb.TxnRequest) (*pb.TxnResponse, error) { - ok := a.q.Available(rt) - resp, err := a.applierV3.Txn(rt) - if err == nil && !ok { - err = ErrNoSpace - } - return resp, err -} - -func (a *quotaApplierV3) LeaseGrant(lc *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - ok := a.q.Available(lc) - resp, err := a.applierV3.LeaseGrant(lc) - if err == nil && !ok { - err = ErrNoSpace - } - return resp, err -} - -type kvSort struct{ kvs []mvccpb.KeyValue } - -func (s *kvSort) Swap(i, j int) { - t := s.kvs[i] - s.kvs[i] = s.kvs[j] - s.kvs[j] = t -} -func (s *kvSort) Len() int { return len(s.kvs) } - -type kvSortByKey struct{ *kvSort } - -func (s *kvSortByKey) Less(i, j int) bool { - return bytes.Compare(s.kvs[i].Key, s.kvs[j].Key) < 0 -} - -type kvSortByVersion struct{ *kvSort } - -func (s *kvSortByVersion) Less(i, j int) bool { - return (s.kvs[i].Version - s.kvs[j].Version) < 0 -} - -type kvSortByCreate struct{ *kvSort } - -func (s *kvSortByCreate) Less(i, j int) bool { - return (s.kvs[i].CreateRevision - s.kvs[j].CreateRevision) < 0 -} - -type kvSortByMod struct{ *kvSort } - -func (s *kvSortByMod) Less(i, j int) bool { - return (s.kvs[i].ModRevision - s.kvs[j].ModRevision) < 0 -} - -type kvSortByValue struct{ *kvSort } - -func (s *kvSortByValue) Less(i, j int) bool { - return bytes.Compare(s.kvs[i].Value, s.kvs[j].Value) < 0 -} - -func checkRequests(rv mvcc.ReadView, rt *pb.TxnRequest, txnPath []bool, f checkReqFunc) (int, error) { - txnCount := 0 - reqs := rt.Success - if !txnPath[0] { - reqs = rt.Failure - } - for _, req := range reqs { - if tv, ok := req.Request.(*pb.RequestOp_RequestTxn); ok && tv.RequestTxn != nil { - txns, err := checkRequests(rv, tv.RequestTxn, txnPath[1:], f) - if err != nil { - return 0, err - } - txnCount += txns + 1 - txnPath = txnPath[txns+1:] - continue - } - if err := f(rv, req); err != nil { - return 0, err - } - } - return txnCount, nil -} - -func (a *applierV3backend) checkRequestPut(rv mvcc.ReadView, reqOp *pb.RequestOp) error { - tv, ok := reqOp.Request.(*pb.RequestOp_RequestPut) - if !ok || tv.RequestPut == nil { - return nil - } - req := tv.RequestPut - if req.IgnoreValue || req.IgnoreLease { - // expects previous key-value, error if not exist - rr, err := rv.Range(req.Key, nil, mvcc.RangeOptions{}) - if err != nil { - return err - } - if rr == nil || len(rr.KVs) == 0 { - return ErrKeyNotFound - } - } - if lease.LeaseID(req.Lease) != lease.NoLease { - if l := a.s.lessor.Lookup(lease.LeaseID(req.Lease)); l == nil { - return lease.ErrLeaseNotFound - } - } - return nil -} - -func (a *applierV3backend) checkRequestRange(rv mvcc.ReadView, reqOp *pb.RequestOp) error { - tv, ok := reqOp.Request.(*pb.RequestOp_RequestRange) - if !ok || tv.RequestRange == nil { - return nil - } - req := tv.RequestRange - switch { - case req.Revision == 0: - return nil - case req.Revision > rv.Rev(): - return mvcc.ErrFutureRev - case req.Revision < rv.FirstRev(): - return mvcc.ErrCompacted - } - return nil -} - -func compareInt64(a, b int64) int { - switch { - case a < b: - return -1 - case a > b: - return 1 - default: - return 0 - } -} - -// mkGteRange determines if the range end is a >= range. This works around grpc -// sending empty byte strings as nil; >= is encoded in the range end as '\0'. -// If it is a GTE range, then []byte{} is returned to indicate the empty byte -// string (vs nil being no byte string). -func mkGteRange(rangeEnd []byte) []byte { - if len(rangeEnd) == 1 && rangeEnd[0] == 0 { - return []byte{} - } - return rangeEnd -} - -func noSideEffect(r *pb.InternalRaftRequest) bool { - return r.Range != nil || r.AuthUserGet != nil || r.AuthRoleGet != nil -} - -func removeNeedlessRangeReqs(txn *pb.TxnRequest) { - f := func(ops []*pb.RequestOp) []*pb.RequestOp { - j := 0 - for i := 0; i < len(ops); i++ { - if _, ok := ops[i].Request.(*pb.RequestOp_RequestRange); ok { - continue - } - ops[j] = ops[i] - j++ - } - - return ops[:j] - } - - txn.Success = f(txn.Success) - txn.Failure = f(txn.Failure) -} - -func pruneKVs(rr *mvcc.RangeResult, isPrunable func(*mvccpb.KeyValue) bool) { - j := 0 - for i := range rr.KVs { - rr.KVs[j] = rr.KVs[i] - if !isPrunable(&rr.KVs[i]) { - j++ - } - } - rr.KVs = rr.KVs[:j] -} - -func newHeader(s *EtcdServer) *pb.ResponseHeader { - return &pb.ResponseHeader{ - ClusterId: uint64(s.Cluster().ID()), - MemberId: uint64(s.ID()), - Revision: s.KV().Rev(), - RaftTerm: s.Term(), - } -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/apply_auth.go b/vendor/go.etcd.io/etcd/etcdserver/apply_auth.go deleted file mode 100644 index ec9391435dab..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/apply_auth.go +++ /dev/null @@ -1,245 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "sync" - - "github.com/coreos/etcd/auth" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/mvcc" -) - -type authApplierV3 struct { - applierV3 - as auth.AuthStore - lessor lease.Lessor - - // mu serializes Apply so that user isn't corrupted and so that - // serialized requests don't leak data from TOCTOU errors - mu sync.Mutex - - authInfo auth.AuthInfo -} - -func newAuthApplierV3(as auth.AuthStore, base applierV3, lessor lease.Lessor) *authApplierV3 { - return &authApplierV3{applierV3: base, as: as, lessor: lessor} -} - -func (aa *authApplierV3) Apply(r *pb.InternalRaftRequest) *applyResult { - aa.mu.Lock() - defer aa.mu.Unlock() - if r.Header != nil { - // backward-compatible with pre-3.0 releases when internalRaftRequest - // does not have header field - aa.authInfo.Username = r.Header.Username - aa.authInfo.Revision = r.Header.AuthRevision - } - if needAdminPermission(r) { - if err := aa.as.IsAdminPermitted(&aa.authInfo); err != nil { - aa.authInfo.Username = "" - aa.authInfo.Revision = 0 - return &applyResult{err: err} - } - } - ret := aa.applierV3.Apply(r) - aa.authInfo.Username = "" - aa.authInfo.Revision = 0 - return ret -} - -func (aa *authApplierV3) Put(txn mvcc.TxnWrite, r *pb.PutRequest) (*pb.PutResponse, error) { - if err := aa.as.IsPutPermitted(&aa.authInfo, r.Key); err != nil { - return nil, err - } - - if err := aa.checkLeasePuts(lease.LeaseID(r.Lease)); err != nil { - // The specified lease is already attached with a key that cannot - // be written by this user. It means the user cannot revoke the - // lease so attaching the lease to the newly written key should - // be forbidden. - return nil, err - } - - if r.PrevKv { - err := aa.as.IsRangePermitted(&aa.authInfo, r.Key, nil) - if err != nil { - return nil, err - } - } - return aa.applierV3.Put(txn, r) -} - -func (aa *authApplierV3) Range(txn mvcc.TxnRead, r *pb.RangeRequest) (*pb.RangeResponse, error) { - if err := aa.as.IsRangePermitted(&aa.authInfo, r.Key, r.RangeEnd); err != nil { - return nil, err - } - return aa.applierV3.Range(txn, r) -} - -func (aa *authApplierV3) DeleteRange(txn mvcc.TxnWrite, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) { - if err := aa.as.IsDeleteRangePermitted(&aa.authInfo, r.Key, r.RangeEnd); err != nil { - return nil, err - } - if r.PrevKv { - err := aa.as.IsRangePermitted(&aa.authInfo, r.Key, r.RangeEnd) - if err != nil { - return nil, err - } - } - - return aa.applierV3.DeleteRange(txn, r) -} - -func checkTxnReqsPermission(as auth.AuthStore, ai *auth.AuthInfo, reqs []*pb.RequestOp) error { - for _, requ := range reqs { - switch tv := requ.Request.(type) { - case *pb.RequestOp_RequestRange: - if tv.RequestRange == nil { - continue - } - - if err := as.IsRangePermitted(ai, tv.RequestRange.Key, tv.RequestRange.RangeEnd); err != nil { - return err - } - - case *pb.RequestOp_RequestPut: - if tv.RequestPut == nil { - continue - } - - if err := as.IsPutPermitted(ai, tv.RequestPut.Key); err != nil { - return err - } - - case *pb.RequestOp_RequestDeleteRange: - if tv.RequestDeleteRange == nil { - continue - } - - if tv.RequestDeleteRange.PrevKv { - err := as.IsRangePermitted(ai, tv.RequestDeleteRange.Key, tv.RequestDeleteRange.RangeEnd) - if err != nil { - return err - } - } - - err := as.IsDeleteRangePermitted(ai, tv.RequestDeleteRange.Key, tv.RequestDeleteRange.RangeEnd) - if err != nil { - return err - } - } - } - - return nil -} - -func checkTxnAuth(as auth.AuthStore, ai *auth.AuthInfo, rt *pb.TxnRequest) error { - for _, c := range rt.Compare { - if err := as.IsRangePermitted(ai, c.Key, c.RangeEnd); err != nil { - return err - } - } - if err := checkTxnReqsPermission(as, ai, rt.Success); err != nil { - return err - } - if err := checkTxnReqsPermission(as, ai, rt.Failure); err != nil { - return err - } - return nil -} - -func (aa *authApplierV3) Txn(rt *pb.TxnRequest) (*pb.TxnResponse, error) { - if err := checkTxnAuth(aa.as, &aa.authInfo, rt); err != nil { - return nil, err - } - return aa.applierV3.Txn(rt) -} - -func (aa *authApplierV3) LeaseRevoke(lc *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) { - if err := aa.checkLeasePuts(lease.LeaseID(lc.ID)); err != nil { - return nil, err - } - return aa.applierV3.LeaseRevoke(lc) -} - -func (aa *authApplierV3) checkLeasePuts(leaseID lease.LeaseID) error { - lease := aa.lessor.Lookup(leaseID) - if lease != nil { - for _, key := range lease.Keys() { - if err := aa.as.IsPutPermitted(&aa.authInfo, []byte(key)); err != nil { - return err - } - } - } - - return nil -} - -func (aa *authApplierV3) UserGet(r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) { - err := aa.as.IsAdminPermitted(&aa.authInfo) - if err != nil && r.Name != aa.authInfo.Username { - aa.authInfo.Username = "" - aa.authInfo.Revision = 0 - return &pb.AuthUserGetResponse{}, err - } - - return aa.applierV3.UserGet(r) -} - -func (aa *authApplierV3) RoleGet(r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) { - err := aa.as.IsAdminPermitted(&aa.authInfo) - if err != nil && !aa.as.HasRole(aa.authInfo.Username, r.Role) { - aa.authInfo.Username = "" - aa.authInfo.Revision = 0 - return &pb.AuthRoleGetResponse{}, err - } - - return aa.applierV3.RoleGet(r) -} - -func needAdminPermission(r *pb.InternalRaftRequest) bool { - switch { - case r.AuthEnable != nil: - return true - case r.AuthDisable != nil: - return true - case r.AuthUserAdd != nil: - return true - case r.AuthUserDelete != nil: - return true - case r.AuthUserChangePassword != nil: - return true - case r.AuthUserGrantRole != nil: - return true - case r.AuthUserRevokeRole != nil: - return true - case r.AuthRoleAdd != nil: - return true - case r.AuthRoleGrantPermission != nil: - return true - case r.AuthRoleRevokePermission != nil: - return true - case r.AuthRoleDelete != nil: - return true - case r.AuthUserList != nil: - return true - case r.AuthRoleList != nil: - return true - default: - return false - } -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/apply_v2.go b/vendor/go.etcd.io/etcd/etcdserver/apply_v2.go deleted file mode 100644 index a49b6823da99..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/apply_v2.go +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "encoding/json" - "path" - "time" - - "github.com/coreos/etcd/etcdserver/api" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/store" - "github.com/coreos/go-semver/semver" -) - -// ApplierV2 is the interface for processing V2 raft messages -type ApplierV2 interface { - Delete(r *RequestV2) Response - Post(r *RequestV2) Response - Put(r *RequestV2) Response - QGet(r *RequestV2) Response - Sync(r *RequestV2) Response -} - -func NewApplierV2(s store.Store, c *membership.RaftCluster) ApplierV2 { - return &applierV2store{store: s, cluster: c} -} - -type applierV2store struct { - store store.Store - cluster *membership.RaftCluster -} - -func (a *applierV2store) Delete(r *RequestV2) Response { - switch { - case r.PrevIndex > 0 || r.PrevValue != "": - return toResponse(a.store.CompareAndDelete(r.Path, r.PrevValue, r.PrevIndex)) - default: - return toResponse(a.store.Delete(r.Path, r.Dir, r.Recursive)) - } -} - -func (a *applierV2store) Post(r *RequestV2) Response { - return toResponse(a.store.Create(r.Path, r.Dir, r.Val, true, r.TTLOptions())) -} - -func (a *applierV2store) Put(r *RequestV2) Response { - ttlOptions := r.TTLOptions() - exists, existsSet := pbutil.GetBool(r.PrevExist) - switch { - case existsSet: - if exists { - if r.PrevIndex == 0 && r.PrevValue == "" { - return toResponse(a.store.Update(r.Path, r.Val, ttlOptions)) - } - return toResponse(a.store.CompareAndSwap(r.Path, r.PrevValue, r.PrevIndex, r.Val, ttlOptions)) - } - return toResponse(a.store.Create(r.Path, r.Dir, r.Val, false, ttlOptions)) - case r.PrevIndex > 0 || r.PrevValue != "": - return toResponse(a.store.CompareAndSwap(r.Path, r.PrevValue, r.PrevIndex, r.Val, ttlOptions)) - default: - if storeMemberAttributeRegexp.MatchString(r.Path) { - id := membership.MustParseMemberIDFromKey(path.Dir(r.Path)) - var attr membership.Attributes - if err := json.Unmarshal([]byte(r.Val), &attr); err != nil { - plog.Panicf("unmarshal %s should never fail: %v", r.Val, err) - } - if a.cluster != nil { - a.cluster.UpdateAttributes(id, attr) - } - // return an empty response since there is no consumer. - return Response{} - } - if r.Path == membership.StoreClusterVersionKey() { - if a.cluster != nil { - a.cluster.SetVersion(semver.Must(semver.NewVersion(r.Val)), api.UpdateCapability) - } - // return an empty response since there is no consumer. - return Response{} - } - return toResponse(a.store.Set(r.Path, r.Dir, r.Val, ttlOptions)) - } -} - -func (a *applierV2store) QGet(r *RequestV2) Response { - return toResponse(a.store.Get(r.Path, r.Recursive, r.Sorted)) -} - -func (a *applierV2store) Sync(r *RequestV2) Response { - a.store.DeleteExpiredKeys(time.Unix(0, r.Time)) - return Response{} -} - -// applyV2Request interprets r as a call to store.X and returns a Response interpreted -// from store.Event -func (s *EtcdServer) applyV2Request(r *RequestV2) Response { - defer warnOfExpensiveRequest(time.Now(), r, nil, nil) - - switch r.Method { - case "POST": - return s.applyV2.Post(r) - case "PUT": - return s.applyV2.Put(r) - case "DELETE": - return s.applyV2.Delete(r) - case "QGET": - return s.applyV2.QGet(r) - case "SYNC": - return s.applyV2.Sync(r) - default: - // This should never be reached, but just in case: - return Response{Err: ErrUnknownMethod} - } -} - -func (r *RequestV2) TTLOptions() store.TTLOptionSet { - refresh, _ := pbutil.GetBool(r.Refresh) - ttlOptions := store.TTLOptionSet{Refresh: refresh} - if r.Expiration != 0 { - ttlOptions.ExpireTime = time.Unix(0, r.Expiration) - } - return ttlOptions -} - -func toResponse(ev *store.Event, err error) Response { - return Response{Event: ev, Err: err} -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/backend.go b/vendor/go.etcd.io/etcd/etcdserver/backend.go deleted file mode 100644 index 647773d474f6..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/backend.go +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "fmt" - "os" - "time" - - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/snap" -) - -func newBackend(cfg ServerConfig) backend.Backend { - bcfg := backend.DefaultBackendConfig() - bcfg.Path = cfg.backendPath() - if cfg.QuotaBackendBytes > 0 && cfg.QuotaBackendBytes != DefaultQuotaBytes { - // permit 10% excess over quota for disarm - bcfg.MmapSize = uint64(cfg.QuotaBackendBytes + cfg.QuotaBackendBytes/10) - } - return backend.New(bcfg) -} - -// openSnapshotBackend renames a snapshot db to the current etcd db and opens it. -func openSnapshotBackend(cfg ServerConfig, ss *snap.Snapshotter, snapshot raftpb.Snapshot) (backend.Backend, error) { - snapPath, err := ss.DBFilePath(snapshot.Metadata.Index) - if err != nil { - return nil, fmt.Errorf("database snapshot file path error: %v", err) - } - if err := os.Rename(snapPath, cfg.backendPath()); err != nil { - return nil, fmt.Errorf("rename snapshot file error: %v", err) - } - return openBackend(cfg), nil -} - -// openBackend returns a backend using the current etcd db. -func openBackend(cfg ServerConfig) backend.Backend { - fn := cfg.backendPath() - beOpened := make(chan backend.Backend) - go func() { - beOpened <- newBackend(cfg) - }() - select { - case be := <-beOpened: - return be - case <-time.After(10 * time.Second): - plog.Warningf("another etcd process is using %q and holds the file lock, or loading backend file is taking >10 seconds", fn) - plog.Warningf("waiting for it to exit before starting...") - } - return <-beOpened -} - -// recoverBackendSnapshot recovers the DB from a snapshot in case etcd crashes -// before updating the backend db after persisting raft snapshot to disk, -// violating the invariant snapshot.Metadata.Index < db.consistentIndex. In this -// case, replace the db with the snapshot db sent by the leader. -func recoverSnapshotBackend(cfg ServerConfig, oldbe backend.Backend, snapshot raftpb.Snapshot) (backend.Backend, error) { - var cIndex consistentIndex - kv := mvcc.New(oldbe, &lease.FakeLessor{}, &cIndex) - defer kv.Close() - if snapshot.Metadata.Index <= kv.ConsistentIndex() { - return oldbe, nil - } - oldbe.Close() - return openSnapshotBackend(cfg, snap.New(cfg.SnapDir()), snapshot) -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/cluster_util.go b/vendor/go.etcd.io/etcd/etcdserver/cluster_util.go deleted file mode 100644 index f44862a46380..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/cluster_util.go +++ /dev/null @@ -1,258 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "sort" - "time" - - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/version" - "github.com/coreos/go-semver/semver" -) - -// isMemberBootstrapped tries to check if the given member has been bootstrapped -// in the given cluster. -func isMemberBootstrapped(cl *membership.RaftCluster, member string, rt http.RoundTripper, timeout time.Duration) bool { - rcl, err := getClusterFromRemotePeers(getRemotePeerURLs(cl, member), timeout, false, rt) - if err != nil { - return false - } - id := cl.MemberByName(member).ID - m := rcl.Member(id) - if m == nil { - return false - } - if len(m.ClientURLs) > 0 { - return true - } - return false -} - -// GetClusterFromRemotePeers takes a set of URLs representing etcd peers, and -// attempts to construct a Cluster by accessing the members endpoint on one of -// these URLs. The first URL to provide a response is used. If no URLs provide -// a response, or a Cluster cannot be successfully created from a received -// response, an error is returned. -// Each request has a 10-second timeout. Because the upper limit of TTL is 5s, -// 10 second is enough for building connection and finishing request. -func GetClusterFromRemotePeers(urls []string, rt http.RoundTripper) (*membership.RaftCluster, error) { - return getClusterFromRemotePeers(urls, 10*time.Second, true, rt) -} - -// If logerr is true, it prints out more error messages. -func getClusterFromRemotePeers(urls []string, timeout time.Duration, logerr bool, rt http.RoundTripper) (*membership.RaftCluster, error) { - cc := &http.Client{ - Transport: rt, - Timeout: timeout, - } - for _, u := range urls { - resp, err := cc.Get(u + "/members") - if err != nil { - if logerr { - plog.Warningf("could not get cluster response from %s: %v", u, err) - } - continue - } - b, err := ioutil.ReadAll(resp.Body) - resp.Body.Close() - if err != nil { - if logerr { - plog.Warningf("could not read the body of cluster response: %v", err) - } - continue - } - var membs []*membership.Member - if err = json.Unmarshal(b, &membs); err != nil { - if logerr { - plog.Warningf("could not unmarshal cluster response: %v", err) - } - continue - } - id, err := types.IDFromString(resp.Header.Get("X-Etcd-Cluster-ID")) - if err != nil { - if logerr { - plog.Warningf("could not parse the cluster ID from cluster res: %v", err) - } - continue - } - - // check the length of membership members - // if the membership members are present then prepare and return raft cluster - // if membership members are not present then the raft cluster formed will be - // an invalid empty cluster hence return failed to get raft cluster member(s) from the given urls error - if len(membs) > 0 { - return membership.NewClusterFromMembers("", id, membs), nil - } - - return nil, fmt.Errorf("failed to get raft cluster member(s) from the given urls.") - } - return nil, fmt.Errorf("could not retrieve cluster information from the given urls") -} - -// getRemotePeerURLs returns peer urls of remote members in the cluster. The -// returned list is sorted in ascending lexicographical order. -func getRemotePeerURLs(cl *membership.RaftCluster, local string) []string { - us := make([]string, 0) - for _, m := range cl.Members() { - if m.Name == local { - continue - } - us = append(us, m.PeerURLs...) - } - sort.Strings(us) - return us -} - -// getVersions returns the versions of the members in the given cluster. -// The key of the returned map is the member's ID. The value of the returned map -// is the semver versions string, including server and cluster. -// If it fails to get the version of a member, the key will be nil. -func getVersions(cl *membership.RaftCluster, local types.ID, rt http.RoundTripper) map[string]*version.Versions { - members := cl.Members() - vers := make(map[string]*version.Versions) - for _, m := range members { - if m.ID == local { - cv := "not_decided" - if cl.Version() != nil { - cv = cl.Version().String() - } - vers[m.ID.String()] = &version.Versions{Server: version.Version, Cluster: cv} - continue - } - ver, err := getVersion(m, rt) - if err != nil { - plog.Warningf("cannot get the version of member %s (%v)", m.ID, err) - vers[m.ID.String()] = nil - } else { - vers[m.ID.String()] = ver - } - } - return vers -} - -// decideClusterVersion decides the cluster version based on the versions map. -// The returned version is the min server version in the map, or nil if the min -// version in unknown. -func decideClusterVersion(vers map[string]*version.Versions) *semver.Version { - var cv *semver.Version - lv := semver.Must(semver.NewVersion(version.Version)) - - for mid, ver := range vers { - if ver == nil { - return nil - } - v, err := semver.NewVersion(ver.Server) - if err != nil { - plog.Errorf("cannot understand the version of member %s (%v)", mid, err) - return nil - } - if lv.LessThan(*v) { - plog.Warningf("the local etcd version %s is not up-to-date", lv.String()) - plog.Warningf("member %s has a higher version %s", mid, ver.Server) - } - if cv == nil { - cv = v - } else if v.LessThan(*cv) { - cv = v - } - } - return cv -} - -// isCompatibleWithCluster return true if the local member has a compatible version with -// the current running cluster. -// The version is considered as compatible when at least one of the other members in the cluster has a -// cluster version in the range of [MinClusterVersion, Version] and no known members has a cluster version -// out of the range. -// We set this rule since when the local member joins, another member might be offline. -func isCompatibleWithCluster(cl *membership.RaftCluster, local types.ID, rt http.RoundTripper) bool { - vers := getVersions(cl, local, rt) - minV := semver.Must(semver.NewVersion(version.MinClusterVersion)) - maxV := semver.Must(semver.NewVersion(version.Version)) - maxV = &semver.Version{ - Major: maxV.Major, - Minor: maxV.Minor, - } - - return isCompatibleWithVers(vers, local, minV, maxV) -} - -func isCompatibleWithVers(vers map[string]*version.Versions, local types.ID, minV, maxV *semver.Version) bool { - var ok bool - for id, v := range vers { - // ignore comparison with local version - if id == local.String() { - continue - } - if v == nil { - continue - } - clusterv, err := semver.NewVersion(v.Cluster) - if err != nil { - plog.Errorf("cannot understand the cluster version of member %s (%v)", id, err) - continue - } - if clusterv.LessThan(*minV) { - plog.Warningf("the running cluster version(%v) is lower than the minimal cluster version(%v) supported", clusterv.String(), minV.String()) - return false - } - if maxV.LessThan(*clusterv) { - plog.Warningf("the running cluster version(%v) is higher than the maximum cluster version(%v) supported", clusterv.String(), maxV.String()) - return false - } - ok = true - } - return ok -} - -// getVersion returns the Versions of the given member via its -// peerURLs. Returns the last error if it fails to get the version. -func getVersion(m *membership.Member, rt http.RoundTripper) (*version.Versions, error) { - cc := &http.Client{ - Transport: rt, - } - var ( - err error - resp *http.Response - ) - - for _, u := range m.PeerURLs { - resp, err = cc.Get(u + "/version") - if err != nil { - plog.Warningf("failed to reach the peerURL(%s) of member %s (%v)", u, m.ID, err) - continue - } - var b []byte - b, err = ioutil.ReadAll(resp.Body) - resp.Body.Close() - if err != nil { - plog.Warningf("failed to read out the response body from the peerURL(%s) of member %s (%v)", u, m.ID, err) - continue - } - var vers version.Versions - if err = json.Unmarshal(b, &vers); err != nil { - plog.Warningf("failed to unmarshal the response body got from the peerURL(%s) of member %s (%v)", u, m.ID, err) - continue - } - return &vers, nil - } - return nil, err -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/config.go b/vendor/go.etcd.io/etcd/etcdserver/config.go deleted file mode 100644 index 295d95299a20..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/config.go +++ /dev/null @@ -1,282 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "context" - "fmt" - "path/filepath" - "sort" - "strings" - "time" - - "github.com/coreos/etcd/pkg/netutil" - "github.com/coreos/etcd/pkg/transport" - "github.com/coreos/etcd/pkg/types" -) - -// ServerConfig holds the configuration of etcd as taken from the command line or discovery. -type ServerConfig struct { - Name string - DiscoveryURL string - DiscoveryProxy string - ClientURLs types.URLs - PeerURLs types.URLs - DataDir string - // DedicatedWALDir config will make the etcd to write the WAL to the WALDir - // rather than the dataDir/member/wal. - DedicatedWALDir string - SnapCount uint64 - MaxSnapFiles uint - MaxWALFiles uint - InitialPeerURLsMap types.URLsMap - InitialClusterToken string - NewCluster bool - ForceNewCluster bool - PeerTLSInfo transport.TLSInfo - - TickMs uint - ElectionTicks int - - // InitialElectionTickAdvance is true, then local member fast-forwards - // election ticks to speed up "initial" leader election trigger. This - // benefits the case of larger election ticks. For instance, cross - // datacenter deployment may require longer election timeout of 10-second. - // If true, local node does not need wait up to 10-second. Instead, - // forwards its election ticks to 8-second, and have only 2-second left - // before leader election. - // - // Major assumptions are that: - // - cluster has no active leader thus advancing ticks enables faster - // leader election, or - // - cluster already has an established leader, and rejoining follower - // is likely to receive heartbeats from the leader after tick advance - // and before election timeout. - // - // However, when network from leader to rejoining follower is congested, - // and the follower does not receive leader heartbeat within left election - // ticks, disruptive election has to happen thus affecting cluster - // availabilities. - // - // Disabling this would slow down initial bootstrap process for cross - // datacenter deployments. Make your own tradeoffs by configuring - // --initial-election-tick-advance at the cost of slow initial bootstrap. - // - // If single-node, it advances ticks regardless. - // - // See https://github.com/coreos/etcd/issues/9333 for more detail. - InitialElectionTickAdvance bool - - BootstrapTimeout time.Duration - - AutoCompactionRetention time.Duration - AutoCompactionMode string - QuotaBackendBytes int64 - MaxTxnOps uint - - // MaxRequestBytes is the maximum request size to send over raft. - MaxRequestBytes uint - - StrictReconfigCheck bool - - // ClientCertAuthEnabled is true when cert has been signed by the client CA. - ClientCertAuthEnabled bool - - AuthToken string - - // InitialCorruptCheck is true to check data corruption on boot - // before serving any peer/client traffic. - InitialCorruptCheck bool - CorruptCheckTime time.Duration - - Debug bool -} - -// VerifyBootstrap sanity-checks the initial config for bootstrap case -// and returns an error for things that should never happen. -func (c *ServerConfig) VerifyBootstrap() error { - if err := c.hasLocalMember(); err != nil { - return err - } - if err := c.advertiseMatchesCluster(); err != nil { - return err - } - if checkDuplicateURL(c.InitialPeerURLsMap) { - return fmt.Errorf("initial cluster %s has duplicate url", c.InitialPeerURLsMap) - } - if c.InitialPeerURLsMap.String() == "" && c.DiscoveryURL == "" { - return fmt.Errorf("initial cluster unset and no discovery URL found") - } - return nil -} - -// VerifyJoinExisting sanity-checks the initial config for join existing cluster -// case and returns an error for things that should never happen. -func (c *ServerConfig) VerifyJoinExisting() error { - // The member has announced its peer urls to the cluster before starting; no need to - // set the configuration again. - if err := c.hasLocalMember(); err != nil { - return err - } - if checkDuplicateURL(c.InitialPeerURLsMap) { - return fmt.Errorf("initial cluster %s has duplicate url", c.InitialPeerURLsMap) - } - if c.DiscoveryURL != "" { - return fmt.Errorf("discovery URL should not be set when joining existing initial cluster") - } - return nil -} - -// hasLocalMember checks that the cluster at least contains the local server. -func (c *ServerConfig) hasLocalMember() error { - if urls := c.InitialPeerURLsMap[c.Name]; urls == nil { - return fmt.Errorf("couldn't find local name %q in the initial cluster configuration", c.Name) - } - return nil -} - -// advertiseMatchesCluster confirms peer URLs match those in the cluster peer list. -func (c *ServerConfig) advertiseMatchesCluster() error { - urls, apurls := c.InitialPeerURLsMap[c.Name], c.PeerURLs.StringSlice() - urls.Sort() - sort.Strings(apurls) - ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second) - defer cancel() - ok, err := netutil.URLStringsEqual(ctx, apurls, urls.StringSlice()) - if ok { - return nil - } - - initMap, apMap := make(map[string]struct{}), make(map[string]struct{}) - for _, url := range c.PeerURLs { - apMap[url.String()] = struct{}{} - } - for _, url := range c.InitialPeerURLsMap[c.Name] { - initMap[url.String()] = struct{}{} - } - - missing := []string{} - for url := range initMap { - if _, ok := apMap[url]; !ok { - missing = append(missing, url) - } - } - if len(missing) > 0 { - for i := range missing { - missing[i] = c.Name + "=" + missing[i] - } - mstr := strings.Join(missing, ",") - apStr := strings.Join(apurls, ",") - return fmt.Errorf("--initial-cluster has %s but missing from --initial-advertise-peer-urls=%s (%v)", mstr, apStr, err) - } - - for url := range apMap { - if _, ok := initMap[url]; !ok { - missing = append(missing, url) - } - } - if len(missing) > 0 { - mstr := strings.Join(missing, ",") - umap := types.URLsMap(map[string]types.URLs{c.Name: c.PeerURLs}) - return fmt.Errorf("--initial-advertise-peer-urls has %s but missing from --initial-cluster=%s", mstr, umap.String()) - } - - // resolved URLs from "--initial-advertise-peer-urls" and "--initial-cluster" did not match or failed - apStr := strings.Join(apurls, ",") - umap := types.URLsMap(map[string]types.URLs{c.Name: c.PeerURLs}) - return fmt.Errorf("failed to resolve %s to match --initial-cluster=%s (%v)", apStr, umap.String(), err) -} - -func (c *ServerConfig) MemberDir() string { return filepath.Join(c.DataDir, "member") } - -func (c *ServerConfig) WALDir() string { - if c.DedicatedWALDir != "" { - return c.DedicatedWALDir - } - return filepath.Join(c.MemberDir(), "wal") -} - -func (c *ServerConfig) SnapDir() string { return filepath.Join(c.MemberDir(), "snap") } - -func (c *ServerConfig) ShouldDiscover() bool { return c.DiscoveryURL != "" } - -// ReqTimeout returns timeout for request to finish. -func (c *ServerConfig) ReqTimeout() time.Duration { - // 5s for queue waiting, computation and disk IO delay - // + 2 * election timeout for possible leader election - return 5*time.Second + 2*time.Duration(c.ElectionTicks*int(c.TickMs))*time.Millisecond -} - -func (c *ServerConfig) electionTimeout() time.Duration { - return time.Duration(c.ElectionTicks*int(c.TickMs)) * time.Millisecond -} - -func (c *ServerConfig) peerDialTimeout() time.Duration { - // 1s for queue wait and election timeout - return time.Second + time.Duration(c.ElectionTicks*int(c.TickMs))*time.Millisecond -} - -func (c *ServerConfig) PrintWithInitial() { c.print(true) } - -func (c *ServerConfig) Print() { c.print(false) } - -func (c *ServerConfig) print(initial bool) { - plog.Infof("name = %s", c.Name) - if c.ForceNewCluster { - plog.Infof("force new cluster") - } - plog.Infof("data dir = %s", c.DataDir) - plog.Infof("member dir = %s", c.MemberDir()) - if c.DedicatedWALDir != "" { - plog.Infof("dedicated WAL dir = %s", c.DedicatedWALDir) - } - plog.Infof("heartbeat = %dms", c.TickMs) - plog.Infof("election = %dms", c.ElectionTicks*int(c.TickMs)) - plog.Infof("snapshot count = %d", c.SnapCount) - if len(c.DiscoveryURL) != 0 { - plog.Infof("discovery URL= %s", c.DiscoveryURL) - if len(c.DiscoveryProxy) != 0 { - plog.Infof("discovery proxy = %s", c.DiscoveryProxy) - } - } - plog.Infof("advertise client URLs = %s", c.ClientURLs) - if initial { - plog.Infof("initial advertise peer URLs = %s", c.PeerURLs) - plog.Infof("initial cluster = %s", c.InitialPeerURLsMap) - } -} - -func checkDuplicateURL(urlsmap types.URLsMap) bool { - um := make(map[string]bool) - for _, urls := range urlsmap { - for _, url := range urls { - u := url.String() - if um[u] { - return true - } - um[u] = true - } - } - return false -} - -func (c *ServerConfig) bootstrapTimeout() time.Duration { - if c.BootstrapTimeout != 0 { - return c.BootstrapTimeout - } - return time.Second -} - -func (c *ServerConfig) backendPath() string { return filepath.Join(c.SnapDir(), "db") } diff --git a/vendor/go.etcd.io/etcd/etcdserver/consistent_index.go b/vendor/go.etcd.io/etcd/etcdserver/consistent_index.go deleted file mode 100644 index d513f6708d33..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/consistent_index.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "sync/atomic" -) - -// consistentIndex represents the offset of an entry in a consistent replica log. -// It implements the mvcc.ConsistentIndexGetter interface. -// It is always set to the offset of current entry before executing the entry, -// so ConsistentWatchableKV could get the consistent index from it. -type consistentIndex uint64 - -func (i *consistentIndex) setConsistentIndex(v uint64) { - atomic.StoreUint64((*uint64)(i), v) -} - -func (i *consistentIndex) ConsistentIndex() uint64 { - return atomic.LoadUint64((*uint64)(i)) -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/corrupt.go b/vendor/go.etcd.io/etcd/etcdserver/corrupt.go deleted file mode 100644 index d998ec590207..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/corrupt.go +++ /dev/null @@ -1,262 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "context" - "fmt" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/pkg/types" -) - -// CheckInitialHashKV compares initial hash values with its peers -// before serving any peer/client traffic. Only mismatch when hashes -// are different at requested revision, with same compact revision. -func (s *EtcdServer) CheckInitialHashKV() error { - if !s.Cfg.InitialCorruptCheck { - return nil - } - - plog.Infof("%s starting initial corruption check with timeout %v...", s.ID(), s.Cfg.ReqTimeout()) - h, rev, crev, err := s.kv.HashByRev(0) - if err != nil { - return fmt.Errorf("%s failed to fetch hash (%v)", s.ID(), err) - } - peers := s.getPeerHashKVs(rev) - mismatch := 0 - for _, p := range peers { - if p.resp != nil { - peerID := types.ID(p.resp.Header.MemberId) - if h != p.resp.Hash { - if crev == p.resp.CompactRevision { - plog.Errorf("%s's hash %d != %s's hash %d (revision %d, peer revision %d, compact revision %d)", s.ID(), h, peerID, p.resp.Hash, rev, p.resp.Header.Revision, crev) - mismatch++ - } else { - plog.Warningf("%s cannot check hash of peer(%s): peer has a different compact revision %d (revision:%d)", s.ID(), peerID, p.resp.CompactRevision, rev) - } - } - continue - } - if p.err != nil { - switch p.err { - case rpctypes.ErrFutureRev: - plog.Warningf("%s cannot check the hash of peer(%q) at revision %d: peer is lagging behind(%q)", s.ID(), p.eps, rev, p.err.Error()) - case rpctypes.ErrCompacted: - plog.Warningf("%s cannot check the hash of peer(%q) at revision %d: local node is lagging behind(%q)", s.ID(), p.eps, rev, p.err.Error()) - } - } - } - if mismatch > 0 { - return fmt.Errorf("%s found data inconsistency with peers", s.ID()) - } - - plog.Infof("%s succeeded on initial corruption checking: no corruption", s.ID()) - return nil -} - -func (s *EtcdServer) monitorKVHash() { - t := s.Cfg.CorruptCheckTime - if t == 0 { - return - } - plog.Infof("enabled corruption checking with %s interval", t) - for { - select { - case <-s.stopping: - return - case <-time.After(t): - } - if !s.isLeader() { - continue - } - if err := s.checkHashKV(); err != nil { - plog.Debugf("check hash kv failed %v", err) - } - } -} - -func (s *EtcdServer) checkHashKV() error { - h, rev, crev, err := s.kv.HashByRev(0) - if err != nil { - plog.Fatalf("failed to hash kv store (%v)", err) - } - peers := s.getPeerHashKVs(rev) - - ctx, cancel := context.WithTimeout(context.Background(), s.Cfg.ReqTimeout()) - err = s.linearizableReadNotify(ctx) - cancel() - if err != nil { - return err - } - - h2, rev2, crev2, err := s.kv.HashByRev(0) - if err != nil { - plog.Warningf("failed to hash kv store (%v)", err) - return err - } - - alarmed := false - mismatch := func(id uint64) { - if alarmed { - return - } - alarmed = true - a := &pb.AlarmRequest{ - MemberID: uint64(id), - Action: pb.AlarmRequest_ACTIVATE, - Alarm: pb.AlarmType_CORRUPT, - } - s.goAttach(func() { - s.raftRequest(s.ctx, pb.InternalRaftRequest{Alarm: a}) - }) - } - - if h2 != h && rev2 == rev && crev == crev2 { - plog.Warningf("mismatched hashes %d and %d for revision %d", h, h2, rev) - mismatch(uint64(s.ID())) - } - - for _, p := range peers { - if p.resp == nil { - continue - } - id := p.resp.Header.MemberId - - // leader expects follower's latest revision less than or equal to leader's - if p.resp.Header.Revision > rev2 { - plog.Warningf( - "revision %d from member %v, expected at most %d", - p.resp.Header.Revision, - types.ID(id), - rev2) - mismatch(id) - } - - // leader expects follower's latest compact revision less than or equal to leader's - if p.resp.CompactRevision > crev2 { - plog.Warningf( - "compact revision %d from member %v, expected at most %d", - p.resp.CompactRevision, - types.ID(id), - crev2, - ) - mismatch(id) - } - - // follower's compact revision is leader's old one, then hashes must match - if p.resp.CompactRevision == crev && p.resp.Hash != h { - plog.Warningf( - "hash %d at revision %d from member %v, expected hash %d", - p.resp.Hash, - rev, - types.ID(id), - h, - ) - mismatch(id) - } - } - return nil -} - -type peerHashKVResp struct { - resp *clientv3.HashKVResponse - err error - eps []string -} - -func (s *EtcdServer) getPeerHashKVs(rev int64) (resps []*peerHashKVResp) { - // TODO: handle the case when "s.cluster.Members" have not - // been populated (e.g. no snapshot to load from disk) - mbs := s.cluster.Members() - pURLs := make([][]string, len(mbs)) - for _, m := range mbs { - if m.ID == s.ID() { - continue - } - pURLs = append(pURLs, m.PeerURLs) - } - - for _, purls := range pURLs { - if len(purls) == 0 { - continue - } - cli, cerr := clientv3.New(clientv3.Config{ - DialTimeout: s.Cfg.ReqTimeout(), - Endpoints: purls, - }) - if cerr != nil { - plog.Warningf("%s failed to create client to peer %q for hash checking (%q)", s.ID(), purls, cerr.Error()) - continue - } - - respsLen := len(resps) - for _, c := range cli.Endpoints() { - ctx, cancel := context.WithTimeout(context.Background(), s.Cfg.ReqTimeout()) - var resp *clientv3.HashKVResponse - resp, cerr = cli.HashKV(ctx, c, rev) - cancel() - if cerr == nil { - resps = append(resps, &peerHashKVResp{resp: resp}) - break - } - plog.Warningf("%s hash-kv error %q on peer %q with revision %d", s.ID(), cerr.Error(), c, rev) - } - cli.Close() - - if respsLen == len(resps) { - resps = append(resps, &peerHashKVResp{err: cerr, eps: purls}) - } - } - return resps -} - -type applierV3Corrupt struct { - applierV3 -} - -func newApplierV3Corrupt(a applierV3) *applierV3Corrupt { return &applierV3Corrupt{a} } - -func (a *applierV3Corrupt) Put(txn mvcc.TxnWrite, p *pb.PutRequest) (*pb.PutResponse, error) { - return nil, ErrCorrupt -} - -func (a *applierV3Corrupt) Range(txn mvcc.TxnRead, p *pb.RangeRequest) (*pb.RangeResponse, error) { - return nil, ErrCorrupt -} - -func (a *applierV3Corrupt) DeleteRange(txn mvcc.TxnWrite, p *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) { - return nil, ErrCorrupt -} - -func (a *applierV3Corrupt) Txn(rt *pb.TxnRequest) (*pb.TxnResponse, error) { - return nil, ErrCorrupt -} - -func (a *applierV3Corrupt) Compaction(compaction *pb.CompactionRequest) (*pb.CompactionResponse, <-chan struct{}, error) { - return nil, nil, ErrCorrupt -} - -func (a *applierV3Corrupt) LeaseGrant(lc *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - return nil, ErrCorrupt -} - -func (a *applierV3Corrupt) LeaseRevoke(lc *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) { - return nil, ErrCorrupt -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/doc.go b/vendor/go.etcd.io/etcd/etcdserver/doc.go deleted file mode 100644 index b195d2d167a6..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package etcdserver defines how etcd servers interact and store their states. -package etcdserver diff --git a/vendor/go.etcd.io/etcd/etcdserver/errors.go b/vendor/go.etcd.io/etcd/etcdserver/errors.go deleted file mode 100644 index fb93c4b2a1dd..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/errors.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "errors" - "fmt" -) - -var ( - ErrUnknownMethod = errors.New("etcdserver: unknown method") - ErrStopped = errors.New("etcdserver: server stopped") - ErrCanceled = errors.New("etcdserver: request cancelled") - ErrTimeout = errors.New("etcdserver: request timed out") - ErrTimeoutDueToLeaderFail = errors.New("etcdserver: request timed out, possibly due to previous leader failure") - ErrTimeoutDueToConnectionLost = errors.New("etcdserver: request timed out, possibly due to connection lost") - ErrTimeoutLeaderTransfer = errors.New("etcdserver: request timed out, leader transfer took too long") - ErrNotEnoughStartedMembers = errors.New("etcdserver: re-configuration failed due to not enough started members") - ErrNoLeader = errors.New("etcdserver: no leader") - ErrNotLeader = errors.New("etcdserver: not leader") - ErrRequestTooLarge = errors.New("etcdserver: request is too large") - ErrNoSpace = errors.New("etcdserver: no space") - ErrTooManyRequests = errors.New("etcdserver: too many requests") - ErrUnhealthy = errors.New("etcdserver: unhealthy cluster") - ErrKeyNotFound = errors.New("etcdserver: key not found") - ErrCorrupt = errors.New("etcdserver: corrupt cluster") -) - -type DiscoveryError struct { - Op string - Err error -} - -func (e DiscoveryError) Error() string { - return fmt.Sprintf("failed to %s discovery cluster (%v)", e.Op, e.Err) -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/etcdserver.pb.go b/vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/etcdserver.pb.go deleted file mode 100644 index 90045a5c9759..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/etcdserver.pb.go +++ /dev/null @@ -1,1035 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: etcdserver.proto - -/* - Package etcdserverpb is a generated protocol buffer package. - - It is generated from these files: - etcdserver.proto - raft_internal.proto - rpc.proto - - It has these top-level messages: - Request - Metadata - RequestHeader - InternalRaftRequest - EmptyResponse - InternalAuthenticateRequest - ResponseHeader - RangeRequest - RangeResponse - PutRequest - PutResponse - DeleteRangeRequest - DeleteRangeResponse - RequestOp - ResponseOp - Compare - TxnRequest - TxnResponse - CompactionRequest - CompactionResponse - HashRequest - HashKVRequest - HashKVResponse - HashResponse - SnapshotRequest - SnapshotResponse - WatchRequest - WatchCreateRequest - WatchCancelRequest - WatchResponse - LeaseGrantRequest - LeaseGrantResponse - LeaseRevokeRequest - LeaseRevokeResponse - LeaseKeepAliveRequest - LeaseKeepAliveResponse - LeaseTimeToLiveRequest - LeaseTimeToLiveResponse - LeaseLeasesRequest - LeaseStatus - LeaseLeasesResponse - Member - MemberAddRequest - MemberAddResponse - MemberRemoveRequest - MemberRemoveResponse - MemberUpdateRequest - MemberUpdateResponse - MemberListRequest - MemberListResponse - DefragmentRequest - DefragmentResponse - MoveLeaderRequest - MoveLeaderResponse - AlarmRequest - AlarmMember - AlarmResponse - StatusRequest - StatusResponse - AuthEnableRequest - AuthDisableRequest - AuthenticateRequest - AuthUserAddRequest - AuthUserGetRequest - AuthUserDeleteRequest - AuthUserChangePasswordRequest - AuthUserGrantRoleRequest - AuthUserRevokeRoleRequest - AuthRoleAddRequest - AuthRoleGetRequest - AuthUserListRequest - AuthRoleListRequest - AuthRoleDeleteRequest - AuthRoleGrantPermissionRequest - AuthRoleRevokePermissionRequest - AuthEnableResponse - AuthDisableResponse - AuthenticateResponse - AuthUserAddResponse - AuthUserGetResponse - AuthUserDeleteResponse - AuthUserChangePasswordResponse - AuthUserGrantRoleResponse - AuthUserRevokeRoleResponse - AuthRoleAddResponse - AuthRoleGetResponse - AuthRoleListResponse - AuthUserListResponse - AuthRoleDeleteResponse - AuthRoleGrantPermissionResponse - AuthRoleRevokePermissionResponse -*/ -package etcdserverpb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type Request struct { - ID uint64 `protobuf:"varint,1,opt,name=ID" json:"ID"` - Method string `protobuf:"bytes,2,opt,name=Method" json:"Method"` - Path string `protobuf:"bytes,3,opt,name=Path" json:"Path"` - Val string `protobuf:"bytes,4,opt,name=Val" json:"Val"` - Dir bool `protobuf:"varint,5,opt,name=Dir" json:"Dir"` - PrevValue string `protobuf:"bytes,6,opt,name=PrevValue" json:"PrevValue"` - PrevIndex uint64 `protobuf:"varint,7,opt,name=PrevIndex" json:"PrevIndex"` - PrevExist *bool `protobuf:"varint,8,opt,name=PrevExist" json:"PrevExist,omitempty"` - Expiration int64 `protobuf:"varint,9,opt,name=Expiration" json:"Expiration"` - Wait bool `protobuf:"varint,10,opt,name=Wait" json:"Wait"` - Since uint64 `protobuf:"varint,11,opt,name=Since" json:"Since"` - Recursive bool `protobuf:"varint,12,opt,name=Recursive" json:"Recursive"` - Sorted bool `protobuf:"varint,13,opt,name=Sorted" json:"Sorted"` - Quorum bool `protobuf:"varint,14,opt,name=Quorum" json:"Quorum"` - Time int64 `protobuf:"varint,15,opt,name=Time" json:"Time"` - Stream bool `protobuf:"varint,16,opt,name=Stream" json:"Stream"` - Refresh *bool `protobuf:"varint,17,opt,name=Refresh" json:"Refresh,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Request) Reset() { *m = Request{} } -func (m *Request) String() string { return proto.CompactTextString(m) } -func (*Request) ProtoMessage() {} -func (*Request) Descriptor() ([]byte, []int) { return fileDescriptorEtcdserver, []int{0} } - -type Metadata struct { - NodeID uint64 `protobuf:"varint,1,opt,name=NodeID" json:"NodeID"` - ClusterID uint64 `protobuf:"varint,2,opt,name=ClusterID" json:"ClusterID"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Metadata) Reset() { *m = Metadata{} } -func (m *Metadata) String() string { return proto.CompactTextString(m) } -func (*Metadata) ProtoMessage() {} -func (*Metadata) Descriptor() ([]byte, []int) { return fileDescriptorEtcdserver, []int{1} } - -func init() { - proto.RegisterType((*Request)(nil), "etcdserverpb.Request") - proto.RegisterType((*Metadata)(nil), "etcdserverpb.Metadata") -} -func (m *Request) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Request) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(m.ID)) - dAtA[i] = 0x12 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(len(m.Method))) - i += copy(dAtA[i:], m.Method) - dAtA[i] = 0x1a - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(len(m.Path))) - i += copy(dAtA[i:], m.Path) - dAtA[i] = 0x22 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(len(m.Val))) - i += copy(dAtA[i:], m.Val) - dAtA[i] = 0x28 - i++ - if m.Dir { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - dAtA[i] = 0x32 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(len(m.PrevValue))) - i += copy(dAtA[i:], m.PrevValue) - dAtA[i] = 0x38 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(m.PrevIndex)) - if m.PrevExist != nil { - dAtA[i] = 0x40 - i++ - if *m.PrevExist { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - dAtA[i] = 0x48 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(m.Expiration)) - dAtA[i] = 0x50 - i++ - if m.Wait { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - dAtA[i] = 0x58 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(m.Since)) - dAtA[i] = 0x60 - i++ - if m.Recursive { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - dAtA[i] = 0x68 - i++ - if m.Sorted { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - dAtA[i] = 0x70 - i++ - if m.Quorum { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - dAtA[i] = 0x78 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(m.Time)) - dAtA[i] = 0x80 - i++ - dAtA[i] = 0x1 - i++ - if m.Stream { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - if m.Refresh != nil { - dAtA[i] = 0x88 - i++ - dAtA[i] = 0x1 - i++ - if *m.Refresh { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *Metadata) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Metadata) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(m.NodeID)) - dAtA[i] = 0x10 - i++ - i = encodeVarintEtcdserver(dAtA, i, uint64(m.ClusterID)) - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func encodeVarintEtcdserver(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *Request) Size() (n int) { - var l int - _ = l - n += 1 + sovEtcdserver(uint64(m.ID)) - l = len(m.Method) - n += 1 + l + sovEtcdserver(uint64(l)) - l = len(m.Path) - n += 1 + l + sovEtcdserver(uint64(l)) - l = len(m.Val) - n += 1 + l + sovEtcdserver(uint64(l)) - n += 2 - l = len(m.PrevValue) - n += 1 + l + sovEtcdserver(uint64(l)) - n += 1 + sovEtcdserver(uint64(m.PrevIndex)) - if m.PrevExist != nil { - n += 2 - } - n += 1 + sovEtcdserver(uint64(m.Expiration)) - n += 2 - n += 1 + sovEtcdserver(uint64(m.Since)) - n += 2 - n += 2 - n += 2 - n += 1 + sovEtcdserver(uint64(m.Time)) - n += 3 - if m.Refresh != nil { - n += 3 - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *Metadata) Size() (n int) { - var l int - _ = l - n += 1 + sovEtcdserver(uint64(m.NodeID)) - n += 1 + sovEtcdserver(uint64(m.ClusterID)) - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func sovEtcdserver(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozEtcdserver(x uint64) (n int) { - return sovEtcdserver(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Request) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Request: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Request: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Method", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthEtcdserver - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Method = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Path", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthEtcdserver - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Path = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Val", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthEtcdserver - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Val = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Dir", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Dir = bool(v != 0) - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PrevValue", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthEtcdserver - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PrevValue = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 7: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PrevIndex", wireType) - } - m.PrevIndex = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.PrevIndex |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PrevExist", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - b := bool(v != 0) - m.PrevExist = &b - case 9: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Expiration", wireType) - } - m.Expiration = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Expiration |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 10: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Wait", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Wait = bool(v != 0) - case 11: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Since", wireType) - } - m.Since = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Since |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 12: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Recursive", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Recursive = bool(v != 0) - case 13: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Sorted", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Sorted = bool(v != 0) - case 14: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Quorum", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Quorum = bool(v != 0) - case 15: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Time", wireType) - } - m.Time = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Time |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 16: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Stream", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Stream = bool(v != 0) - case 17: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Refresh", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - b := bool(v != 0) - m.Refresh = &b - default: - iNdEx = preIndex - skippy, err := skipEtcdserver(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthEtcdserver - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Metadata) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Metadata: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Metadata: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field NodeID", wireType) - } - m.NodeID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.NodeID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClusterID", wireType) - } - m.ClusterID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ClusterID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipEtcdserver(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthEtcdserver - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipEtcdserver(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthEtcdserver - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowEtcdserver - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipEtcdserver(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthEtcdserver = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowEtcdserver = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("etcdserver.proto", fileDescriptorEtcdserver) } - -var fileDescriptorEtcdserver = []byte{ - // 380 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0xd2, 0xdd, 0x6e, 0xda, 0x30, - 0x14, 0x07, 0x70, 0x0c, 0xe1, 0xcb, 0x63, 0x1b, 0xb3, 0xd0, 0x74, 0x84, 0xa6, 0x2c, 0x42, 0xbb, - 0xc8, 0xd5, 0xf6, 0x0e, 0x2c, 0x5c, 0x44, 0x2a, 0x15, 0x0d, 0x15, 0xbd, 0x76, 0xc9, 0x29, 0x58, - 0x02, 0x4c, 0x1d, 0x07, 0xf1, 0x06, 0x7d, 0x85, 0x3e, 0x12, 0x97, 0x7d, 0x82, 0xaa, 0xa5, 0x2f, - 0x52, 0x39, 0x24, 0xc4, 0xed, 0x5d, 0xf4, 0xfb, 0x9f, 0x1c, 0x1f, 0x7f, 0xd0, 0x2e, 0xea, 0x79, - 0x9c, 0xa0, 0xda, 0xa1, 0xfa, 0xbb, 0x55, 0x52, 0x4b, 0xd6, 0x29, 0x65, 0x7b, 0xdb, 0xef, 0x2d, - 0xe4, 0x42, 0x66, 0xc1, 0x3f, 0xf3, 0x75, 0xaa, 0x19, 0x3c, 0x38, 0xb4, 0x19, 0xe1, 0x7d, 0x8a, - 0x89, 0x66, 0x3d, 0x5a, 0x0d, 0x03, 0x20, 0x1e, 0xf1, 0x9d, 0xa1, 0x73, 0x78, 0xfe, 0x5d, 0x89, - 0xaa, 0x61, 0xc0, 0x7e, 0xd1, 0xc6, 0x18, 0xf5, 0x52, 0xc6, 0x50, 0xf5, 0x88, 0xdf, 0xce, 0x93, - 0xdc, 0x18, 0x50, 0x67, 0xc2, 0xf5, 0x12, 0x6a, 0x56, 0x96, 0x09, 0xfb, 0x49, 0x6b, 0x33, 0xbe, - 0x02, 0xc7, 0x0a, 0x0c, 0x18, 0x0f, 0x84, 0x82, 0xba, 0x47, 0xfc, 0x56, 0xe1, 0x81, 0x50, 0x6c, - 0x40, 0xdb, 0x13, 0x85, 0xbb, 0x19, 0x5f, 0xa5, 0x08, 0x0d, 0xeb, 0xaf, 0x92, 0x8b, 0x9a, 0x70, - 0x13, 0xe3, 0x1e, 0x9a, 0xd6, 0xa0, 0x25, 0x17, 0x35, 0xa3, 0xbd, 0x48, 0x34, 0xb4, 0xce, 0xab, - 0x90, 0xa8, 0x64, 0xf6, 0x87, 0xd2, 0xd1, 0x7e, 0x2b, 0x14, 0xd7, 0x42, 0x6e, 0xa0, 0xed, 0x11, - 0xbf, 0x96, 0x37, 0xb2, 0xdc, 0xec, 0xed, 0x86, 0x0b, 0x0d, 0xd4, 0x1a, 0x35, 0x13, 0xd6, 0xa7, - 0xf5, 0xa9, 0xd8, 0xcc, 0x11, 0xbe, 0x58, 0x33, 0x9c, 0xc8, 0xac, 0x1f, 0xe1, 0x3c, 0x55, 0x89, - 0xd8, 0x21, 0x74, 0xac, 0x5f, 0x4b, 0x36, 0x67, 0x3a, 0x95, 0x4a, 0x63, 0x0c, 0x5f, 0xad, 0x82, - 0xdc, 0x4c, 0x7a, 0x95, 0x4a, 0x95, 0xae, 0xe1, 0x9b, 0x9d, 0x9e, 0xcc, 0x4c, 0x75, 0x2d, 0xd6, - 0x08, 0xdf, 0xad, 0xa9, 0x33, 0xc9, 0xba, 0x6a, 0x85, 0x7c, 0x0d, 0xdd, 0x0f, 0x5d, 0x33, 0x63, - 0xae, 0xb9, 0xe8, 0x3b, 0x85, 0xc9, 0x12, 0x7e, 0x58, 0xa7, 0x52, 0xe0, 0xe0, 0x82, 0xb6, 0xc6, - 0xa8, 0x79, 0xcc, 0x35, 0x37, 0x9d, 0x2e, 0x65, 0x8c, 0x9f, 0x5e, 0x43, 0x6e, 0x66, 0x87, 0xff, - 0x57, 0x69, 0xa2, 0x51, 0x85, 0x41, 0xf6, 0x28, 0xce, 0xb7, 0x70, 0xe6, 0x61, 0xef, 0xf0, 0xea, - 0x56, 0x0e, 0x47, 0x97, 0x3c, 0x1d, 0x5d, 0xf2, 0x72, 0x74, 0xc9, 0xe3, 0x9b, 0x5b, 0x79, 0x0f, - 0x00, 0x00, 0xff, 0xff, 0xee, 0x40, 0xba, 0xd6, 0xa4, 0x02, 0x00, 0x00, -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/gw/rpc.pb.gw.go b/vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/gw/rpc.pb.gw.go deleted file mode 100644 index c50525ba392d..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/gw/rpc.pb.gw.go +++ /dev/null @@ -1,2134 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: etcdserver/etcdserverpb/rpc.proto - -/* -Package etcdserverpb is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package gw - -import ( - "github.com/coreos/etcd/etcdserver/etcdserverpb" - "io" - "net/http" - - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "golang.org/x/net/context" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/status" -) - -var _ codes.Code -var _ io.Reader -var _ status.Status -var _ = runtime.String -var _ = utilities.NewDoubleArray - -func request_KV_Range_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.KVClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.RangeRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Range(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_KV_Put_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.KVClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.PutRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Put(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_KV_DeleteRange_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.KVClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.DeleteRangeRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.DeleteRange(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_KV_Txn_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.KVClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.TxnRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Txn(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_KV_Compact_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.KVClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.CompactionRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Compact(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Watch_Watch_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.WatchClient, req *http.Request, pathParams map[string]string) (etcdserverpb.Watch_WatchClient, runtime.ServerMetadata, error) { - var metadata runtime.ServerMetadata - stream, err := client.Watch(ctx) - if err != nil { - grpclog.Printf("Failed to start streaming: %v", err) - return nil, metadata, err - } - dec := marshaler.NewDecoder(req.Body) - handleSend := func() error { - var protoReq etcdserverpb.WatchRequest - err = dec.Decode(&protoReq) - if err == io.EOF { - return err - } - if err != nil { - grpclog.Printf("Failed to decode request: %v", err) - return err - } - if err = stream.Send(&protoReq); err != nil { - grpclog.Printf("Failed to send request: %v", err) - return err - } - return nil - } - if err := handleSend(); err != nil { - if cerr := stream.CloseSend(); cerr != nil { - grpclog.Printf("Failed to terminate client stream: %v", cerr) - } - if err == io.EOF { - return stream, metadata, nil - } - return nil, metadata, err - } - go func() { - for { - if err := handleSend(); err != nil { - break - } - } - if err := stream.CloseSend(); err != nil { - grpclog.Printf("Failed to terminate client stream: %v", err) - } - }() - header, err := stream.Header() - if err != nil { - grpclog.Printf("Failed to get header from client: %v", err) - return nil, metadata, err - } - metadata.HeaderMD = header - return stream, metadata, nil -} - -func request_Lease_LeaseGrant_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.LeaseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseGrantRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.LeaseGrant(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Lease_LeaseRevoke_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.LeaseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseRevokeRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.LeaseRevoke(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Lease_LeaseKeepAlive_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.LeaseClient, req *http.Request, pathParams map[string]string) (etcdserverpb.Lease_LeaseKeepAliveClient, runtime.ServerMetadata, error) { - var metadata runtime.ServerMetadata - stream, err := client.LeaseKeepAlive(ctx) - if err != nil { - grpclog.Printf("Failed to start streaming: %v", err) - return nil, metadata, err - } - dec := marshaler.NewDecoder(req.Body) - handleSend := func() error { - var protoReq etcdserverpb.LeaseKeepAliveRequest - err = dec.Decode(&protoReq) - if err == io.EOF { - return err - } - if err != nil { - grpclog.Printf("Failed to decode request: %v", err) - return err - } - if err = stream.Send(&protoReq); err != nil { - grpclog.Printf("Failed to send request: %v", err) - return err - } - return nil - } - if err := handleSend(); err != nil { - if cerr := stream.CloseSend(); cerr != nil { - grpclog.Printf("Failed to terminate client stream: %v", cerr) - } - if err == io.EOF { - return stream, metadata, nil - } - return nil, metadata, err - } - go func() { - for { - if err := handleSend(); err != nil { - break - } - } - if err := stream.CloseSend(); err != nil { - grpclog.Printf("Failed to terminate client stream: %v", err) - } - }() - header, err := stream.Header() - if err != nil { - grpclog.Printf("Failed to get header from client: %v", err) - return nil, metadata, err - } - metadata.HeaderMD = header - return stream, metadata, nil -} - -func request_Lease_LeaseTimeToLive_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.LeaseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseTimeToLiveRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.LeaseTimeToLive(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Lease_LeaseLeases_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.LeaseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseLeasesRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.LeaseLeases(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Cluster_MemberAdd_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.ClusterClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MemberAddRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.MemberAdd(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Cluster_MemberRemove_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.ClusterClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MemberRemoveRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.MemberRemove(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Cluster_MemberUpdate_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.ClusterClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MemberUpdateRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.MemberUpdate(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Cluster_MemberList_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.ClusterClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MemberListRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.MemberList(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Maintenance_Alarm_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AlarmRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Alarm(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Maintenance_Status_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.StatusRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Status(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Maintenance_Defragment_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.DefragmentRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Defragment(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Maintenance_Hash_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.HashRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Hash(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Maintenance_HashKV_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.HashKVRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.HashKV(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Maintenance_Snapshot_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (etcdserverpb.Maintenance_SnapshotClient, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.SnapshotRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - stream, err := client.Snapshot(ctx, &protoReq) - if err != nil { - return nil, metadata, err - } - header, err := stream.Header() - if err != nil { - return nil, metadata, err - } - metadata.HeaderMD = header - return stream, metadata, nil - -} - -func request_Maintenance_MoveLeader_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MoveLeaderRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.MoveLeader(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_AuthEnable_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthEnableRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.AuthEnable(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_AuthDisable_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthDisableRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.AuthDisable(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_Authenticate_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthenticateRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Authenticate(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_UserAdd_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserAddRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserAdd(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_UserGet_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserGetRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserGet(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_UserList_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserListRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserList(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_UserDelete_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserDeleteRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserDelete(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_UserChangePassword_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserChangePasswordRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserChangePassword(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_UserGrantRole_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserGrantRoleRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserGrantRole(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_UserRevokeRole_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserRevokeRoleRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserRevokeRole(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_RoleAdd_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleAddRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RoleAdd(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_RoleGet_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleGetRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RoleGet(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_RoleList_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleListRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RoleList(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_RoleDelete_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleDeleteRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RoleDelete(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_RoleGrantPermission_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleGrantPermissionRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RoleGrantPermission(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func request_Auth_RoleRevokePermission_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleRevokePermissionRequest - var metadata runtime.ServerMetadata - - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RoleRevokePermission(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -// RegisterKVHandlerFromEndpoint is same as RegisterKVHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterKVHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterKVHandler(ctx, mux, conn) -} - -// RegisterKVHandler registers the http handlers for service KV to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterKVHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterKVHandlerClient(ctx, mux, etcdserverpb.NewKVClient(conn)) -} - -// RegisterKVHandler registers the http handlers for service KV to "mux". -// The handlers forward requests to the grpc endpoint over the given implementation of "KVClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "KVClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "KVClient" to call the correct interceptors. -func RegisterKVHandlerClient(ctx context.Context, mux *runtime.ServeMux, client etcdserverpb.KVClient) error { - - mux.Handle("POST", pattern_KV_Range_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_KV_Range_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_Range_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_KV_Put_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_KV_Put_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_Put_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_KV_DeleteRange_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_KV_DeleteRange_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_DeleteRange_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_KV_Txn_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_KV_Txn_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_Txn_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_KV_Compact_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_KV_Compact_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_Compact_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_KV_Range_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "kv", "range"}, "")) - - pattern_KV_Put_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "kv", "put"}, "")) - - pattern_KV_DeleteRange_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "kv", "deleterange"}, "")) - - pattern_KV_Txn_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "kv", "txn"}, "")) - - pattern_KV_Compact_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "kv", "compaction"}, "")) -) - -var ( - forward_KV_Range_0 = runtime.ForwardResponseMessage - - forward_KV_Put_0 = runtime.ForwardResponseMessage - - forward_KV_DeleteRange_0 = runtime.ForwardResponseMessage - - forward_KV_Txn_0 = runtime.ForwardResponseMessage - - forward_KV_Compact_0 = runtime.ForwardResponseMessage -) - -// RegisterWatchHandlerFromEndpoint is same as RegisterWatchHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterWatchHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterWatchHandler(ctx, mux, conn) -} - -// RegisterWatchHandler registers the http handlers for service Watch to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterWatchHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterWatchHandlerClient(ctx, mux, etcdserverpb.NewWatchClient(conn)) -} - -// RegisterWatchHandler registers the http handlers for service Watch to "mux". -// The handlers forward requests to the grpc endpoint over the given implementation of "WatchClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "WatchClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "WatchClient" to call the correct interceptors. -func RegisterWatchHandlerClient(ctx context.Context, mux *runtime.ServeMux, client etcdserverpb.WatchClient) error { - - mux.Handle("POST", pattern_Watch_Watch_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Watch_Watch_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Watch_Watch_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Watch_Watch_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v3beta", "watch"}, "")) -) - -var ( - forward_Watch_Watch_0 = runtime.ForwardResponseStream -) - -// RegisterLeaseHandlerFromEndpoint is same as RegisterLeaseHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterLeaseHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterLeaseHandler(ctx, mux, conn) -} - -// RegisterLeaseHandler registers the http handlers for service Lease to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterLeaseHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterLeaseHandlerClient(ctx, mux, etcdserverpb.NewLeaseClient(conn)) -} - -// RegisterLeaseHandler registers the http handlers for service Lease to "mux". -// The handlers forward requests to the grpc endpoint over the given implementation of "LeaseClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "LeaseClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "LeaseClient" to call the correct interceptors. -func RegisterLeaseHandlerClient(ctx context.Context, mux *runtime.ServeMux, client etcdserverpb.LeaseClient) error { - - mux.Handle("POST", pattern_Lease_LeaseGrant_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lease_LeaseGrant_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseGrant_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseRevoke_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lease_LeaseRevoke_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseRevoke_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseKeepAlive_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lease_LeaseKeepAlive_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseKeepAlive_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseTimeToLive_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lease_LeaseTimeToLive_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseTimeToLive_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseLeases_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lease_LeaseLeases_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseLeases_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Lease_LeaseGrant_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "lease", "grant"}, "")) - - pattern_Lease_LeaseRevoke_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "kv", "lease", "revoke"}, "")) - - pattern_Lease_LeaseKeepAlive_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "lease", "keepalive"}, "")) - - pattern_Lease_LeaseTimeToLive_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "kv", "lease", "timetolive"}, "")) - - pattern_Lease_LeaseLeases_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "kv", "lease", "leases"}, "")) -) - -var ( - forward_Lease_LeaseGrant_0 = runtime.ForwardResponseMessage - - forward_Lease_LeaseRevoke_0 = runtime.ForwardResponseMessage - - forward_Lease_LeaseKeepAlive_0 = runtime.ForwardResponseStream - - forward_Lease_LeaseTimeToLive_0 = runtime.ForwardResponseMessage - - forward_Lease_LeaseLeases_0 = runtime.ForwardResponseMessage -) - -// RegisterClusterHandlerFromEndpoint is same as RegisterClusterHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterClusterHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterClusterHandler(ctx, mux, conn) -} - -// RegisterClusterHandler registers the http handlers for service Cluster to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterClusterHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterClusterHandlerClient(ctx, mux, etcdserverpb.NewClusterClient(conn)) -} - -// RegisterClusterHandler registers the http handlers for service Cluster to "mux". -// The handlers forward requests to the grpc endpoint over the given implementation of "ClusterClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "ClusterClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "ClusterClient" to call the correct interceptors. -func RegisterClusterHandlerClient(ctx context.Context, mux *runtime.ServeMux, client etcdserverpb.ClusterClient) error { - - mux.Handle("POST", pattern_Cluster_MemberAdd_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Cluster_MemberAdd_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Cluster_MemberAdd_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Cluster_MemberRemove_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Cluster_MemberRemove_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Cluster_MemberRemove_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Cluster_MemberUpdate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Cluster_MemberUpdate_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Cluster_MemberUpdate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Cluster_MemberList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Cluster_MemberList_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Cluster_MemberList_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Cluster_MemberAdd_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "cluster", "member", "add"}, "")) - - pattern_Cluster_MemberRemove_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "cluster", "member", "remove"}, "")) - - pattern_Cluster_MemberUpdate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "cluster", "member", "update"}, "")) - - pattern_Cluster_MemberList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "cluster", "member", "list"}, "")) -) - -var ( - forward_Cluster_MemberAdd_0 = runtime.ForwardResponseMessage - - forward_Cluster_MemberRemove_0 = runtime.ForwardResponseMessage - - forward_Cluster_MemberUpdate_0 = runtime.ForwardResponseMessage - - forward_Cluster_MemberList_0 = runtime.ForwardResponseMessage -) - -// RegisterMaintenanceHandlerFromEndpoint is same as RegisterMaintenanceHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterMaintenanceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterMaintenanceHandler(ctx, mux, conn) -} - -// RegisterMaintenanceHandler registers the http handlers for service Maintenance to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterMaintenanceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterMaintenanceHandlerClient(ctx, mux, etcdserverpb.NewMaintenanceClient(conn)) -} - -// RegisterMaintenanceHandler registers the http handlers for service Maintenance to "mux". -// The handlers forward requests to the grpc endpoint over the given implementation of "MaintenanceClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "MaintenanceClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "MaintenanceClient" to call the correct interceptors. -func RegisterMaintenanceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client etcdserverpb.MaintenanceClient) error { - - mux.Handle("POST", pattern_Maintenance_Alarm_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_Alarm_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Alarm_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_Status_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_Status_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Status_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_Defragment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_Defragment_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Defragment_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_Hash_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_Hash_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Hash_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_HashKV_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_HashKV_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_HashKV_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_Snapshot_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_Snapshot_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Snapshot_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_MoveLeader_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_MoveLeader_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_MoveLeader_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Maintenance_Alarm_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "maintenance", "alarm"}, "")) - - pattern_Maintenance_Status_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "maintenance", "status"}, "")) - - pattern_Maintenance_Defragment_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "maintenance", "defragment"}, "")) - - pattern_Maintenance_Hash_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "maintenance", "hash"}, "")) - - pattern_Maintenance_HashKV_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "maintenance", "hash"}, "")) - - pattern_Maintenance_Snapshot_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "maintenance", "snapshot"}, "")) - - pattern_Maintenance_MoveLeader_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "maintenance", "transfer-leadership"}, "")) -) - -var ( - forward_Maintenance_Alarm_0 = runtime.ForwardResponseMessage - - forward_Maintenance_Status_0 = runtime.ForwardResponseMessage - - forward_Maintenance_Defragment_0 = runtime.ForwardResponseMessage - - forward_Maintenance_Hash_0 = runtime.ForwardResponseMessage - - forward_Maintenance_HashKV_0 = runtime.ForwardResponseMessage - - forward_Maintenance_Snapshot_0 = runtime.ForwardResponseStream - - forward_Maintenance_MoveLeader_0 = runtime.ForwardResponseMessage -) - -// RegisterAuthHandlerFromEndpoint is same as RegisterAuthHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterAuthHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterAuthHandler(ctx, mux, conn) -} - -// RegisterAuthHandler registers the http handlers for service Auth to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterAuthHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterAuthHandlerClient(ctx, mux, etcdserverpb.NewAuthClient(conn)) -} - -// RegisterAuthHandler registers the http handlers for service Auth to "mux". -// The handlers forward requests to the grpc endpoint over the given implementation of "AuthClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "AuthClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "AuthClient" to call the correct interceptors. -func RegisterAuthHandlerClient(ctx context.Context, mux *runtime.ServeMux, client etcdserverpb.AuthClient) error { - - mux.Handle("POST", pattern_Auth_AuthEnable_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_AuthEnable_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_AuthEnable_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_AuthDisable_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_AuthDisable_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_AuthDisable_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_Authenticate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_Authenticate_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_Authenticate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserAdd_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserAdd_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserAdd_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserGet_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserGet_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserGet_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserList_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserList_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserDelete_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserDelete_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserDelete_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserChangePassword_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserChangePassword_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserChangePassword_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserGrantRole_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserGrantRole_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserGrantRole_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserRevokeRole_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserRevokeRole_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserRevokeRole_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleAdd_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_RoleAdd_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleAdd_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleGet_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_RoleGet_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleGet_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_RoleList_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleList_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleDelete_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_RoleDelete_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleDelete_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleGrantPermission_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_RoleGrantPermission_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleGrantPermission_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleRevokePermission_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_RoleRevokePermission_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleRevokePermission_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Auth_AuthEnable_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "auth", "enable"}, "")) - - pattern_Auth_AuthDisable_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "auth", "disable"}, "")) - - pattern_Auth_Authenticate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3beta", "auth", "authenticate"}, "")) - - pattern_Auth_UserAdd_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "user", "add"}, "")) - - pattern_Auth_UserGet_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "user", "get"}, "")) - - pattern_Auth_UserList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "user", "list"}, "")) - - pattern_Auth_UserDelete_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "user", "delete"}, "")) - - pattern_Auth_UserChangePassword_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "user", "changepw"}, "")) - - pattern_Auth_UserGrantRole_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "user", "grant"}, "")) - - pattern_Auth_UserRevokeRole_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "user", "revoke"}, "")) - - pattern_Auth_RoleAdd_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "role", "add"}, "")) - - pattern_Auth_RoleGet_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "role", "get"}, "")) - - pattern_Auth_RoleList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "role", "list"}, "")) - - pattern_Auth_RoleDelete_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "role", "delete"}, "")) - - pattern_Auth_RoleGrantPermission_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "role", "grant"}, "")) - - pattern_Auth_RoleRevokePermission_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3beta", "auth", "role", "revoke"}, "")) -) - -var ( - forward_Auth_AuthEnable_0 = runtime.ForwardResponseMessage - - forward_Auth_AuthDisable_0 = runtime.ForwardResponseMessage - - forward_Auth_Authenticate_0 = runtime.ForwardResponseMessage - - forward_Auth_UserAdd_0 = runtime.ForwardResponseMessage - - forward_Auth_UserGet_0 = runtime.ForwardResponseMessage - - forward_Auth_UserList_0 = runtime.ForwardResponseMessage - - forward_Auth_UserDelete_0 = runtime.ForwardResponseMessage - - forward_Auth_UserChangePassword_0 = runtime.ForwardResponseMessage - - forward_Auth_UserGrantRole_0 = runtime.ForwardResponseMessage - - forward_Auth_UserRevokeRole_0 = runtime.ForwardResponseMessage - - forward_Auth_RoleAdd_0 = runtime.ForwardResponseMessage - - forward_Auth_RoleGet_0 = runtime.ForwardResponseMessage - - forward_Auth_RoleList_0 = runtime.ForwardResponseMessage - - forward_Auth_RoleDelete_0 = runtime.ForwardResponseMessage - - forward_Auth_RoleGrantPermission_0 = runtime.ForwardResponseMessage - - forward_Auth_RoleRevokePermission_0 = runtime.ForwardResponseMessage -) diff --git a/vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/raft_internal.pb.go b/vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/raft_internal.pb.go deleted file mode 100644 index 3084c6cbf864..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/raft_internal.pb.go +++ /dev/null @@ -1,2077 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: raft_internal.proto - -package etcdserverpb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -type RequestHeader struct { - ID uint64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` - // username is a username that is associated with an auth token of gRPC connection - Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"` - // auth_revision is a revision number of auth.authStore. It is not related to mvcc - AuthRevision uint64 `protobuf:"varint,3,opt,name=auth_revision,json=authRevision,proto3" json:"auth_revision,omitempty"` -} - -func (m *RequestHeader) Reset() { *m = RequestHeader{} } -func (m *RequestHeader) String() string { return proto.CompactTextString(m) } -func (*RequestHeader) ProtoMessage() {} -func (*RequestHeader) Descriptor() ([]byte, []int) { return fileDescriptorRaftInternal, []int{0} } - -// An InternalRaftRequest is the union of all requests which can be -// sent via raft. -type InternalRaftRequest struct { - Header *RequestHeader `protobuf:"bytes,100,opt,name=header" json:"header,omitempty"` - ID uint64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` - V2 *Request `protobuf:"bytes,2,opt,name=v2" json:"v2,omitempty"` - Range *RangeRequest `protobuf:"bytes,3,opt,name=range" json:"range,omitempty"` - Put *PutRequest `protobuf:"bytes,4,opt,name=put" json:"put,omitempty"` - DeleteRange *DeleteRangeRequest `protobuf:"bytes,5,opt,name=delete_range,json=deleteRange" json:"delete_range,omitempty"` - Txn *TxnRequest `protobuf:"bytes,6,opt,name=txn" json:"txn,omitempty"` - Compaction *CompactionRequest `protobuf:"bytes,7,opt,name=compaction" json:"compaction,omitempty"` - LeaseGrant *LeaseGrantRequest `protobuf:"bytes,8,opt,name=lease_grant,json=leaseGrant" json:"lease_grant,omitempty"` - LeaseRevoke *LeaseRevokeRequest `protobuf:"bytes,9,opt,name=lease_revoke,json=leaseRevoke" json:"lease_revoke,omitempty"` - Alarm *AlarmRequest `protobuf:"bytes,10,opt,name=alarm" json:"alarm,omitempty"` - AuthEnable *AuthEnableRequest `protobuf:"bytes,1000,opt,name=auth_enable,json=authEnable" json:"auth_enable,omitempty"` - AuthDisable *AuthDisableRequest `protobuf:"bytes,1011,opt,name=auth_disable,json=authDisable" json:"auth_disable,omitempty"` - Authenticate *InternalAuthenticateRequest `protobuf:"bytes,1012,opt,name=authenticate" json:"authenticate,omitempty"` - AuthUserAdd *AuthUserAddRequest `protobuf:"bytes,1100,opt,name=auth_user_add,json=authUserAdd" json:"auth_user_add,omitempty"` - AuthUserDelete *AuthUserDeleteRequest `protobuf:"bytes,1101,opt,name=auth_user_delete,json=authUserDelete" json:"auth_user_delete,omitempty"` - AuthUserGet *AuthUserGetRequest `protobuf:"bytes,1102,opt,name=auth_user_get,json=authUserGet" json:"auth_user_get,omitempty"` - AuthUserChangePassword *AuthUserChangePasswordRequest `protobuf:"bytes,1103,opt,name=auth_user_change_password,json=authUserChangePassword" json:"auth_user_change_password,omitempty"` - AuthUserGrantRole *AuthUserGrantRoleRequest `protobuf:"bytes,1104,opt,name=auth_user_grant_role,json=authUserGrantRole" json:"auth_user_grant_role,omitempty"` - AuthUserRevokeRole *AuthUserRevokeRoleRequest `protobuf:"bytes,1105,opt,name=auth_user_revoke_role,json=authUserRevokeRole" json:"auth_user_revoke_role,omitempty"` - AuthUserList *AuthUserListRequest `protobuf:"bytes,1106,opt,name=auth_user_list,json=authUserList" json:"auth_user_list,omitempty"` - AuthRoleList *AuthRoleListRequest `protobuf:"bytes,1107,opt,name=auth_role_list,json=authRoleList" json:"auth_role_list,omitempty"` - AuthRoleAdd *AuthRoleAddRequest `protobuf:"bytes,1200,opt,name=auth_role_add,json=authRoleAdd" json:"auth_role_add,omitempty"` - AuthRoleDelete *AuthRoleDeleteRequest `protobuf:"bytes,1201,opt,name=auth_role_delete,json=authRoleDelete" json:"auth_role_delete,omitempty"` - AuthRoleGet *AuthRoleGetRequest `protobuf:"bytes,1202,opt,name=auth_role_get,json=authRoleGet" json:"auth_role_get,omitempty"` - AuthRoleGrantPermission *AuthRoleGrantPermissionRequest `protobuf:"bytes,1203,opt,name=auth_role_grant_permission,json=authRoleGrantPermission" json:"auth_role_grant_permission,omitempty"` - AuthRoleRevokePermission *AuthRoleRevokePermissionRequest `protobuf:"bytes,1204,opt,name=auth_role_revoke_permission,json=authRoleRevokePermission" json:"auth_role_revoke_permission,omitempty"` -} - -func (m *InternalRaftRequest) Reset() { *m = InternalRaftRequest{} } -func (m *InternalRaftRequest) String() string { return proto.CompactTextString(m) } -func (*InternalRaftRequest) ProtoMessage() {} -func (*InternalRaftRequest) Descriptor() ([]byte, []int) { return fileDescriptorRaftInternal, []int{1} } - -type EmptyResponse struct { -} - -func (m *EmptyResponse) Reset() { *m = EmptyResponse{} } -func (m *EmptyResponse) String() string { return proto.CompactTextString(m) } -func (*EmptyResponse) ProtoMessage() {} -func (*EmptyResponse) Descriptor() ([]byte, []int) { return fileDescriptorRaftInternal, []int{2} } - -// What is the difference between AuthenticateRequest (defined in rpc.proto) and InternalAuthenticateRequest? -// InternalAuthenticateRequest has a member that is filled by etcdserver and shouldn't be user-facing. -// For avoiding misusage the field, we have an internal version of AuthenticateRequest. -type InternalAuthenticateRequest struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` - // simple_token is generated in API layer (etcdserver/v3_server.go) - SimpleToken string `protobuf:"bytes,3,opt,name=simple_token,json=simpleToken,proto3" json:"simple_token,omitempty"` -} - -func (m *InternalAuthenticateRequest) Reset() { *m = InternalAuthenticateRequest{} } -func (m *InternalAuthenticateRequest) String() string { return proto.CompactTextString(m) } -func (*InternalAuthenticateRequest) ProtoMessage() {} -func (*InternalAuthenticateRequest) Descriptor() ([]byte, []int) { - return fileDescriptorRaftInternal, []int{3} -} - -func init() { - proto.RegisterType((*RequestHeader)(nil), "etcdserverpb.RequestHeader") - proto.RegisterType((*InternalRaftRequest)(nil), "etcdserverpb.InternalRaftRequest") - proto.RegisterType((*EmptyResponse)(nil), "etcdserverpb.EmptyResponse") - proto.RegisterType((*InternalAuthenticateRequest)(nil), "etcdserverpb.InternalAuthenticateRequest") -} -func (m *RequestHeader) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *RequestHeader) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.ID)) - } - if len(m.Username) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(len(m.Username))) - i += copy(dAtA[i:], m.Username) - } - if m.AuthRevision != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthRevision)) - } - return i, nil -} - -func (m *InternalRaftRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *InternalRaftRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.ID)) - } - if m.V2 != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.V2.Size())) - n1, err := m.V2.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - } - if m.Range != nil { - dAtA[i] = 0x1a - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.Range.Size())) - n2, err := m.Range.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - } - if m.Put != nil { - dAtA[i] = 0x22 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.Put.Size())) - n3, err := m.Put.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n3 - } - if m.DeleteRange != nil { - dAtA[i] = 0x2a - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.DeleteRange.Size())) - n4, err := m.DeleteRange.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n4 - } - if m.Txn != nil { - dAtA[i] = 0x32 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.Txn.Size())) - n5, err := m.Txn.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n5 - } - if m.Compaction != nil { - dAtA[i] = 0x3a - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.Compaction.Size())) - n6, err := m.Compaction.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n6 - } - if m.LeaseGrant != nil { - dAtA[i] = 0x42 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.LeaseGrant.Size())) - n7, err := m.LeaseGrant.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n7 - } - if m.LeaseRevoke != nil { - dAtA[i] = 0x4a - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.LeaseRevoke.Size())) - n8, err := m.LeaseRevoke.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n8 - } - if m.Alarm != nil { - dAtA[i] = 0x52 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.Alarm.Size())) - n9, err := m.Alarm.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n9 - } - if m.Header != nil { - dAtA[i] = 0xa2 - i++ - dAtA[i] = 0x6 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.Header.Size())) - n10, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n10 - } - if m.AuthEnable != nil { - dAtA[i] = 0xc2 - i++ - dAtA[i] = 0x3e - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthEnable.Size())) - n11, err := m.AuthEnable.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n11 - } - if m.AuthDisable != nil { - dAtA[i] = 0x9a - i++ - dAtA[i] = 0x3f - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthDisable.Size())) - n12, err := m.AuthDisable.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n12 - } - if m.Authenticate != nil { - dAtA[i] = 0xa2 - i++ - dAtA[i] = 0x3f - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.Authenticate.Size())) - n13, err := m.Authenticate.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n13 - } - if m.AuthUserAdd != nil { - dAtA[i] = 0xe2 - i++ - dAtA[i] = 0x44 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthUserAdd.Size())) - n14, err := m.AuthUserAdd.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n14 - } - if m.AuthUserDelete != nil { - dAtA[i] = 0xea - i++ - dAtA[i] = 0x44 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthUserDelete.Size())) - n15, err := m.AuthUserDelete.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n15 - } - if m.AuthUserGet != nil { - dAtA[i] = 0xf2 - i++ - dAtA[i] = 0x44 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthUserGet.Size())) - n16, err := m.AuthUserGet.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n16 - } - if m.AuthUserChangePassword != nil { - dAtA[i] = 0xfa - i++ - dAtA[i] = 0x44 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthUserChangePassword.Size())) - n17, err := m.AuthUserChangePassword.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n17 - } - if m.AuthUserGrantRole != nil { - dAtA[i] = 0x82 - i++ - dAtA[i] = 0x45 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthUserGrantRole.Size())) - n18, err := m.AuthUserGrantRole.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n18 - } - if m.AuthUserRevokeRole != nil { - dAtA[i] = 0x8a - i++ - dAtA[i] = 0x45 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthUserRevokeRole.Size())) - n19, err := m.AuthUserRevokeRole.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n19 - } - if m.AuthUserList != nil { - dAtA[i] = 0x92 - i++ - dAtA[i] = 0x45 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthUserList.Size())) - n20, err := m.AuthUserList.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n20 - } - if m.AuthRoleList != nil { - dAtA[i] = 0x9a - i++ - dAtA[i] = 0x45 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthRoleList.Size())) - n21, err := m.AuthRoleList.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n21 - } - if m.AuthRoleAdd != nil { - dAtA[i] = 0x82 - i++ - dAtA[i] = 0x4b - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthRoleAdd.Size())) - n22, err := m.AuthRoleAdd.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n22 - } - if m.AuthRoleDelete != nil { - dAtA[i] = 0x8a - i++ - dAtA[i] = 0x4b - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthRoleDelete.Size())) - n23, err := m.AuthRoleDelete.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n23 - } - if m.AuthRoleGet != nil { - dAtA[i] = 0x92 - i++ - dAtA[i] = 0x4b - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthRoleGet.Size())) - n24, err := m.AuthRoleGet.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n24 - } - if m.AuthRoleGrantPermission != nil { - dAtA[i] = 0x9a - i++ - dAtA[i] = 0x4b - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthRoleGrantPermission.Size())) - n25, err := m.AuthRoleGrantPermission.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n25 - } - if m.AuthRoleRevokePermission != nil { - dAtA[i] = 0xa2 - i++ - dAtA[i] = 0x4b - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthRoleRevokePermission.Size())) - n26, err := m.AuthRoleRevokePermission.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n26 - } - return i, nil -} - -func (m *EmptyResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *EmptyResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *InternalAuthenticateRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *InternalAuthenticateRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.Password) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(len(m.Password))) - i += copy(dAtA[i:], m.Password) - } - if len(m.SimpleToken) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintRaftInternal(dAtA, i, uint64(len(m.SimpleToken))) - i += copy(dAtA[i:], m.SimpleToken) - } - return i, nil -} - -func encodeVarintRaftInternal(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *RequestHeader) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovRaftInternal(uint64(m.ID)) - } - l = len(m.Username) - if l > 0 { - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.AuthRevision != 0 { - n += 1 + sovRaftInternal(uint64(m.AuthRevision)) - } - return n -} - -func (m *InternalRaftRequest) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovRaftInternal(uint64(m.ID)) - } - if m.V2 != nil { - l = m.V2.Size() - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.Range != nil { - l = m.Range.Size() - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.Put != nil { - l = m.Put.Size() - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.DeleteRange != nil { - l = m.DeleteRange.Size() - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.Txn != nil { - l = m.Txn.Size() - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.Compaction != nil { - l = m.Compaction.Size() - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.LeaseGrant != nil { - l = m.LeaseGrant.Size() - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.LeaseRevoke != nil { - l = m.LeaseRevoke.Size() - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.Alarm != nil { - l = m.Alarm.Size() - n += 1 + l + sovRaftInternal(uint64(l)) - } - if m.Header != nil { - l = m.Header.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthEnable != nil { - l = m.AuthEnable.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthDisable != nil { - l = m.AuthDisable.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.Authenticate != nil { - l = m.Authenticate.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthUserAdd != nil { - l = m.AuthUserAdd.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthUserDelete != nil { - l = m.AuthUserDelete.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthUserGet != nil { - l = m.AuthUserGet.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthUserChangePassword != nil { - l = m.AuthUserChangePassword.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthUserGrantRole != nil { - l = m.AuthUserGrantRole.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthUserRevokeRole != nil { - l = m.AuthUserRevokeRole.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthUserList != nil { - l = m.AuthUserList.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthRoleList != nil { - l = m.AuthRoleList.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthRoleAdd != nil { - l = m.AuthRoleAdd.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthRoleDelete != nil { - l = m.AuthRoleDelete.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthRoleGet != nil { - l = m.AuthRoleGet.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthRoleGrantPermission != nil { - l = m.AuthRoleGrantPermission.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - if m.AuthRoleRevokePermission != nil { - l = m.AuthRoleRevokePermission.Size() - n += 2 + l + sovRaftInternal(uint64(l)) - } - return n -} - -func (m *EmptyResponse) Size() (n int) { - var l int - _ = l - return n -} - -func (m *InternalAuthenticateRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRaftInternal(uint64(l)) - } - l = len(m.Password) - if l > 0 { - n += 1 + l + sovRaftInternal(uint64(l)) - } - l = len(m.SimpleToken) - if l > 0 { - n += 1 + l + sovRaftInternal(uint64(l)) - } - return n -} - -func sovRaftInternal(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozRaftInternal(x uint64) (n int) { - return sovRaftInternal(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *RequestHeader) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: RequestHeader: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: RequestHeader: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Username", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Username = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthRevision", wireType) - } - m.AuthRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.AuthRevision |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRaftInternal(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaftInternal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *InternalRaftRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: InternalRaftRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: InternalRaftRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field V2", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.V2 == nil { - m.V2 = &Request{} - } - if err := m.V2.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Range", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Range == nil { - m.Range = &RangeRequest{} - } - if err := m.Range.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Put", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Put == nil { - m.Put = &PutRequest{} - } - if err := m.Put.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field DeleteRange", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.DeleteRange == nil { - m.DeleteRange = &DeleteRangeRequest{} - } - if err := m.DeleteRange.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Txn", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Txn == nil { - m.Txn = &TxnRequest{} - } - if err := m.Txn.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Compaction", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Compaction == nil { - m.Compaction = &CompactionRequest{} - } - if err := m.Compaction.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 8: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field LeaseGrant", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.LeaseGrant == nil { - m.LeaseGrant = &LeaseGrantRequest{} - } - if err := m.LeaseGrant.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 9: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field LeaseRevoke", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.LeaseRevoke == nil { - m.LeaseRevoke = &LeaseRevokeRequest{} - } - if err := m.LeaseRevoke.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 10: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Alarm", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Alarm == nil { - m.Alarm = &AlarmRequest{} - } - if err := m.Alarm.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 100: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &RequestHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1000: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthEnable", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthEnable == nil { - m.AuthEnable = &AuthEnableRequest{} - } - if err := m.AuthEnable.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1011: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthDisable", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthDisable == nil { - m.AuthDisable = &AuthDisableRequest{} - } - if err := m.AuthDisable.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1012: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Authenticate", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Authenticate == nil { - m.Authenticate = &InternalAuthenticateRequest{} - } - if err := m.Authenticate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1100: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthUserAdd", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthUserAdd == nil { - m.AuthUserAdd = &AuthUserAddRequest{} - } - if err := m.AuthUserAdd.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1101: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthUserDelete", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthUserDelete == nil { - m.AuthUserDelete = &AuthUserDeleteRequest{} - } - if err := m.AuthUserDelete.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1102: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthUserGet", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthUserGet == nil { - m.AuthUserGet = &AuthUserGetRequest{} - } - if err := m.AuthUserGet.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1103: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthUserChangePassword", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthUserChangePassword == nil { - m.AuthUserChangePassword = &AuthUserChangePasswordRequest{} - } - if err := m.AuthUserChangePassword.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1104: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthUserGrantRole", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthUserGrantRole == nil { - m.AuthUserGrantRole = &AuthUserGrantRoleRequest{} - } - if err := m.AuthUserGrantRole.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1105: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthUserRevokeRole", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthUserRevokeRole == nil { - m.AuthUserRevokeRole = &AuthUserRevokeRoleRequest{} - } - if err := m.AuthUserRevokeRole.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1106: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthUserList", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthUserList == nil { - m.AuthUserList = &AuthUserListRequest{} - } - if err := m.AuthUserList.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1107: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthRoleList", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthRoleList == nil { - m.AuthRoleList = &AuthRoleListRequest{} - } - if err := m.AuthRoleList.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1200: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthRoleAdd", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthRoleAdd == nil { - m.AuthRoleAdd = &AuthRoleAddRequest{} - } - if err := m.AuthRoleAdd.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1201: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthRoleDelete", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthRoleDelete == nil { - m.AuthRoleDelete = &AuthRoleDeleteRequest{} - } - if err := m.AuthRoleDelete.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1202: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthRoleGet", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthRoleGet == nil { - m.AuthRoleGet = &AuthRoleGetRequest{} - } - if err := m.AuthRoleGet.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1203: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthRoleGrantPermission", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthRoleGrantPermission == nil { - m.AuthRoleGrantPermission = &AuthRoleGrantPermissionRequest{} - } - if err := m.AuthRoleGrantPermission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 1204: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthRoleRevokePermission", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthRoleRevokePermission == nil { - m.AuthRoleRevokePermission = &AuthRoleRevokePermissionRequest{} - } - if err := m.AuthRoleRevokePermission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRaftInternal(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaftInternal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *EmptyResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: EmptyResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: EmptyResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRaftInternal(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaftInternal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *InternalAuthenticateRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: InternalAuthenticateRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: InternalAuthenticateRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Password", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Password = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SimpleToken", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRaftInternal - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SimpleToken = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRaftInternal(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaftInternal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipRaftInternal(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthRaftInternal - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaftInternal - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipRaftInternal(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthRaftInternal = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowRaftInternal = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("raft_internal.proto", fileDescriptorRaftInternal) } - -var fileDescriptorRaftInternal = []byte{ - // 837 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x96, 0xdd, 0x52, 0xd3, 0x40, - 0x14, 0xc7, 0x69, 0xf9, 0xec, 0xb6, 0x54, 0x5c, 0x40, 0xd7, 0x32, 0x53, 0xa1, 0x8c, 0x8a, 0x5f, - 0xe8, 0x94, 0x07, 0xd0, 0x4a, 0x19, 0x60, 0x86, 0x61, 0x98, 0x0c, 0xce, 0x38, 0xe3, 0x45, 0x5c, - 0x9a, 0x43, 0x1b, 0x49, 0x93, 0xb8, 0xd9, 0x56, 0x7c, 0x13, 0x1f, 0xc3, 0xaf, 0x87, 0xe0, 0xc2, - 0x0f, 0xd4, 0x17, 0x50, 0xbc, 0xf1, 0xca, 0x1b, 0x7d, 0x00, 0x67, 0x3f, 0x92, 0x34, 0x6d, 0xca, - 0x5d, 0x72, 0xce, 0xff, 0xfc, 0xce, 0xd9, 0xec, 0x7f, 0xbb, 0x45, 0xb3, 0x8c, 0x1e, 0x72, 0xd3, - 0x76, 0x39, 0x30, 0x97, 0x3a, 0xab, 0x3e, 0xf3, 0xb8, 0x87, 0x0b, 0xc0, 0x1b, 0x56, 0x00, 0xac, - 0x0b, 0xcc, 0x3f, 0x28, 0xcd, 0x35, 0xbd, 0xa6, 0x27, 0x13, 0xf7, 0xc4, 0x93, 0xd2, 0x94, 0x66, - 0x62, 0x8d, 0x8e, 0xe4, 0x98, 0xdf, 0x50, 0x8f, 0x95, 0x67, 0x68, 0xda, 0x80, 0x17, 0x1d, 0x08, - 0xf8, 0x16, 0x50, 0x0b, 0x18, 0x2e, 0xa2, 0xec, 0x76, 0x9d, 0x64, 0x16, 0x33, 0x2b, 0x63, 0x46, - 0x76, 0xbb, 0x8e, 0x4b, 0x68, 0xaa, 0x13, 0x88, 0x96, 0x6d, 0x20, 0xd9, 0xc5, 0xcc, 0x4a, 0xce, - 0x88, 0xde, 0xf1, 0x32, 0x9a, 0xa6, 0x1d, 0xde, 0x32, 0x19, 0x74, 0xed, 0xc0, 0xf6, 0x5c, 0x32, - 0x2a, 0xcb, 0x0a, 0x22, 0x68, 0xe8, 0x58, 0xe5, 0x4f, 0x11, 0xcd, 0x6e, 0xeb, 0xa9, 0x0d, 0x7a, - 0xc8, 0x75, 0xbb, 0x81, 0x46, 0xd7, 0x50, 0xb6, 0x5b, 0x95, 0x2d, 0xf2, 0xd5, 0xf9, 0xd5, 0xde, - 0x75, 0xad, 0xea, 0x12, 0x23, 0xdb, 0xad, 0xe2, 0xfb, 0x68, 0x9c, 0x51, 0xb7, 0x09, 0xb2, 0x57, - 0xbe, 0x5a, 0xea, 0x53, 0x8a, 0x54, 0x28, 0x57, 0x42, 0x7c, 0x0b, 0x8d, 0xfa, 0x1d, 0x4e, 0xc6, - 0xa4, 0x9e, 0x24, 0xf5, 0x7b, 0x9d, 0x70, 0x1e, 0x43, 0x88, 0xf0, 0x3a, 0x2a, 0x58, 0xe0, 0x00, - 0x07, 0x53, 0x35, 0x19, 0x97, 0x45, 0x8b, 0xc9, 0xa2, 0xba, 0x54, 0x24, 0x5a, 0xe5, 0xad, 0x38, - 0x26, 0x1a, 0xf2, 0x63, 0x97, 0x4c, 0xa4, 0x35, 0xdc, 0x3f, 0x76, 0xa3, 0x86, 0xfc, 0xd8, 0xc5, - 0x0f, 0x10, 0x6a, 0x78, 0x6d, 0x9f, 0x36, 0xb8, 0xf8, 0x7e, 0x93, 0xb2, 0xe4, 0x6a, 0xb2, 0x64, - 0x3d, 0xca, 0x87, 0x95, 0x3d, 0x25, 0xf8, 0x21, 0xca, 0x3b, 0x40, 0x03, 0x30, 0x9b, 0x8c, 0xba, - 0x9c, 0x4c, 0xa5, 0x11, 0x76, 0x84, 0x60, 0x53, 0xe4, 0x23, 0x82, 0x13, 0x85, 0xc4, 0x9a, 0x15, - 0x81, 0x41, 0xd7, 0x3b, 0x02, 0x92, 0x4b, 0x5b, 0xb3, 0x44, 0x18, 0x52, 0x10, 0xad, 0xd9, 0x89, - 0x63, 0x62, 0x5b, 0xa8, 0x43, 0x59, 0x9b, 0xa0, 0xb4, 0x6d, 0xa9, 0x89, 0x54, 0xb4, 0x2d, 0x52, - 0x88, 0xd7, 0xd0, 0x44, 0x4b, 0x5a, 0x8e, 0x58, 0xb2, 0x64, 0x21, 0x75, 0xcf, 0x95, 0x2b, 0x0d, - 0x2d, 0xc5, 0x35, 0x94, 0x97, 0x8e, 0x03, 0x97, 0x1e, 0x38, 0x40, 0x7e, 0xa7, 0x7e, 0xb0, 0x5a, - 0x87, 0xb7, 0x36, 0xa4, 0x20, 0x5a, 0x2e, 0x8d, 0x42, 0xb8, 0x8e, 0xa4, 0x3f, 0x4d, 0xcb, 0x0e, - 0x24, 0xe3, 0xef, 0x64, 0xda, 0x7a, 0x05, 0xa3, 0xae, 0x14, 0xd1, 0x7a, 0x69, 0x1c, 0xc3, 0xbb, - 0x8a, 0x02, 0x2e, 0xb7, 0x1b, 0x94, 0x03, 0xf9, 0xa7, 0x28, 0x37, 0x93, 0x94, 0xd0, 0xf7, 0xb5, - 0x1e, 0x69, 0x88, 0x4b, 0xd4, 0xe3, 0x0d, 0x7d, 0x94, 0xc4, 0xd9, 0x32, 0xa9, 0x65, 0x91, 0x8f, - 0x53, 0xc3, 0xc6, 0x7a, 0x1c, 0x00, 0xab, 0x59, 0x56, 0x62, 0x2c, 0x1d, 0xc3, 0xbb, 0x68, 0x26, - 0xc6, 0x28, 0x4f, 0x92, 0x4f, 0x8a, 0xb4, 0x9c, 0x4e, 0xd2, 0x66, 0xd6, 0xb0, 0x22, 0x4d, 0x84, - 0x93, 0x63, 0x35, 0x81, 0x93, 0xcf, 0xe7, 0x8e, 0xb5, 0x09, 0x7c, 0x60, 0xac, 0x4d, 0xe0, 0xb8, - 0x89, 0xae, 0xc4, 0x98, 0x46, 0x4b, 0x9c, 0x12, 0xd3, 0xa7, 0x41, 0xf0, 0xd2, 0x63, 0x16, 0xf9, - 0xa2, 0x90, 0xb7, 0xd3, 0x91, 0xeb, 0x52, 0xbd, 0xa7, 0xc5, 0x21, 0xfd, 0x12, 0x4d, 0x4d, 0xe3, - 0x27, 0x68, 0xae, 0x67, 0x5e, 0x61, 0x6f, 0x93, 0x79, 0x0e, 0x90, 0x53, 0xd5, 0xe3, 0xfa, 0x90, - 0xb1, 0xe5, 0xd1, 0xf0, 0xe2, 0xad, 0xbe, 0x48, 0xfb, 0x33, 0xf8, 0x29, 0x9a, 0x8f, 0xc9, 0xea, - 0xa4, 0x28, 0xf4, 0x57, 0x85, 0xbe, 0x91, 0x8e, 0xd6, 0x47, 0xa6, 0x87, 0x8d, 0xe9, 0x40, 0x0a, - 0x6f, 0xa1, 0x62, 0x0c, 0x77, 0xec, 0x80, 0x93, 0x6f, 0x8a, 0xba, 0x94, 0x4e, 0xdd, 0xb1, 0x03, - 0x9e, 0xf0, 0x51, 0x18, 0x8c, 0x48, 0x62, 0x34, 0x45, 0xfa, 0x3e, 0x94, 0x24, 0x5a, 0x0f, 0x90, - 0xc2, 0x60, 0xb4, 0xf5, 0x92, 0x24, 0x1c, 0xf9, 0x26, 0x37, 0x6c, 0xeb, 0x45, 0x4d, 0xbf, 0x23, - 0x75, 0x2c, 0x72, 0xa4, 0xc4, 0x68, 0x47, 0xbe, 0xcd, 0x0d, 0x73, 0xa4, 0xa8, 0x4a, 0x71, 0x64, - 0x1c, 0x4e, 0x8e, 0x25, 0x1c, 0xf9, 0xee, 0xdc, 0xb1, 0xfa, 0x1d, 0xa9, 0x63, 0xf8, 0x39, 0x2a, - 0xf5, 0x60, 0xa4, 0x51, 0x7c, 0x60, 0x6d, 0x3b, 0x90, 0xf7, 0xd8, 0x7b, 0xc5, 0xbc, 0x33, 0x84, - 0x29, 0xe4, 0x7b, 0x91, 0x3a, 0xe4, 0x5f, 0xa6, 0xe9, 0x79, 0xdc, 0x46, 0x0b, 0x71, 0x2f, 0x6d, - 0x9d, 0x9e, 0x66, 0x1f, 0x54, 0xb3, 0xbb, 0xe9, 0xcd, 0x94, 0x4b, 0x06, 0xbb, 0x11, 0x3a, 0x44, - 0x50, 0xb9, 0x80, 0xa6, 0x37, 0xda, 0x3e, 0x7f, 0x65, 0x40, 0xe0, 0x7b, 0x6e, 0x00, 0x15, 0x1f, - 0x2d, 0x9c, 0xf3, 0x43, 0x84, 0x31, 0x1a, 0x93, 0xb7, 0x7b, 0x46, 0xde, 0xee, 0xf2, 0x59, 0xdc, - 0xfa, 0xd1, 0xf9, 0xd4, 0xb7, 0x7e, 0xf8, 0x8e, 0x97, 0x50, 0x21, 0xb0, 0xdb, 0xbe, 0x03, 0x26, - 0xf7, 0x8e, 0x40, 0x5d, 0xfa, 0x39, 0x23, 0xaf, 0x62, 0xfb, 0x22, 0xf4, 0x68, 0xee, 0xe4, 0x67, - 0x79, 0xe4, 0xe4, 0xac, 0x9c, 0x39, 0x3d, 0x2b, 0x67, 0x7e, 0x9c, 0x95, 0x33, 0xaf, 0x7f, 0x95, - 0x47, 0x0e, 0x26, 0xe4, 0x5f, 0x8e, 0xb5, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xff, 0xc9, 0xfc, - 0x0e, 0xca, 0x08, 0x00, 0x00, -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/raft_internal_stringer.go b/vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/raft_internal_stringer.go deleted file mode 100644 index 3d3536a326dd..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/raft_internal_stringer.go +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserverpb - -import ( - "fmt" - "strings" - - proto "github.com/golang/protobuf/proto" -) - -// InternalRaftStringer implements custom proto Stringer: -// redact password, replace value fields with value_size fields. -type InternalRaftStringer struct { - Request *InternalRaftRequest -} - -func (as *InternalRaftStringer) String() string { - switch { - case as.Request.LeaseGrant != nil: - return fmt.Sprintf("header:<%s> lease_grant:", - as.Request.Header.String(), - as.Request.LeaseGrant.TTL, - as.Request.LeaseGrant.ID, - ) - case as.Request.LeaseRevoke != nil: - return fmt.Sprintf("header:<%s> lease_revoke:", - as.Request.Header.String(), - as.Request.LeaseRevoke.ID, - ) - case as.Request.Authenticate != nil: - return fmt.Sprintf("header:<%s> authenticate:", - as.Request.Header.String(), - as.Request.Authenticate.Name, - as.Request.Authenticate.SimpleToken, - ) - case as.Request.AuthUserAdd != nil: - return fmt.Sprintf("header:<%s> auth_user_add:", - as.Request.Header.String(), - as.Request.AuthUserAdd.Name, - ) - case as.Request.AuthUserChangePassword != nil: - return fmt.Sprintf("header:<%s> auth_user_change_password:", - as.Request.Header.String(), - as.Request.AuthUserChangePassword.Name, - ) - case as.Request.Put != nil: - return fmt.Sprintf("header:<%s> put:<%s>", - as.Request.Header.String(), - NewLoggablePutRequest(as.Request.Put).String(), - ) - case as.Request.Txn != nil: - return fmt.Sprintf("header:<%s> txn:<%s>", - as.Request.Header.String(), - NewLoggableTxnRequest(as.Request.Txn).String(), - ) - default: - // nothing to redact - } - return as.Request.String() -} - -// txnRequestStringer implements a custom proto String to replace value bytes fields with value size -// fields in any nested txn and put operations. -type txnRequestStringer struct { - Request *TxnRequest -} - -func NewLoggableTxnRequest(request *TxnRequest) *txnRequestStringer { - return &txnRequestStringer{request} -} - -func (as *txnRequestStringer) String() string { - var compare []string - for _, c := range as.Request.Compare { - switch cv := c.TargetUnion.(type) { - case *Compare_Value: - compare = append(compare, newLoggableValueCompare(c, cv).String()) - default: - // nothing to redact - compare = append(compare, c.String()) - } - } - var success []string - for _, s := range as.Request.Success { - success = append(success, newLoggableRequestOp(s).String()) - } - var failure []string - for _, f := range as.Request.Failure { - failure = append(failure, newLoggableRequestOp(f).String()) - } - return fmt.Sprintf("compare:<%s> success:<%s> failure:<%s>", - strings.Join(compare, " "), - strings.Join(success, " "), - strings.Join(failure, " "), - ) -} - -// requestOpStringer implements a custom proto String to replace value bytes fields with value -// size fields in any nested txn and put operations. -type requestOpStringer struct { - Op *RequestOp -} - -func newLoggableRequestOp(op *RequestOp) *requestOpStringer { - return &requestOpStringer{op} -} - -func (as *requestOpStringer) String() string { - switch op := as.Op.Request.(type) { - case *RequestOp_RequestPut: - return fmt.Sprintf("request_put:<%s>", NewLoggablePutRequest(op.RequestPut).String()) - case *RequestOp_RequestTxn: - return fmt.Sprintf("request_txn:<%s>", NewLoggableTxnRequest(op.RequestTxn).String()) - default: - // nothing to redact - } - return as.Op.String() -} - -// loggableValueCompare implements a custom proto String for Compare.Value union member types to -// replace the value bytes field with a value size field. -// To preserve proto encoding of the key and range_end bytes, a faked out proto type is used here. -type loggableValueCompare struct { - Result Compare_CompareResult `protobuf:"varint,1,opt,name=result,proto3,enum=etcdserverpb.Compare_CompareResult"` - Target Compare_CompareTarget `protobuf:"varint,2,opt,name=target,proto3,enum=etcdserverpb.Compare_CompareTarget"` - Key []byte `protobuf:"bytes,3,opt,name=key,proto3"` - ValueSize int `protobuf:"bytes,7,opt,name=value_size,proto3"` - RangeEnd []byte `protobuf:"bytes,64,opt,name=range_end,proto3"` -} - -func newLoggableValueCompare(c *Compare, cv *Compare_Value) *loggableValueCompare { - return &loggableValueCompare{ - c.Result, - c.Target, - c.Key, - len(cv.Value), - c.RangeEnd, - } -} - -func (m *loggableValueCompare) Reset() { *m = loggableValueCompare{} } -func (m *loggableValueCompare) String() string { return proto.CompactTextString(m) } -func (*loggableValueCompare) ProtoMessage() {} - -// loggablePutRequest implements a custom proto String to replace value bytes field with a value -// size field. -// To preserve proto encoding of the key bytes, a faked out proto type is used here. -type loggablePutRequest struct { - Key []byte `protobuf:"bytes,1,opt,name=key,proto3"` - ValueSize int `protobuf:"varint,2,opt,name=value_size,proto3"` - Lease int64 `protobuf:"varint,3,opt,name=lease,proto3"` - PrevKv bool `protobuf:"varint,4,opt,name=prev_kv,proto3"` - IgnoreValue bool `protobuf:"varint,5,opt,name=ignore_value,proto3"` - IgnoreLease bool `protobuf:"varint,6,opt,name=ignore_lease,proto3"` -} - -func NewLoggablePutRequest(request *PutRequest) *loggablePutRequest { - return &loggablePutRequest{ - request.Key, - len(request.Value), - request.Lease, - request.PrevKv, - request.IgnoreValue, - request.IgnoreLease, - } -} - -func (m *loggablePutRequest) Reset() { *m = loggablePutRequest{} } -func (m *loggablePutRequest) String() string { return proto.CompactTextString(m) } -func (*loggablePutRequest) ProtoMessage() {} diff --git a/vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/rpc.pb.go b/vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/rpc.pb.go deleted file mode 100644 index 40147f935ab2..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/etcdserverpb/rpc.pb.go +++ /dev/null @@ -1,18665 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: rpc.proto - -package etcdserverpb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - mvccpb "github.com/coreos/etcd/mvcc/mvccpb" - - authpb "github.com/coreos/etcd/auth/authpb" - - context "golang.org/x/net/context" - - grpc "google.golang.org/grpc" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -type AlarmType int32 - -const ( - AlarmType_NONE AlarmType = 0 - AlarmType_NOSPACE AlarmType = 1 - AlarmType_CORRUPT AlarmType = 2 -) - -var AlarmType_name = map[int32]string{ - 0: "NONE", - 1: "NOSPACE", - 2: "CORRUPT", -} -var AlarmType_value = map[string]int32{ - "NONE": 0, - "NOSPACE": 1, - "CORRUPT": 2, -} - -func (x AlarmType) String() string { - return proto.EnumName(AlarmType_name, int32(x)) -} -func (AlarmType) EnumDescriptor() ([]byte, []int) { return fileDescriptorRpc, []int{0} } - -type RangeRequest_SortOrder int32 - -const ( - RangeRequest_NONE RangeRequest_SortOrder = 0 - RangeRequest_ASCEND RangeRequest_SortOrder = 1 - RangeRequest_DESCEND RangeRequest_SortOrder = 2 -) - -var RangeRequest_SortOrder_name = map[int32]string{ - 0: "NONE", - 1: "ASCEND", - 2: "DESCEND", -} -var RangeRequest_SortOrder_value = map[string]int32{ - "NONE": 0, - "ASCEND": 1, - "DESCEND": 2, -} - -func (x RangeRequest_SortOrder) String() string { - return proto.EnumName(RangeRequest_SortOrder_name, int32(x)) -} -func (RangeRequest_SortOrder) EnumDescriptor() ([]byte, []int) { return fileDescriptorRpc, []int{1, 0} } - -type RangeRequest_SortTarget int32 - -const ( - RangeRequest_KEY RangeRequest_SortTarget = 0 - RangeRequest_VERSION RangeRequest_SortTarget = 1 - RangeRequest_CREATE RangeRequest_SortTarget = 2 - RangeRequest_MOD RangeRequest_SortTarget = 3 - RangeRequest_VALUE RangeRequest_SortTarget = 4 -) - -var RangeRequest_SortTarget_name = map[int32]string{ - 0: "KEY", - 1: "VERSION", - 2: "CREATE", - 3: "MOD", - 4: "VALUE", -} -var RangeRequest_SortTarget_value = map[string]int32{ - "KEY": 0, - "VERSION": 1, - "CREATE": 2, - "MOD": 3, - "VALUE": 4, -} - -func (x RangeRequest_SortTarget) String() string { - return proto.EnumName(RangeRequest_SortTarget_name, int32(x)) -} -func (RangeRequest_SortTarget) EnumDescriptor() ([]byte, []int) { return fileDescriptorRpc, []int{1, 1} } - -type Compare_CompareResult int32 - -const ( - Compare_EQUAL Compare_CompareResult = 0 - Compare_GREATER Compare_CompareResult = 1 - Compare_LESS Compare_CompareResult = 2 - Compare_NOT_EQUAL Compare_CompareResult = 3 -) - -var Compare_CompareResult_name = map[int32]string{ - 0: "EQUAL", - 1: "GREATER", - 2: "LESS", - 3: "NOT_EQUAL", -} -var Compare_CompareResult_value = map[string]int32{ - "EQUAL": 0, - "GREATER": 1, - "LESS": 2, - "NOT_EQUAL": 3, -} - -func (x Compare_CompareResult) String() string { - return proto.EnumName(Compare_CompareResult_name, int32(x)) -} -func (Compare_CompareResult) EnumDescriptor() ([]byte, []int) { return fileDescriptorRpc, []int{9, 0} } - -type Compare_CompareTarget int32 - -const ( - Compare_VERSION Compare_CompareTarget = 0 - Compare_CREATE Compare_CompareTarget = 1 - Compare_MOD Compare_CompareTarget = 2 - Compare_VALUE Compare_CompareTarget = 3 - Compare_LEASE Compare_CompareTarget = 4 -) - -var Compare_CompareTarget_name = map[int32]string{ - 0: "VERSION", - 1: "CREATE", - 2: "MOD", - 3: "VALUE", - 4: "LEASE", -} -var Compare_CompareTarget_value = map[string]int32{ - "VERSION": 0, - "CREATE": 1, - "MOD": 2, - "VALUE": 3, - "LEASE": 4, -} - -func (x Compare_CompareTarget) String() string { - return proto.EnumName(Compare_CompareTarget_name, int32(x)) -} -func (Compare_CompareTarget) EnumDescriptor() ([]byte, []int) { return fileDescriptorRpc, []int{9, 1} } - -type WatchCreateRequest_FilterType int32 - -const ( - // filter out put event. - WatchCreateRequest_NOPUT WatchCreateRequest_FilterType = 0 - // filter out delete event. - WatchCreateRequest_NODELETE WatchCreateRequest_FilterType = 1 -) - -var WatchCreateRequest_FilterType_name = map[int32]string{ - 0: "NOPUT", - 1: "NODELETE", -} -var WatchCreateRequest_FilterType_value = map[string]int32{ - "NOPUT": 0, - "NODELETE": 1, -} - -func (x WatchCreateRequest_FilterType) String() string { - return proto.EnumName(WatchCreateRequest_FilterType_name, int32(x)) -} -func (WatchCreateRequest_FilterType) EnumDescriptor() ([]byte, []int) { - return fileDescriptorRpc, []int{21, 0} -} - -type AlarmRequest_AlarmAction int32 - -const ( - AlarmRequest_GET AlarmRequest_AlarmAction = 0 - AlarmRequest_ACTIVATE AlarmRequest_AlarmAction = 1 - AlarmRequest_DEACTIVATE AlarmRequest_AlarmAction = 2 -) - -var AlarmRequest_AlarmAction_name = map[int32]string{ - 0: "GET", - 1: "ACTIVATE", - 2: "DEACTIVATE", -} -var AlarmRequest_AlarmAction_value = map[string]int32{ - "GET": 0, - "ACTIVATE": 1, - "DEACTIVATE": 2, -} - -func (x AlarmRequest_AlarmAction) String() string { - return proto.EnumName(AlarmRequest_AlarmAction_name, int32(x)) -} -func (AlarmRequest_AlarmAction) EnumDescriptor() ([]byte, []int) { - return fileDescriptorRpc, []int{48, 0} -} - -type ResponseHeader struct { - // cluster_id is the ID of the cluster which sent the response. - ClusterId uint64 `protobuf:"varint,1,opt,name=cluster_id,json=clusterId,proto3" json:"cluster_id,omitempty"` - // member_id is the ID of the member which sent the response. - MemberId uint64 `protobuf:"varint,2,opt,name=member_id,json=memberId,proto3" json:"member_id,omitempty"` - // revision is the key-value store revision when the request was applied. - Revision int64 `protobuf:"varint,3,opt,name=revision,proto3" json:"revision,omitempty"` - // raft_term is the raft term when the request was applied. - RaftTerm uint64 `protobuf:"varint,4,opt,name=raft_term,json=raftTerm,proto3" json:"raft_term,omitempty"` -} - -func (m *ResponseHeader) Reset() { *m = ResponseHeader{} } -func (m *ResponseHeader) String() string { return proto.CompactTextString(m) } -func (*ResponseHeader) ProtoMessage() {} -func (*ResponseHeader) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{0} } - -func (m *ResponseHeader) GetClusterId() uint64 { - if m != nil { - return m.ClusterId - } - return 0 -} - -func (m *ResponseHeader) GetMemberId() uint64 { - if m != nil { - return m.MemberId - } - return 0 -} - -func (m *ResponseHeader) GetRevision() int64 { - if m != nil { - return m.Revision - } - return 0 -} - -func (m *ResponseHeader) GetRaftTerm() uint64 { - if m != nil { - return m.RaftTerm - } - return 0 -} - -type RangeRequest struct { - // key is the first key for the range. If range_end is not given, the request only looks up key. - Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - // range_end is the upper bound on the requested range [key, range_end). - // If range_end is '\0', the range is all keys >= key. - // If range_end is key plus one (e.g., "aa"+1 == "ab", "a\xff"+1 == "b"), - // then the range request gets all keys prefixed with key. - // If both key and range_end are '\0', then the range request returns all keys. - RangeEnd []byte `protobuf:"bytes,2,opt,name=range_end,json=rangeEnd,proto3" json:"range_end,omitempty"` - // limit is a limit on the number of keys returned for the request. When limit is set to 0, - // it is treated as no limit. - Limit int64 `protobuf:"varint,3,opt,name=limit,proto3" json:"limit,omitempty"` - // revision is the point-in-time of the key-value store to use for the range. - // If revision is less or equal to zero, the range is over the newest key-value store. - // If the revision has been compacted, ErrCompacted is returned as a response. - Revision int64 `protobuf:"varint,4,opt,name=revision,proto3" json:"revision,omitempty"` - // sort_order is the order for returned sorted results. - SortOrder RangeRequest_SortOrder `protobuf:"varint,5,opt,name=sort_order,json=sortOrder,proto3,enum=etcdserverpb.RangeRequest_SortOrder" json:"sort_order,omitempty"` - // sort_target is the key-value field to use for sorting. - SortTarget RangeRequest_SortTarget `protobuf:"varint,6,opt,name=sort_target,json=sortTarget,proto3,enum=etcdserverpb.RangeRequest_SortTarget" json:"sort_target,omitempty"` - // serializable sets the range request to use serializable member-local reads. - // Range requests are linearizable by default; linearizable requests have higher - // latency and lower throughput than serializable requests but reflect the current - // consensus of the cluster. For better performance, in exchange for possible stale reads, - // a serializable range request is served locally without needing to reach consensus - // with other nodes in the cluster. - Serializable bool `protobuf:"varint,7,opt,name=serializable,proto3" json:"serializable,omitempty"` - // keys_only when set returns only the keys and not the values. - KeysOnly bool `protobuf:"varint,8,opt,name=keys_only,json=keysOnly,proto3" json:"keys_only,omitempty"` - // count_only when set returns only the count of the keys in the range. - CountOnly bool `protobuf:"varint,9,opt,name=count_only,json=countOnly,proto3" json:"count_only,omitempty"` - // min_mod_revision is the lower bound for returned key mod revisions; all keys with - // lesser mod revisions will be filtered away. - MinModRevision int64 `protobuf:"varint,10,opt,name=min_mod_revision,json=minModRevision,proto3" json:"min_mod_revision,omitempty"` - // max_mod_revision is the upper bound for returned key mod revisions; all keys with - // greater mod revisions will be filtered away. - MaxModRevision int64 `protobuf:"varint,11,opt,name=max_mod_revision,json=maxModRevision,proto3" json:"max_mod_revision,omitempty"` - // min_create_revision is the lower bound for returned key create revisions; all keys with - // lesser create trevisions will be filtered away. - MinCreateRevision int64 `protobuf:"varint,12,opt,name=min_create_revision,json=minCreateRevision,proto3" json:"min_create_revision,omitempty"` - // max_create_revision is the upper bound for returned key create revisions; all keys with - // greater create revisions will be filtered away. - MaxCreateRevision int64 `protobuf:"varint,13,opt,name=max_create_revision,json=maxCreateRevision,proto3" json:"max_create_revision,omitempty"` -} - -func (m *RangeRequest) Reset() { *m = RangeRequest{} } -func (m *RangeRequest) String() string { return proto.CompactTextString(m) } -func (*RangeRequest) ProtoMessage() {} -func (*RangeRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{1} } - -func (m *RangeRequest) GetKey() []byte { - if m != nil { - return m.Key - } - return nil -} - -func (m *RangeRequest) GetRangeEnd() []byte { - if m != nil { - return m.RangeEnd - } - return nil -} - -func (m *RangeRequest) GetLimit() int64 { - if m != nil { - return m.Limit - } - return 0 -} - -func (m *RangeRequest) GetRevision() int64 { - if m != nil { - return m.Revision - } - return 0 -} - -func (m *RangeRequest) GetSortOrder() RangeRequest_SortOrder { - if m != nil { - return m.SortOrder - } - return RangeRequest_NONE -} - -func (m *RangeRequest) GetSortTarget() RangeRequest_SortTarget { - if m != nil { - return m.SortTarget - } - return RangeRequest_KEY -} - -func (m *RangeRequest) GetSerializable() bool { - if m != nil { - return m.Serializable - } - return false -} - -func (m *RangeRequest) GetKeysOnly() bool { - if m != nil { - return m.KeysOnly - } - return false -} - -func (m *RangeRequest) GetCountOnly() bool { - if m != nil { - return m.CountOnly - } - return false -} - -func (m *RangeRequest) GetMinModRevision() int64 { - if m != nil { - return m.MinModRevision - } - return 0 -} - -func (m *RangeRequest) GetMaxModRevision() int64 { - if m != nil { - return m.MaxModRevision - } - return 0 -} - -func (m *RangeRequest) GetMinCreateRevision() int64 { - if m != nil { - return m.MinCreateRevision - } - return 0 -} - -func (m *RangeRequest) GetMaxCreateRevision() int64 { - if m != nil { - return m.MaxCreateRevision - } - return 0 -} - -type RangeResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // kvs is the list of key-value pairs matched by the range request. - // kvs is empty when count is requested. - Kvs []*mvccpb.KeyValue `protobuf:"bytes,2,rep,name=kvs" json:"kvs,omitempty"` - // more indicates if there are more keys to return in the requested range. - More bool `protobuf:"varint,3,opt,name=more,proto3" json:"more,omitempty"` - // count is set to the number of keys within the range when requested. - Count int64 `protobuf:"varint,4,opt,name=count,proto3" json:"count,omitempty"` -} - -func (m *RangeResponse) Reset() { *m = RangeResponse{} } -func (m *RangeResponse) String() string { return proto.CompactTextString(m) } -func (*RangeResponse) ProtoMessage() {} -func (*RangeResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{2} } - -func (m *RangeResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *RangeResponse) GetKvs() []*mvccpb.KeyValue { - if m != nil { - return m.Kvs - } - return nil -} - -func (m *RangeResponse) GetMore() bool { - if m != nil { - return m.More - } - return false -} - -func (m *RangeResponse) GetCount() int64 { - if m != nil { - return m.Count - } - return 0 -} - -type PutRequest struct { - // key is the key, in bytes, to put into the key-value store. - Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - // value is the value, in bytes, to associate with the key in the key-value store. - Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` - // lease is the lease ID to associate with the key in the key-value store. A lease - // value of 0 indicates no lease. - Lease int64 `protobuf:"varint,3,opt,name=lease,proto3" json:"lease,omitempty"` - // If prev_kv is set, etcd gets the previous key-value pair before changing it. - // The previous key-value pair will be returned in the put response. - PrevKv bool `protobuf:"varint,4,opt,name=prev_kv,json=prevKv,proto3" json:"prev_kv,omitempty"` - // If ignore_value is set, etcd updates the key using its current value. - // Returns an error if the key does not exist. - IgnoreValue bool `protobuf:"varint,5,opt,name=ignore_value,json=ignoreValue,proto3" json:"ignore_value,omitempty"` - // If ignore_lease is set, etcd updates the key using its current lease. - // Returns an error if the key does not exist. - IgnoreLease bool `protobuf:"varint,6,opt,name=ignore_lease,json=ignoreLease,proto3" json:"ignore_lease,omitempty"` -} - -func (m *PutRequest) Reset() { *m = PutRequest{} } -func (m *PutRequest) String() string { return proto.CompactTextString(m) } -func (*PutRequest) ProtoMessage() {} -func (*PutRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{3} } - -func (m *PutRequest) GetKey() []byte { - if m != nil { - return m.Key - } - return nil -} - -func (m *PutRequest) GetValue() []byte { - if m != nil { - return m.Value - } - return nil -} - -func (m *PutRequest) GetLease() int64 { - if m != nil { - return m.Lease - } - return 0 -} - -func (m *PutRequest) GetPrevKv() bool { - if m != nil { - return m.PrevKv - } - return false -} - -func (m *PutRequest) GetIgnoreValue() bool { - if m != nil { - return m.IgnoreValue - } - return false -} - -func (m *PutRequest) GetIgnoreLease() bool { - if m != nil { - return m.IgnoreLease - } - return false -} - -type PutResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // if prev_kv is set in the request, the previous key-value pair will be returned. - PrevKv *mvccpb.KeyValue `protobuf:"bytes,2,opt,name=prev_kv,json=prevKv" json:"prev_kv,omitempty"` -} - -func (m *PutResponse) Reset() { *m = PutResponse{} } -func (m *PutResponse) String() string { return proto.CompactTextString(m) } -func (*PutResponse) ProtoMessage() {} -func (*PutResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{4} } - -func (m *PutResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *PutResponse) GetPrevKv() *mvccpb.KeyValue { - if m != nil { - return m.PrevKv - } - return nil -} - -type DeleteRangeRequest struct { - // key is the first key to delete in the range. - Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - // range_end is the key following the last key to delete for the range [key, range_end). - // If range_end is not given, the range is defined to contain only the key argument. - // If range_end is one bit larger than the given key, then the range is all the keys - // with the prefix (the given key). - // If range_end is '\0', the range is all keys greater than or equal to the key argument. - RangeEnd []byte `protobuf:"bytes,2,opt,name=range_end,json=rangeEnd,proto3" json:"range_end,omitempty"` - // If prev_kv is set, etcd gets the previous key-value pairs before deleting it. - // The previous key-value pairs will be returned in the delete response. - PrevKv bool `protobuf:"varint,3,opt,name=prev_kv,json=prevKv,proto3" json:"prev_kv,omitempty"` -} - -func (m *DeleteRangeRequest) Reset() { *m = DeleteRangeRequest{} } -func (m *DeleteRangeRequest) String() string { return proto.CompactTextString(m) } -func (*DeleteRangeRequest) ProtoMessage() {} -func (*DeleteRangeRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{5} } - -func (m *DeleteRangeRequest) GetKey() []byte { - if m != nil { - return m.Key - } - return nil -} - -func (m *DeleteRangeRequest) GetRangeEnd() []byte { - if m != nil { - return m.RangeEnd - } - return nil -} - -func (m *DeleteRangeRequest) GetPrevKv() bool { - if m != nil { - return m.PrevKv - } - return false -} - -type DeleteRangeResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // deleted is the number of keys deleted by the delete range request. - Deleted int64 `protobuf:"varint,2,opt,name=deleted,proto3" json:"deleted,omitempty"` - // if prev_kv is set in the request, the previous key-value pairs will be returned. - PrevKvs []*mvccpb.KeyValue `protobuf:"bytes,3,rep,name=prev_kvs,json=prevKvs" json:"prev_kvs,omitempty"` -} - -func (m *DeleteRangeResponse) Reset() { *m = DeleteRangeResponse{} } -func (m *DeleteRangeResponse) String() string { return proto.CompactTextString(m) } -func (*DeleteRangeResponse) ProtoMessage() {} -func (*DeleteRangeResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{6} } - -func (m *DeleteRangeResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *DeleteRangeResponse) GetDeleted() int64 { - if m != nil { - return m.Deleted - } - return 0 -} - -func (m *DeleteRangeResponse) GetPrevKvs() []*mvccpb.KeyValue { - if m != nil { - return m.PrevKvs - } - return nil -} - -type RequestOp struct { - // request is a union of request types accepted by a transaction. - // - // Types that are valid to be assigned to Request: - // *RequestOp_RequestRange - // *RequestOp_RequestPut - // *RequestOp_RequestDeleteRange - // *RequestOp_RequestTxn - Request isRequestOp_Request `protobuf_oneof:"request"` -} - -func (m *RequestOp) Reset() { *m = RequestOp{} } -func (m *RequestOp) String() string { return proto.CompactTextString(m) } -func (*RequestOp) ProtoMessage() {} -func (*RequestOp) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{7} } - -type isRequestOp_Request interface { - isRequestOp_Request() - MarshalTo([]byte) (int, error) - Size() int -} - -type RequestOp_RequestRange struct { - RequestRange *RangeRequest `protobuf:"bytes,1,opt,name=request_range,json=requestRange,oneof"` -} -type RequestOp_RequestPut struct { - RequestPut *PutRequest `protobuf:"bytes,2,opt,name=request_put,json=requestPut,oneof"` -} -type RequestOp_RequestDeleteRange struct { - RequestDeleteRange *DeleteRangeRequest `protobuf:"bytes,3,opt,name=request_delete_range,json=requestDeleteRange,oneof"` -} -type RequestOp_RequestTxn struct { - RequestTxn *TxnRequest `protobuf:"bytes,4,opt,name=request_txn,json=requestTxn,oneof"` -} - -func (*RequestOp_RequestRange) isRequestOp_Request() {} -func (*RequestOp_RequestPut) isRequestOp_Request() {} -func (*RequestOp_RequestDeleteRange) isRequestOp_Request() {} -func (*RequestOp_RequestTxn) isRequestOp_Request() {} - -func (m *RequestOp) GetRequest() isRequestOp_Request { - if m != nil { - return m.Request - } - return nil -} - -func (m *RequestOp) GetRequestRange() *RangeRequest { - if x, ok := m.GetRequest().(*RequestOp_RequestRange); ok { - return x.RequestRange - } - return nil -} - -func (m *RequestOp) GetRequestPut() *PutRequest { - if x, ok := m.GetRequest().(*RequestOp_RequestPut); ok { - return x.RequestPut - } - return nil -} - -func (m *RequestOp) GetRequestDeleteRange() *DeleteRangeRequest { - if x, ok := m.GetRequest().(*RequestOp_RequestDeleteRange); ok { - return x.RequestDeleteRange - } - return nil -} - -func (m *RequestOp) GetRequestTxn() *TxnRequest { - if x, ok := m.GetRequest().(*RequestOp_RequestTxn); ok { - return x.RequestTxn - } - return nil -} - -// XXX_OneofFuncs is for the internal use of the proto package. -func (*RequestOp) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { - return _RequestOp_OneofMarshaler, _RequestOp_OneofUnmarshaler, _RequestOp_OneofSizer, []interface{}{ - (*RequestOp_RequestRange)(nil), - (*RequestOp_RequestPut)(nil), - (*RequestOp_RequestDeleteRange)(nil), - (*RequestOp_RequestTxn)(nil), - } -} - -func _RequestOp_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { - m := msg.(*RequestOp) - // request - switch x := m.Request.(type) { - case *RequestOp_RequestRange: - _ = b.EncodeVarint(1<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.RequestRange); err != nil { - return err - } - case *RequestOp_RequestPut: - _ = b.EncodeVarint(2<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.RequestPut); err != nil { - return err - } - case *RequestOp_RequestDeleteRange: - _ = b.EncodeVarint(3<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.RequestDeleteRange); err != nil { - return err - } - case *RequestOp_RequestTxn: - _ = b.EncodeVarint(4<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.RequestTxn); err != nil { - return err - } - case nil: - default: - return fmt.Errorf("RequestOp.Request has unexpected type %T", x) - } - return nil -} - -func _RequestOp_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { - m := msg.(*RequestOp) - switch tag { - case 1: // request.request_range - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(RangeRequest) - err := b.DecodeMessage(msg) - m.Request = &RequestOp_RequestRange{msg} - return true, err - case 2: // request.request_put - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(PutRequest) - err := b.DecodeMessage(msg) - m.Request = &RequestOp_RequestPut{msg} - return true, err - case 3: // request.request_delete_range - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(DeleteRangeRequest) - err := b.DecodeMessage(msg) - m.Request = &RequestOp_RequestDeleteRange{msg} - return true, err - case 4: // request.request_txn - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(TxnRequest) - err := b.DecodeMessage(msg) - m.Request = &RequestOp_RequestTxn{msg} - return true, err - default: - return false, nil - } -} - -func _RequestOp_OneofSizer(msg proto.Message) (n int) { - m := msg.(*RequestOp) - // request - switch x := m.Request.(type) { - case *RequestOp_RequestRange: - s := proto.Size(x.RequestRange) - n += proto.SizeVarint(1<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case *RequestOp_RequestPut: - s := proto.Size(x.RequestPut) - n += proto.SizeVarint(2<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case *RequestOp_RequestDeleteRange: - s := proto.Size(x.RequestDeleteRange) - n += proto.SizeVarint(3<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case *RequestOp_RequestTxn: - s := proto.Size(x.RequestTxn) - n += proto.SizeVarint(4<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case nil: - default: - panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) - } - return n -} - -type ResponseOp struct { - // response is a union of response types returned by a transaction. - // - // Types that are valid to be assigned to Response: - // *ResponseOp_ResponseRange - // *ResponseOp_ResponsePut - // *ResponseOp_ResponseDeleteRange - // *ResponseOp_ResponseTxn - Response isResponseOp_Response `protobuf_oneof:"response"` -} - -func (m *ResponseOp) Reset() { *m = ResponseOp{} } -func (m *ResponseOp) String() string { return proto.CompactTextString(m) } -func (*ResponseOp) ProtoMessage() {} -func (*ResponseOp) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{8} } - -type isResponseOp_Response interface { - isResponseOp_Response() - MarshalTo([]byte) (int, error) - Size() int -} - -type ResponseOp_ResponseRange struct { - ResponseRange *RangeResponse `protobuf:"bytes,1,opt,name=response_range,json=responseRange,oneof"` -} -type ResponseOp_ResponsePut struct { - ResponsePut *PutResponse `protobuf:"bytes,2,opt,name=response_put,json=responsePut,oneof"` -} -type ResponseOp_ResponseDeleteRange struct { - ResponseDeleteRange *DeleteRangeResponse `protobuf:"bytes,3,opt,name=response_delete_range,json=responseDeleteRange,oneof"` -} -type ResponseOp_ResponseTxn struct { - ResponseTxn *TxnResponse `protobuf:"bytes,4,opt,name=response_txn,json=responseTxn,oneof"` -} - -func (*ResponseOp_ResponseRange) isResponseOp_Response() {} -func (*ResponseOp_ResponsePut) isResponseOp_Response() {} -func (*ResponseOp_ResponseDeleteRange) isResponseOp_Response() {} -func (*ResponseOp_ResponseTxn) isResponseOp_Response() {} - -func (m *ResponseOp) GetResponse() isResponseOp_Response { - if m != nil { - return m.Response - } - return nil -} - -func (m *ResponseOp) GetResponseRange() *RangeResponse { - if x, ok := m.GetResponse().(*ResponseOp_ResponseRange); ok { - return x.ResponseRange - } - return nil -} - -func (m *ResponseOp) GetResponsePut() *PutResponse { - if x, ok := m.GetResponse().(*ResponseOp_ResponsePut); ok { - return x.ResponsePut - } - return nil -} - -func (m *ResponseOp) GetResponseDeleteRange() *DeleteRangeResponse { - if x, ok := m.GetResponse().(*ResponseOp_ResponseDeleteRange); ok { - return x.ResponseDeleteRange - } - return nil -} - -func (m *ResponseOp) GetResponseTxn() *TxnResponse { - if x, ok := m.GetResponse().(*ResponseOp_ResponseTxn); ok { - return x.ResponseTxn - } - return nil -} - -// XXX_OneofFuncs is for the internal use of the proto package. -func (*ResponseOp) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { - return _ResponseOp_OneofMarshaler, _ResponseOp_OneofUnmarshaler, _ResponseOp_OneofSizer, []interface{}{ - (*ResponseOp_ResponseRange)(nil), - (*ResponseOp_ResponsePut)(nil), - (*ResponseOp_ResponseDeleteRange)(nil), - (*ResponseOp_ResponseTxn)(nil), - } -} - -func _ResponseOp_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { - m := msg.(*ResponseOp) - // response - switch x := m.Response.(type) { - case *ResponseOp_ResponseRange: - _ = b.EncodeVarint(1<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.ResponseRange); err != nil { - return err - } - case *ResponseOp_ResponsePut: - _ = b.EncodeVarint(2<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.ResponsePut); err != nil { - return err - } - case *ResponseOp_ResponseDeleteRange: - _ = b.EncodeVarint(3<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.ResponseDeleteRange); err != nil { - return err - } - case *ResponseOp_ResponseTxn: - _ = b.EncodeVarint(4<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.ResponseTxn); err != nil { - return err - } - case nil: - default: - return fmt.Errorf("ResponseOp.Response has unexpected type %T", x) - } - return nil -} - -func _ResponseOp_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { - m := msg.(*ResponseOp) - switch tag { - case 1: // response.response_range - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(RangeResponse) - err := b.DecodeMessage(msg) - m.Response = &ResponseOp_ResponseRange{msg} - return true, err - case 2: // response.response_put - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(PutResponse) - err := b.DecodeMessage(msg) - m.Response = &ResponseOp_ResponsePut{msg} - return true, err - case 3: // response.response_delete_range - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(DeleteRangeResponse) - err := b.DecodeMessage(msg) - m.Response = &ResponseOp_ResponseDeleteRange{msg} - return true, err - case 4: // response.response_txn - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(TxnResponse) - err := b.DecodeMessage(msg) - m.Response = &ResponseOp_ResponseTxn{msg} - return true, err - default: - return false, nil - } -} - -func _ResponseOp_OneofSizer(msg proto.Message) (n int) { - m := msg.(*ResponseOp) - // response - switch x := m.Response.(type) { - case *ResponseOp_ResponseRange: - s := proto.Size(x.ResponseRange) - n += proto.SizeVarint(1<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case *ResponseOp_ResponsePut: - s := proto.Size(x.ResponsePut) - n += proto.SizeVarint(2<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case *ResponseOp_ResponseDeleteRange: - s := proto.Size(x.ResponseDeleteRange) - n += proto.SizeVarint(3<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case *ResponseOp_ResponseTxn: - s := proto.Size(x.ResponseTxn) - n += proto.SizeVarint(4<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case nil: - default: - panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) - } - return n -} - -type Compare struct { - // result is logical comparison operation for this comparison. - Result Compare_CompareResult `protobuf:"varint,1,opt,name=result,proto3,enum=etcdserverpb.Compare_CompareResult" json:"result,omitempty"` - // target is the key-value field to inspect for the comparison. - Target Compare_CompareTarget `protobuf:"varint,2,opt,name=target,proto3,enum=etcdserverpb.Compare_CompareTarget" json:"target,omitempty"` - // key is the subject key for the comparison operation. - Key []byte `protobuf:"bytes,3,opt,name=key,proto3" json:"key,omitempty"` - // Types that are valid to be assigned to TargetUnion: - // *Compare_Version - // *Compare_CreateRevision - // *Compare_ModRevision - // *Compare_Value - // *Compare_Lease - TargetUnion isCompare_TargetUnion `protobuf_oneof:"target_union"` - // range_end compares the given target to all keys in the range [key, range_end). - // See RangeRequest for more details on key ranges. - RangeEnd []byte `protobuf:"bytes,64,opt,name=range_end,json=rangeEnd,proto3" json:"range_end,omitempty"` -} - -func (m *Compare) Reset() { *m = Compare{} } -func (m *Compare) String() string { return proto.CompactTextString(m) } -func (*Compare) ProtoMessage() {} -func (*Compare) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{9} } - -type isCompare_TargetUnion interface { - isCompare_TargetUnion() - MarshalTo([]byte) (int, error) - Size() int -} - -type Compare_Version struct { - Version int64 `protobuf:"varint,4,opt,name=version,proto3,oneof"` -} -type Compare_CreateRevision struct { - CreateRevision int64 `protobuf:"varint,5,opt,name=create_revision,json=createRevision,proto3,oneof"` -} -type Compare_ModRevision struct { - ModRevision int64 `protobuf:"varint,6,opt,name=mod_revision,json=modRevision,proto3,oneof"` -} -type Compare_Value struct { - Value []byte `protobuf:"bytes,7,opt,name=value,proto3,oneof"` -} -type Compare_Lease struct { - Lease int64 `protobuf:"varint,8,opt,name=lease,proto3,oneof"` -} - -func (*Compare_Version) isCompare_TargetUnion() {} -func (*Compare_CreateRevision) isCompare_TargetUnion() {} -func (*Compare_ModRevision) isCompare_TargetUnion() {} -func (*Compare_Value) isCompare_TargetUnion() {} -func (*Compare_Lease) isCompare_TargetUnion() {} - -func (m *Compare) GetTargetUnion() isCompare_TargetUnion { - if m != nil { - return m.TargetUnion - } - return nil -} - -func (m *Compare) GetResult() Compare_CompareResult { - if m != nil { - return m.Result - } - return Compare_EQUAL -} - -func (m *Compare) GetTarget() Compare_CompareTarget { - if m != nil { - return m.Target - } - return Compare_VERSION -} - -func (m *Compare) GetKey() []byte { - if m != nil { - return m.Key - } - return nil -} - -func (m *Compare) GetVersion() int64 { - if x, ok := m.GetTargetUnion().(*Compare_Version); ok { - return x.Version - } - return 0 -} - -func (m *Compare) GetCreateRevision() int64 { - if x, ok := m.GetTargetUnion().(*Compare_CreateRevision); ok { - return x.CreateRevision - } - return 0 -} - -func (m *Compare) GetModRevision() int64 { - if x, ok := m.GetTargetUnion().(*Compare_ModRevision); ok { - return x.ModRevision - } - return 0 -} - -func (m *Compare) GetValue() []byte { - if x, ok := m.GetTargetUnion().(*Compare_Value); ok { - return x.Value - } - return nil -} - -func (m *Compare) GetLease() int64 { - if x, ok := m.GetTargetUnion().(*Compare_Lease); ok { - return x.Lease - } - return 0 -} - -func (m *Compare) GetRangeEnd() []byte { - if m != nil { - return m.RangeEnd - } - return nil -} - -// XXX_OneofFuncs is for the internal use of the proto package. -func (*Compare) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { - return _Compare_OneofMarshaler, _Compare_OneofUnmarshaler, _Compare_OneofSizer, []interface{}{ - (*Compare_Version)(nil), - (*Compare_CreateRevision)(nil), - (*Compare_ModRevision)(nil), - (*Compare_Value)(nil), - (*Compare_Lease)(nil), - } -} - -func _Compare_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { - m := msg.(*Compare) - // target_union - switch x := m.TargetUnion.(type) { - case *Compare_Version: - _ = b.EncodeVarint(4<<3 | proto.WireVarint) - _ = b.EncodeVarint(uint64(x.Version)) - case *Compare_CreateRevision: - _ = b.EncodeVarint(5<<3 | proto.WireVarint) - _ = b.EncodeVarint(uint64(x.CreateRevision)) - case *Compare_ModRevision: - _ = b.EncodeVarint(6<<3 | proto.WireVarint) - _ = b.EncodeVarint(uint64(x.ModRevision)) - case *Compare_Value: - _ = b.EncodeVarint(7<<3 | proto.WireBytes) - _ = b.EncodeRawBytes(x.Value) - case *Compare_Lease: - _ = b.EncodeVarint(8<<3 | proto.WireVarint) - _ = b.EncodeVarint(uint64(x.Lease)) - case nil: - default: - return fmt.Errorf("Compare.TargetUnion has unexpected type %T", x) - } - return nil -} - -func _Compare_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { - m := msg.(*Compare) - switch tag { - case 4: // target_union.version - if wire != proto.WireVarint { - return true, proto.ErrInternalBadWireType - } - x, err := b.DecodeVarint() - m.TargetUnion = &Compare_Version{int64(x)} - return true, err - case 5: // target_union.create_revision - if wire != proto.WireVarint { - return true, proto.ErrInternalBadWireType - } - x, err := b.DecodeVarint() - m.TargetUnion = &Compare_CreateRevision{int64(x)} - return true, err - case 6: // target_union.mod_revision - if wire != proto.WireVarint { - return true, proto.ErrInternalBadWireType - } - x, err := b.DecodeVarint() - m.TargetUnion = &Compare_ModRevision{int64(x)} - return true, err - case 7: // target_union.value - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - x, err := b.DecodeRawBytes(true) - m.TargetUnion = &Compare_Value{x} - return true, err - case 8: // target_union.lease - if wire != proto.WireVarint { - return true, proto.ErrInternalBadWireType - } - x, err := b.DecodeVarint() - m.TargetUnion = &Compare_Lease{int64(x)} - return true, err - default: - return false, nil - } -} - -func _Compare_OneofSizer(msg proto.Message) (n int) { - m := msg.(*Compare) - // target_union - switch x := m.TargetUnion.(type) { - case *Compare_Version: - n += proto.SizeVarint(4<<3 | proto.WireVarint) - n += proto.SizeVarint(uint64(x.Version)) - case *Compare_CreateRevision: - n += proto.SizeVarint(5<<3 | proto.WireVarint) - n += proto.SizeVarint(uint64(x.CreateRevision)) - case *Compare_ModRevision: - n += proto.SizeVarint(6<<3 | proto.WireVarint) - n += proto.SizeVarint(uint64(x.ModRevision)) - case *Compare_Value: - n += proto.SizeVarint(7<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(len(x.Value))) - n += len(x.Value) - case *Compare_Lease: - n += proto.SizeVarint(8<<3 | proto.WireVarint) - n += proto.SizeVarint(uint64(x.Lease)) - case nil: - default: - panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) - } - return n -} - -// From google paxosdb paper: -// Our implementation hinges around a powerful primitive which we call MultiOp. All other database -// operations except for iteration are implemented as a single call to MultiOp. A MultiOp is applied atomically -// and consists of three components: -// 1. A list of tests called guard. Each test in guard checks a single entry in the database. It may check -// for the absence or presence of a value, or compare with a given value. Two different tests in the guard -// may apply to the same or different entries in the database. All tests in the guard are applied and -// MultiOp returns the results. If all tests are true, MultiOp executes t op (see item 2 below), otherwise -// it executes f op (see item 3 below). -// 2. A list of database operations called t op. Each operation in the list is either an insert, delete, or -// lookup operation, and applies to a single database entry. Two different operations in the list may apply -// to the same or different entries in the database. These operations are executed -// if guard evaluates to -// true. -// 3. A list of database operations called f op. Like t op, but executed if guard evaluates to false. -type TxnRequest struct { - // compare is a list of predicates representing a conjunction of terms. - // If the comparisons succeed, then the success requests will be processed in order, - // and the response will contain their respective responses in order. - // If the comparisons fail, then the failure requests will be processed in order, - // and the response will contain their respective responses in order. - Compare []*Compare `protobuf:"bytes,1,rep,name=compare" json:"compare,omitempty"` - // success is a list of requests which will be applied when compare evaluates to true. - Success []*RequestOp `protobuf:"bytes,2,rep,name=success" json:"success,omitempty"` - // failure is a list of requests which will be applied when compare evaluates to false. - Failure []*RequestOp `protobuf:"bytes,3,rep,name=failure" json:"failure,omitempty"` -} - -func (m *TxnRequest) Reset() { *m = TxnRequest{} } -func (m *TxnRequest) String() string { return proto.CompactTextString(m) } -func (*TxnRequest) ProtoMessage() {} -func (*TxnRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{10} } - -func (m *TxnRequest) GetCompare() []*Compare { - if m != nil { - return m.Compare - } - return nil -} - -func (m *TxnRequest) GetSuccess() []*RequestOp { - if m != nil { - return m.Success - } - return nil -} - -func (m *TxnRequest) GetFailure() []*RequestOp { - if m != nil { - return m.Failure - } - return nil -} - -type TxnResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // succeeded is set to true if the compare evaluated to true or false otherwise. - Succeeded bool `protobuf:"varint,2,opt,name=succeeded,proto3" json:"succeeded,omitempty"` - // responses is a list of responses corresponding to the results from applying - // success if succeeded is true or failure if succeeded is false. - Responses []*ResponseOp `protobuf:"bytes,3,rep,name=responses" json:"responses,omitempty"` -} - -func (m *TxnResponse) Reset() { *m = TxnResponse{} } -func (m *TxnResponse) String() string { return proto.CompactTextString(m) } -func (*TxnResponse) ProtoMessage() {} -func (*TxnResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{11} } - -func (m *TxnResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *TxnResponse) GetSucceeded() bool { - if m != nil { - return m.Succeeded - } - return false -} - -func (m *TxnResponse) GetResponses() []*ResponseOp { - if m != nil { - return m.Responses - } - return nil -} - -// CompactionRequest compacts the key-value store up to a given revision. All superseded keys -// with a revision less than the compaction revision will be removed. -type CompactionRequest struct { - // revision is the key-value store revision for the compaction operation. - Revision int64 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` - // physical is set so the RPC will wait until the compaction is physically - // applied to the local database such that compacted entries are totally - // removed from the backend database. - Physical bool `protobuf:"varint,2,opt,name=physical,proto3" json:"physical,omitempty"` -} - -func (m *CompactionRequest) Reset() { *m = CompactionRequest{} } -func (m *CompactionRequest) String() string { return proto.CompactTextString(m) } -func (*CompactionRequest) ProtoMessage() {} -func (*CompactionRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{12} } - -func (m *CompactionRequest) GetRevision() int64 { - if m != nil { - return m.Revision - } - return 0 -} - -func (m *CompactionRequest) GetPhysical() bool { - if m != nil { - return m.Physical - } - return false -} - -type CompactionResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *CompactionResponse) Reset() { *m = CompactionResponse{} } -func (m *CompactionResponse) String() string { return proto.CompactTextString(m) } -func (*CompactionResponse) ProtoMessage() {} -func (*CompactionResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{13} } - -func (m *CompactionResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type HashRequest struct { -} - -func (m *HashRequest) Reset() { *m = HashRequest{} } -func (m *HashRequest) String() string { return proto.CompactTextString(m) } -func (*HashRequest) ProtoMessage() {} -func (*HashRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{14} } - -type HashKVRequest struct { - // revision is the key-value store revision for the hash operation. - Revision int64 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` -} - -func (m *HashKVRequest) Reset() { *m = HashKVRequest{} } -func (m *HashKVRequest) String() string { return proto.CompactTextString(m) } -func (*HashKVRequest) ProtoMessage() {} -func (*HashKVRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{15} } - -func (m *HashKVRequest) GetRevision() int64 { - if m != nil { - return m.Revision - } - return 0 -} - -type HashKVResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // hash is the hash value computed from the responding member's MVCC keys up to a given revision. - Hash uint32 `protobuf:"varint,2,opt,name=hash,proto3" json:"hash,omitempty"` - // compact_revision is the compacted revision of key-value store when hash begins. - CompactRevision int64 `protobuf:"varint,3,opt,name=compact_revision,json=compactRevision,proto3" json:"compact_revision,omitempty"` -} - -func (m *HashKVResponse) Reset() { *m = HashKVResponse{} } -func (m *HashKVResponse) String() string { return proto.CompactTextString(m) } -func (*HashKVResponse) ProtoMessage() {} -func (*HashKVResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{16} } - -func (m *HashKVResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *HashKVResponse) GetHash() uint32 { - if m != nil { - return m.Hash - } - return 0 -} - -func (m *HashKVResponse) GetCompactRevision() int64 { - if m != nil { - return m.CompactRevision - } - return 0 -} - -type HashResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // hash is the hash value computed from the responding member's KV's backend. - Hash uint32 `protobuf:"varint,2,opt,name=hash,proto3" json:"hash,omitempty"` -} - -func (m *HashResponse) Reset() { *m = HashResponse{} } -func (m *HashResponse) String() string { return proto.CompactTextString(m) } -func (*HashResponse) ProtoMessage() {} -func (*HashResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{17} } - -func (m *HashResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *HashResponse) GetHash() uint32 { - if m != nil { - return m.Hash - } - return 0 -} - -type SnapshotRequest struct { -} - -func (m *SnapshotRequest) Reset() { *m = SnapshotRequest{} } -func (m *SnapshotRequest) String() string { return proto.CompactTextString(m) } -func (*SnapshotRequest) ProtoMessage() {} -func (*SnapshotRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{18} } - -type SnapshotResponse struct { - // header has the current key-value store information. The first header in the snapshot - // stream indicates the point in time of the snapshot. - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // remaining_bytes is the number of blob bytes to be sent after this message - RemainingBytes uint64 `protobuf:"varint,2,opt,name=remaining_bytes,json=remainingBytes,proto3" json:"remaining_bytes,omitempty"` - // blob contains the next chunk of the snapshot in the snapshot stream. - Blob []byte `protobuf:"bytes,3,opt,name=blob,proto3" json:"blob,omitempty"` -} - -func (m *SnapshotResponse) Reset() { *m = SnapshotResponse{} } -func (m *SnapshotResponse) String() string { return proto.CompactTextString(m) } -func (*SnapshotResponse) ProtoMessage() {} -func (*SnapshotResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{19} } - -func (m *SnapshotResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *SnapshotResponse) GetRemainingBytes() uint64 { - if m != nil { - return m.RemainingBytes - } - return 0 -} - -func (m *SnapshotResponse) GetBlob() []byte { - if m != nil { - return m.Blob - } - return nil -} - -type WatchRequest struct { - // request_union is a request to either create a new watcher or cancel an existing watcher. - // - // Types that are valid to be assigned to RequestUnion: - // *WatchRequest_CreateRequest - // *WatchRequest_CancelRequest - RequestUnion isWatchRequest_RequestUnion `protobuf_oneof:"request_union"` -} - -func (m *WatchRequest) Reset() { *m = WatchRequest{} } -func (m *WatchRequest) String() string { return proto.CompactTextString(m) } -func (*WatchRequest) ProtoMessage() {} -func (*WatchRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{20} } - -type isWatchRequest_RequestUnion interface { - isWatchRequest_RequestUnion() - MarshalTo([]byte) (int, error) - Size() int -} - -type WatchRequest_CreateRequest struct { - CreateRequest *WatchCreateRequest `protobuf:"bytes,1,opt,name=create_request,json=createRequest,oneof"` -} -type WatchRequest_CancelRequest struct { - CancelRequest *WatchCancelRequest `protobuf:"bytes,2,opt,name=cancel_request,json=cancelRequest,oneof"` -} - -func (*WatchRequest_CreateRequest) isWatchRequest_RequestUnion() {} -func (*WatchRequest_CancelRequest) isWatchRequest_RequestUnion() {} - -func (m *WatchRequest) GetRequestUnion() isWatchRequest_RequestUnion { - if m != nil { - return m.RequestUnion - } - return nil -} - -func (m *WatchRequest) GetCreateRequest() *WatchCreateRequest { - if x, ok := m.GetRequestUnion().(*WatchRequest_CreateRequest); ok { - return x.CreateRequest - } - return nil -} - -func (m *WatchRequest) GetCancelRequest() *WatchCancelRequest { - if x, ok := m.GetRequestUnion().(*WatchRequest_CancelRequest); ok { - return x.CancelRequest - } - return nil -} - -// XXX_OneofFuncs is for the internal use of the proto package. -func (*WatchRequest) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { - return _WatchRequest_OneofMarshaler, _WatchRequest_OneofUnmarshaler, _WatchRequest_OneofSizer, []interface{}{ - (*WatchRequest_CreateRequest)(nil), - (*WatchRequest_CancelRequest)(nil), - } -} - -func _WatchRequest_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { - m := msg.(*WatchRequest) - // request_union - switch x := m.RequestUnion.(type) { - case *WatchRequest_CreateRequest: - _ = b.EncodeVarint(1<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.CreateRequest); err != nil { - return err - } - case *WatchRequest_CancelRequest: - _ = b.EncodeVarint(2<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.CancelRequest); err != nil { - return err - } - case nil: - default: - return fmt.Errorf("WatchRequest.RequestUnion has unexpected type %T", x) - } - return nil -} - -func _WatchRequest_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { - m := msg.(*WatchRequest) - switch tag { - case 1: // request_union.create_request - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(WatchCreateRequest) - err := b.DecodeMessage(msg) - m.RequestUnion = &WatchRequest_CreateRequest{msg} - return true, err - case 2: // request_union.cancel_request - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(WatchCancelRequest) - err := b.DecodeMessage(msg) - m.RequestUnion = &WatchRequest_CancelRequest{msg} - return true, err - default: - return false, nil - } -} - -func _WatchRequest_OneofSizer(msg proto.Message) (n int) { - m := msg.(*WatchRequest) - // request_union - switch x := m.RequestUnion.(type) { - case *WatchRequest_CreateRequest: - s := proto.Size(x.CreateRequest) - n += proto.SizeVarint(1<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case *WatchRequest_CancelRequest: - s := proto.Size(x.CancelRequest) - n += proto.SizeVarint(2<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case nil: - default: - panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) - } - return n -} - -type WatchCreateRequest struct { - // key is the key to register for watching. - Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - // range_end is the end of the range [key, range_end) to watch. If range_end is not given, - // only the key argument is watched. If range_end is equal to '\0', all keys greater than - // or equal to the key argument are watched. - // If the range_end is one bit larger than the given key, - // then all keys with the prefix (the given key) will be watched. - RangeEnd []byte `protobuf:"bytes,2,opt,name=range_end,json=rangeEnd,proto3" json:"range_end,omitempty"` - // start_revision is an optional revision to watch from (inclusive). No start_revision is "now". - StartRevision int64 `protobuf:"varint,3,opt,name=start_revision,json=startRevision,proto3" json:"start_revision,omitempty"` - // progress_notify is set so that the etcd server will periodically send a WatchResponse with - // no events to the new watcher if there are no recent events. It is useful when clients - // wish to recover a disconnected watcher starting from a recent known revision. - // The etcd server may decide how often it will send notifications based on current load. - ProgressNotify bool `protobuf:"varint,4,opt,name=progress_notify,json=progressNotify,proto3" json:"progress_notify,omitempty"` - // filters filter the events at server side before it sends back to the watcher. - Filters []WatchCreateRequest_FilterType `protobuf:"varint,5,rep,packed,name=filters,enum=etcdserverpb.WatchCreateRequest_FilterType" json:"filters,omitempty"` - // If prev_kv is set, created watcher gets the previous KV before the event happens. - // If the previous KV is already compacted, nothing will be returned. - PrevKv bool `protobuf:"varint,6,opt,name=prev_kv,json=prevKv,proto3" json:"prev_kv,omitempty"` -} - -func (m *WatchCreateRequest) Reset() { *m = WatchCreateRequest{} } -func (m *WatchCreateRequest) String() string { return proto.CompactTextString(m) } -func (*WatchCreateRequest) ProtoMessage() {} -func (*WatchCreateRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{21} } - -func (m *WatchCreateRequest) GetKey() []byte { - if m != nil { - return m.Key - } - return nil -} - -func (m *WatchCreateRequest) GetRangeEnd() []byte { - if m != nil { - return m.RangeEnd - } - return nil -} - -func (m *WatchCreateRequest) GetStartRevision() int64 { - if m != nil { - return m.StartRevision - } - return 0 -} - -func (m *WatchCreateRequest) GetProgressNotify() bool { - if m != nil { - return m.ProgressNotify - } - return false -} - -func (m *WatchCreateRequest) GetFilters() []WatchCreateRequest_FilterType { - if m != nil { - return m.Filters - } - return nil -} - -func (m *WatchCreateRequest) GetPrevKv() bool { - if m != nil { - return m.PrevKv - } - return false -} - -type WatchCancelRequest struct { - // watch_id is the watcher id to cancel so that no more events are transmitted. - WatchId int64 `protobuf:"varint,1,opt,name=watch_id,json=watchId,proto3" json:"watch_id,omitempty"` -} - -func (m *WatchCancelRequest) Reset() { *m = WatchCancelRequest{} } -func (m *WatchCancelRequest) String() string { return proto.CompactTextString(m) } -func (*WatchCancelRequest) ProtoMessage() {} -func (*WatchCancelRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{22} } - -func (m *WatchCancelRequest) GetWatchId() int64 { - if m != nil { - return m.WatchId - } - return 0 -} - -type WatchResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // watch_id is the ID of the watcher that corresponds to the response. - WatchId int64 `protobuf:"varint,2,opt,name=watch_id,json=watchId,proto3" json:"watch_id,omitempty"` - // created is set to true if the response is for a create watch request. - // The client should record the watch_id and expect to receive events for - // the created watcher from the same stream. - // All events sent to the created watcher will attach with the same watch_id. - Created bool `protobuf:"varint,3,opt,name=created,proto3" json:"created,omitempty"` - // canceled is set to true if the response is for a cancel watch request. - // No further events will be sent to the canceled watcher. - Canceled bool `protobuf:"varint,4,opt,name=canceled,proto3" json:"canceled,omitempty"` - // compact_revision is set to the minimum index if a watcher tries to watch - // at a compacted index. - // - // This happens when creating a watcher at a compacted revision or the watcher cannot - // catch up with the progress of the key-value store. - // - // The client should treat the watcher as canceled and should not try to create any - // watcher with the same start_revision again. - CompactRevision int64 `protobuf:"varint,5,opt,name=compact_revision,json=compactRevision,proto3" json:"compact_revision,omitempty"` - // cancel_reason indicates the reason for canceling the watcher. - CancelReason string `protobuf:"bytes,6,opt,name=cancel_reason,json=cancelReason,proto3" json:"cancel_reason,omitempty"` - Events []*mvccpb.Event `protobuf:"bytes,11,rep,name=events" json:"events,omitempty"` -} - -func (m *WatchResponse) Reset() { *m = WatchResponse{} } -func (m *WatchResponse) String() string { return proto.CompactTextString(m) } -func (*WatchResponse) ProtoMessage() {} -func (*WatchResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{23} } - -func (m *WatchResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *WatchResponse) GetWatchId() int64 { - if m != nil { - return m.WatchId - } - return 0 -} - -func (m *WatchResponse) GetCreated() bool { - if m != nil { - return m.Created - } - return false -} - -func (m *WatchResponse) GetCanceled() bool { - if m != nil { - return m.Canceled - } - return false -} - -func (m *WatchResponse) GetCompactRevision() int64 { - if m != nil { - return m.CompactRevision - } - return 0 -} - -func (m *WatchResponse) GetCancelReason() string { - if m != nil { - return m.CancelReason - } - return "" -} - -func (m *WatchResponse) GetEvents() []*mvccpb.Event { - if m != nil { - return m.Events - } - return nil -} - -type LeaseGrantRequest struct { - // TTL is the advisory time-to-live in seconds. Expired lease will return -1. - TTL int64 `protobuf:"varint,1,opt,name=TTL,proto3" json:"TTL,omitempty"` - // ID is the requested ID for the lease. If ID is set to 0, the lessor chooses an ID. - ID int64 `protobuf:"varint,2,opt,name=ID,proto3" json:"ID,omitempty"` -} - -func (m *LeaseGrantRequest) Reset() { *m = LeaseGrantRequest{} } -func (m *LeaseGrantRequest) String() string { return proto.CompactTextString(m) } -func (*LeaseGrantRequest) ProtoMessage() {} -func (*LeaseGrantRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{24} } - -func (m *LeaseGrantRequest) GetTTL() int64 { - if m != nil { - return m.TTL - } - return 0 -} - -func (m *LeaseGrantRequest) GetID() int64 { - if m != nil { - return m.ID - } - return 0 -} - -type LeaseGrantResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // ID is the lease ID for the granted lease. - ID int64 `protobuf:"varint,2,opt,name=ID,proto3" json:"ID,omitempty"` - // TTL is the server chosen lease time-to-live in seconds. - TTL int64 `protobuf:"varint,3,opt,name=TTL,proto3" json:"TTL,omitempty"` - Error string `protobuf:"bytes,4,opt,name=error,proto3" json:"error,omitempty"` -} - -func (m *LeaseGrantResponse) Reset() { *m = LeaseGrantResponse{} } -func (m *LeaseGrantResponse) String() string { return proto.CompactTextString(m) } -func (*LeaseGrantResponse) ProtoMessage() {} -func (*LeaseGrantResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{25} } - -func (m *LeaseGrantResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *LeaseGrantResponse) GetID() int64 { - if m != nil { - return m.ID - } - return 0 -} - -func (m *LeaseGrantResponse) GetTTL() int64 { - if m != nil { - return m.TTL - } - return 0 -} - -func (m *LeaseGrantResponse) GetError() string { - if m != nil { - return m.Error - } - return "" -} - -type LeaseRevokeRequest struct { - // ID is the lease ID to revoke. When the ID is revoked, all associated keys will be deleted. - ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` -} - -func (m *LeaseRevokeRequest) Reset() { *m = LeaseRevokeRequest{} } -func (m *LeaseRevokeRequest) String() string { return proto.CompactTextString(m) } -func (*LeaseRevokeRequest) ProtoMessage() {} -func (*LeaseRevokeRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{26} } - -func (m *LeaseRevokeRequest) GetID() int64 { - if m != nil { - return m.ID - } - return 0 -} - -type LeaseRevokeResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *LeaseRevokeResponse) Reset() { *m = LeaseRevokeResponse{} } -func (m *LeaseRevokeResponse) String() string { return proto.CompactTextString(m) } -func (*LeaseRevokeResponse) ProtoMessage() {} -func (*LeaseRevokeResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{27} } - -func (m *LeaseRevokeResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type LeaseKeepAliveRequest struct { - // ID is the lease ID for the lease to keep alive. - ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` -} - -func (m *LeaseKeepAliveRequest) Reset() { *m = LeaseKeepAliveRequest{} } -func (m *LeaseKeepAliveRequest) String() string { return proto.CompactTextString(m) } -func (*LeaseKeepAliveRequest) ProtoMessage() {} -func (*LeaseKeepAliveRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{28} } - -func (m *LeaseKeepAliveRequest) GetID() int64 { - if m != nil { - return m.ID - } - return 0 -} - -type LeaseKeepAliveResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // ID is the lease ID from the keep alive request. - ID int64 `protobuf:"varint,2,opt,name=ID,proto3" json:"ID,omitempty"` - // TTL is the new time-to-live for the lease. - TTL int64 `protobuf:"varint,3,opt,name=TTL,proto3" json:"TTL,omitempty"` -} - -func (m *LeaseKeepAliveResponse) Reset() { *m = LeaseKeepAliveResponse{} } -func (m *LeaseKeepAliveResponse) String() string { return proto.CompactTextString(m) } -func (*LeaseKeepAliveResponse) ProtoMessage() {} -func (*LeaseKeepAliveResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{29} } - -func (m *LeaseKeepAliveResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *LeaseKeepAliveResponse) GetID() int64 { - if m != nil { - return m.ID - } - return 0 -} - -func (m *LeaseKeepAliveResponse) GetTTL() int64 { - if m != nil { - return m.TTL - } - return 0 -} - -type LeaseTimeToLiveRequest struct { - // ID is the lease ID for the lease. - ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` - // keys is true to query all the keys attached to this lease. - Keys bool `protobuf:"varint,2,opt,name=keys,proto3" json:"keys,omitempty"` -} - -func (m *LeaseTimeToLiveRequest) Reset() { *m = LeaseTimeToLiveRequest{} } -func (m *LeaseTimeToLiveRequest) String() string { return proto.CompactTextString(m) } -func (*LeaseTimeToLiveRequest) ProtoMessage() {} -func (*LeaseTimeToLiveRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{30} } - -func (m *LeaseTimeToLiveRequest) GetID() int64 { - if m != nil { - return m.ID - } - return 0 -} - -func (m *LeaseTimeToLiveRequest) GetKeys() bool { - if m != nil { - return m.Keys - } - return false -} - -type LeaseTimeToLiveResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // ID is the lease ID from the keep alive request. - ID int64 `protobuf:"varint,2,opt,name=ID,proto3" json:"ID,omitempty"` - // TTL is the remaining TTL in seconds for the lease; the lease will expire in under TTL+1 seconds. - TTL int64 `protobuf:"varint,3,opt,name=TTL,proto3" json:"TTL,omitempty"` - // GrantedTTL is the initial granted time in seconds upon lease creation/renewal. - GrantedTTL int64 `protobuf:"varint,4,opt,name=grantedTTL,proto3" json:"grantedTTL,omitempty"` - // Keys is the list of keys attached to this lease. - Keys [][]byte `protobuf:"bytes,5,rep,name=keys" json:"keys,omitempty"` -} - -func (m *LeaseTimeToLiveResponse) Reset() { *m = LeaseTimeToLiveResponse{} } -func (m *LeaseTimeToLiveResponse) String() string { return proto.CompactTextString(m) } -func (*LeaseTimeToLiveResponse) ProtoMessage() {} -func (*LeaseTimeToLiveResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{31} } - -func (m *LeaseTimeToLiveResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *LeaseTimeToLiveResponse) GetID() int64 { - if m != nil { - return m.ID - } - return 0 -} - -func (m *LeaseTimeToLiveResponse) GetTTL() int64 { - if m != nil { - return m.TTL - } - return 0 -} - -func (m *LeaseTimeToLiveResponse) GetGrantedTTL() int64 { - if m != nil { - return m.GrantedTTL - } - return 0 -} - -func (m *LeaseTimeToLiveResponse) GetKeys() [][]byte { - if m != nil { - return m.Keys - } - return nil -} - -type LeaseLeasesRequest struct { -} - -func (m *LeaseLeasesRequest) Reset() { *m = LeaseLeasesRequest{} } -func (m *LeaseLeasesRequest) String() string { return proto.CompactTextString(m) } -func (*LeaseLeasesRequest) ProtoMessage() {} -func (*LeaseLeasesRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{32} } - -type LeaseStatus struct { - ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` -} - -func (m *LeaseStatus) Reset() { *m = LeaseStatus{} } -func (m *LeaseStatus) String() string { return proto.CompactTextString(m) } -func (*LeaseStatus) ProtoMessage() {} -func (*LeaseStatus) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{33} } - -func (m *LeaseStatus) GetID() int64 { - if m != nil { - return m.ID - } - return 0 -} - -type LeaseLeasesResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - Leases []*LeaseStatus `protobuf:"bytes,2,rep,name=leases" json:"leases,omitempty"` -} - -func (m *LeaseLeasesResponse) Reset() { *m = LeaseLeasesResponse{} } -func (m *LeaseLeasesResponse) String() string { return proto.CompactTextString(m) } -func (*LeaseLeasesResponse) ProtoMessage() {} -func (*LeaseLeasesResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{34} } - -func (m *LeaseLeasesResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *LeaseLeasesResponse) GetLeases() []*LeaseStatus { - if m != nil { - return m.Leases - } - return nil -} - -type Member struct { - // ID is the member ID for this member. - ID uint64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` - // name is the human-readable name of the member. If the member is not started, the name will be an empty string. - Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` - // peerURLs is the list of URLs the member exposes to the cluster for communication. - PeerURLs []string `protobuf:"bytes,3,rep,name=peerURLs" json:"peerURLs,omitempty"` - // clientURLs is the list of URLs the member exposes to clients for communication. If the member is not started, clientURLs will be empty. - ClientURLs []string `protobuf:"bytes,4,rep,name=clientURLs" json:"clientURLs,omitempty"` -} - -func (m *Member) Reset() { *m = Member{} } -func (m *Member) String() string { return proto.CompactTextString(m) } -func (*Member) ProtoMessage() {} -func (*Member) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{35} } - -func (m *Member) GetID() uint64 { - if m != nil { - return m.ID - } - return 0 -} - -func (m *Member) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -func (m *Member) GetPeerURLs() []string { - if m != nil { - return m.PeerURLs - } - return nil -} - -func (m *Member) GetClientURLs() []string { - if m != nil { - return m.ClientURLs - } - return nil -} - -type MemberAddRequest struct { - // peerURLs is the list of URLs the added member will use to communicate with the cluster. - PeerURLs []string `protobuf:"bytes,1,rep,name=peerURLs" json:"peerURLs,omitempty"` -} - -func (m *MemberAddRequest) Reset() { *m = MemberAddRequest{} } -func (m *MemberAddRequest) String() string { return proto.CompactTextString(m) } -func (*MemberAddRequest) ProtoMessage() {} -func (*MemberAddRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{36} } - -func (m *MemberAddRequest) GetPeerURLs() []string { - if m != nil { - return m.PeerURLs - } - return nil -} - -type MemberAddResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // member is the member information for the added member. - Member *Member `protobuf:"bytes,2,opt,name=member" json:"member,omitempty"` - // members is a list of all members after adding the new member. - Members []*Member `protobuf:"bytes,3,rep,name=members" json:"members,omitempty"` -} - -func (m *MemberAddResponse) Reset() { *m = MemberAddResponse{} } -func (m *MemberAddResponse) String() string { return proto.CompactTextString(m) } -func (*MemberAddResponse) ProtoMessage() {} -func (*MemberAddResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{37} } - -func (m *MemberAddResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *MemberAddResponse) GetMember() *Member { - if m != nil { - return m.Member - } - return nil -} - -func (m *MemberAddResponse) GetMembers() []*Member { - if m != nil { - return m.Members - } - return nil -} - -type MemberRemoveRequest struct { - // ID is the member ID of the member to remove. - ID uint64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` -} - -func (m *MemberRemoveRequest) Reset() { *m = MemberRemoveRequest{} } -func (m *MemberRemoveRequest) String() string { return proto.CompactTextString(m) } -func (*MemberRemoveRequest) ProtoMessage() {} -func (*MemberRemoveRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{38} } - -func (m *MemberRemoveRequest) GetID() uint64 { - if m != nil { - return m.ID - } - return 0 -} - -type MemberRemoveResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // members is a list of all members after removing the member. - Members []*Member `protobuf:"bytes,2,rep,name=members" json:"members,omitempty"` -} - -func (m *MemberRemoveResponse) Reset() { *m = MemberRemoveResponse{} } -func (m *MemberRemoveResponse) String() string { return proto.CompactTextString(m) } -func (*MemberRemoveResponse) ProtoMessage() {} -func (*MemberRemoveResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{39} } - -func (m *MemberRemoveResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *MemberRemoveResponse) GetMembers() []*Member { - if m != nil { - return m.Members - } - return nil -} - -type MemberUpdateRequest struct { - // ID is the member ID of the member to update. - ID uint64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` - // peerURLs is the new list of URLs the member will use to communicate with the cluster. - PeerURLs []string `protobuf:"bytes,2,rep,name=peerURLs" json:"peerURLs,omitempty"` -} - -func (m *MemberUpdateRequest) Reset() { *m = MemberUpdateRequest{} } -func (m *MemberUpdateRequest) String() string { return proto.CompactTextString(m) } -func (*MemberUpdateRequest) ProtoMessage() {} -func (*MemberUpdateRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{40} } - -func (m *MemberUpdateRequest) GetID() uint64 { - if m != nil { - return m.ID - } - return 0 -} - -func (m *MemberUpdateRequest) GetPeerURLs() []string { - if m != nil { - return m.PeerURLs - } - return nil -} - -type MemberUpdateResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // members is a list of all members after updating the member. - Members []*Member `protobuf:"bytes,2,rep,name=members" json:"members,omitempty"` -} - -func (m *MemberUpdateResponse) Reset() { *m = MemberUpdateResponse{} } -func (m *MemberUpdateResponse) String() string { return proto.CompactTextString(m) } -func (*MemberUpdateResponse) ProtoMessage() {} -func (*MemberUpdateResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{41} } - -func (m *MemberUpdateResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *MemberUpdateResponse) GetMembers() []*Member { - if m != nil { - return m.Members - } - return nil -} - -type MemberListRequest struct { -} - -func (m *MemberListRequest) Reset() { *m = MemberListRequest{} } -func (m *MemberListRequest) String() string { return proto.CompactTextString(m) } -func (*MemberListRequest) ProtoMessage() {} -func (*MemberListRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{42} } - -type MemberListResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // members is a list of all members associated with the cluster. - Members []*Member `protobuf:"bytes,2,rep,name=members" json:"members,omitempty"` -} - -func (m *MemberListResponse) Reset() { *m = MemberListResponse{} } -func (m *MemberListResponse) String() string { return proto.CompactTextString(m) } -func (*MemberListResponse) ProtoMessage() {} -func (*MemberListResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{43} } - -func (m *MemberListResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *MemberListResponse) GetMembers() []*Member { - if m != nil { - return m.Members - } - return nil -} - -type DefragmentRequest struct { -} - -func (m *DefragmentRequest) Reset() { *m = DefragmentRequest{} } -func (m *DefragmentRequest) String() string { return proto.CompactTextString(m) } -func (*DefragmentRequest) ProtoMessage() {} -func (*DefragmentRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{44} } - -type DefragmentResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *DefragmentResponse) Reset() { *m = DefragmentResponse{} } -func (m *DefragmentResponse) String() string { return proto.CompactTextString(m) } -func (*DefragmentResponse) ProtoMessage() {} -func (*DefragmentResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{45} } - -func (m *DefragmentResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type MoveLeaderRequest struct { - // targetID is the node ID for the new leader. - TargetID uint64 `protobuf:"varint,1,opt,name=targetID,proto3" json:"targetID,omitempty"` -} - -func (m *MoveLeaderRequest) Reset() { *m = MoveLeaderRequest{} } -func (m *MoveLeaderRequest) String() string { return proto.CompactTextString(m) } -func (*MoveLeaderRequest) ProtoMessage() {} -func (*MoveLeaderRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{46} } - -func (m *MoveLeaderRequest) GetTargetID() uint64 { - if m != nil { - return m.TargetID - } - return 0 -} - -type MoveLeaderResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *MoveLeaderResponse) Reset() { *m = MoveLeaderResponse{} } -func (m *MoveLeaderResponse) String() string { return proto.CompactTextString(m) } -func (*MoveLeaderResponse) ProtoMessage() {} -func (*MoveLeaderResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{47} } - -func (m *MoveLeaderResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AlarmRequest struct { - // action is the kind of alarm request to issue. The action - // may GET alarm statuses, ACTIVATE an alarm, or DEACTIVATE a - // raised alarm. - Action AlarmRequest_AlarmAction `protobuf:"varint,1,opt,name=action,proto3,enum=etcdserverpb.AlarmRequest_AlarmAction" json:"action,omitempty"` - // memberID is the ID of the member associated with the alarm. If memberID is 0, the - // alarm request covers all members. - MemberID uint64 `protobuf:"varint,2,opt,name=memberID,proto3" json:"memberID,omitempty"` - // alarm is the type of alarm to consider for this request. - Alarm AlarmType `protobuf:"varint,3,opt,name=alarm,proto3,enum=etcdserverpb.AlarmType" json:"alarm,omitempty"` -} - -func (m *AlarmRequest) Reset() { *m = AlarmRequest{} } -func (m *AlarmRequest) String() string { return proto.CompactTextString(m) } -func (*AlarmRequest) ProtoMessage() {} -func (*AlarmRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{48} } - -func (m *AlarmRequest) GetAction() AlarmRequest_AlarmAction { - if m != nil { - return m.Action - } - return AlarmRequest_GET -} - -func (m *AlarmRequest) GetMemberID() uint64 { - if m != nil { - return m.MemberID - } - return 0 -} - -func (m *AlarmRequest) GetAlarm() AlarmType { - if m != nil { - return m.Alarm - } - return AlarmType_NONE -} - -type AlarmMember struct { - // memberID is the ID of the member associated with the raised alarm. - MemberID uint64 `protobuf:"varint,1,opt,name=memberID,proto3" json:"memberID,omitempty"` - // alarm is the type of alarm which has been raised. - Alarm AlarmType `protobuf:"varint,2,opt,name=alarm,proto3,enum=etcdserverpb.AlarmType" json:"alarm,omitempty"` -} - -func (m *AlarmMember) Reset() { *m = AlarmMember{} } -func (m *AlarmMember) String() string { return proto.CompactTextString(m) } -func (*AlarmMember) ProtoMessage() {} -func (*AlarmMember) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{49} } - -func (m *AlarmMember) GetMemberID() uint64 { - if m != nil { - return m.MemberID - } - return 0 -} - -func (m *AlarmMember) GetAlarm() AlarmType { - if m != nil { - return m.Alarm - } - return AlarmType_NONE -} - -type AlarmResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // alarms is a list of alarms associated with the alarm request. - Alarms []*AlarmMember `protobuf:"bytes,2,rep,name=alarms" json:"alarms,omitempty"` -} - -func (m *AlarmResponse) Reset() { *m = AlarmResponse{} } -func (m *AlarmResponse) String() string { return proto.CompactTextString(m) } -func (*AlarmResponse) ProtoMessage() {} -func (*AlarmResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{50} } - -func (m *AlarmResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *AlarmResponse) GetAlarms() []*AlarmMember { - if m != nil { - return m.Alarms - } - return nil -} - -type StatusRequest struct { -} - -func (m *StatusRequest) Reset() { *m = StatusRequest{} } -func (m *StatusRequest) String() string { return proto.CompactTextString(m) } -func (*StatusRequest) ProtoMessage() {} -func (*StatusRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{51} } - -type StatusResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // version is the cluster protocol version used by the responding member. - Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` - // dbSize is the size of the backend database, in bytes, of the responding member. - DbSize int64 `protobuf:"varint,3,opt,name=dbSize,proto3" json:"dbSize,omitempty"` - // leader is the member ID which the responding member believes is the current leader. - Leader uint64 `protobuf:"varint,4,opt,name=leader,proto3" json:"leader,omitempty"` - // raftIndex is the current raft index of the responding member. - RaftIndex uint64 `protobuf:"varint,5,opt,name=raftIndex,proto3" json:"raftIndex,omitempty"` - // raftTerm is the current raft term of the responding member. - RaftTerm uint64 `protobuf:"varint,6,opt,name=raftTerm,proto3" json:"raftTerm,omitempty"` -} - -func (m *StatusResponse) Reset() { *m = StatusResponse{} } -func (m *StatusResponse) String() string { return proto.CompactTextString(m) } -func (*StatusResponse) ProtoMessage() {} -func (*StatusResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{52} } - -func (m *StatusResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *StatusResponse) GetVersion() string { - if m != nil { - return m.Version - } - return "" -} - -func (m *StatusResponse) GetDbSize() int64 { - if m != nil { - return m.DbSize - } - return 0 -} - -func (m *StatusResponse) GetLeader() uint64 { - if m != nil { - return m.Leader - } - return 0 -} - -func (m *StatusResponse) GetRaftIndex() uint64 { - if m != nil { - return m.RaftIndex - } - return 0 -} - -func (m *StatusResponse) GetRaftTerm() uint64 { - if m != nil { - return m.RaftTerm - } - return 0 -} - -type AuthEnableRequest struct { -} - -func (m *AuthEnableRequest) Reset() { *m = AuthEnableRequest{} } -func (m *AuthEnableRequest) String() string { return proto.CompactTextString(m) } -func (*AuthEnableRequest) ProtoMessage() {} -func (*AuthEnableRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{53} } - -type AuthDisableRequest struct { -} - -func (m *AuthDisableRequest) Reset() { *m = AuthDisableRequest{} } -func (m *AuthDisableRequest) String() string { return proto.CompactTextString(m) } -func (*AuthDisableRequest) ProtoMessage() {} -func (*AuthDisableRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{54} } - -type AuthenticateRequest struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` -} - -func (m *AuthenticateRequest) Reset() { *m = AuthenticateRequest{} } -func (m *AuthenticateRequest) String() string { return proto.CompactTextString(m) } -func (*AuthenticateRequest) ProtoMessage() {} -func (*AuthenticateRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{55} } - -func (m *AuthenticateRequest) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -func (m *AuthenticateRequest) GetPassword() string { - if m != nil { - return m.Password - } - return "" -} - -type AuthUserAddRequest struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` -} - -func (m *AuthUserAddRequest) Reset() { *m = AuthUserAddRequest{} } -func (m *AuthUserAddRequest) String() string { return proto.CompactTextString(m) } -func (*AuthUserAddRequest) ProtoMessage() {} -func (*AuthUserAddRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{56} } - -func (m *AuthUserAddRequest) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -func (m *AuthUserAddRequest) GetPassword() string { - if m != nil { - return m.Password - } - return "" -} - -type AuthUserGetRequest struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` -} - -func (m *AuthUserGetRequest) Reset() { *m = AuthUserGetRequest{} } -func (m *AuthUserGetRequest) String() string { return proto.CompactTextString(m) } -func (*AuthUserGetRequest) ProtoMessage() {} -func (*AuthUserGetRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{57} } - -func (m *AuthUserGetRequest) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -type AuthUserDeleteRequest struct { - // name is the name of the user to delete. - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` -} - -func (m *AuthUserDeleteRequest) Reset() { *m = AuthUserDeleteRequest{} } -func (m *AuthUserDeleteRequest) String() string { return proto.CompactTextString(m) } -func (*AuthUserDeleteRequest) ProtoMessage() {} -func (*AuthUserDeleteRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{58} } - -func (m *AuthUserDeleteRequest) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -type AuthUserChangePasswordRequest struct { - // name is the name of the user whose password is being changed. - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - // password is the new password for the user. - Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` -} - -func (m *AuthUserChangePasswordRequest) Reset() { *m = AuthUserChangePasswordRequest{} } -func (m *AuthUserChangePasswordRequest) String() string { return proto.CompactTextString(m) } -func (*AuthUserChangePasswordRequest) ProtoMessage() {} -func (*AuthUserChangePasswordRequest) Descriptor() ([]byte, []int) { - return fileDescriptorRpc, []int{59} -} - -func (m *AuthUserChangePasswordRequest) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -func (m *AuthUserChangePasswordRequest) GetPassword() string { - if m != nil { - return m.Password - } - return "" -} - -type AuthUserGrantRoleRequest struct { - // user is the name of the user which should be granted a given role. - User string `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` - // role is the name of the role to grant to the user. - Role string `protobuf:"bytes,2,opt,name=role,proto3" json:"role,omitempty"` -} - -func (m *AuthUserGrantRoleRequest) Reset() { *m = AuthUserGrantRoleRequest{} } -func (m *AuthUserGrantRoleRequest) String() string { return proto.CompactTextString(m) } -func (*AuthUserGrantRoleRequest) ProtoMessage() {} -func (*AuthUserGrantRoleRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{60} } - -func (m *AuthUserGrantRoleRequest) GetUser() string { - if m != nil { - return m.User - } - return "" -} - -func (m *AuthUserGrantRoleRequest) GetRole() string { - if m != nil { - return m.Role - } - return "" -} - -type AuthUserRevokeRoleRequest struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Role string `protobuf:"bytes,2,opt,name=role,proto3" json:"role,omitempty"` -} - -func (m *AuthUserRevokeRoleRequest) Reset() { *m = AuthUserRevokeRoleRequest{} } -func (m *AuthUserRevokeRoleRequest) String() string { return proto.CompactTextString(m) } -func (*AuthUserRevokeRoleRequest) ProtoMessage() {} -func (*AuthUserRevokeRoleRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{61} } - -func (m *AuthUserRevokeRoleRequest) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -func (m *AuthUserRevokeRoleRequest) GetRole() string { - if m != nil { - return m.Role - } - return "" -} - -type AuthRoleAddRequest struct { - // name is the name of the role to add to the authentication system. - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` -} - -func (m *AuthRoleAddRequest) Reset() { *m = AuthRoleAddRequest{} } -func (m *AuthRoleAddRequest) String() string { return proto.CompactTextString(m) } -func (*AuthRoleAddRequest) ProtoMessage() {} -func (*AuthRoleAddRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{62} } - -func (m *AuthRoleAddRequest) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -type AuthRoleGetRequest struct { - Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` -} - -func (m *AuthRoleGetRequest) Reset() { *m = AuthRoleGetRequest{} } -func (m *AuthRoleGetRequest) String() string { return proto.CompactTextString(m) } -func (*AuthRoleGetRequest) ProtoMessage() {} -func (*AuthRoleGetRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{63} } - -func (m *AuthRoleGetRequest) GetRole() string { - if m != nil { - return m.Role - } - return "" -} - -type AuthUserListRequest struct { -} - -func (m *AuthUserListRequest) Reset() { *m = AuthUserListRequest{} } -func (m *AuthUserListRequest) String() string { return proto.CompactTextString(m) } -func (*AuthUserListRequest) ProtoMessage() {} -func (*AuthUserListRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{64} } - -type AuthRoleListRequest struct { -} - -func (m *AuthRoleListRequest) Reset() { *m = AuthRoleListRequest{} } -func (m *AuthRoleListRequest) String() string { return proto.CompactTextString(m) } -func (*AuthRoleListRequest) ProtoMessage() {} -func (*AuthRoleListRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{65} } - -type AuthRoleDeleteRequest struct { - Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` -} - -func (m *AuthRoleDeleteRequest) Reset() { *m = AuthRoleDeleteRequest{} } -func (m *AuthRoleDeleteRequest) String() string { return proto.CompactTextString(m) } -func (*AuthRoleDeleteRequest) ProtoMessage() {} -func (*AuthRoleDeleteRequest) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{66} } - -func (m *AuthRoleDeleteRequest) GetRole() string { - if m != nil { - return m.Role - } - return "" -} - -type AuthRoleGrantPermissionRequest struct { - // name is the name of the role which will be granted the permission. - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - // perm is the permission to grant to the role. - Perm *authpb.Permission `protobuf:"bytes,2,opt,name=perm" json:"perm,omitempty"` -} - -func (m *AuthRoleGrantPermissionRequest) Reset() { *m = AuthRoleGrantPermissionRequest{} } -func (m *AuthRoleGrantPermissionRequest) String() string { return proto.CompactTextString(m) } -func (*AuthRoleGrantPermissionRequest) ProtoMessage() {} -func (*AuthRoleGrantPermissionRequest) Descriptor() ([]byte, []int) { - return fileDescriptorRpc, []int{67} -} - -func (m *AuthRoleGrantPermissionRequest) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -func (m *AuthRoleGrantPermissionRequest) GetPerm() *authpb.Permission { - if m != nil { - return m.Perm - } - return nil -} - -type AuthRoleRevokePermissionRequest struct { - Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` - Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` - RangeEnd string `protobuf:"bytes,3,opt,name=range_end,json=rangeEnd,proto3" json:"range_end,omitempty"` -} - -func (m *AuthRoleRevokePermissionRequest) Reset() { *m = AuthRoleRevokePermissionRequest{} } -func (m *AuthRoleRevokePermissionRequest) String() string { return proto.CompactTextString(m) } -func (*AuthRoleRevokePermissionRequest) ProtoMessage() {} -func (*AuthRoleRevokePermissionRequest) Descriptor() ([]byte, []int) { - return fileDescriptorRpc, []int{68} -} - -func (m *AuthRoleRevokePermissionRequest) GetRole() string { - if m != nil { - return m.Role - } - return "" -} - -func (m *AuthRoleRevokePermissionRequest) GetKey() string { - if m != nil { - return m.Key - } - return "" -} - -func (m *AuthRoleRevokePermissionRequest) GetRangeEnd() string { - if m != nil { - return m.RangeEnd - } - return "" -} - -type AuthEnableResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthEnableResponse) Reset() { *m = AuthEnableResponse{} } -func (m *AuthEnableResponse) String() string { return proto.CompactTextString(m) } -func (*AuthEnableResponse) ProtoMessage() {} -func (*AuthEnableResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{69} } - -func (m *AuthEnableResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthDisableResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthDisableResponse) Reset() { *m = AuthDisableResponse{} } -func (m *AuthDisableResponse) String() string { return proto.CompactTextString(m) } -func (*AuthDisableResponse) ProtoMessage() {} -func (*AuthDisableResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{70} } - -func (m *AuthDisableResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthenticateResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - // token is an authorized token that can be used in succeeding RPCs - Token string `protobuf:"bytes,2,opt,name=token,proto3" json:"token,omitempty"` -} - -func (m *AuthenticateResponse) Reset() { *m = AuthenticateResponse{} } -func (m *AuthenticateResponse) String() string { return proto.CompactTextString(m) } -func (*AuthenticateResponse) ProtoMessage() {} -func (*AuthenticateResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{71} } - -func (m *AuthenticateResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *AuthenticateResponse) GetToken() string { - if m != nil { - return m.Token - } - return "" -} - -type AuthUserAddResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthUserAddResponse) Reset() { *m = AuthUserAddResponse{} } -func (m *AuthUserAddResponse) String() string { return proto.CompactTextString(m) } -func (*AuthUserAddResponse) ProtoMessage() {} -func (*AuthUserAddResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{72} } - -func (m *AuthUserAddResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthUserGetResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - Roles []string `protobuf:"bytes,2,rep,name=roles" json:"roles,omitempty"` -} - -func (m *AuthUserGetResponse) Reset() { *m = AuthUserGetResponse{} } -func (m *AuthUserGetResponse) String() string { return proto.CompactTextString(m) } -func (*AuthUserGetResponse) ProtoMessage() {} -func (*AuthUserGetResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{73} } - -func (m *AuthUserGetResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *AuthUserGetResponse) GetRoles() []string { - if m != nil { - return m.Roles - } - return nil -} - -type AuthUserDeleteResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthUserDeleteResponse) Reset() { *m = AuthUserDeleteResponse{} } -func (m *AuthUserDeleteResponse) String() string { return proto.CompactTextString(m) } -func (*AuthUserDeleteResponse) ProtoMessage() {} -func (*AuthUserDeleteResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{74} } - -func (m *AuthUserDeleteResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthUserChangePasswordResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthUserChangePasswordResponse) Reset() { *m = AuthUserChangePasswordResponse{} } -func (m *AuthUserChangePasswordResponse) String() string { return proto.CompactTextString(m) } -func (*AuthUserChangePasswordResponse) ProtoMessage() {} -func (*AuthUserChangePasswordResponse) Descriptor() ([]byte, []int) { - return fileDescriptorRpc, []int{75} -} - -func (m *AuthUserChangePasswordResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthUserGrantRoleResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthUserGrantRoleResponse) Reset() { *m = AuthUserGrantRoleResponse{} } -func (m *AuthUserGrantRoleResponse) String() string { return proto.CompactTextString(m) } -func (*AuthUserGrantRoleResponse) ProtoMessage() {} -func (*AuthUserGrantRoleResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{76} } - -func (m *AuthUserGrantRoleResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthUserRevokeRoleResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthUserRevokeRoleResponse) Reset() { *m = AuthUserRevokeRoleResponse{} } -func (m *AuthUserRevokeRoleResponse) String() string { return proto.CompactTextString(m) } -func (*AuthUserRevokeRoleResponse) ProtoMessage() {} -func (*AuthUserRevokeRoleResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{77} } - -func (m *AuthUserRevokeRoleResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthRoleAddResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthRoleAddResponse) Reset() { *m = AuthRoleAddResponse{} } -func (m *AuthRoleAddResponse) String() string { return proto.CompactTextString(m) } -func (*AuthRoleAddResponse) ProtoMessage() {} -func (*AuthRoleAddResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{78} } - -func (m *AuthRoleAddResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthRoleGetResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - Perm []*authpb.Permission `protobuf:"bytes,2,rep,name=perm" json:"perm,omitempty"` -} - -func (m *AuthRoleGetResponse) Reset() { *m = AuthRoleGetResponse{} } -func (m *AuthRoleGetResponse) String() string { return proto.CompactTextString(m) } -func (*AuthRoleGetResponse) ProtoMessage() {} -func (*AuthRoleGetResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{79} } - -func (m *AuthRoleGetResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *AuthRoleGetResponse) GetPerm() []*authpb.Permission { - if m != nil { - return m.Perm - } - return nil -} - -type AuthRoleListResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - Roles []string `protobuf:"bytes,2,rep,name=roles" json:"roles,omitempty"` -} - -func (m *AuthRoleListResponse) Reset() { *m = AuthRoleListResponse{} } -func (m *AuthRoleListResponse) String() string { return proto.CompactTextString(m) } -func (*AuthRoleListResponse) ProtoMessage() {} -func (*AuthRoleListResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{80} } - -func (m *AuthRoleListResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *AuthRoleListResponse) GetRoles() []string { - if m != nil { - return m.Roles - } - return nil -} - -type AuthUserListResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - Users []string `protobuf:"bytes,2,rep,name=users" json:"users,omitempty"` -} - -func (m *AuthUserListResponse) Reset() { *m = AuthUserListResponse{} } -func (m *AuthUserListResponse) String() string { return proto.CompactTextString(m) } -func (*AuthUserListResponse) ProtoMessage() {} -func (*AuthUserListResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{81} } - -func (m *AuthUserListResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *AuthUserListResponse) GetUsers() []string { - if m != nil { - return m.Users - } - return nil -} - -type AuthRoleDeleteResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthRoleDeleteResponse) Reset() { *m = AuthRoleDeleteResponse{} } -func (m *AuthRoleDeleteResponse) String() string { return proto.CompactTextString(m) } -func (*AuthRoleDeleteResponse) ProtoMessage() {} -func (*AuthRoleDeleteResponse) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{82} } - -func (m *AuthRoleDeleteResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthRoleGrantPermissionResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthRoleGrantPermissionResponse) Reset() { *m = AuthRoleGrantPermissionResponse{} } -func (m *AuthRoleGrantPermissionResponse) String() string { return proto.CompactTextString(m) } -func (*AuthRoleGrantPermissionResponse) ProtoMessage() {} -func (*AuthRoleGrantPermissionResponse) Descriptor() ([]byte, []int) { - return fileDescriptorRpc, []int{83} -} - -func (m *AuthRoleGrantPermissionResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type AuthRoleRevokePermissionResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` -} - -func (m *AuthRoleRevokePermissionResponse) Reset() { *m = AuthRoleRevokePermissionResponse{} } -func (m *AuthRoleRevokePermissionResponse) String() string { return proto.CompactTextString(m) } -func (*AuthRoleRevokePermissionResponse) ProtoMessage() {} -func (*AuthRoleRevokePermissionResponse) Descriptor() ([]byte, []int) { - return fileDescriptorRpc, []int{84} -} - -func (m *AuthRoleRevokePermissionResponse) GetHeader() *ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func init() { - proto.RegisterType((*ResponseHeader)(nil), "etcdserverpb.ResponseHeader") - proto.RegisterType((*RangeRequest)(nil), "etcdserverpb.RangeRequest") - proto.RegisterType((*RangeResponse)(nil), "etcdserverpb.RangeResponse") - proto.RegisterType((*PutRequest)(nil), "etcdserverpb.PutRequest") - proto.RegisterType((*PutResponse)(nil), "etcdserverpb.PutResponse") - proto.RegisterType((*DeleteRangeRequest)(nil), "etcdserverpb.DeleteRangeRequest") - proto.RegisterType((*DeleteRangeResponse)(nil), "etcdserverpb.DeleteRangeResponse") - proto.RegisterType((*RequestOp)(nil), "etcdserverpb.RequestOp") - proto.RegisterType((*ResponseOp)(nil), "etcdserverpb.ResponseOp") - proto.RegisterType((*Compare)(nil), "etcdserverpb.Compare") - proto.RegisterType((*TxnRequest)(nil), "etcdserverpb.TxnRequest") - proto.RegisterType((*TxnResponse)(nil), "etcdserverpb.TxnResponse") - proto.RegisterType((*CompactionRequest)(nil), "etcdserverpb.CompactionRequest") - proto.RegisterType((*CompactionResponse)(nil), "etcdserverpb.CompactionResponse") - proto.RegisterType((*HashRequest)(nil), "etcdserverpb.HashRequest") - proto.RegisterType((*HashKVRequest)(nil), "etcdserverpb.HashKVRequest") - proto.RegisterType((*HashKVResponse)(nil), "etcdserverpb.HashKVResponse") - proto.RegisterType((*HashResponse)(nil), "etcdserverpb.HashResponse") - proto.RegisterType((*SnapshotRequest)(nil), "etcdserverpb.SnapshotRequest") - proto.RegisterType((*SnapshotResponse)(nil), "etcdserverpb.SnapshotResponse") - proto.RegisterType((*WatchRequest)(nil), "etcdserverpb.WatchRequest") - proto.RegisterType((*WatchCreateRequest)(nil), "etcdserverpb.WatchCreateRequest") - proto.RegisterType((*WatchCancelRequest)(nil), "etcdserverpb.WatchCancelRequest") - proto.RegisterType((*WatchResponse)(nil), "etcdserverpb.WatchResponse") - proto.RegisterType((*LeaseGrantRequest)(nil), "etcdserverpb.LeaseGrantRequest") - proto.RegisterType((*LeaseGrantResponse)(nil), "etcdserverpb.LeaseGrantResponse") - proto.RegisterType((*LeaseRevokeRequest)(nil), "etcdserverpb.LeaseRevokeRequest") - proto.RegisterType((*LeaseRevokeResponse)(nil), "etcdserverpb.LeaseRevokeResponse") - proto.RegisterType((*LeaseKeepAliveRequest)(nil), "etcdserverpb.LeaseKeepAliveRequest") - proto.RegisterType((*LeaseKeepAliveResponse)(nil), "etcdserverpb.LeaseKeepAliveResponse") - proto.RegisterType((*LeaseTimeToLiveRequest)(nil), "etcdserverpb.LeaseTimeToLiveRequest") - proto.RegisterType((*LeaseTimeToLiveResponse)(nil), "etcdserverpb.LeaseTimeToLiveResponse") - proto.RegisterType((*LeaseLeasesRequest)(nil), "etcdserverpb.LeaseLeasesRequest") - proto.RegisterType((*LeaseStatus)(nil), "etcdserverpb.LeaseStatus") - proto.RegisterType((*LeaseLeasesResponse)(nil), "etcdserverpb.LeaseLeasesResponse") - proto.RegisterType((*Member)(nil), "etcdserverpb.Member") - proto.RegisterType((*MemberAddRequest)(nil), "etcdserverpb.MemberAddRequest") - proto.RegisterType((*MemberAddResponse)(nil), "etcdserverpb.MemberAddResponse") - proto.RegisterType((*MemberRemoveRequest)(nil), "etcdserverpb.MemberRemoveRequest") - proto.RegisterType((*MemberRemoveResponse)(nil), "etcdserverpb.MemberRemoveResponse") - proto.RegisterType((*MemberUpdateRequest)(nil), "etcdserverpb.MemberUpdateRequest") - proto.RegisterType((*MemberUpdateResponse)(nil), "etcdserverpb.MemberUpdateResponse") - proto.RegisterType((*MemberListRequest)(nil), "etcdserverpb.MemberListRequest") - proto.RegisterType((*MemberListResponse)(nil), "etcdserverpb.MemberListResponse") - proto.RegisterType((*DefragmentRequest)(nil), "etcdserverpb.DefragmentRequest") - proto.RegisterType((*DefragmentResponse)(nil), "etcdserverpb.DefragmentResponse") - proto.RegisterType((*MoveLeaderRequest)(nil), "etcdserverpb.MoveLeaderRequest") - proto.RegisterType((*MoveLeaderResponse)(nil), "etcdserverpb.MoveLeaderResponse") - proto.RegisterType((*AlarmRequest)(nil), "etcdserverpb.AlarmRequest") - proto.RegisterType((*AlarmMember)(nil), "etcdserverpb.AlarmMember") - proto.RegisterType((*AlarmResponse)(nil), "etcdserverpb.AlarmResponse") - proto.RegisterType((*StatusRequest)(nil), "etcdserverpb.StatusRequest") - proto.RegisterType((*StatusResponse)(nil), "etcdserverpb.StatusResponse") - proto.RegisterType((*AuthEnableRequest)(nil), "etcdserverpb.AuthEnableRequest") - proto.RegisterType((*AuthDisableRequest)(nil), "etcdserverpb.AuthDisableRequest") - proto.RegisterType((*AuthenticateRequest)(nil), "etcdserverpb.AuthenticateRequest") - proto.RegisterType((*AuthUserAddRequest)(nil), "etcdserverpb.AuthUserAddRequest") - proto.RegisterType((*AuthUserGetRequest)(nil), "etcdserverpb.AuthUserGetRequest") - proto.RegisterType((*AuthUserDeleteRequest)(nil), "etcdserverpb.AuthUserDeleteRequest") - proto.RegisterType((*AuthUserChangePasswordRequest)(nil), "etcdserverpb.AuthUserChangePasswordRequest") - proto.RegisterType((*AuthUserGrantRoleRequest)(nil), "etcdserverpb.AuthUserGrantRoleRequest") - proto.RegisterType((*AuthUserRevokeRoleRequest)(nil), "etcdserverpb.AuthUserRevokeRoleRequest") - proto.RegisterType((*AuthRoleAddRequest)(nil), "etcdserverpb.AuthRoleAddRequest") - proto.RegisterType((*AuthRoleGetRequest)(nil), "etcdserverpb.AuthRoleGetRequest") - proto.RegisterType((*AuthUserListRequest)(nil), "etcdserverpb.AuthUserListRequest") - proto.RegisterType((*AuthRoleListRequest)(nil), "etcdserverpb.AuthRoleListRequest") - proto.RegisterType((*AuthRoleDeleteRequest)(nil), "etcdserverpb.AuthRoleDeleteRequest") - proto.RegisterType((*AuthRoleGrantPermissionRequest)(nil), "etcdserverpb.AuthRoleGrantPermissionRequest") - proto.RegisterType((*AuthRoleRevokePermissionRequest)(nil), "etcdserverpb.AuthRoleRevokePermissionRequest") - proto.RegisterType((*AuthEnableResponse)(nil), "etcdserverpb.AuthEnableResponse") - proto.RegisterType((*AuthDisableResponse)(nil), "etcdserverpb.AuthDisableResponse") - proto.RegisterType((*AuthenticateResponse)(nil), "etcdserverpb.AuthenticateResponse") - proto.RegisterType((*AuthUserAddResponse)(nil), "etcdserverpb.AuthUserAddResponse") - proto.RegisterType((*AuthUserGetResponse)(nil), "etcdserverpb.AuthUserGetResponse") - proto.RegisterType((*AuthUserDeleteResponse)(nil), "etcdserverpb.AuthUserDeleteResponse") - proto.RegisterType((*AuthUserChangePasswordResponse)(nil), "etcdserverpb.AuthUserChangePasswordResponse") - proto.RegisterType((*AuthUserGrantRoleResponse)(nil), "etcdserverpb.AuthUserGrantRoleResponse") - proto.RegisterType((*AuthUserRevokeRoleResponse)(nil), "etcdserverpb.AuthUserRevokeRoleResponse") - proto.RegisterType((*AuthRoleAddResponse)(nil), "etcdserverpb.AuthRoleAddResponse") - proto.RegisterType((*AuthRoleGetResponse)(nil), "etcdserverpb.AuthRoleGetResponse") - proto.RegisterType((*AuthRoleListResponse)(nil), "etcdserverpb.AuthRoleListResponse") - proto.RegisterType((*AuthUserListResponse)(nil), "etcdserverpb.AuthUserListResponse") - proto.RegisterType((*AuthRoleDeleteResponse)(nil), "etcdserverpb.AuthRoleDeleteResponse") - proto.RegisterType((*AuthRoleGrantPermissionResponse)(nil), "etcdserverpb.AuthRoleGrantPermissionResponse") - proto.RegisterType((*AuthRoleRevokePermissionResponse)(nil), "etcdserverpb.AuthRoleRevokePermissionResponse") - proto.RegisterEnum("etcdserverpb.AlarmType", AlarmType_name, AlarmType_value) - proto.RegisterEnum("etcdserverpb.RangeRequest_SortOrder", RangeRequest_SortOrder_name, RangeRequest_SortOrder_value) - proto.RegisterEnum("etcdserverpb.RangeRequest_SortTarget", RangeRequest_SortTarget_name, RangeRequest_SortTarget_value) - proto.RegisterEnum("etcdserverpb.Compare_CompareResult", Compare_CompareResult_name, Compare_CompareResult_value) - proto.RegisterEnum("etcdserverpb.Compare_CompareTarget", Compare_CompareTarget_name, Compare_CompareTarget_value) - proto.RegisterEnum("etcdserverpb.WatchCreateRequest_FilterType", WatchCreateRequest_FilterType_name, WatchCreateRequest_FilterType_value) - proto.RegisterEnum("etcdserverpb.AlarmRequest_AlarmAction", AlarmRequest_AlarmAction_name, AlarmRequest_AlarmAction_value) -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// Client API for KV service - -type KVClient interface { - // Range gets the keys in the range from the key-value store. - Range(ctx context.Context, in *RangeRequest, opts ...grpc.CallOption) (*RangeResponse, error) - // Put puts the given key into the key-value store. - // A put request increments the revision of the key-value store - // and generates one event in the event history. - Put(ctx context.Context, in *PutRequest, opts ...grpc.CallOption) (*PutResponse, error) - // DeleteRange deletes the given range from the key-value store. - // A delete request increments the revision of the key-value store - // and generates a delete event in the event history for every deleted key. - DeleteRange(ctx context.Context, in *DeleteRangeRequest, opts ...grpc.CallOption) (*DeleteRangeResponse, error) - // Txn processes multiple requests in a single transaction. - // A txn request increments the revision of the key-value store - // and generates events with the same revision for every completed request. - // It is not allowed to modify the same key several times within one txn. - Txn(ctx context.Context, in *TxnRequest, opts ...grpc.CallOption) (*TxnResponse, error) - // Compact compacts the event history in the etcd key-value store. The key-value - // store should be periodically compacted or the event history will continue to grow - // indefinitely. - Compact(ctx context.Context, in *CompactionRequest, opts ...grpc.CallOption) (*CompactionResponse, error) -} - -type kVClient struct { - cc *grpc.ClientConn -} - -func NewKVClient(cc *grpc.ClientConn) KVClient { - return &kVClient{cc} -} - -func (c *kVClient) Range(ctx context.Context, in *RangeRequest, opts ...grpc.CallOption) (*RangeResponse, error) { - out := new(RangeResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.KV/Range", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *kVClient) Put(ctx context.Context, in *PutRequest, opts ...grpc.CallOption) (*PutResponse, error) { - out := new(PutResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.KV/Put", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *kVClient) DeleteRange(ctx context.Context, in *DeleteRangeRequest, opts ...grpc.CallOption) (*DeleteRangeResponse, error) { - out := new(DeleteRangeResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.KV/DeleteRange", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *kVClient) Txn(ctx context.Context, in *TxnRequest, opts ...grpc.CallOption) (*TxnResponse, error) { - out := new(TxnResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.KV/Txn", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *kVClient) Compact(ctx context.Context, in *CompactionRequest, opts ...grpc.CallOption) (*CompactionResponse, error) { - out := new(CompactionResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.KV/Compact", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for KV service - -type KVServer interface { - // Range gets the keys in the range from the key-value store. - Range(context.Context, *RangeRequest) (*RangeResponse, error) - // Put puts the given key into the key-value store. - // A put request increments the revision of the key-value store - // and generates one event in the event history. - Put(context.Context, *PutRequest) (*PutResponse, error) - // DeleteRange deletes the given range from the key-value store. - // A delete request increments the revision of the key-value store - // and generates a delete event in the event history for every deleted key. - DeleteRange(context.Context, *DeleteRangeRequest) (*DeleteRangeResponse, error) - // Txn processes multiple requests in a single transaction. - // A txn request increments the revision of the key-value store - // and generates events with the same revision for every completed request. - // It is not allowed to modify the same key several times within one txn. - Txn(context.Context, *TxnRequest) (*TxnResponse, error) - // Compact compacts the event history in the etcd key-value store. The key-value - // store should be periodically compacted or the event history will continue to grow - // indefinitely. - Compact(context.Context, *CompactionRequest) (*CompactionResponse, error) -} - -func RegisterKVServer(s *grpc.Server, srv KVServer) { - s.RegisterService(&_KV_serviceDesc, srv) -} - -func _KV_Range_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(RangeRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(KVServer).Range(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.KV/Range", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(KVServer).Range(ctx, req.(*RangeRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _KV_Put_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(PutRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(KVServer).Put(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.KV/Put", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(KVServer).Put(ctx, req.(*PutRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _KV_DeleteRange_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(DeleteRangeRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(KVServer).DeleteRange(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.KV/DeleteRange", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(KVServer).DeleteRange(ctx, req.(*DeleteRangeRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _KV_Txn_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(TxnRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(KVServer).Txn(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.KV/Txn", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(KVServer).Txn(ctx, req.(*TxnRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _KV_Compact_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(CompactionRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(KVServer).Compact(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.KV/Compact", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(KVServer).Compact(ctx, req.(*CompactionRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _KV_serviceDesc = grpc.ServiceDesc{ - ServiceName: "etcdserverpb.KV", - HandlerType: (*KVServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Range", - Handler: _KV_Range_Handler, - }, - { - MethodName: "Put", - Handler: _KV_Put_Handler, - }, - { - MethodName: "DeleteRange", - Handler: _KV_DeleteRange_Handler, - }, - { - MethodName: "Txn", - Handler: _KV_Txn_Handler, - }, - { - MethodName: "Compact", - Handler: _KV_Compact_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "rpc.proto", -} - -// Client API for Watch service - -type WatchClient interface { - // Watch watches for events happening or that have happened. Both input and output - // are streams; the input stream is for creating and canceling watchers and the output - // stream sends events. One watch RPC can watch on multiple key ranges, streaming events - // for several watches at once. The entire event history can be watched starting from the - // last compaction revision. - Watch(ctx context.Context, opts ...grpc.CallOption) (Watch_WatchClient, error) -} - -type watchClient struct { - cc *grpc.ClientConn -} - -func NewWatchClient(cc *grpc.ClientConn) WatchClient { - return &watchClient{cc} -} - -func (c *watchClient) Watch(ctx context.Context, opts ...grpc.CallOption) (Watch_WatchClient, error) { - stream, err := grpc.NewClientStream(ctx, &_Watch_serviceDesc.Streams[0], c.cc, "/etcdserverpb.Watch/Watch", opts...) - if err != nil { - return nil, err - } - x := &watchWatchClient{stream} - return x, nil -} - -type Watch_WatchClient interface { - Send(*WatchRequest) error - Recv() (*WatchResponse, error) - grpc.ClientStream -} - -type watchWatchClient struct { - grpc.ClientStream -} - -func (x *watchWatchClient) Send(m *WatchRequest) error { - return x.ClientStream.SendMsg(m) -} - -func (x *watchWatchClient) Recv() (*WatchResponse, error) { - m := new(WatchResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -// Server API for Watch service - -type WatchServer interface { - // Watch watches for events happening or that have happened. Both input and output - // are streams; the input stream is for creating and canceling watchers and the output - // stream sends events. One watch RPC can watch on multiple key ranges, streaming events - // for several watches at once. The entire event history can be watched starting from the - // last compaction revision. - Watch(Watch_WatchServer) error -} - -func RegisterWatchServer(s *grpc.Server, srv WatchServer) { - s.RegisterService(&_Watch_serviceDesc, srv) -} - -func _Watch_Watch_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(WatchServer).Watch(&watchWatchServer{stream}) -} - -type Watch_WatchServer interface { - Send(*WatchResponse) error - Recv() (*WatchRequest, error) - grpc.ServerStream -} - -type watchWatchServer struct { - grpc.ServerStream -} - -func (x *watchWatchServer) Send(m *WatchResponse) error { - return x.ServerStream.SendMsg(m) -} - -func (x *watchWatchServer) Recv() (*WatchRequest, error) { - m := new(WatchRequest) - if err := x.ServerStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -var _Watch_serviceDesc = grpc.ServiceDesc{ - ServiceName: "etcdserverpb.Watch", - HandlerType: (*WatchServer)(nil), - Methods: []grpc.MethodDesc{}, - Streams: []grpc.StreamDesc{ - { - StreamName: "Watch", - Handler: _Watch_Watch_Handler, - ServerStreams: true, - ClientStreams: true, - }, - }, - Metadata: "rpc.proto", -} - -// Client API for Lease service - -type LeaseClient interface { - // LeaseGrant creates a lease which expires if the server does not receive a keepAlive - // within a given time to live period. All keys attached to the lease will be expired and - // deleted if the lease expires. Each expired key generates a delete event in the event history. - LeaseGrant(ctx context.Context, in *LeaseGrantRequest, opts ...grpc.CallOption) (*LeaseGrantResponse, error) - // LeaseRevoke revokes a lease. All keys attached to the lease will expire and be deleted. - LeaseRevoke(ctx context.Context, in *LeaseRevokeRequest, opts ...grpc.CallOption) (*LeaseRevokeResponse, error) - // LeaseKeepAlive keeps the lease alive by streaming keep alive requests from the client - // to the server and streaming keep alive responses from the server to the client. - LeaseKeepAlive(ctx context.Context, opts ...grpc.CallOption) (Lease_LeaseKeepAliveClient, error) - // LeaseTimeToLive retrieves lease information. - LeaseTimeToLive(ctx context.Context, in *LeaseTimeToLiveRequest, opts ...grpc.CallOption) (*LeaseTimeToLiveResponse, error) - // LeaseLeases lists all existing leases. - LeaseLeases(ctx context.Context, in *LeaseLeasesRequest, opts ...grpc.CallOption) (*LeaseLeasesResponse, error) -} - -type leaseClient struct { - cc *grpc.ClientConn -} - -func NewLeaseClient(cc *grpc.ClientConn) LeaseClient { - return &leaseClient{cc} -} - -func (c *leaseClient) LeaseGrant(ctx context.Context, in *LeaseGrantRequest, opts ...grpc.CallOption) (*LeaseGrantResponse, error) { - out := new(LeaseGrantResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Lease/LeaseGrant", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *leaseClient) LeaseRevoke(ctx context.Context, in *LeaseRevokeRequest, opts ...grpc.CallOption) (*LeaseRevokeResponse, error) { - out := new(LeaseRevokeResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Lease/LeaseRevoke", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *leaseClient) LeaseKeepAlive(ctx context.Context, opts ...grpc.CallOption) (Lease_LeaseKeepAliveClient, error) { - stream, err := grpc.NewClientStream(ctx, &_Lease_serviceDesc.Streams[0], c.cc, "/etcdserverpb.Lease/LeaseKeepAlive", opts...) - if err != nil { - return nil, err - } - x := &leaseLeaseKeepAliveClient{stream} - return x, nil -} - -type Lease_LeaseKeepAliveClient interface { - Send(*LeaseKeepAliveRequest) error - Recv() (*LeaseKeepAliveResponse, error) - grpc.ClientStream -} - -type leaseLeaseKeepAliveClient struct { - grpc.ClientStream -} - -func (x *leaseLeaseKeepAliveClient) Send(m *LeaseKeepAliveRequest) error { - return x.ClientStream.SendMsg(m) -} - -func (x *leaseLeaseKeepAliveClient) Recv() (*LeaseKeepAliveResponse, error) { - m := new(LeaseKeepAliveResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *leaseClient) LeaseTimeToLive(ctx context.Context, in *LeaseTimeToLiveRequest, opts ...grpc.CallOption) (*LeaseTimeToLiveResponse, error) { - out := new(LeaseTimeToLiveResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Lease/LeaseTimeToLive", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *leaseClient) LeaseLeases(ctx context.Context, in *LeaseLeasesRequest, opts ...grpc.CallOption) (*LeaseLeasesResponse, error) { - out := new(LeaseLeasesResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Lease/LeaseLeases", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for Lease service - -type LeaseServer interface { - // LeaseGrant creates a lease which expires if the server does not receive a keepAlive - // within a given time to live period. All keys attached to the lease will be expired and - // deleted if the lease expires. Each expired key generates a delete event in the event history. - LeaseGrant(context.Context, *LeaseGrantRequest) (*LeaseGrantResponse, error) - // LeaseRevoke revokes a lease. All keys attached to the lease will expire and be deleted. - LeaseRevoke(context.Context, *LeaseRevokeRequest) (*LeaseRevokeResponse, error) - // LeaseKeepAlive keeps the lease alive by streaming keep alive requests from the client - // to the server and streaming keep alive responses from the server to the client. - LeaseKeepAlive(Lease_LeaseKeepAliveServer) error - // LeaseTimeToLive retrieves lease information. - LeaseTimeToLive(context.Context, *LeaseTimeToLiveRequest) (*LeaseTimeToLiveResponse, error) - // LeaseLeases lists all existing leases. - LeaseLeases(context.Context, *LeaseLeasesRequest) (*LeaseLeasesResponse, error) -} - -func RegisterLeaseServer(s *grpc.Server, srv LeaseServer) { - s.RegisterService(&_Lease_serviceDesc, srv) -} - -func _Lease_LeaseGrant_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(LeaseGrantRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(LeaseServer).LeaseGrant(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Lease/LeaseGrant", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(LeaseServer).LeaseGrant(ctx, req.(*LeaseGrantRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Lease_LeaseRevoke_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(LeaseRevokeRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(LeaseServer).LeaseRevoke(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Lease/LeaseRevoke", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(LeaseServer).LeaseRevoke(ctx, req.(*LeaseRevokeRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Lease_LeaseKeepAlive_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(LeaseServer).LeaseKeepAlive(&leaseLeaseKeepAliveServer{stream}) -} - -type Lease_LeaseKeepAliveServer interface { - Send(*LeaseKeepAliveResponse) error - Recv() (*LeaseKeepAliveRequest, error) - grpc.ServerStream -} - -type leaseLeaseKeepAliveServer struct { - grpc.ServerStream -} - -func (x *leaseLeaseKeepAliveServer) Send(m *LeaseKeepAliveResponse) error { - return x.ServerStream.SendMsg(m) -} - -func (x *leaseLeaseKeepAliveServer) Recv() (*LeaseKeepAliveRequest, error) { - m := new(LeaseKeepAliveRequest) - if err := x.ServerStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func _Lease_LeaseTimeToLive_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(LeaseTimeToLiveRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(LeaseServer).LeaseTimeToLive(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Lease/LeaseTimeToLive", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(LeaseServer).LeaseTimeToLive(ctx, req.(*LeaseTimeToLiveRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Lease_LeaseLeases_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(LeaseLeasesRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(LeaseServer).LeaseLeases(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Lease/LeaseLeases", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(LeaseServer).LeaseLeases(ctx, req.(*LeaseLeasesRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Lease_serviceDesc = grpc.ServiceDesc{ - ServiceName: "etcdserverpb.Lease", - HandlerType: (*LeaseServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "LeaseGrant", - Handler: _Lease_LeaseGrant_Handler, - }, - { - MethodName: "LeaseRevoke", - Handler: _Lease_LeaseRevoke_Handler, - }, - { - MethodName: "LeaseTimeToLive", - Handler: _Lease_LeaseTimeToLive_Handler, - }, - { - MethodName: "LeaseLeases", - Handler: _Lease_LeaseLeases_Handler, - }, - }, - Streams: []grpc.StreamDesc{ - { - StreamName: "LeaseKeepAlive", - Handler: _Lease_LeaseKeepAlive_Handler, - ServerStreams: true, - ClientStreams: true, - }, - }, - Metadata: "rpc.proto", -} - -// Client API for Cluster service - -type ClusterClient interface { - // MemberAdd adds a member into the cluster. - MemberAdd(ctx context.Context, in *MemberAddRequest, opts ...grpc.CallOption) (*MemberAddResponse, error) - // MemberRemove removes an existing member from the cluster. - MemberRemove(ctx context.Context, in *MemberRemoveRequest, opts ...grpc.CallOption) (*MemberRemoveResponse, error) - // MemberUpdate updates the member configuration. - MemberUpdate(ctx context.Context, in *MemberUpdateRequest, opts ...grpc.CallOption) (*MemberUpdateResponse, error) - // MemberList lists all the members in the cluster. - MemberList(ctx context.Context, in *MemberListRequest, opts ...grpc.CallOption) (*MemberListResponse, error) -} - -type clusterClient struct { - cc *grpc.ClientConn -} - -func NewClusterClient(cc *grpc.ClientConn) ClusterClient { - return &clusterClient{cc} -} - -func (c *clusterClient) MemberAdd(ctx context.Context, in *MemberAddRequest, opts ...grpc.CallOption) (*MemberAddResponse, error) { - out := new(MemberAddResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Cluster/MemberAdd", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *clusterClient) MemberRemove(ctx context.Context, in *MemberRemoveRequest, opts ...grpc.CallOption) (*MemberRemoveResponse, error) { - out := new(MemberRemoveResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Cluster/MemberRemove", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *clusterClient) MemberUpdate(ctx context.Context, in *MemberUpdateRequest, opts ...grpc.CallOption) (*MemberUpdateResponse, error) { - out := new(MemberUpdateResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Cluster/MemberUpdate", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *clusterClient) MemberList(ctx context.Context, in *MemberListRequest, opts ...grpc.CallOption) (*MemberListResponse, error) { - out := new(MemberListResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Cluster/MemberList", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for Cluster service - -type ClusterServer interface { - // MemberAdd adds a member into the cluster. - MemberAdd(context.Context, *MemberAddRequest) (*MemberAddResponse, error) - // MemberRemove removes an existing member from the cluster. - MemberRemove(context.Context, *MemberRemoveRequest) (*MemberRemoveResponse, error) - // MemberUpdate updates the member configuration. - MemberUpdate(context.Context, *MemberUpdateRequest) (*MemberUpdateResponse, error) - // MemberList lists all the members in the cluster. - MemberList(context.Context, *MemberListRequest) (*MemberListResponse, error) -} - -func RegisterClusterServer(s *grpc.Server, srv ClusterServer) { - s.RegisterService(&_Cluster_serviceDesc, srv) -} - -func _Cluster_MemberAdd_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MemberAddRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ClusterServer).MemberAdd(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Cluster/MemberAdd", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ClusterServer).MemberAdd(ctx, req.(*MemberAddRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Cluster_MemberRemove_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MemberRemoveRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ClusterServer).MemberRemove(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Cluster/MemberRemove", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ClusterServer).MemberRemove(ctx, req.(*MemberRemoveRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Cluster_MemberUpdate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MemberUpdateRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ClusterServer).MemberUpdate(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Cluster/MemberUpdate", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ClusterServer).MemberUpdate(ctx, req.(*MemberUpdateRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Cluster_MemberList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MemberListRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ClusterServer).MemberList(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Cluster/MemberList", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ClusterServer).MemberList(ctx, req.(*MemberListRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Cluster_serviceDesc = grpc.ServiceDesc{ - ServiceName: "etcdserverpb.Cluster", - HandlerType: (*ClusterServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "MemberAdd", - Handler: _Cluster_MemberAdd_Handler, - }, - { - MethodName: "MemberRemove", - Handler: _Cluster_MemberRemove_Handler, - }, - { - MethodName: "MemberUpdate", - Handler: _Cluster_MemberUpdate_Handler, - }, - { - MethodName: "MemberList", - Handler: _Cluster_MemberList_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "rpc.proto", -} - -// Client API for Maintenance service - -type MaintenanceClient interface { - // Alarm activates, deactivates, and queries alarms regarding cluster health. - Alarm(ctx context.Context, in *AlarmRequest, opts ...grpc.CallOption) (*AlarmResponse, error) - // Status gets the status of the member. - Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*StatusResponse, error) - // Defragment defragments a member's backend database to recover storage space. - Defragment(ctx context.Context, in *DefragmentRequest, opts ...grpc.CallOption) (*DefragmentResponse, error) - // Hash computes the hash of the KV's backend. - // This is designed for testing; do not use this in production when there - // are ongoing transactions. - Hash(ctx context.Context, in *HashRequest, opts ...grpc.CallOption) (*HashResponse, error) - // HashKV computes the hash of all MVCC keys up to a given revision. - HashKV(ctx context.Context, in *HashKVRequest, opts ...grpc.CallOption) (*HashKVResponse, error) - // Snapshot sends a snapshot of the entire backend from a member over a stream to a client. - Snapshot(ctx context.Context, in *SnapshotRequest, opts ...grpc.CallOption) (Maintenance_SnapshotClient, error) - // MoveLeader requests current leader node to transfer its leadership to transferee. - MoveLeader(ctx context.Context, in *MoveLeaderRequest, opts ...grpc.CallOption) (*MoveLeaderResponse, error) -} - -type maintenanceClient struct { - cc *grpc.ClientConn -} - -func NewMaintenanceClient(cc *grpc.ClientConn) MaintenanceClient { - return &maintenanceClient{cc} -} - -func (c *maintenanceClient) Alarm(ctx context.Context, in *AlarmRequest, opts ...grpc.CallOption) (*AlarmResponse, error) { - out := new(AlarmResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Maintenance/Alarm", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *maintenanceClient) Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*StatusResponse, error) { - out := new(StatusResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Maintenance/Status", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *maintenanceClient) Defragment(ctx context.Context, in *DefragmentRequest, opts ...grpc.CallOption) (*DefragmentResponse, error) { - out := new(DefragmentResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Maintenance/Defragment", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *maintenanceClient) Hash(ctx context.Context, in *HashRequest, opts ...grpc.CallOption) (*HashResponse, error) { - out := new(HashResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Maintenance/Hash", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *maintenanceClient) HashKV(ctx context.Context, in *HashKVRequest, opts ...grpc.CallOption) (*HashKVResponse, error) { - out := new(HashKVResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Maintenance/HashKV", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *maintenanceClient) Snapshot(ctx context.Context, in *SnapshotRequest, opts ...grpc.CallOption) (Maintenance_SnapshotClient, error) { - stream, err := grpc.NewClientStream(ctx, &_Maintenance_serviceDesc.Streams[0], c.cc, "/etcdserverpb.Maintenance/Snapshot", opts...) - if err != nil { - return nil, err - } - x := &maintenanceSnapshotClient{stream} - if err := x.ClientStream.SendMsg(in); err != nil { - return nil, err - } - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - return x, nil -} - -type Maintenance_SnapshotClient interface { - Recv() (*SnapshotResponse, error) - grpc.ClientStream -} - -type maintenanceSnapshotClient struct { - grpc.ClientStream -} - -func (x *maintenanceSnapshotClient) Recv() (*SnapshotResponse, error) { - m := new(SnapshotResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *maintenanceClient) MoveLeader(ctx context.Context, in *MoveLeaderRequest, opts ...grpc.CallOption) (*MoveLeaderResponse, error) { - out := new(MoveLeaderResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Maintenance/MoveLeader", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for Maintenance service - -type MaintenanceServer interface { - // Alarm activates, deactivates, and queries alarms regarding cluster health. - Alarm(context.Context, *AlarmRequest) (*AlarmResponse, error) - // Status gets the status of the member. - Status(context.Context, *StatusRequest) (*StatusResponse, error) - // Defragment defragments a member's backend database to recover storage space. - Defragment(context.Context, *DefragmentRequest) (*DefragmentResponse, error) - // Hash computes the hash of the KV's backend. - // This is designed for testing; do not use this in production when there - // are ongoing transactions. - Hash(context.Context, *HashRequest) (*HashResponse, error) - // HashKV computes the hash of all MVCC keys up to a given revision. - HashKV(context.Context, *HashKVRequest) (*HashKVResponse, error) - // Snapshot sends a snapshot of the entire backend from a member over a stream to a client. - Snapshot(*SnapshotRequest, Maintenance_SnapshotServer) error - // MoveLeader requests current leader node to transfer its leadership to transferee. - MoveLeader(context.Context, *MoveLeaderRequest) (*MoveLeaderResponse, error) -} - -func RegisterMaintenanceServer(s *grpc.Server, srv MaintenanceServer) { - s.RegisterService(&_Maintenance_serviceDesc, srv) -} - -func _Maintenance_Alarm_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AlarmRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MaintenanceServer).Alarm(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Maintenance/Alarm", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MaintenanceServer).Alarm(ctx, req.(*AlarmRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Maintenance_Status_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(StatusRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MaintenanceServer).Status(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Maintenance/Status", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MaintenanceServer).Status(ctx, req.(*StatusRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Maintenance_Defragment_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(DefragmentRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MaintenanceServer).Defragment(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Maintenance/Defragment", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MaintenanceServer).Defragment(ctx, req.(*DefragmentRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Maintenance_Hash_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(HashRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MaintenanceServer).Hash(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Maintenance/Hash", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MaintenanceServer).Hash(ctx, req.(*HashRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Maintenance_HashKV_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(HashKVRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MaintenanceServer).HashKV(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Maintenance/HashKV", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MaintenanceServer).HashKV(ctx, req.(*HashKVRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Maintenance_Snapshot_Handler(srv interface{}, stream grpc.ServerStream) error { - m := new(SnapshotRequest) - if err := stream.RecvMsg(m); err != nil { - return err - } - return srv.(MaintenanceServer).Snapshot(m, &maintenanceSnapshotServer{stream}) -} - -type Maintenance_SnapshotServer interface { - Send(*SnapshotResponse) error - grpc.ServerStream -} - -type maintenanceSnapshotServer struct { - grpc.ServerStream -} - -func (x *maintenanceSnapshotServer) Send(m *SnapshotResponse) error { - return x.ServerStream.SendMsg(m) -} - -func _Maintenance_MoveLeader_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MoveLeaderRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MaintenanceServer).MoveLeader(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Maintenance/MoveLeader", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MaintenanceServer).MoveLeader(ctx, req.(*MoveLeaderRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Maintenance_serviceDesc = grpc.ServiceDesc{ - ServiceName: "etcdserverpb.Maintenance", - HandlerType: (*MaintenanceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Alarm", - Handler: _Maintenance_Alarm_Handler, - }, - { - MethodName: "Status", - Handler: _Maintenance_Status_Handler, - }, - { - MethodName: "Defragment", - Handler: _Maintenance_Defragment_Handler, - }, - { - MethodName: "Hash", - Handler: _Maintenance_Hash_Handler, - }, - { - MethodName: "HashKV", - Handler: _Maintenance_HashKV_Handler, - }, - { - MethodName: "MoveLeader", - Handler: _Maintenance_MoveLeader_Handler, - }, - }, - Streams: []grpc.StreamDesc{ - { - StreamName: "Snapshot", - Handler: _Maintenance_Snapshot_Handler, - ServerStreams: true, - }, - }, - Metadata: "rpc.proto", -} - -// Client API for Auth service - -type AuthClient interface { - // AuthEnable enables authentication. - AuthEnable(ctx context.Context, in *AuthEnableRequest, opts ...grpc.CallOption) (*AuthEnableResponse, error) - // AuthDisable disables authentication. - AuthDisable(ctx context.Context, in *AuthDisableRequest, opts ...grpc.CallOption) (*AuthDisableResponse, error) - // Authenticate processes an authenticate request. - Authenticate(ctx context.Context, in *AuthenticateRequest, opts ...grpc.CallOption) (*AuthenticateResponse, error) - // UserAdd adds a new user. - UserAdd(ctx context.Context, in *AuthUserAddRequest, opts ...grpc.CallOption) (*AuthUserAddResponse, error) - // UserGet gets detailed user information. - UserGet(ctx context.Context, in *AuthUserGetRequest, opts ...grpc.CallOption) (*AuthUserGetResponse, error) - // UserList gets a list of all users. - UserList(ctx context.Context, in *AuthUserListRequest, opts ...grpc.CallOption) (*AuthUserListResponse, error) - // UserDelete deletes a specified user. - UserDelete(ctx context.Context, in *AuthUserDeleteRequest, opts ...grpc.CallOption) (*AuthUserDeleteResponse, error) - // UserChangePassword changes the password of a specified user. - UserChangePassword(ctx context.Context, in *AuthUserChangePasswordRequest, opts ...grpc.CallOption) (*AuthUserChangePasswordResponse, error) - // UserGrant grants a role to a specified user. - UserGrantRole(ctx context.Context, in *AuthUserGrantRoleRequest, opts ...grpc.CallOption) (*AuthUserGrantRoleResponse, error) - // UserRevokeRole revokes a role of specified user. - UserRevokeRole(ctx context.Context, in *AuthUserRevokeRoleRequest, opts ...grpc.CallOption) (*AuthUserRevokeRoleResponse, error) - // RoleAdd adds a new role. - RoleAdd(ctx context.Context, in *AuthRoleAddRequest, opts ...grpc.CallOption) (*AuthRoleAddResponse, error) - // RoleGet gets detailed role information. - RoleGet(ctx context.Context, in *AuthRoleGetRequest, opts ...grpc.CallOption) (*AuthRoleGetResponse, error) - // RoleList gets lists of all roles. - RoleList(ctx context.Context, in *AuthRoleListRequest, opts ...grpc.CallOption) (*AuthRoleListResponse, error) - // RoleDelete deletes a specified role. - RoleDelete(ctx context.Context, in *AuthRoleDeleteRequest, opts ...grpc.CallOption) (*AuthRoleDeleteResponse, error) - // RoleGrantPermission grants a permission of a specified key or range to a specified role. - RoleGrantPermission(ctx context.Context, in *AuthRoleGrantPermissionRequest, opts ...grpc.CallOption) (*AuthRoleGrantPermissionResponse, error) - // RoleRevokePermission revokes a key or range permission of a specified role. - RoleRevokePermission(ctx context.Context, in *AuthRoleRevokePermissionRequest, opts ...grpc.CallOption) (*AuthRoleRevokePermissionResponse, error) -} - -type authClient struct { - cc *grpc.ClientConn -} - -func NewAuthClient(cc *grpc.ClientConn) AuthClient { - return &authClient{cc} -} - -func (c *authClient) AuthEnable(ctx context.Context, in *AuthEnableRequest, opts ...grpc.CallOption) (*AuthEnableResponse, error) { - out := new(AuthEnableResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/AuthEnable", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) AuthDisable(ctx context.Context, in *AuthDisableRequest, opts ...grpc.CallOption) (*AuthDisableResponse, error) { - out := new(AuthDisableResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/AuthDisable", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) Authenticate(ctx context.Context, in *AuthenticateRequest, opts ...grpc.CallOption) (*AuthenticateResponse, error) { - out := new(AuthenticateResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/Authenticate", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) UserAdd(ctx context.Context, in *AuthUserAddRequest, opts ...grpc.CallOption) (*AuthUserAddResponse, error) { - out := new(AuthUserAddResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/UserAdd", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) UserGet(ctx context.Context, in *AuthUserGetRequest, opts ...grpc.CallOption) (*AuthUserGetResponse, error) { - out := new(AuthUserGetResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/UserGet", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) UserList(ctx context.Context, in *AuthUserListRequest, opts ...grpc.CallOption) (*AuthUserListResponse, error) { - out := new(AuthUserListResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/UserList", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) UserDelete(ctx context.Context, in *AuthUserDeleteRequest, opts ...grpc.CallOption) (*AuthUserDeleteResponse, error) { - out := new(AuthUserDeleteResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/UserDelete", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) UserChangePassword(ctx context.Context, in *AuthUserChangePasswordRequest, opts ...grpc.CallOption) (*AuthUserChangePasswordResponse, error) { - out := new(AuthUserChangePasswordResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/UserChangePassword", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) UserGrantRole(ctx context.Context, in *AuthUserGrantRoleRequest, opts ...grpc.CallOption) (*AuthUserGrantRoleResponse, error) { - out := new(AuthUserGrantRoleResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/UserGrantRole", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) UserRevokeRole(ctx context.Context, in *AuthUserRevokeRoleRequest, opts ...grpc.CallOption) (*AuthUserRevokeRoleResponse, error) { - out := new(AuthUserRevokeRoleResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/UserRevokeRole", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) RoleAdd(ctx context.Context, in *AuthRoleAddRequest, opts ...grpc.CallOption) (*AuthRoleAddResponse, error) { - out := new(AuthRoleAddResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/RoleAdd", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) RoleGet(ctx context.Context, in *AuthRoleGetRequest, opts ...grpc.CallOption) (*AuthRoleGetResponse, error) { - out := new(AuthRoleGetResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/RoleGet", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) RoleList(ctx context.Context, in *AuthRoleListRequest, opts ...grpc.CallOption) (*AuthRoleListResponse, error) { - out := new(AuthRoleListResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/RoleList", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) RoleDelete(ctx context.Context, in *AuthRoleDeleteRequest, opts ...grpc.CallOption) (*AuthRoleDeleteResponse, error) { - out := new(AuthRoleDeleteResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/RoleDelete", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) RoleGrantPermission(ctx context.Context, in *AuthRoleGrantPermissionRequest, opts ...grpc.CallOption) (*AuthRoleGrantPermissionResponse, error) { - out := new(AuthRoleGrantPermissionResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/RoleGrantPermission", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) RoleRevokePermission(ctx context.Context, in *AuthRoleRevokePermissionRequest, opts ...grpc.CallOption) (*AuthRoleRevokePermissionResponse, error) { - out := new(AuthRoleRevokePermissionResponse) - err := grpc.Invoke(ctx, "/etcdserverpb.Auth/RoleRevokePermission", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for Auth service - -type AuthServer interface { - // AuthEnable enables authentication. - AuthEnable(context.Context, *AuthEnableRequest) (*AuthEnableResponse, error) - // AuthDisable disables authentication. - AuthDisable(context.Context, *AuthDisableRequest) (*AuthDisableResponse, error) - // Authenticate processes an authenticate request. - Authenticate(context.Context, *AuthenticateRequest) (*AuthenticateResponse, error) - // UserAdd adds a new user. - UserAdd(context.Context, *AuthUserAddRequest) (*AuthUserAddResponse, error) - // UserGet gets detailed user information. - UserGet(context.Context, *AuthUserGetRequest) (*AuthUserGetResponse, error) - // UserList gets a list of all users. - UserList(context.Context, *AuthUserListRequest) (*AuthUserListResponse, error) - // UserDelete deletes a specified user. - UserDelete(context.Context, *AuthUserDeleteRequest) (*AuthUserDeleteResponse, error) - // UserChangePassword changes the password of a specified user. - UserChangePassword(context.Context, *AuthUserChangePasswordRequest) (*AuthUserChangePasswordResponse, error) - // UserGrant grants a role to a specified user. - UserGrantRole(context.Context, *AuthUserGrantRoleRequest) (*AuthUserGrantRoleResponse, error) - // UserRevokeRole revokes a role of specified user. - UserRevokeRole(context.Context, *AuthUserRevokeRoleRequest) (*AuthUserRevokeRoleResponse, error) - // RoleAdd adds a new role. - RoleAdd(context.Context, *AuthRoleAddRequest) (*AuthRoleAddResponse, error) - // RoleGet gets detailed role information. - RoleGet(context.Context, *AuthRoleGetRequest) (*AuthRoleGetResponse, error) - // RoleList gets lists of all roles. - RoleList(context.Context, *AuthRoleListRequest) (*AuthRoleListResponse, error) - // RoleDelete deletes a specified role. - RoleDelete(context.Context, *AuthRoleDeleteRequest) (*AuthRoleDeleteResponse, error) - // RoleGrantPermission grants a permission of a specified key or range to a specified role. - RoleGrantPermission(context.Context, *AuthRoleGrantPermissionRequest) (*AuthRoleGrantPermissionResponse, error) - // RoleRevokePermission revokes a key or range permission of a specified role. - RoleRevokePermission(context.Context, *AuthRoleRevokePermissionRequest) (*AuthRoleRevokePermissionResponse, error) -} - -func RegisterAuthServer(s *grpc.Server, srv AuthServer) { - s.RegisterService(&_Auth_serviceDesc, srv) -} - -func _Auth_AuthEnable_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthEnableRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).AuthEnable(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/AuthEnable", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).AuthEnable(ctx, req.(*AuthEnableRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_AuthDisable_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthDisableRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).AuthDisable(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/AuthDisable", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).AuthDisable(ctx, req.(*AuthDisableRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_Authenticate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthenticateRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).Authenticate(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/Authenticate", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).Authenticate(ctx, req.(*AuthenticateRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_UserAdd_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthUserAddRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).UserAdd(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/UserAdd", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).UserAdd(ctx, req.(*AuthUserAddRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_UserGet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthUserGetRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).UserGet(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/UserGet", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).UserGet(ctx, req.(*AuthUserGetRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_UserList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthUserListRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).UserList(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/UserList", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).UserList(ctx, req.(*AuthUserListRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_UserDelete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthUserDeleteRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).UserDelete(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/UserDelete", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).UserDelete(ctx, req.(*AuthUserDeleteRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_UserChangePassword_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthUserChangePasswordRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).UserChangePassword(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/UserChangePassword", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).UserChangePassword(ctx, req.(*AuthUserChangePasswordRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_UserGrantRole_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthUserGrantRoleRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).UserGrantRole(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/UserGrantRole", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).UserGrantRole(ctx, req.(*AuthUserGrantRoleRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_UserRevokeRole_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthUserRevokeRoleRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).UserRevokeRole(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/UserRevokeRole", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).UserRevokeRole(ctx, req.(*AuthUserRevokeRoleRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_RoleAdd_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthRoleAddRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).RoleAdd(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/RoleAdd", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).RoleAdd(ctx, req.(*AuthRoleAddRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_RoleGet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthRoleGetRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).RoleGet(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/RoleGet", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).RoleGet(ctx, req.(*AuthRoleGetRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_RoleList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthRoleListRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).RoleList(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/RoleList", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).RoleList(ctx, req.(*AuthRoleListRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_RoleDelete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthRoleDeleteRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).RoleDelete(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/RoleDelete", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).RoleDelete(ctx, req.(*AuthRoleDeleteRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_RoleGrantPermission_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthRoleGrantPermissionRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).RoleGrantPermission(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/RoleGrantPermission", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).RoleGrantPermission(ctx, req.(*AuthRoleGrantPermissionRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_RoleRevokePermission_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AuthRoleRevokePermissionRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).RoleRevokePermission(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/etcdserverpb.Auth/RoleRevokePermission", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).RoleRevokePermission(ctx, req.(*AuthRoleRevokePermissionRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Auth_serviceDesc = grpc.ServiceDesc{ - ServiceName: "etcdserverpb.Auth", - HandlerType: (*AuthServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "AuthEnable", - Handler: _Auth_AuthEnable_Handler, - }, - { - MethodName: "AuthDisable", - Handler: _Auth_AuthDisable_Handler, - }, - { - MethodName: "Authenticate", - Handler: _Auth_Authenticate_Handler, - }, - { - MethodName: "UserAdd", - Handler: _Auth_UserAdd_Handler, - }, - { - MethodName: "UserGet", - Handler: _Auth_UserGet_Handler, - }, - { - MethodName: "UserList", - Handler: _Auth_UserList_Handler, - }, - { - MethodName: "UserDelete", - Handler: _Auth_UserDelete_Handler, - }, - { - MethodName: "UserChangePassword", - Handler: _Auth_UserChangePassword_Handler, - }, - { - MethodName: "UserGrantRole", - Handler: _Auth_UserGrantRole_Handler, - }, - { - MethodName: "UserRevokeRole", - Handler: _Auth_UserRevokeRole_Handler, - }, - { - MethodName: "RoleAdd", - Handler: _Auth_RoleAdd_Handler, - }, - { - MethodName: "RoleGet", - Handler: _Auth_RoleGet_Handler, - }, - { - MethodName: "RoleList", - Handler: _Auth_RoleList_Handler, - }, - { - MethodName: "RoleDelete", - Handler: _Auth_RoleDelete_Handler, - }, - { - MethodName: "RoleGrantPermission", - Handler: _Auth_RoleGrantPermission_Handler, - }, - { - MethodName: "RoleRevokePermission", - Handler: _Auth_RoleRevokePermission_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "rpc.proto", -} - -func (m *ResponseHeader) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ResponseHeader) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ClusterId != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ClusterId)) - } - if m.MemberId != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.MemberId)) - } - if m.Revision != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Revision)) - } - if m.RaftTerm != 0 { - dAtA[i] = 0x20 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.RaftTerm)) - } - return i, nil -} - -func (m *RangeRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *RangeRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Key) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - if len(m.RangeEnd) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.RangeEnd))) - i += copy(dAtA[i:], m.RangeEnd) - } - if m.Limit != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Limit)) - } - if m.Revision != 0 { - dAtA[i] = 0x20 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Revision)) - } - if m.SortOrder != 0 { - dAtA[i] = 0x28 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.SortOrder)) - } - if m.SortTarget != 0 { - dAtA[i] = 0x30 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.SortTarget)) - } - if m.Serializable { - dAtA[i] = 0x38 - i++ - if m.Serializable { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.KeysOnly { - dAtA[i] = 0x40 - i++ - if m.KeysOnly { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.CountOnly { - dAtA[i] = 0x48 - i++ - if m.CountOnly { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.MinModRevision != 0 { - dAtA[i] = 0x50 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.MinModRevision)) - } - if m.MaxModRevision != 0 { - dAtA[i] = 0x58 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.MaxModRevision)) - } - if m.MinCreateRevision != 0 { - dAtA[i] = 0x60 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.MinCreateRevision)) - } - if m.MaxCreateRevision != 0 { - dAtA[i] = 0x68 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.MaxCreateRevision)) - } - return i, nil -} - -func (m *RangeResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *RangeResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n1, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - } - if len(m.Kvs) > 0 { - for _, msg := range m.Kvs { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - if m.More { - dAtA[i] = 0x18 - i++ - if m.More { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.Count != 0 { - dAtA[i] = 0x20 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Count)) - } - return i, nil -} - -func (m *PutRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *PutRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Key) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - if len(m.Value) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Value))) - i += copy(dAtA[i:], m.Value) - } - if m.Lease != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Lease)) - } - if m.PrevKv { - dAtA[i] = 0x20 - i++ - if m.PrevKv { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.IgnoreValue { - dAtA[i] = 0x28 - i++ - if m.IgnoreValue { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.IgnoreLease { - dAtA[i] = 0x30 - i++ - if m.IgnoreLease { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - return i, nil -} - -func (m *PutResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *PutResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n2, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - } - if m.PrevKv != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.PrevKv.Size())) - n3, err := m.PrevKv.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n3 - } - return i, nil -} - -func (m *DeleteRangeRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *DeleteRangeRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Key) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - if len(m.RangeEnd) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.RangeEnd))) - i += copy(dAtA[i:], m.RangeEnd) - } - if m.PrevKv { - dAtA[i] = 0x18 - i++ - if m.PrevKv { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - return i, nil -} - -func (m *DeleteRangeResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *DeleteRangeResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n4, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n4 - } - if m.Deleted != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Deleted)) - } - if len(m.PrevKvs) > 0 { - for _, msg := range m.PrevKvs { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *RequestOp) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *RequestOp) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Request != nil { - nn5, err := m.Request.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += nn5 - } - return i, nil -} - -func (m *RequestOp_RequestRange) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.RequestRange != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.RequestRange.Size())) - n6, err := m.RequestRange.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n6 - } - return i, nil -} -func (m *RequestOp_RequestPut) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.RequestPut != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.RequestPut.Size())) - n7, err := m.RequestPut.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n7 - } - return i, nil -} -func (m *RequestOp_RequestDeleteRange) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.RequestDeleteRange != nil { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.RequestDeleteRange.Size())) - n8, err := m.RequestDeleteRange.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n8 - } - return i, nil -} -func (m *RequestOp_RequestTxn) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.RequestTxn != nil { - dAtA[i] = 0x22 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.RequestTxn.Size())) - n9, err := m.RequestTxn.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n9 - } - return i, nil -} -func (m *ResponseOp) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ResponseOp) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Response != nil { - nn10, err := m.Response.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += nn10 - } - return i, nil -} - -func (m *ResponseOp_ResponseRange) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.ResponseRange != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ResponseRange.Size())) - n11, err := m.ResponseRange.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n11 - } - return i, nil -} -func (m *ResponseOp_ResponsePut) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.ResponsePut != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ResponsePut.Size())) - n12, err := m.ResponsePut.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n12 - } - return i, nil -} -func (m *ResponseOp_ResponseDeleteRange) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.ResponseDeleteRange != nil { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ResponseDeleteRange.Size())) - n13, err := m.ResponseDeleteRange.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n13 - } - return i, nil -} -func (m *ResponseOp_ResponseTxn) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.ResponseTxn != nil { - dAtA[i] = 0x22 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ResponseTxn.Size())) - n14, err := m.ResponseTxn.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n14 - } - return i, nil -} -func (m *Compare) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Compare) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Result != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Result)) - } - if m.Target != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Target)) - } - if len(m.Key) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - if m.TargetUnion != nil { - nn15, err := m.TargetUnion.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += nn15 - } - if len(m.RangeEnd) > 0 { - dAtA[i] = 0x82 - i++ - dAtA[i] = 0x4 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.RangeEnd))) - i += copy(dAtA[i:], m.RangeEnd) - } - return i, nil -} - -func (m *Compare_Version) MarshalTo(dAtA []byte) (int, error) { - i := 0 - dAtA[i] = 0x20 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Version)) - return i, nil -} -func (m *Compare_CreateRevision) MarshalTo(dAtA []byte) (int, error) { - i := 0 - dAtA[i] = 0x28 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.CreateRevision)) - return i, nil -} -func (m *Compare_ModRevision) MarshalTo(dAtA []byte) (int, error) { - i := 0 - dAtA[i] = 0x30 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ModRevision)) - return i, nil -} -func (m *Compare_Value) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.Value != nil { - dAtA[i] = 0x3a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Value))) - i += copy(dAtA[i:], m.Value) - } - return i, nil -} -func (m *Compare_Lease) MarshalTo(dAtA []byte) (int, error) { - i := 0 - dAtA[i] = 0x40 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Lease)) - return i, nil -} -func (m *TxnRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *TxnRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Compare) > 0 { - for _, msg := range m.Compare { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - if len(m.Success) > 0 { - for _, msg := range m.Success { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - if len(m.Failure) > 0 { - for _, msg := range m.Failure { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *TxnResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *TxnResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n16, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n16 - } - if m.Succeeded { - dAtA[i] = 0x10 - i++ - if m.Succeeded { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if len(m.Responses) > 0 { - for _, msg := range m.Responses { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *CompactionRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *CompactionRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Revision != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Revision)) - } - if m.Physical { - dAtA[i] = 0x10 - i++ - if m.Physical { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - return i, nil -} - -func (m *CompactionResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *CompactionResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n17, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n17 - } - return i, nil -} - -func (m *HashRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *HashRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *HashKVRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *HashKVRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Revision != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Revision)) - } - return i, nil -} - -func (m *HashKVResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *HashKVResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n18, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n18 - } - if m.Hash != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Hash)) - } - if m.CompactRevision != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.CompactRevision)) - } - return i, nil -} - -func (m *HashResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *HashResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n19, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n19 - } - if m.Hash != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Hash)) - } - return i, nil -} - -func (m *SnapshotRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SnapshotRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *SnapshotResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SnapshotResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n20, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n20 - } - if m.RemainingBytes != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.RemainingBytes)) - } - if len(m.Blob) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Blob))) - i += copy(dAtA[i:], m.Blob) - } - return i, nil -} - -func (m *WatchRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *WatchRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.RequestUnion != nil { - nn21, err := m.RequestUnion.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += nn21 - } - return i, nil -} - -func (m *WatchRequest_CreateRequest) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.CreateRequest != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.CreateRequest.Size())) - n22, err := m.CreateRequest.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n22 - } - return i, nil -} -func (m *WatchRequest_CancelRequest) MarshalTo(dAtA []byte) (int, error) { - i := 0 - if m.CancelRequest != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.CancelRequest.Size())) - n23, err := m.CancelRequest.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n23 - } - return i, nil -} -func (m *WatchCreateRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *WatchCreateRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Key) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - if len(m.RangeEnd) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.RangeEnd))) - i += copy(dAtA[i:], m.RangeEnd) - } - if m.StartRevision != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.StartRevision)) - } - if m.ProgressNotify { - dAtA[i] = 0x20 - i++ - if m.ProgressNotify { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if len(m.Filters) > 0 { - dAtA25 := make([]byte, len(m.Filters)*10) - var j24 int - for _, num := range m.Filters { - for num >= 1<<7 { - dAtA25[j24] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j24++ - } - dAtA25[j24] = uint8(num) - j24++ - } - dAtA[i] = 0x2a - i++ - i = encodeVarintRpc(dAtA, i, uint64(j24)) - i += copy(dAtA[i:], dAtA25[:j24]) - } - if m.PrevKv { - dAtA[i] = 0x30 - i++ - if m.PrevKv { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - return i, nil -} - -func (m *WatchCancelRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *WatchCancelRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.WatchId != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.WatchId)) - } - return i, nil -} - -func (m *WatchResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *WatchResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n26, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n26 - } - if m.WatchId != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.WatchId)) - } - if m.Created { - dAtA[i] = 0x18 - i++ - if m.Created { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.Canceled { - dAtA[i] = 0x20 - i++ - if m.Canceled { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.CompactRevision != 0 { - dAtA[i] = 0x28 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.CompactRevision)) - } - if len(m.CancelReason) > 0 { - dAtA[i] = 0x32 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.CancelReason))) - i += copy(dAtA[i:], m.CancelReason) - } - if len(m.Events) > 0 { - for _, msg := range m.Events { - dAtA[i] = 0x5a - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *LeaseGrantRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseGrantRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.TTL != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.TTL)) - } - if m.ID != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - return i, nil -} - -func (m *LeaseGrantResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseGrantResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n27, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n27 - } - if m.ID != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - if m.TTL != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.TTL)) - } - if len(m.Error) > 0 { - dAtA[i] = 0x22 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Error))) - i += copy(dAtA[i:], m.Error) - } - return i, nil -} - -func (m *LeaseRevokeRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseRevokeRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - return i, nil -} - -func (m *LeaseRevokeResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseRevokeResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n28, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n28 - } - return i, nil -} - -func (m *LeaseKeepAliveRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseKeepAliveRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - return i, nil -} - -func (m *LeaseKeepAliveResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseKeepAliveResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n29, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n29 - } - if m.ID != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - if m.TTL != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.TTL)) - } - return i, nil -} - -func (m *LeaseTimeToLiveRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseTimeToLiveRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - if m.Keys { - dAtA[i] = 0x10 - i++ - if m.Keys { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - return i, nil -} - -func (m *LeaseTimeToLiveResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseTimeToLiveResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n30, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n30 - } - if m.ID != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - if m.TTL != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.TTL)) - } - if m.GrantedTTL != 0 { - dAtA[i] = 0x20 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.GrantedTTL)) - } - if len(m.Keys) > 0 { - for _, b := range m.Keys { - dAtA[i] = 0x2a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(b))) - i += copy(dAtA[i:], b) - } - } - return i, nil -} - -func (m *LeaseLeasesRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseLeasesRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *LeaseStatus) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseStatus) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - return i, nil -} - -func (m *LeaseLeasesResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseLeasesResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n31, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n31 - } - if len(m.Leases) > 0 { - for _, msg := range m.Leases { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *Member) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Member) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - if len(m.Name) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.PeerURLs) > 0 { - for _, s := range m.PeerURLs { - dAtA[i] = 0x1a - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if len(m.ClientURLs) > 0 { - for _, s := range m.ClientURLs { - dAtA[i] = 0x22 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - return i, nil -} - -func (m *MemberAddRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MemberAddRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.PeerURLs) > 0 { - for _, s := range m.PeerURLs { - dAtA[i] = 0xa - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - return i, nil -} - -func (m *MemberAddResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MemberAddResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n32, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n32 - } - if m.Member != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Member.Size())) - n33, err := m.Member.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n33 - } - if len(m.Members) > 0 { - for _, msg := range m.Members { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *MemberRemoveRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MemberRemoveRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - return i, nil -} - -func (m *MemberRemoveResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MemberRemoveResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n34, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n34 - } - if len(m.Members) > 0 { - for _, msg := range m.Members { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *MemberUpdateRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MemberUpdateRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ID)) - } - if len(m.PeerURLs) > 0 { - for _, s := range m.PeerURLs { - dAtA[i] = 0x12 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - return i, nil -} - -func (m *MemberUpdateResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MemberUpdateResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n35, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n35 - } - if len(m.Members) > 0 { - for _, msg := range m.Members { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *MemberListRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MemberListRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *MemberListResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MemberListResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n36, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n36 - } - if len(m.Members) > 0 { - for _, msg := range m.Members { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *DefragmentRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *DefragmentRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *DefragmentResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *DefragmentResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n37, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n37 - } - return i, nil -} - -func (m *MoveLeaderRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MoveLeaderRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.TargetID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.TargetID)) - } - return i, nil -} - -func (m *MoveLeaderResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MoveLeaderResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n38, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n38 - } - return i, nil -} - -func (m *AlarmRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AlarmRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Action != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Action)) - } - if m.MemberID != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.MemberID)) - } - if m.Alarm != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Alarm)) - } - return i, nil -} - -func (m *AlarmMember) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AlarmMember) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.MemberID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.MemberID)) - } - if m.Alarm != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Alarm)) - } - return i, nil -} - -func (m *AlarmResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AlarmResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n39, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n39 - } - if len(m.Alarms) > 0 { - for _, msg := range m.Alarms { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *StatusRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *StatusRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *StatusResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *StatusResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n40, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n40 - } - if len(m.Version) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Version))) - i += copy(dAtA[i:], m.Version) - } - if m.DbSize != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.DbSize)) - } - if m.Leader != 0 { - dAtA[i] = 0x20 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Leader)) - } - if m.RaftIndex != 0 { - dAtA[i] = 0x28 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.RaftIndex)) - } - if m.RaftTerm != 0 { - dAtA[i] = 0x30 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.RaftTerm)) - } - return i, nil -} - -func (m *AuthEnableRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthEnableRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *AuthDisableRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthDisableRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *AuthenticateRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthenticateRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.Password) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Password))) - i += copy(dAtA[i:], m.Password) - } - return i, nil -} - -func (m *AuthUserAddRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserAddRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.Password) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Password))) - i += copy(dAtA[i:], m.Password) - } - return i, nil -} - -func (m *AuthUserGetRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserGetRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - return i, nil -} - -func (m *AuthUserDeleteRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserDeleteRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - return i, nil -} - -func (m *AuthUserChangePasswordRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserChangePasswordRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.Password) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Password))) - i += copy(dAtA[i:], m.Password) - } - return i, nil -} - -func (m *AuthUserGrantRoleRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserGrantRoleRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.User) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.User))) - i += copy(dAtA[i:], m.User) - } - if len(m.Role) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Role))) - i += copy(dAtA[i:], m.Role) - } - return i, nil -} - -func (m *AuthUserRevokeRoleRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserRevokeRoleRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.Role) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Role))) - i += copy(dAtA[i:], m.Role) - } - return i, nil -} - -func (m *AuthRoleAddRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleAddRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - return i, nil -} - -func (m *AuthRoleGetRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleGetRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Role) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Role))) - i += copy(dAtA[i:], m.Role) - } - return i, nil -} - -func (m *AuthUserListRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserListRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *AuthRoleListRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleListRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - return i, nil -} - -func (m *AuthRoleDeleteRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleDeleteRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Role) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Role))) - i += copy(dAtA[i:], m.Role) - } - return i, nil -} - -func (m *AuthRoleGrantPermissionRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleGrantPermissionRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if m.Perm != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Perm.Size())) - n41, err := m.Perm.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n41 - } - return i, nil -} - -func (m *AuthRoleRevokePermissionRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleRevokePermissionRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Role) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Role))) - i += copy(dAtA[i:], m.Role) - } - if len(m.Key) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - if len(m.RangeEnd) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.RangeEnd))) - i += copy(dAtA[i:], m.RangeEnd) - } - return i, nil -} - -func (m *AuthEnableResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthEnableResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n42, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n42 - } - return i, nil -} - -func (m *AuthDisableResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthDisableResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n43, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n43 - } - return i, nil -} - -func (m *AuthenticateResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthenticateResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n44, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n44 - } - if len(m.Token) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Token))) - i += copy(dAtA[i:], m.Token) - } - return i, nil -} - -func (m *AuthUserAddResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserAddResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n45, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n45 - } - return i, nil -} - -func (m *AuthUserGetResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserGetResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n46, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n46 - } - if len(m.Roles) > 0 { - for _, s := range m.Roles { - dAtA[i] = 0x12 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - return i, nil -} - -func (m *AuthUserDeleteResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserDeleteResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n47, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n47 - } - return i, nil -} - -func (m *AuthUserChangePasswordResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserChangePasswordResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n48, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n48 - } - return i, nil -} - -func (m *AuthUserGrantRoleResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserGrantRoleResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n49, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n49 - } - return i, nil -} - -func (m *AuthUserRevokeRoleResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserRevokeRoleResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n50, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n50 - } - return i, nil -} - -func (m *AuthRoleAddResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleAddResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n51, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n51 - } - return i, nil -} - -func (m *AuthRoleGetResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleGetResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n52, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n52 - } - if len(m.Perm) > 0 { - for _, msg := range m.Perm { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - return i, nil -} - -func (m *AuthRoleListResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleListResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n53, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n53 - } - if len(m.Roles) > 0 { - for _, s := range m.Roles { - dAtA[i] = 0x12 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - return i, nil -} - -func (m *AuthUserListResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthUserListResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n54, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n54 - } - if len(m.Users) > 0 { - for _, s := range m.Users { - dAtA[i] = 0x12 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - return i, nil -} - -func (m *AuthRoleDeleteResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleDeleteResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n55, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n55 - } - return i, nil -} - -func (m *AuthRoleGrantPermissionResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleGrantPermissionResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n56, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n56 - } - return i, nil -} - -func (m *AuthRoleRevokePermissionResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AuthRoleRevokePermissionResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Header != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Header.Size())) - n57, err := m.Header.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n57 - } - return i, nil -} - -func encodeVarintRpc(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *ResponseHeader) Size() (n int) { - var l int - _ = l - if m.ClusterId != 0 { - n += 1 + sovRpc(uint64(m.ClusterId)) - } - if m.MemberId != 0 { - n += 1 + sovRpc(uint64(m.MemberId)) - } - if m.Revision != 0 { - n += 1 + sovRpc(uint64(m.Revision)) - } - if m.RaftTerm != 0 { - n += 1 + sovRpc(uint64(m.RaftTerm)) - } - return n -} - -func (m *RangeRequest) Size() (n int) { - var l int - _ = l - l = len(m.Key) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.RangeEnd) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.Limit != 0 { - n += 1 + sovRpc(uint64(m.Limit)) - } - if m.Revision != 0 { - n += 1 + sovRpc(uint64(m.Revision)) - } - if m.SortOrder != 0 { - n += 1 + sovRpc(uint64(m.SortOrder)) - } - if m.SortTarget != 0 { - n += 1 + sovRpc(uint64(m.SortTarget)) - } - if m.Serializable { - n += 2 - } - if m.KeysOnly { - n += 2 - } - if m.CountOnly { - n += 2 - } - if m.MinModRevision != 0 { - n += 1 + sovRpc(uint64(m.MinModRevision)) - } - if m.MaxModRevision != 0 { - n += 1 + sovRpc(uint64(m.MaxModRevision)) - } - if m.MinCreateRevision != 0 { - n += 1 + sovRpc(uint64(m.MinCreateRevision)) - } - if m.MaxCreateRevision != 0 { - n += 1 + sovRpc(uint64(m.MaxCreateRevision)) - } - return n -} - -func (m *RangeResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Kvs) > 0 { - for _, e := range m.Kvs { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - if m.More { - n += 2 - } - if m.Count != 0 { - n += 1 + sovRpc(uint64(m.Count)) - } - return n -} - -func (m *PutRequest) Size() (n int) { - var l int - _ = l - l = len(m.Key) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Value) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.Lease != 0 { - n += 1 + sovRpc(uint64(m.Lease)) - } - if m.PrevKv { - n += 2 - } - if m.IgnoreValue { - n += 2 - } - if m.IgnoreLease { - n += 2 - } - return n -} - -func (m *PutResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.PrevKv != nil { - l = m.PrevKv.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *DeleteRangeRequest) Size() (n int) { - var l int - _ = l - l = len(m.Key) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.RangeEnd) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.PrevKv { - n += 2 - } - return n -} - -func (m *DeleteRangeResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.Deleted != 0 { - n += 1 + sovRpc(uint64(m.Deleted)) - } - if len(m.PrevKvs) > 0 { - for _, e := range m.PrevKvs { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *RequestOp) Size() (n int) { - var l int - _ = l - if m.Request != nil { - n += m.Request.Size() - } - return n -} - -func (m *RequestOp_RequestRange) Size() (n int) { - var l int - _ = l - if m.RequestRange != nil { - l = m.RequestRange.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *RequestOp_RequestPut) Size() (n int) { - var l int - _ = l - if m.RequestPut != nil { - l = m.RequestPut.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *RequestOp_RequestDeleteRange) Size() (n int) { - var l int - _ = l - if m.RequestDeleteRange != nil { - l = m.RequestDeleteRange.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *RequestOp_RequestTxn) Size() (n int) { - var l int - _ = l - if m.RequestTxn != nil { - l = m.RequestTxn.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *ResponseOp) Size() (n int) { - var l int - _ = l - if m.Response != nil { - n += m.Response.Size() - } - return n -} - -func (m *ResponseOp_ResponseRange) Size() (n int) { - var l int - _ = l - if m.ResponseRange != nil { - l = m.ResponseRange.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *ResponseOp_ResponsePut) Size() (n int) { - var l int - _ = l - if m.ResponsePut != nil { - l = m.ResponsePut.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *ResponseOp_ResponseDeleteRange) Size() (n int) { - var l int - _ = l - if m.ResponseDeleteRange != nil { - l = m.ResponseDeleteRange.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *ResponseOp_ResponseTxn) Size() (n int) { - var l int - _ = l - if m.ResponseTxn != nil { - l = m.ResponseTxn.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *Compare) Size() (n int) { - var l int - _ = l - if m.Result != 0 { - n += 1 + sovRpc(uint64(m.Result)) - } - if m.Target != 0 { - n += 1 + sovRpc(uint64(m.Target)) - } - l = len(m.Key) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.TargetUnion != nil { - n += m.TargetUnion.Size() - } - l = len(m.RangeEnd) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *Compare_Version) Size() (n int) { - var l int - _ = l - n += 1 + sovRpc(uint64(m.Version)) - return n -} -func (m *Compare_CreateRevision) Size() (n int) { - var l int - _ = l - n += 1 + sovRpc(uint64(m.CreateRevision)) - return n -} -func (m *Compare_ModRevision) Size() (n int) { - var l int - _ = l - n += 1 + sovRpc(uint64(m.ModRevision)) - return n -} -func (m *Compare_Value) Size() (n int) { - var l int - _ = l - if m.Value != nil { - l = len(m.Value) - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *Compare_Lease) Size() (n int) { - var l int - _ = l - n += 1 + sovRpc(uint64(m.Lease)) - return n -} -func (m *TxnRequest) Size() (n int) { - var l int - _ = l - if len(m.Compare) > 0 { - for _, e := range m.Compare { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - if len(m.Success) > 0 { - for _, e := range m.Success { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - if len(m.Failure) > 0 { - for _, e := range m.Failure { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *TxnResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.Succeeded { - n += 2 - } - if len(m.Responses) > 0 { - for _, e := range m.Responses { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *CompactionRequest) Size() (n int) { - var l int - _ = l - if m.Revision != 0 { - n += 1 + sovRpc(uint64(m.Revision)) - } - if m.Physical { - n += 2 - } - return n -} - -func (m *CompactionResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *HashRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *HashKVRequest) Size() (n int) { - var l int - _ = l - if m.Revision != 0 { - n += 1 + sovRpc(uint64(m.Revision)) - } - return n -} - -func (m *HashKVResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.Hash != 0 { - n += 1 + sovRpc(uint64(m.Hash)) - } - if m.CompactRevision != 0 { - n += 1 + sovRpc(uint64(m.CompactRevision)) - } - return n -} - -func (m *HashResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.Hash != 0 { - n += 1 + sovRpc(uint64(m.Hash)) - } - return n -} - -func (m *SnapshotRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *SnapshotResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.RemainingBytes != 0 { - n += 1 + sovRpc(uint64(m.RemainingBytes)) - } - l = len(m.Blob) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *WatchRequest) Size() (n int) { - var l int - _ = l - if m.RequestUnion != nil { - n += m.RequestUnion.Size() - } - return n -} - -func (m *WatchRequest_CreateRequest) Size() (n int) { - var l int - _ = l - if m.CreateRequest != nil { - l = m.CreateRequest.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *WatchRequest_CancelRequest) Size() (n int) { - var l int - _ = l - if m.CancelRequest != nil { - l = m.CancelRequest.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} -func (m *WatchCreateRequest) Size() (n int) { - var l int - _ = l - l = len(m.Key) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.RangeEnd) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.StartRevision != 0 { - n += 1 + sovRpc(uint64(m.StartRevision)) - } - if m.ProgressNotify { - n += 2 - } - if len(m.Filters) > 0 { - l = 0 - for _, e := range m.Filters { - l += sovRpc(uint64(e)) - } - n += 1 + sovRpc(uint64(l)) + l - } - if m.PrevKv { - n += 2 - } - return n -} - -func (m *WatchCancelRequest) Size() (n int) { - var l int - _ = l - if m.WatchId != 0 { - n += 1 + sovRpc(uint64(m.WatchId)) - } - return n -} - -func (m *WatchResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.WatchId != 0 { - n += 1 + sovRpc(uint64(m.WatchId)) - } - if m.Created { - n += 2 - } - if m.Canceled { - n += 2 - } - if m.CompactRevision != 0 { - n += 1 + sovRpc(uint64(m.CompactRevision)) - } - l = len(m.CancelReason) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Events) > 0 { - for _, e := range m.Events { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *LeaseGrantRequest) Size() (n int) { - var l int - _ = l - if m.TTL != 0 { - n += 1 + sovRpc(uint64(m.TTL)) - } - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - return n -} - -func (m *LeaseGrantResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - if m.TTL != 0 { - n += 1 + sovRpc(uint64(m.TTL)) - } - l = len(m.Error) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *LeaseRevokeRequest) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - return n -} - -func (m *LeaseRevokeResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *LeaseKeepAliveRequest) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - return n -} - -func (m *LeaseKeepAliveResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - if m.TTL != 0 { - n += 1 + sovRpc(uint64(m.TTL)) - } - return n -} - -func (m *LeaseTimeToLiveRequest) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - if m.Keys { - n += 2 - } - return n -} - -func (m *LeaseTimeToLiveResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - if m.TTL != 0 { - n += 1 + sovRpc(uint64(m.TTL)) - } - if m.GrantedTTL != 0 { - n += 1 + sovRpc(uint64(m.GrantedTTL)) - } - if len(m.Keys) > 0 { - for _, b := range m.Keys { - l = len(b) - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *LeaseLeasesRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *LeaseStatus) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - return n -} - -func (m *LeaseLeasesResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Leases) > 0 { - for _, e := range m.Leases { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *Member) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.PeerURLs) > 0 { - for _, s := range m.PeerURLs { - l = len(s) - n += 1 + l + sovRpc(uint64(l)) - } - } - if len(m.ClientURLs) > 0 { - for _, s := range m.ClientURLs { - l = len(s) - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *MemberAddRequest) Size() (n int) { - var l int - _ = l - if len(m.PeerURLs) > 0 { - for _, s := range m.PeerURLs { - l = len(s) - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *MemberAddResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.Member != nil { - l = m.Member.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Members) > 0 { - for _, e := range m.Members { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *MemberRemoveRequest) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - return n -} - -func (m *MemberRemoveResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Members) > 0 { - for _, e := range m.Members { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *MemberUpdateRequest) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovRpc(uint64(m.ID)) - } - if len(m.PeerURLs) > 0 { - for _, s := range m.PeerURLs { - l = len(s) - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *MemberUpdateResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Members) > 0 { - for _, e := range m.Members { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *MemberListRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *MemberListResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Members) > 0 { - for _, e := range m.Members { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *DefragmentRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *DefragmentResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *MoveLeaderRequest) Size() (n int) { - var l int - _ = l - if m.TargetID != 0 { - n += 1 + sovRpc(uint64(m.TargetID)) - } - return n -} - -func (m *MoveLeaderResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AlarmRequest) Size() (n int) { - var l int - _ = l - if m.Action != 0 { - n += 1 + sovRpc(uint64(m.Action)) - } - if m.MemberID != 0 { - n += 1 + sovRpc(uint64(m.MemberID)) - } - if m.Alarm != 0 { - n += 1 + sovRpc(uint64(m.Alarm)) - } - return n -} - -func (m *AlarmMember) Size() (n int) { - var l int - _ = l - if m.MemberID != 0 { - n += 1 + sovRpc(uint64(m.MemberID)) - } - if m.Alarm != 0 { - n += 1 + sovRpc(uint64(m.Alarm)) - } - return n -} - -func (m *AlarmResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Alarms) > 0 { - for _, e := range m.Alarms { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *StatusRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *StatusResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Version) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.DbSize != 0 { - n += 1 + sovRpc(uint64(m.DbSize)) - } - if m.Leader != 0 { - n += 1 + sovRpc(uint64(m.Leader)) - } - if m.RaftIndex != 0 { - n += 1 + sovRpc(uint64(m.RaftIndex)) - } - if m.RaftTerm != 0 { - n += 1 + sovRpc(uint64(m.RaftTerm)) - } - return n -} - -func (m *AuthEnableRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *AuthDisableRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *AuthenticateRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Password) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserAddRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Password) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserGetRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserDeleteRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserChangePasswordRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Password) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserGrantRoleRequest) Size() (n int) { - var l int - _ = l - l = len(m.User) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Role) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserRevokeRoleRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Role) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthRoleAddRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthRoleGetRequest) Size() (n int) { - var l int - _ = l - l = len(m.Role) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserListRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *AuthRoleListRequest) Size() (n int) { - var l int - _ = l - return n -} - -func (m *AuthRoleDeleteRequest) Size() (n int) { - var l int - _ = l - l = len(m.Role) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthRoleGrantPermissionRequest) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.Perm != nil { - l = m.Perm.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthRoleRevokePermissionRequest) Size() (n int) { - var l int - _ = l - l = len(m.Role) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Key) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.RangeEnd) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthEnableResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthDisableResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthenticateResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Token) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserAddResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserGetResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Roles) > 0 { - for _, s := range m.Roles { - l = len(s) - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *AuthUserDeleteResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserChangePasswordResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserGrantRoleResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthUserRevokeRoleResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthRoleAddResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthRoleGetResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Perm) > 0 { - for _, e := range m.Perm { - l = e.Size() - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *AuthRoleListResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Roles) > 0 { - for _, s := range m.Roles { - l = len(s) - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *AuthUserListResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.Users) > 0 { - for _, s := range m.Users { - l = len(s) - n += 1 + l + sovRpc(uint64(l)) - } - } - return n -} - -func (m *AuthRoleDeleteResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthRoleGrantPermissionResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *AuthRoleRevokePermissionResponse) Size() (n int) { - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func sovRpc(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozRpc(x uint64) (n int) { - return sovRpc(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *ResponseHeader) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ResponseHeader: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ResponseHeader: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClusterId", wireType) - } - m.ClusterId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ClusterId |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MemberId", wireType) - } - m.MemberId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MemberId |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Revision", wireType) - } - m.Revision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Revision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RaftTerm", wireType) - } - m.RaftTerm = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RaftTerm |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *RangeRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: RangeRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: RangeRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RangeEnd", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RangeEnd = append(m.RangeEnd[:0], dAtA[iNdEx:postIndex]...) - if m.RangeEnd == nil { - m.RangeEnd = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Limit", wireType) - } - m.Limit = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Limit |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Revision", wireType) - } - m.Revision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Revision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SortOrder", wireType) - } - m.SortOrder = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.SortOrder |= (RangeRequest_SortOrder(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SortTarget", wireType) - } - m.SortTarget = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.SortTarget |= (RangeRequest_SortTarget(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 7: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Serializable", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Serializable = bool(v != 0) - case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field KeysOnly", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.KeysOnly = bool(v != 0) - case 9: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CountOnly", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.CountOnly = bool(v != 0) - case 10: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MinModRevision", wireType) - } - m.MinModRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MinModRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 11: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MaxModRevision", wireType) - } - m.MaxModRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MaxModRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 12: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MinCreateRevision", wireType) - } - m.MinCreateRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MinCreateRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 13: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MaxCreateRevision", wireType) - } - m.MaxCreateRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MaxCreateRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *RangeResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: RangeResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: RangeResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Kvs", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Kvs = append(m.Kvs, &mvccpb.KeyValue{}) - if err := m.Kvs[len(m.Kvs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field More", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.More = bool(v != 0) - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Count", wireType) - } - m.Count = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Count |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *PutRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: PutRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: PutRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...) - if m.Value == nil { - m.Value = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Lease", wireType) - } - m.Lease = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Lease |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PrevKv", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.PrevKv = bool(v != 0) - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field IgnoreValue", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.IgnoreValue = bool(v != 0) - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field IgnoreLease", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.IgnoreLease = bool(v != 0) - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *PutResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: PutResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: PutResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PrevKv", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.PrevKv == nil { - m.PrevKv = &mvccpb.KeyValue{} - } - if err := m.PrevKv.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *DeleteRangeRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: DeleteRangeRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: DeleteRangeRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RangeEnd", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RangeEnd = append(m.RangeEnd[:0], dAtA[iNdEx:postIndex]...) - if m.RangeEnd == nil { - m.RangeEnd = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PrevKv", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.PrevKv = bool(v != 0) - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *DeleteRangeResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: DeleteRangeResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: DeleteRangeResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Deleted", wireType) - } - m.Deleted = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Deleted |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PrevKvs", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PrevKvs = append(m.PrevKvs, &mvccpb.KeyValue{}) - if err := m.PrevKvs[len(m.PrevKvs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *RequestOp) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: RequestOp: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: RequestOp: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RequestRange", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &RangeRequest{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Request = &RequestOp_RequestRange{v} - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RequestPut", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &PutRequest{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Request = &RequestOp_RequestPut{v} - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RequestDeleteRange", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &DeleteRangeRequest{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Request = &RequestOp_RequestDeleteRange{v} - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RequestTxn", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &TxnRequest{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Request = &RequestOp_RequestTxn{v} - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ResponseOp) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ResponseOp: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ResponseOp: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ResponseRange", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &RangeResponse{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Response = &ResponseOp_ResponseRange{v} - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ResponsePut", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &PutResponse{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Response = &ResponseOp_ResponsePut{v} - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ResponseDeleteRange", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &DeleteRangeResponse{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Response = &ResponseOp_ResponseDeleteRange{v} - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ResponseTxn", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &TxnResponse{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Response = &ResponseOp_ResponseTxn{v} - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Compare) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Compare: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Compare: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Result", wireType) - } - m.Result = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Result |= (Compare_CompareResult(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Target", wireType) - } - m.Target = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Target |= (Compare_CompareTarget(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) - } - var v int64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.TargetUnion = &Compare_Version{v} - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CreateRevision", wireType) - } - var v int64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.TargetUnion = &Compare_CreateRevision{v} - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ModRevision", wireType) - } - var v int64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.TargetUnion = &Compare_ModRevision{v} - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := make([]byte, postIndex-iNdEx) - copy(v, dAtA[iNdEx:postIndex]) - m.TargetUnion = &Compare_Value{v} - iNdEx = postIndex - case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Lease", wireType) - } - var v int64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.TargetUnion = &Compare_Lease{v} - case 64: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RangeEnd", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RangeEnd = append(m.RangeEnd[:0], dAtA[iNdEx:postIndex]...) - if m.RangeEnd == nil { - m.RangeEnd = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *TxnRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: TxnRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: TxnRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Compare", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Compare = append(m.Compare, &Compare{}) - if err := m.Compare[len(m.Compare)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Success", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Success = append(m.Success, &RequestOp{}) - if err := m.Success[len(m.Success)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Failure", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Failure = append(m.Failure, &RequestOp{}) - if err := m.Failure[len(m.Failure)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *TxnResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: TxnResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: TxnResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Succeeded", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Succeeded = bool(v != 0) - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Responses", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Responses = append(m.Responses, &ResponseOp{}) - if err := m.Responses[len(m.Responses)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *CompactionRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: CompactionRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: CompactionRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Revision", wireType) - } - m.Revision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Revision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Physical", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Physical = bool(v != 0) - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *CompactionResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: CompactionResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: CompactionResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *HashRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: HashRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HashRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *HashKVRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: HashKVRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HashKVRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Revision", wireType) - } - m.Revision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Revision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *HashKVResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: HashKVResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HashKVResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType) - } - m.Hash = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Hash |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CompactRevision", wireType) - } - m.CompactRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.CompactRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *HashResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: HashResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HashResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType) - } - m.Hash = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Hash |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *SnapshotRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SnapshotRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SnapshotRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *SnapshotResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SnapshotResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SnapshotResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RemainingBytes", wireType) - } - m.RemainingBytes = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RemainingBytes |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Blob", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Blob = append(m.Blob[:0], dAtA[iNdEx:postIndex]...) - if m.Blob == nil { - m.Blob = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *WatchRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: WatchRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: WatchRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CreateRequest", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &WatchCreateRequest{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.RequestUnion = &WatchRequest_CreateRequest{v} - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CancelRequest", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &WatchCancelRequest{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.RequestUnion = &WatchRequest_CancelRequest{v} - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *WatchCreateRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: WatchCreateRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: WatchCreateRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RangeEnd", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RangeEnd = append(m.RangeEnd[:0], dAtA[iNdEx:postIndex]...) - if m.RangeEnd == nil { - m.RangeEnd = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StartRevision", wireType) - } - m.StartRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StartRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ProgressNotify", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.ProgressNotify = bool(v != 0) - case 5: - if wireType == 0 { - var v WatchCreateRequest_FilterType - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (WatchCreateRequest_FilterType(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Filters = append(m.Filters, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + packedLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - for iNdEx < postIndex { - var v WatchCreateRequest_FilterType - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (WatchCreateRequest_FilterType(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Filters = append(m.Filters, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field Filters", wireType) - } - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PrevKv", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.PrevKv = bool(v != 0) - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *WatchCancelRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: WatchCancelRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: WatchCancelRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field WatchId", wireType) - } - m.WatchId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.WatchId |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *WatchResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: WatchResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: WatchResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field WatchId", wireType) - } - m.WatchId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.WatchId |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Created", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Created = bool(v != 0) - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Canceled", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Canceled = bool(v != 0) - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CompactRevision", wireType) - } - m.CompactRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.CompactRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CancelReason", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.CancelReason = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 11: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Events", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Events = append(m.Events, &mvccpb.Event{}) - if err := m.Events[len(m.Events)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseGrantRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseGrantRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseGrantRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TTL", wireType) - } - m.TTL = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TTL |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseGrantResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseGrantResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseGrantResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TTL", wireType) - } - m.TTL = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TTL |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Error", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Error = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseRevokeRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseRevokeRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseRevokeRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseRevokeResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseRevokeResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseRevokeResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseKeepAliveRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseKeepAliveRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseKeepAliveRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseKeepAliveResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseKeepAliveResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseKeepAliveResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TTL", wireType) - } - m.TTL = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TTL |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseTimeToLiveRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseTimeToLiveRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseTimeToLiveRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Keys", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Keys = bool(v != 0) - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseTimeToLiveResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseTimeToLiveResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseTimeToLiveResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TTL", wireType) - } - m.TTL = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TTL |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field GrantedTTL", wireType) - } - m.GrantedTTL = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.GrantedTTL |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Keys", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Keys = append(m.Keys, make([]byte, postIndex-iNdEx)) - copy(m.Keys[len(m.Keys)-1], dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseLeasesRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseLeasesRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseLeasesRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseStatus) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseStatus: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseStatus: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseLeasesResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseLeasesResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseLeasesResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Leases", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Leases = append(m.Leases, &LeaseStatus{}) - if err := m.Leases[len(m.Leases)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Member) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Member: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Member: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerURLs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerURLs = append(m.PeerURLs, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientURLs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientURLs = append(m.ClientURLs, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MemberAddRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MemberAddRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MemberAddRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerURLs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerURLs = append(m.PeerURLs, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MemberAddResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MemberAddResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MemberAddResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Member", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Member == nil { - m.Member = &Member{} - } - if err := m.Member.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Members", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Members = append(m.Members, &Member{}) - if err := m.Members[len(m.Members)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MemberRemoveRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MemberRemoveRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MemberRemoveRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MemberRemoveResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MemberRemoveResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MemberRemoveResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Members", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Members = append(m.Members, &Member{}) - if err := m.Members[len(m.Members)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MemberUpdateRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MemberUpdateRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MemberUpdateRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerURLs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerURLs = append(m.PeerURLs, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MemberUpdateResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MemberUpdateResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MemberUpdateResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Members", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Members = append(m.Members, &Member{}) - if err := m.Members[len(m.Members)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MemberListRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MemberListRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MemberListRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MemberListResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MemberListResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MemberListResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Members", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Members = append(m.Members, &Member{}) - if err := m.Members[len(m.Members)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *DefragmentRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: DefragmentRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: DefragmentRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *DefragmentResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: DefragmentResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: DefragmentResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MoveLeaderRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MoveLeaderRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MoveLeaderRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TargetID", wireType) - } - m.TargetID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TargetID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MoveLeaderResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MoveLeaderResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MoveLeaderResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AlarmRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AlarmRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AlarmRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Action", wireType) - } - m.Action = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Action |= (AlarmRequest_AlarmAction(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MemberID", wireType) - } - m.MemberID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MemberID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Alarm", wireType) - } - m.Alarm = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Alarm |= (AlarmType(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AlarmMember) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AlarmMember: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AlarmMember: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MemberID", wireType) - } - m.MemberID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MemberID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Alarm", wireType) - } - m.Alarm = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Alarm |= (AlarmType(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AlarmResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AlarmResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AlarmResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Alarms", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Alarms = append(m.Alarms, &AlarmMember{}) - if err := m.Alarms[len(m.Alarms)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *StatusRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: StatusRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: StatusRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *StatusResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: StatusResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: StatusResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Version = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field DbSize", wireType) - } - m.DbSize = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.DbSize |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Leader", wireType) - } - m.Leader = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Leader |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RaftIndex", wireType) - } - m.RaftIndex = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RaftIndex |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RaftTerm", wireType) - } - m.RaftTerm = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RaftTerm |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthEnableRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthEnableRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthEnableRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthDisableRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthDisableRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthDisableRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthenticateRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthenticateRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthenticateRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Password", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Password = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserAddRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserAddRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserAddRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Password", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Password = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserGetRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserGetRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserGetRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserDeleteRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserDeleteRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserDeleteRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserChangePasswordRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserChangePasswordRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserChangePasswordRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Password", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Password = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserGrantRoleRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserGrantRoleRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserGrantRoleRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field User", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.User = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Role", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Role = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserRevokeRoleRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserRevokeRoleRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserRevokeRoleRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Role", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Role = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleAddRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleAddRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleAddRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleGetRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleGetRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleGetRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Role", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Role = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserListRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserListRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserListRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleListRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleListRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleListRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleDeleteRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleDeleteRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleDeleteRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Role", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Role = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleGrantPermissionRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleGrantPermissionRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleGrantPermissionRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Perm", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Perm == nil { - m.Perm = &authpb.Permission{} - } - if err := m.Perm.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleRevokePermissionRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleRevokePermissionRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleRevokePermissionRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Role", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Role = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RangeEnd", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RangeEnd = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthEnableResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthEnableResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthEnableResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthDisableResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthDisableResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthDisableResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthenticateResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthenticateResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthenticateResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Token", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Token = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserAddResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserAddResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserAddResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserGetResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserGetResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserGetResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Roles", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Roles = append(m.Roles, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserDeleteResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserDeleteResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserDeleteResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserChangePasswordResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserChangePasswordResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserChangePasswordResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserGrantRoleResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserGrantRoleResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserGrantRoleResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserRevokeRoleResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserRevokeRoleResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserRevokeRoleResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleAddResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleAddResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleAddResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleGetResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleGetResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleGetResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Perm", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Perm = append(m.Perm, &authpb.Permission{}) - if err := m.Perm[len(m.Perm)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleListResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleListResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleListResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Roles", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Roles = append(m.Roles, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthUserListResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthUserListResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthUserListResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Users", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Users = append(m.Users, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleDeleteResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleDeleteResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleDeleteResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleGrantPermissionResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleGrantPermissionResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleGrantPermissionResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthRoleRevokePermissionResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AuthRoleRevokePermissionResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthRoleRevokePermissionResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipRpc(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthRpc - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipRpc(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthRpc = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowRpc = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("rpc.proto", fileDescriptorRpc) } - -var fileDescriptorRpc = []byte{ - // 3669 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x5b, 0x5b, 0x6f, 0x23, 0xc7, - 0x72, 0xd6, 0x90, 0x22, 0x29, 0x16, 0x2f, 0xe2, 0xb6, 0xb4, 0xbb, 0x14, 0x77, 0x57, 0xab, 0xed, - 0xbd, 0x69, 0x2f, 0x16, 0x6d, 0xd9, 0xc9, 0xc3, 0x26, 0x30, 0xac, 0x95, 0xe8, 0x95, 0x2c, 0xad, - 0x24, 0x8f, 0xa8, 0xb5, 0x03, 0x38, 0x11, 0x46, 0x64, 0x4b, 0x62, 0x44, 0xce, 0x30, 0x33, 0x43, - 0xae, 0xb4, 0x31, 0x12, 0xc0, 0x71, 0x82, 0xbc, 0xe4, 0x25, 0x06, 0x82, 0xc4, 0xaf, 0x41, 0x60, - 0xf8, 0x07, 0x04, 0xf9, 0x0b, 0x41, 0x5e, 0x12, 0x20, 0x7f, 0xe0, 0xc0, 0xe7, 0xbc, 0x9c, 0x5f, - 0x70, 0x2e, 0x4f, 0x07, 0x7d, 0x9b, 0xe9, 0xb9, 0x51, 0xb2, 0x69, 0xfb, 0x45, 0x3b, 0x5d, 0x5d, - 0x5d, 0x55, 0x5d, 0xdd, 0x55, 0xd5, 0xfd, 0x35, 0x17, 0xf2, 0x76, 0xbf, 0xb5, 0xd4, 0xb7, 0x2d, - 0xd7, 0x42, 0x45, 0xe2, 0xb6, 0xda, 0x0e, 0xb1, 0x87, 0xc4, 0xee, 0x1f, 0xd6, 0x66, 0x8f, 0xad, - 0x63, 0x8b, 0x75, 0xd4, 0xe9, 0x17, 0xe7, 0xa9, 0xcd, 0x51, 0x9e, 0x7a, 0x6f, 0xd8, 0x6a, 0xb1, - 0x3f, 0xfd, 0xc3, 0xfa, 0xe9, 0x50, 0x74, 0xdd, 0x60, 0x5d, 0xc6, 0xc0, 0x3d, 0x61, 0x7f, 0xfa, - 0x87, 0xec, 0x1f, 0xd1, 0x79, 0xf3, 0xd8, 0xb2, 0x8e, 0xbb, 0xa4, 0x6e, 0xf4, 0x3b, 0x75, 0xc3, - 0x34, 0x2d, 0xd7, 0x70, 0x3b, 0x96, 0xe9, 0xf0, 0x5e, 0xfc, 0xf7, 0x1a, 0x94, 0x75, 0xe2, 0xf4, - 0x2d, 0xd3, 0x21, 0xeb, 0xc4, 0x68, 0x13, 0x1b, 0xdd, 0x02, 0x68, 0x75, 0x07, 0x8e, 0x4b, 0xec, - 0x83, 0x4e, 0xbb, 0xaa, 0x2d, 0x68, 0x8b, 0x93, 0x7a, 0x5e, 0x50, 0x36, 0xda, 0xe8, 0x06, 0xe4, - 0x7b, 0xa4, 0x77, 0xc8, 0x7b, 0x53, 0xac, 0x77, 0x8a, 0x13, 0x36, 0xda, 0xa8, 0x06, 0x53, 0x36, - 0x19, 0x76, 0x9c, 0x8e, 0x65, 0x56, 0xd3, 0x0b, 0xda, 0x62, 0x5a, 0xf7, 0xda, 0x74, 0xa0, 0x6d, - 0x1c, 0xb9, 0x07, 0x2e, 0xb1, 0x7b, 0xd5, 0x49, 0x3e, 0x90, 0x12, 0x9a, 0xc4, 0xee, 0xe1, 0x2f, - 0x33, 0x50, 0xd4, 0x0d, 0xf3, 0x98, 0xe8, 0xe4, 0xaf, 0x06, 0xc4, 0x71, 0x51, 0x05, 0xd2, 0xa7, - 0xe4, 0x9c, 0xa9, 0x2f, 0xea, 0xf4, 0x93, 0x8f, 0x37, 0x8f, 0xc9, 0x01, 0x31, 0xb9, 0xe2, 0x22, - 0x1d, 0x6f, 0x1e, 0x93, 0x86, 0xd9, 0x46, 0xb3, 0x90, 0xe9, 0x76, 0x7a, 0x1d, 0x57, 0x68, 0xe5, - 0x8d, 0x80, 0x39, 0x93, 0x21, 0x73, 0x56, 0x01, 0x1c, 0xcb, 0x76, 0x0f, 0x2c, 0xbb, 0x4d, 0xec, - 0x6a, 0x66, 0x41, 0x5b, 0x2c, 0x2f, 0xdf, 0x5b, 0x52, 0x17, 0x62, 0x49, 0x35, 0x68, 0x69, 0xcf, - 0xb2, 0xdd, 0x1d, 0xca, 0xab, 0xe7, 0x1d, 0xf9, 0x89, 0x3e, 0x84, 0x02, 0x13, 0xe2, 0x1a, 0xf6, - 0x31, 0x71, 0xab, 0x59, 0x26, 0xe5, 0xfe, 0x05, 0x52, 0x9a, 0x8c, 0x59, 0x67, 0xea, 0xf9, 0x37, - 0xc2, 0x50, 0x74, 0x88, 0xdd, 0x31, 0xba, 0x9d, 0x37, 0xc6, 0x61, 0x97, 0x54, 0x73, 0x0b, 0xda, - 0xe2, 0x94, 0x1e, 0xa0, 0xd1, 0xf9, 0x9f, 0x92, 0x73, 0xe7, 0xc0, 0x32, 0xbb, 0xe7, 0xd5, 0x29, - 0xc6, 0x30, 0x45, 0x09, 0x3b, 0x66, 0xf7, 0x9c, 0x2d, 0x9a, 0x35, 0x30, 0x5d, 0xde, 0x9b, 0x67, - 0xbd, 0x79, 0x46, 0x61, 0xdd, 0x8b, 0x50, 0xe9, 0x75, 0xcc, 0x83, 0x9e, 0xd5, 0x3e, 0xf0, 0x1c, - 0x02, 0xcc, 0x21, 0xe5, 0x5e, 0xc7, 0x7c, 0x69, 0xb5, 0x75, 0xe9, 0x16, 0xca, 0x69, 0x9c, 0x05, - 0x39, 0x0b, 0x82, 0xd3, 0x38, 0x53, 0x39, 0x97, 0x60, 0x86, 0xca, 0x6c, 0xd9, 0xc4, 0x70, 0x89, - 0xcf, 0x5c, 0x64, 0xcc, 0x57, 0x7a, 0x1d, 0x73, 0x95, 0xf5, 0x04, 0xf8, 0x8d, 0xb3, 0x08, 0x7f, - 0x49, 0xf0, 0x1b, 0x67, 0x41, 0x7e, 0xbc, 0x04, 0x79, 0xcf, 0xe7, 0x68, 0x0a, 0x26, 0xb7, 0x77, - 0xb6, 0x1b, 0x95, 0x09, 0x04, 0x90, 0x5d, 0xd9, 0x5b, 0x6d, 0x6c, 0xaf, 0x55, 0x34, 0x54, 0x80, - 0xdc, 0x5a, 0x83, 0x37, 0x52, 0xf8, 0x39, 0x80, 0xef, 0x5d, 0x94, 0x83, 0xf4, 0x66, 0xe3, 0xcf, - 0x2a, 0x13, 0x94, 0xe7, 0x55, 0x43, 0xdf, 0xdb, 0xd8, 0xd9, 0xae, 0x68, 0x74, 0xf0, 0xaa, 0xde, - 0x58, 0x69, 0x36, 0x2a, 0x29, 0xca, 0xf1, 0x72, 0x67, 0xad, 0x92, 0x46, 0x79, 0xc8, 0xbc, 0x5a, - 0xd9, 0xda, 0x6f, 0x54, 0x26, 0xf1, 0x57, 0x1a, 0x94, 0xc4, 0x7a, 0xf1, 0x98, 0x40, 0xef, 0x41, - 0xf6, 0x84, 0xc5, 0x05, 0xdb, 0x8a, 0x85, 0xe5, 0x9b, 0xa1, 0xc5, 0x0d, 0xc4, 0x8e, 0x2e, 0x78, - 0x11, 0x86, 0xf4, 0xe9, 0xd0, 0xa9, 0xa6, 0x16, 0xd2, 0x8b, 0x85, 0xe5, 0xca, 0x12, 0x0f, 0xd8, - 0xa5, 0x4d, 0x72, 0xfe, 0xca, 0xe8, 0x0e, 0x88, 0x4e, 0x3b, 0x11, 0x82, 0xc9, 0x9e, 0x65, 0x13, - 0xb6, 0x63, 0xa7, 0x74, 0xf6, 0x4d, 0xb7, 0x31, 0x5b, 0x34, 0xb1, 0x5b, 0x79, 0x03, 0x7f, 0xab, - 0x01, 0xec, 0x0e, 0xdc, 0xe4, 0xd0, 0x98, 0x85, 0xcc, 0x90, 0x0a, 0x16, 0x61, 0xc1, 0x1b, 0x2c, - 0x26, 0x88, 0xe1, 0x10, 0x2f, 0x26, 0x68, 0x03, 0x5d, 0x87, 0x5c, 0xdf, 0x26, 0xc3, 0x83, 0xd3, - 0x21, 0x53, 0x32, 0xa5, 0x67, 0x69, 0x73, 0x73, 0x88, 0xee, 0x40, 0xb1, 0x73, 0x6c, 0x5a, 0x36, - 0x39, 0xe0, 0xb2, 0x32, 0xac, 0xb7, 0xc0, 0x69, 0xcc, 0x6e, 0x85, 0x85, 0x0b, 0xce, 0xaa, 0x2c, - 0x5b, 0x94, 0x84, 0x4d, 0x28, 0x30, 0x53, 0xc7, 0x72, 0xdf, 0x23, 0xdf, 0xc6, 0x14, 0x1b, 0x16, - 0x75, 0xa1, 0xb0, 0x1a, 0x7f, 0x06, 0x68, 0x8d, 0x74, 0x89, 0x4b, 0xc6, 0xc9, 0x1e, 0x8a, 0x4f, - 0xd2, 0xaa, 0x4f, 0xf0, 0x3f, 0x6b, 0x30, 0x13, 0x10, 0x3f, 0xd6, 0xb4, 0xaa, 0x90, 0x6b, 0x33, - 0x61, 0xdc, 0x82, 0xb4, 0x2e, 0x9b, 0xe8, 0x09, 0x4c, 0x09, 0x03, 0x9c, 0x6a, 0x3a, 0x61, 0xd3, - 0xe4, 0xb8, 0x4d, 0x0e, 0xfe, 0x36, 0x05, 0x79, 0x31, 0xd1, 0x9d, 0x3e, 0x5a, 0x81, 0x92, 0xcd, - 0x1b, 0x07, 0x6c, 0x3e, 0xc2, 0xa2, 0x5a, 0x72, 0x12, 0x5a, 0x9f, 0xd0, 0x8b, 0x62, 0x08, 0x23, - 0xa3, 0x3f, 0x81, 0x82, 0x14, 0xd1, 0x1f, 0xb8, 0xc2, 0xe5, 0xd5, 0xa0, 0x00, 0x7f, 0xff, 0xad, - 0x4f, 0xe8, 0x20, 0xd8, 0x77, 0x07, 0x2e, 0x6a, 0xc2, 0xac, 0x1c, 0xcc, 0x67, 0x23, 0xcc, 0x48, - 0x33, 0x29, 0x0b, 0x41, 0x29, 0xd1, 0xa5, 0x5a, 0x9f, 0xd0, 0x91, 0x18, 0xaf, 0x74, 0xaa, 0x26, - 0xb9, 0x67, 0x3c, 0x79, 0x47, 0x4c, 0x6a, 0x9e, 0x99, 0x51, 0x93, 0x9a, 0x67, 0xe6, 0xf3, 0x3c, - 0xe4, 0x44, 0x0b, 0xff, 0x57, 0x0a, 0x40, 0xae, 0xc6, 0x4e, 0x1f, 0xad, 0x41, 0xd9, 0x16, 0xad, - 0x80, 0xb7, 0x6e, 0xc4, 0x7a, 0x4b, 0x2c, 0xe2, 0x84, 0x5e, 0x92, 0x83, 0xb8, 0x71, 0xef, 0x43, - 0xd1, 0x93, 0xe2, 0x3b, 0x6c, 0x2e, 0xc6, 0x61, 0x9e, 0x84, 0x82, 0x1c, 0x40, 0x5d, 0xf6, 0x09, - 0x5c, 0xf5, 0xc6, 0xc7, 0xf8, 0xec, 0xce, 0x08, 0x9f, 0x79, 0x02, 0x67, 0xa4, 0x04, 0xd5, 0x6b, - 0xaa, 0x61, 0xbe, 0xdb, 0xe6, 0x62, 0xdc, 0x16, 0x35, 0x8c, 0x3a, 0x0e, 0x68, 0xbd, 0xe4, 0x4d, - 0xfc, 0xeb, 0x34, 0xe4, 0x56, 0xad, 0x5e, 0xdf, 0xb0, 0xe9, 0x6a, 0x64, 0x6d, 0xe2, 0x0c, 0xba, - 0x2e, 0x73, 0x57, 0x79, 0xf9, 0x6e, 0x50, 0xa2, 0x60, 0x93, 0xff, 0xea, 0x8c, 0x55, 0x17, 0x43, - 0xe8, 0x60, 0x51, 0x1e, 0x53, 0x97, 0x18, 0x2c, 0x8a, 0xa3, 0x18, 0x22, 0x03, 0x39, 0xed, 0x07, - 0x72, 0x0d, 0x72, 0x43, 0x62, 0xfb, 0x25, 0x7d, 0x7d, 0x42, 0x97, 0x04, 0xf4, 0x08, 0xa6, 0xc3, - 0xe5, 0x25, 0x23, 0x78, 0xca, 0xad, 0x60, 0x35, 0xba, 0x0b, 0xc5, 0x40, 0x8d, 0xcb, 0x0a, 0xbe, - 0x42, 0x4f, 0x29, 0x71, 0xd7, 0x64, 0x5e, 0xa5, 0xf5, 0xb8, 0xb8, 0x3e, 0x21, 0x33, 0xeb, 0x35, - 0x99, 0x59, 0xa7, 0xc4, 0x28, 0x91, 0x5b, 0x03, 0x49, 0xe6, 0x83, 0x60, 0x92, 0xc1, 0x1f, 0x40, - 0x29, 0xe0, 0x20, 0x5a, 0x77, 0x1a, 0x1f, 0xef, 0xaf, 0x6c, 0xf1, 0x22, 0xf5, 0x82, 0xd5, 0x25, - 0xbd, 0xa2, 0xd1, 0x5a, 0xb7, 0xd5, 0xd8, 0xdb, 0xab, 0xa4, 0x50, 0x09, 0xf2, 0xdb, 0x3b, 0xcd, - 0x03, 0xce, 0x95, 0xc6, 0x2f, 0x3c, 0x09, 0xa2, 0xc8, 0x29, 0xb5, 0x6d, 0x42, 0xa9, 0x6d, 0x9a, - 0xac, 0x6d, 0x29, 0xbf, 0xb6, 0xb1, 0x32, 0xb7, 0xd5, 0x58, 0xd9, 0x6b, 0x54, 0x26, 0x9f, 0x97, - 0xa1, 0xc8, 0xfd, 0x7b, 0x30, 0x30, 0x69, 0xa9, 0xfd, 0x77, 0x0d, 0xc0, 0x8f, 0x26, 0x54, 0x87, - 0x5c, 0x8b, 0xeb, 0xa9, 0x6a, 0x2c, 0x19, 0x5d, 0x8d, 0x5d, 0x32, 0x5d, 0x72, 0xa1, 0x77, 0x20, - 0xe7, 0x0c, 0x5a, 0x2d, 0xe2, 0xc8, 0x92, 0x77, 0x3d, 0x9c, 0x0f, 0x45, 0xb6, 0xd2, 0x25, 0x1f, - 0x1d, 0x72, 0x64, 0x74, 0xba, 0x03, 0x56, 0x00, 0x47, 0x0f, 0x11, 0x7c, 0xf8, 0xdf, 0x34, 0x28, - 0x28, 0x9b, 0xf7, 0x07, 0x26, 0xe1, 0x9b, 0x90, 0x67, 0x36, 0x90, 0xb6, 0x48, 0xc3, 0x53, 0xba, - 0x4f, 0x40, 0x7f, 0x0c, 0x79, 0x19, 0x01, 0x32, 0x13, 0x57, 0xe3, 0xc5, 0xee, 0xf4, 0x75, 0x9f, - 0x15, 0x6f, 0xc2, 0x15, 0xe6, 0x95, 0x16, 0x3d, 0x5c, 0x4b, 0x3f, 0xaa, 0xc7, 0x4f, 0x2d, 0x74, - 0xfc, 0xac, 0xc1, 0x54, 0xff, 0xe4, 0xdc, 0xe9, 0xb4, 0x8c, 0xae, 0xb0, 0xc2, 0x6b, 0xe3, 0x8f, - 0x00, 0xa9, 0xc2, 0xc6, 0x99, 0x2e, 0x2e, 0x41, 0x61, 0xdd, 0x70, 0x4e, 0x84, 0x49, 0xf8, 0x09, - 0x94, 0x68, 0x73, 0xf3, 0xd5, 0x25, 0x6c, 0x64, 0x97, 0x03, 0xc9, 0x3d, 0x96, 0xcf, 0x11, 0x4c, - 0x9e, 0x18, 0xce, 0x09, 0x9b, 0x68, 0x49, 0x67, 0xdf, 0xe8, 0x11, 0x54, 0x5a, 0x7c, 0x92, 0x07, - 0xa1, 0x2b, 0xc3, 0xb4, 0xa0, 0x7b, 0x27, 0xc1, 0x4f, 0xa1, 0xc8, 0xe7, 0xf0, 0x63, 0x1b, 0x81, - 0xaf, 0xc0, 0xf4, 0x9e, 0x69, 0xf4, 0x9d, 0x13, 0x4b, 0x56, 0x37, 0x3a, 0xe9, 0x8a, 0x4f, 0x1b, - 0x4b, 0xe3, 0x43, 0x98, 0xb6, 0x49, 0xcf, 0xe8, 0x98, 0x1d, 0xf3, 0xf8, 0xe0, 0xf0, 0xdc, 0x25, - 0x8e, 0xb8, 0x30, 0x95, 0x3d, 0xf2, 0x73, 0x4a, 0xa5, 0xa6, 0x1d, 0x76, 0xad, 0x43, 0x91, 0xe6, - 0xd8, 0x37, 0xfe, 0x4f, 0x0d, 0x8a, 0x9f, 0x18, 0x6e, 0x4b, 0x2e, 0x1d, 0xda, 0x80, 0xb2, 0x97, - 0xdc, 0x18, 0x45, 0xd8, 0x12, 0x2a, 0xb1, 0x6c, 0x8c, 0x3c, 0x4a, 0xcb, 0xea, 0x58, 0x6a, 0xa9, - 0x04, 0x26, 0xca, 0x30, 0x5b, 0xa4, 0xeb, 0x89, 0x4a, 0x25, 0x8b, 0x62, 0x8c, 0xaa, 0x28, 0x95, - 0xf0, 0x7c, 0xda, 0x3f, 0x7e, 0xf0, 0x5c, 0xf2, 0x75, 0x0a, 0x50, 0xd4, 0x86, 0xef, 0x7b, 0x22, - 0xbb, 0x0f, 0x65, 0xc7, 0x35, 0xec, 0xc8, 0xde, 0x28, 0x31, 0xaa, 0x97, 0xa0, 0x1f, 0xc2, 0x74, - 0xdf, 0xb6, 0x8e, 0x6d, 0xe2, 0x38, 0x07, 0xa6, 0xe5, 0x76, 0x8e, 0xce, 0xc5, 0xa1, 0xb6, 0x2c, - 0xc9, 0xdb, 0x8c, 0x8a, 0x1a, 0x90, 0x3b, 0xea, 0x74, 0x5d, 0x62, 0x3b, 0xd5, 0xcc, 0x42, 0x7a, - 0xb1, 0xbc, 0xfc, 0xe4, 0x22, 0xaf, 0x2d, 0x7d, 0xc8, 0xf8, 0x9b, 0xe7, 0x7d, 0xa2, 0xcb, 0xb1, - 0xea, 0x41, 0x31, 0x1b, 0x38, 0x28, 0xde, 0x07, 0xf0, 0xf9, 0x69, 0xaa, 0xdd, 0xde, 0xd9, 0xdd, - 0x6f, 0x56, 0x26, 0x50, 0x11, 0xa6, 0xb6, 0x77, 0xd6, 0x1a, 0x5b, 0x0d, 0x9a, 0x97, 0x71, 0x5d, - 0xfa, 0x46, 0xf5, 0x21, 0x9a, 0x83, 0xa9, 0xd7, 0x94, 0x2a, 0xef, 0xdb, 0x69, 0x3d, 0xc7, 0xda, - 0x1b, 0x6d, 0xfc, 0x4f, 0x29, 0x28, 0x89, 0x5d, 0x30, 0xd6, 0x56, 0x54, 0x55, 0xa4, 0x02, 0x2a, - 0xe8, 0xa9, 0x94, 0xef, 0x8e, 0xb6, 0x38, 0xfc, 0xca, 0x26, 0xcd, 0x0d, 0x7c, 0xb1, 0x49, 0x5b, - 0xb8, 0xd5, 0x6b, 0xc7, 0x86, 0x6f, 0x26, 0x36, 0x7c, 0xd1, 0x5d, 0x28, 0x79, 0xbb, 0xcd, 0x70, - 0x44, 0xad, 0xcd, 0xeb, 0x45, 0xb9, 0x91, 0x28, 0x0d, 0xdd, 0x87, 0x2c, 0x19, 0x12, 0xd3, 0x75, - 0xaa, 0x05, 0x96, 0x75, 0x4b, 0xf2, 0xfc, 0xdb, 0xa0, 0x54, 0x5d, 0x74, 0xe2, 0x3f, 0x82, 0x2b, - 0xec, 0x9e, 0xf1, 0xc2, 0x36, 0x4c, 0xf5, 0x42, 0xd4, 0x6c, 0x6e, 0x09, 0xd7, 0xd1, 0x4f, 0x54, - 0x86, 0xd4, 0xc6, 0x9a, 0x98, 0x68, 0x6a, 0x63, 0x0d, 0x7f, 0xa1, 0x01, 0x52, 0xc7, 0x8d, 0xe5, - 0xcb, 0x90, 0x70, 0xa9, 0x3e, 0xed, 0xab, 0x9f, 0x85, 0x0c, 0xb1, 0x6d, 0xcb, 0x66, 0x5e, 0xcb, - 0xeb, 0xbc, 0x81, 0xef, 0x09, 0x1b, 0x74, 0x32, 0xb4, 0x4e, 0xbd, 0xc0, 0xe0, 0xd2, 0x34, 0xcf, - 0xd4, 0x4d, 0x98, 0x09, 0x70, 0x8d, 0x95, 0xfd, 0x1f, 0xc2, 0x55, 0x26, 0x6c, 0x93, 0x90, 0xfe, - 0x4a, 0xb7, 0x33, 0x4c, 0xd4, 0xda, 0x87, 0x6b, 0x61, 0xc6, 0x9f, 0xd6, 0x47, 0xf8, 0x4f, 0x85, - 0xc6, 0x66, 0xa7, 0x47, 0x9a, 0xd6, 0x56, 0xb2, 0x6d, 0x34, 0x3b, 0x9e, 0x92, 0x73, 0x47, 0x94, - 0x49, 0xf6, 0x8d, 0xff, 0x43, 0x83, 0xeb, 0x91, 0xe1, 0x3f, 0xf1, 0xaa, 0xce, 0x03, 0x1c, 0xd3, - 0xed, 0x43, 0xda, 0xb4, 0x83, 0xdf, 0xd0, 0x15, 0x8a, 0x67, 0x27, 0x4d, 0x30, 0x45, 0x61, 0xe7, - 0xac, 0x58, 0x73, 0xf6, 0xc7, 0x91, 0x35, 0xe6, 0x16, 0x14, 0x18, 0x61, 0xcf, 0x35, 0xdc, 0x81, - 0x13, 0x59, 0x8c, 0xbf, 0x11, 0x5b, 0x40, 0x0e, 0x1a, 0x6b, 0x5e, 0xef, 0x40, 0x96, 0x1d, 0x4e, - 0xe5, 0xd1, 0x2c, 0x74, 0x1b, 0x50, 0xec, 0xd0, 0x05, 0x23, 0x3e, 0x81, 0xec, 0x4b, 0x86, 0xe8, - 0x29, 0x96, 0x4d, 0xca, 0xa5, 0x30, 0x8d, 0x1e, 0xc7, 0x19, 0xf2, 0x3a, 0xfb, 0x66, 0x27, 0x19, - 0x42, 0xec, 0x7d, 0x7d, 0x8b, 0x9f, 0x98, 0xf2, 0xba, 0xd7, 0xa6, 0x2e, 0x6b, 0x75, 0x3b, 0xc4, - 0x74, 0x59, 0xef, 0x24, 0xeb, 0x55, 0x28, 0x78, 0x09, 0x2a, 0x5c, 0xd3, 0x4a, 0xbb, 0xad, 0x9c, - 0x48, 0x3c, 0x79, 0x5a, 0x50, 0x1e, 0xfe, 0x46, 0x83, 0x2b, 0xca, 0x80, 0xb1, 0x1c, 0xf3, 0x14, - 0xb2, 0x1c, 0xb7, 0x14, 0xc5, 0x6f, 0x36, 0x38, 0x8a, 0xab, 0xd1, 0x05, 0x0f, 0x5a, 0x82, 0x1c, - 0xff, 0x92, 0xc7, 0xc2, 0x78, 0x76, 0xc9, 0x84, 0xef, 0xc3, 0x8c, 0x20, 0x91, 0x9e, 0x15, 0xb7, - 0xb7, 0x99, 0x43, 0xf1, 0xe7, 0x30, 0x1b, 0x64, 0x1b, 0x6b, 0x4a, 0x8a, 0x91, 0xa9, 0xcb, 0x18, - 0xb9, 0x22, 0x8d, 0xdc, 0xef, 0xb7, 0x95, 0x5a, 0x1d, 0x5e, 0x75, 0x75, 0x45, 0x52, 0xa1, 0x15, - 0xf1, 0x26, 0x20, 0x45, 0xfc, 0xac, 0x13, 0x98, 0x91, 0xdb, 0x61, 0xab, 0xe3, 0x78, 0x27, 0xb8, - 0x37, 0x80, 0x54, 0xe2, 0xcf, 0x6d, 0xd0, 0x1a, 0x39, 0xb2, 0x8d, 0xe3, 0x1e, 0xf1, 0xea, 0x13, - 0x3d, 0xcf, 0xab, 0xc4, 0xb1, 0x32, 0x7a, 0x1d, 0xae, 0xbc, 0xb4, 0x86, 0x34, 0x35, 0x50, 0xaa, - 0x1f, 0x32, 0xfc, 0x3e, 0xe7, 0x2d, 0x9b, 0xd7, 0xa6, 0xca, 0xd5, 0x01, 0x63, 0x29, 0xff, 0x5f, - 0x0d, 0x8a, 0x2b, 0x5d, 0xc3, 0xee, 0x49, 0xc5, 0xef, 0x43, 0x96, 0xdf, 0x52, 0x04, 0x30, 0xf0, - 0x20, 0x28, 0x46, 0xe5, 0xe5, 0x8d, 0x15, 0x7e, 0xa7, 0x11, 0xa3, 0xa8, 0xe1, 0xe2, 0xed, 0x60, - 0x2d, 0xf4, 0x96, 0xb0, 0x86, 0xde, 0x82, 0x8c, 0x41, 0x87, 0xb0, 0x14, 0x5c, 0x0e, 0xdf, 0x0f, - 0x99, 0x34, 0x76, 0x38, 0xe3, 0x5c, 0xf8, 0x3d, 0x28, 0x28, 0x1a, 0xe8, 0x0d, 0xf8, 0x45, 0x43, - 0x1c, 0xc0, 0x56, 0x56, 0x9b, 0x1b, 0xaf, 0xf8, 0xc5, 0xb8, 0x0c, 0xb0, 0xd6, 0xf0, 0xda, 0x29, - 0xfc, 0xa9, 0x18, 0x25, 0xf2, 0x9d, 0x6a, 0x8f, 0x96, 0x64, 0x4f, 0xea, 0x52, 0xf6, 0x9c, 0x41, - 0x49, 0x4c, 0x7f, 0xdc, 0xf4, 0xcd, 0xe4, 0x25, 0xa4, 0x6f, 0xc5, 0x78, 0x5d, 0x30, 0xe2, 0x69, - 0x28, 0x89, 0x84, 0x2e, 0xf6, 0xdf, 0xff, 0x68, 0x50, 0x96, 0x94, 0x71, 0x01, 0x4c, 0x89, 0xbd, - 0xf0, 0x0a, 0xe0, 0x21, 0x2f, 0xd7, 0x20, 0xdb, 0x3e, 0xdc, 0xeb, 0xbc, 0x91, 0x60, 0xb3, 0x68, - 0x51, 0x7a, 0x97, 0xeb, 0xe1, 0x2f, 0x3e, 0xa2, 0x45, 0x6f, 0xe1, 0xb6, 0x71, 0xe4, 0x6e, 0x98, - 0x6d, 0x72, 0xc6, 0xce, 0x8d, 0x93, 0xba, 0x4f, 0x60, 0x97, 0x52, 0xf1, 0x32, 0xc4, 0x0e, 0x8b, - 0xea, 0x4b, 0xd1, 0x0c, 0x5c, 0x59, 0x19, 0xb8, 0x27, 0x0d, 0xd3, 0x38, 0xec, 0xca, 0x8c, 0x45, - 0xcb, 0x2c, 0x25, 0xae, 0x75, 0x1c, 0x95, 0xda, 0x80, 0x19, 0x4a, 0x25, 0xa6, 0xdb, 0x69, 0x29, - 0xe9, 0x4d, 0x16, 0x31, 0x2d, 0x54, 0xc4, 0x0c, 0xc7, 0x79, 0x6d, 0xd9, 0x6d, 0x31, 0x35, 0xaf, - 0x8d, 0xd7, 0xb8, 0xf0, 0x7d, 0x27, 0x50, 0xa6, 0xbe, 0xaf, 0x94, 0x45, 0x5f, 0xca, 0x0b, 0xe2, - 0x8e, 0x90, 0x82, 0x9f, 0xc0, 0x55, 0xc9, 0x29, 0xc0, 0xbd, 0x11, 0xcc, 0x3b, 0x70, 0x4b, 0x32, - 0xaf, 0x9e, 0xd0, 0xdb, 0xd3, 0xae, 0x50, 0xf8, 0x43, 0xed, 0x7c, 0x0e, 0x55, 0xcf, 0x4e, 0x76, - 0x58, 0xb6, 0xba, 0xaa, 0x01, 0x03, 0x47, 0xec, 0x99, 0xbc, 0xce, 0xbe, 0x29, 0xcd, 0xb6, 0xba, - 0xde, 0x91, 0x80, 0x7e, 0xe3, 0x55, 0x98, 0x93, 0x32, 0xc4, 0x31, 0x36, 0x28, 0x24, 0x62, 0x50, - 0x9c, 0x10, 0xe1, 0x30, 0x3a, 0x74, 0xb4, 0xdb, 0x55, 0xce, 0xa0, 0x6b, 0x99, 0x4c, 0x4d, 0x91, - 0x79, 0x95, 0xef, 0x08, 0x6a, 0x98, 0x5a, 0x31, 0x04, 0x99, 0x0a, 0x50, 0xc9, 0x62, 0x21, 0x28, - 0x39, 0xb2, 0x10, 0x11, 0xd1, 0x9f, 0xc1, 0xbc, 0x67, 0x04, 0xf5, 0xdb, 0x2e, 0xb1, 0x7b, 0x1d, - 0xc7, 0x51, 0xe0, 0xa0, 0xb8, 0x89, 0x3f, 0x80, 0xc9, 0x3e, 0x11, 0x39, 0xa5, 0xb0, 0x8c, 0x96, - 0xf8, 0xfb, 0xed, 0x92, 0x32, 0x98, 0xf5, 0xe3, 0x36, 0xdc, 0x96, 0xd2, 0xb9, 0x47, 0x63, 0xc5, - 0x87, 0x8d, 0x92, 0xb7, 0x6e, 0xee, 0xd6, 0xe8, 0xad, 0x3b, 0xcd, 0xd7, 0xde, 0x83, 0x28, 0x3f, - 0xe2, 0x8e, 0x94, 0xb1, 0x35, 0x56, 0xad, 0xd8, 0xe4, 0x3e, 0xf5, 0x42, 0x72, 0x2c, 0x61, 0x87, - 0x30, 0x1b, 0x8c, 0xe4, 0xb1, 0xd2, 0xd8, 0x2c, 0x64, 0x5c, 0xeb, 0x94, 0xc8, 0x24, 0xc6, 0x1b, - 0xd2, 0x60, 0x2f, 0xcc, 0xc7, 0x32, 0xd8, 0xf0, 0x85, 0xb1, 0x2d, 0x39, 0xae, 0xbd, 0x74, 0x35, - 0xe5, 0xe1, 0x8b, 0x37, 0xf0, 0x36, 0x5c, 0x0b, 0xa7, 0x89, 0xb1, 0x4c, 0x7e, 0xc5, 0x37, 0x70, - 0x5c, 0x26, 0x19, 0x4b, 0xee, 0xc7, 0x7e, 0x32, 0x50, 0x12, 0xca, 0x58, 0x22, 0x75, 0xa8, 0xc5, - 0xe5, 0x97, 0x1f, 0x63, 0xbf, 0x7a, 0xe9, 0x66, 0x2c, 0x61, 0x8e, 0x2f, 0x6c, 0xfc, 0xe5, 0xf7, - 0x73, 0x44, 0x7a, 0x64, 0x8e, 0x10, 0x41, 0xe2, 0x67, 0xb1, 0x9f, 0x60, 0xd3, 0x09, 0x1d, 0x7e, - 0x02, 0x1d, 0x57, 0x07, 0xad, 0x21, 0x9e, 0x0e, 0xd6, 0x90, 0x1b, 0x5b, 0x4d, 0xbb, 0x63, 0x2d, - 0xc6, 0x27, 0x7e, 0xee, 0x8c, 0x64, 0xe6, 0xb1, 0x04, 0x7f, 0x0a, 0x0b, 0xc9, 0x49, 0x79, 0x1c, - 0xc9, 0x8f, 0xeb, 0x90, 0xf7, 0x0e, 0x94, 0xca, 0x6f, 0x1f, 0x0a, 0x90, 0xdb, 0xde, 0xd9, 0xdb, - 0x5d, 0x59, 0x6d, 0xf0, 0x1f, 0x3f, 0xac, 0xee, 0xe8, 0xfa, 0xfe, 0x6e, 0xb3, 0x92, 0x5a, 0xfe, - 0x6d, 0x1a, 0x52, 0x9b, 0xaf, 0xd0, 0x9f, 0x43, 0x86, 0xbf, 0x04, 0x8e, 0x78, 0xfe, 0xad, 0x8d, - 0x7a, 0xec, 0xc4, 0x37, 0xbe, 0xf8, 0xff, 0x5f, 0x7d, 0x95, 0xba, 0x8a, 0x2b, 0xf5, 0xe1, 0xbb, - 0x87, 0xc4, 0x35, 0xea, 0xa7, 0xc3, 0x3a, 0xab, 0x0f, 0xcf, 0xb4, 0xc7, 0x68, 0x1f, 0xd2, 0xbb, - 0x03, 0x17, 0x25, 0x3e, 0x0d, 0xd7, 0x92, 0xdf, 0x40, 0xf1, 0x1c, 0x13, 0x3c, 0x83, 0xcb, 0x8a, - 0xe0, 0xfe, 0xc0, 0xa5, 0x62, 0x07, 0x50, 0x50, 0x5f, 0x31, 0x2f, 0x7c, 0x33, 0xae, 0x5d, 0xfc, - 0x42, 0x8a, 0xef, 0x30, 0x75, 0x37, 0xf0, 0x35, 0x45, 0x1d, 0x7f, 0x6b, 0x55, 0x67, 0xd3, 0x3c, - 0x33, 0x51, 0xe2, 0xab, 0x72, 0x2d, 0xf9, 0xe1, 0x34, 0x76, 0x36, 0xee, 0x99, 0x49, 0xc5, 0x9a, - 0xe2, 0xdd, 0xb4, 0xe5, 0xa2, 0xdb, 0x31, 0xef, 0x66, 0xea, 0x0b, 0x51, 0x6d, 0x21, 0x99, 0x41, - 0x28, 0x5a, 0x60, 0x8a, 0x6a, 0xf8, 0xaa, 0xa2, 0xa8, 0xe5, 0xb1, 0x3d, 0xd3, 0x1e, 0x2f, 0x1f, - 0x43, 0x86, 0x21, 0xc4, 0xe8, 0x2f, 0xe4, 0x47, 0x2d, 0x06, 0xdb, 0x4e, 0x58, 0xfc, 0x00, 0xb6, - 0x8c, 0xab, 0x4c, 0x19, 0xc2, 0x25, 0xa9, 0x8c, 0x61, 0xc4, 0xcf, 0xb4, 0xc7, 0x8b, 0xda, 0xdb, - 0xda, 0xf2, 0x6f, 0x26, 0x21, 0xc3, 0xe0, 0x22, 0x64, 0x01, 0xf8, 0x68, 0x6a, 0x78, 0x96, 0x11, - 0x7c, 0x36, 0x3c, 0xcb, 0x28, 0x10, 0x8b, 0xe7, 0x99, 0xe2, 0x2a, 0x9e, 0x91, 0x8a, 0x19, 0x12, - 0x55, 0x67, 0xe0, 0x1a, 0xf5, 0xe9, 0x50, 0x00, 0x66, 0x3c, 0xcc, 0x50, 0x9c, 0xc0, 0x00, 0xaa, - 0x1a, 0xde, 0x21, 0x31, 0x88, 0x2a, 0xc6, 0x4c, 0xe7, 0x4d, 0x7c, 0x5d, 0xf1, 0x2c, 0x57, 0x6b, - 0x33, 0x46, 0xaa, 0xf7, 0xef, 0x34, 0x28, 0x07, 0x71, 0x51, 0x74, 0x37, 0x46, 0x72, 0x18, 0x5e, - 0xad, 0xdd, 0x1b, 0xcd, 0x94, 0x64, 0x01, 0x57, 0x7f, 0x4a, 0x48, 0xdf, 0xa0, 0x8c, 0xc2, 0xf1, - 0xe8, 0x1f, 0x34, 0x98, 0x0e, 0x81, 0x9d, 0x28, 0x4e, 0x43, 0x04, 0x4a, 0xad, 0xdd, 0xbf, 0x80, - 0x4b, 0x18, 0xf2, 0x80, 0x19, 0xb2, 0x80, 0x6f, 0x44, 0x5c, 0xe1, 0x76, 0x7a, 0xc4, 0xb5, 0x84, - 0x31, 0xde, 0x32, 0x70, 0x60, 0x32, 0x76, 0x19, 0x02, 0x40, 0x67, 0xec, 0x32, 0x04, 0x51, 0xcd, - 0x11, 0xcb, 0xc0, 0xd1, 0x48, 0xba, 0xc5, 0x7f, 0x97, 0x86, 0xdc, 0x2a, 0xff, 0x05, 0x22, 0x72, - 0x20, 0xef, 0x21, 0x80, 0x68, 0x3e, 0x0e, 0x8d, 0xf1, 0x6f, 0x0b, 0xb5, 0xdb, 0x89, 0xfd, 0x42, - 0xfb, 0x7d, 0xa6, 0xfd, 0x36, 0xae, 0x49, 0xed, 0xe2, 0x87, 0x8e, 0x75, 0x7e, 0xed, 0xaf, 0x1b, - 0xed, 0x36, 0x9d, 0xf8, 0xdf, 0x42, 0x51, 0x85, 0xe9, 0xd0, 0x9d, 0x58, 0x14, 0x48, 0x45, 0xfa, - 0x6a, 0x78, 0x14, 0x8b, 0xd0, 0xbe, 0xc8, 0xb4, 0x63, 0x7c, 0x2b, 0x41, 0xbb, 0xcd, 0xd8, 0x03, - 0x06, 0x70, 0x98, 0x2d, 0xde, 0x80, 0x00, 0x8a, 0x17, 0x6f, 0x40, 0x10, 0xa5, 0xbb, 0xd0, 0x80, - 0x01, 0x63, 0xa7, 0x06, 0xbc, 0x06, 0xf0, 0x41, 0x35, 0x14, 0xeb, 0x57, 0xe5, 0xea, 0x14, 0x0e, - 0xf9, 0x28, 0x1e, 0x17, 0xdd, 0x73, 0x21, 0xd5, 0xdd, 0x8e, 0x43, 0x43, 0x7f, 0xf9, 0x9b, 0x2c, - 0x14, 0x5e, 0x1a, 0x1d, 0xd3, 0x25, 0xa6, 0x61, 0xb6, 0x08, 0x3a, 0x82, 0x0c, 0x2b, 0x8d, 0xe1, - 0x2c, 0xa7, 0x62, 0x4d, 0xe1, 0x2c, 0x17, 0x00, 0x62, 0xf0, 0x3d, 0xa6, 0x79, 0x1e, 0xcf, 0x49, - 0xcd, 0x3d, 0x5f, 0x7c, 0x9d, 0x61, 0x28, 0x74, 0xc2, 0x7f, 0x09, 0x59, 0x01, 0xcf, 0x87, 0x84, - 0x05, 0xb0, 0x95, 0xda, 0xcd, 0xf8, 0xce, 0xa4, 0xed, 0xa5, 0xaa, 0x72, 0x18, 0x2f, 0xd5, 0xf5, - 0x06, 0xc0, 0x07, 0x08, 0xc3, 0xce, 0x8d, 0xe0, 0x89, 0xb5, 0x85, 0x64, 0x06, 0xa1, 0xf7, 0x11, - 0xd3, 0x7b, 0x17, 0xcf, 0xc7, 0xe9, 0x6d, 0x7b, 0xfc, 0x54, 0xf7, 0x21, 0x4c, 0xae, 0x1b, 0xce, - 0x09, 0x0a, 0x15, 0x3b, 0xe5, 0x47, 0x03, 0xb5, 0x5a, 0x5c, 0x97, 0xd0, 0x74, 0x97, 0x69, 0xba, - 0x85, 0xab, 0x71, 0x9a, 0x4e, 0x0c, 0x87, 0x56, 0x0f, 0x74, 0x02, 0x59, 0xfe, 0x3b, 0x82, 0xb0, - 0x2f, 0x03, 0xbf, 0x45, 0x08, 0xfb, 0x32, 0xf8, 0xd3, 0x83, 0xcb, 0x69, 0x72, 0x61, 0x4a, 0x3e, - 0xde, 0xa3, 0x5b, 0xa1, 0xa5, 0x09, 0x3e, 0xf4, 0xd7, 0xe6, 0x93, 0xba, 0x85, 0xbe, 0x87, 0x4c, - 0xdf, 0x1d, 0x7c, 0x33, 0x76, 0xed, 0x04, 0xf7, 0x33, 0xed, 0xf1, 0xdb, 0x1a, 0x2d, 0x13, 0xe0, - 0x83, 0xac, 0x91, 0xe8, 0x08, 0xe3, 0xb5, 0x91, 0xe8, 0x88, 0xe0, 0xb3, 0x78, 0x99, 0x29, 0x7f, - 0x8a, 0x1f, 0xc6, 0x29, 0x77, 0x6d, 0xc3, 0x74, 0x8e, 0x88, 0xfd, 0x16, 0x07, 0xd3, 0x9c, 0x93, - 0x4e, 0x9f, 0x46, 0xca, 0xef, 0xa7, 0x61, 0x92, 0x9e, 0x47, 0x69, 0x79, 0xf6, 0xaf, 0xf1, 0x61, - 0x6b, 0x22, 0xe0, 0x59, 0xd8, 0x9a, 0x28, 0x02, 0x10, 0x2d, 0xcf, 0xec, 0xb7, 0xe6, 0x84, 0x31, - 0x51, 0xaf, 0x3b, 0x50, 0x50, 0xee, 0xfa, 0x28, 0x46, 0x60, 0x10, 0x99, 0x0b, 0xd7, 0x85, 0x18, - 0xa0, 0x00, 0xdf, 0x66, 0x3a, 0xe7, 0xf0, 0x6c, 0x40, 0x67, 0x9b, 0x73, 0x51, 0xa5, 0x7f, 0x0d, - 0x45, 0x15, 0x13, 0x40, 0x31, 0x32, 0x43, 0xc8, 0x5f, 0x38, 0x25, 0xc6, 0x41, 0x0a, 0xd1, 0xec, - 0xe0, 0xfd, 0xae, 0x5e, 0xb2, 0x52, 0xe5, 0x7d, 0xc8, 0x09, 0xa0, 0x20, 0x6e, 0xb6, 0x41, 0xa8, - 0x30, 0x6e, 0xb6, 0x21, 0x94, 0x21, 0x7a, 0xcc, 0x63, 0x5a, 0xe9, 0x7d, 0x48, 0x96, 0x20, 0xa1, - 0xf1, 0x05, 0x71, 0x93, 0x34, 0xfa, 0xd8, 0x57, 0x92, 0x46, 0xe5, 0x2e, 0x3a, 0x4a, 0xe3, 0x31, - 0x71, 0x45, 0x2c, 0xc9, 0x7b, 0x1e, 0x4a, 0x10, 0xa8, 0xa6, 0x7c, 0x3c, 0x8a, 0x25, 0xe9, 0x54, - 0xee, 0x2b, 0x15, 0xf9, 0x1e, 0x7d, 0x0e, 0xe0, 0x43, 0x1a, 0xe1, 0xd3, 0x56, 0x2c, 0x2e, 0x1a, - 0x3e, 0x6d, 0xc5, 0xa3, 0x22, 0xd1, 0xfc, 0xe1, 0xeb, 0xe6, 0x17, 0x03, 0xaa, 0xfd, 0x5f, 0x34, - 0x40, 0x51, 0x04, 0x04, 0x3d, 0x89, 0xd7, 0x10, 0x8b, 0xb8, 0xd6, 0x9e, 0x5e, 0x8e, 0x39, 0xa9, - 0x44, 0xf8, 0x66, 0xb5, 0xd8, 0x88, 0xfe, 0x6b, 0x6a, 0xd8, 0x97, 0x1a, 0x94, 0x02, 0x10, 0x0a, - 0x7a, 0x90, 0xb0, 0xc6, 0x21, 0xd0, 0xb6, 0xf6, 0xf0, 0x42, 0xbe, 0xa4, 0x93, 0x98, 0xb2, 0x23, - 0xe4, 0x41, 0xfc, 0x1f, 0x35, 0x28, 0x07, 0x61, 0x17, 0x94, 0x20, 0x3f, 0x02, 0xfc, 0xd6, 0x16, - 0x2f, 0x66, 0xbc, 0x78, 0xa9, 0xfc, 0xb3, 0x79, 0x1f, 0x72, 0x02, 0xac, 0x89, 0x0b, 0x88, 0x20, - 0x6c, 0x1c, 0x17, 0x10, 0x21, 0xa4, 0x27, 0x21, 0x20, 0x6c, 0xab, 0x4b, 0x94, 0x10, 0x14, 0x88, - 0x4e, 0x92, 0xc6, 0xd1, 0x21, 0x18, 0x82, 0x83, 0x46, 0x69, 0xf4, 0x43, 0x50, 0xc2, 0x39, 0x28, - 0x41, 0xe0, 0x05, 0x21, 0x18, 0x46, 0x83, 0x12, 0x42, 0x90, 0x29, 0x55, 0x42, 0xd0, 0x07, 0x5f, - 0xe2, 0x42, 0x30, 0x82, 0x88, 0xc7, 0x85, 0x60, 0x14, 0xbf, 0x49, 0x58, 0x57, 0xa6, 0x3b, 0x10, - 0x82, 0x33, 0x31, 0x58, 0x0d, 0x7a, 0x9a, 0xe0, 0xd0, 0x58, 0xb0, 0xbd, 0xf6, 0xd6, 0x25, 0xb9, - 0x47, 0xee, 0x7d, 0xbe, 0x14, 0x72, 0xef, 0x7f, 0xad, 0xc1, 0x6c, 0x1c, 0xd6, 0x83, 0x12, 0x74, - 0x25, 0x00, 0xf5, 0xb5, 0xa5, 0xcb, 0xb2, 0x5f, 0xec, 0x35, 0x2f, 0x1a, 0x9e, 0x57, 0xfe, 0xfb, - 0xbb, 0x79, 0xed, 0xff, 0xbe, 0x9b, 0xd7, 0x7e, 0xf1, 0xdd, 0xbc, 0xf6, 0xaf, 0xbf, 0x9c, 0x9f, - 0x38, 0xcc, 0xb2, 0xff, 0xe1, 0xf5, 0xee, 0x1f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x74, 0x55, 0x61, - 0xe6, 0x68, 0x36, 0x00, 0x00, -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/metrics.go b/vendor/go.etcd.io/etcd/etcdserver/metrics.go deleted file mode 100644 index 10f8a475fca7..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/metrics.go +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - goruntime "runtime" - "time" - - "github.com/coreos/etcd/pkg/runtime" - "github.com/coreos/etcd/version" - "github.com/prometheus/client_golang/prometheus" -) - -var ( - hasLeader = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "has_leader", - Help: "Whether or not a leader exists. 1 is existence, 0 is not.", - }) - isLeader = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "is_leader", - Help: "Whether or not this member is a leader. 1 if is, 0 otherwise.", - }) - leaderChanges = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "leader_changes_seen_total", - Help: "The number of leader changes seen.", - }) - heartbeatSendFailures = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "heartbeat_send_failures_total", - Help: "The total number of leader heartbeat send failures (likely overloaded from slow disk).", - }) - slowApplies = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "slow_apply_total", - Help: "The total number of slow apply requests (likely overloaded from slow disk).", - }) - proposalsCommitted = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "proposals_committed_total", - Help: "The total number of consensus proposals committed.", - }) - proposalsApplied = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "proposals_applied_total", - Help: "The total number of consensus proposals applied.", - }) - proposalsPending = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "proposals_pending", - Help: "The current number of pending proposals to commit.", - }) - proposalsFailed = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "proposals_failed_total", - Help: "The total number of failed proposals seen.", - }) - leaseExpired = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "server", - Name: "lease_expired_total", - Help: "The total number of expired leases.", - }) - slowReadIndex = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "slow_read_indexes_total", - Help: "The total number of pending read indexes not in sync with leader's or timed out read index requests.", - }) - readIndexFailed = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "read_indexes_failed_total", - Help: "The total number of failed read indexes seen.", - }) - quotaBackendBytes = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "quota_backend_bytes", - Help: "Current backend storage quota size in bytes.", - }) - currentVersion = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "version", - Help: "Which version is running. 1 for 'server_version' label with current version.", - }, - []string{"server_version"}) - currentGoVersion = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "go_version", - Help: "Which Go version server is running with. 1 for 'server_go_version' label with current version.", - }, - []string{"server_go_version"}) - serverID = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "id", - Help: "Server or member ID in hexadecimal format. 1 for 'server_id' label with current ID.", - }, - []string{"server_id"}) -) - -func init() { - prometheus.MustRegister(hasLeader) - prometheus.MustRegister(isLeader) - prometheus.MustRegister(leaderChanges) - prometheus.MustRegister(heartbeatSendFailures) - prometheus.MustRegister(slowApplies) - prometheus.MustRegister(proposalsCommitted) - prometheus.MustRegister(proposalsApplied) - prometheus.MustRegister(proposalsPending) - prometheus.MustRegister(proposalsFailed) - prometheus.MustRegister(leaseExpired) - prometheus.MustRegister(slowReadIndex) - prometheus.MustRegister(readIndexFailed) - prometheus.MustRegister(quotaBackendBytes) - prometheus.MustRegister(currentVersion) - prometheus.MustRegister(currentGoVersion) - prometheus.MustRegister(serverID) - - currentVersion.With(prometheus.Labels{ - "server_version": version.Version, - }).Set(1) - currentGoVersion.With(prometheus.Labels{ - "server_go_version": goruntime.Version(), - }).Set(1) -} - -func monitorFileDescriptor(done <-chan struct{}) { - ticker := time.NewTicker(5 * time.Second) - defer ticker.Stop() - for { - used, err := runtime.FDUsage() - if err != nil { - plog.Errorf("cannot monitor file descriptor usage (%v)", err) - return - } - limit, err := runtime.FDLimit() - if err != nil { - plog.Errorf("cannot monitor file descriptor usage (%v)", err) - return - } - if used >= limit/5*4 { - plog.Warningf("80%% of the file descriptor limit is used [used = %d, limit = %d]", used, limit) - } - select { - case <-ticker.C: - case <-done: - return - } - } -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/quota.go b/vendor/go.etcd.io/etcd/etcdserver/quota.go deleted file mode 100644 index 882eb76f81b6..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/quota.go +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - -const ( - // DefaultQuotaBytes is the number of bytes the backend Size may - // consume before exceeding the space quota. - DefaultQuotaBytes = int64(2 * 1024 * 1024 * 1024) // 2GB - // MaxQuotaBytes is the maximum number of bytes suggested for a backend - // quota. A larger quota may lead to degraded performance. - MaxQuotaBytes = int64(8 * 1024 * 1024 * 1024) // 8GB -) - -// Quota represents an arbitrary quota against arbitrary requests. Each request -// costs some charge; if there is not enough remaining charge, then there are -// too few resources available within the quota to apply the request. -type Quota interface { - // Available judges whether the given request fits within the quota. - Available(req interface{}) bool - // Cost computes the charge against the quota for a given request. - Cost(req interface{}) int - // Remaining is the amount of charge left for the quota. - Remaining() int64 -} - -type passthroughQuota struct{} - -func (*passthroughQuota) Available(interface{}) bool { return true } -func (*passthroughQuota) Cost(interface{}) int { return 0 } -func (*passthroughQuota) Remaining() int64 { return 1 } - -type backendQuota struct { - s *EtcdServer - maxBackendBytes int64 -} - -const ( - // leaseOverhead is an estimate for the cost of storing a lease - leaseOverhead = 64 - // kvOverhead is an estimate for the cost of storing a key's metadata - kvOverhead = 256 -) - -func NewBackendQuota(s *EtcdServer) Quota { - quotaBackendBytes.Set(float64(s.Cfg.QuotaBackendBytes)) - - if s.Cfg.QuotaBackendBytes < 0 { - // disable quotas if negative - plog.Warningf("disabling backend quota") - return &passthroughQuota{} - } - - if s.Cfg.QuotaBackendBytes == 0 { - // use default size if no quota size given - quotaBackendBytes.Set(float64(DefaultQuotaBytes)) - return &backendQuota{s, DefaultQuotaBytes} - } - - if s.Cfg.QuotaBackendBytes > MaxQuotaBytes { - plog.Warningf("backend quota %v exceeds maximum recommended quota %v", s.Cfg.QuotaBackendBytes, MaxQuotaBytes) - } - return &backendQuota{s, s.Cfg.QuotaBackendBytes} -} - -func (b *backendQuota) Available(v interface{}) bool { - // TODO: maybe optimize backend.Size() - return b.s.Backend().Size()+int64(b.Cost(v)) < b.maxBackendBytes -} - -func (b *backendQuota) Cost(v interface{}) int { - switch r := v.(type) { - case *pb.PutRequest: - return costPut(r) - case *pb.TxnRequest: - return costTxn(r) - case *pb.LeaseGrantRequest: - return leaseOverhead - default: - panic("unexpected cost") - } -} - -func costPut(r *pb.PutRequest) int { return kvOverhead + len(r.Key) + len(r.Value) } - -func costTxnReq(u *pb.RequestOp) int { - r := u.GetRequestPut() - if r == nil { - return 0 - } - return costPut(r) -} - -func costTxn(r *pb.TxnRequest) int { - sizeSuccess := 0 - for _, u := range r.Success { - sizeSuccess += costTxnReq(u) - } - sizeFailure := 0 - for _, u := range r.Failure { - sizeFailure += costTxnReq(u) - } - if sizeFailure > sizeSuccess { - return sizeFailure - } - return sizeSuccess -} - -func (b *backendQuota) Remaining() int64 { - return b.maxBackendBytes - b.s.Backend().Size() -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/raft.go b/vendor/go.etcd.io/etcd/etcdserver/raft.go deleted file mode 100644 index f73df6c7dc0d..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/raft.go +++ /dev/null @@ -1,608 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "encoding/json" - "expvar" - "sort" - "sync" - "sync/atomic" - "time" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/pkg/contention" - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/rafthttp" - "github.com/coreos/etcd/wal" - "github.com/coreos/etcd/wal/walpb" - "github.com/coreos/pkg/capnslog" -) - -const ( - // Number of entries for slow follower to catch-up after compacting - // the raft storage entries. - // We expect the follower has a millisecond level latency with the leader. - // The max throughput is around 10K. Keep a 5K entries is enough for helping - // follower to catch up. - numberOfCatchUpEntries = 5000 - - // The max throughput of etcd will not exceed 100MB/s (100K * 1KB value). - // Assuming the RTT is around 10ms, 1MB max size is large enough. - maxSizePerMsg = 1 * 1024 * 1024 - // Never overflow the rafthttp buffer, which is 4096. - // TODO: a better const? - maxInflightMsgs = 4096 / 8 -) - -var ( - // protects raftStatus - raftStatusMu sync.Mutex - // indirection for expvar func interface - // expvar panics when publishing duplicate name - // expvar does not support remove a registered name - // so only register a func that calls raftStatus - // and change raftStatus as we need. - raftStatus func() raft.Status -) - -func init() { - raft.SetLogger(capnslog.NewPackageLogger("github.com/coreos/etcd", "raft")) - expvar.Publish("raft.status", expvar.Func(func() interface{} { - raftStatusMu.Lock() - defer raftStatusMu.Unlock() - return raftStatus() - })) -} - -type RaftTimer interface { - Index() uint64 - Term() uint64 -} - -// apply contains entries, snapshot to be applied. Once -// an apply is consumed, the entries will be persisted to -// to raft storage concurrently; the application must read -// raftDone before assuming the raft messages are stable. -type apply struct { - entries []raftpb.Entry - snapshot raftpb.Snapshot - // notifyc synchronizes etcd server applies with the raft node - notifyc chan struct{} -} - -type raftNode struct { - // Cache of the latest raft index and raft term the server has seen. - // These three unit64 fields must be the first elements to keep 64-bit - // alignment for atomic access to the fields. - index uint64 - term uint64 - lead uint64 - - tickMu *sync.Mutex - raftNodeConfig - - // a chan to send/receive snapshot - msgSnapC chan raftpb.Message - - // a chan to send out apply - applyc chan apply - - // a chan to send out readState - readStateC chan raft.ReadState - - // utility - ticker *time.Ticker - // contention detectors for raft heartbeat message - td *contention.TimeoutDetector - - stopped chan struct{} - done chan struct{} -} - -type raftNodeConfig struct { - // to check if msg receiver is removed from cluster - isIDRemoved func(id uint64) bool - raft.Node - raftStorage *raft.MemoryStorage - storage Storage - heartbeat time.Duration // for logging - // transport specifies the transport to send and receive msgs to members. - // Sending messages MUST NOT block. It is okay to drop messages, since - // clients should timeout and reissue their messages. - // If transport is nil, server will panic. - transport rafthttp.Transporter -} - -func newRaftNode(cfg raftNodeConfig) *raftNode { - r := &raftNode{ - tickMu: new(sync.Mutex), - raftNodeConfig: cfg, - // set up contention detectors for raft heartbeat message. - // expect to send a heartbeat within 2 heartbeat intervals. - td: contention.NewTimeoutDetector(2 * cfg.heartbeat), - readStateC: make(chan raft.ReadState, 1), - msgSnapC: make(chan raftpb.Message, maxInFlightMsgSnap), - applyc: make(chan apply), - stopped: make(chan struct{}), - done: make(chan struct{}), - } - if r.heartbeat == 0 { - r.ticker = &time.Ticker{} - } else { - r.ticker = time.NewTicker(r.heartbeat) - } - return r -} - -// raft.Node does not have locks in Raft package -func (r *raftNode) tick() { - r.tickMu.Lock() - r.Tick() - r.tickMu.Unlock() -} - -// start prepares and starts raftNode in a new goroutine. It is no longer safe -// to modify the fields after it has been started. -func (r *raftNode) start(rh *raftReadyHandler) { - internalTimeout := time.Second - - go func() { - defer r.onStop() - islead := false - - for { - select { - case <-r.ticker.C: - r.tick() - case rd := <-r.Ready(): - if rd.SoftState != nil { - newLeader := rd.SoftState.Lead != raft.None && atomic.LoadUint64(&r.lead) != rd.SoftState.Lead - if newLeader { - leaderChanges.Inc() - } - - if rd.SoftState.Lead == raft.None { - hasLeader.Set(0) - } else { - hasLeader.Set(1) - } - - atomic.StoreUint64(&r.lead, rd.SoftState.Lead) - islead = rd.RaftState == raft.StateLeader - if islead { - isLeader.Set(1) - } else { - isLeader.Set(0) - } - rh.updateLeadership(newLeader) - r.td.Reset() - } - - if len(rd.ReadStates) != 0 { - select { - case r.readStateC <- rd.ReadStates[len(rd.ReadStates)-1]: - case <-time.After(internalTimeout): - plog.Warningf("timed out sending read state") - case <-r.stopped: - return - } - } - - notifyc := make(chan struct{}, 1) - ap := apply{ - entries: rd.CommittedEntries, - snapshot: rd.Snapshot, - notifyc: notifyc, - } - - updateCommittedIndex(&ap, rh) - - select { - case r.applyc <- ap: - case <-r.stopped: - return - } - - // the leader can write to its disk in parallel with replicating to the followers and them - // writing to their disks. - // For more details, check raft thesis 10.2.1 - if islead { - // gofail: var raftBeforeLeaderSend struct{} - r.transport.Send(r.processMessages(rd.Messages)) - } - - // gofail: var raftBeforeSave struct{} - if err := r.storage.Save(rd.HardState, rd.Entries); err != nil { - plog.Fatalf("raft save state and entries error: %v", err) - } - if !raft.IsEmptyHardState(rd.HardState) { - proposalsCommitted.Set(float64(rd.HardState.Commit)) - } - // gofail: var raftAfterSave struct{} - - if !raft.IsEmptySnap(rd.Snapshot) { - // gofail: var raftBeforeSaveSnap struct{} - if err := r.storage.SaveSnap(rd.Snapshot); err != nil { - plog.Fatalf("raft save snapshot error: %v", err) - } - // etcdserver now claim the snapshot has been persisted onto the disk - notifyc <- struct{}{} - - // gofail: var raftAfterSaveSnap struct{} - r.raftStorage.ApplySnapshot(rd.Snapshot) - plog.Infof("raft applied incoming snapshot at index %d", rd.Snapshot.Metadata.Index) - // gofail: var raftAfterApplySnap struct{} - } - - r.raftStorage.Append(rd.Entries) - - if !islead { - // finish processing incoming messages before we signal raftdone chan - msgs := r.processMessages(rd.Messages) - - // now unblocks 'applyAll' that waits on Raft log disk writes before triggering snapshots - notifyc <- struct{}{} - - // Candidate or follower needs to wait for all pending configuration - // changes to be applied before sending messages. - // Otherwise we might incorrectly count votes (e.g. votes from removed members). - // Also slow machine's follower raft-layer could proceed to become the leader - // on its own single-node cluster, before apply-layer applies the config change. - // We simply wait for ALL pending entries to be applied for now. - // We might improve this later on if it causes unnecessary long blocking issues. - waitApply := false - for _, ent := range rd.CommittedEntries { - if ent.Type == raftpb.EntryConfChange { - waitApply = true - break - } - } - if waitApply { - // blocks until 'applyAll' calls 'applyWait.Trigger' - // to be in sync with scheduled config-change job - // (assume notifyc has cap of 1) - select { - case notifyc <- struct{}{}: - case <-r.stopped: - return - } - } - - // gofail: var raftBeforeFollowerSend struct{} - r.transport.Send(msgs) - } else { - // leader already processed 'MsgSnap' and signaled - notifyc <- struct{}{} - } - - r.Advance() - case <-r.stopped: - return - } - } - }() -} - -func updateCommittedIndex(ap *apply, rh *raftReadyHandler) { - var ci uint64 - if len(ap.entries) != 0 { - ci = ap.entries[len(ap.entries)-1].Index - } - if ap.snapshot.Metadata.Index > ci { - ci = ap.snapshot.Metadata.Index - } - if ci != 0 { - rh.updateCommittedIndex(ci) - } -} - -func (r *raftNode) processMessages(ms []raftpb.Message) []raftpb.Message { - sentAppResp := false - for i := len(ms) - 1; i >= 0; i-- { - if r.isIDRemoved(ms[i].To) { - ms[i].To = 0 - } - - if ms[i].Type == raftpb.MsgAppResp { - if sentAppResp { - ms[i].To = 0 - } else { - sentAppResp = true - } - } - - if ms[i].Type == raftpb.MsgSnap { - // There are two separate data store: the store for v2, and the KV for v3. - // The msgSnap only contains the most recent snapshot of store without KV. - // So we need to redirect the msgSnap to etcd server main loop for merging in the - // current store snapshot and KV snapshot. - select { - case r.msgSnapC <- ms[i]: - default: - // drop msgSnap if the inflight chan if full. - } - ms[i].To = 0 - } - if ms[i].Type == raftpb.MsgHeartbeat { - ok, exceed := r.td.Observe(ms[i].To) - if !ok { - // TODO: limit request rate. - plog.Warningf("failed to send out heartbeat on time (exceeded the %v timeout for %v, to %x)", r.heartbeat, exceed, ms[i].To) - plog.Warningf("server is likely overloaded") - heartbeatSendFailures.Inc() - } - } - } - return ms -} - -func (r *raftNode) apply() chan apply { - return r.applyc -} - -func (r *raftNode) stop() { - r.stopped <- struct{}{} - <-r.done -} - -func (r *raftNode) onStop() { - r.Stop() - r.ticker.Stop() - r.transport.Stop() - if err := r.storage.Close(); err != nil { - plog.Panicf("raft close storage error: %v", err) - } - close(r.done) -} - -// for testing -func (r *raftNode) pauseSending() { - p := r.transport.(rafthttp.Pausable) - p.Pause() -} - -func (r *raftNode) resumeSending() { - p := r.transport.(rafthttp.Pausable) - p.Resume() -} - -// advanceTicks advances ticks of Raft node. -// This can be used for fast-forwarding election -// ticks in multi data-center deployments, thus -// speeding up election process. -func (r *raftNode) advanceTicks(ticks int) { - for i := 0; i < ticks; i++ { - r.tick() - } -} - -func startNode(cfg ServerConfig, cl *membership.RaftCluster, ids []types.ID) (id types.ID, n raft.Node, s *raft.MemoryStorage, w *wal.WAL) { - var err error - member := cl.MemberByName(cfg.Name) - metadata := pbutil.MustMarshal( - &pb.Metadata{ - NodeID: uint64(member.ID), - ClusterID: uint64(cl.ID()), - }, - ) - if w, err = wal.Create(cfg.WALDir(), metadata); err != nil { - plog.Panicf("create wal error: %v", err) - } - peers := make([]raft.Peer, len(ids)) - for i, id := range ids { - ctx, err := json.Marshal((*cl).Member(id)) - if err != nil { - plog.Panicf("marshal member should never fail: %v", err) - } - peers[i] = raft.Peer{ID: uint64(id), Context: ctx} - } - id = member.ID - plog.Infof("starting member %s in cluster %s", id, cl.ID()) - s = raft.NewMemoryStorage() - c := &raft.Config{ - ID: uint64(id), - ElectionTick: cfg.ElectionTicks, - HeartbeatTick: 1, - Storage: s, - MaxSizePerMsg: maxSizePerMsg, - MaxInflightMsgs: maxInflightMsgs, - CheckQuorum: true, - } - - n = raft.StartNode(c, peers) - raftStatusMu.Lock() - raftStatus = n.Status - raftStatusMu.Unlock() - return id, n, s, w -} - -func restartNode(cfg ServerConfig, snapshot *raftpb.Snapshot) (types.ID, *membership.RaftCluster, raft.Node, *raft.MemoryStorage, *wal.WAL) { - var walsnap walpb.Snapshot - if snapshot != nil { - walsnap.Index, walsnap.Term = snapshot.Metadata.Index, snapshot.Metadata.Term - } - w, id, cid, st, ents := readWAL(cfg.WALDir(), walsnap) - - plog.Infof("restarting member %s in cluster %s at commit index %d", id, cid, st.Commit) - cl := membership.NewCluster("") - cl.SetID(cid) - s := raft.NewMemoryStorage() - if snapshot != nil { - s.ApplySnapshot(*snapshot) - } - s.SetHardState(st) - s.Append(ents) - c := &raft.Config{ - ID: uint64(id), - ElectionTick: cfg.ElectionTicks, - HeartbeatTick: 1, - Storage: s, - MaxSizePerMsg: maxSizePerMsg, - MaxInflightMsgs: maxInflightMsgs, - CheckQuorum: true, - } - - n := raft.RestartNode(c) - raftStatusMu.Lock() - raftStatus = n.Status - raftStatusMu.Unlock() - return id, cl, n, s, w -} - -func restartAsStandaloneNode(cfg ServerConfig, snapshot *raftpb.Snapshot) (types.ID, *membership.RaftCluster, raft.Node, *raft.MemoryStorage, *wal.WAL) { - var walsnap walpb.Snapshot - if snapshot != nil { - walsnap.Index, walsnap.Term = snapshot.Metadata.Index, snapshot.Metadata.Term - } - w, id, cid, st, ents := readWAL(cfg.WALDir(), walsnap) - - // discard the previously uncommitted entries - for i, ent := range ents { - if ent.Index > st.Commit { - plog.Infof("discarding %d uncommitted WAL entries ", len(ents)-i) - ents = ents[:i] - break - } - } - - // force append the configuration change entries - toAppEnts := createConfigChangeEnts(getIDs(snapshot, ents), uint64(id), st.Term, st.Commit) - ents = append(ents, toAppEnts...) - - // force commit newly appended entries - err := w.Save(raftpb.HardState{}, toAppEnts) - if err != nil { - plog.Fatalf("%v", err) - } - if len(ents) != 0 { - st.Commit = ents[len(ents)-1].Index - } - - plog.Printf("forcing restart of member %s in cluster %s at commit index %d", id, cid, st.Commit) - cl := membership.NewCluster("") - cl.SetID(cid) - s := raft.NewMemoryStorage() - if snapshot != nil { - s.ApplySnapshot(*snapshot) - } - s.SetHardState(st) - s.Append(ents) - c := &raft.Config{ - ID: uint64(id), - ElectionTick: cfg.ElectionTicks, - HeartbeatTick: 1, - Storage: s, - MaxSizePerMsg: maxSizePerMsg, - MaxInflightMsgs: maxInflightMsgs, - CheckQuorum: true, - } - n := raft.RestartNode(c) - raftStatus = n.Status - return id, cl, n, s, w -} - -// getIDs returns an ordered set of IDs included in the given snapshot and -// the entries. The given snapshot/entries can contain two kinds of -// ID-related entry: -// - ConfChangeAddNode, in which case the contained ID will be added into the set. -// - ConfChangeRemoveNode, in which case the contained ID will be removed from the set. -func getIDs(snap *raftpb.Snapshot, ents []raftpb.Entry) []uint64 { - ids := make(map[uint64]bool) - if snap != nil { - for _, id := range snap.Metadata.ConfState.Nodes { - ids[id] = true - } - } - for _, e := range ents { - if e.Type != raftpb.EntryConfChange { - continue - } - var cc raftpb.ConfChange - pbutil.MustUnmarshal(&cc, e.Data) - switch cc.Type { - case raftpb.ConfChangeAddNode: - ids[cc.NodeID] = true - case raftpb.ConfChangeRemoveNode: - delete(ids, cc.NodeID) - case raftpb.ConfChangeUpdateNode: - // do nothing - default: - plog.Panicf("ConfChange Type should be either ConfChangeAddNode or ConfChangeRemoveNode!") - } - } - sids := make(types.Uint64Slice, 0, len(ids)) - for id := range ids { - sids = append(sids, id) - } - sort.Sort(sids) - return []uint64(sids) -} - -// createConfigChangeEnts creates a series of Raft entries (i.e. -// EntryConfChange) to remove the set of given IDs from the cluster. The ID -// `self` is _not_ removed, even if present in the set. -// If `self` is not inside the given ids, it creates a Raft entry to add a -// default member with the given `self`. -func createConfigChangeEnts(ids []uint64, self uint64, term, index uint64) []raftpb.Entry { - ents := make([]raftpb.Entry, 0) - next := index + 1 - found := false - for _, id := range ids { - if id == self { - found = true - continue - } - cc := &raftpb.ConfChange{ - Type: raftpb.ConfChangeRemoveNode, - NodeID: id, - } - e := raftpb.Entry{ - Type: raftpb.EntryConfChange, - Data: pbutil.MustMarshal(cc), - Term: term, - Index: next, - } - ents = append(ents, e) - next++ - } - if !found { - m := membership.Member{ - ID: types.ID(self), - RaftAttributes: membership.RaftAttributes{PeerURLs: []string{"http://localhost:2380"}}, - } - ctx, err := json.Marshal(m) - if err != nil { - plog.Panicf("marshal member should never fail: %v", err) - } - cc := &raftpb.ConfChange{ - Type: raftpb.ConfChangeAddNode, - NodeID: self, - Context: ctx, - } - e := raftpb.Entry{ - Type: raftpb.EntryConfChange, - Data: pbutil.MustMarshal(cc), - Term: term, - Index: next, - } - ents = append(ents, e) - } - return ents -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/server.go b/vendor/go.etcd.io/etcd/etcdserver/server.go deleted file mode 100644 index 71e2bcf4bc73..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/server.go +++ /dev/null @@ -1,1745 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "context" - "encoding/json" - "expvar" - "fmt" - "math" - "math/rand" - "net/http" - "os" - "path" - "regexp" - "sync" - "sync/atomic" - "time" - - "github.com/coreos/etcd/alarm" - "github.com/coreos/etcd/auth" - "github.com/coreos/etcd/compactor" - "github.com/coreos/etcd/discovery" - "github.com/coreos/etcd/etcdserver/api" - "github.com/coreos/etcd/etcdserver/api/v2http/httptypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/etcdserver/stats" - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/lease/leasehttp" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/pkg/fileutil" - "github.com/coreos/etcd/pkg/idutil" - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/pkg/runtime" - "github.com/coreos/etcd/pkg/schedule" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/pkg/wait" - "github.com/coreos/etcd/raft" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/rafthttp" - "github.com/coreos/etcd/snap" - "github.com/coreos/etcd/store" - "github.com/coreos/etcd/version" - "github.com/coreos/etcd/wal" - - "github.com/coreos/go-semver/semver" - "github.com/coreos/pkg/capnslog" - "github.com/prometheus/client_golang/prometheus" -) - -const ( - DefaultSnapCount = 100000 - - StoreClusterPrefix = "/0" - StoreKeysPrefix = "/1" - - // HealthInterval is the minimum time the cluster should be healthy - // before accepting add member requests. - HealthInterval = 5 * time.Second - - purgeFileInterval = 30 * time.Second - // monitorVersionInterval should be smaller than the timeout - // on the connection. Or we will not be able to reuse the connection - // (since it will timeout). - monitorVersionInterval = rafthttp.ConnWriteTimeout - time.Second - - // max number of in-flight snapshot messages etcdserver allows to have - // This number is more than enough for most clusters with 5 machines. - maxInFlightMsgSnap = 16 - - releaseDelayAfterSnapshot = 30 * time.Second - - // maxPendingRevokes is the maximum number of outstanding expired lease revocations. - maxPendingRevokes = 16 - - recommendedMaxRequestBytes = 10 * 1024 * 1024 -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdserver") - - storeMemberAttributeRegexp = regexp.MustCompile(path.Join(membership.StoreMembersPrefix, "[[:xdigit:]]{1,16}", "attributes")) -) - -func init() { - rand.Seed(time.Now().UnixNano()) - - expvar.Publish( - "file_descriptor_limit", - expvar.Func( - func() interface{} { - n, _ := runtime.FDLimit() - return n - }, - ), - ) -} - -type Response struct { - Term uint64 - Index uint64 - Event *store.Event - Watcher store.Watcher - Err error -} - -type ServerV2 interface { - Server - // Do takes a V2 request and attempts to fulfill it, returning a Response. - Do(ctx context.Context, r pb.Request) (Response, error) - stats.Stats - ClientCertAuthEnabled() bool -} - -type ServerV3 interface { - Server - ID() types.ID - RaftTimer -} - -func (s *EtcdServer) ClientCertAuthEnabled() bool { return s.Cfg.ClientCertAuthEnabled } - -type Server interface { - // Leader returns the ID of the leader Server. - Leader() types.ID - - // AddMember attempts to add a member into the cluster. It will return - // ErrIDRemoved if member ID is removed from the cluster, or return - // ErrIDExists if member ID exists in the cluster. - AddMember(ctx context.Context, memb membership.Member) ([]*membership.Member, error) - // RemoveMember attempts to remove a member from the cluster. It will - // return ErrIDRemoved if member ID is removed from the cluster, or return - // ErrIDNotFound if member ID is not in the cluster. - RemoveMember(ctx context.Context, id uint64) ([]*membership.Member, error) - // UpdateMember attempts to update an existing member in the cluster. It will - // return ErrIDNotFound if the member ID does not exist. - UpdateMember(ctx context.Context, updateMemb membership.Member) ([]*membership.Member, error) - - // ClusterVersion is the cluster-wide minimum major.minor version. - // Cluster version is set to the min version that an etcd member is - // compatible with when first bootstrap. - // - // ClusterVersion is nil until the cluster is bootstrapped (has a quorum). - // - // During a rolling upgrades, the ClusterVersion will be updated - // automatically after a sync. (5 second by default) - // - // The API/raft component can utilize ClusterVersion to determine if - // it can accept a client request or a raft RPC. - // NOTE: ClusterVersion might be nil when etcd 2.1 works with etcd 2.0 and - // the leader is etcd 2.0. etcd 2.0 leader will not update clusterVersion since - // this feature is introduced post 2.0. - ClusterVersion() *semver.Version - Cluster() api.Cluster - Alarms() []*pb.AlarmMember -} - -// EtcdServer is the production implementation of the Server interface -type EtcdServer struct { - // inflightSnapshots holds count the number of snapshots currently inflight. - inflightSnapshots int64 // must use atomic operations to access; keep 64-bit aligned. - appliedIndex uint64 // must use atomic operations to access; keep 64-bit aligned. - committedIndex uint64 // must use atomic operations to access; keep 64-bit aligned. - // consistIndex used to hold the offset of current executing entry - // It is initialized to 0 before executing any entry. - consistIndex consistentIndex // must use atomic operations to access; keep 64-bit aligned. - r raftNode // uses 64-bit atomics; keep 64-bit aligned. - - readych chan struct{} - Cfg ServerConfig - - w wait.Wait - - readMu sync.RWMutex - // read routine notifies etcd server that it waits for reading by sending an empty struct to - // readwaitC - readwaitc chan struct{} - // readNotifier is used to notify the read routine that it can process the request - // when there is no error - readNotifier *notifier - - // stop signals the run goroutine should shutdown. - stop chan struct{} - // stopping is closed by run goroutine on shutdown. - stopping chan struct{} - // done is closed when all goroutines from start() complete. - done chan struct{} - - errorc chan error - id types.ID - attributes membership.Attributes - - cluster *membership.RaftCluster - - store store.Store - snapshotter *snap.Snapshotter - - applyV2 ApplierV2 - - // applyV3 is the applier with auth and quotas - applyV3 applierV3 - // applyV3Base is the core applier without auth or quotas - applyV3Base applierV3 - applyWait wait.WaitTime - - kv mvcc.ConsistentWatchableKV - lessor lease.Lessor - bemu sync.Mutex - be backend.Backend - authStore auth.AuthStore - alarmStore *alarm.AlarmStore - - stats *stats.ServerStats - lstats *stats.LeaderStats - - SyncTicker *time.Ticker - // compactor is used to auto-compact the KV. - compactor compactor.Compactor - - // peerRt used to send requests (version, lease) to peers. - peerRt http.RoundTripper - reqIDGen *idutil.Generator - - // forceVersionC is used to force the version monitor loop - // to detect the cluster version immediately. - forceVersionC chan struct{} - - // wgMu blocks concurrent waitgroup mutation while server stopping - wgMu sync.RWMutex - // wg is used to wait for the go routines that depends on the server state - // to exit when stopping the server. - wg sync.WaitGroup - - // ctx is used for etcd-initiated requests that may need to be canceled - // on etcd server shutdown. - ctx context.Context - cancel context.CancelFunc - - leadTimeMu sync.RWMutex - leadElectedTime time.Time -} - -// NewServer creates a new EtcdServer from the supplied configuration. The -// configuration is considered static for the lifetime of the EtcdServer. -func NewServer(cfg ServerConfig) (srv *EtcdServer, err error) { - st := store.New(StoreClusterPrefix, StoreKeysPrefix) - - var ( - w *wal.WAL - n raft.Node - s *raft.MemoryStorage - id types.ID - cl *membership.RaftCluster - ) - - if cfg.MaxRequestBytes > recommendedMaxRequestBytes { - plog.Warningf("MaxRequestBytes %v exceeds maximum recommended size %v", cfg.MaxRequestBytes, recommendedMaxRequestBytes) - } - - if terr := fileutil.TouchDirAll(cfg.DataDir); terr != nil { - return nil, fmt.Errorf("cannot access data directory: %v", terr) - } - - haveWAL := wal.Exist(cfg.WALDir()) - - if err = fileutil.TouchDirAll(cfg.SnapDir()); err != nil { - plog.Fatalf("create snapshot directory error: %v", err) - } - ss := snap.New(cfg.SnapDir()) - - bepath := cfg.backendPath() - beExist := fileutil.Exist(bepath) - be := openBackend(cfg) - - defer func() { - if err != nil { - be.Close() - } - }() - - prt, err := rafthttp.NewRoundTripper(cfg.PeerTLSInfo, cfg.peerDialTimeout()) - if err != nil { - return nil, err - } - var ( - remotes []*membership.Member - snapshot *raftpb.Snapshot - ) - - switch { - case !haveWAL && !cfg.NewCluster: - if err = cfg.VerifyJoinExisting(); err != nil { - return nil, err - } - cl, err = membership.NewClusterFromURLsMap(cfg.InitialClusterToken, cfg.InitialPeerURLsMap) - if err != nil { - return nil, err - } - existingCluster, gerr := GetClusterFromRemotePeers(getRemotePeerURLs(cl, cfg.Name), prt) - if gerr != nil { - return nil, fmt.Errorf("cannot fetch cluster info from peer urls: %v", gerr) - } - if err = membership.ValidateClusterAndAssignIDs(cl, existingCluster); err != nil { - return nil, fmt.Errorf("error validating peerURLs %s: %v", existingCluster, err) - } - if !isCompatibleWithCluster(cl, cl.MemberByName(cfg.Name).ID, prt) { - return nil, fmt.Errorf("incompatible with current running cluster") - } - - remotes = existingCluster.Members() - cl.SetID(existingCluster.ID()) - cl.SetStore(st) - cl.SetBackend(be) - cfg.Print() - id, n, s, w = startNode(cfg, cl, nil) - case !haveWAL && cfg.NewCluster: - if err = cfg.VerifyBootstrap(); err != nil { - return nil, err - } - cl, err = membership.NewClusterFromURLsMap(cfg.InitialClusterToken, cfg.InitialPeerURLsMap) - if err != nil { - return nil, err - } - m := cl.MemberByName(cfg.Name) - if isMemberBootstrapped(cl, cfg.Name, prt, cfg.bootstrapTimeout()) { - return nil, fmt.Errorf("member %s has already been bootstrapped", m.ID) - } - if cfg.ShouldDiscover() { - var str string - str, err = discovery.JoinCluster(cfg.DiscoveryURL, cfg.DiscoveryProxy, m.ID, cfg.InitialPeerURLsMap.String()) - if err != nil { - return nil, &DiscoveryError{Op: "join", Err: err} - } - var urlsmap types.URLsMap - urlsmap, err = types.NewURLsMap(str) - if err != nil { - return nil, err - } - if checkDuplicateURL(urlsmap) { - return nil, fmt.Errorf("discovery cluster %s has duplicate url", urlsmap) - } - if cl, err = membership.NewClusterFromURLsMap(cfg.InitialClusterToken, urlsmap); err != nil { - return nil, err - } - } - cl.SetStore(st) - cl.SetBackend(be) - cfg.PrintWithInitial() - id, n, s, w = startNode(cfg, cl, cl.MemberIDs()) - case haveWAL: - if err = fileutil.IsDirWriteable(cfg.MemberDir()); err != nil { - return nil, fmt.Errorf("cannot write to member directory: %v", err) - } - - if err = fileutil.IsDirWriteable(cfg.WALDir()); err != nil { - return nil, fmt.Errorf("cannot write to WAL directory: %v", err) - } - - if cfg.ShouldDiscover() { - plog.Warningf("discovery token ignored since a cluster has already been initialized. Valid log found at %q", cfg.WALDir()) - } - snapshot, err = ss.Load() - if err != nil && err != snap.ErrNoSnapshot { - return nil, err - } - if snapshot != nil { - if err = st.Recovery(snapshot.Data); err != nil { - plog.Panicf("recovered store from snapshot error: %v", err) - } - plog.Infof("recovered store from snapshot at index %d", snapshot.Metadata.Index) - if be, err = recoverSnapshotBackend(cfg, be, *snapshot); err != nil { - plog.Panicf("recovering backend from snapshot error: %v", err) - } - } - cfg.Print() - if !cfg.ForceNewCluster { - id, cl, n, s, w = restartNode(cfg, snapshot) - } else { - id, cl, n, s, w = restartAsStandaloneNode(cfg, snapshot) - } - cl.SetStore(st) - cl.SetBackend(be) - cl.Recover(api.UpdateCapability) - if cl.Version() != nil && !cl.Version().LessThan(semver.Version{Major: 3}) && !beExist { - os.RemoveAll(bepath) - return nil, fmt.Errorf("database file (%v) of the backend is missing", bepath) - } - default: - return nil, fmt.Errorf("unsupported bootstrap config") - } - - if terr := fileutil.TouchDirAll(cfg.MemberDir()); terr != nil { - return nil, fmt.Errorf("cannot access member directory: %v", terr) - } - - sstats := stats.NewServerStats(cfg.Name, id.String()) - lstats := stats.NewLeaderStats(id.String()) - - heartbeat := time.Duration(cfg.TickMs) * time.Millisecond - srv = &EtcdServer{ - readych: make(chan struct{}), - Cfg: cfg, - errorc: make(chan error, 1), - store: st, - snapshotter: ss, - r: *newRaftNode( - raftNodeConfig{ - isIDRemoved: func(id uint64) bool { return cl.IsIDRemoved(types.ID(id)) }, - Node: n, - heartbeat: heartbeat, - raftStorage: s, - storage: NewStorage(w, ss), - }, - ), - id: id, - attributes: membership.Attributes{Name: cfg.Name, ClientURLs: cfg.ClientURLs.StringSlice()}, - cluster: cl, - stats: sstats, - lstats: lstats, - SyncTicker: time.NewTicker(500 * time.Millisecond), - peerRt: prt, - reqIDGen: idutil.NewGenerator(uint16(id), time.Now()), - forceVersionC: make(chan struct{}), - } - serverID.With(prometheus.Labels{"server_id": id.String()}).Set(1) - - srv.applyV2 = &applierV2store{store: srv.store, cluster: srv.cluster} - - srv.be = be - minTTL := time.Duration((3*cfg.ElectionTicks)/2) * heartbeat - - // always recover lessor before kv. When we recover the mvcc.KV it will reattach keys to its leases. - // If we recover mvcc.KV first, it will attach the keys to the wrong lessor before it recovers. - srv.lessor = lease.NewLessor(srv.be, int64(math.Ceil(minTTL.Seconds()))) - srv.kv = mvcc.New(srv.be, srv.lessor, &srv.consistIndex) - if beExist { - kvindex := srv.kv.ConsistentIndex() - // TODO: remove kvindex != 0 checking when we do not expect users to upgrade - // etcd from pre-3.0 release. - if snapshot != nil && kvindex < snapshot.Metadata.Index { - if kvindex != 0 { - return nil, fmt.Errorf("database file (%v index %d) does not match with snapshot (index %d).", bepath, kvindex, snapshot.Metadata.Index) - } - plog.Warningf("consistent index never saved (snapshot index=%d)", snapshot.Metadata.Index) - } - } - newSrv := srv // since srv == nil in defer if srv is returned as nil - defer func() { - // closing backend without first closing kv can cause - // resumed compactions to fail with closed tx errors - if err != nil { - newSrv.kv.Close() - } - }() - - srv.consistIndex.setConsistentIndex(srv.kv.ConsistentIndex()) - tp, err := auth.NewTokenProvider(cfg.AuthToken, - func(index uint64) <-chan struct{} { - return srv.applyWait.Wait(index) - }, - ) - if err != nil { - plog.Errorf("failed to create token provider: %s", err) - return nil, err - } - srv.authStore = auth.NewAuthStore(srv.be, tp) - if num := cfg.AutoCompactionRetention; num != 0 { - srv.compactor, err = compactor.New(cfg.AutoCompactionMode, num, srv.kv, srv) - if err != nil { - return nil, err - } - srv.compactor.Run() - } - - srv.applyV3Base = srv.newApplierV3Backend() - if err = srv.restoreAlarms(); err != nil { - return nil, err - } - - // TODO: move transport initialization near the definition of remote - tr := &rafthttp.Transport{ - TLSInfo: cfg.PeerTLSInfo, - DialTimeout: cfg.peerDialTimeout(), - ID: id, - URLs: cfg.PeerURLs, - ClusterID: cl.ID(), - Raft: srv, - Snapshotter: ss, - ServerStats: sstats, - LeaderStats: lstats, - ErrorC: srv.errorc, - } - if err = tr.Start(); err != nil { - return nil, err - } - // add all remotes into transport - for _, m := range remotes { - if m.ID != id { - tr.AddRemote(m.ID, m.PeerURLs) - } - } - for _, m := range cl.Members() { - if m.ID != id { - tr.AddPeer(m.ID, m.PeerURLs) - } - } - srv.r.transport = tr - - return srv, nil -} - -func (s *EtcdServer) adjustTicks() { - clusterN := len(s.cluster.Members()) - - // single-node fresh start, or single-node recovers from snapshot - if clusterN == 1 { - ticks := s.Cfg.ElectionTicks - 1 - plog.Infof("%s as single-node; fast-forwarding %d ticks (election ticks %d)", s.ID(), ticks, s.Cfg.ElectionTicks) - s.r.advanceTicks(ticks) - return - } - - if !s.Cfg.InitialElectionTickAdvance { - plog.Infof("skipping initial election tick advance (election tick %d)", s.Cfg.ElectionTicks) - return - } - - // retry up to "rafthttp.ConnReadTimeout", which is 5-sec - // until peer connection reports; otherwise: - // 1. all connections failed, or - // 2. no active peers, or - // 3. restarted single-node with no snapshot - // then, do nothing, because advancing ticks would have no effect - waitTime := rafthttp.ConnReadTimeout - itv := 50 * time.Millisecond - for i := int64(0); i < int64(waitTime/itv); i++ { - select { - case <-time.After(itv): - case <-s.stopping: - return - } - - peerN := s.r.transport.ActivePeers() - if peerN > 1 { - // multi-node received peer connection reports - // adjust ticks, in case slow leader message receive - ticks := s.Cfg.ElectionTicks - 2 - plog.Infof("%s initialzed peer connection; fast-forwarding %d ticks (election ticks %d) with %d active peer(s)", s.ID(), ticks, s.Cfg.ElectionTicks, peerN) - s.r.advanceTicks(ticks) - return - } - } -} - -// Start performs any initialization of the Server necessary for it to -// begin serving requests. It must be called before Do or Process. -// Start must be non-blocking; any long-running server functionality -// should be implemented in goroutines. -func (s *EtcdServer) Start() { - s.start() - s.goAttach(func() { s.adjustTicks() }) - s.goAttach(func() { s.publish(s.Cfg.ReqTimeout()) }) - s.goAttach(s.purgeFile) - s.goAttach(func() { monitorFileDescriptor(s.stopping) }) - s.goAttach(s.monitorVersions) - s.goAttach(s.linearizableReadLoop) - s.goAttach(s.monitorKVHash) -} - -// start prepares and starts server in a new goroutine. It is no longer safe to -// modify a server's fields after it has been sent to Start. -// This function is just used for testing. -func (s *EtcdServer) start() { - if s.Cfg.SnapCount == 0 { - plog.Infof("set snapshot count to default %d", DefaultSnapCount) - s.Cfg.SnapCount = DefaultSnapCount - } - s.w = wait.New() - s.applyWait = wait.NewTimeList() - s.done = make(chan struct{}) - s.stop = make(chan struct{}) - s.stopping = make(chan struct{}) - s.ctx, s.cancel = context.WithCancel(context.Background()) - s.readwaitc = make(chan struct{}, 1) - s.readNotifier = newNotifier() - if s.ClusterVersion() != nil { - plog.Infof("starting server... [version: %v, cluster version: %v]", version.Version, version.Cluster(s.ClusterVersion().String())) - } else { - plog.Infof("starting server... [version: %v, cluster version: to_be_decided]", version.Version) - } - // TODO: if this is an empty log, writes all peer infos - // into the first entry - go s.run() -} - -func (s *EtcdServer) purgeFile() { - var dberrc, serrc, werrc <-chan error - if s.Cfg.MaxSnapFiles > 0 { - dberrc = fileutil.PurgeFile(s.Cfg.SnapDir(), "snap.db", s.Cfg.MaxSnapFiles, purgeFileInterval, s.done) - serrc = fileutil.PurgeFile(s.Cfg.SnapDir(), "snap", s.Cfg.MaxSnapFiles, purgeFileInterval, s.done) - } - if s.Cfg.MaxWALFiles > 0 { - werrc = fileutil.PurgeFile(s.Cfg.WALDir(), "wal", s.Cfg.MaxWALFiles, purgeFileInterval, s.done) - } - select { - case e := <-dberrc: - plog.Fatalf("failed to purge snap db file %v", e) - case e := <-serrc: - plog.Fatalf("failed to purge snap file %v", e) - case e := <-werrc: - plog.Fatalf("failed to purge wal file %v", e) - case <-s.stopping: - return - } -} - -func (s *EtcdServer) ID() types.ID { return s.id } - -func (s *EtcdServer) Cluster() api.Cluster { return s.cluster } - -func (s *EtcdServer) ApplyWait() <-chan struct{} { return s.applyWait.Wait(s.getCommittedIndex()) } - -type ServerPeer interface { - ServerV2 - RaftHandler() http.Handler - LeaseHandler() http.Handler -} - -func (s *EtcdServer) LeaseHandler() http.Handler { - if s.lessor == nil { - return nil - } - return leasehttp.NewHandler(s.lessor, s.ApplyWait) -} - -func (s *EtcdServer) RaftHandler() http.Handler { return s.r.transport.Handler() } - -// Process takes a raft message and applies it to the server's raft state -// machine, respecting any timeout of the given context. -func (s *EtcdServer) Process(ctx context.Context, m raftpb.Message) error { - if s.cluster.IsIDRemoved(types.ID(m.From)) { - plog.Warningf("reject message from removed member %s", types.ID(m.From).String()) - return httptypes.NewHTTPError(http.StatusForbidden, "cannot process message from removed member") - } - if m.Type == raftpb.MsgApp { - s.stats.RecvAppendReq(types.ID(m.From).String(), m.Size()) - } - return s.r.Step(ctx, m) -} - -func (s *EtcdServer) IsIDRemoved(id uint64) bool { return s.cluster.IsIDRemoved(types.ID(id)) } - -func (s *EtcdServer) ReportUnreachable(id uint64) { s.r.ReportUnreachable(id) } - -// ReportSnapshot reports snapshot sent status to the raft state machine, -// and clears the used snapshot from the snapshot store. -func (s *EtcdServer) ReportSnapshot(id uint64, status raft.SnapshotStatus) { - s.r.ReportSnapshot(id, status) -} - -type etcdProgress struct { - confState raftpb.ConfState - snapi uint64 - appliedt uint64 - appliedi uint64 -} - -// raftReadyHandler contains a set of EtcdServer operations to be called by raftNode, -// and helps decouple state machine logic from Raft algorithms. -// TODO: add a state machine interface to apply the commit entries and do snapshot/recover -type raftReadyHandler struct { - updateLeadership func(newLeader bool) - updateCommittedIndex func(uint64) -} - -func (s *EtcdServer) run() { - sn, err := s.r.raftStorage.Snapshot() - if err != nil { - plog.Panicf("get snapshot from raft storage error: %v", err) - } - - // asynchronously accept apply packets, dispatch progress in-order - sched := schedule.NewFIFOScheduler() - - var ( - smu sync.RWMutex - syncC <-chan time.Time - ) - setSyncC := func(ch <-chan time.Time) { - smu.Lock() - syncC = ch - smu.Unlock() - } - getSyncC := func() (ch <-chan time.Time) { - smu.RLock() - ch = syncC - smu.RUnlock() - return - } - rh := &raftReadyHandler{ - updateLeadership: func(newLeader bool) { - if !s.isLeader() { - if s.lessor != nil { - s.lessor.Demote() - } - if s.compactor != nil { - s.compactor.Pause() - } - setSyncC(nil) - } else { - if newLeader { - t := time.Now() - s.leadTimeMu.Lock() - s.leadElectedTime = t - s.leadTimeMu.Unlock() - } - setSyncC(s.SyncTicker.C) - if s.compactor != nil { - s.compactor.Resume() - } - } - - // TODO: remove the nil checking - // current test utility does not provide the stats - if s.stats != nil { - s.stats.BecomeLeader() - } - }, - updateCommittedIndex: func(ci uint64) { - cci := s.getCommittedIndex() - if ci > cci { - s.setCommittedIndex(ci) - } - }, - } - s.r.start(rh) - - ep := etcdProgress{ - confState: sn.Metadata.ConfState, - snapi: sn.Metadata.Index, - appliedt: sn.Metadata.Term, - appliedi: sn.Metadata.Index, - } - - defer func() { - s.wgMu.Lock() // block concurrent waitgroup adds in goAttach while stopping - close(s.stopping) - s.wgMu.Unlock() - s.cancel() - - sched.Stop() - - // wait for gouroutines before closing raft so wal stays open - s.wg.Wait() - - s.SyncTicker.Stop() - - // must stop raft after scheduler-- etcdserver can leak rafthttp pipelines - // by adding a peer after raft stops the transport - s.r.stop() - - // kv, lessor and backend can be nil if running without v3 enabled - // or running unit tests. - if s.lessor != nil { - s.lessor.Stop() - } - if s.kv != nil { - s.kv.Close() - } - if s.authStore != nil { - s.authStore.Close() - } - if s.be != nil { - s.be.Close() - } - if s.compactor != nil { - s.compactor.Stop() - } - close(s.done) - }() - - var expiredLeaseC <-chan []*lease.Lease - if s.lessor != nil { - expiredLeaseC = s.lessor.ExpiredLeasesC() - } - - for { - select { - case ap := <-s.r.apply(): - f := func(context.Context) { s.applyAll(&ep, &ap) } - sched.Schedule(f) - case leases := <-expiredLeaseC: - s.goAttach(func() { - // Increases throughput of expired leases deletion process through parallelization - c := make(chan struct{}, maxPendingRevokes) - for _, lease := range leases { - select { - case c <- struct{}{}: - case <-s.stopping: - return - } - lid := lease.ID - s.goAttach(func() { - ctx := s.authStore.WithRoot(s.ctx) - _, lerr := s.LeaseRevoke(ctx, &pb.LeaseRevokeRequest{ID: int64(lid)}) - if lerr == nil { - leaseExpired.Inc() - } else { - plog.Warningf("failed to revoke %016x (%q)", lid, lerr.Error()) - } - - <-c - }) - } - }) - case err := <-s.errorc: - plog.Errorf("%s", err) - plog.Infof("the data-dir used by this member must be removed.") - return - case <-getSyncC(): - if s.store.HasTTLKeys() { - s.sync(s.Cfg.ReqTimeout()) - } - case <-s.stop: - return - } - } -} - -func (s *EtcdServer) applyAll(ep *etcdProgress, apply *apply) { - s.applySnapshot(ep, apply) - s.applyEntries(ep, apply) - - proposalsApplied.Set(float64(ep.appliedi)) - s.applyWait.Trigger(ep.appliedi) - // wait for the raft routine to finish the disk writes before triggering a - // snapshot. or applied index might be greater than the last index in raft - // storage, since the raft routine might be slower than apply routine. - <-apply.notifyc - - s.triggerSnapshot(ep) - select { - // snapshot requested via send() - case m := <-s.r.msgSnapC: - merged := s.createMergedSnapshotMessage(m, ep.appliedt, ep.appliedi, ep.confState) - s.sendMergedSnap(merged) - default: - } -} - -func (s *EtcdServer) applySnapshot(ep *etcdProgress, apply *apply) { - if raft.IsEmptySnap(apply.snapshot) { - return - } - - plog.Infof("applying snapshot at index %d...", ep.snapi) - defer plog.Infof("finished applying incoming snapshot at index %d", ep.snapi) - - if apply.snapshot.Metadata.Index <= ep.appliedi { - plog.Panicf("snapshot index [%d] should > appliedi[%d] + 1", - apply.snapshot.Metadata.Index, ep.appliedi) - } - - // wait for raftNode to persist snapshot onto the disk - <-apply.notifyc - - newbe, err := openSnapshotBackend(s.Cfg, s.snapshotter, apply.snapshot) - if err != nil { - plog.Panic(err) - } - - // always recover lessor before kv. When we recover the mvcc.KV it will reattach keys to its leases. - // If we recover mvcc.KV first, it will attach the keys to the wrong lessor before it recovers. - if s.lessor != nil { - plog.Info("recovering lessor...") - s.lessor.Recover(newbe, func() lease.TxnDelete { return s.kv.Write() }) - plog.Info("finished recovering lessor") - } - - plog.Info("restoring mvcc store...") - - if err := s.kv.Restore(newbe); err != nil { - plog.Panicf("restore KV error: %v", err) - } - s.consistIndex.setConsistentIndex(s.kv.ConsistentIndex()) - - plog.Info("finished restoring mvcc store") - - // Closing old backend might block until all the txns - // on the backend are finished. - // We do not want to wait on closing the old backend. - s.bemu.Lock() - oldbe := s.be - go func() { - plog.Info("closing old backend...") - defer plog.Info("finished closing old backend") - - if err := oldbe.Close(); err != nil { - plog.Panicf("close backend error: %v", err) - } - }() - - s.be = newbe - s.bemu.Unlock() - - plog.Info("recovering alarms...") - if err := s.restoreAlarms(); err != nil { - plog.Panicf("restore alarms error: %v", err) - } - plog.Info("finished recovering alarms") - - if s.authStore != nil { - plog.Info("recovering auth store...") - s.authStore.Recover(newbe) - plog.Info("finished recovering auth store") - } - - plog.Info("recovering store v2...") - if err := s.store.Recovery(apply.snapshot.Data); err != nil { - plog.Panicf("recovery store error: %v", err) - } - plog.Info("finished recovering store v2") - - s.cluster.SetBackend(s.be) - plog.Info("recovering cluster configuration...") - s.cluster.Recover(api.UpdateCapability) - plog.Info("finished recovering cluster configuration") - - plog.Info("removing old peers from network...") - // recover raft transport - s.r.transport.RemoveAllPeers() - plog.Info("finished removing old peers from network") - - plog.Info("adding peers from new cluster configuration into network...") - for _, m := range s.cluster.Members() { - if m.ID == s.ID() { - continue - } - s.r.transport.AddPeer(m.ID, m.PeerURLs) - } - plog.Info("finished adding peers from new cluster configuration into network...") - - ep.appliedt = apply.snapshot.Metadata.Term - ep.appliedi = apply.snapshot.Metadata.Index - ep.snapi = ep.appliedi - ep.confState = apply.snapshot.Metadata.ConfState -} - -func (s *EtcdServer) applyEntries(ep *etcdProgress, apply *apply) { - if len(apply.entries) == 0 { - return - } - firsti := apply.entries[0].Index - if firsti > ep.appliedi+1 { - plog.Panicf("first index of committed entry[%d] should <= appliedi[%d] + 1", firsti, ep.appliedi) - } - var ents []raftpb.Entry - if ep.appliedi+1-firsti < uint64(len(apply.entries)) { - ents = apply.entries[ep.appliedi+1-firsti:] - } - if len(ents) == 0 { - return - } - var shouldstop bool - if ep.appliedt, ep.appliedi, shouldstop = s.apply(ents, &ep.confState); shouldstop { - go s.stopWithDelay(10*100*time.Millisecond, fmt.Errorf("the member has been permanently removed from the cluster")) - } -} - -func (s *EtcdServer) triggerSnapshot(ep *etcdProgress) { - if ep.appliedi-ep.snapi <= s.Cfg.SnapCount { - return - } - - plog.Infof("start to snapshot (applied: %d, lastsnap: %d)", ep.appliedi, ep.snapi) - s.snapshot(ep.appliedi, ep.confState) - ep.snapi = ep.appliedi -} - -func (s *EtcdServer) isMultiNode() bool { - return s.cluster != nil && len(s.cluster.MemberIDs()) > 1 -} - -func (s *EtcdServer) isLeader() bool { - return uint64(s.ID()) == s.Lead() -} - -// MoveLeader transfers the leader to the given transferee. -func (s *EtcdServer) MoveLeader(ctx context.Context, lead, transferee uint64) error { - now := time.Now() - interval := time.Duration(s.Cfg.TickMs) * time.Millisecond - - plog.Infof("%s starts leadership transfer from %s to %s", s.ID(), types.ID(lead), types.ID(transferee)) - s.r.TransferLeadership(ctx, lead, transferee) - for s.Lead() != transferee { - select { - case <-ctx.Done(): // time out - return ErrTimeoutLeaderTransfer - case <-time.After(interval): - } - } - - // TODO: drain all requests, or drop all messages to the old leader - - plog.Infof("%s finished leadership transfer from %s to %s (took %v)", s.ID(), types.ID(lead), types.ID(transferee), time.Since(now)) - return nil -} - -// TransferLeadership transfers the leader to the chosen transferee. -func (s *EtcdServer) TransferLeadership() error { - if !s.isLeader() { - plog.Printf("skipped leadership transfer for stopping non-leader member") - return nil - } - - if !s.isMultiNode() { - plog.Printf("skipped leadership transfer for single member cluster") - return nil - } - - transferee, ok := longestConnected(s.r.transport, s.cluster.MemberIDs()) - if !ok { - return ErrUnhealthy - } - - tm := s.Cfg.ReqTimeout() - ctx, cancel := context.WithTimeout(s.ctx, tm) - err := s.MoveLeader(ctx, s.Lead(), uint64(transferee)) - cancel() - return err -} - -// HardStop stops the server without coordination with other members in the cluster. -func (s *EtcdServer) HardStop() { - select { - case s.stop <- struct{}{}: - case <-s.done: - return - } - <-s.done -} - -// Stop stops the server gracefully, and shuts down the running goroutine. -// Stop should be called after a Start(s), otherwise it will block forever. -// When stopping leader, Stop transfers its leadership to one of its peers -// before stopping the server. -// Stop terminates the Server and performs any necessary finalization. -// Do and Process cannot be called after Stop has been invoked. -func (s *EtcdServer) Stop() { - if err := s.TransferLeadership(); err != nil { - plog.Warningf("%s failed to transfer leadership (%v)", s.ID(), err) - } - s.HardStop() -} - -// ReadyNotify returns a channel that will be closed when the server -// is ready to serve client requests -func (s *EtcdServer) ReadyNotify() <-chan struct{} { return s.readych } - -func (s *EtcdServer) stopWithDelay(d time.Duration, err error) { - select { - case <-time.After(d): - case <-s.done: - } - select { - case s.errorc <- err: - default: - } -} - -// StopNotify returns a channel that receives a empty struct -// when the server is stopped. -func (s *EtcdServer) StopNotify() <-chan struct{} { return s.done } - -func (s *EtcdServer) SelfStats() []byte { return s.stats.JSON() } - -func (s *EtcdServer) LeaderStats() []byte { - lead := atomic.LoadUint64(&s.r.lead) - if lead != uint64(s.id) { - return nil - } - return s.lstats.JSON() -} - -func (s *EtcdServer) StoreStats() []byte { return s.store.JsonStats() } - -func (s *EtcdServer) checkMembershipOperationPermission(ctx context.Context) error { - if s.authStore == nil { - // In the context of ordinary etcd process, s.authStore will never be nil. - // This branch is for handling cases in server_test.go - return nil - } - - // Note that this permission check is done in the API layer, - // so TOCTOU problem can be caused potentially in a schedule like this: - // update membership with user A -> revoke root role of A -> apply membership change - // in the state machine layer - // However, both of membership change and role management requires the root privilege. - // So careful operation by admins can prevent the problem. - authInfo, err := s.AuthInfoFromCtx(ctx) - if err != nil { - return err - } - - return s.AuthStore().IsAdminPermitted(authInfo) -} - -func (s *EtcdServer) AddMember(ctx context.Context, memb membership.Member) ([]*membership.Member, error) { - if err := s.checkMembershipOperationPermission(ctx); err != nil { - return nil, err - } - - if s.Cfg.StrictReconfigCheck { - // by default StrictReconfigCheck is enabled; reject new members if unhealthy - if !s.cluster.IsReadyToAddNewMember() { - plog.Warningf("not enough started members, rejecting member add %+v", memb) - return nil, ErrNotEnoughStartedMembers - } - if !isConnectedFullySince(s.r.transport, time.Now().Add(-HealthInterval), s.ID(), s.cluster.Members()) { - plog.Warningf("not healthy for reconfigure, rejecting member add %+v", memb) - return nil, ErrUnhealthy - } - } - - // TODO: move Member to protobuf type - b, err := json.Marshal(memb) - if err != nil { - return nil, err - } - cc := raftpb.ConfChange{ - Type: raftpb.ConfChangeAddNode, - NodeID: uint64(memb.ID), - Context: b, - } - return s.configure(ctx, cc) -} - -func (s *EtcdServer) RemoveMember(ctx context.Context, id uint64) ([]*membership.Member, error) { - if err := s.checkMembershipOperationPermission(ctx); err != nil { - return nil, err - } - - // by default StrictReconfigCheck is enabled; reject removal if leads to quorum loss - if err := s.mayRemoveMember(types.ID(id)); err != nil { - return nil, err - } - - cc := raftpb.ConfChange{ - Type: raftpb.ConfChangeRemoveNode, - NodeID: id, - } - return s.configure(ctx, cc) -} - -func (s *EtcdServer) mayRemoveMember(id types.ID) error { - if !s.Cfg.StrictReconfigCheck { - return nil - } - - if !s.cluster.IsReadyToRemoveMember(uint64(id)) { - plog.Warningf("not enough started members, rejecting remove member %s", id) - return ErrNotEnoughStartedMembers - } - - // downed member is safe to remove since it's not part of the active quorum - if t := s.r.transport.ActiveSince(id); id != s.ID() && t.IsZero() { - return nil - } - - // protect quorum if some members are down - m := s.cluster.Members() - active := numConnectedSince(s.r.transport, time.Now().Add(-HealthInterval), s.ID(), m) - if (active - 1) < 1+((len(m)-1)/2) { - plog.Warningf("reconfigure breaks active quorum, rejecting remove member %s", id) - return ErrUnhealthy - } - - return nil -} - -func (s *EtcdServer) UpdateMember(ctx context.Context, memb membership.Member) ([]*membership.Member, error) { - b, merr := json.Marshal(memb) - if merr != nil { - return nil, merr - } - - if err := s.checkMembershipOperationPermission(ctx); err != nil { - return nil, err - } - cc := raftpb.ConfChange{ - Type: raftpb.ConfChangeUpdateNode, - NodeID: uint64(memb.ID), - Context: b, - } - return s.configure(ctx, cc) -} - -// Implement the RaftTimer interface - -func (s *EtcdServer) Index() uint64 { return atomic.LoadUint64(&s.r.index) } - -func (s *EtcdServer) Term() uint64 { return atomic.LoadUint64(&s.r.term) } - -// Lead is only for testing purposes. -// TODO: add Raft server interface to expose raft related info: -// Index, Term, Lead, Committed, Applied, LastIndex, etc. -func (s *EtcdServer) Lead() uint64 { return atomic.LoadUint64(&s.r.lead) } - -func (s *EtcdServer) Leader() types.ID { return types.ID(s.Lead()) } - -type confChangeResponse struct { - membs []*membership.Member - err error -} - -// configure sends a configuration change through consensus and -// then waits for it to be applied to the server. It -// will block until the change is performed or there is an error. -func (s *EtcdServer) configure(ctx context.Context, cc raftpb.ConfChange) ([]*membership.Member, error) { - cc.ID = s.reqIDGen.Next() - ch := s.w.Register(cc.ID) - start := time.Now() - if err := s.r.ProposeConfChange(ctx, cc); err != nil { - s.w.Trigger(cc.ID, nil) - return nil, err - } - select { - case x := <-ch: - if x == nil { - plog.Panicf("configure trigger value should never be nil") - } - resp := x.(*confChangeResponse) - return resp.membs, resp.err - case <-ctx.Done(): - s.w.Trigger(cc.ID, nil) // GC wait - return nil, s.parseProposeCtxErr(ctx.Err(), start) - case <-s.stopping: - return nil, ErrStopped - } -} - -// sync proposes a SYNC request and is non-blocking. -// This makes no guarantee that the request will be proposed or performed. -// The request will be canceled after the given timeout. -func (s *EtcdServer) sync(timeout time.Duration) { - req := pb.Request{ - Method: "SYNC", - ID: s.reqIDGen.Next(), - Time: time.Now().UnixNano(), - } - data := pbutil.MustMarshal(&req) - // There is no promise that node has leader when do SYNC request, - // so it uses goroutine to propose. - ctx, cancel := context.WithTimeout(s.ctx, timeout) - s.goAttach(func() { - s.r.Propose(ctx, data) - cancel() - }) -} - -// publish registers server information into the cluster. The information -// is the JSON representation of this server's member struct, updated with the -// static clientURLs of the server. -// The function keeps attempting to register until it succeeds, -// or its server is stopped. -func (s *EtcdServer) publish(timeout time.Duration) { - b, err := json.Marshal(s.attributes) - if err != nil { - plog.Panicf("json marshal error: %v", err) - return - } - req := pb.Request{ - Method: "PUT", - Path: membership.MemberAttributesStorePath(s.id), - Val: string(b), - } - - for { - ctx, cancel := context.WithTimeout(s.ctx, timeout) - _, err := s.Do(ctx, req) - cancel() - switch err { - case nil: - close(s.readych) - plog.Infof("published %+v to cluster %s", s.attributes, s.cluster.ID()) - return - case ErrStopped: - plog.Infof("aborting publish because server is stopped") - return - default: - plog.Errorf("publish error: %v", err) - } - } -} - -func (s *EtcdServer) sendMergedSnap(merged snap.Message) { - atomic.AddInt64(&s.inflightSnapshots, 1) - - s.r.transport.SendSnapshot(merged) - s.goAttach(func() { - select { - case ok := <-merged.CloseNotify(): - // delay releasing inflight snapshot for another 30 seconds to - // block log compaction. - // If the follower still fails to catch up, it is probably just too slow - // to catch up. We cannot avoid the snapshot cycle anyway. - if ok { - select { - case <-time.After(releaseDelayAfterSnapshot): - case <-s.stopping: - } - } - atomic.AddInt64(&s.inflightSnapshots, -1) - case <-s.stopping: - return - } - }) -} - -// apply takes entries received from Raft (after it has been committed) and -// applies them to the current state of the EtcdServer. -// The given entries should not be empty. -func (s *EtcdServer) apply(es []raftpb.Entry, confState *raftpb.ConfState) (appliedt uint64, appliedi uint64, shouldStop bool) { - for i := range es { - e := es[i] - switch e.Type { - case raftpb.EntryNormal: - s.applyEntryNormal(&e) - case raftpb.EntryConfChange: - // set the consistent index of current executing entry - if e.Index > s.consistIndex.ConsistentIndex() { - s.consistIndex.setConsistentIndex(e.Index) - } - var cc raftpb.ConfChange - pbutil.MustUnmarshal(&cc, e.Data) - removedSelf, err := s.applyConfChange(cc, confState) - s.setAppliedIndex(e.Index) - shouldStop = shouldStop || removedSelf - s.w.Trigger(cc.ID, &confChangeResponse{s.cluster.Members(), err}) - default: - plog.Panicf("entry type should be either EntryNormal or EntryConfChange") - } - atomic.StoreUint64(&s.r.index, e.Index) - atomic.StoreUint64(&s.r.term, e.Term) - appliedt = e.Term - appliedi = e.Index - } - return appliedt, appliedi, shouldStop -} - -// applyEntryNormal apples an EntryNormal type raftpb request to the EtcdServer -func (s *EtcdServer) applyEntryNormal(e *raftpb.Entry) { - shouldApplyV3 := false - if e.Index > s.consistIndex.ConsistentIndex() { - // set the consistent index of current executing entry - s.consistIndex.setConsistentIndex(e.Index) - shouldApplyV3 = true - } - defer s.setAppliedIndex(e.Index) - - // raft state machine may generate noop entry when leader confirmation. - // skip it in advance to avoid some potential bug in the future - if len(e.Data) == 0 { - select { - case s.forceVersionC <- struct{}{}: - default: - } - // promote lessor when the local member is leader and finished - // applying all entries from the last term. - if s.isLeader() { - s.lessor.Promote(s.Cfg.electionTimeout()) - } - return - } - - var raftReq pb.InternalRaftRequest - if !pbutil.MaybeUnmarshal(&raftReq, e.Data) { // backward compatible - var r pb.Request - rp := &r - pbutil.MustUnmarshal(rp, e.Data) - s.w.Trigger(r.ID, s.applyV2Request((*RequestV2)(rp))) - return - } - if raftReq.V2 != nil { - req := (*RequestV2)(raftReq.V2) - s.w.Trigger(req.ID, s.applyV2Request(req)) - return - } - - // do not re-apply applied entries. - if !shouldApplyV3 { - return - } - - id := raftReq.ID - if id == 0 { - id = raftReq.Header.ID - } - - var ar *applyResult - needResult := s.w.IsRegistered(id) - if needResult || !noSideEffect(&raftReq) { - if !needResult && raftReq.Txn != nil { - removeNeedlessRangeReqs(raftReq.Txn) - } - ar = s.applyV3.Apply(&raftReq) - } - - if ar == nil { - return - } - - if ar.err != ErrNoSpace || len(s.alarmStore.Get(pb.AlarmType_NOSPACE)) > 0 { - s.w.Trigger(id, ar) - return - } - - plog.Errorf("applying raft message exceeded backend quota") - s.goAttach(func() { - a := &pb.AlarmRequest{ - MemberID: uint64(s.ID()), - Action: pb.AlarmRequest_ACTIVATE, - Alarm: pb.AlarmType_NOSPACE, - } - s.raftRequest(s.ctx, pb.InternalRaftRequest{Alarm: a}) - s.w.Trigger(id, ar) - }) -} - -// applyConfChange applies a ConfChange to the server. It is only -// invoked with a ConfChange that has already passed through Raft -func (s *EtcdServer) applyConfChange(cc raftpb.ConfChange, confState *raftpb.ConfState) (bool, error) { - if err := s.cluster.ValidateConfigurationChange(cc); err != nil { - cc.NodeID = raft.None - s.r.ApplyConfChange(cc) - return false, err - } - *confState = *s.r.ApplyConfChange(cc) - switch cc.Type { - case raftpb.ConfChangeAddNode: - m := new(membership.Member) - if err := json.Unmarshal(cc.Context, m); err != nil { - plog.Panicf("unmarshal member should never fail: %v", err) - } - if cc.NodeID != uint64(m.ID) { - plog.Panicf("nodeID should always be equal to member ID") - } - s.cluster.AddMember(m) - if m.ID != s.id { - s.r.transport.AddPeer(m.ID, m.PeerURLs) - } - case raftpb.ConfChangeRemoveNode: - id := types.ID(cc.NodeID) - s.cluster.RemoveMember(id) - if id == s.id { - return true, nil - } - s.r.transport.RemovePeer(id) - case raftpb.ConfChangeUpdateNode: - m := new(membership.Member) - if err := json.Unmarshal(cc.Context, m); err != nil { - plog.Panicf("unmarshal member should never fail: %v", err) - } - if cc.NodeID != uint64(m.ID) { - plog.Panicf("nodeID should always be equal to member ID") - } - s.cluster.UpdateRaftAttributes(m.ID, m.RaftAttributes) - if m.ID != s.id { - s.r.transport.UpdatePeer(m.ID, m.PeerURLs) - } - } - return false, nil -} - -// TODO: non-blocking snapshot -func (s *EtcdServer) snapshot(snapi uint64, confState raftpb.ConfState) { - clone := s.store.Clone() - // commit kv to write metadata (for example: consistent index) to disk. - // KV().commit() updates the consistent index in backend. - // All operations that update consistent index must be called sequentially - // from applyAll function. - // So KV().Commit() cannot run in parallel with apply. It has to be called outside - // the go routine created below. - s.KV().Commit() - - s.goAttach(func() { - d, err := clone.SaveNoCopy() - // TODO: current store will never fail to do a snapshot - // what should we do if the store might fail? - if err != nil { - plog.Panicf("store save should never fail: %v", err) - } - snap, err := s.r.raftStorage.CreateSnapshot(snapi, &confState, d) - if err != nil { - // the snapshot was done asynchronously with the progress of raft. - // raft might have already got a newer snapshot. - if err == raft.ErrSnapOutOfDate { - return - } - plog.Panicf("unexpected create snapshot error %v", err) - } - // SaveSnap saves the snapshot and releases the locked wal files - // to the snapshot index. - if err = s.r.storage.SaveSnap(snap); err != nil { - plog.Fatalf("save snapshot error: %v", err) - } - plog.Infof("saved snapshot at index %d", snap.Metadata.Index) - - // When sending a snapshot, etcd will pause compaction. - // After receives a snapshot, the slow follower needs to get all the entries right after - // the snapshot sent to catch up. If we do not pause compaction, the log entries right after - // the snapshot sent might already be compacted. It happens when the snapshot takes long time - // to send and save. Pausing compaction avoids triggering a snapshot sending cycle. - if atomic.LoadInt64(&s.inflightSnapshots) != 0 { - plog.Infof("skip compaction since there is an inflight snapshot") - return - } - - // keep some in memory log entries for slow followers. - compacti := uint64(1) - if snapi > numberOfCatchUpEntries { - compacti = snapi - numberOfCatchUpEntries - } - err = s.r.raftStorage.Compact(compacti) - if err != nil { - // the compaction was done asynchronously with the progress of raft. - // raft log might already been compact. - if err == raft.ErrCompacted { - return - } - plog.Panicf("unexpected compaction error %v", err) - } - plog.Infof("compacted raft log at %d", compacti) - }) -} - -// CutPeer drops messages to the specified peer. -func (s *EtcdServer) CutPeer(id types.ID) { - tr, ok := s.r.transport.(*rafthttp.Transport) - if ok { - tr.CutPeer(id) - } -} - -// MendPeer recovers the message dropping behavior of the given peer. -func (s *EtcdServer) MendPeer(id types.ID) { - tr, ok := s.r.transport.(*rafthttp.Transport) - if ok { - tr.MendPeer(id) - } -} - -func (s *EtcdServer) PauseSending() { s.r.pauseSending() } - -func (s *EtcdServer) ResumeSending() { s.r.resumeSending() } - -func (s *EtcdServer) ClusterVersion() *semver.Version { - if s.cluster == nil { - return nil - } - return s.cluster.Version() -} - -// monitorVersions checks the member's version every monitorVersionInterval. -// It updates the cluster version if all members agrees on a higher one. -// It prints out log if there is a member with a higher version than the -// local version. -func (s *EtcdServer) monitorVersions() { - for { - select { - case <-s.forceVersionC: - case <-time.After(monitorVersionInterval): - case <-s.stopping: - return - } - - if s.Leader() != s.ID() { - continue - } - - v := decideClusterVersion(getVersions(s.cluster, s.id, s.peerRt)) - if v != nil { - // only keep major.minor version for comparison - v = &semver.Version{ - Major: v.Major, - Minor: v.Minor, - } - } - - // if the current version is nil: - // 1. use the decided version if possible - // 2. or use the min cluster version - if s.cluster.Version() == nil { - verStr := version.MinClusterVersion - if v != nil { - verStr = v.String() - } - s.goAttach(func() { s.updateClusterVersion(verStr) }) - continue - } - - // update cluster version only if the decided version is greater than - // the current cluster version - if v != nil && s.cluster.Version().LessThan(*v) { - s.goAttach(func() { s.updateClusterVersion(v.String()) }) - } - } -} - -func (s *EtcdServer) updateClusterVersion(ver string) { - if s.cluster.Version() == nil { - plog.Infof("setting up the initial cluster version to %s", version.Cluster(ver)) - } else { - plog.Infof("updating the cluster version from %s to %s", version.Cluster(s.cluster.Version().String()), version.Cluster(ver)) - } - req := pb.Request{ - Method: "PUT", - Path: membership.StoreClusterVersionKey(), - Val: ver, - } - ctx, cancel := context.WithTimeout(s.ctx, s.Cfg.ReqTimeout()) - _, err := s.Do(ctx, req) - cancel() - switch err { - case nil: - return - case ErrStopped: - plog.Infof("aborting update cluster version because server is stopped") - return - default: - plog.Errorf("error updating cluster version (%v)", err) - } -} - -func (s *EtcdServer) parseProposeCtxErr(err error, start time.Time) error { - switch err { - case context.Canceled: - return ErrCanceled - case context.DeadlineExceeded: - s.leadTimeMu.RLock() - curLeadElected := s.leadElectedTime - s.leadTimeMu.RUnlock() - prevLeadLost := curLeadElected.Add(-2 * time.Duration(s.Cfg.ElectionTicks) * time.Duration(s.Cfg.TickMs) * time.Millisecond) - if start.After(prevLeadLost) && start.Before(curLeadElected) { - return ErrTimeoutDueToLeaderFail - } - - lead := types.ID(atomic.LoadUint64(&s.r.lead)) - switch lead { - case types.ID(raft.None): - // TODO: return error to specify it happens because the cluster does not have leader now - case s.ID(): - if !isConnectedToQuorumSince(s.r.transport, start, s.ID(), s.cluster.Members()) { - return ErrTimeoutDueToConnectionLost - } - default: - if !isConnectedSince(s.r.transport, start, lead) { - return ErrTimeoutDueToConnectionLost - } - } - - return ErrTimeout - default: - return err - } -} - -func (s *EtcdServer) KV() mvcc.ConsistentWatchableKV { return s.kv } -func (s *EtcdServer) Backend() backend.Backend { - s.bemu.Lock() - defer s.bemu.Unlock() - return s.be -} - -func (s *EtcdServer) AuthStore() auth.AuthStore { return s.authStore } - -func (s *EtcdServer) restoreAlarms() error { - s.applyV3 = s.newApplierV3() - as, err := alarm.NewAlarmStore(s) - if err != nil { - return err - } - s.alarmStore = as - if len(as.Get(pb.AlarmType_NOSPACE)) > 0 { - s.applyV3 = newApplierV3Capped(s.applyV3) - } - if len(as.Get(pb.AlarmType_CORRUPT)) > 0 { - s.applyV3 = newApplierV3Corrupt(s.applyV3) - } - return nil -} - -func (s *EtcdServer) getAppliedIndex() uint64 { - return atomic.LoadUint64(&s.appliedIndex) -} - -func (s *EtcdServer) setAppliedIndex(v uint64) { - atomic.StoreUint64(&s.appliedIndex, v) -} - -func (s *EtcdServer) getCommittedIndex() uint64 { - return atomic.LoadUint64(&s.committedIndex) -} - -func (s *EtcdServer) setCommittedIndex(v uint64) { - atomic.StoreUint64(&s.committedIndex, v) -} - -// goAttach creates a goroutine on a given function and tracks it using -// the etcdserver waitgroup. -func (s *EtcdServer) goAttach(f func()) { - s.wgMu.RLock() // this blocks with ongoing close(s.stopping) - defer s.wgMu.RUnlock() - select { - case <-s.stopping: - plog.Warning("server has stopped (skipping goAttach)") - return - default: - } - - // now safe to add since waitgroup wait has not started yet - s.wg.Add(1) - go func() { - defer s.wg.Done() - f() - }() -} - -func (s *EtcdServer) Alarms() []*pb.AlarmMember { - return s.alarmStore.Get(pb.AlarmType_NONE) -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/snapshot_merge.go b/vendor/go.etcd.io/etcd/etcdserver/snapshot_merge.go deleted file mode 100644 index 928aa95b6b16..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/snapshot_merge.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "io" - - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/snap" -) - -// createMergedSnapshotMessage creates a snapshot message that contains: raft status (term, conf), -// a snapshot of v2 store inside raft.Snapshot as []byte, a snapshot of v3 KV in the top level message -// as ReadCloser. -func (s *EtcdServer) createMergedSnapshotMessage(m raftpb.Message, snapt, snapi uint64, confState raftpb.ConfState) snap.Message { - // get a snapshot of v2 store as []byte - clone := s.store.Clone() - d, err := clone.SaveNoCopy() - if err != nil { - plog.Panicf("store save should never fail: %v", err) - } - - // commit kv to write metadata(for example: consistent index). - s.KV().Commit() - dbsnap := s.be.Snapshot() - // get a snapshot of v3 KV as readCloser - rc := newSnapshotReaderCloser(dbsnap) - - // put the []byte snapshot of store into raft snapshot and return the merged snapshot with - // KV readCloser snapshot. - snapshot := raftpb.Snapshot{ - Metadata: raftpb.SnapshotMetadata{ - Index: snapi, - Term: snapt, - ConfState: confState, - }, - Data: d, - } - m.Snapshot = snapshot - - return *snap.NewMessage(m, rc, dbsnap.Size()) -} - -func newSnapshotReaderCloser(snapshot backend.Snapshot) io.ReadCloser { - pr, pw := io.Pipe() - go func() { - n, err := snapshot.WriteTo(pw) - if err == nil { - plog.Infof("wrote database snapshot out [total bytes: %d]", n) - } else { - plog.Warningf("failed to write database snapshot out [written bytes: %d]: %v", n, err) - } - pw.CloseWithError(err) - err = snapshot.Close() - if err != nil { - plog.Panicf("failed to close database snapshot: %v", err) - } - }() - return pr -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/storage.go b/vendor/go.etcd.io/etcd/etcdserver/storage.go deleted file mode 100644 index 55c2dd4b6a41..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/storage.go +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "io" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/snap" - "github.com/coreos/etcd/wal" - "github.com/coreos/etcd/wal/walpb" -) - -type Storage interface { - // Save function saves ents and state to the underlying stable storage. - // Save MUST block until st and ents are on stable storage. - Save(st raftpb.HardState, ents []raftpb.Entry) error - // SaveSnap function saves snapshot to the underlying stable storage. - SaveSnap(snap raftpb.Snapshot) error - // Close closes the Storage and performs finalization. - Close() error -} - -type storage struct { - *wal.WAL - *snap.Snapshotter -} - -func NewStorage(w *wal.WAL, s *snap.Snapshotter) Storage { - return &storage{w, s} -} - -// SaveSnap saves the snapshot to disk and release the locked -// wal files since they will not be used. -func (st *storage) SaveSnap(snap raftpb.Snapshot) error { - walsnap := walpb.Snapshot{ - Index: snap.Metadata.Index, - Term: snap.Metadata.Term, - } - err := st.WAL.SaveSnapshot(walsnap) - if err != nil { - return err - } - err = st.Snapshotter.SaveSnap(snap) - if err != nil { - return err - } - return st.WAL.ReleaseLockTo(snap.Metadata.Index) -} - -func readWAL(waldir string, snap walpb.Snapshot) (w *wal.WAL, id, cid types.ID, st raftpb.HardState, ents []raftpb.Entry) { - var ( - err error - wmetadata []byte - ) - - repaired := false - for { - if w, err = wal.Open(waldir, snap); err != nil { - plog.Fatalf("open wal error: %v", err) - } - if wmetadata, st, ents, err = w.ReadAll(); err != nil { - w.Close() - // we can only repair ErrUnexpectedEOF and we never repair twice. - if repaired || err != io.ErrUnexpectedEOF { - plog.Fatalf("read wal error (%v) and cannot be repaired", err) - } - if !wal.Repair(waldir) { - plog.Fatalf("WAL error (%v) cannot be repaired", err) - } else { - plog.Infof("repaired WAL error (%v)", err) - repaired = true - } - continue - } - break - } - var metadata pb.Metadata - pbutil.MustUnmarshal(&metadata, wmetadata) - id = types.ID(metadata.NodeID) - cid = types.ID(metadata.ClusterID) - return w, id, cid, st, ents -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/util.go b/vendor/go.etcd.io/etcd/etcdserver/util.go deleted file mode 100644 index 79bb6b859ca8..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/util.go +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "fmt" - "reflect" - "strings" - "time" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/rafthttp" - "github.com/golang/protobuf/proto" -) - -// isConnectedToQuorumSince checks whether the local member is connected to the -// quorum of the cluster since the given time. -func isConnectedToQuorumSince(transport rafthttp.Transporter, since time.Time, self types.ID, members []*membership.Member) bool { - return numConnectedSince(transport, since, self, members) >= (len(members)/2)+1 -} - -// isConnectedSince checks whether the local member is connected to the -// remote member since the given time. -func isConnectedSince(transport rafthttp.Transporter, since time.Time, remote types.ID) bool { - t := transport.ActiveSince(remote) - return !t.IsZero() && t.Before(since) -} - -// isConnectedFullySince checks whether the local member is connected to all -// members in the cluster since the given time. -func isConnectedFullySince(transport rafthttp.Transporter, since time.Time, self types.ID, members []*membership.Member) bool { - return numConnectedSince(transport, since, self, members) == len(members) -} - -// numConnectedSince counts how many members are connected to the local member -// since the given time. -func numConnectedSince(transport rafthttp.Transporter, since time.Time, self types.ID, members []*membership.Member) int { - connectedNum := 0 - for _, m := range members { - if m.ID == self || isConnectedSince(transport, since, m.ID) { - connectedNum++ - } - } - return connectedNum -} - -// longestConnected chooses the member with longest active-since-time. -// It returns false, if nothing is active. -func longestConnected(tp rafthttp.Transporter, membs []types.ID) (types.ID, bool) { - var longest types.ID - var oldest time.Time - for _, id := range membs { - tm := tp.ActiveSince(id) - if tm.IsZero() { // inactive - continue - } - - if oldest.IsZero() { // first longest candidate - oldest = tm - longest = id - } - - if tm.Before(oldest) { - oldest = tm - longest = id - } - } - if uint64(longest) == 0 { - return longest, false - } - return longest, true -} - -type notifier struct { - c chan struct{} - err error -} - -func newNotifier() *notifier { - return ¬ifier{ - c: make(chan struct{}), - } -} - -func (nc *notifier) notify(err error) { - nc.err = err - close(nc.c) -} - -func warnOfExpensiveRequest(now time.Time, reqStringer fmt.Stringer, respMsg proto.Message, err error) { - var resp string - if !isNil(respMsg) { - resp = fmt.Sprintf("size:%d", proto.Size(respMsg)) - } - warnOfExpensiveGenericRequest(now, reqStringer, "", resp, err) -} - -func warnOfExpensiveReadOnlyTxnRequest(now time.Time, r *pb.TxnRequest, txnResponse *pb.TxnResponse, err error) { - reqStringer := pb.NewLoggableTxnRequest(r) - var resp string - if !isNil(txnResponse) { - var resps []string - for _, r := range txnResponse.Responses { - switch op := r.Response.(type) { - case *pb.ResponseOp_ResponseRange: - resps = append(resps, fmt.Sprintf("range_response_count:%d", len(op.ResponseRange.Kvs))) - default: - // only range responses should be in a read only txn request - } - } - resp = fmt.Sprintf("responses:<%s> size:%d", strings.Join(resps, " "), proto.Size(txnResponse)) - } - warnOfExpensiveGenericRequest(now, reqStringer, "read-only range ", resp, err) -} - -func warnOfExpensiveReadOnlyRangeRequest(now time.Time, reqStringer fmt.Stringer, rangeResponse *pb.RangeResponse, err error) { - var resp string - if !isNil(rangeResponse) { - resp = fmt.Sprintf("range_response_count:%d size:%d", len(rangeResponse.Kvs), proto.Size(rangeResponse)) - } - warnOfExpensiveGenericRequest(now, reqStringer, "read-only range ", resp, err) -} - -func warnOfExpensiveGenericRequest(now time.Time, reqStringer fmt.Stringer, prefix string, resp string, err error) { - // TODO: add metrics - d := time.Since(now) - if d > warnApplyDuration { - var result string - if err != nil { - result = fmt.Sprintf("error:%v", err) - } else { - result = resp - } - plog.Warningf("%srequest %q with result %q took too long (%v) to execute", prefix, reqStringer.String(), result, d) - slowApplies.Inc() - } -} - -func isNil(msg proto.Message) bool { - return msg == nil || reflect.ValueOf(msg).IsNil() -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/v2_server.go b/vendor/go.etcd.io/etcd/etcdserver/v2_server.go deleted file mode 100644 index b458350c10bf..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/v2_server.go +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "context" - "time" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/store" -) - -type RequestV2 pb.Request - -type RequestV2Handler interface { - Post(ctx context.Context, r *RequestV2) (Response, error) - Put(ctx context.Context, r *RequestV2) (Response, error) - Delete(ctx context.Context, r *RequestV2) (Response, error) - QGet(ctx context.Context, r *RequestV2) (Response, error) - Get(ctx context.Context, r *RequestV2) (Response, error) - Head(ctx context.Context, r *RequestV2) (Response, error) -} - -type reqV2HandlerEtcdServer struct { - reqV2HandlerStore - s *EtcdServer -} - -type reqV2HandlerStore struct { - store store.Store - applier ApplierV2 -} - -func NewStoreRequestV2Handler(s store.Store, applier ApplierV2) RequestV2Handler { - return &reqV2HandlerStore{s, applier} -} - -func (a *reqV2HandlerStore) Post(ctx context.Context, r *RequestV2) (Response, error) { - return a.applier.Post(r), nil -} - -func (a *reqV2HandlerStore) Put(ctx context.Context, r *RequestV2) (Response, error) { - return a.applier.Put(r), nil -} - -func (a *reqV2HandlerStore) Delete(ctx context.Context, r *RequestV2) (Response, error) { - return a.applier.Delete(r), nil -} - -func (a *reqV2HandlerStore) QGet(ctx context.Context, r *RequestV2) (Response, error) { - return a.applier.QGet(r), nil -} - -func (a *reqV2HandlerStore) Get(ctx context.Context, r *RequestV2) (Response, error) { - if r.Wait { - wc, err := a.store.Watch(r.Path, r.Recursive, r.Stream, r.Since) - return Response{Watcher: wc}, err - } - ev, err := a.store.Get(r.Path, r.Recursive, r.Sorted) - return Response{Event: ev}, err -} - -func (a *reqV2HandlerStore) Head(ctx context.Context, r *RequestV2) (Response, error) { - ev, err := a.store.Get(r.Path, r.Recursive, r.Sorted) - return Response{Event: ev}, err -} - -func (a *reqV2HandlerEtcdServer) Post(ctx context.Context, r *RequestV2) (Response, error) { - return a.processRaftRequest(ctx, r) -} - -func (a *reqV2HandlerEtcdServer) Put(ctx context.Context, r *RequestV2) (Response, error) { - return a.processRaftRequest(ctx, r) -} - -func (a *reqV2HandlerEtcdServer) Delete(ctx context.Context, r *RequestV2) (Response, error) { - return a.processRaftRequest(ctx, r) -} - -func (a *reqV2HandlerEtcdServer) QGet(ctx context.Context, r *RequestV2) (Response, error) { - return a.processRaftRequest(ctx, r) -} - -func (a *reqV2HandlerEtcdServer) processRaftRequest(ctx context.Context, r *RequestV2) (Response, error) { - data, err := ((*pb.Request)(r)).Marshal() - if err != nil { - return Response{}, err - } - ch := a.s.w.Register(r.ID) - - start := time.Now() - a.s.r.Propose(ctx, data) - proposalsPending.Inc() - defer proposalsPending.Dec() - - select { - case x := <-ch: - resp := x.(Response) - return resp, resp.Err - case <-ctx.Done(): - proposalsFailed.Inc() - a.s.w.Trigger(r.ID, nil) // GC wait - return Response{}, a.s.parseProposeCtxErr(ctx.Err(), start) - case <-a.s.stopping: - } - return Response{}, ErrStopped -} - -func (s *EtcdServer) Do(ctx context.Context, r pb.Request) (Response, error) { - r.ID = s.reqIDGen.Next() - h := &reqV2HandlerEtcdServer{ - reqV2HandlerStore: reqV2HandlerStore{ - store: s.store, - applier: s.applyV2, - }, - s: s, - } - rp := &r - resp, err := ((*RequestV2)(rp)).Handle(ctx, h) - resp.Term, resp.Index = s.Term(), s.Index() - return resp, err -} - -// Handle interprets r and performs an operation on s.store according to r.Method -// and other fields. If r.Method is "POST", "PUT", "DELETE", or a "GET" with -// Quorum == true, r will be sent through consensus before performing its -// respective operation. Do will block until an action is performed or there is -// an error. -func (r *RequestV2) Handle(ctx context.Context, v2api RequestV2Handler) (Response, error) { - if r.Method == "GET" && r.Quorum { - r.Method = "QGET" - } - switch r.Method { - case "POST": - return v2api.Post(ctx, r) - case "PUT": - return v2api.Put(ctx, r) - case "DELETE": - return v2api.Delete(ctx, r) - case "QGET": - return v2api.QGet(ctx, r) - case "GET": - return v2api.Get(ctx, r) - case "HEAD": - return v2api.Head(ctx, r) - } - return Response{}, ErrUnknownMethod -} - -func (r *RequestV2) String() string { - rpb := pb.Request(*r) - return rpb.String() -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/v3_server.go b/vendor/go.etcd.io/etcd/etcdserver/v3_server.go deleted file mode 100644 index f214a1926bb9..000000000000 --- a/vendor/go.etcd.io/etcd/etcdserver/v3_server.go +++ /dev/null @@ -1,720 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "bytes" - "context" - "encoding/binary" - "time" - - "github.com/coreos/etcd/auth" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/etcdserver/membership" - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/lease/leasehttp" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/raft" - - "github.com/gogo/protobuf/proto" -) - -const ( - // In the health case, there might be a small gap (10s of entries) between - // the applied index and committed index. - // However, if the committed entries are very heavy to apply, the gap might grow. - // We should stop accepting new proposals if the gap growing to a certain point. - maxGapBetweenApplyAndCommitIndex = 5000 -) - -type RaftKV interface { - Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, error) - Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error) - DeleteRange(ctx context.Context, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) - Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error) - Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error) -} - -type Lessor interface { - // LeaseGrant sends LeaseGrant request to raft and apply it after committed. - LeaseGrant(ctx context.Context, r *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) - // LeaseRevoke sends LeaseRevoke request to raft and apply it after committed. - LeaseRevoke(ctx context.Context, r *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) - - // LeaseRenew renews the lease with given ID. The renewed TTL is returned. Or an error - // is returned. - LeaseRenew(ctx context.Context, id lease.LeaseID) (int64, error) - - // LeaseTimeToLive retrieves lease information. - LeaseTimeToLive(ctx context.Context, r *pb.LeaseTimeToLiveRequest) (*pb.LeaseTimeToLiveResponse, error) - - // LeaseLeases lists all leases. - LeaseLeases(ctx context.Context, r *pb.LeaseLeasesRequest) (*pb.LeaseLeasesResponse, error) -} - -type Authenticator interface { - AuthEnable(ctx context.Context, r *pb.AuthEnableRequest) (*pb.AuthEnableResponse, error) - AuthDisable(ctx context.Context, r *pb.AuthDisableRequest) (*pb.AuthDisableResponse, error) - Authenticate(ctx context.Context, r *pb.AuthenticateRequest) (*pb.AuthenticateResponse, error) - UserAdd(ctx context.Context, r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) - UserDelete(ctx context.Context, r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) - UserChangePassword(ctx context.Context, r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) - UserGrantRole(ctx context.Context, r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) - UserGet(ctx context.Context, r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) - UserRevokeRole(ctx context.Context, r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) - RoleAdd(ctx context.Context, r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) - RoleGrantPermission(ctx context.Context, r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) - RoleGet(ctx context.Context, r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) - RoleRevokePermission(ctx context.Context, r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) - RoleDelete(ctx context.Context, r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) - UserList(ctx context.Context, r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) - RoleList(ctx context.Context, r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) -} - -func (s *EtcdServer) Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, error) { - var resp *pb.RangeResponse - var err error - defer func(start time.Time) { - warnOfExpensiveReadOnlyRangeRequest(start, r, resp, err) - }(time.Now()) - - if !r.Serializable { - err = s.linearizableReadNotify(ctx) - if err != nil { - return nil, err - } - } - chk := func(ai *auth.AuthInfo) error { - return s.authStore.IsRangePermitted(ai, r.Key, r.RangeEnd) - } - - get := func() { resp, err = s.applyV3Base.Range(nil, r) } - if serr := s.doSerialize(ctx, chk, get); serr != nil { - err = serr - return nil, err - } - return resp, err -} - -func (s *EtcdServer) Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{Put: r}) - if err != nil { - return nil, err - } - return resp.(*pb.PutResponse), nil -} - -func (s *EtcdServer) DeleteRange(ctx context.Context, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{DeleteRange: r}) - if err != nil { - return nil, err - } - return resp.(*pb.DeleteRangeResponse), nil -} - -func (s *EtcdServer) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error) { - if isTxnReadonly(r) { - if !isTxnSerializable(r) { - err := s.linearizableReadNotify(ctx) - if err != nil { - return nil, err - } - } - var resp *pb.TxnResponse - var err error - chk := func(ai *auth.AuthInfo) error { - return checkTxnAuth(s.authStore, ai, r) - } - - defer func(start time.Time) { - warnOfExpensiveReadOnlyTxnRequest(start, r, resp, err) - }(time.Now()) - - get := func() { resp, err = s.applyV3Base.Txn(r) } - if serr := s.doSerialize(ctx, chk, get); serr != nil { - return nil, serr - } - return resp, err - } - - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{Txn: r}) - if err != nil { - return nil, err - } - return resp.(*pb.TxnResponse), nil -} - -func isTxnSerializable(r *pb.TxnRequest) bool { - for _, u := range r.Success { - if r := u.GetRequestRange(); r == nil || !r.Serializable { - return false - } - } - for _, u := range r.Failure { - if r := u.GetRequestRange(); r == nil || !r.Serializable { - return false - } - } - return true -} - -func isTxnReadonly(r *pb.TxnRequest) bool { - for _, u := range r.Success { - if r := u.GetRequestRange(); r == nil { - return false - } - } - for _, u := range r.Failure { - if r := u.GetRequestRange(); r == nil { - return false - } - } - return true -} - -func (s *EtcdServer) Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error) { - result, err := s.processInternalRaftRequestOnce(ctx, pb.InternalRaftRequest{Compaction: r}) - if r.Physical && result != nil && result.physc != nil { - <-result.physc - // The compaction is done deleting keys; the hash is now settled - // but the data is not necessarily committed. If there's a crash, - // the hash may revert to a hash prior to compaction completing - // if the compaction resumes. Force the finished compaction to - // commit so it won't resume following a crash. - s.be.ForceCommit() - } - if err != nil { - return nil, err - } - if result.err != nil { - return nil, result.err - } - resp := result.resp.(*pb.CompactionResponse) - if resp == nil { - resp = &pb.CompactionResponse{} - } - if resp.Header == nil { - resp.Header = &pb.ResponseHeader{} - } - resp.Header.Revision = s.kv.Rev() - return resp, nil -} - -func (s *EtcdServer) LeaseGrant(ctx context.Context, r *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - // no id given? choose one - for r.ID == int64(lease.NoLease) { - // only use positive int64 id's - r.ID = int64(s.reqIDGen.Next() & ((1 << 63) - 1)) - } - resp, err := s.raftRequestOnce(ctx, pb.InternalRaftRequest{LeaseGrant: r}) - if err != nil { - return nil, err - } - return resp.(*pb.LeaseGrantResponse), nil -} - -func (s *EtcdServer) LeaseRevoke(ctx context.Context, r *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) { - resp, err := s.raftRequestOnce(ctx, pb.InternalRaftRequest{LeaseRevoke: r}) - if err != nil { - return nil, err - } - return resp.(*pb.LeaseRevokeResponse), nil -} - -func (s *EtcdServer) LeaseRenew(ctx context.Context, id lease.LeaseID) (int64, error) { - ttl, err := s.lessor.Renew(id) - if err == nil { // already requested to primary lessor(leader) - return ttl, nil - } - if err != lease.ErrNotPrimary { - return -1, err - } - - cctx, cancel := context.WithTimeout(ctx, s.Cfg.ReqTimeout()) - defer cancel() - - // renewals don't go through raft; forward to leader manually - for cctx.Err() == nil && err != nil { - leader, lerr := s.waitLeader(cctx) - if lerr != nil { - return -1, lerr - } - for _, url := range leader.PeerURLs { - lurl := url + leasehttp.LeasePrefix - ttl, err = leasehttp.RenewHTTP(cctx, id, lurl, s.peerRt) - if err == nil || err == lease.ErrLeaseNotFound { - return ttl, err - } - } - } - return -1, ErrTimeout -} - -func (s *EtcdServer) LeaseTimeToLive(ctx context.Context, r *pb.LeaseTimeToLiveRequest) (*pb.LeaseTimeToLiveResponse, error) { - if s.Leader() == s.ID() { - // primary; timetolive directly from leader - le := s.lessor.Lookup(lease.LeaseID(r.ID)) - if le == nil { - return nil, lease.ErrLeaseNotFound - } - // TODO: fill out ResponseHeader - resp := &pb.LeaseTimeToLiveResponse{Header: &pb.ResponseHeader{}, ID: r.ID, TTL: int64(le.Remaining().Seconds()), GrantedTTL: le.TTL()} - if r.Keys { - ks := le.Keys() - kbs := make([][]byte, len(ks)) - for i := range ks { - kbs[i] = []byte(ks[i]) - } - resp.Keys = kbs - } - return resp, nil - } - - cctx, cancel := context.WithTimeout(ctx, s.Cfg.ReqTimeout()) - defer cancel() - - // forward to leader - for cctx.Err() == nil { - leader, err := s.waitLeader(cctx) - if err != nil { - return nil, err - } - for _, url := range leader.PeerURLs { - lurl := url + leasehttp.LeaseInternalPrefix - resp, err := leasehttp.TimeToLiveHTTP(cctx, lease.LeaseID(r.ID), r.Keys, lurl, s.peerRt) - if err == nil { - return resp.LeaseTimeToLiveResponse, nil - } - if err == lease.ErrLeaseNotFound { - return nil, err - } - } - } - return nil, ErrTimeout -} - -func (s *EtcdServer) LeaseLeases(ctx context.Context, r *pb.LeaseLeasesRequest) (*pb.LeaseLeasesResponse, error) { - ls := s.lessor.Leases() - lss := make([]*pb.LeaseStatus, len(ls)) - for i := range ls { - lss[i] = &pb.LeaseStatus{ID: int64(ls[i].ID)} - } - return &pb.LeaseLeasesResponse{Header: newHeader(s), Leases: lss}, nil -} - -func (s *EtcdServer) waitLeader(ctx context.Context) (*membership.Member, error) { - leader := s.cluster.Member(s.Leader()) - for leader == nil { - // wait an election - dur := time.Duration(s.Cfg.ElectionTicks) * time.Duration(s.Cfg.TickMs) * time.Millisecond - select { - case <-time.After(dur): - leader = s.cluster.Member(s.Leader()) - case <-s.stopping: - return nil, ErrStopped - case <-ctx.Done(): - return nil, ErrNoLeader - } - } - if leader == nil || len(leader.PeerURLs) == 0 { - return nil, ErrNoLeader - } - return leader, nil -} - -func (s *EtcdServer) Alarm(ctx context.Context, r *pb.AlarmRequest) (*pb.AlarmResponse, error) { - resp, err := s.raftRequestOnce(ctx, pb.InternalRaftRequest{Alarm: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AlarmResponse), nil -} - -func (s *EtcdServer) AuthEnable(ctx context.Context, r *pb.AuthEnableRequest) (*pb.AuthEnableResponse, error) { - resp, err := s.raftRequestOnce(ctx, pb.InternalRaftRequest{AuthEnable: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthEnableResponse), nil -} - -func (s *EtcdServer) AuthDisable(ctx context.Context, r *pb.AuthDisableRequest) (*pb.AuthDisableResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthDisable: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthDisableResponse), nil -} - -func (s *EtcdServer) Authenticate(ctx context.Context, r *pb.AuthenticateRequest) (*pb.AuthenticateResponse, error) { - if err := s.linearizableReadNotify(ctx); err != nil { - return nil, err - } - - var resp proto.Message - for { - checkedRevision, err := s.AuthStore().CheckPassword(r.Name, r.Password) - if err != nil { - if err != auth.ErrAuthNotEnabled { - plog.Errorf("invalid authentication request to user %s was issued", r.Name) - } - return nil, err - } - - st, err := s.AuthStore().GenTokenPrefix() - if err != nil { - return nil, err - } - - internalReq := &pb.InternalAuthenticateRequest{ - Name: r.Name, - Password: r.Password, - SimpleToken: st, - } - - resp, err = s.raftRequestOnce(ctx, pb.InternalRaftRequest{Authenticate: internalReq}) - if err != nil { - return nil, err - } - if checkedRevision == s.AuthStore().Revision() { - break - } - plog.Infof("revision when password checked is obsolete, retrying") - } - - return resp.(*pb.AuthenticateResponse), nil -} - -func (s *EtcdServer) UserAdd(ctx context.Context, r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserAdd: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserAddResponse), nil -} - -func (s *EtcdServer) UserDelete(ctx context.Context, r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserDelete: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserDeleteResponse), nil -} - -func (s *EtcdServer) UserChangePassword(ctx context.Context, r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserChangePassword: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserChangePasswordResponse), nil -} - -func (s *EtcdServer) UserGrantRole(ctx context.Context, r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserGrantRole: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserGrantRoleResponse), nil -} - -func (s *EtcdServer) UserGet(ctx context.Context, r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserGet: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserGetResponse), nil -} - -func (s *EtcdServer) UserList(ctx context.Context, r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserList: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserListResponse), nil -} - -func (s *EtcdServer) UserRevokeRole(ctx context.Context, r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserRevokeRole: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserRevokeRoleResponse), nil -} - -func (s *EtcdServer) RoleAdd(ctx context.Context, r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthRoleAdd: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthRoleAddResponse), nil -} - -func (s *EtcdServer) RoleGrantPermission(ctx context.Context, r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthRoleGrantPermission: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthRoleGrantPermissionResponse), nil -} - -func (s *EtcdServer) RoleGet(ctx context.Context, r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthRoleGet: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthRoleGetResponse), nil -} - -func (s *EtcdServer) RoleList(ctx context.Context, r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthRoleList: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthRoleListResponse), nil -} - -func (s *EtcdServer) RoleRevokePermission(ctx context.Context, r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthRoleRevokePermission: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthRoleRevokePermissionResponse), nil -} - -func (s *EtcdServer) RoleDelete(ctx context.Context, r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthRoleDelete: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthRoleDeleteResponse), nil -} - -func (s *EtcdServer) raftRequestOnce(ctx context.Context, r pb.InternalRaftRequest) (proto.Message, error) { - result, err := s.processInternalRaftRequestOnce(ctx, r) - if err != nil { - return nil, err - } - if result.err != nil { - return nil, result.err - } - return result.resp, nil -} - -func (s *EtcdServer) raftRequest(ctx context.Context, r pb.InternalRaftRequest) (proto.Message, error) { - for { - resp, err := s.raftRequestOnce(ctx, r) - if err != auth.ErrAuthOldRevision { - return resp, err - } - } -} - -// doSerialize handles the auth logic, with permissions checked by "chk", for a serialized request "get". Returns a non-nil error on authentication failure. -func (s *EtcdServer) doSerialize(ctx context.Context, chk func(*auth.AuthInfo) error, get func()) error { - for { - ai, err := s.AuthInfoFromCtx(ctx) - if err != nil { - return err - } - if ai == nil { - // chk expects non-nil AuthInfo; use empty credentials - ai = &auth.AuthInfo{} - } - if err = chk(ai); err != nil { - if err == auth.ErrAuthOldRevision { - continue - } - return err - } - // fetch response for serialized request - get() - // empty credentials or current auth info means no need to retry - if ai.Revision == 0 || ai.Revision == s.authStore.Revision() { - return nil - } - // avoid TOCTOU error, retry of the request is required. - } -} - -func (s *EtcdServer) processInternalRaftRequestOnce(ctx context.Context, r pb.InternalRaftRequest) (*applyResult, error) { - ai := s.getAppliedIndex() - ci := s.getCommittedIndex() - if ci > ai+maxGapBetweenApplyAndCommitIndex { - return nil, ErrTooManyRequests - } - - r.Header = &pb.RequestHeader{ - ID: s.reqIDGen.Next(), - } - - authInfo, err := s.AuthInfoFromCtx(ctx) - if err != nil { - return nil, err - } - if authInfo != nil { - r.Header.Username = authInfo.Username - r.Header.AuthRevision = authInfo.Revision - } - - data, err := r.Marshal() - if err != nil { - return nil, err - } - - if len(data) > int(s.Cfg.MaxRequestBytes) { - return nil, ErrRequestTooLarge - } - - id := r.ID - if id == 0 { - id = r.Header.ID - } - ch := s.w.Register(id) - - cctx, cancel := context.WithTimeout(ctx, s.Cfg.ReqTimeout()) - defer cancel() - - start := time.Now() - s.r.Propose(cctx, data) - proposalsPending.Inc() - defer proposalsPending.Dec() - - select { - case x := <-ch: - return x.(*applyResult), nil - case <-cctx.Done(): - proposalsFailed.Inc() - s.w.Trigger(id, nil) // GC wait - return nil, s.parseProposeCtxErr(cctx.Err(), start) - case <-s.done: - return nil, ErrStopped - } -} - -// Watchable returns a watchable interface attached to the etcdserver. -func (s *EtcdServer) Watchable() mvcc.WatchableKV { return s.KV() } - -func (s *EtcdServer) linearizableReadLoop() { - var rs raft.ReadState - - for { - ctxToSend := make([]byte, 8) - id1 := s.reqIDGen.Next() - binary.BigEndian.PutUint64(ctxToSend, id1) - - select { - case <-s.readwaitc: - case <-s.stopping: - return - } - - nextnr := newNotifier() - - s.readMu.Lock() - nr := s.readNotifier - s.readNotifier = nextnr - s.readMu.Unlock() - - cctx, cancel := context.WithTimeout(context.Background(), s.Cfg.ReqTimeout()) - if err := s.r.ReadIndex(cctx, ctxToSend); err != nil { - cancel() - if err == raft.ErrStopped { - return - } - plog.Errorf("failed to get read index from raft: %v", err) - readIndexFailed.Inc() - nr.notify(err) - continue - } - cancel() - - var ( - timeout bool - done bool - ) - for !timeout && !done { - select { - case rs = <-s.r.readStateC: - done = bytes.Equal(rs.RequestCtx, ctxToSend) - if !done { - // a previous request might time out. now we should ignore the response of it and - // continue waiting for the response of the current requests. - id2 := uint64(0) - if len(rs.RequestCtx) == 8 { - id2 = binary.BigEndian.Uint64(rs.RequestCtx) - } - plog.Warningf("ignored out-of-date read index response; local node read indexes queueing up and waiting to be in sync with leader (request ID want %d, got %d)", id1, id2) - slowReadIndex.Inc() - } - - case <-time.After(s.Cfg.ReqTimeout()): - plog.Warningf("timed out waiting for read index response (local node might have slow network)") - nr.notify(ErrTimeout) - timeout = true - slowReadIndex.Inc() - - case <-s.stopping: - return - } - } - if !done { - continue - } - - if ai := s.getAppliedIndex(); ai < rs.Index { - select { - case <-s.applyWait.Wait(rs.Index): - case <-s.stopping: - return - } - } - // unblock all l-reads requested at indices before rs.Index - nr.notify(nil) - } -} - -func (s *EtcdServer) linearizableReadNotify(ctx context.Context) error { - s.readMu.RLock() - nc := s.readNotifier - s.readMu.RUnlock() - - // signal linearizable loop for current notify if it hasn't been already - select { - case s.readwaitc <- struct{}{}: - default: - } - - // wait for read state notification - select { - case <-nc.c: - return nc.err - case <-ctx.Done(): - return ctx.Err() - case <-s.done: - return ErrStopped - } -} - -func (s *EtcdServer) AuthInfoFromCtx(ctx context.Context) (*auth.AuthInfo, error) { - authInfo, err := s.AuthStore().AuthInfoFromCtx(ctx) - if authInfo != nil || err != nil { - return authInfo, err - } - if !s.Cfg.ClientCertAuthEnabled { - return nil, nil - } - authInfo = s.AuthStore().AuthInfoFromTLS(ctx) - return authInfo, nil -} diff --git a/vendor/go.etcd.io/etcd/functional/agent/doc.go b/vendor/go.etcd.io/etcd/functional/agent/doc.go deleted file mode 100644 index 0195c4c74040..000000000000 --- a/vendor/go.etcd.io/etcd/functional/agent/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package agent implements functional-tester agent server. -package agent diff --git a/vendor/go.etcd.io/etcd/functional/agent/handler.go b/vendor/go.etcd.io/etcd/functional/agent/handler.go deleted file mode 100644 index 7cd8e6cec35f..000000000000 --- a/vendor/go.etcd.io/etcd/functional/agent/handler.go +++ /dev/null @@ -1,698 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package agent - -import ( - "errors" - "fmt" - "io/ioutil" - "net/url" - "os" - "os/exec" - "path/filepath" - "syscall" - "time" - - "github.com/coreos/etcd/functional/rpcpb" - "github.com/coreos/etcd/pkg/fileutil" - "github.com/coreos/etcd/pkg/proxy" - - "go.uber.org/zap" -) - -// return error for system errors (e.g. fail to create files) -// return status error in response for wrong configuration/operation (e.g. start etcd twice) -func (srv *Server) handleTesterRequest(req *rpcpb.Request) (resp *rpcpb.Response, err error) { - defer func() { - if err == nil && req != nil { - srv.last = req.Operation - srv.lg.Info("handler success", zap.String("operation", req.Operation.String())) - } - }() - if req != nil { - srv.Member = req.Member - srv.Tester = req.Tester - } - - switch req.Operation { - case rpcpb.Operation_INITIAL_START_ETCD: - return srv.handle_INITIAL_START_ETCD(req) - case rpcpb.Operation_RESTART_ETCD: - return srv.handle_RESTART_ETCD() - - case rpcpb.Operation_SIGTERM_ETCD: - return srv.handle_SIGTERM_ETCD() - case rpcpb.Operation_SIGQUIT_ETCD_AND_REMOVE_DATA: - return srv.handle_SIGQUIT_ETCD_AND_REMOVE_DATA() - - case rpcpb.Operation_SAVE_SNAPSHOT: - return srv.handle_SAVE_SNAPSHOT() - case rpcpb.Operation_RESTORE_RESTART_FROM_SNAPSHOT: - return srv.handle_RESTORE_RESTART_FROM_SNAPSHOT() - case rpcpb.Operation_RESTART_FROM_SNAPSHOT: - return srv.handle_RESTART_FROM_SNAPSHOT() - - case rpcpb.Operation_SIGQUIT_ETCD_AND_ARCHIVE_DATA: - return srv.handle_SIGQUIT_ETCD_AND_ARCHIVE_DATA() - case rpcpb.Operation_SIGQUIT_ETCD_AND_REMOVE_DATA_AND_STOP_AGENT: - return srv.handle_SIGQUIT_ETCD_AND_REMOVE_DATA_AND_STOP_AGENT() - - case rpcpb.Operation_BLACKHOLE_PEER_PORT_TX_RX: - return srv.handle_BLACKHOLE_PEER_PORT_TX_RX() - case rpcpb.Operation_UNBLACKHOLE_PEER_PORT_TX_RX: - return srv.handle_UNBLACKHOLE_PEER_PORT_TX_RX() - case rpcpb.Operation_DELAY_PEER_PORT_TX_RX: - return srv.handle_DELAY_PEER_PORT_TX_RX() - case rpcpb.Operation_UNDELAY_PEER_PORT_TX_RX: - return srv.handle_UNDELAY_PEER_PORT_TX_RX() - - default: - msg := fmt.Sprintf("operation not found (%v)", req.Operation) - return &rpcpb.Response{Success: false, Status: msg}, errors.New(msg) - } -} - -func (srv *Server) handle_INITIAL_START_ETCD(req *rpcpb.Request) (*rpcpb.Response, error) { - if srv.last != rpcpb.Operation_NOT_STARTED { - return &rpcpb.Response{ - Success: false, - Status: fmt.Sprintf("%q is not valid; last server operation was %q", rpcpb.Operation_INITIAL_START_ETCD.String(), srv.last.String()), - Member: req.Member, - }, nil - } - - err := fileutil.TouchDirAll(srv.Member.BaseDir) - if err != nil { - return nil, err - } - srv.lg.Info("created base directory", zap.String("path", srv.Member.BaseDir)) - - if err = srv.createEtcdLogFile(); err != nil { - return nil, err - } - - srv.creatEtcdCmd(false) - - if err = srv.saveTLSAssets(); err != nil { - return nil, err - } - if err = srv.startEtcdCmd(); err != nil { - return nil, err - } - srv.lg.Info("started etcd", zap.String("command-path", srv.etcdCmd.Path)) - if err = srv.loadAutoTLSAssets(); err != nil { - return nil, err - } - - // wait some time for etcd listener start - // before setting up proxy - time.Sleep(time.Second) - if err = srv.startProxy(); err != nil { - return nil, err - } - - return &rpcpb.Response{ - Success: true, - Status: "start etcd PASS", - Member: srv.Member, - }, nil -} - -func (srv *Server) startProxy() error { - if srv.Member.EtcdClientProxy { - advertiseClientURL, advertiseClientURLPort, err := getURLAndPort(srv.Member.Etcd.AdvertiseClientURLs[0]) - if err != nil { - return err - } - listenClientURL, _, err := getURLAndPort(srv.Member.Etcd.ListenClientURLs[0]) - if err != nil { - return err - } - - srv.advertiseClientPortToProxy[advertiseClientURLPort] = proxy.NewServer(proxy.ServerConfig{ - Logger: srv.lg, - From: *advertiseClientURL, - To: *listenClientURL, - }) - select { - case err = <-srv.advertiseClientPortToProxy[advertiseClientURLPort].Error(): - return err - case <-time.After(2 * time.Second): - srv.lg.Info("started proxy on client traffic", zap.String("url", advertiseClientURL.String())) - } - } - - if srv.Member.EtcdPeerProxy { - advertisePeerURL, advertisePeerURLPort, err := getURLAndPort(srv.Member.Etcd.AdvertisePeerURLs[0]) - if err != nil { - return err - } - listenPeerURL, _, err := getURLAndPort(srv.Member.Etcd.ListenPeerURLs[0]) - if err != nil { - return err - } - - srv.advertisePeerPortToProxy[advertisePeerURLPort] = proxy.NewServer(proxy.ServerConfig{ - Logger: srv.lg, - From: *advertisePeerURL, - To: *listenPeerURL, - }) - select { - case err = <-srv.advertisePeerPortToProxy[advertisePeerURLPort].Error(): - return err - case <-time.After(2 * time.Second): - srv.lg.Info("started proxy on peer traffic", zap.String("url", advertisePeerURL.String())) - } - } - return nil -} - -func (srv *Server) stopProxy() { - if srv.Member.EtcdClientProxy && len(srv.advertiseClientPortToProxy) > 0 { - for port, px := range srv.advertiseClientPortToProxy { - if err := px.Close(); err != nil { - srv.lg.Warn("failed to close proxy", zap.Int("port", port)) - continue - } - select { - case <-px.Done(): - // enough time to release port - time.Sleep(time.Second) - case <-time.After(time.Second): - } - srv.lg.Info("closed proxy", - zap.Int("port", port), - zap.String("from", px.From()), - zap.String("to", px.To()), - ) - } - srv.advertiseClientPortToProxy = make(map[int]proxy.Server) - } - if srv.Member.EtcdPeerProxy && len(srv.advertisePeerPortToProxy) > 0 { - for port, px := range srv.advertisePeerPortToProxy { - if err := px.Close(); err != nil { - srv.lg.Warn("failed to close proxy", zap.Int("port", port)) - continue - } - select { - case <-px.Done(): - // enough time to release port - time.Sleep(time.Second) - case <-time.After(time.Second): - } - srv.lg.Info("closed proxy", - zap.Int("port", port), - zap.String("from", px.From()), - zap.String("to", px.To()), - ) - } - srv.advertisePeerPortToProxy = make(map[int]proxy.Server) - } -} - -func (srv *Server) createEtcdLogFile() error { - var err error - srv.etcdLogFile, err = os.Create(srv.Member.EtcdLogPath) - if err != nil { - return err - } - srv.lg.Info("created etcd log file", zap.String("path", srv.Member.EtcdLogPath)) - return nil -} - -func (srv *Server) creatEtcdCmd(fromSnapshot bool) { - etcdPath, etcdFlags := srv.Member.EtcdExecPath, srv.Member.Etcd.Flags() - if fromSnapshot { - etcdFlags = srv.Member.EtcdOnSnapshotRestore.Flags() - } - u, _ := url.Parse(srv.Member.FailpointHTTPAddr) - srv.lg.Info("creating etcd command", - zap.String("etcd-exec-path", etcdPath), - zap.Strings("etcd-flags", etcdFlags), - zap.String("failpoint-http-addr", srv.Member.FailpointHTTPAddr), - zap.String("failpoint-addr", u.Host), - ) - srv.etcdCmd = exec.Command(etcdPath, etcdFlags...) - srv.etcdCmd.Env = []string{"GOFAIL_HTTP=" + u.Host} - srv.etcdCmd.Stdout = srv.etcdLogFile - srv.etcdCmd.Stderr = srv.etcdLogFile -} - -// if started with manual TLS, stores TLS assets -// from tester/client to disk before starting etcd process -func (srv *Server) saveTLSAssets() error { - if srv.Member.PeerCertPath != "" { - if srv.Member.PeerCertData == "" { - return fmt.Errorf("got empty data for %q", srv.Member.PeerCertPath) - } - if err := ioutil.WriteFile(srv.Member.PeerCertPath, []byte(srv.Member.PeerCertData), 0644); err != nil { - return err - } - } - if srv.Member.PeerKeyPath != "" { - if srv.Member.PeerKeyData == "" { - return fmt.Errorf("got empty data for %q", srv.Member.PeerKeyPath) - } - if err := ioutil.WriteFile(srv.Member.PeerKeyPath, []byte(srv.Member.PeerKeyData), 0644); err != nil { - return err - } - } - if srv.Member.PeerTrustedCAPath != "" { - if srv.Member.PeerTrustedCAData == "" { - return fmt.Errorf("got empty data for %q", srv.Member.PeerTrustedCAPath) - } - if err := ioutil.WriteFile(srv.Member.PeerTrustedCAPath, []byte(srv.Member.PeerTrustedCAData), 0644); err != nil { - return err - } - } - if srv.Member.PeerCertPath != "" && - srv.Member.PeerKeyPath != "" && - srv.Member.PeerTrustedCAPath != "" { - srv.lg.Info( - "wrote", - zap.String("peer-cert", srv.Member.PeerCertPath), - zap.String("peer-key", srv.Member.PeerKeyPath), - zap.String("peer-trusted-ca", srv.Member.PeerTrustedCAPath), - ) - } - - if srv.Member.ClientCertPath != "" { - if srv.Member.ClientCertData == "" { - return fmt.Errorf("got empty data for %q", srv.Member.ClientCertPath) - } - if err := ioutil.WriteFile(srv.Member.ClientCertPath, []byte(srv.Member.ClientCertData), 0644); err != nil { - return err - } - } - if srv.Member.ClientKeyPath != "" { - if srv.Member.ClientKeyData == "" { - return fmt.Errorf("got empty data for %q", srv.Member.ClientKeyPath) - } - if err := ioutil.WriteFile(srv.Member.ClientKeyPath, []byte(srv.Member.ClientKeyData), 0644); err != nil { - return err - } - } - if srv.Member.ClientTrustedCAPath != "" { - if srv.Member.ClientTrustedCAData == "" { - return fmt.Errorf("got empty data for %q", srv.Member.ClientTrustedCAPath) - } - if err := ioutil.WriteFile(srv.Member.ClientTrustedCAPath, []byte(srv.Member.ClientTrustedCAData), 0644); err != nil { - return err - } - } - if srv.Member.ClientCertPath != "" && - srv.Member.ClientKeyPath != "" && - srv.Member.ClientTrustedCAPath != "" { - srv.lg.Info( - "wrote", - zap.String("client-cert", srv.Member.ClientCertPath), - zap.String("client-key", srv.Member.ClientKeyPath), - zap.String("client-trusted-ca", srv.Member.ClientTrustedCAPath), - ) - } - - return nil -} - -func (srv *Server) loadAutoTLSAssets() error { - if srv.Member.Etcd.PeerAutoTLS { - // in case of slow disk - time.Sleep(time.Second) - - fdir := filepath.Join(srv.Member.Etcd.DataDir, "fixtures", "peer") - - srv.lg.Info( - "loading client auto TLS assets", - zap.String("dir", fdir), - zap.String("endpoint", srv.EtcdClientEndpoint), - ) - - certPath := filepath.Join(fdir, "cert.pem") - if !fileutil.Exist(certPath) { - return fmt.Errorf("cannot find %q", certPath) - } - certData, err := ioutil.ReadFile(certPath) - if err != nil { - return fmt.Errorf("cannot read %q (%v)", certPath, err) - } - srv.Member.PeerCertData = string(certData) - - keyPath := filepath.Join(fdir, "key.pem") - if !fileutil.Exist(keyPath) { - return fmt.Errorf("cannot find %q", keyPath) - } - keyData, err := ioutil.ReadFile(keyPath) - if err != nil { - return fmt.Errorf("cannot read %q (%v)", keyPath, err) - } - srv.Member.PeerKeyData = string(keyData) - - srv.lg.Info( - "loaded peer auto TLS assets", - zap.String("peer-cert-path", certPath), - zap.Int("peer-cert-length", len(certData)), - zap.String("peer-key-path", keyPath), - zap.Int("peer-key-length", len(keyData)), - ) - } - - if srv.Member.Etcd.ClientAutoTLS { - // in case of slow disk - time.Sleep(time.Second) - - fdir := filepath.Join(srv.Member.Etcd.DataDir, "fixtures", "client") - - srv.lg.Info( - "loading client TLS assets", - zap.String("dir", fdir), - zap.String("endpoint", srv.EtcdClientEndpoint), - ) - - certPath := filepath.Join(fdir, "cert.pem") - if !fileutil.Exist(certPath) { - return fmt.Errorf("cannot find %q", certPath) - } - certData, err := ioutil.ReadFile(certPath) - if err != nil { - return fmt.Errorf("cannot read %q (%v)", certPath, err) - } - srv.Member.ClientCertData = string(certData) - - keyPath := filepath.Join(fdir, "key.pem") - if !fileutil.Exist(keyPath) { - return fmt.Errorf("cannot find %q", keyPath) - } - keyData, err := ioutil.ReadFile(keyPath) - if err != nil { - return fmt.Errorf("cannot read %q (%v)", keyPath, err) - } - srv.Member.ClientKeyData = string(keyData) - - srv.lg.Info( - "loaded client TLS assets", - zap.String("peer-cert-path", certPath), - zap.Int("peer-cert-length", len(certData)), - zap.String("peer-key-path", keyPath), - zap.Int("peer-key-length", len(keyData)), - ) - } - - return nil -} - -// start but do not wait for it to complete -func (srv *Server) startEtcdCmd() error { - return srv.etcdCmd.Start() -} - -func (srv *Server) handle_RESTART_ETCD() (*rpcpb.Response, error) { - var err error - if !fileutil.Exist(srv.Member.BaseDir) { - err = fileutil.TouchDirAll(srv.Member.BaseDir) - if err != nil { - return nil, err - } - } - - srv.creatEtcdCmd(false) - - if err = srv.saveTLSAssets(); err != nil { - return nil, err - } - if err = srv.startEtcdCmd(); err != nil { - return nil, err - } - srv.lg.Info("restarted etcd", zap.String("command-path", srv.etcdCmd.Path)) - if err = srv.loadAutoTLSAssets(); err != nil { - return nil, err - } - - // wait some time for etcd listener start - // before setting up proxy - // TODO: local tests should handle port conflicts - // with clients on restart - time.Sleep(time.Second) - if err = srv.startProxy(); err != nil { - return nil, err - } - - return &rpcpb.Response{ - Success: true, - Status: "restart etcd PASS", - Member: srv.Member, - }, nil -} - -func (srv *Server) handle_SIGTERM_ETCD() (*rpcpb.Response, error) { - srv.stopProxy() - - err := stopWithSig(srv.etcdCmd, syscall.SIGTERM) - if err != nil { - return nil, err - } - srv.lg.Info("killed etcd", zap.String("signal", syscall.SIGTERM.String())) - - return &rpcpb.Response{ - Success: true, - Status: "killed etcd", - }, nil -} - -func (srv *Server) handle_SIGQUIT_ETCD_AND_REMOVE_DATA() (*rpcpb.Response, error) { - srv.stopProxy() - - err := stopWithSig(srv.etcdCmd, syscall.SIGQUIT) - if err != nil { - return nil, err - } - srv.lg.Info("killed etcd", zap.String("signal", syscall.SIGQUIT.String())) - - srv.etcdLogFile.Sync() - srv.etcdLogFile.Close() - - // for debugging purposes, rename instead of removing - if err = os.RemoveAll(srv.Member.BaseDir + ".backup"); err != nil { - return nil, err - } - if err = os.Rename(srv.Member.BaseDir, srv.Member.BaseDir+".backup"); err != nil { - return nil, err - } - srv.lg.Info( - "renamed", - zap.String("base-dir", srv.Member.BaseDir), - zap.String("new-dir", srv.Member.BaseDir+".backup"), - ) - - // create a new log file for next new member restart - if !fileutil.Exist(srv.Member.BaseDir) { - err = fileutil.TouchDirAll(srv.Member.BaseDir) - if err != nil { - return nil, err - } - } - if err = srv.createEtcdLogFile(); err != nil { - return nil, err - } - - return &rpcpb.Response{ - Success: true, - Status: "killed etcd and removed base directory", - }, nil -} - -func (srv *Server) handle_SAVE_SNAPSHOT() (*rpcpb.Response, error) { - err := srv.Member.SaveSnapshot(srv.lg) - if err != nil { - return nil, err - } - return &rpcpb.Response{ - Success: true, - Status: "saved snapshot", - SnapshotInfo: srv.Member.SnapshotInfo, - }, nil -} - -func (srv *Server) handle_RESTORE_RESTART_FROM_SNAPSHOT() (resp *rpcpb.Response, err error) { - err = srv.Member.RestoreSnapshot(srv.lg) - if err != nil { - return nil, err - } - resp, err = srv.handle_RESTART_FROM_SNAPSHOT() - if resp != nil && err == nil { - resp.Status = "restored snapshot and " + resp.Status - } - return resp, err -} - -func (srv *Server) handle_RESTART_FROM_SNAPSHOT() (resp *rpcpb.Response, err error) { - srv.creatEtcdCmd(true) - - if err = srv.saveTLSAssets(); err != nil { - return nil, err - } - if err = srv.startEtcdCmd(); err != nil { - return nil, err - } - srv.lg.Info("restarted etcd", zap.String("command-path", srv.etcdCmd.Path)) - if err = srv.loadAutoTLSAssets(); err != nil { - return nil, err - } - - // wait some time for etcd listener start - // before setting up proxy - // TODO: local tests should handle port conflicts - // with clients on restart - time.Sleep(time.Second) - if err = srv.startProxy(); err != nil { - return nil, err - } - - return &rpcpb.Response{ - Success: true, - Status: "restarted etcd from snapshot", - SnapshotInfo: srv.Member.SnapshotInfo, - }, nil -} - -func (srv *Server) handle_SIGQUIT_ETCD_AND_ARCHIVE_DATA() (*rpcpb.Response, error) { - srv.stopProxy() - - // exit with stackstrace - err := stopWithSig(srv.etcdCmd, syscall.SIGQUIT) - if err != nil { - return nil, err - } - srv.lg.Info("killed etcd", zap.String("signal", syscall.SIGQUIT.String())) - - srv.etcdLogFile.Sync() - srv.etcdLogFile.Close() - - // TODO: support separate WAL directory - if err = archive( - srv.Member.BaseDir, - srv.Member.EtcdLogPath, - srv.Member.Etcd.DataDir, - ); err != nil { - return nil, err - } - srv.lg.Info("archived data", zap.String("base-dir", srv.Member.BaseDir)) - - if err = srv.createEtcdLogFile(); err != nil { - return nil, err - } - - srv.lg.Info("cleaning up page cache") - if err := cleanPageCache(); err != nil { - srv.lg.Warn("failed to clean up page cache", zap.String("error", err.Error())) - } - srv.lg.Info("cleaned up page cache") - - return &rpcpb.Response{ - Success: true, - Status: "cleaned up etcd", - }, nil -} - -// stop proxy, etcd, delete data directory -func (srv *Server) handle_SIGQUIT_ETCD_AND_REMOVE_DATA_AND_STOP_AGENT() (*rpcpb.Response, error) { - srv.stopProxy() - - err := stopWithSig(srv.etcdCmd, syscall.SIGQUIT) - if err != nil { - return nil, err - } - srv.lg.Info("killed etcd", zap.String("signal", syscall.SIGQUIT.String())) - - srv.etcdLogFile.Sync() - srv.etcdLogFile.Close() - - err = os.RemoveAll(srv.Member.BaseDir) - if err != nil { - return nil, err - } - srv.lg.Info("removed base directory", zap.String("dir", srv.Member.BaseDir)) - - // stop agent server - srv.Stop() - - return &rpcpb.Response{ - Success: true, - Status: "destroyed etcd and agent", - }, nil -} - -func (srv *Server) handle_BLACKHOLE_PEER_PORT_TX_RX() (*rpcpb.Response, error) { - for port, px := range srv.advertisePeerPortToProxy { - srv.lg.Info("blackholing", zap.Int("peer-port", port)) - px.BlackholeTx() - px.BlackholeRx() - srv.lg.Info("blackholed", zap.Int("peer-port", port)) - } - return &rpcpb.Response{ - Success: true, - Status: "blackholed peer port tx/rx", - }, nil -} - -func (srv *Server) handle_UNBLACKHOLE_PEER_PORT_TX_RX() (*rpcpb.Response, error) { - for port, px := range srv.advertisePeerPortToProxy { - srv.lg.Info("unblackholing", zap.Int("peer-port", port)) - px.UnblackholeTx() - px.UnblackholeRx() - srv.lg.Info("unblackholed", zap.Int("peer-port", port)) - } - return &rpcpb.Response{ - Success: true, - Status: "unblackholed peer port tx/rx", - }, nil -} - -func (srv *Server) handle_DELAY_PEER_PORT_TX_RX() (*rpcpb.Response, error) { - lat := time.Duration(srv.Tester.UpdatedDelayLatencyMs) * time.Millisecond - rv := time.Duration(srv.Tester.DelayLatencyMsRv) * time.Millisecond - - for port, px := range srv.advertisePeerPortToProxy { - srv.lg.Info("delaying", - zap.Int("peer-port", port), - zap.Duration("latency", lat), - zap.Duration("random-variable", rv), - ) - px.DelayTx(lat, rv) - px.DelayRx(lat, rv) - srv.lg.Info("delayed", - zap.Int("peer-port", port), - zap.Duration("latency", lat), - zap.Duration("random-variable", rv), - ) - } - - return &rpcpb.Response{ - Success: true, - Status: "delayed peer port tx/rx", - }, nil -} - -func (srv *Server) handle_UNDELAY_PEER_PORT_TX_RX() (*rpcpb.Response, error) { - for port, px := range srv.advertisePeerPortToProxy { - srv.lg.Info("undelaying", zap.Int("peer-port", port)) - px.UndelayTx() - px.UndelayRx() - srv.lg.Info("undelayed", zap.Int("peer-port", port)) - } - return &rpcpb.Response{ - Success: true, - Status: "undelayed peer port tx/rx", - }, nil -} diff --git a/vendor/go.etcd.io/etcd/functional/agent/server.go b/vendor/go.etcd.io/etcd/functional/agent/server.go deleted file mode 100644 index d6313d955d6f..000000000000 --- a/vendor/go.etcd.io/etcd/functional/agent/server.go +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package agent - -import ( - "math" - "net" - "os" - "os/exec" - "strings" - - "github.com/coreos/etcd/functional/rpcpb" - "github.com/coreos/etcd/pkg/proxy" - - "go.uber.org/zap" - "google.golang.org/grpc" -) - -// Server implements "rpcpb.TransportServer" -// and other etcd operations as an agent -// no need to lock fields since request operations are -// serialized in tester-side -type Server struct { - grpcServer *grpc.Server - lg *zap.Logger - - network string - address string - ln net.Listener - - rpcpb.TransportServer - last rpcpb.Operation - - *rpcpb.Member - *rpcpb.Tester - - etcdCmd *exec.Cmd - etcdLogFile *os.File - - // forward incoming advertise URLs traffic to listen URLs - advertiseClientPortToProxy map[int]proxy.Server - advertisePeerPortToProxy map[int]proxy.Server -} - -// NewServer returns a new agent server. -func NewServer( - lg *zap.Logger, - network string, - address string, -) *Server { - return &Server{ - lg: lg, - network: network, - address: address, - last: rpcpb.Operation_NOT_STARTED, - advertiseClientPortToProxy: make(map[int]proxy.Server), - advertisePeerPortToProxy: make(map[int]proxy.Server), - } -} - -const ( - maxRequestBytes = 1.5 * 1024 * 1024 - grpcOverheadBytes = 512 * 1024 - maxStreams = math.MaxUint32 - maxSendBytes = math.MaxInt32 -) - -// StartServe starts serving agent server. -func (srv *Server) StartServe() error { - var err error - srv.ln, err = net.Listen(srv.network, srv.address) - if err != nil { - return err - } - - var opts []grpc.ServerOption - opts = append(opts, grpc.MaxRecvMsgSize(int(maxRequestBytes+grpcOverheadBytes))) - opts = append(opts, grpc.MaxSendMsgSize(maxSendBytes)) - opts = append(opts, grpc.MaxConcurrentStreams(maxStreams)) - srv.grpcServer = grpc.NewServer(opts...) - - rpcpb.RegisterTransportServer(srv.grpcServer, srv) - - srv.lg.Info( - "gRPC server started", - zap.String("address", srv.address), - zap.String("listener-address", srv.ln.Addr().String()), - ) - err = srv.grpcServer.Serve(srv.ln) - if err != nil && strings.Contains(err.Error(), "use of closed network connection") { - srv.lg.Info( - "gRPC server is shut down", - zap.String("address", srv.address), - zap.Error(err), - ) - } else { - srv.lg.Warn( - "gRPC server returned with error", - zap.String("address", srv.address), - zap.Error(err), - ) - } - return err -} - -// Stop stops serving gRPC server. -func (srv *Server) Stop() { - srv.lg.Info("gRPC server stopping", zap.String("address", srv.address)) - srv.grpcServer.Stop() - srv.lg.Info("gRPC server stopped", zap.String("address", srv.address)) -} - -// Transport communicates with etcd tester. -func (srv *Server) Transport(stream rpcpb.Transport_TransportServer) (err error) { - errc := make(chan error) - go func() { - for { - var req *rpcpb.Request - req, err = stream.Recv() - if err != nil { - errc <- err - // TODO: handle error and retry - return - } - if req.Member != nil { - srv.Member = req.Member - } - if req.Tester != nil { - srv.Tester = req.Tester - } - - var resp *rpcpb.Response - resp, err = srv.handleTesterRequest(req) - if err != nil { - errc <- err - // TODO: handle error and retry - return - } - - if err = stream.Send(resp); err != nil { - errc <- err - // TODO: handle error and retry - return - } - } - }() - - select { - case err = <-errc: - case <-stream.Context().Done(): - err = stream.Context().Err() - } - return err -} diff --git a/vendor/go.etcd.io/etcd/functional/agent/utils.go b/vendor/go.etcd.io/etcd/functional/agent/utils.go deleted file mode 100644 index 437ffa96199b..000000000000 --- a/vendor/go.etcd.io/etcd/functional/agent/utils.go +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package agent - -import ( - "net" - "net/url" - "os" - "os/exec" - "path/filepath" - "strconv" - "time" - - "github.com/coreos/etcd/pkg/fileutil" -) - -// TODO: support separate WAL directory -func archive(baseDir, etcdLogPath, dataDir string) error { - dir := filepath.Join(baseDir, "etcd-failure-archive", time.Now().Format(time.RFC3339)) - if existDir(dir) { - dir = filepath.Join(baseDir, "etcd-failure-archive", time.Now().Add(time.Second).Format(time.RFC3339)) - } - if err := fileutil.TouchDirAll(dir); err != nil { - return err - } - - if err := os.Rename(etcdLogPath, filepath.Join(dir, "etcd.log")); err != nil { - if !os.IsNotExist(err) { - return err - } - } - if err := os.Rename(dataDir, filepath.Join(dir, filepath.Base(dataDir))); err != nil { - if !os.IsNotExist(err) { - return err - } - } - - return nil -} - -func existDir(fpath string) bool { - st, err := os.Stat(fpath) - if err != nil { - if os.IsNotExist(err) { - return false - } - } else { - return st.IsDir() - } - return false -} - -func getURLAndPort(addr string) (urlAddr *url.URL, port int, err error) { - urlAddr, err = url.Parse(addr) - if err != nil { - return nil, -1, err - } - var s string - _, s, err = net.SplitHostPort(urlAddr.Host) - if err != nil { - return nil, -1, err - } - port, err = strconv.Atoi(s) - if err != nil { - return nil, -1, err - } - return urlAddr, port, err -} - -func stopWithSig(cmd *exec.Cmd, sig os.Signal) error { - err := cmd.Process.Signal(sig) - if err != nil { - return err - } - - errc := make(chan error) - go func() { - _, ew := cmd.Process.Wait() - errc <- ew - close(errc) - }() - - select { - case <-time.After(5 * time.Second): - cmd.Process.Kill() - case e := <-errc: - return e - } - err = <-errc - return err -} - -func cleanPageCache() error { - // https://www.kernel.org/doc/Documentation/sysctl/vm.txt - // https://github.com/torvalds/linux/blob/master/fs/drop_caches.c - cmd := exec.Command("/bin/sh", "-c", `echo "echo 1 > /proc/sys/vm/drop_caches" | sudo sh`) - return cmd.Run() -} diff --git a/vendor/go.etcd.io/etcd/functional/rpcpb/etcd_config.go b/vendor/go.etcd.io/etcd/functional/rpcpb/etcd_config.go deleted file mode 100644 index 9d3d8c2350c1..000000000000 --- a/vendor/go.etcd.io/etcd/functional/rpcpb/etcd_config.go +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rpcpb - -import ( - "fmt" - "reflect" - "strings" -) - -var etcdFields = []string{ - "Name", - "DataDir", - "WALDir", - - "HeartbeatIntervalMs", - "ElectionTimeoutMs", - - "ListenClientURLs", - "AdvertiseClientURLs", - "ClientAutoTLS", - "ClientCertAuth", - "ClientCertFile", - "ClientKeyFile", - "ClientTrustedCAFile", - - "ListenPeerURLs", - "AdvertisePeerURLs", - "PeerAutoTLS", - "PeerClientCertAuth", - "PeerCertFile", - "PeerKeyFile", - "PeerTrustedCAFile", - - "InitialCluster", - "InitialClusterState", - "InitialClusterToken", - - "SnapshotCount", - "QuotaBackendBytes", - - // "PreVote", - // "InitialCorruptCheck", -} - -// Flags returns etcd flags in string slice. -func (cfg *Etcd) Flags() (fs []string) { - tp := reflect.TypeOf(*cfg) - vo := reflect.ValueOf(*cfg) - for _, name := range etcdFields { - field, ok := tp.FieldByName(name) - if !ok { - panic(fmt.Errorf("field %q not found", name)) - } - fv := reflect.Indirect(vo).FieldByName(name) - var sv string - switch fv.Type().Kind() { - case reflect.String: - sv = fv.String() - case reflect.Slice: - n := fv.Len() - sl := make([]string, n) - for i := 0; i < n; i++ { - sl[i] = fv.Index(i).String() - } - sv = strings.Join(sl, ",") - case reflect.Int64: - sv = fmt.Sprintf("%d", fv.Int()) - case reflect.Bool: - sv = fmt.Sprintf("%v", fv.Bool()) - default: - panic(fmt.Errorf("field %q (%v) cannot be parsed", name, fv.Type().Kind())) - } - - fname := field.Tag.Get("yaml") - - // not supported in old etcd - if fname == "pre-vote" || fname == "initial-corrupt-check" { - continue - } - - if sv != "" { - fs = append(fs, fmt.Sprintf("--%s=%s", fname, sv)) - } - } - return fs -} diff --git a/vendor/go.etcd.io/etcd/functional/rpcpb/member.go b/vendor/go.etcd.io/etcd/functional/rpcpb/member.go deleted file mode 100644 index 01f68411340a..000000000000 --- a/vendor/go.etcd.io/etcd/functional/rpcpb/member.go +++ /dev/null @@ -1,361 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rpcpb - -import ( - "context" - "crypto/tls" - "fmt" - "net/url" - "os" - "time" - - "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/pkg/transport" - "github.com/coreos/etcd/snapshot" - - "github.com/dustin/go-humanize" - "go.uber.org/zap" - grpc "google.golang.org/grpc" - "google.golang.org/grpc/credentials" -) - -// ElectionTimeout returns an election timeout duration. -func (m *Member) ElectionTimeout() time.Duration { - return time.Duration(m.Etcd.ElectionTimeoutMs) * time.Millisecond -} - -// DialEtcdGRPCServer creates a raw gRPC connection to an etcd member. -func (m *Member) DialEtcdGRPCServer(opts ...grpc.DialOption) (*grpc.ClientConn, error) { - dialOpts := []grpc.DialOption{ - grpc.WithTimeout(5 * time.Second), - grpc.WithBlock(), - } - - secure := false - for _, cu := range m.Etcd.AdvertiseClientURLs { - u, err := url.Parse(cu) - if err != nil { - return nil, err - } - if u.Scheme == "https" { // TODO: handle unix - secure = true - } - } - - if secure { - // assume save TLS assets are already stord on disk - tlsInfo := transport.TLSInfo{ - CertFile: m.ClientCertPath, - KeyFile: m.ClientKeyPath, - TrustedCAFile: m.ClientTrustedCAPath, - - // TODO: remove this with generated certs - // only need it for auto TLS - InsecureSkipVerify: true, - } - tlsConfig, err := tlsInfo.ClientConfig() - if err != nil { - return nil, err - } - creds := credentials.NewTLS(tlsConfig) - dialOpts = append(dialOpts, grpc.WithTransportCredentials(creds)) - } else { - dialOpts = append(dialOpts, grpc.WithInsecure()) - } - dialOpts = append(dialOpts, opts...) - return grpc.Dial(m.EtcdClientEndpoint, dialOpts...) -} - -// CreateEtcdClientConfig creates a client configuration from member. -func (m *Member) CreateEtcdClientConfig(opts ...grpc.DialOption) (cfg *clientv3.Config, err error) { - secure := false - for _, cu := range m.Etcd.AdvertiseClientURLs { - var u *url.URL - u, err = url.Parse(cu) - if err != nil { - return nil, err - } - if u.Scheme == "https" { // TODO: handle unix - secure = true - } - } - - cfg = &clientv3.Config{ - Endpoints: []string{m.EtcdClientEndpoint}, - DialTimeout: 10 * time.Second, - DialOptions: opts, - } - if secure { - // assume save TLS assets are already stord on disk - tlsInfo := transport.TLSInfo{ - CertFile: m.ClientCertPath, - KeyFile: m.ClientKeyPath, - TrustedCAFile: m.ClientTrustedCAPath, - - // TODO: remove this with generated certs - // only need it for auto TLS - InsecureSkipVerify: true, - } - var tlsConfig *tls.Config - tlsConfig, err = tlsInfo.ClientConfig() - if err != nil { - return nil, err - } - cfg.TLS = tlsConfig - } - return cfg, err -} - -// CreateEtcdClient creates a client from member. -func (m *Member) CreateEtcdClient(opts ...grpc.DialOption) (*clientv3.Client, error) { - cfg, err := m.CreateEtcdClientConfig(opts...) - if err != nil { - return nil, err - } - return clientv3.New(*cfg) -} - -// CheckCompact ensures that historical data before given revision has been compacted. -func (m *Member) CheckCompact(rev int64) error { - cli, err := m.CreateEtcdClient() - if err != nil { - return fmt.Errorf("%v (%q)", err, m.EtcdClientEndpoint) - } - defer cli.Close() - - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - wch := cli.Watch(ctx, "\x00", clientv3.WithFromKey(), clientv3.WithRev(rev-1)) - wr, ok := <-wch - cancel() - - if !ok { - return fmt.Errorf("watch channel terminated (endpoint %q)", m.EtcdClientEndpoint) - } - if wr.CompactRevision != rev { - return fmt.Errorf("got compact revision %v, wanted %v (endpoint %q)", wr.CompactRevision, rev, m.EtcdClientEndpoint) - } - - return nil -} - -// Defrag runs defragmentation on this member. -func (m *Member) Defrag() error { - cli, err := m.CreateEtcdClient() - if err != nil { - return fmt.Errorf("%v (%q)", err, m.EtcdClientEndpoint) - } - defer cli.Close() - - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) - _, err = cli.Defragment(ctx, m.EtcdClientEndpoint) - cancel() - return err -} - -// RevHash fetches current revision and hash on this member. -func (m *Member) RevHash() (int64, int64, error) { - conn, err := m.DialEtcdGRPCServer() - if err != nil { - return 0, 0, err - } - defer conn.Close() - - mt := pb.NewMaintenanceClient(conn) - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - resp, err := mt.Hash(ctx, &pb.HashRequest{}, grpc.FailFast(false)) - cancel() - - if err != nil { - return 0, 0, err - } - - return resp.Header.Revision, int64(resp.Hash), nil -} - -// Rev fetches current revision on this member. -func (m *Member) Rev(ctx context.Context) (int64, error) { - cli, err := m.CreateEtcdClient() - if err != nil { - return 0, fmt.Errorf("%v (%q)", err, m.EtcdClientEndpoint) - } - defer cli.Close() - - resp, err := cli.Status(ctx, m.EtcdClientEndpoint) - if err != nil { - return 0, err - } - return resp.Header.Revision, nil -} - -// Compact compacts member storage with given revision. -// It blocks until it's physically done. -func (m *Member) Compact(rev int64, timeout time.Duration) error { - cli, err := m.CreateEtcdClient() - if err != nil { - return fmt.Errorf("%v (%q)", err, m.EtcdClientEndpoint) - } - defer cli.Close() - - ctx, cancel := context.WithTimeout(context.Background(), timeout) - _, err = cli.Compact(ctx, rev, clientv3.WithCompactPhysical()) - cancel() - return err -} - -// IsLeader returns true if this member is the current cluster leader. -func (m *Member) IsLeader() (bool, error) { - cli, err := m.CreateEtcdClient() - if err != nil { - return false, fmt.Errorf("%v (%q)", err, m.EtcdClientEndpoint) - } - defer cli.Close() - - resp, err := cli.Status(context.Background(), m.EtcdClientEndpoint) - if err != nil { - return false, err - } - return resp.Header.MemberId == resp.Leader, nil -} - -// WriteHealthKey writes a health key to this member. -func (m *Member) WriteHealthKey() error { - cli, err := m.CreateEtcdClient() - if err != nil { - return fmt.Errorf("%v (%q)", err, m.EtcdClientEndpoint) - } - defer cli.Close() - - // give enough time-out in case expensive requests (range/delete) are pending - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - _, err = cli.Put(ctx, "health", "good") - cancel() - if err != nil { - return fmt.Errorf("%v (%q)", err, m.EtcdClientEndpoint) - } - return nil -} - -// SaveSnapshot downloads a snapshot file from this member, locally. -// It's meant to requested remotely, so that local member can store -// snapshot file on local disk. -func (m *Member) SaveSnapshot(lg *zap.Logger) (err error) { - // remove existing snapshot first - if err = os.RemoveAll(m.SnapshotPath); err != nil { - return err - } - - var ccfg *clientv3.Config - ccfg, err = m.CreateEtcdClientConfig() - if err != nil { - return fmt.Errorf("%v (%q)", err, m.EtcdClientEndpoint) - } - - lg.Info( - "snapshot save START", - zap.String("member-name", m.Etcd.Name), - zap.Strings("member-client-urls", m.Etcd.AdvertiseClientURLs), - zap.String("snapshot-path", m.SnapshotPath), - ) - now := time.Now() - mgr := snapshot.NewV3(lg) - if err = mgr.Save(context.Background(), *ccfg, m.SnapshotPath); err != nil { - return err - } - took := time.Since(now) - - var fi os.FileInfo - fi, err = os.Stat(m.SnapshotPath) - if err != nil { - return err - } - var st snapshot.Status - st, err = mgr.Status(m.SnapshotPath) - if err != nil { - return err - } - m.SnapshotInfo = &SnapshotInfo{ - MemberName: m.Etcd.Name, - MemberClientURLs: m.Etcd.AdvertiseClientURLs, - SnapshotPath: m.SnapshotPath, - SnapshotFileSize: humanize.Bytes(uint64(fi.Size())), - SnapshotTotalSize: humanize.Bytes(uint64(st.TotalSize)), - SnapshotTotalKey: int64(st.TotalKey), - SnapshotHash: int64(st.Hash), - SnapshotRevision: st.Revision, - Took: fmt.Sprintf("%v", took), - } - lg.Info( - "snapshot save END", - zap.String("member-name", m.SnapshotInfo.MemberName), - zap.Strings("member-client-urls", m.SnapshotInfo.MemberClientURLs), - zap.String("snapshot-path", m.SnapshotPath), - zap.String("snapshot-file-size", m.SnapshotInfo.SnapshotFileSize), - zap.String("snapshot-total-size", m.SnapshotInfo.SnapshotTotalSize), - zap.Int64("snapshot-total-key", m.SnapshotInfo.SnapshotTotalKey), - zap.Int64("snapshot-hash", m.SnapshotInfo.SnapshotHash), - zap.Int64("snapshot-revision", m.SnapshotInfo.SnapshotRevision), - zap.String("took", m.SnapshotInfo.Took), - ) - return nil -} - -// RestoreSnapshot restores a cluster from a given snapshot file on disk. -// It's meant to requested remotely, so that local member can load the -// snapshot file from local disk. -func (m *Member) RestoreSnapshot(lg *zap.Logger) (err error) { - if err = os.RemoveAll(m.EtcdOnSnapshotRestore.DataDir); err != nil { - return err - } - if err = os.RemoveAll(m.EtcdOnSnapshotRestore.WALDir); err != nil { - return err - } - - lg.Info( - "snapshot restore START", - zap.String("member-name", m.Etcd.Name), - zap.Strings("member-client-urls", m.Etcd.AdvertiseClientURLs), - zap.String("snapshot-path", m.SnapshotPath), - ) - now := time.Now() - mgr := snapshot.NewV3(lg) - err = mgr.Restore(snapshot.RestoreConfig{ - SnapshotPath: m.SnapshotInfo.SnapshotPath, - Name: m.EtcdOnSnapshotRestore.Name, - OutputDataDir: m.EtcdOnSnapshotRestore.DataDir, - OutputWALDir: m.EtcdOnSnapshotRestore.WALDir, - PeerURLs: m.EtcdOnSnapshotRestore.AdvertisePeerURLs, - InitialCluster: m.EtcdOnSnapshotRestore.InitialCluster, - InitialClusterToken: m.EtcdOnSnapshotRestore.InitialClusterToken, - SkipHashCheck: false, - // TODO: set SkipHashCheck it true, to recover from existing db file - }) - took := time.Since(now) - lg.Info( - "snapshot restore END", - zap.String("member-name", m.SnapshotInfo.MemberName), - zap.Strings("member-client-urls", m.SnapshotInfo.MemberClientURLs), - zap.String("snapshot-path", m.SnapshotPath), - zap.String("snapshot-file-size", m.SnapshotInfo.SnapshotFileSize), - zap.String("snapshot-total-size", m.SnapshotInfo.SnapshotTotalSize), - zap.Int64("snapshot-total-key", m.SnapshotInfo.SnapshotTotalKey), - zap.Int64("snapshot-hash", m.SnapshotInfo.SnapshotHash), - zap.Int64("snapshot-revision", m.SnapshotInfo.SnapshotRevision), - zap.String("took", took.String()), - zap.Error(err), - ) - return err -} diff --git a/vendor/go.etcd.io/etcd/functional/rpcpb/rpc.pb.go b/vendor/go.etcd.io/etcd/functional/rpcpb/rpc.pb.go deleted file mode 100644 index 1c488dc47336..000000000000 --- a/vendor/go.etcd.io/etcd/functional/rpcpb/rpc.pb.go +++ /dev/null @@ -1,5112 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: rpcpb/rpc.proto - -/* - Package rpcpb is a generated protocol buffer package. - - It is generated from these files: - rpcpb/rpc.proto - - It has these top-level messages: - Request - SnapshotInfo - Response - Member - Tester - Etcd -*/ -package rpcpb - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" -import _ "github.com/gogo/protobuf/gogoproto" - -import context "golang.org/x/net/context" -import grpc "google.golang.org/grpc" - -import io "io" - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type Operation int32 - -const ( - // NOT_STARTED is the agent status before etcd first start. - Operation_NOT_STARTED Operation = 0 - // INITIAL_START_ETCD is only called to start etcd, the very first time. - Operation_INITIAL_START_ETCD Operation = 10 - // RESTART_ETCD is sent to restart killed etcd. - Operation_RESTART_ETCD Operation = 11 - // SIGTERM_ETCD pauses etcd process while keeping data directories - // and previous etcd configurations. - Operation_SIGTERM_ETCD Operation = 20 - // SIGQUIT_ETCD_AND_REMOVE_DATA kills etcd process and removes all data - // directories to simulate destroying the whole machine. - Operation_SIGQUIT_ETCD_AND_REMOVE_DATA Operation = 21 - // SAVE_SNAPSHOT is sent to trigger local member to download its snapshot - // onto its local disk with the specified path from tester. - Operation_SAVE_SNAPSHOT Operation = 30 - // RESTORE_RESTART_FROM_SNAPSHOT is sent to trigger local member to - // restore a cluster from existing snapshot from disk, and restart - // an etcd instance from recovered data. - Operation_RESTORE_RESTART_FROM_SNAPSHOT Operation = 31 - // RESTART_FROM_SNAPSHOT is sent to trigger local member to restart - // and join an existing cluster that has been recovered from a snapshot. - // Local member joins this cluster with fresh data. - Operation_RESTART_FROM_SNAPSHOT Operation = 32 - // SIGQUIT_ETCD_AND_ARCHIVE_DATA is sent when consistency check failed, - // thus need to archive etcd data directories. - Operation_SIGQUIT_ETCD_AND_ARCHIVE_DATA Operation = 40 - // SIGQUIT_ETCD_AND_REMOVE_DATA_AND_STOP_AGENT destroys etcd process, - // etcd data, and agent server. - Operation_SIGQUIT_ETCD_AND_REMOVE_DATA_AND_STOP_AGENT Operation = 41 - // BLACKHOLE_PEER_PORT_TX_RX drops all outgoing/incoming packets from/to - // the peer port on target member's peer port. - Operation_BLACKHOLE_PEER_PORT_TX_RX Operation = 100 - // UNBLACKHOLE_PEER_PORT_TX_RX removes outgoing/incoming packet dropping. - Operation_UNBLACKHOLE_PEER_PORT_TX_RX Operation = 101 - // DELAY_PEER_PORT_TX_RX delays all outgoing/incoming packets from/to - // the peer port on target member's peer port. - Operation_DELAY_PEER_PORT_TX_RX Operation = 200 - // UNDELAY_PEER_PORT_TX_RX removes all outgoing/incoming delays. - Operation_UNDELAY_PEER_PORT_TX_RX Operation = 201 -) - -var Operation_name = map[int32]string{ - 0: "NOT_STARTED", - 10: "INITIAL_START_ETCD", - 11: "RESTART_ETCD", - 20: "SIGTERM_ETCD", - 21: "SIGQUIT_ETCD_AND_REMOVE_DATA", - 30: "SAVE_SNAPSHOT", - 31: "RESTORE_RESTART_FROM_SNAPSHOT", - 32: "RESTART_FROM_SNAPSHOT", - 40: "SIGQUIT_ETCD_AND_ARCHIVE_DATA", - 41: "SIGQUIT_ETCD_AND_REMOVE_DATA_AND_STOP_AGENT", - 100: "BLACKHOLE_PEER_PORT_TX_RX", - 101: "UNBLACKHOLE_PEER_PORT_TX_RX", - 200: "DELAY_PEER_PORT_TX_RX", - 201: "UNDELAY_PEER_PORT_TX_RX", -} -var Operation_value = map[string]int32{ - "NOT_STARTED": 0, - "INITIAL_START_ETCD": 10, - "RESTART_ETCD": 11, - "SIGTERM_ETCD": 20, - "SIGQUIT_ETCD_AND_REMOVE_DATA": 21, - "SAVE_SNAPSHOT": 30, - "RESTORE_RESTART_FROM_SNAPSHOT": 31, - "RESTART_FROM_SNAPSHOT": 32, - "SIGQUIT_ETCD_AND_ARCHIVE_DATA": 40, - "SIGQUIT_ETCD_AND_REMOVE_DATA_AND_STOP_AGENT": 41, - "BLACKHOLE_PEER_PORT_TX_RX": 100, - "UNBLACKHOLE_PEER_PORT_TX_RX": 101, - "DELAY_PEER_PORT_TX_RX": 200, - "UNDELAY_PEER_PORT_TX_RX": 201, -} - -func (x Operation) String() string { - return proto.EnumName(Operation_name, int32(x)) -} -func (Operation) EnumDescriptor() ([]byte, []int) { return fileDescriptorRpc, []int{0} } - -// Case defines various system faults or test case in distributed systems, -// in order to verify correct behavior of etcd servers and clients. -type Case int32 - -const ( - // SIGTERM_ONE_FOLLOWER stops a randomly chosen follower (non-leader) - // but does not delete its data directories on disk for next restart. - // It waits "delay-ms" before recovering this failure. - // The expected behavior is that the follower comes back online - // and rejoins the cluster, and then each member continues to process - // client requests ('Put' request that requires Raft consensus). - Case_SIGTERM_ONE_FOLLOWER Case = 0 - // SIGTERM_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT stops a randomly chosen - // follower but does not delete its data directories on disk for next - // restart. And waits until most up-to-date node (leader) applies the - // snapshot count of entries since the stop operation. - // The expected behavior is that the follower comes back online and - // rejoins the cluster, and then active leader sends snapshot - // to the follower to force it to follow the leader's log. - // As always, after recovery, each member must be able to process - // client requests. - Case_SIGTERM_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT Case = 1 - // SIGTERM_LEADER stops the active leader node but does not delete its - // data directories on disk for next restart. Then it waits "delay-ms" - // before recovering this failure, in order to trigger election timeouts. - // The expected behavior is that a new leader gets elected, and the - // old leader comes back online and rejoins the cluster as a follower. - // As always, after recovery, each member must be able to process - // client requests. - Case_SIGTERM_LEADER Case = 2 - // SIGTERM_LEADER_UNTIL_TRIGGER_SNAPSHOT stops the active leader node - // but does not delete its data directories on disk for next restart. - // And waits until most up-to-date node ("new" leader) applies the - // snapshot count of entries since the stop operation. - // The expected behavior is that cluster elects a new leader, and the - // old leader comes back online and rejoins the cluster as a follower. - // And it receives the snapshot from the new leader to overwrite its - // store. As always, after recovery, each member must be able to - // process client requests. - Case_SIGTERM_LEADER_UNTIL_TRIGGER_SNAPSHOT Case = 3 - // SIGTERM_QUORUM stops majority number of nodes to make the whole cluster - // inoperable but does not delete data directories on stopped nodes - // for next restart. And it waits "delay-ms" before recovering failure. - // The expected behavior is that nodes come back online, thus cluster - // comes back operative as well. As always, after recovery, each member - // must be able to process client requests. - Case_SIGTERM_QUORUM Case = 4 - // SIGTERM_ALL stops the whole cluster but does not delete data directories - // on disk for next restart. And it waits "delay-ms" before recovering - // this failure. - // The expected behavior is that nodes come back online, thus cluster - // comes back operative as well. As always, after recovery, each member - // must be able to process client requests. - Case_SIGTERM_ALL Case = 5 - // SIGQUIT_AND_REMOVE_ONE_FOLLOWER stops a randomly chosen follower - // (non-leader), deletes its data directories on disk, and removes - // this member from cluster (membership reconfiguration). On recovery, - // tester adds a new member, and this member joins the existing cluster - // with fresh data. It waits "delay-ms" before recovering this - // failure. This simulates destroying one follower machine, where operator - // needs to add a new member from a fresh machine. - // The expected behavior is that a new member joins the existing cluster, - // and then each member continues to process client requests. - Case_SIGQUIT_AND_REMOVE_ONE_FOLLOWER Case = 10 - // SIGQUIT_AND_REMOVE_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT stops a randomly - // chosen follower, deletes its data directories on disk, and removes - // this member from cluster (membership reconfiguration). On recovery, - // tester adds a new member, and this member joins the existing cluster - // restart. On member remove, cluster waits until most up-to-date node - // (leader) applies the snapshot count of entries since the stop operation. - // This simulates destroying a leader machine, where operator needs to add - // a new member from a fresh machine. - // The expected behavior is that a new member joins the existing cluster, - // and receives a snapshot from the active leader. As always, after - // recovery, each member must be able to process client requests. - Case_SIGQUIT_AND_REMOVE_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT Case = 11 - // SIGQUIT_AND_REMOVE_LEADER stops the active leader node, deletes its - // data directories on disk, and removes this member from cluster. - // On recovery, tester adds a new member, and this member joins the - // existing cluster with fresh data. It waits "delay-ms" before - // recovering this failure. This simulates destroying a leader machine, - // where operator needs to add a new member from a fresh machine. - // The expected behavior is that a new member joins the existing cluster, - // and then each member continues to process client requests. - Case_SIGQUIT_AND_REMOVE_LEADER Case = 12 - // SIGQUIT_AND_REMOVE_LEADER_UNTIL_TRIGGER_SNAPSHOT stops the active leader, - // deletes its data directories on disk, and removes this member from - // cluster (membership reconfiguration). On recovery, tester adds a new - // member, and this member joins the existing cluster restart. On member - // remove, cluster waits until most up-to-date node (new leader) applies - // the snapshot count of entries since the stop operation. This simulates - // destroying a leader machine, where operator needs to add a new member - // from a fresh machine. - // The expected behavior is that on member remove, cluster elects a new - // leader, and a new member joins the existing cluster and receives a - // snapshot from the newly elected leader. As always, after recovery, each - // member must be able to process client requests. - Case_SIGQUIT_AND_REMOVE_LEADER_UNTIL_TRIGGER_SNAPSHOT Case = 13 - // SIGQUIT_AND_REMOVE_QUORUM_AND_RESTORE_LEADER_SNAPSHOT_FROM_SCRATCH first - // stops majority number of nodes, deletes data directories on those quorum - // nodes, to make the whole cluster inoperable. Now that quorum and their - // data are totally destroyed, cluster cannot even remove unavailable nodes - // (e.g. 2 out of 3 are lost, so no leader can be elected). - // Let's assume 3-node cluster of node A, B, and C. One day, node A and B - // are destroyed and all their data are gone. The only viable solution is - // to recover from C's latest snapshot. - // - // To simulate: - // 1. Assume node C is the current leader with most up-to-date data. - // 2. Download snapshot from node C, before destroying node A and B. - // 3. Destroy node A and B, and make the whole cluster inoperable. - // 4. Now node C cannot operate either. - // 5. SIGTERM node C and remove its data directories. - // 6. Restore a new seed member from node C's latest snapshot file. - // 7. Add another member to establish 2-node cluster. - // 8. Add another member to establish 3-node cluster. - // 9. Add more if any. - // - // The expected behavior is that etcd successfully recovers from such - // disastrous situation as only 1-node survives out of 3-node cluster, - // new members joins the existing cluster, and previous data from snapshot - // are still preserved after recovery process. As always, after recovery, - // each member must be able to process client requests. - Case_SIGQUIT_AND_REMOVE_QUORUM_AND_RESTORE_LEADER_SNAPSHOT_FROM_SCRATCH Case = 14 - // BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER drops all outgoing/incoming - // packets from/to the peer port on a randomly chosen follower - // (non-leader), and waits for "delay-ms" until recovery. - // The expected behavior is that once dropping operation is undone, - // each member must be able to process client requests. - Case_BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER Case = 100 - // BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT drops - // all outgoing/incoming packets from/to the peer port on a randomly - // chosen follower (non-leader), and waits for most up-to-date node - // (leader) applies the snapshot count of entries since the blackhole - // operation. - // The expected behavior is that once packet drop operation is undone, - // the slow follower tries to catch up, possibly receiving the snapshot - // from the active leader. As always, after recovery, each member must - // be able to process client requests. - Case_BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT Case = 101 - // BLACKHOLE_PEER_PORT_TX_RX_LEADER drops all outgoing/incoming packets - // from/to the peer port on the active leader (isolated), and waits for - // "delay-ms" until recovery, in order to trigger election timeout. - // The expected behavior is that after election timeout, a new leader gets - // elected, and once dropping operation is undone, the old leader comes - // back and rejoins the cluster as a follower. As always, after recovery, - // each member must be able to process client requests. - Case_BLACKHOLE_PEER_PORT_TX_RX_LEADER Case = 102 - // BLACKHOLE_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT drops all - // outgoing/incoming packets from/to the peer port on the active leader, - // and waits for most up-to-date node (leader) applies the snapshot - // count of entries since the blackhole operation. - // The expected behavior is that cluster elects a new leader, and once - // dropping operation is undone, the old leader comes back and rejoins - // the cluster as a follower. The slow follower tries to catch up, likely - // receiving the snapshot from the new active leader. As always, after - // recovery, each member must be able to process client requests. - Case_BLACKHOLE_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT Case = 103 - // BLACKHOLE_PEER_PORT_TX_RX_QUORUM drops all outgoing/incoming packets - // from/to the peer ports on majority nodes of cluster, thus losing its - // leader and cluster being inoperable. And it waits for "delay-ms" - // until recovery. - // The expected behavior is that once packet drop operation is undone, - // nodes come back online, thus cluster comes back operative. As always, - // after recovery, each member must be able to process client requests. - Case_BLACKHOLE_PEER_PORT_TX_RX_QUORUM Case = 104 - // BLACKHOLE_PEER_PORT_TX_RX_ALL drops all outgoing/incoming packets - // from/to the peer ports on all nodes, thus making cluster totally - // inoperable. It waits for "delay-ms" until recovery. - // The expected behavior is that once packet drop operation is undone, - // nodes come back online, thus cluster comes back operative. As always, - // after recovery, each member must be able to process client requests. - Case_BLACKHOLE_PEER_PORT_TX_RX_ALL Case = 105 - // DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER delays outgoing/incoming packets - // from/to the peer port on a randomly chosen follower (non-leader). - // It waits for "delay-ms" until recovery. - // The expected behavior is that once packet delay operation is undone, - // the follower comes back and tries to catch up with latest changes from - // cluster. And as always, after recovery, each member must be able to - // process client requests. - Case_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER Case = 200 - // RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER delays outgoing/incoming - // packets from/to the peer port on a randomly chosen follower - // (non-leader) with a randomized time duration (thus isolated). It - // waits for "delay-ms" until recovery. - // The expected behavior is that once packet delay operation is undone, - // each member must be able to process client requests. - Case_RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER Case = 201 - // DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT delays - // outgoing/incoming packets from/to the peer port on a randomly chosen - // follower (non-leader), and waits for most up-to-date node (leader) - // applies the snapshot count of entries since the delay operation. - // The expected behavior is that the delayed follower gets isolated - // and behind the current active leader, and once delay operation is undone, - // the slow follower comes back and catches up possibly receiving snapshot - // from the active leader. As always, after recovery, each member must be - // able to process client requests. - Case_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT Case = 202 - // RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT delays - // outgoing/incoming packets from/to the peer port on a randomly chosen - // follower (non-leader) with a randomized time duration, and waits for - // most up-to-date node (leader) applies the snapshot count of entries - // since the delay operation. - // The expected behavior is that the delayed follower gets isolated - // and behind the current active leader, and once delay operation is undone, - // the slow follower comes back and catches up, possibly receiving a - // snapshot from the active leader. As always, after recovery, each member - // must be able to process client requests. - Case_RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT Case = 203 - // DELAY_PEER_PORT_TX_RX_LEADER delays outgoing/incoming packets from/to - // the peer port on the active leader. And waits for "delay-ms" until - // recovery. - // The expected behavior is that cluster may elect a new leader, and - // once packet delay operation is undone, the (old) leader comes back - // and tries to catch up with latest changes from cluster. As always, - // after recovery, each member must be able to process client requests. - Case_DELAY_PEER_PORT_TX_RX_LEADER Case = 204 - // RANDOM_DELAY_PEER_PORT_TX_RX_LEADER delays outgoing/incoming packets - // from/to the peer port on the active leader with a randomized time - // duration. And waits for "delay-ms" until recovery. - // The expected behavior is that cluster may elect a new leader, and - // once packet delay operation is undone, the (old) leader comes back - // and tries to catch up with latest changes from cluster. As always, - // after recovery, each member must be able to process client requests. - Case_RANDOM_DELAY_PEER_PORT_TX_RX_LEADER Case = 205 - // DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT delays - // outgoing/incoming packets from/to the peer port on the active leader, - // and waits for most up-to-date node (current or new leader) applies the - // snapshot count of entries since the delay operation. - // The expected behavior is that cluster may elect a new leader, and - // the old leader gets isolated and behind the current active leader, - // and once delay operation is undone, the slow follower comes back - // and catches up, likely receiving a snapshot from the active leader. - // As always, after recovery, each member must be able to process client - // requests. - Case_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT Case = 206 - // RANDOM_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT delays - // outgoing/incoming packets from/to the peer port on the active leader, - // with a randomized time duration. And it waits for most up-to-date node - // (current or new leader) applies the snapshot count of entries since the - // delay operation. - // The expected behavior is that cluster may elect a new leader, and - // the old leader gets isolated and behind the current active leader, - // and once delay operation is undone, the slow follower comes back - // and catches up, likely receiving a snapshot from the active leader. - // As always, after recovery, each member must be able to process client - // requests. - Case_RANDOM_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT Case = 207 - // DELAY_PEER_PORT_TX_RX_QUORUM delays outgoing/incoming packets from/to - // the peer ports on majority nodes of cluster. And it waits for - // "delay-ms" until recovery, likely to trigger election timeouts. - // The expected behavior is that cluster may elect a new leader, while - // quorum of nodes struggle with slow networks, and once delay operation - // is undone, nodes come back and cluster comes back operative. As always, - // after recovery, each member must be able to process client requests. - Case_DELAY_PEER_PORT_TX_RX_QUORUM Case = 208 - // RANDOM_DELAY_PEER_PORT_TX_RX_QUORUM delays outgoing/incoming packets - // from/to the peer ports on majority nodes of cluster, with randomized - // time durations. And it waits for "delay-ms" until recovery, likely - // to trigger election timeouts. - // The expected behavior is that cluster may elect a new leader, while - // quorum of nodes struggle with slow networks, and once delay operation - // is undone, nodes come back and cluster comes back operative. As always, - // after recovery, each member must be able to process client requests. - Case_RANDOM_DELAY_PEER_PORT_TX_RX_QUORUM Case = 209 - // DELAY_PEER_PORT_TX_RX_ALL delays outgoing/incoming packets from/to the - // peer ports on all nodes. And it waits for "delay-ms" until recovery, - // likely to trigger election timeouts. - // The expected behavior is that cluster may become totally inoperable, - // struggling with slow networks across the whole cluster. Once delay - // operation is undone, nodes come back and cluster comes back operative. - // As always, after recovery, each member must be able to process client - // requests. - Case_DELAY_PEER_PORT_TX_RX_ALL Case = 210 - // RANDOM_DELAY_PEER_PORT_TX_RX_ALL delays outgoing/incoming packets - // from/to the peer ports on all nodes, with randomized time durations. - // And it waits for "delay-ms" until recovery, likely to trigger - // election timeouts. - // The expected behavior is that cluster may become totally inoperable, - // struggling with slow networks across the whole cluster. Once delay - // operation is undone, nodes come back and cluster comes back operative. - // As always, after recovery, each member must be able to process client - // requests. - Case_RANDOM_DELAY_PEER_PORT_TX_RX_ALL Case = 211 - // NO_FAIL_WITH_STRESS stops injecting failures while testing the - // consistency and correctness under pressure loads, for the duration of - // "delay-ms". Goal is to ensure cluster be still making progress - // on recovery, and verify system does not deadlock following a sequence - // of failure injections. - // The expected behavior is that cluster remains fully operative in healthy - // condition. As always, after recovery, each member must be able to process - // client requests. - Case_NO_FAIL_WITH_STRESS Case = 300 - // NO_FAIL_WITH_NO_STRESS_FOR_LIVENESS neither injects failures nor - // sends stressig client requests to the cluster, for the duration of - // "delay-ms". Goal is to ensure cluster be still making progress - // on recovery, and verify system does not deadlock following a sequence - // of failure injections. - // The expected behavior is that cluster remains fully operative in healthy - // condition, and clients requests during liveness period succeed without - // errors. - // Note: this is how Google Chubby does failure injection testing - // https://static.googleusercontent.com/media/research.google.com/en//archive/paxos_made_live.pdf. - Case_NO_FAIL_WITH_NO_STRESS_FOR_LIVENESS Case = 301 - // FAILPOINTS injects failpoints to etcd server runtime, triggering panics - // in critical code paths. - Case_FAILPOINTS Case = 400 - // EXTERNAL runs external failure injection scripts. - Case_EXTERNAL Case = 500 -) - -var Case_name = map[int32]string{ - 0: "SIGTERM_ONE_FOLLOWER", - 1: "SIGTERM_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT", - 2: "SIGTERM_LEADER", - 3: "SIGTERM_LEADER_UNTIL_TRIGGER_SNAPSHOT", - 4: "SIGTERM_QUORUM", - 5: "SIGTERM_ALL", - 10: "SIGQUIT_AND_REMOVE_ONE_FOLLOWER", - 11: "SIGQUIT_AND_REMOVE_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT", - 12: "SIGQUIT_AND_REMOVE_LEADER", - 13: "SIGQUIT_AND_REMOVE_LEADER_UNTIL_TRIGGER_SNAPSHOT", - 14: "SIGQUIT_AND_REMOVE_QUORUM_AND_RESTORE_LEADER_SNAPSHOT_FROM_SCRATCH", - 100: "BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER", - 101: "BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT", - 102: "BLACKHOLE_PEER_PORT_TX_RX_LEADER", - 103: "BLACKHOLE_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT", - 104: "BLACKHOLE_PEER_PORT_TX_RX_QUORUM", - 105: "BLACKHOLE_PEER_PORT_TX_RX_ALL", - 200: "DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER", - 201: "RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER", - 202: "DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT", - 203: "RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT", - 204: "DELAY_PEER_PORT_TX_RX_LEADER", - 205: "RANDOM_DELAY_PEER_PORT_TX_RX_LEADER", - 206: "DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT", - 207: "RANDOM_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT", - 208: "DELAY_PEER_PORT_TX_RX_QUORUM", - 209: "RANDOM_DELAY_PEER_PORT_TX_RX_QUORUM", - 210: "DELAY_PEER_PORT_TX_RX_ALL", - 211: "RANDOM_DELAY_PEER_PORT_TX_RX_ALL", - 300: "NO_FAIL_WITH_STRESS", - 301: "NO_FAIL_WITH_NO_STRESS_FOR_LIVENESS", - 400: "FAILPOINTS", - 500: "EXTERNAL", -} -var Case_value = map[string]int32{ - "SIGTERM_ONE_FOLLOWER": 0, - "SIGTERM_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT": 1, - "SIGTERM_LEADER": 2, - "SIGTERM_LEADER_UNTIL_TRIGGER_SNAPSHOT": 3, - "SIGTERM_QUORUM": 4, - "SIGTERM_ALL": 5, - "SIGQUIT_AND_REMOVE_ONE_FOLLOWER": 10, - "SIGQUIT_AND_REMOVE_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT": 11, - "SIGQUIT_AND_REMOVE_LEADER": 12, - "SIGQUIT_AND_REMOVE_LEADER_UNTIL_TRIGGER_SNAPSHOT": 13, - "SIGQUIT_AND_REMOVE_QUORUM_AND_RESTORE_LEADER_SNAPSHOT_FROM_SCRATCH": 14, - "BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER": 100, - "BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT": 101, - "BLACKHOLE_PEER_PORT_TX_RX_LEADER": 102, - "BLACKHOLE_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT": 103, - "BLACKHOLE_PEER_PORT_TX_RX_QUORUM": 104, - "BLACKHOLE_PEER_PORT_TX_RX_ALL": 105, - "DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER": 200, - "RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER": 201, - "DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT": 202, - "RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT": 203, - "DELAY_PEER_PORT_TX_RX_LEADER": 204, - "RANDOM_DELAY_PEER_PORT_TX_RX_LEADER": 205, - "DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT": 206, - "RANDOM_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT": 207, - "DELAY_PEER_PORT_TX_RX_QUORUM": 208, - "RANDOM_DELAY_PEER_PORT_TX_RX_QUORUM": 209, - "DELAY_PEER_PORT_TX_RX_ALL": 210, - "RANDOM_DELAY_PEER_PORT_TX_RX_ALL": 211, - "NO_FAIL_WITH_STRESS": 300, - "NO_FAIL_WITH_NO_STRESS_FOR_LIVENESS": 301, - "FAILPOINTS": 400, - "EXTERNAL": 500, -} - -func (x Case) String() string { - return proto.EnumName(Case_name, int32(x)) -} -func (Case) EnumDescriptor() ([]byte, []int) { return fileDescriptorRpc, []int{1} } - -type Stresser int32 - -const ( - Stresser_KV Stresser = 0 - Stresser_LEASE Stresser = 1 - Stresser_ELECTION_RUNNER Stresser = 2 - Stresser_WATCH_RUNNER Stresser = 3 - Stresser_LOCK_RACER_RUNNER Stresser = 4 - Stresser_LEASE_RUNNER Stresser = 5 -) - -var Stresser_name = map[int32]string{ - 0: "KV", - 1: "LEASE", - 2: "ELECTION_RUNNER", - 3: "WATCH_RUNNER", - 4: "LOCK_RACER_RUNNER", - 5: "LEASE_RUNNER", -} -var Stresser_value = map[string]int32{ - "KV": 0, - "LEASE": 1, - "ELECTION_RUNNER": 2, - "WATCH_RUNNER": 3, - "LOCK_RACER_RUNNER": 4, - "LEASE_RUNNER": 5, -} - -func (x Stresser) String() string { - return proto.EnumName(Stresser_name, int32(x)) -} -func (Stresser) EnumDescriptor() ([]byte, []int) { return fileDescriptorRpc, []int{2} } - -type Checker int32 - -const ( - Checker_KV_HASH Checker = 0 - Checker_LEASE_EXPIRE Checker = 1 - Checker_RUNNER Checker = 2 - Checker_NO_CHECK Checker = 3 -) - -var Checker_name = map[int32]string{ - 0: "KV_HASH", - 1: "LEASE_EXPIRE", - 2: "RUNNER", - 3: "NO_CHECK", -} -var Checker_value = map[string]int32{ - "KV_HASH": 0, - "LEASE_EXPIRE": 1, - "RUNNER": 2, - "NO_CHECK": 3, -} - -func (x Checker) String() string { - return proto.EnumName(Checker_name, int32(x)) -} -func (Checker) EnumDescriptor() ([]byte, []int) { return fileDescriptorRpc, []int{3} } - -type Request struct { - Operation Operation `protobuf:"varint,1,opt,name=Operation,proto3,enum=rpcpb.Operation" json:"Operation,omitempty"` - // Member contains the same Member object from tester configuration. - Member *Member `protobuf:"bytes,2,opt,name=Member" json:"Member,omitempty"` - // Tester contains tester configuration. - Tester *Tester `protobuf:"bytes,3,opt,name=Tester" json:"Tester,omitempty"` -} - -func (m *Request) Reset() { *m = Request{} } -func (m *Request) String() string { return proto.CompactTextString(m) } -func (*Request) ProtoMessage() {} -func (*Request) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{0} } - -// SnapshotInfo contains SAVE_SNAPSHOT request results. -type SnapshotInfo struct { - MemberName string `protobuf:"bytes,1,opt,name=MemberName,proto3" json:"MemberName,omitempty"` - MemberClientURLs []string `protobuf:"bytes,2,rep,name=MemberClientURLs" json:"MemberClientURLs,omitempty"` - SnapshotPath string `protobuf:"bytes,3,opt,name=SnapshotPath,proto3" json:"SnapshotPath,omitempty"` - SnapshotFileSize string `protobuf:"bytes,4,opt,name=SnapshotFileSize,proto3" json:"SnapshotFileSize,omitempty"` - SnapshotTotalSize string `protobuf:"bytes,5,opt,name=SnapshotTotalSize,proto3" json:"SnapshotTotalSize,omitempty"` - SnapshotTotalKey int64 `protobuf:"varint,6,opt,name=SnapshotTotalKey,proto3" json:"SnapshotTotalKey,omitempty"` - SnapshotHash int64 `protobuf:"varint,7,opt,name=SnapshotHash,proto3" json:"SnapshotHash,omitempty"` - SnapshotRevision int64 `protobuf:"varint,8,opt,name=SnapshotRevision,proto3" json:"SnapshotRevision,omitempty"` - Took string `protobuf:"bytes,9,opt,name=Took,proto3" json:"Took,omitempty"` -} - -func (m *SnapshotInfo) Reset() { *m = SnapshotInfo{} } -func (m *SnapshotInfo) String() string { return proto.CompactTextString(m) } -func (*SnapshotInfo) ProtoMessage() {} -func (*SnapshotInfo) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{1} } - -type Response struct { - Success bool `protobuf:"varint,1,opt,name=Success,proto3" json:"Success,omitempty"` - Status string `protobuf:"bytes,2,opt,name=Status,proto3" json:"Status,omitempty"` - // Member contains the same Member object from tester request. - Member *Member `protobuf:"bytes,3,opt,name=Member" json:"Member,omitempty"` - // SnapshotInfo contains SAVE_SNAPSHOT request results. - SnapshotInfo *SnapshotInfo `protobuf:"bytes,4,opt,name=SnapshotInfo" json:"SnapshotInfo,omitempty"` -} - -func (m *Response) Reset() { *m = Response{} } -func (m *Response) String() string { return proto.CompactTextString(m) } -func (*Response) ProtoMessage() {} -func (*Response) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{2} } - -type Member struct { - // EtcdExecPath is the executable etcd binary path in agent server. - EtcdExecPath string `protobuf:"bytes,1,opt,name=EtcdExecPath,proto3" json:"EtcdExecPath,omitempty" yaml:"etcd-exec-path"` - // AgentAddr is the agent HTTP server address. - AgentAddr string `protobuf:"bytes,11,opt,name=AgentAddr,proto3" json:"AgentAddr,omitempty" yaml:"agent-addr"` - // FailpointHTTPAddr is the agent's failpoints HTTP server address. - FailpointHTTPAddr string `protobuf:"bytes,12,opt,name=FailpointHTTPAddr,proto3" json:"FailpointHTTPAddr,omitempty" yaml:"failpoint-http-addr"` - // BaseDir is the base directory where all logs and etcd data are stored. - BaseDir string `protobuf:"bytes,101,opt,name=BaseDir,proto3" json:"BaseDir,omitempty" yaml:"base-dir"` - // EtcdLogPath is the log file to store current etcd server logs. - EtcdLogPath string `protobuf:"bytes,102,opt,name=EtcdLogPath,proto3" json:"EtcdLogPath,omitempty" yaml:"etcd-log-path"` - // EtcdClientProxy is true when client traffic needs to be proxied. - // If true, listen client URL port must be different than advertise client URL port. - EtcdClientProxy bool `protobuf:"varint,201,opt,name=EtcdClientProxy,proto3" json:"EtcdClientProxy,omitempty" yaml:"etcd-client-proxy"` - // EtcdPeerProxy is true when peer traffic needs to be proxied. - // If true, listen peer URL port must be different than advertise peer URL port. - EtcdPeerProxy bool `protobuf:"varint,202,opt,name=EtcdPeerProxy,proto3" json:"EtcdPeerProxy,omitempty" yaml:"etcd-peer-proxy"` - // EtcdClientEndpoint is the etcd client endpoint. - EtcdClientEndpoint string `protobuf:"bytes,301,opt,name=EtcdClientEndpoint,proto3" json:"EtcdClientEndpoint,omitempty" yaml:"etcd-client-endpoint"` - // Etcd defines etcd binary configuration flags. - Etcd *Etcd `protobuf:"bytes,302,opt,name=Etcd" json:"Etcd,omitempty" yaml:"etcd"` - // EtcdOnSnapshotRestore defines one-time use configuration during etcd - // snapshot recovery process. - EtcdOnSnapshotRestore *Etcd `protobuf:"bytes,303,opt,name=EtcdOnSnapshotRestore" json:"EtcdOnSnapshotRestore,omitempty"` - // ClientCertData contains cert file contents from this member's etcd server. - ClientCertData string `protobuf:"bytes,401,opt,name=ClientCertData,proto3" json:"ClientCertData,omitempty" yaml:"client-cert-data"` - ClientCertPath string `protobuf:"bytes,402,opt,name=ClientCertPath,proto3" json:"ClientCertPath,omitempty" yaml:"client-cert-path"` - // ClientKeyData contains key file contents from this member's etcd server. - ClientKeyData string `protobuf:"bytes,403,opt,name=ClientKeyData,proto3" json:"ClientKeyData,omitempty" yaml:"client-key-data"` - ClientKeyPath string `protobuf:"bytes,404,opt,name=ClientKeyPath,proto3" json:"ClientKeyPath,omitempty" yaml:"client-key-path"` - // ClientTrustedCAData contains trusted CA file contents from this member's etcd server. - ClientTrustedCAData string `protobuf:"bytes,405,opt,name=ClientTrustedCAData,proto3" json:"ClientTrustedCAData,omitempty" yaml:"client-trusted-ca-data"` - ClientTrustedCAPath string `protobuf:"bytes,406,opt,name=ClientTrustedCAPath,proto3" json:"ClientTrustedCAPath,omitempty" yaml:"client-trusted-ca-path"` - // PeerCertData contains cert file contents from this member's etcd server. - PeerCertData string `protobuf:"bytes,501,opt,name=PeerCertData,proto3" json:"PeerCertData,omitempty" yaml:"peer-cert-data"` - PeerCertPath string `protobuf:"bytes,502,opt,name=PeerCertPath,proto3" json:"PeerCertPath,omitempty" yaml:"peer-cert-path"` - // PeerKeyData contains key file contents from this member's etcd server. - PeerKeyData string `protobuf:"bytes,503,opt,name=PeerKeyData,proto3" json:"PeerKeyData,omitempty" yaml:"peer-key-data"` - PeerKeyPath string `protobuf:"bytes,504,opt,name=PeerKeyPath,proto3" json:"PeerKeyPath,omitempty" yaml:"peer-key-path"` - // PeerTrustedCAData contains trusted CA file contents from this member's etcd server. - PeerTrustedCAData string `protobuf:"bytes,505,opt,name=PeerTrustedCAData,proto3" json:"PeerTrustedCAData,omitempty" yaml:"peer-trusted-ca-data"` - PeerTrustedCAPath string `protobuf:"bytes,506,opt,name=PeerTrustedCAPath,proto3" json:"PeerTrustedCAPath,omitempty" yaml:"peer-trusted-ca-path"` - // SnapshotPath is the snapshot file path to store or restore from. - SnapshotPath string `protobuf:"bytes,601,opt,name=SnapshotPath,proto3" json:"SnapshotPath,omitempty" yaml:"snapshot-path"` - // SnapshotInfo contains last SAVE_SNAPSHOT request results. - SnapshotInfo *SnapshotInfo `protobuf:"bytes,602,opt,name=SnapshotInfo" json:"SnapshotInfo,omitempty"` -} - -func (m *Member) Reset() { *m = Member{} } -func (m *Member) String() string { return proto.CompactTextString(m) } -func (*Member) ProtoMessage() {} -func (*Member) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{3} } - -type Tester struct { - DataDir string `protobuf:"bytes,1,opt,name=DataDir,proto3" json:"DataDir,omitempty" yaml:"data-dir"` - Network string `protobuf:"bytes,2,opt,name=Network,proto3" json:"Network,omitempty" yaml:"network"` - Addr string `protobuf:"bytes,3,opt,name=Addr,proto3" json:"Addr,omitempty" yaml:"addr"` - // DelayLatencyMsRv is the delay latency in milliseconds, - // to inject to simulated slow network. - DelayLatencyMs uint32 `protobuf:"varint,11,opt,name=DelayLatencyMs,proto3" json:"DelayLatencyMs,omitempty" yaml:"delay-latency-ms"` - // DelayLatencyMsRv is the delay latency random variable in milliseconds. - DelayLatencyMsRv uint32 `protobuf:"varint,12,opt,name=DelayLatencyMsRv,proto3" json:"DelayLatencyMsRv,omitempty" yaml:"delay-latency-ms-rv"` - // UpdatedDelayLatencyMs is the update delay latency in milliseconds, - // to inject to simulated slow network. It's the final latency to apply, - // in case the latency numbers are randomly generated from given delay latency field. - UpdatedDelayLatencyMs uint32 `protobuf:"varint,13,opt,name=UpdatedDelayLatencyMs,proto3" json:"UpdatedDelayLatencyMs,omitempty" yaml:"updated-delay-latency-ms"` - // RoundLimit is the limit of rounds to run failure set (-1 to run without limits). - RoundLimit int32 `protobuf:"varint,21,opt,name=RoundLimit,proto3" json:"RoundLimit,omitempty" yaml:"round-limit"` - // ExitOnCaseFail is true, then exit tester on first failure. - ExitOnCaseFail bool `protobuf:"varint,22,opt,name=ExitOnCaseFail,proto3" json:"ExitOnCaseFail,omitempty" yaml:"exit-on-failure"` - // EnablePprof is true to enable profiler. - EnablePprof bool `protobuf:"varint,23,opt,name=EnablePprof,proto3" json:"EnablePprof,omitempty" yaml:"enable-pprof"` - // CaseDelayMs is the delay duration after failure is injected. - // Useful when triggering snapshot or no-op failure cases. - CaseDelayMs uint32 `protobuf:"varint,31,opt,name=CaseDelayMs,proto3" json:"CaseDelayMs,omitempty" yaml:"case-delay-ms"` - // CaseShuffle is true to randomize failure injecting order. - CaseShuffle bool `protobuf:"varint,32,opt,name=CaseShuffle,proto3" json:"CaseShuffle,omitempty" yaml:"case-shuffle"` - // Cases is the selected test cases to schedule. - // If empty, run all failure cases. - Cases []string `protobuf:"bytes,33,rep,name=Cases" json:"Cases,omitempty" yaml:"cases"` - // FailpointCommands is the list of "gofail" commands - // (e.g. panic("etcd-tester"),1*sleep(1000). - FailpointCommands []string `protobuf:"bytes,34,rep,name=FailpointCommands" json:"FailpointCommands,omitempty" yaml:"failpoint-commands"` - // RunnerExecPath is a path of etcd-runner binary. - RunnerExecPath string `protobuf:"bytes,41,opt,name=RunnerExecPath,proto3" json:"RunnerExecPath,omitempty" yaml:"runner-exec-path"` - // ExternalExecPath is a path of script for enabling/disabling an external fault injector. - ExternalExecPath string `protobuf:"bytes,42,opt,name=ExternalExecPath,proto3" json:"ExternalExecPath,omitempty" yaml:"external-exec-path"` - // Stressers is the list of stresser types: - // KV, LEASE, ELECTION_RUNNER, WATCH_RUNNER, LOCK_RACER_RUNNER, LEASE_RUNNER. - Stressers []string `protobuf:"bytes,101,rep,name=Stressers" json:"Stressers,omitempty" yaml:"stressers"` - // Checkers is the list of consistency checker types: - // KV_HASH, LEASE_EXPIRE, NO_CHECK, RUNNER. - // Leave empty to skip consistency checks. - Checkers []string `protobuf:"bytes,102,rep,name=Checkers" json:"Checkers,omitempty" yaml:"checkers"` - // StressKeySize is the size of each small key written into etcd. - StressKeySize int32 `protobuf:"varint,201,opt,name=StressKeySize,proto3" json:"StressKeySize,omitempty" yaml:"stress-key-size"` - // StressKeySizeLarge is the size of each large key written into etcd. - StressKeySizeLarge int32 `protobuf:"varint,202,opt,name=StressKeySizeLarge,proto3" json:"StressKeySizeLarge,omitempty" yaml:"stress-key-size-large"` - // StressKeySuffixRange is the count of key range written into etcd. - // Stress keys are created with "fmt.Sprintf("foo%016x", rand.Intn(keySuffixRange)". - StressKeySuffixRange int32 `protobuf:"varint,203,opt,name=StressKeySuffixRange,proto3" json:"StressKeySuffixRange,omitempty" yaml:"stress-key-suffix-range"` - // StressKeySuffixRangeTxn is the count of key range written into etcd txn (max 100). - // Stress keys are created with "fmt.Sprintf("/k%03d", i)". - StressKeySuffixRangeTxn int32 `protobuf:"varint,204,opt,name=StressKeySuffixRangeTxn,proto3" json:"StressKeySuffixRangeTxn,omitempty" yaml:"stress-key-suffix-range-txn"` - // StressKeyTxnOps is the number of operations per a transaction (max 64). - StressKeyTxnOps int32 `protobuf:"varint,205,opt,name=StressKeyTxnOps,proto3" json:"StressKeyTxnOps,omitempty" yaml:"stress-key-txn-ops"` - // StressClients is the number of concurrent stressing clients - // with "one" shared TCP connection. - StressClients int32 `protobuf:"varint,301,opt,name=StressClients,proto3" json:"StressClients,omitempty" yaml:"stress-clients"` - // StressQPS is the maximum number of stresser requests per second. - StressQPS int32 `protobuf:"varint,302,opt,name=StressQPS,proto3" json:"StressQPS,omitempty" yaml:"stress-qps"` -} - -func (m *Tester) Reset() { *m = Tester{} } -func (m *Tester) String() string { return proto.CompactTextString(m) } -func (*Tester) ProtoMessage() {} -func (*Tester) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{4} } - -type Etcd struct { - Name string `protobuf:"bytes,1,opt,name=Name,proto3" json:"Name,omitempty" yaml:"name"` - DataDir string `protobuf:"bytes,2,opt,name=DataDir,proto3" json:"DataDir,omitempty" yaml:"data-dir"` - WALDir string `protobuf:"bytes,3,opt,name=WALDir,proto3" json:"WALDir,omitempty" yaml:"wal-dir"` - // HeartbeatIntervalMs is the time (in milliseconds) of a heartbeat interval. - // Default value is 100, which is 100ms. - HeartbeatIntervalMs int64 `protobuf:"varint,11,opt,name=HeartbeatIntervalMs,proto3" json:"HeartbeatIntervalMs,omitempty" yaml:"heartbeat-interval"` - // ElectionTimeoutMs is the time (in milliseconds) for an election to timeout. - // Default value is 1000, which is 1s. - ElectionTimeoutMs int64 `protobuf:"varint,12,opt,name=ElectionTimeoutMs,proto3" json:"ElectionTimeoutMs,omitempty" yaml:"election-timeout"` - ListenClientURLs []string `protobuf:"bytes,21,rep,name=ListenClientURLs" json:"ListenClientURLs,omitempty" yaml:"listen-client-urls"` - AdvertiseClientURLs []string `protobuf:"bytes,22,rep,name=AdvertiseClientURLs" json:"AdvertiseClientURLs,omitempty" yaml:"advertise-client-urls"` - ClientAutoTLS bool `protobuf:"varint,23,opt,name=ClientAutoTLS,proto3" json:"ClientAutoTLS,omitempty" yaml:"auto-tls"` - ClientCertAuth bool `protobuf:"varint,24,opt,name=ClientCertAuth,proto3" json:"ClientCertAuth,omitempty" yaml:"client-cert-auth"` - ClientCertFile string `protobuf:"bytes,25,opt,name=ClientCertFile,proto3" json:"ClientCertFile,omitempty" yaml:"cert-file"` - ClientKeyFile string `protobuf:"bytes,26,opt,name=ClientKeyFile,proto3" json:"ClientKeyFile,omitempty" yaml:"key-file"` - ClientTrustedCAFile string `protobuf:"bytes,27,opt,name=ClientTrustedCAFile,proto3" json:"ClientTrustedCAFile,omitempty" yaml:"trusted-ca-file"` - ListenPeerURLs []string `protobuf:"bytes,31,rep,name=ListenPeerURLs" json:"ListenPeerURLs,omitempty" yaml:"listen-peer-urls"` - AdvertisePeerURLs []string `protobuf:"bytes,32,rep,name=AdvertisePeerURLs" json:"AdvertisePeerURLs,omitempty" yaml:"initial-advertise-peer-urls"` - PeerAutoTLS bool `protobuf:"varint,33,opt,name=PeerAutoTLS,proto3" json:"PeerAutoTLS,omitempty" yaml:"peer-auto-tls"` - PeerClientCertAuth bool `protobuf:"varint,34,opt,name=PeerClientCertAuth,proto3" json:"PeerClientCertAuth,omitempty" yaml:"peer-client-cert-auth"` - PeerCertFile string `protobuf:"bytes,35,opt,name=PeerCertFile,proto3" json:"PeerCertFile,omitempty" yaml:"peer-cert-file"` - PeerKeyFile string `protobuf:"bytes,36,opt,name=PeerKeyFile,proto3" json:"PeerKeyFile,omitempty" yaml:"peer-key-file"` - PeerTrustedCAFile string `protobuf:"bytes,37,opt,name=PeerTrustedCAFile,proto3" json:"PeerTrustedCAFile,omitempty" yaml:"peer-trusted-ca-file"` - InitialCluster string `protobuf:"bytes,41,opt,name=InitialCluster,proto3" json:"InitialCluster,omitempty" yaml:"initial-cluster"` - InitialClusterState string `protobuf:"bytes,42,opt,name=InitialClusterState,proto3" json:"InitialClusterState,omitempty" yaml:"initial-cluster-state"` - InitialClusterToken string `protobuf:"bytes,43,opt,name=InitialClusterToken,proto3" json:"InitialClusterToken,omitempty" yaml:"initial-cluster-token"` - SnapshotCount int64 `protobuf:"varint,51,opt,name=SnapshotCount,proto3" json:"SnapshotCount,omitempty" yaml:"snapshot-count"` - QuotaBackendBytes int64 `protobuf:"varint,52,opt,name=QuotaBackendBytes,proto3" json:"QuotaBackendBytes,omitempty" yaml:"quota-backend-bytes"` - PreVote bool `protobuf:"varint,63,opt,name=PreVote,proto3" json:"PreVote,omitempty" yaml:"pre-vote"` - InitialCorruptCheck bool `protobuf:"varint,64,opt,name=InitialCorruptCheck,proto3" json:"InitialCorruptCheck,omitempty" yaml:"initial-corrupt-check"` -} - -func (m *Etcd) Reset() { *m = Etcd{} } -func (m *Etcd) String() string { return proto.CompactTextString(m) } -func (*Etcd) ProtoMessage() {} -func (*Etcd) Descriptor() ([]byte, []int) { return fileDescriptorRpc, []int{5} } - -func init() { - proto.RegisterType((*Request)(nil), "rpcpb.Request") - proto.RegisterType((*SnapshotInfo)(nil), "rpcpb.SnapshotInfo") - proto.RegisterType((*Response)(nil), "rpcpb.Response") - proto.RegisterType((*Member)(nil), "rpcpb.Member") - proto.RegisterType((*Tester)(nil), "rpcpb.Tester") - proto.RegisterType((*Etcd)(nil), "rpcpb.Etcd") - proto.RegisterEnum("rpcpb.Operation", Operation_name, Operation_value) - proto.RegisterEnum("rpcpb.Case", Case_name, Case_value) - proto.RegisterEnum("rpcpb.Stresser", Stresser_name, Stresser_value) - proto.RegisterEnum("rpcpb.Checker", Checker_name, Checker_value) -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// Client API for Transport service - -type TransportClient interface { - Transport(ctx context.Context, opts ...grpc.CallOption) (Transport_TransportClient, error) -} - -type transportClient struct { - cc *grpc.ClientConn -} - -func NewTransportClient(cc *grpc.ClientConn) TransportClient { - return &transportClient{cc} -} - -func (c *transportClient) Transport(ctx context.Context, opts ...grpc.CallOption) (Transport_TransportClient, error) { - stream, err := grpc.NewClientStream(ctx, &_Transport_serviceDesc.Streams[0], c.cc, "/rpcpb.Transport/Transport", opts...) - if err != nil { - return nil, err - } - x := &transportTransportClient{stream} - return x, nil -} - -type Transport_TransportClient interface { - Send(*Request) error - Recv() (*Response, error) - grpc.ClientStream -} - -type transportTransportClient struct { - grpc.ClientStream -} - -func (x *transportTransportClient) Send(m *Request) error { - return x.ClientStream.SendMsg(m) -} - -func (x *transportTransportClient) Recv() (*Response, error) { - m := new(Response) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -// Server API for Transport service - -type TransportServer interface { - Transport(Transport_TransportServer) error -} - -func RegisterTransportServer(s *grpc.Server, srv TransportServer) { - s.RegisterService(&_Transport_serviceDesc, srv) -} - -func _Transport_Transport_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(TransportServer).Transport(&transportTransportServer{stream}) -} - -type Transport_TransportServer interface { - Send(*Response) error - Recv() (*Request, error) - grpc.ServerStream -} - -type transportTransportServer struct { - grpc.ServerStream -} - -func (x *transportTransportServer) Send(m *Response) error { - return x.ServerStream.SendMsg(m) -} - -func (x *transportTransportServer) Recv() (*Request, error) { - m := new(Request) - if err := x.ServerStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -var _Transport_serviceDesc = grpc.ServiceDesc{ - ServiceName: "rpcpb.Transport", - HandlerType: (*TransportServer)(nil), - Methods: []grpc.MethodDesc{}, - Streams: []grpc.StreamDesc{ - { - StreamName: "Transport", - Handler: _Transport_Transport_Handler, - ServerStreams: true, - ClientStreams: true, - }, - }, - Metadata: "rpcpb/rpc.proto", -} - -func (m *Request) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Request) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Operation != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Operation)) - } - if m.Member != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Member.Size())) - n1, err := m.Member.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - } - if m.Tester != nil { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Tester.Size())) - n2, err := m.Tester.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - } - return i, nil -} - -func (m *SnapshotInfo) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SnapshotInfo) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.MemberName) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.MemberName))) - i += copy(dAtA[i:], m.MemberName) - } - if len(m.MemberClientURLs) > 0 { - for _, s := range m.MemberClientURLs { - dAtA[i] = 0x12 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if len(m.SnapshotPath) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.SnapshotPath))) - i += copy(dAtA[i:], m.SnapshotPath) - } - if len(m.SnapshotFileSize) > 0 { - dAtA[i] = 0x22 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.SnapshotFileSize))) - i += copy(dAtA[i:], m.SnapshotFileSize) - } - if len(m.SnapshotTotalSize) > 0 { - dAtA[i] = 0x2a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.SnapshotTotalSize))) - i += copy(dAtA[i:], m.SnapshotTotalSize) - } - if m.SnapshotTotalKey != 0 { - dAtA[i] = 0x30 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.SnapshotTotalKey)) - } - if m.SnapshotHash != 0 { - dAtA[i] = 0x38 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.SnapshotHash)) - } - if m.SnapshotRevision != 0 { - dAtA[i] = 0x40 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.SnapshotRevision)) - } - if len(m.Took) > 0 { - dAtA[i] = 0x4a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Took))) - i += copy(dAtA[i:], m.Took) - } - return i, nil -} - -func (m *Response) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Response) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Success { - dAtA[i] = 0x8 - i++ - if m.Success { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if len(m.Status) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Status))) - i += copy(dAtA[i:], m.Status) - } - if m.Member != nil { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Member.Size())) - n3, err := m.Member.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n3 - } - if m.SnapshotInfo != nil { - dAtA[i] = 0x22 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.SnapshotInfo.Size())) - n4, err := m.SnapshotInfo.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n4 - } - return i, nil -} - -func (m *Member) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Member) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.EtcdExecPath) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.EtcdExecPath))) - i += copy(dAtA[i:], m.EtcdExecPath) - } - if len(m.AgentAddr) > 0 { - dAtA[i] = 0x5a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.AgentAddr))) - i += copy(dAtA[i:], m.AgentAddr) - } - if len(m.FailpointHTTPAddr) > 0 { - dAtA[i] = 0x62 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.FailpointHTTPAddr))) - i += copy(dAtA[i:], m.FailpointHTTPAddr) - } - if len(m.BaseDir) > 0 { - dAtA[i] = 0xaa - i++ - dAtA[i] = 0x6 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.BaseDir))) - i += copy(dAtA[i:], m.BaseDir) - } - if len(m.EtcdLogPath) > 0 { - dAtA[i] = 0xb2 - i++ - dAtA[i] = 0x6 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.EtcdLogPath))) - i += copy(dAtA[i:], m.EtcdLogPath) - } - if m.EtcdClientProxy { - dAtA[i] = 0xc8 - i++ - dAtA[i] = 0xc - i++ - if m.EtcdClientProxy { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.EtcdPeerProxy { - dAtA[i] = 0xd0 - i++ - dAtA[i] = 0xc - i++ - if m.EtcdPeerProxy { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if len(m.EtcdClientEndpoint) > 0 { - dAtA[i] = 0xea - i++ - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.EtcdClientEndpoint))) - i += copy(dAtA[i:], m.EtcdClientEndpoint) - } - if m.Etcd != nil { - dAtA[i] = 0xf2 - i++ - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.Etcd.Size())) - n5, err := m.Etcd.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n5 - } - if m.EtcdOnSnapshotRestore != nil { - dAtA[i] = 0xfa - i++ - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.EtcdOnSnapshotRestore.Size())) - n6, err := m.EtcdOnSnapshotRestore.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n6 - } - if len(m.ClientCertData) > 0 { - dAtA[i] = 0x8a - i++ - dAtA[i] = 0x19 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ClientCertData))) - i += copy(dAtA[i:], m.ClientCertData) - } - if len(m.ClientCertPath) > 0 { - dAtA[i] = 0x92 - i++ - dAtA[i] = 0x19 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ClientCertPath))) - i += copy(dAtA[i:], m.ClientCertPath) - } - if len(m.ClientKeyData) > 0 { - dAtA[i] = 0x9a - i++ - dAtA[i] = 0x19 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ClientKeyData))) - i += copy(dAtA[i:], m.ClientKeyData) - } - if len(m.ClientKeyPath) > 0 { - dAtA[i] = 0xa2 - i++ - dAtA[i] = 0x19 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ClientKeyPath))) - i += copy(dAtA[i:], m.ClientKeyPath) - } - if len(m.ClientTrustedCAData) > 0 { - dAtA[i] = 0xaa - i++ - dAtA[i] = 0x19 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ClientTrustedCAData))) - i += copy(dAtA[i:], m.ClientTrustedCAData) - } - if len(m.ClientTrustedCAPath) > 0 { - dAtA[i] = 0xb2 - i++ - dAtA[i] = 0x19 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ClientTrustedCAPath))) - i += copy(dAtA[i:], m.ClientTrustedCAPath) - } - if len(m.PeerCertData) > 0 { - dAtA[i] = 0xaa - i++ - dAtA[i] = 0x1f - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.PeerCertData))) - i += copy(dAtA[i:], m.PeerCertData) - } - if len(m.PeerCertPath) > 0 { - dAtA[i] = 0xb2 - i++ - dAtA[i] = 0x1f - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.PeerCertPath))) - i += copy(dAtA[i:], m.PeerCertPath) - } - if len(m.PeerKeyData) > 0 { - dAtA[i] = 0xba - i++ - dAtA[i] = 0x1f - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.PeerKeyData))) - i += copy(dAtA[i:], m.PeerKeyData) - } - if len(m.PeerKeyPath) > 0 { - dAtA[i] = 0xc2 - i++ - dAtA[i] = 0x1f - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.PeerKeyPath))) - i += copy(dAtA[i:], m.PeerKeyPath) - } - if len(m.PeerTrustedCAData) > 0 { - dAtA[i] = 0xca - i++ - dAtA[i] = 0x1f - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.PeerTrustedCAData))) - i += copy(dAtA[i:], m.PeerTrustedCAData) - } - if len(m.PeerTrustedCAPath) > 0 { - dAtA[i] = 0xd2 - i++ - dAtA[i] = 0x1f - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.PeerTrustedCAPath))) - i += copy(dAtA[i:], m.PeerTrustedCAPath) - } - if len(m.SnapshotPath) > 0 { - dAtA[i] = 0xca - i++ - dAtA[i] = 0x25 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.SnapshotPath))) - i += copy(dAtA[i:], m.SnapshotPath) - } - if m.SnapshotInfo != nil { - dAtA[i] = 0xd2 - i++ - dAtA[i] = 0x25 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.SnapshotInfo.Size())) - n7, err := m.SnapshotInfo.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n7 - } - return i, nil -} - -func (m *Tester) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Tester) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.DataDir) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.DataDir))) - i += copy(dAtA[i:], m.DataDir) - } - if len(m.Network) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Network))) - i += copy(dAtA[i:], m.Network) - } - if len(m.Addr) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Addr))) - i += copy(dAtA[i:], m.Addr) - } - if m.DelayLatencyMs != 0 { - dAtA[i] = 0x58 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.DelayLatencyMs)) - } - if m.DelayLatencyMsRv != 0 { - dAtA[i] = 0x60 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.DelayLatencyMsRv)) - } - if m.UpdatedDelayLatencyMs != 0 { - dAtA[i] = 0x68 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.UpdatedDelayLatencyMs)) - } - if m.RoundLimit != 0 { - dAtA[i] = 0xa8 - i++ - dAtA[i] = 0x1 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.RoundLimit)) - } - if m.ExitOnCaseFail { - dAtA[i] = 0xb0 - i++ - dAtA[i] = 0x1 - i++ - if m.ExitOnCaseFail { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.EnablePprof { - dAtA[i] = 0xb8 - i++ - dAtA[i] = 0x1 - i++ - if m.EnablePprof { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.CaseDelayMs != 0 { - dAtA[i] = 0xf8 - i++ - dAtA[i] = 0x1 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.CaseDelayMs)) - } - if m.CaseShuffle { - dAtA[i] = 0x80 - i++ - dAtA[i] = 0x2 - i++ - if m.CaseShuffle { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if len(m.Cases) > 0 { - for _, s := range m.Cases { - dAtA[i] = 0x8a - i++ - dAtA[i] = 0x2 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if len(m.FailpointCommands) > 0 { - for _, s := range m.FailpointCommands { - dAtA[i] = 0x92 - i++ - dAtA[i] = 0x2 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if len(m.RunnerExecPath) > 0 { - dAtA[i] = 0xca - i++ - dAtA[i] = 0x2 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.RunnerExecPath))) - i += copy(dAtA[i:], m.RunnerExecPath) - } - if len(m.ExternalExecPath) > 0 { - dAtA[i] = 0xd2 - i++ - dAtA[i] = 0x2 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ExternalExecPath))) - i += copy(dAtA[i:], m.ExternalExecPath) - } - if len(m.Stressers) > 0 { - for _, s := range m.Stressers { - dAtA[i] = 0xaa - i++ - dAtA[i] = 0x6 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if len(m.Checkers) > 0 { - for _, s := range m.Checkers { - dAtA[i] = 0xb2 - i++ - dAtA[i] = 0x6 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if m.StressKeySize != 0 { - dAtA[i] = 0xc8 - i++ - dAtA[i] = 0xc - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.StressKeySize)) - } - if m.StressKeySizeLarge != 0 { - dAtA[i] = 0xd0 - i++ - dAtA[i] = 0xc - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.StressKeySizeLarge)) - } - if m.StressKeySuffixRange != 0 { - dAtA[i] = 0xd8 - i++ - dAtA[i] = 0xc - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.StressKeySuffixRange)) - } - if m.StressKeySuffixRangeTxn != 0 { - dAtA[i] = 0xe0 - i++ - dAtA[i] = 0xc - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.StressKeySuffixRangeTxn)) - } - if m.StressKeyTxnOps != 0 { - dAtA[i] = 0xe8 - i++ - dAtA[i] = 0xc - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.StressKeyTxnOps)) - } - if m.StressClients != 0 { - dAtA[i] = 0xe8 - i++ - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.StressClients)) - } - if m.StressQPS != 0 { - dAtA[i] = 0xf0 - i++ - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.StressQPS)) - } - return i, nil -} - -func (m *Etcd) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Etcd) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Name) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if len(m.DataDir) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.DataDir))) - i += copy(dAtA[i:], m.DataDir) - } - if len(m.WALDir) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.WALDir))) - i += copy(dAtA[i:], m.WALDir) - } - if m.HeartbeatIntervalMs != 0 { - dAtA[i] = 0x58 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.HeartbeatIntervalMs)) - } - if m.ElectionTimeoutMs != 0 { - dAtA[i] = 0x60 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.ElectionTimeoutMs)) - } - if len(m.ListenClientURLs) > 0 { - for _, s := range m.ListenClientURLs { - dAtA[i] = 0xaa - i++ - dAtA[i] = 0x1 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if len(m.AdvertiseClientURLs) > 0 { - for _, s := range m.AdvertiseClientURLs { - dAtA[i] = 0xb2 - i++ - dAtA[i] = 0x1 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if m.ClientAutoTLS { - dAtA[i] = 0xb8 - i++ - dAtA[i] = 0x1 - i++ - if m.ClientAutoTLS { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.ClientCertAuth { - dAtA[i] = 0xc0 - i++ - dAtA[i] = 0x1 - i++ - if m.ClientCertAuth { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if len(m.ClientCertFile) > 0 { - dAtA[i] = 0xca - i++ - dAtA[i] = 0x1 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ClientCertFile))) - i += copy(dAtA[i:], m.ClientCertFile) - } - if len(m.ClientKeyFile) > 0 { - dAtA[i] = 0xd2 - i++ - dAtA[i] = 0x1 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ClientKeyFile))) - i += copy(dAtA[i:], m.ClientKeyFile) - } - if len(m.ClientTrustedCAFile) > 0 { - dAtA[i] = 0xda - i++ - dAtA[i] = 0x1 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.ClientTrustedCAFile))) - i += copy(dAtA[i:], m.ClientTrustedCAFile) - } - if len(m.ListenPeerURLs) > 0 { - for _, s := range m.ListenPeerURLs { - dAtA[i] = 0xfa - i++ - dAtA[i] = 0x1 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if len(m.AdvertisePeerURLs) > 0 { - for _, s := range m.AdvertisePeerURLs { - dAtA[i] = 0x82 - i++ - dAtA[i] = 0x2 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if m.PeerAutoTLS { - dAtA[i] = 0x88 - i++ - dAtA[i] = 0x2 - i++ - if m.PeerAutoTLS { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.PeerClientCertAuth { - dAtA[i] = 0x90 - i++ - dAtA[i] = 0x2 - i++ - if m.PeerClientCertAuth { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if len(m.PeerCertFile) > 0 { - dAtA[i] = 0x9a - i++ - dAtA[i] = 0x2 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.PeerCertFile))) - i += copy(dAtA[i:], m.PeerCertFile) - } - if len(m.PeerKeyFile) > 0 { - dAtA[i] = 0xa2 - i++ - dAtA[i] = 0x2 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.PeerKeyFile))) - i += copy(dAtA[i:], m.PeerKeyFile) - } - if len(m.PeerTrustedCAFile) > 0 { - dAtA[i] = 0xaa - i++ - dAtA[i] = 0x2 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.PeerTrustedCAFile))) - i += copy(dAtA[i:], m.PeerTrustedCAFile) - } - if len(m.InitialCluster) > 0 { - dAtA[i] = 0xca - i++ - dAtA[i] = 0x2 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.InitialCluster))) - i += copy(dAtA[i:], m.InitialCluster) - } - if len(m.InitialClusterState) > 0 { - dAtA[i] = 0xd2 - i++ - dAtA[i] = 0x2 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.InitialClusterState))) - i += copy(dAtA[i:], m.InitialClusterState) - } - if len(m.InitialClusterToken) > 0 { - dAtA[i] = 0xda - i++ - dAtA[i] = 0x2 - i++ - i = encodeVarintRpc(dAtA, i, uint64(len(m.InitialClusterToken))) - i += copy(dAtA[i:], m.InitialClusterToken) - } - if m.SnapshotCount != 0 { - dAtA[i] = 0x98 - i++ - dAtA[i] = 0x3 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.SnapshotCount)) - } - if m.QuotaBackendBytes != 0 { - dAtA[i] = 0xa0 - i++ - dAtA[i] = 0x3 - i++ - i = encodeVarintRpc(dAtA, i, uint64(m.QuotaBackendBytes)) - } - if m.PreVote { - dAtA[i] = 0xf8 - i++ - dAtA[i] = 0x3 - i++ - if m.PreVote { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.InitialCorruptCheck { - dAtA[i] = 0x80 - i++ - dAtA[i] = 0x4 - i++ - if m.InitialCorruptCheck { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - return i, nil -} - -func encodeVarintRpc(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *Request) Size() (n int) { - var l int - _ = l - if m.Operation != 0 { - n += 1 + sovRpc(uint64(m.Operation)) - } - if m.Member != nil { - l = m.Member.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.Tester != nil { - l = m.Tester.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *SnapshotInfo) Size() (n int) { - var l int - _ = l - l = len(m.MemberName) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if len(m.MemberClientURLs) > 0 { - for _, s := range m.MemberClientURLs { - l = len(s) - n += 1 + l + sovRpc(uint64(l)) - } - } - l = len(m.SnapshotPath) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.SnapshotFileSize) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.SnapshotTotalSize) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.SnapshotTotalKey != 0 { - n += 1 + sovRpc(uint64(m.SnapshotTotalKey)) - } - if m.SnapshotHash != 0 { - n += 1 + sovRpc(uint64(m.SnapshotHash)) - } - if m.SnapshotRevision != 0 { - n += 1 + sovRpc(uint64(m.SnapshotRevision)) - } - l = len(m.Took) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *Response) Size() (n int) { - var l int - _ = l - if m.Success { - n += 2 - } - l = len(m.Status) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.Member != nil { - l = m.Member.Size() - n += 1 + l + sovRpc(uint64(l)) - } - if m.SnapshotInfo != nil { - l = m.SnapshotInfo.Size() - n += 1 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *Member) Size() (n int) { - var l int - _ = l - l = len(m.EtcdExecPath) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.AgentAddr) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.FailpointHTTPAddr) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.BaseDir) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.EtcdLogPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - if m.EtcdClientProxy { - n += 3 - } - if m.EtcdPeerProxy { - n += 3 - } - l = len(m.EtcdClientEndpoint) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - if m.Etcd != nil { - l = m.Etcd.Size() - n += 2 + l + sovRpc(uint64(l)) - } - if m.EtcdOnSnapshotRestore != nil { - l = m.EtcdOnSnapshotRestore.Size() - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.ClientCertData) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.ClientCertPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.ClientKeyData) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.ClientKeyPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.ClientTrustedCAData) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.ClientTrustedCAPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.PeerCertData) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.PeerCertPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.PeerKeyData) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.PeerKeyPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.PeerTrustedCAData) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.PeerTrustedCAPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.SnapshotPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - if m.SnapshotInfo != nil { - l = m.SnapshotInfo.Size() - n += 2 + l + sovRpc(uint64(l)) - } - return n -} - -func (m *Tester) Size() (n int) { - var l int - _ = l - l = len(m.DataDir) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Network) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.Addr) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.DelayLatencyMs != 0 { - n += 1 + sovRpc(uint64(m.DelayLatencyMs)) - } - if m.DelayLatencyMsRv != 0 { - n += 1 + sovRpc(uint64(m.DelayLatencyMsRv)) - } - if m.UpdatedDelayLatencyMs != 0 { - n += 1 + sovRpc(uint64(m.UpdatedDelayLatencyMs)) - } - if m.RoundLimit != 0 { - n += 2 + sovRpc(uint64(m.RoundLimit)) - } - if m.ExitOnCaseFail { - n += 3 - } - if m.EnablePprof { - n += 3 - } - if m.CaseDelayMs != 0 { - n += 2 + sovRpc(uint64(m.CaseDelayMs)) - } - if m.CaseShuffle { - n += 3 - } - if len(m.Cases) > 0 { - for _, s := range m.Cases { - l = len(s) - n += 2 + l + sovRpc(uint64(l)) - } - } - if len(m.FailpointCommands) > 0 { - for _, s := range m.FailpointCommands { - l = len(s) - n += 2 + l + sovRpc(uint64(l)) - } - } - l = len(m.RunnerExecPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.ExternalExecPath) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - if len(m.Stressers) > 0 { - for _, s := range m.Stressers { - l = len(s) - n += 2 + l + sovRpc(uint64(l)) - } - } - if len(m.Checkers) > 0 { - for _, s := range m.Checkers { - l = len(s) - n += 2 + l + sovRpc(uint64(l)) - } - } - if m.StressKeySize != 0 { - n += 2 + sovRpc(uint64(m.StressKeySize)) - } - if m.StressKeySizeLarge != 0 { - n += 2 + sovRpc(uint64(m.StressKeySizeLarge)) - } - if m.StressKeySuffixRange != 0 { - n += 2 + sovRpc(uint64(m.StressKeySuffixRange)) - } - if m.StressKeySuffixRangeTxn != 0 { - n += 2 + sovRpc(uint64(m.StressKeySuffixRangeTxn)) - } - if m.StressKeyTxnOps != 0 { - n += 2 + sovRpc(uint64(m.StressKeyTxnOps)) - } - if m.StressClients != 0 { - n += 2 + sovRpc(uint64(m.StressClients)) - } - if m.StressQPS != 0 { - n += 2 + sovRpc(uint64(m.StressQPS)) - } - return n -} - -func (m *Etcd) Size() (n int) { - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.DataDir) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - l = len(m.WALDir) - if l > 0 { - n += 1 + l + sovRpc(uint64(l)) - } - if m.HeartbeatIntervalMs != 0 { - n += 1 + sovRpc(uint64(m.HeartbeatIntervalMs)) - } - if m.ElectionTimeoutMs != 0 { - n += 1 + sovRpc(uint64(m.ElectionTimeoutMs)) - } - if len(m.ListenClientURLs) > 0 { - for _, s := range m.ListenClientURLs { - l = len(s) - n += 2 + l + sovRpc(uint64(l)) - } - } - if len(m.AdvertiseClientURLs) > 0 { - for _, s := range m.AdvertiseClientURLs { - l = len(s) - n += 2 + l + sovRpc(uint64(l)) - } - } - if m.ClientAutoTLS { - n += 3 - } - if m.ClientCertAuth { - n += 3 - } - l = len(m.ClientCertFile) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.ClientKeyFile) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.ClientTrustedCAFile) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - if len(m.ListenPeerURLs) > 0 { - for _, s := range m.ListenPeerURLs { - l = len(s) - n += 2 + l + sovRpc(uint64(l)) - } - } - if len(m.AdvertisePeerURLs) > 0 { - for _, s := range m.AdvertisePeerURLs { - l = len(s) - n += 2 + l + sovRpc(uint64(l)) - } - } - if m.PeerAutoTLS { - n += 3 - } - if m.PeerClientCertAuth { - n += 3 - } - l = len(m.PeerCertFile) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.PeerKeyFile) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.PeerTrustedCAFile) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.InitialCluster) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.InitialClusterState) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - l = len(m.InitialClusterToken) - if l > 0 { - n += 2 + l + sovRpc(uint64(l)) - } - if m.SnapshotCount != 0 { - n += 2 + sovRpc(uint64(m.SnapshotCount)) - } - if m.QuotaBackendBytes != 0 { - n += 2 + sovRpc(uint64(m.QuotaBackendBytes)) - } - if m.PreVote { - n += 3 - } - if m.InitialCorruptCheck { - n += 3 - } - return n -} - -func sovRpc(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozRpc(x uint64) (n int) { - return sovRpc(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Request) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Request: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Request: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Operation", wireType) - } - m.Operation = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Operation |= (Operation(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Member", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Member == nil { - m.Member = &Member{} - } - if err := m.Member.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Tester", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Tester == nil { - m.Tester = &Tester{} - } - if err := m.Tester.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *SnapshotInfo) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SnapshotInfo: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SnapshotInfo: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MemberName", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.MemberName = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MemberClientURLs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.MemberClientURLs = append(m.MemberClientURLs, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SnapshotPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotFileSize", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SnapshotFileSize = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotTotalSize", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SnapshotTotalSize = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotTotalKey", wireType) - } - m.SnapshotTotalKey = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.SnapshotTotalKey |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 7: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotHash", wireType) - } - m.SnapshotHash = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.SnapshotHash |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotRevision", wireType) - } - m.SnapshotRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.SnapshotRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 9: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Took", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Took = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Response) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Response: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Response: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Success", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Success = bool(v != 0) - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Status", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Status = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Member", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Member == nil { - m.Member = &Member{} - } - if err := m.Member.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotInfo", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.SnapshotInfo == nil { - m.SnapshotInfo = &SnapshotInfo{} - } - if err := m.SnapshotInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Member) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Member: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Member: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EtcdExecPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.EtcdExecPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 11: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AgentAddr", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.AgentAddr = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 12: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field FailpointHTTPAddr", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.FailpointHTTPAddr = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 101: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BaseDir", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.BaseDir = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 102: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EtcdLogPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.EtcdLogPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 201: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field EtcdClientProxy", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.EtcdClientProxy = bool(v != 0) - case 202: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field EtcdPeerProxy", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.EtcdPeerProxy = bool(v != 0) - case 301: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EtcdClientEndpoint", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.EtcdClientEndpoint = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 302: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Etcd", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Etcd == nil { - m.Etcd = &Etcd{} - } - if err := m.Etcd.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 303: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EtcdOnSnapshotRestore", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.EtcdOnSnapshotRestore == nil { - m.EtcdOnSnapshotRestore = &Etcd{} - } - if err := m.EtcdOnSnapshotRestore.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 401: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientCertData", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientCertData = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 402: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientCertPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientCertPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 403: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientKeyData", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientKeyData = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 404: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientKeyPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientKeyPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 405: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientTrustedCAData", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientTrustedCAData = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 406: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientTrustedCAPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientTrustedCAPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 501: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerCertData", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerCertData = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 502: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerCertPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerCertPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 503: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerKeyData", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerKeyData = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 504: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerKeyPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerKeyPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 505: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerTrustedCAData", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerTrustedCAData = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 506: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerTrustedCAPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerTrustedCAPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 601: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SnapshotPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 602: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotInfo", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.SnapshotInfo == nil { - m.SnapshotInfo = &SnapshotInfo{} - } - if err := m.SnapshotInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Tester) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Tester: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Tester: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field DataDir", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.DataDir = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Network", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Network = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Addr", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Addr = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 11: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field DelayLatencyMs", wireType) - } - m.DelayLatencyMs = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.DelayLatencyMs |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 12: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field DelayLatencyMsRv", wireType) - } - m.DelayLatencyMsRv = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.DelayLatencyMsRv |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 13: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field UpdatedDelayLatencyMs", wireType) - } - m.UpdatedDelayLatencyMs = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.UpdatedDelayLatencyMs |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 21: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RoundLimit", wireType) - } - m.RoundLimit = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RoundLimit |= (int32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 22: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ExitOnCaseFail", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.ExitOnCaseFail = bool(v != 0) - case 23: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field EnablePprof", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.EnablePprof = bool(v != 0) - case 31: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CaseDelayMs", wireType) - } - m.CaseDelayMs = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.CaseDelayMs |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 32: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CaseShuffle", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.CaseShuffle = bool(v != 0) - case 33: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Cases", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Cases = append(m.Cases, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 34: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field FailpointCommands", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.FailpointCommands = append(m.FailpointCommands, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 41: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RunnerExecPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RunnerExecPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 42: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ExternalExecPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ExternalExecPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 101: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Stressers", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Stressers = append(m.Stressers, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 102: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Checkers", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Checkers = append(m.Checkers, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 201: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StressKeySize", wireType) - } - m.StressKeySize = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StressKeySize |= (int32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 202: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StressKeySizeLarge", wireType) - } - m.StressKeySizeLarge = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StressKeySizeLarge |= (int32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 203: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StressKeySuffixRange", wireType) - } - m.StressKeySuffixRange = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StressKeySuffixRange |= (int32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 204: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StressKeySuffixRangeTxn", wireType) - } - m.StressKeySuffixRangeTxn = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StressKeySuffixRangeTxn |= (int32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 205: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StressKeyTxnOps", wireType) - } - m.StressKeyTxnOps = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StressKeyTxnOps |= (int32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 301: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StressClients", wireType) - } - m.StressClients = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StressClients |= (int32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 302: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StressQPS", wireType) - } - m.StressQPS = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StressQPS |= (int32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Etcd) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Etcd: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Etcd: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field DataDir", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.DataDir = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field WALDir", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.WALDir = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 11: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field HeartbeatIntervalMs", wireType) - } - m.HeartbeatIntervalMs = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.HeartbeatIntervalMs |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 12: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ElectionTimeoutMs", wireType) - } - m.ElectionTimeoutMs = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ElectionTimeoutMs |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 21: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ListenClientURLs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ListenClientURLs = append(m.ListenClientURLs, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 22: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AdvertiseClientURLs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.AdvertiseClientURLs = append(m.AdvertiseClientURLs, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 23: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientAutoTLS", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.ClientAutoTLS = bool(v != 0) - case 24: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientCertAuth", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.ClientCertAuth = bool(v != 0) - case 25: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientCertFile", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientCertFile = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 26: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientKeyFile", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientKeyFile = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 27: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientTrustedCAFile", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientTrustedCAFile = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 31: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ListenPeerURLs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ListenPeerURLs = append(m.ListenPeerURLs, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 32: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AdvertisePeerURLs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.AdvertisePeerURLs = append(m.AdvertisePeerURLs, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 33: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerAutoTLS", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.PeerAutoTLS = bool(v != 0) - case 34: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerClientCertAuth", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.PeerClientCertAuth = bool(v != 0) - case 35: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerCertFile", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerCertFile = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 36: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerKeyFile", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerKeyFile = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 37: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeerTrustedCAFile", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PeerTrustedCAFile = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 41: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field InitialCluster", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.InitialCluster = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 42: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field InitialClusterState", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.InitialClusterState = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 43: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field InitialClusterToken", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRpc - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.InitialClusterToken = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 51: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SnapshotCount", wireType) - } - m.SnapshotCount = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.SnapshotCount |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 52: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field QuotaBackendBytes", wireType) - } - m.QuotaBackendBytes = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.QuotaBackendBytes |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 63: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PreVote", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.PreVote = bool(v != 0) - case 64: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field InitialCorruptCheck", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.InitialCorruptCheck = bool(v != 0) - default: - iNdEx = preIndex - skippy, err := skipRpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipRpc(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthRpc - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipRpc(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthRpc = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowRpc = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("rpcpb/rpc.proto", fileDescriptorRpc) } - -var fileDescriptorRpc = []byte{ - // 2808 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x59, 0xdb, 0x73, 0xdb, 0xc6, - 0xf5, 0x16, 0x44, 0x5d, 0x57, 0x37, 0x68, 0x65, 0xd9, 0xf0, 0x4d, 0x90, 0xe1, 0x38, 0x3f, 0x59, - 0x09, 0xec, 0xfc, 0xec, 0x4c, 0x2e, 0x4e, 0x13, 0x07, 0xa4, 0x20, 0x8b, 0x15, 0x44, 0xd2, 0x4b, - 0xc8, 0x76, 0x9e, 0x38, 0x10, 0xb9, 0x92, 0x30, 0xa6, 0x00, 0x06, 0x58, 0x2a, 0x52, 0xfe, 0x81, - 0xbe, 0xf6, 0x3e, 0xed, 0x4c, 0x9f, 0xfa, 0xdc, 0xb4, 0xff, 0x86, 0x73, 0x6b, 0xd3, 0xf6, 0xa9, - 0xed, 0x0c, 0xa7, 0x4d, 0x5f, 0xfa, 0xd4, 0x07, 0x4e, 0x6f, 0xe9, 0x53, 0x67, 0x77, 0x01, 0x71, - 0x01, 0x90, 0x92, 0x9e, 0xa4, 0x3d, 0xe7, 0xfb, 0xbe, 0x3d, 0xbb, 0x67, 0xb1, 0xe7, 0x00, 0x04, - 0x73, 0x41, 0xab, 0xde, 0xda, 0xb9, 0x1b, 0xb4, 0xea, 0x77, 0x5a, 0x81, 0x4f, 0x7c, 0x38, 0xca, - 0x0c, 0x57, 0xf4, 0x3d, 0x97, 0xec, 0xb7, 0x77, 0xee, 0xd4, 0xfd, 0x83, 0xbb, 0x7b, 0xfe, 0x9e, - 0x7f, 0x97, 0x79, 0x77, 0xda, 0xbb, 0x6c, 0xc4, 0x06, 0xec, 0x3f, 0xce, 0xd2, 0xbe, 0x23, 0x81, - 0x71, 0x84, 0x3f, 0x6c, 0xe3, 0x90, 0xc0, 0x3b, 0x60, 0xb2, 0xdc, 0xc2, 0x81, 0x43, 0x5c, 0xdf, - 0x53, 0xa4, 0x65, 0x69, 0x65, 0xf6, 0x9e, 0x7c, 0x87, 0xa9, 0xde, 0x39, 0xb1, 0xa3, 0x1e, 0x04, - 0xde, 0x02, 0x63, 0x5b, 0xf8, 0x60, 0x07, 0x07, 0xca, 0xf0, 0xb2, 0xb4, 0x32, 0x75, 0x6f, 0x26, - 0x02, 0x73, 0x23, 0x8a, 0x9c, 0x14, 0x66, 0xe3, 0x90, 0xe0, 0x40, 0xc9, 0x25, 0x60, 0xdc, 0x88, - 0x22, 0xa7, 0xf6, 0xb7, 0x61, 0x30, 0x5d, 0xf5, 0x9c, 0x56, 0xb8, 0xef, 0x93, 0xa2, 0xb7, 0xeb, - 0xc3, 0x25, 0x00, 0xb8, 0x42, 0xc9, 0x39, 0xc0, 0x2c, 0x9e, 0x49, 0x24, 0x58, 0xe0, 0x2a, 0x90, - 0xf9, 0xa8, 0xd0, 0x74, 0xb1, 0x47, 0xb6, 0x91, 0x15, 0x2a, 0xc3, 0xcb, 0xb9, 0x95, 0x49, 0x94, - 0xb1, 0x43, 0xad, 0xa7, 0x5d, 0x71, 0xc8, 0x3e, 0x8b, 0x64, 0x12, 0x25, 0x6c, 0x54, 0x2f, 0x1e, - 0xaf, 0xbb, 0x4d, 0x5c, 0x75, 0x3f, 0xc6, 0xca, 0x08, 0xc3, 0x65, 0xec, 0xf0, 0x55, 0x30, 0x1f, - 0xdb, 0x6c, 0x9f, 0x38, 0x4d, 0x06, 0x1e, 0x65, 0xe0, 0xac, 0x43, 0x54, 0x66, 0xc6, 0x4d, 0x7c, - 0xac, 0x8c, 0x2d, 0x4b, 0x2b, 0x39, 0x94, 0xb1, 0x8b, 0x91, 0x6e, 0x38, 0xe1, 0xbe, 0x32, 0xce, - 0x70, 0x09, 0x9b, 0xa8, 0x87, 0xf0, 0xa1, 0x1b, 0xd2, 0x7c, 0x4d, 0x24, 0xf5, 0x62, 0x3b, 0x84, - 0x60, 0xc4, 0xf6, 0xfd, 0xe7, 0xca, 0x24, 0x0b, 0x8e, 0xfd, 0xaf, 0xfd, 0x4c, 0x02, 0x13, 0x08, - 0x87, 0x2d, 0xdf, 0x0b, 0x31, 0x54, 0xc0, 0x78, 0xb5, 0x5d, 0xaf, 0xe3, 0x30, 0x64, 0x7b, 0x3c, - 0x81, 0xe2, 0x21, 0xbc, 0x08, 0xc6, 0xaa, 0xc4, 0x21, 0xed, 0x90, 0xe5, 0x77, 0x12, 0x45, 0x23, - 0x21, 0xef, 0xb9, 0xd3, 0xf2, 0xfe, 0x66, 0x32, 0x9f, 0x6c, 0x2f, 0xa7, 0xee, 0x2d, 0x44, 0x60, - 0xd1, 0x85, 0x12, 0x40, 0xed, 0x4f, 0xd3, 0xf1, 0x04, 0xf0, 0x5d, 0x30, 0x6d, 0x92, 0x7a, 0xc3, - 0x3c, 0xc2, 0x75, 0x96, 0x37, 0x76, 0x0a, 0xf2, 0x97, 0xbb, 0x1d, 0x75, 0xf1, 0xd8, 0x39, 0x68, - 0x3e, 0xd0, 0x30, 0xa9, 0x37, 0x74, 0x7c, 0x84, 0xeb, 0x7a, 0xcb, 0x21, 0xfb, 0x1a, 0x4a, 0xc0, - 0xe1, 0x7d, 0x30, 0x69, 0xec, 0x61, 0x8f, 0x18, 0x8d, 0x46, 0xa0, 0x4c, 0x31, 0xee, 0x62, 0xb7, - 0xa3, 0xce, 0x73, 0xae, 0x43, 0x5d, 0xba, 0xd3, 0x68, 0x04, 0x1a, 0xea, 0xe1, 0xa0, 0x05, 0xe6, - 0xd7, 0x1d, 0xb7, 0xd9, 0xf2, 0x5d, 0x8f, 0x6c, 0xd8, 0x76, 0x85, 0x91, 0xa7, 0x19, 0x79, 0xa9, - 0xdb, 0x51, 0xaf, 0x70, 0xf2, 0x6e, 0x0c, 0xd1, 0xf7, 0x09, 0x69, 0x45, 0x2a, 0x59, 0x22, 0xd4, - 0xc1, 0x78, 0xde, 0x09, 0xf1, 0x9a, 0x1b, 0x28, 0x98, 0x69, 0x2c, 0x74, 0x3b, 0xea, 0x1c, 0xd7, - 0xd8, 0x71, 0x42, 0xac, 0x37, 0xdc, 0x40, 0x43, 0x31, 0x06, 0x3e, 0x00, 0x53, 0x74, 0x05, 0x96, - 0xbf, 0xc7, 0xd6, 0xbb, 0xcb, 0x28, 0x4a, 0xb7, 0xa3, 0x5e, 0x10, 0xd6, 0xdb, 0xf4, 0xf7, 0xa2, - 0xe5, 0x8a, 0x60, 0xf8, 0x08, 0xcc, 0xd1, 0x21, 0x3f, 0xf6, 0x95, 0xc0, 0x3f, 0x3a, 0x56, 0x3e, - 0x65, 0x29, 0xcd, 0x5f, 0xeb, 0x76, 0x54, 0x45, 0x10, 0xa8, 0x33, 0x88, 0xde, 0xa2, 0x18, 0x0d, - 0xa5, 0x59, 0xd0, 0x00, 0x33, 0xd4, 0x54, 0xc1, 0x38, 0xe0, 0x32, 0x9f, 0x71, 0x99, 0x2b, 0xdd, - 0x8e, 0x7a, 0x51, 0x90, 0x69, 0x61, 0x1c, 0xc4, 0x22, 0x49, 0x06, 0xac, 0x00, 0xd8, 0x53, 0x35, - 0xbd, 0x06, 0xdb, 0x14, 0xe5, 0x13, 0x76, 0x90, 0xf2, 0x6a, 0xb7, 0xa3, 0x5e, 0xcd, 0x86, 0x83, - 0x23, 0x98, 0x86, 0xfa, 0x70, 0xe1, 0xff, 0x83, 0x11, 0x6a, 0x55, 0x7e, 0xc9, 0x2f, 0x9b, 0xa9, - 0xe8, 0x1c, 0x51, 0x5b, 0x7e, 0xae, 0xdb, 0x51, 0xa7, 0x7a, 0x82, 0x1a, 0x62, 0x50, 0x98, 0x07, - 0x8b, 0xf4, 0x6f, 0xd9, 0xeb, 0x3d, 0x15, 0x21, 0xf1, 0x03, 0xac, 0xfc, 0x2a, 0xab, 0x81, 0xfa, - 0x43, 0xe1, 0x1a, 0x98, 0xe5, 0x81, 0x14, 0x70, 0x40, 0xd6, 0x1c, 0xe2, 0x28, 0xdf, 0x63, 0x97, - 0x47, 0xfe, 0x6a, 0xb7, 0xa3, 0x5e, 0xe2, 0x73, 0x46, 0xf1, 0xd7, 0x71, 0x40, 0xf4, 0x86, 0x43, - 0x1c, 0x0d, 0xa5, 0x38, 0x49, 0x15, 0x96, 0xd9, 0xef, 0x9f, 0xaa, 0xc2, 0xb3, 0x9b, 0xe2, 0xd0, - 0xbc, 0x70, 0xcb, 0x26, 0x3e, 0x66, 0xa1, 0xfc, 0x80, 0x8b, 0x08, 0x79, 0x89, 0x44, 0x9e, 0xe3, - 0xe3, 0x28, 0x92, 0x24, 0x23, 0x21, 0xc1, 0xe2, 0xf8, 0xe1, 0x69, 0x12, 0x3c, 0x8c, 0x24, 0x03, - 0xda, 0x60, 0x81, 0x1b, 0xec, 0xa0, 0x1d, 0x12, 0xdc, 0x28, 0x18, 0x2c, 0x96, 0x1f, 0x71, 0xa1, - 0x1b, 0xdd, 0x8e, 0x7a, 0x3d, 0x21, 0x44, 0x38, 0x4c, 0xaf, 0x3b, 0x51, 0x48, 0xfd, 0xe8, 0x7d, - 0x54, 0x59, 0x78, 0x3f, 0x3e, 0x87, 0x2a, 0x8f, 0xb2, 0x1f, 0x1d, 0xbe, 0x07, 0xa6, 0xe9, 0x99, - 0x3c, 0xc9, 0xdd, 0x3f, 0x73, 0xe9, 0x0b, 0x84, 0x9d, 0x61, 0x21, 0x73, 0x09, 0xbc, 0xc8, 0x67, - 0xe1, 0xfc, 0xeb, 0x14, 0x7e, 0x74, 0x01, 0x89, 0x78, 0xf8, 0x0e, 0x98, 0xa2, 0xe3, 0x38, 0x5f, - 0xff, 0xce, 0xa5, 0x9f, 0x67, 0x46, 0xef, 0x65, 0x4b, 0x44, 0x0b, 0x64, 0x36, 0xf7, 0x7f, 0x06, - 0x93, 0xa3, 0xcb, 0x40, 0x40, 0xc3, 0x12, 0x98, 0xa7, 0xc3, 0x64, 0x8e, 0xbe, 0xc9, 0xa5, 0x9f, - 0x3f, 0x26, 0x91, 0xc9, 0x50, 0x96, 0x9a, 0xd1, 0x63, 0x21, 0xfd, 0xf7, 0x4c, 0x3d, 0x1e, 0x59, - 0x96, 0x4a, 0x6f, 0xf6, 0x44, 0x45, 0xfe, 0xc3, 0x48, 0x7a, 0x75, 0x61, 0xe4, 0x8e, 0x37, 0x36, - 0x51, 0xac, 0xdf, 0x4a, 0x15, 0x97, 0x3f, 0x9e, 0xbb, 0xba, 0xfc, 0x7c, 0x3a, 0xee, 0x47, 0xe8, - 0xdd, 0x4c, 0xd7, 0x46, 0xef, 0x66, 0x29, 0x7d, 0x37, 0xd3, 0x8d, 0x88, 0xee, 0xe6, 0x08, 0x03, - 0x5f, 0x05, 0xe3, 0x25, 0x4c, 0x3e, 0xf2, 0x83, 0xe7, 0xbc, 0x20, 0xe6, 0x61, 0xb7, 0xa3, 0xce, - 0x72, 0xb8, 0xc7, 0x1d, 0x1a, 0x8a, 0x21, 0xf0, 0x26, 0x18, 0x61, 0x95, 0x83, 0x6f, 0x91, 0x70, - 0x43, 0xf1, 0x52, 0xc1, 0x9c, 0xb0, 0x00, 0x66, 0xd7, 0x70, 0xd3, 0x39, 0xb6, 0x1c, 0x82, 0xbd, - 0xfa, 0xf1, 0x56, 0xc8, 0xaa, 0xd4, 0x8c, 0x78, 0x2d, 0x34, 0xa8, 0x5f, 0x6f, 0x72, 0x80, 0x7e, - 0x10, 0x6a, 0x28, 0x45, 0x81, 0xdf, 0x06, 0x72, 0xd2, 0x82, 0x0e, 0x59, 0xbd, 0x9a, 0x11, 0xeb, - 0x55, 0x5a, 0x46, 0x0f, 0x0e, 0x35, 0x94, 0xe1, 0xc1, 0x0f, 0xc0, 0xe2, 0x76, 0xab, 0xe1, 0x10, - 0xdc, 0x48, 0xc5, 0x35, 0xc3, 0x04, 0x6f, 0x76, 0x3b, 0xaa, 0xca, 0x05, 0xdb, 0x1c, 0xa6, 0x67, - 0xe3, 0xeb, 0xaf, 0x00, 0xdf, 0x00, 0x00, 0xf9, 0x6d, 0xaf, 0x61, 0xb9, 0x07, 0x2e, 0x51, 0x16, - 0x97, 0xa5, 0x95, 0xd1, 0xfc, 0xc5, 0x6e, 0x47, 0x85, 0x5c, 0x2f, 0xa0, 0x3e, 0xbd, 0x49, 0x9d, - 0x1a, 0x12, 0x90, 0x30, 0x0f, 0x66, 0xcd, 0x23, 0x97, 0x94, 0xbd, 0x82, 0x13, 0x62, 0x5a, 0x60, - 0x95, 0x8b, 0x99, 0x6a, 0x74, 0xe4, 0x12, 0xdd, 0xf7, 0x74, 0x5a, 0x94, 0xdb, 0x01, 0xd6, 0x50, - 0x8a, 0x01, 0xdf, 0x06, 0x53, 0xa6, 0xe7, 0xec, 0x34, 0x71, 0xa5, 0x15, 0xf8, 0xbb, 0xca, 0x25, - 0x26, 0x70, 0xa9, 0xdb, 0x51, 0x17, 0x22, 0x01, 0xe6, 0xd4, 0x5b, 0xd4, 0x4b, 0xab, 0x6a, 0x0f, - 0x4b, 0x2b, 0x32, 0x95, 0x61, 0x8b, 0xd9, 0x0a, 0x15, 0x95, 0xed, 0x83, 0x70, 0x4c, 0xeb, 0xac, - 0x88, 0xb3, 0x4d, 0xa0, 0x8b, 0x17, 0xc1, 0x74, 0x5a, 0x3a, 0xac, 0xee, 0xb7, 0x77, 0x77, 0x9b, - 0x58, 0x59, 0x4e, 0x4f, 0xcb, 0xb8, 0x21, 0xf7, 0x46, 0xd4, 0x08, 0x0b, 0x5f, 0x06, 0xa3, 0x74, - 0x18, 0x2a, 0x37, 0x68, 0x4b, 0x9b, 0x97, 0xbb, 0x1d, 0x75, 0xba, 0x47, 0x0a, 0x35, 0xc4, 0xdd, - 0x70, 0x53, 0xe8, 0x56, 0x0a, 0xfe, 0xc1, 0x81, 0xe3, 0x35, 0x42, 0x45, 0x63, 0x9c, 0xeb, 0xdd, - 0x8e, 0x7a, 0x39, 0xdd, 0xad, 0xd4, 0x23, 0x8c, 0xd8, 0xac, 0xc4, 0x3c, 0x7a, 0x1c, 0x51, 0xdb, - 0xf3, 0x70, 0x70, 0xd2, 0x70, 0xdd, 0x4e, 0x57, 0xa9, 0x80, 0xf9, 0xc5, 0x96, 0x2b, 0x45, 0x81, - 0x45, 0x20, 0x9b, 0x47, 0x04, 0x07, 0x9e, 0xd3, 0x3c, 0x91, 0x59, 0x65, 0x32, 0x42, 0x40, 0x38, - 0x42, 0x88, 0x42, 0x19, 0x1a, 0xbc, 0x07, 0x26, 0xab, 0x24, 0xc0, 0x61, 0x88, 0x83, 0x50, 0xc1, - 0x6c, 0x51, 0x17, 0xba, 0x1d, 0x55, 0x8e, 0x2e, 0x88, 0xd8, 0xa5, 0xa1, 0x1e, 0x0c, 0xde, 0x05, - 0x13, 0x85, 0x7d, 0x5c, 0x7f, 0x4e, 0x29, 0xbb, 0x8c, 0x22, 0x3c, 0xd5, 0xf5, 0xc8, 0xa3, 0xa1, - 0x13, 0x10, 0x2d, 0x89, 0x9c, 0xbd, 0x89, 0x8f, 0x59, 0x1f, 0xcf, 0x9a, 0xa6, 0x51, 0xf1, 0x7c, - 0xf1, 0x99, 0xd8, 0x55, 0x1b, 0xba, 0x1f, 0x63, 0x0d, 0x25, 0x19, 0xf0, 0x31, 0x80, 0x09, 0x83, - 0xe5, 0x04, 0x7b, 0x98, 0x77, 0x4d, 0xa3, 0xf9, 0xe5, 0x6e, 0x47, 0xbd, 0xd6, 0x57, 0x47, 0x6f, - 0x52, 0x9c, 0x86, 0xfa, 0x90, 0xe1, 0x53, 0x70, 0xa1, 0x67, 0x6d, 0xef, 0xee, 0xba, 0x47, 0xc8, - 0xf1, 0xf6, 0xb0, 0xf2, 0x39, 0x17, 0xd5, 0xba, 0x1d, 0x75, 0x29, 0x2b, 0xca, 0x80, 0x7a, 0x40, - 0x91, 0x1a, 0xea, 0x2b, 0x00, 0x1d, 0x70, 0xa9, 0x9f, 0xdd, 0x3e, 0xf2, 0x94, 0x2f, 0xb8, 0xf6, - 0xcb, 0xdd, 0x8e, 0xaa, 0x9d, 0xaa, 0xad, 0x93, 0x23, 0x4f, 0x43, 0x83, 0x74, 0xe0, 0x06, 0x98, - 0x3b, 0x71, 0xd9, 0x47, 0x5e, 0xb9, 0x15, 0x2a, 0x5f, 0x72, 0x69, 0xe1, 0x04, 0x08, 0xd2, 0xe4, - 0xc8, 0xd3, 0xfd, 0x56, 0xa8, 0xa1, 0x34, 0x0d, 0xbe, 0x1f, 0xe7, 0x86, 0x17, 0xf7, 0x90, 0x77, - 0x90, 0xa3, 0x62, 0x01, 0x8e, 0x74, 0x78, 0x5b, 0x10, 0x9e, 0xa4, 0x26, 0x22, 0xc0, 0xd7, 0xe3, - 0x23, 0xf4, 0xb8, 0x52, 0xe5, 0xbd, 0xe3, 0xa8, 0xf8, 0x0e, 0x10, 0xb1, 0x3f, 0x6c, 0xf5, 0x0e, - 0xd1, 0xe3, 0x4a, 0x55, 0xfb, 0x66, 0x86, 0x77, 0x9b, 0xf4, 0x16, 0xef, 0xbd, 0x7e, 0x8a, 0xb7, - 0xb8, 0xe7, 0x1c, 0x60, 0x0d, 0x31, 0xa7, 0x58, 0x47, 0x86, 0xcf, 0x51, 0x47, 0x56, 0xc1, 0xd8, - 0x53, 0xc3, 0xa2, 0xe8, 0x5c, 0xba, 0x8c, 0x7c, 0xe4, 0x34, 0x39, 0x38, 0x42, 0xc0, 0x32, 0x58, - 0xd8, 0xc0, 0x4e, 0x40, 0x76, 0xb0, 0x43, 0x8a, 0x1e, 0xc1, 0xc1, 0xa1, 0xd3, 0x8c, 0xaa, 0x44, - 0x4e, 0xdc, 0xcd, 0xfd, 0x18, 0xa4, 0xbb, 0x11, 0x4a, 0x43, 0xfd, 0x98, 0xb0, 0x08, 0xe6, 0xcd, - 0x26, 0xae, 0xd3, 0x17, 0x78, 0xdb, 0x3d, 0xc0, 0x7e, 0x9b, 0x6c, 0x85, 0xac, 0x5a, 0xe4, 0xc4, - 0xa7, 0x1c, 0x47, 0x10, 0x9d, 0x70, 0x8c, 0x86, 0xb2, 0x2c, 0xfa, 0xa0, 0x5b, 0x6e, 0x48, 0xb0, - 0x27, 0xbc, 0x80, 0x2f, 0xa6, 0x6f, 0x9e, 0x26, 0x43, 0xc4, 0x2d, 0x7e, 0x3b, 0x68, 0x86, 0x1a, - 0xca, 0xd0, 0x20, 0x02, 0x0b, 0x46, 0xe3, 0x10, 0x07, 0xc4, 0x0d, 0xb1, 0xa0, 0x76, 0x91, 0xa9, - 0x09, 0x0f, 0x90, 0x13, 0x83, 0x92, 0x82, 0xfd, 0xc8, 0xf0, 0xed, 0xb8, 0xd5, 0x35, 0xda, 0xc4, - 0xb7, 0xad, 0x6a, 0x74, 0xeb, 0x0b, 0xb9, 0x71, 0xda, 0xc4, 0xd7, 0x09, 0x15, 0x48, 0x22, 0xe9, - 0x3d, 0xd8, 0x6b, 0xbd, 0x8d, 0x36, 0xd9, 0x57, 0x14, 0xc6, 0x1d, 0xd0, 0xad, 0x3b, 0xed, 0x54, - 0xb7, 0x4e, 0x29, 0xf0, 0x5b, 0xa2, 0xc8, 0xba, 0xdb, 0xc4, 0xca, 0x65, 0x96, 0x6e, 0xe1, 0x06, - 0x63, 0xec, 0x5d, 0x97, 0x5e, 0xfe, 0x29, 0x6c, 0x2f, 0xfa, 0x4d, 0x7c, 0xcc, 0xc8, 0x57, 0xd2, - 0x27, 0x8b, 0x3e, 0x39, 0x9c, 0x9b, 0x44, 0x42, 0x2b, 0xd3, 0x4a, 0x33, 0x81, 0xab, 0xe9, 0x46, - 0x5f, 0x68, 0xd3, 0xb8, 0x4e, 0x3f, 0x1a, 0xdd, 0x0b, 0x9e, 0x2e, 0xda, 0xc3, 0xb1, 0xac, 0xa8, - 0x2c, 0x2b, 0xc2, 0x5e, 0x44, 0x39, 0x66, 0xbd, 0x1f, 0x4f, 0x48, 0x8a, 0x02, 0x6d, 0x30, 0x7f, - 0x92, 0xa2, 0x13, 0x9d, 0x65, 0xa6, 0x23, 0xdc, 0x36, 0xae, 0xe7, 0x12, 0xd7, 0x69, 0xea, 0xbd, - 0x2c, 0x0b, 0x92, 0x59, 0x01, 0x5a, 0x9a, 0xe9, 0xff, 0x71, 0x7e, 0x6f, 0xb0, 0x1c, 0xa5, 0xfb, - 0xe3, 0x5e, 0x92, 0x45, 0x30, 0x7d, 0x41, 0x65, 0x9d, 0x7a, 0x32, 0xcd, 0x1a, 0x93, 0x10, 0x0e, - 0x1c, 0x6f, 0xef, 0x33, 0xb9, 0xee, 0xc3, 0xa5, 0x1d, 0x6d, 0xdc, 0xfb, 0xb3, 0xfd, 0xbe, 0x39, - 0xf8, 0x55, 0x81, 0x6f, 0x77, 0x02, 0x1e, 0x2f, 0x26, 0x4e, 0xf7, 0x4b, 0x03, 0x9b, 0x7d, 0x4e, - 0x16, 0xc1, 0x70, 0x2b, 0xd5, 0x9c, 0x33, 0x85, 0x5b, 0x67, 0xf5, 0xe6, 0x5c, 0x28, 0xcb, 0xa4, - 0x1d, 0x57, 0x91, 0xa7, 0xa2, 0xd0, 0x6c, 0xb3, 0x2f, 0x77, 0xb7, 0xd3, 0x67, 0x27, 0x4e, 0x55, - 0x9d, 0x03, 0x34, 0x94, 0x62, 0xd0, 0x27, 0x3a, 0x69, 0xa9, 0x12, 0x87, 0xe0, 0xa8, 0x11, 0x10, - 0x36, 0x38, 0x25, 0xa4, 0x87, 0x14, 0xa6, 0xa1, 0x7e, 0xe4, 0xac, 0xa6, 0xed, 0x3f, 0xc7, 0x9e, - 0xf2, 0xca, 0x59, 0x9a, 0x84, 0xc2, 0x32, 0x9a, 0x8c, 0x0c, 0x1f, 0x82, 0x99, 0xf8, 0xf5, 0xa0, - 0xe0, 0xb7, 0x3d, 0xa2, 0xdc, 0x67, 0x77, 0xa1, 0x58, 0x60, 0xe2, 0xf7, 0x90, 0x3a, 0xf5, 0xd3, - 0x02, 0x23, 0xe2, 0xa1, 0x05, 0xe6, 0x1f, 0xb7, 0x7d, 0xe2, 0xe4, 0x9d, 0xfa, 0x73, 0xec, 0x35, - 0xf2, 0xc7, 0x04, 0x87, 0xca, 0xeb, 0x4c, 0x44, 0x68, 0xbf, 0x3f, 0xa4, 0x10, 0x7d, 0x87, 0x63, - 0xf4, 0x1d, 0x0a, 0xd2, 0x50, 0x96, 0x48, 0x4b, 0x49, 0x25, 0xc0, 0x4f, 0x7c, 0x82, 0x95, 0x87, - 0xe9, 0xeb, 0xaa, 0x15, 0x60, 0xfd, 0xd0, 0xa7, 0xbb, 0x13, 0x63, 0xc4, 0x1d, 0xf1, 0x83, 0xa0, - 0xdd, 0x22, 0xac, 0xab, 0x51, 0xde, 0x4f, 0x1f, 0xe3, 0x93, 0x1d, 0xe1, 0x28, 0x9d, 0xf5, 0x41, - 0xc2, 0x8e, 0x08, 0xe4, 0xd5, 0x9f, 0xe6, 0x84, 0xef, 0xc0, 0x70, 0x0e, 0x4c, 0x95, 0xca, 0x76, - 0xad, 0x6a, 0x1b, 0xc8, 0x36, 0xd7, 0xe4, 0x21, 0x78, 0x11, 0xc0, 0x62, 0xa9, 0x68, 0x17, 0x0d, - 0x8b, 0x1b, 0x6b, 0xa6, 0x5d, 0x58, 0x93, 0x01, 0x94, 0xc1, 0x34, 0x32, 0x05, 0xcb, 0x14, 0xb5, - 0x54, 0x8b, 0x8f, 0x6c, 0x13, 0x6d, 0x71, 0xcb, 0x05, 0xb8, 0x0c, 0xae, 0x55, 0x8b, 0x8f, 0x1e, - 0x6f, 0x17, 0x39, 0xa6, 0x66, 0x94, 0xd6, 0x6a, 0xc8, 0xdc, 0x2a, 0x3f, 0x31, 0x6b, 0x6b, 0x86, - 0x6d, 0xc8, 0x8b, 0x70, 0x1e, 0xcc, 0x54, 0x8d, 0x27, 0x66, 0xad, 0x5a, 0x32, 0x2a, 0xd5, 0x8d, - 0xb2, 0x2d, 0x2f, 0xc1, 0x1b, 0xe0, 0x3a, 0x15, 0x2e, 0x23, 0xb3, 0x16, 0x4f, 0xb0, 0x8e, 0xca, - 0x5b, 0x3d, 0x88, 0x0a, 0x2f, 0x83, 0xc5, 0xfe, 0xae, 0x65, 0xca, 0xce, 0x4c, 0x69, 0xa0, 0xc2, - 0x46, 0x31, 0x9e, 0x73, 0x05, 0xde, 0x05, 0xaf, 0x9c, 0x16, 0x15, 0x1b, 0x57, 0xed, 0x72, 0xa5, - 0x66, 0x3c, 0x32, 0x4b, 0xb6, 0x7c, 0x1b, 0x5e, 0x07, 0x97, 0xf3, 0x96, 0x51, 0xd8, 0xdc, 0x28, - 0x5b, 0x66, 0xad, 0x62, 0x9a, 0xa8, 0x56, 0x29, 0x23, 0xbb, 0x66, 0x3f, 0xab, 0xa1, 0x67, 0x72, - 0x03, 0xaa, 0xe0, 0xea, 0x76, 0x69, 0x30, 0x00, 0xc3, 0x2b, 0x60, 0x71, 0xcd, 0xb4, 0x8c, 0x0f, - 0x32, 0xae, 0x17, 0x12, 0xbc, 0x06, 0x2e, 0x6d, 0x97, 0xfa, 0x7b, 0x3f, 0x95, 0x56, 0xff, 0x0e, - 0xc0, 0x08, 0xed, 0xfb, 0xa1, 0x02, 0x2e, 0xc4, 0x7b, 0x5b, 0x2e, 0x99, 0xb5, 0xf5, 0xb2, 0x65, - 0x95, 0x9f, 0x9a, 0x48, 0x1e, 0x8a, 0x56, 0x93, 0xf1, 0xd4, 0xb6, 0x4b, 0x76, 0xd1, 0xaa, 0xd9, - 0xa8, 0xf8, 0xe8, 0x91, 0x89, 0x7a, 0x3b, 0x24, 0x41, 0x08, 0x66, 0x63, 0x82, 0x65, 0x1a, 0x6b, - 0x26, 0x92, 0x87, 0xe1, 0x6d, 0x70, 0x2b, 0x69, 0x1b, 0x44, 0xcf, 0x89, 0xf4, 0xc7, 0xdb, 0x65, - 0xb4, 0xbd, 0x25, 0x8f, 0xd0, 0x43, 0x13, 0xdb, 0x0c, 0xcb, 0x92, 0x47, 0xe1, 0x4d, 0xa0, 0xc6, - 0x5b, 0x2c, 0xec, 0x6e, 0x22, 0x72, 0x00, 0x1f, 0x80, 0x37, 0xce, 0x00, 0x0d, 0x8a, 0x62, 0x8a, - 0xa6, 0xa4, 0x0f, 0x37, 0x5a, 0xcf, 0x34, 0x7c, 0x1d, 0xbc, 0x36, 0xd0, 0x3d, 0x48, 0x74, 0x06, - 0xae, 0x83, 0x7c, 0x1f, 0x16, 0x5f, 0x65, 0x64, 0xe1, 0xe7, 0x32, 0x12, 0x8a, 0xa9, 0xd1, 0x21, - 0x2c, 0x20, 0xc3, 0x2e, 0x6c, 0xc8, 0xb3, 0x70, 0x15, 0xbc, 0x3c, 0xf0, 0x38, 0x24, 0x37, 0xa1, - 0x01, 0x0d, 0xf0, 0xee, 0xf9, 0xb0, 0x83, 0xc2, 0xc6, 0xf0, 0x25, 0xb0, 0x3c, 0x58, 0x22, 0xda, - 0x92, 0x5d, 0xf8, 0x0e, 0x78, 0xf3, 0x2c, 0xd4, 0xa0, 0x29, 0xf6, 0x4e, 0x9f, 0x22, 0x3a, 0x06, - 0xfb, 0xf4, 0xd9, 0x1b, 0x8c, 0xa2, 0x07, 0xc3, 0x85, 0xff, 0x07, 0xb4, 0xbe, 0x87, 0x3d, 0xb9, - 0x2d, 0x2f, 0x24, 0x78, 0x07, 0xdc, 0x46, 0x46, 0x69, 0xad, 0xbc, 0x55, 0x3b, 0x07, 0xfe, 0x53, - 0x09, 0xbe, 0x07, 0xde, 0x3e, 0x1b, 0x38, 0x68, 0x81, 0x9f, 0x49, 0xd0, 0x04, 0xef, 0x9f, 0x7b, - 0xbe, 0x41, 0x32, 0x9f, 0x4b, 0xf0, 0x06, 0xb8, 0xd6, 0x9f, 0x1f, 0xe5, 0xe1, 0x0b, 0x09, 0xae, - 0x80, 0x9b, 0xa7, 0xce, 0x14, 0x21, 0xbf, 0x94, 0xe0, 0x5b, 0xe0, 0xfe, 0x69, 0x90, 0x41, 0x61, - 0xfc, 0x5a, 0x82, 0x0f, 0xc1, 0x83, 0x73, 0xcc, 0x31, 0x48, 0xe0, 0x37, 0xa7, 0xac, 0x23, 0x4a, - 0xf6, 0x57, 0x67, 0xaf, 0x23, 0x42, 0xfe, 0x56, 0x82, 0x4b, 0xe0, 0x72, 0x7f, 0x08, 0x3d, 0x13, - 0xbf, 0x93, 0xe0, 0x2d, 0xb0, 0x7c, 0xaa, 0x12, 0x85, 0xfd, 0x5e, 0x82, 0x0a, 0x58, 0x28, 0x95, - 0x6b, 0xeb, 0x46, 0xd1, 0xaa, 0x3d, 0x2d, 0xda, 0x1b, 0xb5, 0xaa, 0x8d, 0xcc, 0x6a, 0x55, 0xfe, - 0xc5, 0x30, 0x0d, 0x25, 0xe1, 0x29, 0x95, 0x23, 0x67, 0x6d, 0xbd, 0x8c, 0x6a, 0x56, 0xf1, 0x89, - 0x59, 0xa2, 0xc8, 0x4f, 0x86, 0xe1, 0x1c, 0x00, 0x14, 0x56, 0x29, 0x17, 0x4b, 0x76, 0x55, 0xfe, - 0x6e, 0x0e, 0xce, 0x80, 0x09, 0xf3, 0x99, 0x6d, 0xa2, 0x92, 0x61, 0xc9, 0xff, 0xc8, 0xad, 0x1e, - 0x80, 0x89, 0xf8, 0xd3, 0x02, 0x1c, 0x03, 0xc3, 0x9b, 0x4f, 0xe4, 0x21, 0x38, 0x09, 0x46, 0x2d, - 0xd3, 0xa8, 0x9a, 0xb2, 0x04, 0x17, 0xc0, 0x9c, 0x69, 0x99, 0x05, 0xbb, 0x58, 0x2e, 0xd5, 0xd0, - 0x76, 0xa9, 0xc4, 0x2e, 0x4f, 0x19, 0x4c, 0x3f, 0xa5, 0x4f, 0x7e, 0x6c, 0xc9, 0xc1, 0x45, 0x30, - 0x6f, 0x95, 0x0b, 0x9b, 0x35, 0x64, 0x14, 0x4c, 0x14, 0x9b, 0x47, 0x28, 0x90, 0x09, 0xc5, 0x96, - 0xd1, 0xd5, 0x3c, 0x18, 0x8f, 0xbe, 0x4b, 0xc0, 0x29, 0x30, 0xbe, 0xf9, 0xa4, 0xb6, 0x61, 0x54, - 0x37, 0xe4, 0xa1, 0x1e, 0xd2, 0x7c, 0x56, 0x29, 0x22, 0x3a, 0x33, 0x00, 0x63, 0x27, 0x13, 0x4e, - 0x83, 0x89, 0x52, 0xb9, 0x56, 0xd8, 0x30, 0x0b, 0x9b, 0x72, 0xee, 0xde, 0x43, 0x30, 0x69, 0x07, - 0x8e, 0x17, 0xb6, 0xfc, 0x80, 0xc0, 0x7b, 0xe2, 0x60, 0x36, 0xfa, 0x3a, 0x1a, 0xfd, 0xe0, 0x7b, - 0x65, 0xee, 0x64, 0xcc, 0x7f, 0x0b, 0xd4, 0x86, 0x56, 0xa4, 0xd7, 0xa4, 0xfc, 0x85, 0x17, 0x7f, - 0x59, 0x1a, 0x7a, 0xf1, 0xf5, 0x92, 0xf4, 0xd5, 0xd7, 0x4b, 0xd2, 0x9f, 0xbf, 0x5e, 0x92, 0x7e, - 0xf2, 0xd7, 0xa5, 0xa1, 0x9d, 0x31, 0xf6, 0x83, 0xf1, 0xfd, 0xff, 0x05, 0x00, 0x00, 0xff, 0xff, - 0x5c, 0x9f, 0x8c, 0x37, 0x79, 0x1e, 0x00, 0x00, -} diff --git a/vendor/go.etcd.io/etcd/functional/runner/election_command.go b/vendor/go.etcd.io/etcd/functional/runner/election_command.go deleted file mode 100644 index b2bc99a16081..000000000000 --- a/vendor/go.etcd.io/etcd/functional/runner/election_command.go +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package runner - -import ( - "context" - "errors" - "fmt" - - "github.com/coreos/etcd/clientv3/concurrency" - - "github.com/spf13/cobra" -) - -// NewElectionCommand returns the cobra command for "election runner". -func NewElectionCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "election [election name (defaults to 'elector')]", - Short: "Performs election operation", - Run: runElectionFunc, - } - cmd.Flags().IntVar(&totalClientConnections, "total-client-connections", 10, "total number of client connections") - return cmd -} - -func runElectionFunc(cmd *cobra.Command, args []string) { - election := "elector" - if len(args) == 1 { - election = args[0] - } - if len(args) > 1 { - ExitWithError(ExitBadArgs, errors.New("election takes at most one argument")) - } - - rcs := make([]roundClient, totalClientConnections) - validatec := make(chan struct{}, len(rcs)) - // nextc closes when election is ready for next round. - nextc := make(chan struct{}) - eps := endpointsFromFlag(cmd) - - for i := range rcs { - v := fmt.Sprintf("%d", i) - observedLeader := "" - validateWaiters := 0 - var rcNextc chan struct{} - setRcNextc := func() { - rcNextc = nextc - } - - rcs[i].c = newClient(eps, dialTimeout) - var ( - s *concurrency.Session - err error - ) - for { - s, err = concurrency.NewSession(rcs[i].c) - if err == nil { - break - } - } - - e := concurrency.NewElection(s, election) - rcs[i].acquire = func() (err error) { - ctx, cancel := context.WithCancel(context.Background()) - donec := make(chan struct{}) - go func() { - defer close(donec) - for ctx.Err() == nil { - if ol, ok := <-e.Observe(ctx); ok { - observedLeader = string(ol.Kvs[0].Value) - break - } - } - if observedLeader != v { - cancel() - } - }() - err = e.Campaign(ctx, v) - cancel() - <-donec - if err == nil { - observedLeader = v - } - if observedLeader == v { - validateWaiters = len(rcs) - } - select { - case <-ctx.Done(): - return nil - default: - return err - } - } - rcs[i].validate = func() error { - l, err := e.Leader(context.TODO()) - if err == nil && string(l.Kvs[0].Value) != observedLeader { - return fmt.Errorf("expected leader %q, got %q", observedLeader, l.Kvs[0].Value) - } - if err != nil { - return err - } - setRcNextc() - validatec <- struct{}{} - return nil - } - rcs[i].release = func() error { - for validateWaiters > 0 { - select { - case <-validatec: - validateWaiters-- - default: - return fmt.Errorf("waiting on followers") - } - } - if err := e.Resign(context.TODO()); err != nil { - return err - } - if observedLeader == v { - oldNextc := nextc - nextc = make(chan struct{}) - close(oldNextc) - - } - <-rcNextc - observedLeader = "" - return nil - } - } - // each client creates 1 key from Campaign() and delete it from Resign() - // a round involves in 2*len(rcs) requests. - doRounds(rcs, rounds, 2*len(rcs)) -} diff --git a/vendor/go.etcd.io/etcd/functional/runner/error.go b/vendor/go.etcd.io/etcd/functional/runner/error.go deleted file mode 100644 index 335e85cb78aa..000000000000 --- a/vendor/go.etcd.io/etcd/functional/runner/error.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package runner - -import ( - "fmt" - "os" - - "github.com/coreos/etcd/client" -) - -const ( - // http://tldp.org/LDP/abs/html/exitcodes.html - ExitSuccess = iota - ExitError - ExitBadConnection - ExitInvalidInput // for txn, watch command - ExitBadFeature // provided a valid flag with an unsupported value - ExitInterrupted - ExitIO - ExitBadArgs = 128 -) - -func ExitWithError(code int, err error) { - fmt.Fprintln(os.Stderr, "Error: ", err) - if cerr, ok := err.(*client.ClusterError); ok { - fmt.Fprintln(os.Stderr, cerr.Detail()) - } - os.Exit(code) -} diff --git a/vendor/go.etcd.io/etcd/functional/runner/global.go b/vendor/go.etcd.io/etcd/functional/runner/global.go deleted file mode 100644 index 94a3a2aaec4d..000000000000 --- a/vendor/go.etcd.io/etcd/functional/runner/global.go +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package runner - -import ( - "context" - "fmt" - "log" - "sync" - "time" - - "github.com/coreos/etcd/clientv3" - - "github.com/spf13/cobra" - "golang.org/x/time/rate" -) - -// shared flags -var ( - totalClientConnections int // total number of client connections to be made with server - endpoints []string - dialTimeout time.Duration - rounds int // total number of rounds to run; set to <= 0 to run forever. - reqRate int // maximum number of requests per second. -) - -type roundClient struct { - c *clientv3.Client - progress int - acquire func() error - validate func() error - release func() error -} - -func newClient(eps []string, timeout time.Duration) *clientv3.Client { - c, err := clientv3.New(clientv3.Config{ - Endpoints: eps, - DialTimeout: time.Duration(timeout) * time.Second, - }) - if err != nil { - log.Fatal(err) - } - return c -} - -func doRounds(rcs []roundClient, rounds int, requests int) { - var wg sync.WaitGroup - - wg.Add(len(rcs)) - finished := make(chan struct{}) - limiter := rate.NewLimiter(rate.Limit(reqRate), reqRate) - for i := range rcs { - go func(rc *roundClient) { - defer wg.Done() - for rc.progress < rounds || rounds <= 0 { - if err := limiter.WaitN(context.Background(), requests/len(rcs)); err != nil { - log.Panicf("rate limiter error %v", err) - } - - for rc.acquire() != nil { /* spin */ - } - - if err := rc.validate(); err != nil { - log.Fatal(err) - } - - time.Sleep(10 * time.Millisecond) - rc.progress++ - finished <- struct{}{} - - for rc.release() != nil { /* spin */ - } - } - }(&rcs[i]) - } - - start := time.Now() - for i := 1; i < len(rcs)*rounds+1 || rounds <= 0; i++ { - select { - case <-finished: - if i%100 == 0 { - fmt.Printf("finished %d, took %v\n", i, time.Since(start)) - start = time.Now() - } - case <-time.After(time.Minute): - log.Panic("no progress after 1 minute!") - } - } - wg.Wait() - - for _, rc := range rcs { - rc.c.Close() - } -} - -func endpointsFromFlag(cmd *cobra.Command) []string { - eps, err := cmd.Flags().GetStringSlice("endpoints") - if err != nil { - ExitWithError(ExitError, err) - } - return eps -} diff --git a/vendor/go.etcd.io/etcd/functional/runner/help.go b/vendor/go.etcd.io/etcd/functional/runner/help.go deleted file mode 100644 index 63e9815ab651..000000000000 --- a/vendor/go.etcd.io/etcd/functional/runner/help.go +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// copied from https://github.com/rkt/rkt/blob/master/rkt/help.go - -package runner - -import ( - "bytes" - "fmt" - "io" - "os" - "strings" - "text/tabwriter" - "text/template" - - "github.com/coreos/etcd/version" - - "github.com/spf13/cobra" - "github.com/spf13/pflag" -) - -var ( - commandUsageTemplate *template.Template - templFuncs = template.FuncMap{ - "descToLines": func(s string) []string { - // trim leading/trailing whitespace and split into slice of lines - return strings.Split(strings.Trim(s, "\n\t "), "\n") - }, - "cmdName": func(cmd *cobra.Command, startCmd *cobra.Command) string { - parts := []string{cmd.Name()} - for cmd.HasParent() && cmd.Parent().Name() != startCmd.Name() { - cmd = cmd.Parent() - parts = append([]string{cmd.Name()}, parts...) - } - return strings.Join(parts, " ") - }, - } -) - -func init() { - commandUsage := ` -{{ $cmd := .Cmd }}\ -{{ $cmdname := cmdName .Cmd .Cmd.Root }}\ -NAME: -{{ if not .Cmd.HasParent }}\ -{{printf "\t%s - %s" .Cmd.Name .Cmd.Short}} -{{else}}\ -{{printf "\t%s - %s" $cmdname .Cmd.Short}} -{{end}}\ - -USAGE: -{{printf "\t%s" .Cmd.UseLine}} -{{ if not .Cmd.HasParent }}\ - -VERSION: -{{printf "\t%s" .Version}} -{{end}}\ -{{if .Cmd.HasSubCommands}}\ - -API VERSION: -{{printf "\t%s" .APIVersion}} -{{end}}\ -{{if .Cmd.HasSubCommands}}\ - - -COMMANDS: -{{range .SubCommands}}\ -{{ $cmdname := cmdName . $cmd }}\ -{{ if .Runnable }}\ -{{printf "\t%s\t%s" $cmdname .Short}} -{{end}}\ -{{end}}\ -{{end}}\ -{{ if .Cmd.Long }}\ - -DESCRIPTION: -{{range $line := descToLines .Cmd.Long}}{{printf "\t%s" $line}} -{{end}}\ -{{end}}\ -{{if .Cmd.HasLocalFlags}}\ - -OPTIONS: -{{.LocalFlags}}\ -{{end}}\ -{{if .Cmd.HasInheritedFlags}}\ - -GLOBAL OPTIONS: -{{.GlobalFlags}}\ -{{end}} -`[1:] - - commandUsageTemplate = template.Must(template.New("command_usage").Funcs(templFuncs).Parse(strings.Replace(commandUsage, "\\\n", "", -1))) -} - -func etcdFlagUsages(flagSet *pflag.FlagSet) string { - x := new(bytes.Buffer) - - flagSet.VisitAll(func(flag *pflag.Flag) { - if len(flag.Deprecated) > 0 { - return - } - var format string - if len(flag.Shorthand) > 0 { - format = " -%s, --%s" - } else { - format = " %s --%s" - } - if len(flag.NoOptDefVal) > 0 { - format = format + "[" - } - if flag.Value.Type() == "string" { - // put quotes on the value - format = format + "=%q" - } else { - format = format + "=%s" - } - if len(flag.NoOptDefVal) > 0 { - format = format + "]" - } - format = format + "\t%s\n" - shorthand := flag.Shorthand - fmt.Fprintf(x, format, shorthand, flag.Name, flag.DefValue, flag.Usage) - }) - - return x.String() -} - -func getSubCommands(cmd *cobra.Command) []*cobra.Command { - var subCommands []*cobra.Command - for _, subCmd := range cmd.Commands() { - subCommands = append(subCommands, subCmd) - subCommands = append(subCommands, getSubCommands(subCmd)...) - } - return subCommands -} - -func usageFunc(cmd *cobra.Command) error { - subCommands := getSubCommands(cmd) - tabOut := getTabOutWithWriter(os.Stdout) - commandUsageTemplate.Execute(tabOut, struct { - Cmd *cobra.Command - LocalFlags string - GlobalFlags string - SubCommands []*cobra.Command - Version string - APIVersion string - }{ - cmd, - etcdFlagUsages(cmd.LocalFlags()), - etcdFlagUsages(cmd.InheritedFlags()), - subCommands, - version.Version, - version.APIVersion, - }) - tabOut.Flush() - return nil -} - -func getTabOutWithWriter(writer io.Writer) *tabwriter.Writer { - aTabOut := new(tabwriter.Writer) - aTabOut.Init(writer, 0, 8, 1, '\t', 0) - return aTabOut -} diff --git a/vendor/go.etcd.io/etcd/functional/runner/lease_renewer_command.go b/vendor/go.etcd.io/etcd/functional/runner/lease_renewer_command.go deleted file mode 100644 index a57c53f27c43..000000000000 --- a/vendor/go.etcd.io/etcd/functional/runner/lease_renewer_command.go +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package runner - -import ( - "context" - "errors" - "fmt" - "log" - "time" - - "github.com/coreos/etcd/clientv3" - - "github.com/spf13/cobra" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -var ( - leaseTTL int64 -) - -// NewLeaseRenewerCommand returns the cobra command for "lease-renewer runner". -func NewLeaseRenewerCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "lease-renewer", - Short: "Performs lease renew operation", - Run: runLeaseRenewerFunc, - } - cmd.Flags().Int64Var(&leaseTTL, "ttl", 5, "lease's ttl") - return cmd -} - -func runLeaseRenewerFunc(cmd *cobra.Command, args []string) { - if len(args) > 0 { - ExitWithError(ExitBadArgs, errors.New("lease-renewer does not take any argument")) - } - - eps := endpointsFromFlag(cmd) - c := newClient(eps, dialTimeout) - ctx := context.Background() - - for { - var ( - l *clientv3.LeaseGrantResponse - lk *clientv3.LeaseKeepAliveResponse - err error - ) - for { - l, err = c.Lease.Grant(ctx, leaseTTL) - if err == nil { - break - } - } - expire := time.Now().Add(time.Duration(l.TTL-1) * time.Second) - - for { - lk, err = c.Lease.KeepAliveOnce(ctx, l.ID) - if ev, ok := status.FromError(err); ok && ev.Code() == codes.NotFound { - if time.Since(expire) < 0 { - log.Fatalf("bad renew! exceeded: %v", time.Since(expire)) - for { - lk, err = c.Lease.KeepAliveOnce(ctx, l.ID) - fmt.Println(lk, err) - time.Sleep(time.Second) - } - } - log.Fatalf("lost lease %d, expire: %v\n", l.ID, expire) - break - } - if err != nil { - continue - } - expire = time.Now().Add(time.Duration(lk.TTL-1) * time.Second) - log.Printf("renewed lease %d, expire: %v\n", lk.ID, expire) - time.Sleep(time.Duration(lk.TTL-2) * time.Second) - } - } -} diff --git a/vendor/go.etcd.io/etcd/functional/runner/lock_racer_command.go b/vendor/go.etcd.io/etcd/functional/runner/lock_racer_command.go deleted file mode 100644 index 18b10e403534..000000000000 --- a/vendor/go.etcd.io/etcd/functional/runner/lock_racer_command.go +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package runner - -import ( - "context" - "errors" - "fmt" - "sync" - - "github.com/coreos/etcd/clientv3/concurrency" - - "github.com/spf13/cobra" -) - -// NewLockRacerCommand returns the cobra command for "lock-racer runner". -func NewLockRacerCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "lock-racer [name of lock (defaults to 'racers')]", - Short: "Performs lock race operation", - Run: runRacerFunc, - } - cmd.Flags().IntVar(&totalClientConnections, "total-client-connections", 10, "total number of client connections") - return cmd -} - -func runRacerFunc(cmd *cobra.Command, args []string) { - racers := "racers" - if len(args) == 1 { - racers = args[0] - } - - if len(args) > 1 { - ExitWithError(ExitBadArgs, errors.New("lock-racer takes at most one argument")) - } - - rcs := make([]roundClient, totalClientConnections) - ctx := context.Background() - // mu ensures validate and release funcs are atomic. - var mu sync.Mutex - cnt := 0 - - eps := endpointsFromFlag(cmd) - - for i := range rcs { - var ( - s *concurrency.Session - err error - ) - - rcs[i].c = newClient(eps, dialTimeout) - - for { - s, err = concurrency.NewSession(rcs[i].c) - if err == nil { - break - } - } - m := concurrency.NewMutex(s, racers) - rcs[i].acquire = func() error { return m.Lock(ctx) } - rcs[i].validate = func() error { - mu.Lock() - defer mu.Unlock() - if cnt++; cnt != 1 { - return fmt.Errorf("bad lock; count: %d", cnt) - } - return nil - } - rcs[i].release = func() error { - mu.Lock() - defer mu.Unlock() - if err := m.Unlock(ctx); err != nil { - return err - } - cnt = 0 - return nil - } - } - // each client creates 1 key from NewMutex() and delete it from Unlock() - // a round involves in 2*len(rcs) requests. - doRounds(rcs, rounds, 2*len(rcs)) -} diff --git a/vendor/go.etcd.io/etcd/functional/runner/root.go b/vendor/go.etcd.io/etcd/functional/runner/root.go deleted file mode 100644 index abd74af1bc92..000000000000 --- a/vendor/go.etcd.io/etcd/functional/runner/root.go +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package runner implements individual etcd-runner commands for the etcd-runner utility. -package runner - -import ( - "log" - "math/rand" - "time" - - "github.com/spf13/cobra" -) - -const ( - cliName = "etcd-runner" - cliDescription = "Stress tests using clientv3 functionality.." - - defaultDialTimeout = 2 * time.Second -) - -var ( - rootCmd = &cobra.Command{ - Use: cliName, - Short: cliDescription, - SuggestFor: []string{"etcd-runner"}, - } -) - -func init() { - cobra.EnablePrefixMatching = true - - rand.Seed(time.Now().UnixNano()) - - log.SetFlags(log.Lmicroseconds) - - rootCmd.PersistentFlags().StringSliceVar(&endpoints, "endpoints", []string{"127.0.0.1:2379"}, "gRPC endpoints") - rootCmd.PersistentFlags().DurationVar(&dialTimeout, "dial-timeout", defaultDialTimeout, "dial timeout for client connections") - rootCmd.PersistentFlags().IntVar(&reqRate, "req-rate", 30, "maximum number of requests per second") - rootCmd.PersistentFlags().IntVar(&rounds, "rounds", 100, "number of rounds to run; 0 to run forever") - - rootCmd.AddCommand( - NewElectionCommand(), - NewLeaseRenewerCommand(), - NewLockRacerCommand(), - NewWatchCommand(), - ) -} - -func Start() { - rootCmd.SetUsageFunc(usageFunc) - - // Make help just show the usage - rootCmd.SetHelpTemplate(`{{.UsageString}}`) - - if err := rootCmd.Execute(); err != nil { - ExitWithError(ExitError, err) - } -} diff --git a/vendor/go.etcd.io/etcd/functional/runner/watch_command.go b/vendor/go.etcd.io/etcd/functional/runner/watch_command.go deleted file mode 100644 index 646092ad0805..000000000000 --- a/vendor/go.etcd.io/etcd/functional/runner/watch_command.go +++ /dev/null @@ -1,210 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package runner - -import ( - "context" - "errors" - "fmt" - "log" - "sync" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/pkg/stringutil" - - "github.com/spf13/cobra" - "golang.org/x/time/rate" -) - -var ( - runningTime time.Duration // time for which operation should be performed - noOfPrefixes int // total number of prefixes which will be watched upon - watchPerPrefix int // number of watchers per prefix - watchPrefix string // prefix append to keys in watcher - totalKeys int // total number of keys for operation -) - -// NewWatchCommand returns the cobra command for "watcher runner". -func NewWatchCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "watcher", - Short: "Performs watch operation", - Run: runWatcherFunc, - } - cmd.Flags().DurationVar(&runningTime, "running-time", 60, "number of seconds to run") - cmd.Flags().StringVar(&watchPrefix, "prefix", "", "the prefix to append on all keys") - cmd.Flags().IntVar(&noOfPrefixes, "total-prefixes", 10, "total no of prefixes to use") - cmd.Flags().IntVar(&watchPerPrefix, "watch-per-prefix", 10, "number of watchers per prefix") - cmd.Flags().IntVar(&totalKeys, "total-keys", 1000, "total number of keys to watch") - - return cmd -} - -func runWatcherFunc(cmd *cobra.Command, args []string) { - if len(args) > 0 { - ExitWithError(ExitBadArgs, errors.New("watcher does not take any argument")) - } - - ctx := context.Background() - for round := 0; round < rounds || rounds <= 0; round++ { - fmt.Println("round", round) - performWatchOnPrefixes(ctx, cmd, round) - } -} - -func performWatchOnPrefixes(ctx context.Context, cmd *cobra.Command, round int) { - keyPerPrefix := totalKeys / noOfPrefixes - prefixes := stringutil.UniqueStrings(5, noOfPrefixes) - keys := stringutil.RandomStrings(10, keyPerPrefix) - - roundPrefix := fmt.Sprintf("%16x", round) - - eps := endpointsFromFlag(cmd) - - var ( - revision int64 - wg sync.WaitGroup - gr *clientv3.GetResponse - err error - ) - - client := newClient(eps, dialTimeout) - defer client.Close() - - gr, err = getKey(ctx, client, "non-existent") - if err != nil { - log.Fatalf("failed to get the initial revision: %v", err) - } - revision = gr.Header.Revision - - ctxt, cancel := context.WithDeadline(ctx, time.Now().Add(runningTime*time.Second)) - defer cancel() - - // generate and put keys in cluster - limiter := rate.NewLimiter(rate.Limit(reqRate), reqRate) - - go func() { - for _, key := range keys { - for _, prefix := range prefixes { - if err = limiter.Wait(ctxt); err != nil { - return - } - if err = putKeyAtMostOnce(ctxt, client, watchPrefix+"-"+roundPrefix+"-"+prefix+"-"+key); err != nil { - log.Fatalf("failed to put key: %v", err) - return - } - } - } - }() - - ctxc, cancelc := context.WithCancel(ctx) - - wcs := make([]clientv3.WatchChan, 0) - rcs := make([]*clientv3.Client, 0) - - for _, prefix := range prefixes { - for j := 0; j < watchPerPrefix; j++ { - rc := newClient(eps, dialTimeout) - rcs = append(rcs, rc) - - wprefix := watchPrefix + "-" + roundPrefix + "-" + prefix - - wc := rc.Watch(ctxc, wprefix, clientv3.WithPrefix(), clientv3.WithRev(revision)) - wcs = append(wcs, wc) - - wg.Add(1) - go func() { - defer wg.Done() - checkWatchResponse(wc, wprefix, keys) - }() - } - } - wg.Wait() - - cancelc() - - // verify all watch channels are closed - for e, wc := range wcs { - if _, ok := <-wc; ok { - log.Fatalf("expected wc to be closed, but received %v", e) - } - } - - for _, rc := range rcs { - rc.Close() - } - - if err = deletePrefix(ctx, client, watchPrefix); err != nil { - log.Fatalf("failed to clean up keys after test: %v", err) - } -} - -func checkWatchResponse(wc clientv3.WatchChan, prefix string, keys []string) { - for n := 0; n < len(keys); { - wr, more := <-wc - if !more { - log.Fatalf("expect more keys (received %d/%d) for %s", n, len(keys), prefix) - } - for _, event := range wr.Events { - expectedKey := prefix + "-" + keys[n] - receivedKey := string(event.Kv.Key) - if expectedKey != receivedKey { - log.Fatalf("expected key %q, got %q for prefix : %q\n", expectedKey, receivedKey, prefix) - } - n++ - } - } -} - -func putKeyAtMostOnce(ctx context.Context, client *clientv3.Client, key string) error { - gr, err := getKey(ctx, client, key) - if err != nil { - return err - } - - var modrev int64 - if len(gr.Kvs) > 0 { - modrev = gr.Kvs[0].ModRevision - } - - for ctx.Err() == nil { - _, err := client.Txn(ctx).If(clientv3.Compare(clientv3.ModRevision(key), "=", modrev)).Then(clientv3.OpPut(key, key)).Commit() - - if err == nil { - return nil - } - } - - return ctx.Err() -} - -func deletePrefix(ctx context.Context, client *clientv3.Client, key string) error { - for ctx.Err() == nil { - if _, err := client.Delete(ctx, key, clientv3.WithPrefix()); err == nil { - return nil - } - } - return ctx.Err() -} - -func getKey(ctx context.Context, client *clientv3.Client, key string) (*clientv3.GetResponse, error) { - for ctx.Err() == nil { - if gr, err := client.Get(ctx, key); err == nil { - return gr, nil - } - } - return nil, ctx.Err() -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/case.go b/vendor/go.etcd.io/etcd/functional/tester/case.go deleted file mode 100644 index e8eef6263327..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/case.go +++ /dev/null @@ -1,327 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "fmt" - "math/rand" - "time" - - "github.com/coreos/etcd/functional/rpcpb" - - "go.uber.org/zap" -) - -// Case defines failure/test injection interface. -// To add a test case: -// 1. implement "Case" interface -// 2. define fail case name in "rpcpb.Case" -type Case interface { - // Inject injeccts the failure into the testing cluster at the given - // round. When calling the function, the cluster should be in health. - Inject(clus *Cluster) error - // Recover recovers the injected failure caused by the injection of the - // given round and wait for the recovery of the testing cluster. - Recover(clus *Cluster) error - // Desc returns a description of the failure - Desc() string - // TestCase returns "rpcpb.Case" enum type. - TestCase() rpcpb.Case -} - -type injectMemberFunc func(*Cluster, int) error -type recoverMemberFunc func(*Cluster, int) error - -type caseByFunc struct { - desc string - rpcpbCase rpcpb.Case - injectMember injectMemberFunc - recoverMember recoverMemberFunc -} - -func (c *caseByFunc) Desc() string { - if c.desc != "" { - return c.desc - } - return c.rpcpbCase.String() -} - -func (c *caseByFunc) TestCase() rpcpb.Case { - return c.rpcpbCase -} - -type caseFollower struct { - caseByFunc - last int - lead int -} - -func (c *caseFollower) updateIndex(clus *Cluster) error { - lead, err := clus.GetLeader() - if err != nil { - return err - } - c.lead = lead - - n := len(clus.Members) - if c.last == -1 { // first run - c.last = clus.rd % n - if c.last == c.lead { - c.last = (c.last + 1) % n - } - } else { - c.last = (c.last + 1) % n - if c.last == c.lead { - c.last = (c.last + 1) % n - } - } - return nil -} - -func (c *caseFollower) Inject(clus *Cluster) error { - if err := c.updateIndex(clus); err != nil { - return err - } - return c.injectMember(clus, c.last) -} - -func (c *caseFollower) Recover(clus *Cluster) error { - return c.recoverMember(clus, c.last) -} - -func (c *caseFollower) Desc() string { - if c.desc != "" { - return c.desc - } - return c.rpcpbCase.String() -} - -func (c *caseFollower) TestCase() rpcpb.Case { - return c.rpcpbCase -} - -type caseLeader struct { - caseByFunc - last int - lead int -} - -func (c *caseLeader) updateIndex(clus *Cluster) error { - lead, err := clus.GetLeader() - if err != nil { - return err - } - c.lead = lead - c.last = lead - return nil -} - -func (c *caseLeader) Inject(clus *Cluster) error { - if err := c.updateIndex(clus); err != nil { - return err - } - return c.injectMember(clus, c.last) -} - -func (c *caseLeader) Recover(clus *Cluster) error { - return c.recoverMember(clus, c.last) -} - -func (c *caseLeader) TestCase() rpcpb.Case { - return c.rpcpbCase -} - -type caseQuorum struct { - caseByFunc - injected map[int]struct{} -} - -func (c *caseQuorum) Inject(clus *Cluster) error { - c.injected = pickQuorum(len(clus.Members)) - for idx := range c.injected { - if err := c.injectMember(clus, idx); err != nil { - return err - } - } - return nil -} - -func (c *caseQuorum) Recover(clus *Cluster) error { - for idx := range c.injected { - if err := c.recoverMember(clus, idx); err != nil { - return err - } - } - return nil -} - -func (c *caseQuorum) Desc() string { - if c.desc != "" { - return c.desc - } - return c.rpcpbCase.String() -} - -func (c *caseQuorum) TestCase() rpcpb.Case { - return c.rpcpbCase -} - -func pickQuorum(size int) (picked map[int]struct{}) { - picked = make(map[int]struct{}) - r := rand.New(rand.NewSource(time.Now().UnixNano())) - quorum := size/2 + 1 - for len(picked) < quorum { - idx := r.Intn(size) - picked[idx] = struct{}{} - } - return picked -} - -type caseAll caseByFunc - -func (c *caseAll) Inject(clus *Cluster) error { - for i := range clus.Members { - if err := c.injectMember(clus, i); err != nil { - return err - } - } - return nil -} - -func (c *caseAll) Recover(clus *Cluster) error { - for i := range clus.Members { - if err := c.recoverMember(clus, i); err != nil { - return err - } - } - return nil -} - -func (c *caseAll) Desc() string { - if c.desc != "" { - return c.desc - } - return c.rpcpbCase.String() -} - -func (c *caseAll) TestCase() rpcpb.Case { - return c.rpcpbCase -} - -// caseUntilSnapshot injects a failure/test and waits for a snapshot event -type caseUntilSnapshot struct { - desc string - rpcpbCase rpcpb.Case - Case -} - -// all delay failure cases except the ones failing with latency -// greater than election timeout (trigger leader election and -// cluster keeps operating anyways) -var slowCases = map[rpcpb.Case]bool{ - rpcpb.Case_RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER: true, - rpcpb.Case_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT: true, - rpcpb.Case_RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT: true, - rpcpb.Case_RANDOM_DELAY_PEER_PORT_TX_RX_LEADER: true, - rpcpb.Case_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT: true, - rpcpb.Case_RANDOM_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT: true, - rpcpb.Case_RANDOM_DELAY_PEER_PORT_TX_RX_QUORUM: true, - rpcpb.Case_RANDOM_DELAY_PEER_PORT_TX_RX_ALL: true, -} - -func (c *caseUntilSnapshot) Inject(clus *Cluster) error { - if err := c.Case.Inject(clus); err != nil { - return err - } - - snapshotCount := clus.Members[0].Etcd.SnapshotCount - - now := time.Now() - clus.lg.Info( - "trigger snapshot START", - zap.String("desc", c.Desc()), - zap.Int64("etcd-snapshot-count", snapshotCount), - ) - - // maxRev may fail since failure just injected, retry if failed. - startRev, err := clus.maxRev() - for i := 0; i < 10 && startRev == 0; i++ { - startRev, err = clus.maxRev() - } - if startRev == 0 { - return err - } - lastRev := startRev - - // healthy cluster could accept 1000 req/sec at least. - // 3x time to trigger snapshot. - retries := int(snapshotCount) / 1000 * 3 - if v, ok := slowCases[c.TestCase()]; v && ok { - // slow network takes more retries - retries *= 5 - } - - for i := 0; i < retries; i++ { - lastRev, err = clus.maxRev() - // If the number of proposals committed is bigger than snapshot count, - // a new snapshot should have been created. - diff := lastRev - startRev - if diff > snapshotCount { - clus.lg.Info( - "trigger snapshot PASS", - zap.Int("retries", i), - zap.String("desc", c.Desc()), - zap.Int64("committed-entries", diff), - zap.Int64("etcd-snapshot-count", snapshotCount), - zap.Int64("start-revision", startRev), - zap.Int64("last-revision", lastRev), - zap.Duration("took", time.Since(now)), - ) - return nil - } - - dur := time.Second - if diff < 0 || err != nil { - dur = 3 * time.Second - } - clus.lg.Info( - "trigger snapshot PROGRESS", - zap.Int("retries", i), - zap.Int64("committed-entries", diff), - zap.Int64("etcd-snapshot-count", snapshotCount), - zap.Int64("start-revision", startRev), - zap.Int64("last-revision", lastRev), - zap.Duration("took", time.Since(now)), - zap.Error(err), - ) - time.Sleep(dur) - } - - return fmt.Errorf("cluster too slow: only %d commits in %d retries", lastRev-startRev, retries) -} - -func (c *caseUntilSnapshot) Desc() string { - if c.desc != "" { - return c.desc - } - if c.rpcpbCase.String() != "" { - return c.rpcpbCase.String() - } - return c.Case.Desc() -} - -func (c *caseUntilSnapshot) TestCase() rpcpb.Case { - return c.rpcpbCase -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/case_delay.go b/vendor/go.etcd.io/etcd/functional/tester/case_delay.go deleted file mode 100644 index d06d1d65dc40..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/case_delay.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "time" - - "go.uber.org/zap" -) - -type caseDelay struct { - Case - delayDuration time.Duration -} - -func (c *caseDelay) Inject(clus *Cluster) error { - if err := c.Case.Inject(clus); err != nil { - return err - } - if c.delayDuration > 0 { - clus.lg.Info( - "wait after inject", - zap.Duration("delay", c.delayDuration), - zap.String("desc", c.Case.Desc()), - ) - time.Sleep(c.delayDuration) - } - return nil -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/case_external.go b/vendor/go.etcd.io/etcd/functional/tester/case_external.go deleted file mode 100644 index 79d2a3717e4d..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/case_external.go +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "fmt" - "os/exec" - - "github.com/coreos/etcd/functional/rpcpb" -) - -type caseExternal struct { - Case - - desc string - rpcpbCase rpcpb.Case - - scriptPath string -} - -func (c *caseExternal) Inject(clus *Cluster) error { - return exec.Command(c.scriptPath, "enable", fmt.Sprintf("%d", clus.rd)).Run() -} - -func (c *caseExternal) Recover(clus *Cluster) error { - return exec.Command(c.scriptPath, "disable", fmt.Sprintf("%d", clus.rd)).Run() -} - -func (c *caseExternal) Desc() string { - return c.desc -} - -func (c *caseExternal) TestCase() rpcpb.Case { - return c.rpcpbCase -} - -func new_Case_EXTERNAL(scriptPath string) Case { - return &caseExternal{ - desc: fmt.Sprintf("external fault injector (script: %q)", scriptPath), - rpcpbCase: rpcpb.Case_EXTERNAL, - scriptPath: scriptPath, - } -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/case_failpoints.go b/vendor/go.etcd.io/etcd/functional/tester/case_failpoints.go deleted file mode 100644 index 4d26c8a8dd00..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/case_failpoints.go +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "fmt" - "io/ioutil" - "net/http" - "strings" - "sync" - - "github.com/coreos/etcd/functional/rpcpb" -) - -type failpointStats struct { - mu sync.Mutex - // crashes counts the number of crashes for a failpoint - crashes map[string]int -} - -var fpStats failpointStats - -func failpointFailures(clus *Cluster) (ret []Case, err error) { - var fps []string - fps, err = failpointPaths(clus.Members[0].FailpointHTTPAddr) - if err != nil { - return nil, err - } - // create failure objects for all failpoints - for _, fp := range fps { - if len(fp) == 0 { - continue - } - - fpFails := casesFromFailpoint(fp, clus.Tester.FailpointCommands) - - // wrap in delays so failpoint has time to trigger - for i, fpf := range fpFails { - if strings.Contains(fp, "Snap") { - // hack to trigger snapshot failpoints - fpFails[i] = &caseUntilSnapshot{ - desc: fpf.Desc(), - rpcpbCase: rpcpb.Case_FAILPOINTS, - Case: fpf, - } - } else { - fpFails[i] = &caseDelay{ - Case: fpf, - delayDuration: clus.GetCaseDelayDuration(), - } - } - } - ret = append(ret, fpFails...) - } - fpStats.crashes = make(map[string]int) - return ret, err -} - -func failpointPaths(endpoint string) ([]string, error) { - resp, err := http.Get(endpoint) - if err != nil { - return nil, err - } - defer resp.Body.Close() - body, rerr := ioutil.ReadAll(resp.Body) - if rerr != nil { - return nil, rerr - } - var fps []string - for _, l := range strings.Split(string(body), "\n") { - fp := strings.Split(l, "=")[0] - fps = append(fps, fp) - } - return fps, nil -} - -// failpoints follows FreeBSD FAIL_POINT syntax. -// e.g. panic("etcd-tester"),1*sleep(1000)->panic("etcd-tester") -func casesFromFailpoint(fp string, failpointCommands []string) (fs []Case) { - recov := makeRecoverFailpoint(fp) - for _, fcmd := range failpointCommands { - inject := makeInjectFailpoint(fp, fcmd) - fs = append(fs, []Case{ - &caseFollower{ - caseByFunc: caseByFunc{ - desc: fmt.Sprintf("failpoint %q (one: %q)", fp, fcmd), - rpcpbCase: rpcpb.Case_FAILPOINTS, - injectMember: inject, - recoverMember: recov, - }, - last: -1, - lead: -1, - }, - &caseLeader{ - caseByFunc: caseByFunc{ - desc: fmt.Sprintf("failpoint %q (leader: %q)", fp, fcmd), - rpcpbCase: rpcpb.Case_FAILPOINTS, - injectMember: inject, - recoverMember: recov, - }, - last: -1, - lead: -1, - }, - &caseQuorum{ - caseByFunc: caseByFunc{ - desc: fmt.Sprintf("failpoint %q (quorum: %q)", fp, fcmd), - rpcpbCase: rpcpb.Case_FAILPOINTS, - injectMember: inject, - recoverMember: recov, - }, - injected: make(map[int]struct{}), - }, - &caseAll{ - desc: fmt.Sprintf("failpoint %q (all: %q)", fp, fcmd), - rpcpbCase: rpcpb.Case_FAILPOINTS, - injectMember: inject, - recoverMember: recov, - }, - }...) - } - return fs -} - -func makeInjectFailpoint(fp, val string) injectMemberFunc { - return func(clus *Cluster, idx int) (err error) { - return putFailpoint(clus.Members[idx].FailpointHTTPAddr, fp, val) - } -} - -func makeRecoverFailpoint(fp string) recoverMemberFunc { - return func(clus *Cluster, idx int) error { - if err := delFailpoint(clus.Members[idx].FailpointHTTPAddr, fp); err == nil { - return nil - } - // node not responding, likely dead from fp panic; restart - fpStats.mu.Lock() - fpStats.crashes[fp]++ - fpStats.mu.Unlock() - return recover_SIGTERM_ETCD(clus, idx) - } -} - -func putFailpoint(ep, fp, val string) error { - req, _ := http.NewRequest(http.MethodPut, ep+"/"+fp, strings.NewReader(val)) - c := http.Client{} - resp, err := c.Do(req) - if err != nil { - return err - } - resp.Body.Close() - if resp.StatusCode/100 != 2 { - return fmt.Errorf("failed to PUT %s=%s at %s (%v)", fp, val, ep, resp.Status) - } - return nil -} - -func delFailpoint(ep, fp string) error { - req, _ := http.NewRequest(http.MethodDelete, ep+"/"+fp, strings.NewReader("")) - c := http.Client{} - resp, err := c.Do(req) - if err != nil { - return err - } - resp.Body.Close() - if resp.StatusCode/100 != 2 { - return fmt.Errorf("failed to DELETE %s at %s (%v)", fp, ep, resp.Status) - } - return nil -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/case_network_blackhole.go b/vendor/go.etcd.io/etcd/functional/tester/case_network_blackhole.go deleted file mode 100644 index 0d496eade4fe..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/case_network_blackhole.go +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import "github.com/coreos/etcd/functional/rpcpb" - -func inject_BLACKHOLE_PEER_PORT_TX_RX(clus *Cluster, idx int) error { - return clus.sendOp(idx, rpcpb.Operation_BLACKHOLE_PEER_PORT_TX_RX) -} - -func recover_BLACKHOLE_PEER_PORT_TX_RX(clus *Cluster, idx int) error { - return clus.sendOp(idx, rpcpb.Operation_UNBLACKHOLE_PEER_PORT_TX_RX) -} - -func new_Case_BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER(clus *Cluster) Case { - cc := caseByFunc{ - rpcpbCase: rpcpb.Case_BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER, - injectMember: inject_BLACKHOLE_PEER_PORT_TX_RX, - recoverMember: recover_BLACKHOLE_PEER_PORT_TX_RX, - } - c := &caseFollower{cc, -1, -1} - return &caseDelay{ - Case: c, - delayDuration: clus.GetCaseDelayDuration(), - } -} - -func new_Case_BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT() Case { - cc := caseByFunc{ - rpcpbCase: rpcpb.Case_BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT, - injectMember: inject_BLACKHOLE_PEER_PORT_TX_RX, - recoverMember: recover_BLACKHOLE_PEER_PORT_TX_RX, - } - c := &caseFollower{cc, -1, -1} - return &caseUntilSnapshot{ - rpcpbCase: rpcpb.Case_BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT, - Case: c, - } -} - -func new_Case_BLACKHOLE_PEER_PORT_TX_RX_LEADER(clus *Cluster) Case { - cc := caseByFunc{ - rpcpbCase: rpcpb.Case_BLACKHOLE_PEER_PORT_TX_RX_LEADER, - injectMember: inject_BLACKHOLE_PEER_PORT_TX_RX, - recoverMember: recover_BLACKHOLE_PEER_PORT_TX_RX, - } - c := &caseLeader{cc, -1, -1} - return &caseDelay{ - Case: c, - delayDuration: clus.GetCaseDelayDuration(), - } -} - -func new_Case_BLACKHOLE_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT() Case { - cc := caseByFunc{ - rpcpbCase: rpcpb.Case_BLACKHOLE_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT, - injectMember: inject_BLACKHOLE_PEER_PORT_TX_RX, - recoverMember: recover_BLACKHOLE_PEER_PORT_TX_RX, - } - c := &caseLeader{cc, -1, -1} - return &caseUntilSnapshot{ - rpcpbCase: rpcpb.Case_BLACKHOLE_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT, - Case: c, - } -} - -func new_Case_BLACKHOLE_PEER_PORT_TX_RX_QUORUM(clus *Cluster) Case { - c := &caseQuorum{ - caseByFunc: caseByFunc{ - rpcpbCase: rpcpb.Case_BLACKHOLE_PEER_PORT_TX_RX_QUORUM, - injectMember: inject_BLACKHOLE_PEER_PORT_TX_RX, - recoverMember: recover_BLACKHOLE_PEER_PORT_TX_RX, - }, - injected: make(map[int]struct{}), - } - return &caseDelay{ - Case: c, - delayDuration: clus.GetCaseDelayDuration(), - } -} - -func new_Case_BLACKHOLE_PEER_PORT_TX_RX_ALL(clus *Cluster) Case { - c := &caseAll{ - rpcpbCase: rpcpb.Case_BLACKHOLE_PEER_PORT_TX_RX_ALL, - injectMember: inject_BLACKHOLE_PEER_PORT_TX_RX, - recoverMember: recover_BLACKHOLE_PEER_PORT_TX_RX, - } - return &caseDelay{ - Case: c, - delayDuration: clus.GetCaseDelayDuration(), - } -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/case_network_delay.go b/vendor/go.etcd.io/etcd/functional/tester/case_network_delay.go deleted file mode 100644 index 39a4717020d9..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/case_network_delay.go +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "time" - - "github.com/coreos/etcd/functional/rpcpb" - - "go.uber.org/zap" -) - -const ( - // Wait more when it recovers from slow network, because network layer - // needs extra time to propagate traffic control (tc command) change. - // Otherwise, we get different hash values from the previous revision. - // For more detail, please see https://github.com/coreos/etcd/issues/5121. - waitRecover = 5 * time.Second -) - -func inject_DELAY_PEER_PORT_TX_RX(clus *Cluster, idx int) error { - clus.lg.Info( - "injecting delay latency", - zap.Duration("latency", time.Duration(clus.Tester.UpdatedDelayLatencyMs)*time.Millisecond), - zap.Duration("latency-rv", time.Duration(clus.Tester.DelayLatencyMsRv)*time.Millisecond), - zap.String("endpoint", clus.Members[idx].EtcdClientEndpoint), - ) - return clus.sendOp(idx, rpcpb.Operation_DELAY_PEER_PORT_TX_RX) -} - -func recover_DELAY_PEER_PORT_TX_RX(clus *Cluster, idx int) error { - err := clus.sendOp(idx, rpcpb.Operation_UNDELAY_PEER_PORT_TX_RX) - time.Sleep(waitRecover) - return err -} - -func new_Case_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER(clus *Cluster, random bool) Case { - cc := caseByFunc{ - rpcpbCase: rpcpb.Case_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER, - injectMember: inject_DELAY_PEER_PORT_TX_RX, - recoverMember: recover_DELAY_PEER_PORT_TX_RX, - } - clus.Tester.UpdatedDelayLatencyMs = clus.Tester.DelayLatencyMs - if random { - clus.UpdateDelayLatencyMs() - cc.rpcpbCase = rpcpb.Case_RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER - } - c := &caseFollower{cc, -1, -1} - return &caseDelay{ - Case: c, - delayDuration: clus.GetCaseDelayDuration(), - } -} - -func new_Case_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT(clus *Cluster, random bool) Case { - cc := caseByFunc{ - rpcpbCase: rpcpb.Case_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT, - injectMember: inject_DELAY_PEER_PORT_TX_RX, - recoverMember: recover_DELAY_PEER_PORT_TX_RX, - } - clus.Tester.UpdatedDelayLatencyMs = clus.Tester.DelayLatencyMs - if random { - clus.UpdateDelayLatencyMs() - cc.rpcpbCase = rpcpb.Case_RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT - } - c := &caseFollower{cc, -1, -1} - return &caseUntilSnapshot{ - rpcpbCase: cc.rpcpbCase, - Case: c, - } -} - -func new_Case_DELAY_PEER_PORT_TX_RX_LEADER(clus *Cluster, random bool) Case { - cc := caseByFunc{ - rpcpbCase: rpcpb.Case_DELAY_PEER_PORT_TX_RX_LEADER, - injectMember: inject_DELAY_PEER_PORT_TX_RX, - recoverMember: recover_DELAY_PEER_PORT_TX_RX, - } - clus.Tester.UpdatedDelayLatencyMs = clus.Tester.DelayLatencyMs - if random { - clus.UpdateDelayLatencyMs() - cc.rpcpbCase = rpcpb.Case_RANDOM_DELAY_PEER_PORT_TX_RX_LEADER - } - c := &caseLeader{cc, -1, -1} - return &caseDelay{ - Case: c, - delayDuration: clus.GetCaseDelayDuration(), - } -} - -func new_Case_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT(clus *Cluster, random bool) Case { - cc := caseByFunc{ - rpcpbCase: rpcpb.Case_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT, - injectMember: inject_DELAY_PEER_PORT_TX_RX, - recoverMember: recover_DELAY_PEER_PORT_TX_RX, - } - clus.Tester.UpdatedDelayLatencyMs = clus.Tester.DelayLatencyMs - if random { - clus.UpdateDelayLatencyMs() - cc.rpcpbCase = rpcpb.Case_RANDOM_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT - } - c := &caseLeader{cc, -1, -1} - return &caseUntilSnapshot{ - rpcpbCase: cc.rpcpbCase, - Case: c, - } -} - -func new_Case_DELAY_PEER_PORT_TX_RX_QUORUM(clus *Cluster, random bool) Case { - c := &caseQuorum{ - caseByFunc: caseByFunc{ - rpcpbCase: rpcpb.Case_DELAY_PEER_PORT_TX_RX_QUORUM, - injectMember: inject_DELAY_PEER_PORT_TX_RX, - recoverMember: recover_DELAY_PEER_PORT_TX_RX, - }, - injected: make(map[int]struct{}), - } - clus.Tester.UpdatedDelayLatencyMs = clus.Tester.DelayLatencyMs - if random { - clus.UpdateDelayLatencyMs() - c.rpcpbCase = rpcpb.Case_RANDOM_DELAY_PEER_PORT_TX_RX_QUORUM - } - return &caseDelay{ - Case: c, - delayDuration: clus.GetCaseDelayDuration(), - } -} - -func new_Case_DELAY_PEER_PORT_TX_RX_ALL(clus *Cluster, random bool) Case { - c := &caseAll{ - rpcpbCase: rpcpb.Case_DELAY_PEER_PORT_TX_RX_ALL, - injectMember: inject_DELAY_PEER_PORT_TX_RX, - recoverMember: recover_DELAY_PEER_PORT_TX_RX, - } - clus.Tester.UpdatedDelayLatencyMs = clus.Tester.DelayLatencyMs - if random { - clus.UpdateDelayLatencyMs() - c.rpcpbCase = rpcpb.Case_RANDOM_DELAY_PEER_PORT_TX_RX_ALL - } - return &caseDelay{ - Case: c, - delayDuration: clus.GetCaseDelayDuration(), - } -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/case_no_fail.go b/vendor/go.etcd.io/etcd/functional/tester/case_no_fail.go deleted file mode 100644 index e85bef93c442..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/case_no_fail.go +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "time" - - "github.com/coreos/etcd/functional/rpcpb" - - "go.uber.org/zap" -) - -type caseNoFailWithStress caseByFunc - -func (c *caseNoFailWithStress) Inject(clus *Cluster) error { - return nil -} - -func (c *caseNoFailWithStress) Recover(clus *Cluster) error { - return nil -} - -func (c *caseNoFailWithStress) Desc() string { - if c.desc != "" { - return c.desc - } - return c.rpcpbCase.String() -} - -func (c *caseNoFailWithStress) TestCase() rpcpb.Case { - return c.rpcpbCase -} - -func new_Case_NO_FAIL_WITH_STRESS(clus *Cluster) Case { - c := &caseNoFailWithStress{ - rpcpbCase: rpcpb.Case_NO_FAIL_WITH_STRESS, - } - return &caseDelay{ - Case: c, - delayDuration: clus.GetCaseDelayDuration(), - } -} - -type caseNoFailWithNoStressForLiveness caseByFunc - -func (c *caseNoFailWithNoStressForLiveness) Inject(clus *Cluster) error { - clus.lg.Info( - "extra delay for liveness mode with no stresser", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.String("desc", c.Desc()), - ) - time.Sleep(clus.GetCaseDelayDuration()) - - clus.lg.Info( - "wait health in liveness mode", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.String("desc", c.Desc()), - ) - return clus.WaitHealth() -} - -func (c *caseNoFailWithNoStressForLiveness) Recover(clus *Cluster) error { - return nil -} - -func (c *caseNoFailWithNoStressForLiveness) Desc() string { - if c.desc != "" { - return c.desc - } - return c.rpcpbCase.String() -} - -func (c *caseNoFailWithNoStressForLiveness) TestCase() rpcpb.Case { - return c.rpcpbCase -} - -func new_Case_NO_FAIL_WITH_NO_STRESS_FOR_LIVENESS(clus *Cluster) Case { - c := &caseNoFailWithNoStressForLiveness{ - rpcpbCase: rpcpb.Case_NO_FAIL_WITH_NO_STRESS_FOR_LIVENESS, - } - return &caseDelay{ - Case: c, - delayDuration: clus.GetCaseDelayDuration(), - } -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/case_sigquit_remove.go b/vendor/go.etcd.io/etcd/functional/tester/case_sigquit_remove.go deleted file mode 100644 index 13fe68f4e141..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/case_sigquit_remove.go +++ /dev/null @@ -1,229 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "context" - "fmt" - "sort" - "strings" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/functional/rpcpb" - - "go.uber.org/zap" -) - -func inject_SIGQUIT_ETCD_AND_REMOVE_DATA(clus *Cluster, idx1 int) error { - cli1, err := clus.Members[idx1].CreateEtcdClient() - if err != nil { - return err - } - defer cli1.Close() - - var mresp *clientv3.MemberListResponse - mresp, err = cli1.MemberList(context.Background()) - mss := []string{} - if err == nil && mresp != nil { - mss = describeMembers(mresp) - } - clus.lg.Info( - "member list before disastrous machine failure", - zap.String("request-to", clus.Members[idx1].EtcdClientEndpoint), - zap.Strings("members", mss), - zap.Error(err), - ) - if err != nil { - return err - } - - sresp, serr := cli1.Status(context.Background(), clus.Members[idx1].EtcdClientEndpoint) - if serr != nil { - return serr - } - id1 := sresp.Header.MemberId - is1 := fmt.Sprintf("%016x", id1) - - clus.lg.Info( - "disastrous machine failure START", - zap.String("target-endpoint", clus.Members[idx1].EtcdClientEndpoint), - zap.String("target-member-id", is1), - zap.Error(err), - ) - err = clus.sendOp(idx1, rpcpb.Operation_SIGQUIT_ETCD_AND_REMOVE_DATA) - clus.lg.Info( - "disastrous machine failure END", - zap.String("target-endpoint", clus.Members[idx1].EtcdClientEndpoint), - zap.String("target-member-id", is1), - zap.Error(err), - ) - if err != nil { - return err - } - - time.Sleep(2 * time.Second) - - idx2 := (idx1 + 1) % len(clus.Members) - var cli2 *clientv3.Client - cli2, err = clus.Members[idx2].CreateEtcdClient() - if err != nil { - return err - } - defer cli2.Close() - - // FIXME(bug): this may block forever during - // "SIGQUIT_AND_REMOVE_LEADER_UNTIL_TRIGGER_SNAPSHOT" - // is the new leader too busy with snapshotting? - // is raft proposal dropped? - // enable client keepalive for failover? - clus.lg.Info( - "member remove after disaster START", - zap.String("target-endpoint", clus.Members[idx1].EtcdClientEndpoint), - zap.String("target-member-id", is1), - zap.String("request-to", clus.Members[idx2].EtcdClientEndpoint), - ) - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - _, err = cli2.MemberRemove(ctx, id1) - cancel() - clus.lg.Info( - "member remove after disaster END", - zap.String("target-endpoint", clus.Members[idx1].EtcdClientEndpoint), - zap.String("target-member-id", is1), - zap.String("request-to", clus.Members[idx2].EtcdClientEndpoint), - zap.Error(err), - ) - if err != nil { - return err - } - - time.Sleep(2 * time.Second) - - mresp, err = cli2.MemberList(context.Background()) - mss = []string{} - if err == nil && mresp != nil { - mss = describeMembers(mresp) - } - clus.lg.Info( - "member list after member remove", - zap.String("request-to", clus.Members[idx2].EtcdClientEndpoint), - zap.Strings("members", mss), - zap.Error(err), - ) - return err -} - -func recover_SIGQUIT_ETCD_AND_REMOVE_DATA(clus *Cluster, idx1 int) error { - idx2 := (idx1 + 1) % len(clus.Members) - cli2, err := clus.Members[idx2].CreateEtcdClient() - if err != nil { - return err - } - defer cli2.Close() - - _, err = cli2.MemberAdd(context.Background(), clus.Members[idx1].Etcd.AdvertisePeerURLs) - clus.lg.Info( - "member add before fresh restart", - zap.String("target-endpoint", clus.Members[idx1].EtcdClientEndpoint), - zap.String("request-to", clus.Members[idx2].EtcdClientEndpoint), - zap.Error(err), - ) - if err != nil { - return err - } - - time.Sleep(2 * time.Second) - - clus.Members[idx1].Etcd.InitialClusterState = "existing" - err = clus.sendOp(idx1, rpcpb.Operation_RESTART_ETCD) - clus.lg.Info( - "fresh restart after member add", - zap.String("target-endpoint", clus.Members[idx1].EtcdClientEndpoint), - zap.Error(err), - ) - if err != nil { - return err - } - - time.Sleep(2 * time.Second) - - var mresp *clientv3.MemberListResponse - mresp, err = cli2.MemberList(context.Background()) - mss := []string{} - if err == nil && mresp != nil { - mss = describeMembers(mresp) - } - clus.lg.Info( - "member list after member add", - zap.String("request-to", clus.Members[idx2].EtcdClientEndpoint), - zap.Strings("members", mss), - zap.Error(err), - ) - return err -} - -func new_Case_SIGQUIT_AND_REMOVE_ONE_FOLLOWER(clus *Cluster) Case { - cc := caseByFunc{ - rpcpbCase: rpcpb.Case_SIGQUIT_AND_REMOVE_ONE_FOLLOWER, - injectMember: inject_SIGQUIT_ETCD_AND_REMOVE_DATA, - recoverMember: recover_SIGQUIT_ETCD_AND_REMOVE_DATA, - } - c := &caseFollower{cc, -1, -1} - return &caseDelay{ - Case: c, - delayDuration: clus.GetCaseDelayDuration(), - } -} - -func new_Case_SIGQUIT_AND_REMOVE_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT(clus *Cluster) Case { - return &caseUntilSnapshot{ - rpcpbCase: rpcpb.Case_SIGQUIT_AND_REMOVE_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT, - Case: new_Case_SIGQUIT_AND_REMOVE_ONE_FOLLOWER(clus), - } -} - -func new_Case_SIGQUIT_AND_REMOVE_LEADER(clus *Cluster) Case { - cc := caseByFunc{ - rpcpbCase: rpcpb.Case_SIGQUIT_AND_REMOVE_LEADER, - injectMember: inject_SIGQUIT_ETCD_AND_REMOVE_DATA, - recoverMember: recover_SIGQUIT_ETCD_AND_REMOVE_DATA, - } - c := &caseLeader{cc, -1, -1} - return &caseDelay{ - Case: c, - delayDuration: clus.GetCaseDelayDuration(), - } -} - -func new_Case_SIGQUIT_AND_REMOVE_LEADER_UNTIL_TRIGGER_SNAPSHOT(clus *Cluster) Case { - return &caseUntilSnapshot{ - rpcpbCase: rpcpb.Case_SIGQUIT_AND_REMOVE_LEADER_UNTIL_TRIGGER_SNAPSHOT, - Case: new_Case_SIGQUIT_AND_REMOVE_LEADER(clus), - } -} - -func describeMembers(mresp *clientv3.MemberListResponse) (ss []string) { - ss = make([]string, len(mresp.Members)) - for i, m := range mresp.Members { - ss[i] = fmt.Sprintf("Name %s / ID %016x / ClientURLs %s / PeerURLs %s", - m.Name, - m.ID, - strings.Join(m.ClientURLs, ","), - strings.Join(m.PeerURLs, ","), - ) - } - sort.Strings(ss) - return ss -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/case_sigquit_remove_quorum.go b/vendor/go.etcd.io/etcd/functional/tester/case_sigquit_remove_quorum.go deleted file mode 100644 index 9653de10dbfd..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/case_sigquit_remove_quorum.go +++ /dev/null @@ -1,275 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "context" - "fmt" - "strings" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/functional/rpcpb" - - "go.uber.org/zap" -) - -type fetchSnapshotCaseQuorum struct { - desc string - rpcpbCase rpcpb.Case - injected map[int]struct{} - snapshotted int -} - -func (c *fetchSnapshotCaseQuorum) Inject(clus *Cluster) error { - // 1. Assume node C is the current leader with most up-to-date data. - lead, err := clus.GetLeader() - if err != nil { - return err - } - c.snapshotted = lead - - // 2. Download snapshot from node C, before destroying node A and B. - clus.lg.Info( - "save snapshot on leader node START", - zap.String("target-endpoint", clus.Members[lead].EtcdClientEndpoint), - ) - var resp *rpcpb.Response - resp, err = clus.sendOpWithResp(lead, rpcpb.Operation_SAVE_SNAPSHOT) - if resp == nil || (resp != nil && !resp.Success) || err != nil { - clus.lg.Info( - "save snapshot on leader node FAIL", - zap.String("target-endpoint", clus.Members[lead].EtcdClientEndpoint), - zap.Error(err), - ) - return err - } - clus.lg.Info( - "save snapshot on leader node SUCCESS", - zap.String("target-endpoint", clus.Members[lead].EtcdClientEndpoint), - zap.String("member-name", resp.SnapshotInfo.MemberName), - zap.Strings("member-client-urls", resp.SnapshotInfo.MemberClientURLs), - zap.String("snapshot-path", resp.SnapshotInfo.SnapshotPath), - zap.String("snapshot-file-size", resp.SnapshotInfo.SnapshotFileSize), - zap.String("snapshot-total-size", resp.SnapshotInfo.SnapshotTotalSize), - zap.Int64("snapshot-total-key", resp.SnapshotInfo.SnapshotTotalKey), - zap.Int64("snapshot-hash", resp.SnapshotInfo.SnapshotHash), - zap.Int64("snapshot-revision", resp.SnapshotInfo.SnapshotRevision), - zap.String("took", resp.SnapshotInfo.Took), - zap.Error(err), - ) - if err != nil { - return err - } - clus.Members[lead].SnapshotInfo = resp.SnapshotInfo - - leaderc, err := clus.Members[lead].CreateEtcdClient() - if err != nil { - return err - } - defer leaderc.Close() - var mresp *clientv3.MemberListResponse - mresp, err = leaderc.MemberList(context.Background()) - mss := []string{} - if err == nil && mresp != nil { - mss = describeMembers(mresp) - } - clus.lg.Info( - "member list before disastrous machine failure", - zap.String("request-to", clus.Members[lead].EtcdClientEndpoint), - zap.Strings("members", mss), - zap.Error(err), - ) - if err != nil { - return err - } - - // simulate real life; machine failures may happen - // after some time since last snapshot save - time.Sleep(time.Second) - - // 3. Destroy node A and B, and make the whole cluster inoperable. - for { - c.injected = pickQuorum(len(clus.Members)) - if _, ok := c.injected[lead]; !ok { - break - } - } - for idx := range c.injected { - clus.lg.Info( - "disastrous machine failure to quorum START", - zap.String("target-endpoint", clus.Members[idx].EtcdClientEndpoint), - ) - err = clus.sendOp(idx, rpcpb.Operation_SIGQUIT_ETCD_AND_REMOVE_DATA) - clus.lg.Info( - "disastrous machine failure to quorum END", - zap.String("target-endpoint", clus.Members[idx].EtcdClientEndpoint), - zap.Error(err), - ) - if err != nil { - return err - } - } - - // 4. Now node C cannot operate either. - // 5. SIGTERM node C and remove its data directories. - clus.lg.Info( - "disastrous machine failure to old leader START", - zap.String("target-endpoint", clus.Members[lead].EtcdClientEndpoint), - ) - err = clus.sendOp(lead, rpcpb.Operation_SIGQUIT_ETCD_AND_REMOVE_DATA) - clus.lg.Info( - "disastrous machine failure to old leader END", - zap.String("target-endpoint", clus.Members[lead].EtcdClientEndpoint), - zap.Error(err), - ) - return err -} - -func (c *fetchSnapshotCaseQuorum) Recover(clus *Cluster) error { - // 6. Restore a new seed member from node C's latest snapshot file. - oldlead := c.snapshotted - - // configuration on restart from recovered snapshot - // seed member's configuration is all the same as previous one - // except initial cluster string is now a single-node cluster - clus.Members[oldlead].EtcdOnSnapshotRestore = clus.Members[oldlead].Etcd - clus.Members[oldlead].EtcdOnSnapshotRestore.InitialClusterState = "existing" - name := clus.Members[oldlead].Etcd.Name - initClus := []string{} - for _, u := range clus.Members[oldlead].Etcd.AdvertisePeerURLs { - initClus = append(initClus, fmt.Sprintf("%s=%s", name, u)) - } - clus.Members[oldlead].EtcdOnSnapshotRestore.InitialCluster = strings.Join(initClus, ",") - - clus.lg.Info( - "restore snapshot and restart from snapshot request START", - zap.String("target-endpoint", clus.Members[oldlead].EtcdClientEndpoint), - zap.Strings("initial-cluster", initClus), - ) - err := clus.sendOp(oldlead, rpcpb.Operation_RESTORE_RESTART_FROM_SNAPSHOT) - clus.lg.Info( - "restore snapshot and restart from snapshot request END", - zap.String("target-endpoint", clus.Members[oldlead].EtcdClientEndpoint), - zap.Strings("initial-cluster", initClus), - zap.Error(err), - ) - if err != nil { - return err - } - - leaderc, err := clus.Members[oldlead].CreateEtcdClient() - if err != nil { - return err - } - defer leaderc.Close() - - // 7. Add another member to establish 2-node cluster. - // 8. Add another member to establish 3-node cluster. - // 9. Add more if any. - idxs := make([]int, 0, len(c.injected)) - for idx := range c.injected { - idxs = append(idxs, idx) - } - clus.lg.Info("member add START", zap.Int("members-to-add", len(idxs))) - for i, idx := range idxs { - clus.lg.Info( - "member add request SENT", - zap.String("target-endpoint", clus.Members[idx].EtcdClientEndpoint), - zap.Strings("peer-urls", clus.Members[idx].Etcd.AdvertisePeerURLs), - ) - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - _, err := leaderc.MemberAdd(ctx, clus.Members[idx].Etcd.AdvertisePeerURLs) - cancel() - clus.lg.Info( - "member add request DONE", - zap.String("target-endpoint", clus.Members[idx].EtcdClientEndpoint), - zap.Strings("peer-urls", clus.Members[idx].Etcd.AdvertisePeerURLs), - zap.Error(err), - ) - if err != nil { - return err - } - - // start the added(new) member with fresh data - clus.Members[idx].EtcdOnSnapshotRestore = clus.Members[idx].Etcd - clus.Members[idx].EtcdOnSnapshotRestore.InitialClusterState = "existing" - name := clus.Members[idx].Etcd.Name - for _, u := range clus.Members[idx].Etcd.AdvertisePeerURLs { - initClus = append(initClus, fmt.Sprintf("%s=%s", name, u)) - } - clus.Members[idx].EtcdOnSnapshotRestore.InitialCluster = strings.Join(initClus, ",") - clus.lg.Info( - "restart from snapshot request SENT", - zap.String("target-endpoint", clus.Members[idx].EtcdClientEndpoint), - zap.Strings("initial-cluster", initClus), - ) - err = clus.sendOp(idx, rpcpb.Operation_RESTART_FROM_SNAPSHOT) - clus.lg.Info( - "restart from snapshot request DONE", - zap.String("target-endpoint", clus.Members[idx].EtcdClientEndpoint), - zap.Strings("initial-cluster", initClus), - zap.Error(err), - ) - if err != nil { - return err - } - - if i != len(c.injected)-1 { - // wait until membership reconfiguration entry gets applied - // TODO: test concurrent member add - dur := 5 * clus.Members[idx].ElectionTimeout() - clus.lg.Info( - "waiting after restart from snapshot request", - zap.Int("i", i), - zap.Int("idx", idx), - zap.Duration("sleep", dur), - ) - time.Sleep(dur) - } else { - clus.lg.Info( - "restart from snapshot request ALL END", - zap.Int("i", i), - zap.Int("idx", idx), - ) - } - } - return nil -} - -func (c *fetchSnapshotCaseQuorum) Desc() string { - if c.desc != "" { - return c.desc - } - return c.rpcpbCase.String() -} - -func (c *fetchSnapshotCaseQuorum) TestCase() rpcpb.Case { - return c.rpcpbCase -} - -func new_Case_SIGQUIT_AND_REMOVE_QUORUM_AND_RESTORE_LEADER_SNAPSHOT_FROM_SCRATCH(clus *Cluster) Case { - c := &fetchSnapshotCaseQuorum{ - rpcpbCase: rpcpb.Case_SIGQUIT_AND_REMOVE_QUORUM_AND_RESTORE_LEADER_SNAPSHOT_FROM_SCRATCH, - injected: make(map[int]struct{}), - snapshotted: -1, - } - // simulate real life; machine replacements may happen - // after some time since disaster - return &caseDelay{ - Case: c, - delayDuration: clus.GetCaseDelayDuration(), - } -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/case_sigterm.go b/vendor/go.etcd.io/etcd/functional/tester/case_sigterm.go deleted file mode 100644 index f5d472afcdc5..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/case_sigterm.go +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import "github.com/coreos/etcd/functional/rpcpb" - -func inject_SIGTERM_ETCD(clus *Cluster, idx int) error { - return clus.sendOp(idx, rpcpb.Operation_SIGTERM_ETCD) -} - -func recover_SIGTERM_ETCD(clus *Cluster, idx int) error { - return clus.sendOp(idx, rpcpb.Operation_RESTART_ETCD) -} - -func new_Case_SIGTERM_ONE_FOLLOWER(clus *Cluster) Case { - cc := caseByFunc{ - rpcpbCase: rpcpb.Case_SIGTERM_ONE_FOLLOWER, - injectMember: inject_SIGTERM_ETCD, - recoverMember: recover_SIGTERM_ETCD, - } - c := &caseFollower{cc, -1, -1} - return &caseDelay{ - Case: c, - delayDuration: clus.GetCaseDelayDuration(), - } -} - -func new_Case_SIGTERM_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT(clus *Cluster) Case { - return &caseUntilSnapshot{ - rpcpbCase: rpcpb.Case_SIGTERM_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT, - Case: new_Case_SIGTERM_ONE_FOLLOWER(clus), - } -} - -func new_Case_SIGTERM_LEADER(clus *Cluster) Case { - cc := caseByFunc{ - rpcpbCase: rpcpb.Case_SIGTERM_LEADER, - injectMember: inject_SIGTERM_ETCD, - recoverMember: recover_SIGTERM_ETCD, - } - c := &caseLeader{cc, -1, -1} - return &caseDelay{ - Case: c, - delayDuration: clus.GetCaseDelayDuration(), - } -} - -func new_Case_SIGTERM_LEADER_UNTIL_TRIGGER_SNAPSHOT(clus *Cluster) Case { - return &caseUntilSnapshot{ - rpcpbCase: rpcpb.Case_SIGTERM_LEADER_UNTIL_TRIGGER_SNAPSHOT, - Case: new_Case_SIGTERM_LEADER(clus), - } -} - -func new_Case_SIGTERM_QUORUM(clus *Cluster) Case { - c := &caseQuorum{ - caseByFunc: caseByFunc{ - rpcpbCase: rpcpb.Case_SIGTERM_QUORUM, - injectMember: inject_SIGTERM_ETCD, - recoverMember: recover_SIGTERM_ETCD, - }, - injected: make(map[int]struct{}), - } - return &caseDelay{ - Case: c, - delayDuration: clus.GetCaseDelayDuration(), - } -} - -func new_Case_SIGTERM_ALL(clus *Cluster) Case { - c := &caseAll{ - rpcpbCase: rpcpb.Case_SIGTERM_ALL, - injectMember: inject_SIGTERM_ETCD, - recoverMember: recover_SIGTERM_ETCD, - } - return &caseDelay{ - Case: c, - delayDuration: clus.GetCaseDelayDuration(), - } -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/checker.go b/vendor/go.etcd.io/etcd/functional/tester/checker.go deleted file mode 100644 index 48e98cb0db82..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/checker.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import "github.com/coreos/etcd/functional/rpcpb" - -// Checker checks cluster consistency. -type Checker interface { - // Type returns the checker type. - Type() rpcpb.Checker - // EtcdClientEndpoints returns the client endpoints of - // all checker target nodes.. - EtcdClientEndpoints() []string - // Check returns an error if the system fails a consistency check. - Check() error -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/checker_kv_hash.go b/vendor/go.etcd.io/etcd/functional/tester/checker_kv_hash.go deleted file mode 100644 index 586ad89bd130..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/checker_kv_hash.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "fmt" - "time" - - "github.com/coreos/etcd/functional/rpcpb" - - "go.uber.org/zap" -) - -const retries = 7 - -type kvHashChecker struct { - ctype rpcpb.Checker - clus *Cluster -} - -func newKVHashChecker(clus *Cluster) Checker { - return &kvHashChecker{ - ctype: rpcpb.Checker_KV_HASH, - clus: clus, - } -} - -func (hc *kvHashChecker) checkRevAndHashes() (err error) { - var ( - revs map[string]int64 - hashes map[string]int64 - ) - // retries in case of transient failure or etcd cluster has not stablized yet. - for i := 0; i < retries; i++ { - revs, hashes, err = hc.clus.getRevisionHash() - if err != nil { - hc.clus.lg.Warn( - "failed to get revision and hash", - zap.Int("retries", i), - zap.Error(err), - ) - } else { - sameRev := getSameValue(revs) - sameHashes := getSameValue(hashes) - if sameRev && sameHashes { - return nil - } - hc.clus.lg.Warn( - "retrying; etcd cluster is not stable", - zap.Int("retries", i), - zap.Bool("same-revisions", sameRev), - zap.Bool("same-hashes", sameHashes), - zap.String("revisions", fmt.Sprintf("%+v", revs)), - zap.String("hashes", fmt.Sprintf("%+v", hashes)), - ) - } - time.Sleep(time.Second) - } - - if err != nil { - return fmt.Errorf("failed revision and hash check (%v)", err) - } - - return fmt.Errorf("etcd cluster is not stable: [revisions: %v] and [hashes: %v]", revs, hashes) -} - -func (hc *kvHashChecker) Type() rpcpb.Checker { - return hc.ctype -} - -func (hc *kvHashChecker) EtcdClientEndpoints() []string { - return hc.clus.EtcdClientEndpoints() -} - -func (hc *kvHashChecker) Check() error { - return hc.checkRevAndHashes() -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/checker_lease_expire.go b/vendor/go.etcd.io/etcd/functional/tester/checker_lease_expire.go deleted file mode 100644 index a897421288ca..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/checker_lease_expire.go +++ /dev/null @@ -1,238 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "context" - "fmt" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - "github.com/coreos/etcd/functional/rpcpb" - - "go.uber.org/zap" - "google.golang.org/grpc" -) - -type leaseExpireChecker struct { - ctype rpcpb.Checker - lg *zap.Logger - m *rpcpb.Member - ls *leaseStresser - cli *clientv3.Client -} - -func newLeaseExpireChecker(ls *leaseStresser) Checker { - return &leaseExpireChecker{ - ctype: rpcpb.Checker_LEASE_EXPIRE, - lg: ls.lg, - m: ls.m, - ls: ls, - } -} - -func (lc *leaseExpireChecker) Type() rpcpb.Checker { - return lc.ctype -} - -func (lc *leaseExpireChecker) EtcdClientEndpoints() []string { - return []string{lc.m.EtcdClientEndpoint} -} - -func (lc *leaseExpireChecker) Check() error { - if lc.ls == nil { - return nil - } - if lc.ls != nil && - (lc.ls.revokedLeases == nil || - lc.ls.aliveLeases == nil || - lc.ls.shortLivedLeases == nil) { - return nil - } - - cli, err := lc.m.CreateEtcdClient(grpc.WithBackoffMaxDelay(time.Second)) - if err != nil { - return fmt.Errorf("%v (%q)", err, lc.m.EtcdClientEndpoint) - } - defer func() { - if cli != nil { - cli.Close() - } - }() - lc.cli = cli - - if err := lc.check(true, lc.ls.revokedLeases.leases); err != nil { - return err - } - if err := lc.check(false, lc.ls.aliveLeases.leases); err != nil { - return err - } - return lc.checkShortLivedLeases() -} - -const leaseExpireCheckerTimeout = 10 * time.Second - -// checkShortLivedLeases ensures leases expire. -func (lc *leaseExpireChecker) checkShortLivedLeases() error { - ctx, cancel := context.WithTimeout(context.Background(), leaseExpireCheckerTimeout) - errc := make(chan error) - defer cancel() - for leaseID := range lc.ls.shortLivedLeases.leases { - go func(id int64) { - errc <- lc.checkShortLivedLease(ctx, id) - }(leaseID) - } - - var errs []error - for range lc.ls.shortLivedLeases.leases { - if err := <-errc; err != nil { - errs = append(errs, err) - } - } - return errsToError(errs) -} - -func (lc *leaseExpireChecker) checkShortLivedLease(ctx context.Context, leaseID int64) (err error) { - // retry in case of transient failure or lease is expired but not yet revoked due to the fact that etcd cluster didn't have enought time to delete it. - var resp *clientv3.LeaseTimeToLiveResponse - for i := 0; i < retries; i++ { - resp, err = lc.getLeaseByID(ctx, leaseID) - // lease not found, for ~v3.1 compatibilities, check ErrLeaseNotFound - if (err == nil && resp.TTL == -1) || (err != nil && rpctypes.Error(err) == rpctypes.ErrLeaseNotFound) { - return nil - } - if err != nil { - lc.lg.Debug( - "retrying; Lease TimeToLive failed", - zap.Int("retries", i), - zap.String("lease-id", fmt.Sprintf("%016x", leaseID)), - zap.Error(err), - ) - continue - } - if resp.TTL > 0 { - dur := time.Duration(resp.TTL) * time.Second - lc.lg.Debug( - "lease has not been expired, wait until expire", - zap.String("lease-id", fmt.Sprintf("%016x", leaseID)), - zap.Int64("ttl", resp.TTL), - zap.Duration("wait-duration", dur), - ) - time.Sleep(dur) - } else { - lc.lg.Debug( - "lease expired but not yet revoked", - zap.Int("retries", i), - zap.String("lease-id", fmt.Sprintf("%016x", leaseID)), - zap.Int64("ttl", resp.TTL), - zap.Duration("wait-duration", time.Second), - ) - time.Sleep(time.Second) - } - if err = lc.checkLease(ctx, false, leaseID); err != nil { - continue - } - return nil - } - return err -} - -func (lc *leaseExpireChecker) checkLease(ctx context.Context, expired bool, leaseID int64) error { - keysExpired, err := lc.hasKeysAttachedToLeaseExpired(ctx, leaseID) - if err != nil { - lc.lg.Warn( - "hasKeysAttachedToLeaseExpired failed", - zap.String("endpoint", lc.m.EtcdClientEndpoint), - zap.Error(err), - ) - return err - } - leaseExpired, err := lc.hasLeaseExpired(ctx, leaseID) - if err != nil { - lc.lg.Warn( - "hasLeaseExpired failed", - zap.String("endpoint", lc.m.EtcdClientEndpoint), - zap.Error(err), - ) - return err - } - if leaseExpired != keysExpired { - return fmt.Errorf("lease %v expiration mismatch (lease expired=%v, keys expired=%v)", leaseID, leaseExpired, keysExpired) - } - if leaseExpired != expired { - return fmt.Errorf("lease %v expected expired=%v, got %v", leaseID, expired, leaseExpired) - } - return nil -} - -func (lc *leaseExpireChecker) check(expired bool, leases map[int64]time.Time) error { - ctx, cancel := context.WithTimeout(context.Background(), leaseExpireCheckerTimeout) - defer cancel() - for leaseID := range leases { - if err := lc.checkLease(ctx, expired, leaseID); err != nil { - return err - } - } - return nil -} - -// TODO: handle failures from "grpc.FailFast(false)" -func (lc *leaseExpireChecker) getLeaseByID(ctx context.Context, leaseID int64) (*clientv3.LeaseTimeToLiveResponse, error) { - return lc.cli.TimeToLive( - ctx, - clientv3.LeaseID(leaseID), - clientv3.WithAttachedKeys(), - ) -} - -func (lc *leaseExpireChecker) hasLeaseExpired(ctx context.Context, leaseID int64) (bool, error) { - // keep retrying until lease's state is known or ctx is being canceled - for ctx.Err() == nil { - resp, err := lc.getLeaseByID(ctx, leaseID) - if err != nil { - // for ~v3.1 compatibilities - if rpctypes.Error(err) == rpctypes.ErrLeaseNotFound { - return true, nil - } - } else { - return resp.TTL == -1, nil - } - lc.lg.Warn( - "hasLeaseExpired getLeaseByID failed", - zap.String("endpoint", lc.m.EtcdClientEndpoint), - zap.String("lease-id", fmt.Sprintf("%016x", leaseID)), - zap.Error(err), - ) - } - return false, ctx.Err() -} - -// The keys attached to the lease has the format of "_" where idx is the ordering key creation -// Since the format of keys contains about leaseID, finding keys base on "" prefix -// determines whether the attached keys for a given leaseID has been deleted or not -func (lc *leaseExpireChecker) hasKeysAttachedToLeaseExpired(ctx context.Context, leaseID int64) (bool, error) { - resp, err := lc.cli.Get(ctx, fmt.Sprintf("%d", leaseID), clientv3.WithPrefix()) - if err != nil { - lc.lg.Warn( - "hasKeysAttachedToLeaseExpired failed", - zap.String("endpoint", lc.m.EtcdClientEndpoint), - zap.String("lease-id", fmt.Sprintf("%016x", leaseID)), - zap.Error(err), - ) - return false, err - } - return len(resp.Kvs) == 0, nil -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/checker_no_check.go b/vendor/go.etcd.io/etcd/functional/tester/checker_no_check.go deleted file mode 100644 index d36702319885..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/checker_no_check.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import "github.com/coreos/etcd/functional/rpcpb" - -type noCheck struct{} - -func newNoChecker() Checker { return &noCheck{} } -func (nc *noCheck) Type() rpcpb.Checker { return rpcpb.Checker_NO_CHECK } -func (nc *noCheck) EtcdClientEndpoints() []string { return nil } -func (nc *noCheck) Check() error { return nil } diff --git a/vendor/go.etcd.io/etcd/functional/tester/checker_runner.go b/vendor/go.etcd.io/etcd/functional/tester/checker_runner.go deleted file mode 100644 index a5b7ff4d15fd..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/checker_runner.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import "github.com/coreos/etcd/functional/rpcpb" - -type runnerChecker struct { - ctype rpcpb.Checker - etcdClientEndpoint string - errc chan error -} - -func newRunnerChecker(ep string, errc chan error) Checker { - return &runnerChecker{ - ctype: rpcpb.Checker_RUNNER, - etcdClientEndpoint: ep, - errc: errc, - } -} - -func (rc *runnerChecker) Type() rpcpb.Checker { - return rc.ctype -} - -func (rc *runnerChecker) EtcdClientEndpoints() []string { - return []string{rc.etcdClientEndpoint} -} - -func (rc *runnerChecker) Check() error { - select { - case err := <-rc.errc: - return err - default: - return nil - } -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/cluster.go b/vendor/go.etcd.io/etcd/functional/tester/cluster.go deleted file mode 100644 index b18084d48ef0..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/cluster.go +++ /dev/null @@ -1,761 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "context" - "errors" - "fmt" - "io" - "io/ioutil" - "math/rand" - "net/http" - "net/url" - "path/filepath" - "strings" - "sync" - "time" - - "github.com/coreos/etcd/functional/rpcpb" - "github.com/coreos/etcd/pkg/debugutil" - "github.com/coreos/etcd/pkg/fileutil" - - "github.com/prometheus/client_golang/prometheus/promhttp" - "go.uber.org/zap" - "golang.org/x/time/rate" - "google.golang.org/grpc" -) - -// Cluster defines tester cluster. -type Cluster struct { - lg *zap.Logger - - agentConns []*grpc.ClientConn - agentClients []rpcpb.TransportClient - agentStreams []rpcpb.Transport_TransportClient - agentRequests []*rpcpb.Request - - testerHTTPServer *http.Server - - Members []*rpcpb.Member `yaml:"agent-configs"` - Tester *rpcpb.Tester `yaml:"tester-config"` - - cases []Case - - rateLimiter *rate.Limiter - stresser Stresser - checkers []Checker - - currentRevision int64 - rd int - cs int -} - -var dialOpts = []grpc.DialOption{ - grpc.WithInsecure(), - grpc.WithTimeout(5 * time.Second), - grpc.WithBlock(), -} - -// NewCluster creates a client from a tester configuration. -func NewCluster(lg *zap.Logger, fpath string) (*Cluster, error) { - clus, err := read(lg, fpath) - if err != nil { - return nil, err - } - - clus.agentConns = make([]*grpc.ClientConn, len(clus.Members)) - clus.agentClients = make([]rpcpb.TransportClient, len(clus.Members)) - clus.agentStreams = make([]rpcpb.Transport_TransportClient, len(clus.Members)) - clus.agentRequests = make([]*rpcpb.Request, len(clus.Members)) - clus.cases = make([]Case, 0) - - for i, ap := range clus.Members { - var err error - clus.agentConns[i], err = grpc.Dial(ap.AgentAddr, dialOpts...) - if err != nil { - return nil, err - } - clus.agentClients[i] = rpcpb.NewTransportClient(clus.agentConns[i]) - clus.lg.Info("connected", zap.String("agent-address", ap.AgentAddr)) - - clus.agentStreams[i], err = clus.agentClients[i].Transport(context.Background()) - if err != nil { - return nil, err - } - clus.lg.Info("created stream", zap.String("agent-address", ap.AgentAddr)) - } - - mux := http.NewServeMux() - mux.Handle("/metrics", promhttp.Handler()) - if clus.Tester.EnablePprof { - for p, h := range debugutil.PProfHandlers() { - mux.Handle(p, h) - } - } - clus.testerHTTPServer = &http.Server{ - Addr: clus.Tester.Addr, - Handler: mux, - } - go clus.serveTesterServer() - - clus.updateCases() - - clus.rateLimiter = rate.NewLimiter( - rate.Limit(int(clus.Tester.StressQPS)), - int(clus.Tester.StressQPS), - ) - - clus.setStresserChecker() - - return clus, nil -} - -// EtcdClientEndpoints returns all etcd client endpoints. -func (clus *Cluster) EtcdClientEndpoints() (css []string) { - css = make([]string, len(clus.Members)) - for i := range clus.Members { - css[i] = clus.Members[i].EtcdClientEndpoint - } - return css -} - -func (clus *Cluster) serveTesterServer() { - clus.lg.Info( - "started tester HTTP server", - zap.String("tester-address", clus.Tester.Addr), - ) - err := clus.testerHTTPServer.ListenAndServe() - clus.lg.Info( - "tester HTTP server returned", - zap.String("tester-address", clus.Tester.Addr), - zap.Error(err), - ) - if err != nil && err != http.ErrServerClosed { - clus.lg.Fatal("tester HTTP errored", zap.Error(err)) - } -} - -func (clus *Cluster) updateCases() { - for _, cs := range clus.Tester.Cases { - switch cs { - case "SIGTERM_ONE_FOLLOWER": - clus.cases = append(clus.cases, - new_Case_SIGTERM_ONE_FOLLOWER(clus)) - case "SIGTERM_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT": - clus.cases = append(clus.cases, - new_Case_SIGTERM_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT(clus)) - case "SIGTERM_LEADER": - clus.cases = append(clus.cases, - new_Case_SIGTERM_LEADER(clus)) - case "SIGTERM_LEADER_UNTIL_TRIGGER_SNAPSHOT": - clus.cases = append(clus.cases, - new_Case_SIGTERM_LEADER_UNTIL_TRIGGER_SNAPSHOT(clus)) - case "SIGTERM_QUORUM": - clus.cases = append(clus.cases, - new_Case_SIGTERM_QUORUM(clus)) - case "SIGTERM_ALL": - clus.cases = append(clus.cases, - new_Case_SIGTERM_ALL(clus)) - - case "SIGQUIT_AND_REMOVE_ONE_FOLLOWER": - clus.cases = append(clus.cases, - new_Case_SIGQUIT_AND_REMOVE_ONE_FOLLOWER(clus)) - case "SIGQUIT_AND_REMOVE_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT": - clus.cases = append(clus.cases, - new_Case_SIGQUIT_AND_REMOVE_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT(clus)) - case "SIGQUIT_AND_REMOVE_LEADER": - clus.cases = append(clus.cases, - new_Case_SIGQUIT_AND_REMOVE_LEADER(clus)) - case "SIGQUIT_AND_REMOVE_LEADER_UNTIL_TRIGGER_SNAPSHOT": - clus.cases = append(clus.cases, - new_Case_SIGQUIT_AND_REMOVE_LEADER_UNTIL_TRIGGER_SNAPSHOT(clus)) - case "SIGQUIT_AND_REMOVE_QUORUM_AND_RESTORE_LEADER_SNAPSHOT_FROM_SCRATCH": - clus.cases = append(clus.cases, - new_Case_SIGQUIT_AND_REMOVE_QUORUM_AND_RESTORE_LEADER_SNAPSHOT_FROM_SCRATCH(clus)) - - case "BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER": - clus.cases = append(clus.cases, - new_Case_BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER(clus)) - case "BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT": - clus.cases = append(clus.cases, - new_Case_BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT()) - case "BLACKHOLE_PEER_PORT_TX_RX_LEADER": - clus.cases = append(clus.cases, - new_Case_BLACKHOLE_PEER_PORT_TX_RX_LEADER(clus)) - case "BLACKHOLE_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT": - clus.cases = append(clus.cases, - new_Case_BLACKHOLE_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT()) - case "BLACKHOLE_PEER_PORT_TX_RX_QUORUM": - clus.cases = append(clus.cases, - new_Case_BLACKHOLE_PEER_PORT_TX_RX_QUORUM(clus)) - case "BLACKHOLE_PEER_PORT_TX_RX_ALL": - clus.cases = append(clus.cases, - new_Case_BLACKHOLE_PEER_PORT_TX_RX_ALL(clus)) - - case "DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER": - clus.cases = append(clus.cases, - new_Case_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER(clus, false)) - case "RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER": - clus.cases = append(clus.cases, - new_Case_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER(clus, true)) - case "DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT": - clus.cases = append(clus.cases, - new_Case_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT(clus, false)) - case "RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT": - clus.cases = append(clus.cases, - new_Case_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT(clus, true)) - case "DELAY_PEER_PORT_TX_RX_LEADER": - clus.cases = append(clus.cases, - new_Case_DELAY_PEER_PORT_TX_RX_LEADER(clus, false)) - case "RANDOM_DELAY_PEER_PORT_TX_RX_LEADER": - clus.cases = append(clus.cases, - new_Case_DELAY_PEER_PORT_TX_RX_LEADER(clus, true)) - case "DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT": - clus.cases = append(clus.cases, - new_Case_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT(clus, false)) - case "RANDOM_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT": - clus.cases = append(clus.cases, - new_Case_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT(clus, true)) - case "DELAY_PEER_PORT_TX_RX_QUORUM": - clus.cases = append(clus.cases, - new_Case_DELAY_PEER_PORT_TX_RX_QUORUM(clus, false)) - case "RANDOM_DELAY_PEER_PORT_TX_RX_QUORUM": - clus.cases = append(clus.cases, - new_Case_DELAY_PEER_PORT_TX_RX_QUORUM(clus, true)) - case "DELAY_PEER_PORT_TX_RX_ALL": - clus.cases = append(clus.cases, - new_Case_DELAY_PEER_PORT_TX_RX_ALL(clus, false)) - case "RANDOM_DELAY_PEER_PORT_TX_RX_ALL": - clus.cases = append(clus.cases, - new_Case_DELAY_PEER_PORT_TX_RX_ALL(clus, true)) - - case "NO_FAIL_WITH_STRESS": - clus.cases = append(clus.cases, - new_Case_NO_FAIL_WITH_STRESS(clus)) - case "NO_FAIL_WITH_NO_STRESS_FOR_LIVENESS": - clus.cases = append(clus.cases, - new_Case_NO_FAIL_WITH_NO_STRESS_FOR_LIVENESS(clus)) - - case "EXTERNAL": - clus.cases = append(clus.cases, - new_Case_EXTERNAL(clus.Tester.ExternalExecPath)) - case "FAILPOINTS": - fpFailures, fperr := failpointFailures(clus) - if len(fpFailures) == 0 { - clus.lg.Info("no failpoints found!", zap.Error(fperr)) - } - clus.cases = append(clus.cases, - fpFailures...) - } - } -} - -func (clus *Cluster) listCases() (css []string) { - css = make([]string, len(clus.cases)) - for i := range clus.cases { - css[i] = clus.cases[i].Desc() - } - return css -} - -// UpdateDelayLatencyMs updates delay latency with random value -// within election timeout. -func (clus *Cluster) UpdateDelayLatencyMs() { - rand.Seed(time.Now().UnixNano()) - clus.Tester.UpdatedDelayLatencyMs = uint32(rand.Int63n(clus.Members[0].Etcd.ElectionTimeoutMs)) - - minLatRv := clus.Tester.DelayLatencyMsRv + clus.Tester.DelayLatencyMsRv/5 - if clus.Tester.UpdatedDelayLatencyMs <= minLatRv { - clus.Tester.UpdatedDelayLatencyMs += minLatRv - } -} - -func (clus *Cluster) setStresserChecker() { - css := &compositeStresser{} - lss := []*leaseStresser{} - rss := []*runnerStresser{} - for _, m := range clus.Members { - sss := newStresser(clus, m) - css.stressers = append(css.stressers, &compositeStresser{sss}) - for _, s := range sss { - if v, ok := s.(*leaseStresser); ok { - lss = append(lss, v) - clus.lg.Info("added lease stresser", zap.String("endpoint", m.EtcdClientEndpoint)) - } - if v, ok := s.(*runnerStresser); ok { - rss = append(rss, v) - clus.lg.Info("added lease stresser", zap.String("endpoint", m.EtcdClientEndpoint)) - } - } - } - clus.stresser = css - - for _, cs := range clus.Tester.Checkers { - switch cs { - case "KV_HASH": - clus.checkers = append(clus.checkers, newKVHashChecker(clus)) - - case "LEASE_EXPIRE": - for _, ls := range lss { - clus.checkers = append(clus.checkers, newLeaseExpireChecker(ls)) - } - - case "RUNNER": - for _, rs := range rss { - clus.checkers = append(clus.checkers, newRunnerChecker(rs.etcdClientEndpoint, rs.errc)) - } - - case "NO_CHECK": - clus.checkers = append(clus.checkers, newNoChecker()) - } - } - clus.lg.Info("updated stressers") -} - -func (clus *Cluster) runCheckers(exceptions ...rpcpb.Checker) (err error) { - defer func() { - if err != nil { - return - } - if err = clus.updateRevision(); err != nil { - clus.lg.Warn( - "updateRevision failed", - zap.Error(err), - ) - return - } - }() - - exs := make(map[rpcpb.Checker]struct{}) - for _, e := range exceptions { - exs[e] = struct{}{} - } - for _, chk := range clus.checkers { - clus.lg.Warn( - "consistency check START", - zap.String("checker", chk.Type().String()), - zap.Strings("client-endpoints", chk.EtcdClientEndpoints()), - ) - err = chk.Check() - clus.lg.Warn( - "consistency check END", - zap.String("checker", chk.Type().String()), - zap.Strings("client-endpoints", chk.EtcdClientEndpoints()), - zap.Error(err), - ) - if err != nil { - _, ok := exs[chk.Type()] - if !ok { - return err - } - clus.lg.Warn( - "consistency check SKIP FAIL", - zap.String("checker", chk.Type().String()), - zap.Strings("client-endpoints", chk.EtcdClientEndpoints()), - zap.Error(err), - ) - } - } - return nil -} - -// Send_INITIAL_START_ETCD bootstraps etcd cluster the very first time. -// After this, just continue to call kill/restart. -func (clus *Cluster) Send_INITIAL_START_ETCD() error { - // this is the only time that creates request from scratch - return clus.broadcast(rpcpb.Operation_INITIAL_START_ETCD) -} - -// send_SIGQUIT_ETCD_AND_ARCHIVE_DATA sends "send_SIGQUIT_ETCD_AND_ARCHIVE_DATA" operation. -func (clus *Cluster) send_SIGQUIT_ETCD_AND_ARCHIVE_DATA() error { - return clus.broadcast(rpcpb.Operation_SIGQUIT_ETCD_AND_ARCHIVE_DATA) -} - -// send_RESTART_ETCD sends restart operation. -func (clus *Cluster) send_RESTART_ETCD() error { - return clus.broadcast(rpcpb.Operation_RESTART_ETCD) -} - -func (clus *Cluster) broadcast(op rpcpb.Operation) error { - var wg sync.WaitGroup - wg.Add(len(clus.agentStreams)) - - errc := make(chan error, len(clus.agentStreams)) - for i := range clus.agentStreams { - go func(idx int, o rpcpb.Operation) { - defer wg.Done() - errc <- clus.sendOp(idx, o) - }(i, op) - } - wg.Wait() - close(errc) - - errs := []string{} - for err := range errc { - if err == nil { - continue - } - - if err != nil { - destroyed := false - if op == rpcpb.Operation_SIGQUIT_ETCD_AND_REMOVE_DATA_AND_STOP_AGENT { - if err == io.EOF { - destroyed = true - } - if strings.Contains(err.Error(), - "rpc error: code = Unavailable desc = transport is closing") { - // agent server has already closed; - // so this error is expected - destroyed = true - } - if strings.Contains(err.Error(), - "desc = os: process already finished") { - destroyed = true - } - } - if !destroyed { - errs = append(errs, err.Error()) - } - } - } - - if len(errs) == 0 { - return nil - } - return errors.New(strings.Join(errs, ", ")) -} - -func (clus *Cluster) sendOp(idx int, op rpcpb.Operation) error { - _, err := clus.sendOpWithResp(idx, op) - return err -} - -func (clus *Cluster) sendOpWithResp(idx int, op rpcpb.Operation) (*rpcpb.Response, error) { - // maintain the initial member object - // throughout the test time - clus.agentRequests[idx] = &rpcpb.Request{ - Operation: op, - Member: clus.Members[idx], - Tester: clus.Tester, - } - - err := clus.agentStreams[idx].Send(clus.agentRequests[idx]) - clus.lg.Info( - "sent request", - zap.String("operation", op.String()), - zap.String("to", clus.Members[idx].EtcdClientEndpoint), - zap.Error(err), - ) - if err != nil { - return nil, err - } - - resp, err := clus.agentStreams[idx].Recv() - if resp != nil { - clus.lg.Info( - "received response", - zap.String("operation", op.String()), - zap.String("from", clus.Members[idx].EtcdClientEndpoint), - zap.Bool("success", resp.Success), - zap.String("status", resp.Status), - zap.Error(err), - ) - } else { - clus.lg.Info( - "received empty response", - zap.String("operation", op.String()), - zap.String("from", clus.Members[idx].EtcdClientEndpoint), - zap.Error(err), - ) - } - if err != nil { - return nil, err - } - - if !resp.Success { - return nil, errors.New(resp.Status) - } - - m, secure := clus.Members[idx], false - for _, cu := range m.Etcd.AdvertiseClientURLs { - u, err := url.Parse(cu) - if err != nil { - return nil, err - } - if u.Scheme == "https" { // TODO: handle unix - secure = true - } - } - - // store TLS assets from agents/servers onto disk - if secure && (op == rpcpb.Operation_INITIAL_START_ETCD || op == rpcpb.Operation_RESTART_ETCD) { - dirClient := filepath.Join( - clus.Tester.DataDir, - clus.Members[idx].Etcd.Name, - "fixtures", - "client", - ) - if err = fileutil.TouchDirAll(dirClient); err != nil { - return nil, err - } - - clientCertData := []byte(resp.Member.ClientCertData) - if len(clientCertData) == 0 { - return nil, fmt.Errorf("got empty client cert from %q", m.EtcdClientEndpoint) - } - clientCertPath := filepath.Join(dirClient, "cert.pem") - if err = ioutil.WriteFile(clientCertPath, clientCertData, 0644); err != nil { // overwrite if exists - return nil, err - } - resp.Member.ClientCertPath = clientCertPath - clus.lg.Info( - "saved client cert file", - zap.String("path", clientCertPath), - ) - - clientKeyData := []byte(resp.Member.ClientKeyData) - if len(clientKeyData) == 0 { - return nil, fmt.Errorf("got empty client key from %q", m.EtcdClientEndpoint) - } - clientKeyPath := filepath.Join(dirClient, "key.pem") - if err = ioutil.WriteFile(clientKeyPath, clientKeyData, 0644); err != nil { // overwrite if exists - return nil, err - } - resp.Member.ClientKeyPath = clientKeyPath - clus.lg.Info( - "saved client key file", - zap.String("path", clientKeyPath), - ) - - clientTrustedCAData := []byte(resp.Member.ClientTrustedCAData) - if len(clientTrustedCAData) != 0 { - // TODO: disable this when auto TLS is deprecated - clientTrustedCAPath := filepath.Join(dirClient, "ca.pem") - if err = ioutil.WriteFile(clientTrustedCAPath, clientTrustedCAData, 0644); err != nil { // overwrite if exists - return nil, err - } - resp.Member.ClientTrustedCAPath = clientTrustedCAPath - clus.lg.Info( - "saved client trusted CA file", - zap.String("path", clientTrustedCAPath), - ) - } - - // no need to store peer certs for tester clients - - clus.Members[idx] = resp.Member - } - - return resp, nil -} - -// Send_SIGQUIT_ETCD_AND_REMOVE_DATA_AND_STOP_AGENT terminates all tester connections to agents and etcd servers. -func (clus *Cluster) Send_SIGQUIT_ETCD_AND_REMOVE_DATA_AND_STOP_AGENT() { - err := clus.broadcast(rpcpb.Operation_SIGQUIT_ETCD_AND_REMOVE_DATA_AND_STOP_AGENT) - if err != nil { - clus.lg.Warn("destroying etcd/agents FAIL", zap.Error(err)) - } else { - clus.lg.Info("destroying etcd/agents PASS") - } - - for i, conn := range clus.agentConns { - err := conn.Close() - clus.lg.Info("closed connection to agent", zap.String("agent-address", clus.Members[i].AgentAddr), zap.Error(err)) - } - - if clus.testerHTTPServer != nil { - ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) - err := clus.testerHTTPServer.Shutdown(ctx) - cancel() - clus.lg.Info("closed tester HTTP server", zap.String("tester-address", clus.Tester.Addr), zap.Error(err)) - } -} - -// WaitHealth ensures all members are healthy -// by writing a test key to etcd cluster. -func (clus *Cluster) WaitHealth() error { - var err error - // wait 60s to check cluster health. - // TODO: set it to a reasonable value. It is set that high because - // follower may use long time to catch up the leader when reboot under - // reasonable workload (https://github.com/coreos/etcd/issues/2698) - for i := 0; i < 60; i++ { - for _, m := range clus.Members { - if err = m.WriteHealthKey(); err != nil { - clus.lg.Warn( - "health check FAIL", - zap.Int("retries", i), - zap.String("endpoint", m.EtcdClientEndpoint), - zap.Error(err), - ) - break - } - clus.lg.Info( - "health check PASS", - zap.Int("retries", i), - zap.String("endpoint", m.EtcdClientEndpoint), - ) - } - if err == nil { - clus.lg.Info("health check ALL PASS") - return nil - } - time.Sleep(time.Second) - } - return err -} - -// GetLeader returns the index of leader and error if any. -func (clus *Cluster) GetLeader() (int, error) { - for i, m := range clus.Members { - isLeader, err := m.IsLeader() - if isLeader || err != nil { - return i, err - } - } - return 0, fmt.Errorf("no leader found") -} - -// maxRev returns the maximum revision found on the cluster. -func (clus *Cluster) maxRev() (rev int64, err error) { - ctx, cancel := context.WithTimeout(context.TODO(), time.Second) - defer cancel() - revc, errc := make(chan int64, len(clus.Members)), make(chan error, len(clus.Members)) - for i := range clus.Members { - go func(m *rpcpb.Member) { - mrev, merr := m.Rev(ctx) - revc <- mrev - errc <- merr - }(clus.Members[i]) - } - for i := 0; i < len(clus.Members); i++ { - if merr := <-errc; merr != nil { - err = merr - } - if mrev := <-revc; mrev > rev { - rev = mrev - } - } - return rev, err -} - -func (clus *Cluster) getRevisionHash() (map[string]int64, map[string]int64, error) { - revs := make(map[string]int64) - hashes := make(map[string]int64) - for _, m := range clus.Members { - rev, hash, err := m.RevHash() - if err != nil { - return nil, nil, err - } - revs[m.EtcdClientEndpoint] = rev - hashes[m.EtcdClientEndpoint] = hash - } - return revs, hashes, nil -} - -func (clus *Cluster) compactKV(rev int64, timeout time.Duration) (err error) { - if rev <= 0 { - return nil - } - - for i, m := range clus.Members { - clus.lg.Info( - "compact START", - zap.String("endpoint", m.EtcdClientEndpoint), - zap.Int64("compact-revision", rev), - zap.Duration("timeout", timeout), - ) - now := time.Now() - cerr := m.Compact(rev, timeout) - succeed := true - if cerr != nil { - if strings.Contains(cerr.Error(), "required revision has been compacted") && i > 0 { - clus.lg.Info( - "compact error is ignored", - zap.String("endpoint", m.EtcdClientEndpoint), - zap.Int64("compact-revision", rev), - zap.Error(cerr), - ) - } else { - clus.lg.Warn( - "compact FAIL", - zap.String("endpoint", m.EtcdClientEndpoint), - zap.Int64("compact-revision", rev), - zap.Error(cerr), - ) - err = cerr - succeed = false - } - } - - if succeed { - clus.lg.Info( - "compact PASS", - zap.String("endpoint", m.EtcdClientEndpoint), - zap.Int64("compact-revision", rev), - zap.Duration("timeout", timeout), - zap.Duration("took", time.Since(now)), - ) - } - } - return err -} - -func (clus *Cluster) checkCompact(rev int64) error { - if rev == 0 { - return nil - } - for _, m := range clus.Members { - if err := m.CheckCompact(rev); err != nil { - return err - } - } - return nil -} - -func (clus *Cluster) defrag() error { - for _, m := range clus.Members { - if err := m.Defrag(); err != nil { - clus.lg.Warn( - "defrag FAIL", - zap.String("endpoint", m.EtcdClientEndpoint), - zap.Error(err), - ) - return err - } - clus.lg.Info( - "defrag PASS", - zap.String("endpoint", m.EtcdClientEndpoint), - ) - } - clus.lg.Info( - "defrag ALL PASS", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.Int("case-total", len(clus.cases)), - ) - return nil -} - -// GetCaseDelayDuration computes failure delay duration. -func (clus *Cluster) GetCaseDelayDuration() time.Duration { - return time.Duration(clus.Tester.CaseDelayMs) * time.Millisecond -} - -// Report reports the number of modified keys. -func (clus *Cluster) Report() int64 { - return clus.stresser.ModifiedKeys() -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/cluster_read_config.go b/vendor/go.etcd.io/etcd/functional/tester/cluster_read_config.go deleted file mode 100644 index 223265e66c84..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/cluster_read_config.go +++ /dev/null @@ -1,358 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "errors" - "fmt" - "io/ioutil" - "net/url" - "path/filepath" - "strings" - - "github.com/coreos/etcd/functional/rpcpb" - - "go.uber.org/zap" - yaml "gopkg.in/yaml.v2" -) - -func read(lg *zap.Logger, fpath string) (*Cluster, error) { - bts, err := ioutil.ReadFile(fpath) - if err != nil { - return nil, err - } - lg.Info("opened configuration file", zap.String("path", fpath)) - - clus := &Cluster{lg: lg} - if err = yaml.Unmarshal(bts, clus); err != nil { - return nil, err - } - - if len(clus.Members) < 3 { - return nil, fmt.Errorf("len(clus.Members) expects at least 3, got %d", len(clus.Members)) - } - - for i, mem := range clus.Members { - if mem.BaseDir == "" { - return nil, fmt.Errorf("BaseDir cannot be empty (got %q)", mem.BaseDir) - } - if mem.EtcdLogPath == "" { - return nil, fmt.Errorf("EtcdLogPath cannot be empty (got %q)", mem.EtcdLogPath) - } - - if mem.Etcd.Name == "" { - return nil, fmt.Errorf("'--name' cannot be empty (got %+v)", mem) - } - if mem.Etcd.DataDir == "" { - return nil, fmt.Errorf("'--data-dir' cannot be empty (got %+v)", mem) - } - if mem.Etcd.SnapshotCount == 0 { - return nil, fmt.Errorf("'--snapshot-count' cannot be 0 (got %+v)", mem.Etcd.SnapshotCount) - } - if mem.Etcd.DataDir == "" { - return nil, fmt.Errorf("'--data-dir' cannot be empty (got %q)", mem.Etcd.DataDir) - } - if mem.Etcd.WALDir == "" { - clus.Members[i].Etcd.WALDir = filepath.Join(mem.Etcd.DataDir, "member", "wal") - } - - switch mem.Etcd.InitialClusterState { - case "new": - case "existing": - default: - return nil, fmt.Errorf("'--initial-cluster-state' got %q", mem.Etcd.InitialClusterState) - } - - if mem.Etcd.HeartbeatIntervalMs == 0 { - return nil, fmt.Errorf("'--heartbeat-interval' cannot be 0 (got %+v)", mem.Etcd) - } - if mem.Etcd.ElectionTimeoutMs == 0 { - return nil, fmt.Errorf("'--election-timeout' cannot be 0 (got %+v)", mem.Etcd) - } - if int64(clus.Tester.DelayLatencyMs) <= mem.Etcd.ElectionTimeoutMs { - return nil, fmt.Errorf("delay latency %d ms must be greater than election timeout %d ms", clus.Tester.DelayLatencyMs, mem.Etcd.ElectionTimeoutMs) - } - - port := "" - listenClientPorts := make([]string, len(clus.Members)) - for i, u := range mem.Etcd.ListenClientURLs { - if !isValidURL(u) { - return nil, fmt.Errorf("'--listen-client-urls' has valid URL %q", u) - } - listenClientPorts[i], err = getPort(u) - if err != nil { - return nil, fmt.Errorf("'--listen-client-urls' has no port %q", u) - } - } - for i, u := range mem.Etcd.AdvertiseClientURLs { - if !isValidURL(u) { - return nil, fmt.Errorf("'--advertise-client-urls' has valid URL %q", u) - } - port, err = getPort(u) - if err != nil { - return nil, fmt.Errorf("'--advertise-client-urls' has no port %q", u) - } - if mem.EtcdClientProxy && listenClientPorts[i] == port { - return nil, fmt.Errorf("clus.Members[%d] requires client port proxy, but advertise port %q conflicts with listener port %q", i, port, listenClientPorts[i]) - } - } - - listenPeerPorts := make([]string, len(clus.Members)) - for i, u := range mem.Etcd.ListenPeerURLs { - if !isValidURL(u) { - return nil, fmt.Errorf("'--listen-peer-urls' has valid URL %q", u) - } - listenPeerPorts[i], err = getPort(u) - if err != nil { - return nil, fmt.Errorf("'--listen-peer-urls' has no port %q", u) - } - } - for j, u := range mem.Etcd.AdvertisePeerURLs { - if !isValidURL(u) { - return nil, fmt.Errorf("'--initial-advertise-peer-urls' has valid URL %q", u) - } - port, err = getPort(u) - if err != nil { - return nil, fmt.Errorf("'--initial-advertise-peer-urls' has no port %q", u) - } - if mem.EtcdPeerProxy && listenPeerPorts[j] == port { - return nil, fmt.Errorf("clus.Members[%d] requires peer port proxy, but advertise port %q conflicts with listener port %q", i, port, listenPeerPorts[j]) - } - } - - if !strings.HasPrefix(mem.EtcdLogPath, mem.BaseDir) { - return nil, fmt.Errorf("EtcdLogPath must be prefixed with BaseDir (got %q)", mem.EtcdLogPath) - } - if !strings.HasPrefix(mem.Etcd.DataDir, mem.BaseDir) { - return nil, fmt.Errorf("Etcd.DataDir must be prefixed with BaseDir (got %q)", mem.Etcd.DataDir) - } - - // TODO: support separate WALDir that can be handled via failure-archive - if !strings.HasPrefix(mem.Etcd.WALDir, mem.BaseDir) { - return nil, fmt.Errorf("Etcd.WALDir must be prefixed with BaseDir (got %q)", mem.Etcd.WALDir) - } - - // TODO: only support generated certs with TLS generator - // deprecate auto TLS - if mem.Etcd.PeerAutoTLS && mem.Etcd.PeerCertFile != "" { - return nil, fmt.Errorf("Etcd.PeerAutoTLS 'true', but Etcd.PeerCertFile is %q", mem.Etcd.PeerCertFile) - } - if mem.Etcd.PeerAutoTLS && mem.Etcd.PeerKeyFile != "" { - return nil, fmt.Errorf("Etcd.PeerAutoTLS 'true', but Etcd.PeerKeyFile is %q", mem.Etcd.PeerKeyFile) - } - if mem.Etcd.PeerAutoTLS && mem.Etcd.PeerTrustedCAFile != "" { - return nil, fmt.Errorf("Etcd.PeerAutoTLS 'true', but Etcd.PeerTrustedCAFile is %q", mem.Etcd.PeerTrustedCAFile) - } - if mem.Etcd.ClientAutoTLS && mem.Etcd.ClientCertFile != "" { - return nil, fmt.Errorf("Etcd.ClientAutoTLS 'true', but Etcd.ClientCertFile is %q", mem.Etcd.ClientCertFile) - } - if mem.Etcd.ClientAutoTLS && mem.Etcd.ClientKeyFile != "" { - return nil, fmt.Errorf("Etcd.ClientAutoTLS 'true', but Etcd.ClientKeyFile is %q", mem.Etcd.ClientKeyFile) - } - if mem.Etcd.ClientAutoTLS && mem.Etcd.ClientTrustedCAFile != "" { - return nil, fmt.Errorf("Etcd.ClientAutoTLS 'true', but Etcd.ClientTrustedCAFile is %q", mem.Etcd.ClientTrustedCAFile) - } - - if mem.Etcd.PeerClientCertAuth && mem.Etcd.PeerCertFile == "" { - return nil, fmt.Errorf("Etcd.PeerClientCertAuth 'true', but Etcd.PeerCertFile is %q", mem.Etcd.PeerCertFile) - } - if mem.Etcd.PeerClientCertAuth && mem.Etcd.PeerKeyFile == "" { - return nil, fmt.Errorf("Etcd.PeerClientCertAuth 'true', but Etcd.PeerKeyFile is %q", mem.Etcd.PeerCertFile) - } - // only support self-signed certs - if mem.Etcd.PeerClientCertAuth && mem.Etcd.PeerTrustedCAFile == "" { - return nil, fmt.Errorf("Etcd.PeerClientCertAuth 'true', but Etcd.PeerTrustedCAFile is %q", mem.Etcd.PeerCertFile) - } - if !mem.Etcd.PeerClientCertAuth && mem.Etcd.PeerCertFile != "" { - return nil, fmt.Errorf("Etcd.PeerClientCertAuth 'false', but Etcd.PeerCertFile is %q", mem.Etcd.PeerCertFile) - } - if !mem.Etcd.PeerClientCertAuth && mem.Etcd.PeerKeyFile != "" { - return nil, fmt.Errorf("Etcd.PeerClientCertAuth 'false', but Etcd.PeerKeyFile is %q", mem.Etcd.PeerCertFile) - } - if !mem.Etcd.PeerClientCertAuth && mem.Etcd.PeerTrustedCAFile != "" { - return nil, fmt.Errorf("Etcd.PeerClientCertAuth 'false', but Etcd.PeerTrustedCAFile is %q", mem.Etcd.PeerTrustedCAFile) - } - if mem.Etcd.PeerClientCertAuth && mem.Etcd.PeerAutoTLS { - return nil, fmt.Errorf("Etcd.PeerClientCertAuth and Etcd.PeerAutoTLS cannot be both 'true'") - } - if (mem.Etcd.PeerCertFile == "") != (mem.Etcd.PeerKeyFile == "") { - return nil, fmt.Errorf("Both Etcd.PeerCertFile %q and Etcd.PeerKeyFile %q must be either empty or non-empty", mem.Etcd.PeerCertFile, mem.Etcd.PeerKeyFile) - } - if mem.Etcd.ClientCertAuth && mem.Etcd.ClientAutoTLS { - return nil, fmt.Errorf("Etcd.ClientCertAuth and Etcd.ClientAutoTLS cannot be both 'true'") - } - if mem.Etcd.ClientCertAuth && mem.Etcd.ClientCertFile == "" { - return nil, fmt.Errorf("Etcd.ClientCertAuth 'true', but Etcd.ClientCertFile is %q", mem.Etcd.PeerCertFile) - } - if mem.Etcd.ClientCertAuth && mem.Etcd.ClientKeyFile == "" { - return nil, fmt.Errorf("Etcd.ClientCertAuth 'true', but Etcd.ClientKeyFile is %q", mem.Etcd.PeerCertFile) - } - if mem.Etcd.ClientCertAuth && mem.Etcd.ClientTrustedCAFile == "" { - return nil, fmt.Errorf("Etcd.ClientCertAuth 'true', but Etcd.ClientTrustedCAFile is %q", mem.Etcd.ClientTrustedCAFile) - } - if !mem.Etcd.ClientCertAuth && mem.Etcd.ClientCertFile != "" { - return nil, fmt.Errorf("Etcd.ClientCertAuth 'false', but Etcd.ClientCertFile is %q", mem.Etcd.PeerCertFile) - } - if !mem.Etcd.ClientCertAuth && mem.Etcd.ClientKeyFile != "" { - return nil, fmt.Errorf("Etcd.ClientCertAuth 'false', but Etcd.ClientKeyFile is %q", mem.Etcd.PeerCertFile) - } - if !mem.Etcd.ClientCertAuth && mem.Etcd.ClientTrustedCAFile != "" { - return nil, fmt.Errorf("Etcd.ClientCertAuth 'false', but Etcd.ClientTrustedCAFile is %q", mem.Etcd.PeerCertFile) - } - if (mem.Etcd.ClientCertFile == "") != (mem.Etcd.ClientKeyFile == "") { - return nil, fmt.Errorf("Both Etcd.ClientCertFile %q and Etcd.ClientKeyFile %q must be either empty or non-empty", mem.Etcd.ClientCertFile, mem.Etcd.ClientKeyFile) - } - - peerTLS := mem.Etcd.PeerAutoTLS || - (mem.Etcd.PeerClientCertAuth && mem.Etcd.PeerCertFile != "" && mem.Etcd.PeerKeyFile != "" && mem.Etcd.PeerTrustedCAFile != "") - if peerTLS { - for _, cu := range mem.Etcd.ListenPeerURLs { - var u *url.URL - u, err = url.Parse(cu) - if err != nil { - return nil, err - } - if u.Scheme != "https" { // TODO: support unix - return nil, fmt.Errorf("peer TLS is enabled with wrong scheme %q", cu) - } - } - for _, cu := range mem.Etcd.AdvertisePeerURLs { - var u *url.URL - u, err = url.Parse(cu) - if err != nil { - return nil, err - } - if u.Scheme != "https" { // TODO: support unix - return nil, fmt.Errorf("peer TLS is enabled with wrong scheme %q", cu) - } - } - clus.Members[i].PeerCertPath = mem.Etcd.PeerCertFile - if mem.Etcd.PeerCertFile != "" { - var data []byte - data, err = ioutil.ReadFile(mem.Etcd.PeerCertFile) - if err != nil { - return nil, fmt.Errorf("failed to read %q (%v)", mem.Etcd.PeerCertFile, err) - } - clus.Members[i].PeerCertData = string(data) - } - clus.Members[i].PeerKeyPath = mem.Etcd.PeerKeyFile - if mem.Etcd.PeerKeyFile != "" { - var data []byte - data, err = ioutil.ReadFile(mem.Etcd.PeerKeyFile) - if err != nil { - return nil, fmt.Errorf("failed to read %q (%v)", mem.Etcd.PeerKeyFile, err) - } - clus.Members[i].PeerCertData = string(data) - } - clus.Members[i].PeerTrustedCAPath = mem.Etcd.PeerTrustedCAFile - if mem.Etcd.PeerTrustedCAFile != "" { - var data []byte - data, err = ioutil.ReadFile(mem.Etcd.PeerTrustedCAFile) - if err != nil { - return nil, fmt.Errorf("failed to read %q (%v)", mem.Etcd.PeerTrustedCAFile, err) - } - clus.Members[i].PeerCertData = string(data) - } - } - - clientTLS := mem.Etcd.ClientAutoTLS || - (mem.Etcd.ClientCertAuth && mem.Etcd.ClientCertFile != "" && mem.Etcd.ClientKeyFile != "" && mem.Etcd.ClientTrustedCAFile != "") - if clientTLS { - for _, cu := range mem.Etcd.ListenClientURLs { - var u *url.URL - u, err = url.Parse(cu) - if err != nil { - return nil, err - } - if u.Scheme != "https" { // TODO: support unix - return nil, fmt.Errorf("client TLS is enabled with wrong scheme %q", cu) - } - } - for _, cu := range mem.Etcd.AdvertiseClientURLs { - var u *url.URL - u, err = url.Parse(cu) - if err != nil { - return nil, err - } - if u.Scheme != "https" { // TODO: support unix - return nil, fmt.Errorf("client TLS is enabled with wrong scheme %q", cu) - } - } - clus.Members[i].ClientCertPath = mem.Etcd.ClientCertFile - if mem.Etcd.ClientCertFile != "" { - var data []byte - data, err = ioutil.ReadFile(mem.Etcd.ClientCertFile) - if err != nil { - return nil, fmt.Errorf("failed to read %q (%v)", mem.Etcd.ClientCertFile, err) - } - clus.Members[i].ClientCertData = string(data) - } - clus.Members[i].ClientKeyPath = mem.Etcd.ClientKeyFile - if mem.Etcd.ClientKeyFile != "" { - var data []byte - data, err = ioutil.ReadFile(mem.Etcd.ClientKeyFile) - if err != nil { - return nil, fmt.Errorf("failed to read %q (%v)", mem.Etcd.ClientKeyFile, err) - } - clus.Members[i].ClientCertData = string(data) - } - clus.Members[i].ClientTrustedCAPath = mem.Etcd.ClientTrustedCAFile - if mem.Etcd.ClientTrustedCAFile != "" { - var data []byte - data, err = ioutil.ReadFile(mem.Etcd.ClientTrustedCAFile) - if err != nil { - return nil, fmt.Errorf("failed to read %q (%v)", mem.Etcd.ClientTrustedCAFile, err) - } - clus.Members[i].ClientCertData = string(data) - } - } - } - - if len(clus.Tester.Cases) == 0 { - return nil, errors.New("Cases not found") - } - if clus.Tester.DelayLatencyMs <= clus.Tester.DelayLatencyMsRv*5 { - return nil, fmt.Errorf("delay latency %d ms must be greater than 5x of delay latency random variable %d ms", clus.Tester.DelayLatencyMs, clus.Tester.DelayLatencyMsRv) - } - if clus.Tester.UpdatedDelayLatencyMs == 0 { - clus.Tester.UpdatedDelayLatencyMs = clus.Tester.DelayLatencyMs - } - - for _, v := range clus.Tester.Cases { - if _, ok := rpcpb.Case_value[v]; !ok { - return nil, fmt.Errorf("%q is not defined in 'rpcpb.Case_value'", v) - } - } - - for _, v := range clus.Tester.Stressers { - if _, ok := rpcpb.Stresser_value[v]; !ok { - return nil, fmt.Errorf("Stresser is unknown; got %q", v) - } - } - for _, v := range clus.Tester.Checkers { - if _, ok := rpcpb.Checker_value[v]; !ok { - return nil, fmt.Errorf("Checker is unknown; got %q", v) - } - } - - if clus.Tester.StressKeySuffixRangeTxn > 100 { - return nil, fmt.Errorf("StressKeySuffixRangeTxn maximum value is 100, got %v", clus.Tester.StressKeySuffixRangeTxn) - } - if clus.Tester.StressKeyTxnOps > 64 { - return nil, fmt.Errorf("StressKeyTxnOps maximum value is 64, got %v", clus.Tester.StressKeyTxnOps) - } - - return clus, err -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/cluster_run.go b/vendor/go.etcd.io/etcd/functional/tester/cluster_run.go deleted file mode 100644 index 6dd0021062da..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/cluster_run.go +++ /dev/null @@ -1,373 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "fmt" - "os" - "time" - - "github.com/coreos/etcd/functional/rpcpb" - "github.com/coreos/etcd/pkg/fileutil" - - "go.uber.org/zap" -) - -// compactQPS is rough number of compact requests per second. -// Previous tests showed etcd can compact about 60,000 entries per second. -const compactQPS = 50000 - -// Run starts tester. -func (clus *Cluster) Run() { - defer printReport() - - if err := fileutil.TouchDirAll(clus.Tester.DataDir); err != nil { - clus.lg.Panic( - "failed to create test data directory", - zap.String("dir", clus.Tester.DataDir), - zap.Error(err), - ) - } - - var preModifiedKey int64 - for round := 0; round < int(clus.Tester.RoundLimit) || clus.Tester.RoundLimit == -1; round++ { - roundTotalCounter.Inc() - clus.rd = round - - if err := clus.doRound(); err != nil { - clus.lg.Warn( - "round FAIL", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.Int("case-total", len(clus.cases)), - zap.Error(err), - ) - if clus.cleanup() != nil { - return - } - // reset preModifiedKey after clean up - preModifiedKey = 0 - continue - } - - // -1 so that logPrefix doesn't print out 'case' - clus.cs = -1 - - revToCompact := max(0, clus.currentRevision-10000) - currentModifiedKey := clus.stresser.ModifiedKeys() - modifiedKey := currentModifiedKey - preModifiedKey - preModifiedKey = currentModifiedKey - timeout := 10 * time.Second - timeout += time.Duration(modifiedKey/compactQPS) * time.Second - clus.lg.Info( - "compact START", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.Int("case-total", len(clus.cases)), - zap.Duration("timeout", timeout), - ) - if err := clus.compact(revToCompact, timeout); err != nil { - clus.lg.Warn( - "compact FAIL", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.Int("case-total", len(clus.cases)), - zap.Error(err), - ) - if err = clus.cleanup(); err != nil { - clus.lg.Warn( - "cleanup FAIL", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.Int("case-total", len(clus.cases)), - zap.Error(err), - ) - return - } - // reset preModifiedKey after clean up - preModifiedKey = 0 - } - if round > 0 && round%500 == 0 { // every 500 rounds - if err := clus.defrag(); err != nil { - clus.failed() - return - } - } - } - - clus.lg.Info( - "functional-tester PASS", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.Int("case-total", len(clus.cases)), - ) -} - -func (clus *Cluster) doRound() error { - if clus.Tester.CaseShuffle { - clus.shuffleCases() - } - - roundNow := time.Now() - clus.lg.Info( - "round START", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.Int("case-total", len(clus.cases)), - zap.Strings("cases", clus.listCases()), - ) - for i, fa := range clus.cases { - clus.cs = i - - caseTotal[fa.Desc()]++ - caseTotalCounter.WithLabelValues(fa.Desc()).Inc() - - caseNow := time.Now() - clus.lg.Info( - "case START", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.Int("case-total", len(clus.cases)), - zap.String("desc", fa.Desc()), - ) - - clus.lg.Info("wait health before injecting failures") - if err := clus.WaitHealth(); err != nil { - return fmt.Errorf("wait full health error: %v", err) - } - - stressStarted := false - fcase := fa.TestCase() - if fcase != rpcpb.Case_NO_FAIL_WITH_NO_STRESS_FOR_LIVENESS { - clus.lg.Info( - "stress START", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.Int("case-total", len(clus.cases)), - zap.String("desc", fa.Desc()), - ) - if err := clus.stresser.Stress(); err != nil { - return fmt.Errorf("start stresser error: %v", err) - } - stressStarted = true - } - - clus.lg.Info( - "inject START", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.Int("case-total", len(clus.cases)), - zap.String("desc", fa.Desc()), - ) - if err := fa.Inject(clus); err != nil { - return fmt.Errorf("injection error: %v", err) - } - - // if run local, recovering server may conflict - // with stressing client ports - // TODO: use unix for local tests - clus.lg.Info( - "recover START", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.Int("case-total", len(clus.cases)), - zap.String("desc", fa.Desc()), - ) - if err := fa.Recover(clus); err != nil { - return fmt.Errorf("recovery error: %v", err) - } - - if stressStarted { - clus.lg.Info( - "stress PAUSE", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.Int("case-total", len(clus.cases)), - zap.String("desc", fa.Desc()), - ) - ems := clus.stresser.Pause() - if fcase == rpcpb.Case_NO_FAIL_WITH_STRESS && len(ems) > 0 { - ess := make([]string, 0, len(ems)) - cnt := 0 - for k, v := range ems { - ess = append(ess, fmt.Sprintf("%s (count: %d)", k, v)) - cnt += v - } - clus.lg.Warn( - "expected no errors", - zap.String("desc", fa.Desc()), - zap.Strings("errors", ess), - ) - - // with network delay, some ongoing requests may fail - // only return error, if more than 10% of QPS requests fail - if cnt > int(clus.Tester.StressQPS)/10 { - return fmt.Errorf("expected no error in %q, got %q", fcase.String(), ess) - } - } - } - - clus.lg.Info( - "health check START", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.Int("case-total", len(clus.cases)), - zap.String("desc", fa.Desc()), - ) - if err := clus.WaitHealth(); err != nil { - return fmt.Errorf("wait full health error: %v", err) - } - - checkerFailExceptions := []rpcpb.Checker{} - switch fcase { - case rpcpb.Case_SIGQUIT_AND_REMOVE_QUORUM_AND_RESTORE_LEADER_SNAPSHOT_FROM_SCRATCH: - // TODO: restore from snapshot - checkerFailExceptions = append(checkerFailExceptions, rpcpb.Checker_LEASE_EXPIRE) - } - - clus.lg.Info( - "consistency check START", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.Int("case-total", len(clus.cases)), - zap.String("desc", fa.Desc()), - ) - if err := clus.runCheckers(checkerFailExceptions...); err != nil { - return fmt.Errorf("consistency check error (%v)", err) - } - clus.lg.Info( - "consistency check PASS", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.Int("case-total", len(clus.cases)), - zap.String("desc", fa.Desc()), - zap.Duration("took", time.Since(caseNow)), - ) - } - - clus.lg.Info( - "round ALL PASS", - zap.Int("round", clus.rd), - zap.Strings("cases", clus.listCases()), - zap.Int("case-total", len(clus.cases)), - zap.Duration("took", time.Since(roundNow)), - ) - return nil -} - -func (clus *Cluster) updateRevision() error { - revs, _, err := clus.getRevisionHash() - for _, rev := range revs { - clus.currentRevision = rev - break // just need get one of the current revisions - } - - clus.lg.Info( - "updated current revision", - zap.Int64("current-revision", clus.currentRevision), - ) - return err -} - -func (clus *Cluster) compact(rev int64, timeout time.Duration) (err error) { - if err = clus.compactKV(rev, timeout); err != nil { - clus.lg.Warn( - "compact FAIL", - zap.Int64("current-revision", clus.currentRevision), - zap.Int64("compact-revision", rev), - zap.Error(err), - ) - return err - } - clus.lg.Info( - "compact DONE", - zap.Int64("current-revision", clus.currentRevision), - zap.Int64("compact-revision", rev), - ) - - if err = clus.checkCompact(rev); err != nil { - clus.lg.Warn( - "check compact FAIL", - zap.Int64("current-revision", clus.currentRevision), - zap.Int64("compact-revision", rev), - zap.Error(err), - ) - return err - } - clus.lg.Info( - "check compact DONE", - zap.Int64("current-revision", clus.currentRevision), - zap.Int64("compact-revision", rev), - ) - - return nil -} - -func (clus *Cluster) failed() { - clus.lg.Info( - "functional-tester FAIL", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.Int("case-total", len(clus.cases)), - ) - clus.Send_SIGQUIT_ETCD_AND_REMOVE_DATA_AND_STOP_AGENT() - - os.Exit(2) -} - -func (clus *Cluster) cleanup() error { - if clus.Tester.ExitOnCaseFail { - defer clus.failed() - } - - roundFailedTotalCounter.Inc() - desc := "compact/defrag" - if clus.cs != -1 { - desc = clus.cases[clus.cs].Desc() - } - caseFailedTotalCounter.WithLabelValues(desc).Inc() - - clus.lg.Info( - "closing stressers before archiving failure data", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.Int("case-total", len(clus.cases)), - ) - clus.stresser.Close() - - if err := clus.send_SIGQUIT_ETCD_AND_ARCHIVE_DATA(); err != nil { - clus.lg.Warn( - "cleanup FAIL", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.Int("case-total", len(clus.cases)), - zap.Error(err), - ) - return err - } - if err := clus.send_RESTART_ETCD(); err != nil { - clus.lg.Warn( - "restart FAIL", - zap.Int("round", clus.rd), - zap.Int("case", clus.cs), - zap.Int("case-total", len(clus.cases)), - zap.Error(err), - ) - return err - } - - clus.setStresserChecker() - return nil -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/cluster_shuffle.go b/vendor/go.etcd.io/etcd/functional/tester/cluster_shuffle.go deleted file mode 100644 index 16c79b2f6e23..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/cluster_shuffle.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "math/rand" - "time" - - "go.uber.org/zap" -) - -func (clus *Cluster) shuffleCases() { - rand.Seed(time.Now().UnixNano()) - offset := rand.Intn(1000) - n := len(clus.cases) - cp := coprime(n) - - css := make([]Case, n) - for i := 0; i < n; i++ { - css[i] = clus.cases[(cp*i+offset)%n] - } - clus.cases = css - clus.lg.Info("shuffled test failure cases", zap.Int("total", n)) -} - -/* -x and y of GCD 1 are coprime to each other - -x1 = ( coprime of n * idx1 + offset ) % n -x2 = ( coprime of n * idx2 + offset ) % n -(x2 - x1) = coprime of n * (idx2 - idx1) % n - = (idx2 - idx1) = 1 - -Consecutive x's are guaranteed to be distinct -*/ -func coprime(n int) int { - coprime := 1 - for i := n / 2; i < n; i++ { - if gcd(i, n) == 1 { - coprime = i - break - } - } - return coprime -} - -func gcd(x, y int) int { - if y == 0 { - return x - } - return gcd(y, x%y) -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/doc.go b/vendor/go.etcd.io/etcd/functional/tester/doc.go deleted file mode 100644 index d1e23e941341..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package tester implements functional-tester tester server. -package tester diff --git a/vendor/go.etcd.io/etcd/functional/tester/metrics_report.go b/vendor/go.etcd.io/etcd/functional/tester/metrics_report.go deleted file mode 100644 index c82e58f5b644..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/metrics_report.go +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "fmt" - "sort" - - "github.com/prometheus/client_golang/prometheus" -) - -var ( - caseTotal = make(map[string]int) - - caseTotalCounter = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "funcational_tester", - Name: "case_total", - Help: "Total number of finished test cases", - }, - []string{"desc"}, - ) - - caseFailedTotalCounter = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "funcational_tester", - Name: "case_failed_total", - Help: "Total number of failed test cases", - }, - []string{"desc"}, - ) - - roundTotalCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "funcational_tester", - Name: "round_total", - Help: "Total number of finished test rounds.", - }) - - roundFailedTotalCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "funcational_tester", - Name: "round_failed_total", - Help: "Total number of failed test rounds.", - }) -) - -func init() { - prometheus.MustRegister(caseTotalCounter) - prometheus.MustRegister(caseFailedTotalCounter) - prometheus.MustRegister(roundTotalCounter) - prometheus.MustRegister(roundFailedTotalCounter) -} - -func printReport() { - rows := make([]string, 0, len(caseTotal)) - for k, v := range caseTotal { - rows = append(rows, fmt.Sprintf("%s: %d", k, v)) - } - sort.Strings(rows) - - println() - for _, row := range rows { - fmt.Println(row) - } - println() -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/stresser.go b/vendor/go.etcd.io/etcd/functional/tester/stresser.go deleted file mode 100644 index b74b84b158ec..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/stresser.go +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "fmt" - "time" - - "github.com/coreos/etcd/functional/rpcpb" - - "go.uber.org/zap" -) - -// Stresser defines stressing client operations. -type Stresser interface { - // Stress starts to stress the etcd cluster - Stress() error - // Pause stops the stresser from sending requests to etcd. Resume by calling Stress. - Pause() map[string]int - // Close releases all of the Stresser's resources. - Close() map[string]int - // ModifiedKeys reports the number of keys created and deleted by stresser - ModifiedKeys() int64 -} - -// newStresser creates stresser from a comma separated list of stresser types. -func newStresser(clus *Cluster, m *rpcpb.Member) (stressers []Stresser) { - stressers = make([]Stresser, len(clus.Tester.Stressers)) - for i, stype := range clus.Tester.Stressers { - clus.lg.Info( - "creating stresser", - zap.String("type", stype), - zap.String("endpoint", m.EtcdClientEndpoint), - ) - - switch stype { - case "KV": - // TODO: Too intensive stressing clients can panic etcd member with - // 'out of memory' error. Put rate limits in server side. - stressers[i] = &keyStresser{ - stype: rpcpb.Stresser_KV, - lg: clus.lg, - m: m, - keySize: int(clus.Tester.StressKeySize), - keyLargeSize: int(clus.Tester.StressKeySizeLarge), - keySuffixRange: int(clus.Tester.StressKeySuffixRange), - keyTxnSuffixRange: int(clus.Tester.StressKeySuffixRangeTxn), - keyTxnOps: int(clus.Tester.StressKeyTxnOps), - clientsN: int(clus.Tester.StressClients), - rateLimiter: clus.rateLimiter, - } - - case "LEASE": - stressers[i] = &leaseStresser{ - stype: rpcpb.Stresser_LEASE, - lg: clus.lg, - m: m, - numLeases: 10, // TODO: configurable - keysPerLease: 10, // TODO: configurable - rateLimiter: clus.rateLimiter, - } - - case "ELECTION_RUNNER": - reqRate := 100 - args := []string{ - "election", - fmt.Sprintf("%v", time.Now().UnixNano()), // election name as current nano time - "--dial-timeout=10s", - "--endpoints", m.EtcdClientEndpoint, - "--total-client-connections=10", - "--rounds=0", // runs forever - "--req-rate", fmt.Sprintf("%v", reqRate), - } - stressers[i] = newRunnerStresser( - rpcpb.Stresser_ELECTION_RUNNER, - m.EtcdClientEndpoint, - clus.lg, - clus.Tester.RunnerExecPath, - args, - clus.rateLimiter, - reqRate, - ) - - case "WATCH_RUNNER": - reqRate := 100 - args := []string{ - "watcher", - "--prefix", fmt.Sprintf("%v", time.Now().UnixNano()), // prefix all keys with nano time - "--total-keys=1", - "--total-prefixes=1", - "--watch-per-prefix=1", - "--endpoints", m.EtcdClientEndpoint, - "--rounds=0", // runs forever - "--req-rate", fmt.Sprintf("%v", reqRate), - } - stressers[i] = newRunnerStresser( - rpcpb.Stresser_WATCH_RUNNER, - m.EtcdClientEndpoint, - clus.lg, - clus.Tester.RunnerExecPath, - args, - clus.rateLimiter, - reqRate, - ) - - case "LOCK_RACER_RUNNER": - reqRate := 100 - args := []string{ - "lock-racer", - fmt.Sprintf("%v", time.Now().UnixNano()), // locker name as current nano time - "--endpoints", m.EtcdClientEndpoint, - "--total-client-connections=10", - "--rounds=0", // runs forever - "--req-rate", fmt.Sprintf("%v", reqRate), - } - stressers[i] = newRunnerStresser( - rpcpb.Stresser_LOCK_RACER_RUNNER, - m.EtcdClientEndpoint, - clus.lg, - clus.Tester.RunnerExecPath, - args, - clus.rateLimiter, - reqRate, - ) - - case "LEASE_RUNNER": - args := []string{ - "lease-renewer", - "--ttl=30", - "--endpoints", m.EtcdClientEndpoint, - } - stressers[i] = newRunnerStresser( - rpcpb.Stresser_LEASE_RUNNER, - m.EtcdClientEndpoint, - clus.lg, - clus.Tester.RunnerExecPath, - args, - clus.rateLimiter, - 0, - ) - } - } - return stressers -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/stresser_composite.go b/vendor/go.etcd.io/etcd/functional/tester/stresser_composite.go deleted file mode 100644 index 09dcb55ff63b..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/stresser_composite.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import "sync" - -// compositeStresser implements a Stresser that runs a slice of -// stressing clients concurrently. -type compositeStresser struct { - stressers []Stresser -} - -func (cs *compositeStresser) Stress() error { - for i, s := range cs.stressers { - if err := s.Stress(); err != nil { - for j := 0; j < i; j++ { - cs.stressers[j].Close() - } - return err - } - } - return nil -} - -func (cs *compositeStresser) Pause() (ems map[string]int) { - var emu sync.Mutex - ems = make(map[string]int) - var wg sync.WaitGroup - wg.Add(len(cs.stressers)) - for i := range cs.stressers { - go func(s Stresser) { - defer wg.Done() - errs := s.Pause() - for k, v := range errs { - emu.Lock() - ems[k] += v - emu.Unlock() - } - }(cs.stressers[i]) - } - wg.Wait() - return ems -} - -func (cs *compositeStresser) Close() (ems map[string]int) { - var emu sync.Mutex - ems = make(map[string]int) - var wg sync.WaitGroup - wg.Add(len(cs.stressers)) - for i := range cs.stressers { - go func(s Stresser) { - defer wg.Done() - errs := s.Close() - for k, v := range errs { - emu.Lock() - ems[k] += v - emu.Unlock() - } - }(cs.stressers[i]) - } - wg.Wait() - return ems -} - -func (cs *compositeStresser) ModifiedKeys() (modifiedKey int64) { - for _, stress := range cs.stressers { - modifiedKey += stress.ModifiedKeys() - } - return modifiedKey -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/stresser_key.go b/vendor/go.etcd.io/etcd/functional/tester/stresser_key.go deleted file mode 100644 index 2fc1bf2b0ced..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/stresser_key.go +++ /dev/null @@ -1,344 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "context" - "fmt" - "math/rand" - "reflect" - "sync" - "sync/atomic" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - "github.com/coreos/etcd/functional/rpcpb" - - "go.uber.org/zap" - "golang.org/x/time/rate" - "google.golang.org/grpc" - "google.golang.org/grpc/transport" -) - -type keyStresser struct { - stype rpcpb.Stresser - lg *zap.Logger - - m *rpcpb.Member - - keySize int - keyLargeSize int - keySuffixRange int - keyTxnSuffixRange int - keyTxnOps int - - rateLimiter *rate.Limiter - - wg sync.WaitGroup - clientsN int - - ctx context.Context - cancel func() - cli *clientv3.Client - - emu sync.RWMutex - ems map[string]int - paused bool - - // atomicModifiedKeys records the number of keys created and deleted by the stresser. - atomicModifiedKeys int64 - - stressTable *stressTable -} - -func (s *keyStresser) Stress() error { - var err error - s.cli, err = s.m.CreateEtcdClient(grpc.WithBackoffMaxDelay(1 * time.Second)) - if err != nil { - return fmt.Errorf("%v (%q)", err, s.m.EtcdClientEndpoint) - } - s.ctx, s.cancel = context.WithCancel(context.Background()) - - s.wg.Add(s.clientsN) - var stressEntries = []stressEntry{ - {weight: 0.7, f: newStressPut(s.cli, s.keySuffixRange, s.keySize)}, - { - weight: 0.7 * float32(s.keySize) / float32(s.keyLargeSize), - f: newStressPut(s.cli, s.keySuffixRange, s.keyLargeSize), - }, - {weight: 0.07, f: newStressRange(s.cli, s.keySuffixRange)}, - {weight: 0.07, f: newStressRangeInterval(s.cli, s.keySuffixRange)}, - {weight: 0.07, f: newStressDelete(s.cli, s.keySuffixRange)}, - {weight: 0.07, f: newStressDeleteInterval(s.cli, s.keySuffixRange)}, - } - if s.keyTxnSuffixRange > 0 { - // adjust to make up ±70% of workloads with writes - stressEntries[0].weight = 0.35 - stressEntries = append(stressEntries, stressEntry{ - weight: 0.35, - f: newStressTxn(s.cli, s.keyTxnSuffixRange, s.keyTxnOps), - }) - } - s.stressTable = createStressTable(stressEntries) - - s.emu.Lock() - s.paused = false - s.ems = make(map[string]int, 100) - s.emu.Unlock() - for i := 0; i < s.clientsN; i++ { - go s.run() - } - - s.lg.Info( - "stress START", - zap.String("stress-type", s.stype.String()), - zap.String("endpoint", s.m.EtcdClientEndpoint), - ) - return nil -} - -func (s *keyStresser) run() { - defer s.wg.Done() - - for { - if err := s.rateLimiter.Wait(s.ctx); err == context.Canceled { - return - } - - // TODO: 10-second is enough timeout to cover leader failure - // and immediate leader election. Find out what other cases this - // could be timed out. - sctx, scancel := context.WithTimeout(s.ctx, 10*time.Second) - err, modifiedKeys := s.stressTable.choose()(sctx) - scancel() - if err == nil { - atomic.AddInt64(&s.atomicModifiedKeys, modifiedKeys) - continue - } - - switch rpctypes.ErrorDesc(err) { - case context.DeadlineExceeded.Error(): - // This retries when request is triggered at the same time as - // leader failure. When we terminate the leader, the request to - // that leader cannot be processed, and times out. Also requests - // to followers cannot be forwarded to the old leader, so timing out - // as well. We want to keep stressing until the cluster elects a - // new leader and start processing requests again. - case etcdserver.ErrTimeoutDueToLeaderFail.Error(), etcdserver.ErrTimeout.Error(): - // This retries when request is triggered at the same time as - // leader failure and follower nodes receive time out errors - // from losing their leader. Followers should retry to connect - // to the new leader. - case etcdserver.ErrStopped.Error(): - // one of the etcd nodes stopped from failure injection - case transport.ErrConnClosing.Desc: - // server closed the transport (failure injected node) - case rpctypes.ErrNotCapable.Error(): - // capability check has not been done (in the beginning) - case rpctypes.ErrTooManyRequests.Error(): - // hitting the recovering member. - case context.Canceled.Error(): - // from stresser.Cancel method: - return - case grpc.ErrClientConnClosing.Error(): - // from stresser.Cancel method: - return - default: - s.lg.Warn( - "stress run exiting", - zap.String("stress-type", s.stype.String()), - zap.String("endpoint", s.m.EtcdClientEndpoint), - zap.String("error-type", reflect.TypeOf(err).String()), - zap.Error(err), - ) - return - } - - // only record errors before pausing stressers - s.emu.Lock() - if !s.paused { - s.ems[err.Error()]++ - } - s.emu.Unlock() - } -} - -func (s *keyStresser) Pause() map[string]int { - return s.Close() -} - -func (s *keyStresser) Close() map[string]int { - s.cancel() - s.cli.Close() - s.wg.Wait() - - s.emu.Lock() - s.paused = true - ess := s.ems - s.ems = make(map[string]int, 100) - s.emu.Unlock() - - s.lg.Info( - "stress STOP", - zap.String("stress-type", s.stype.String()), - zap.String("endpoint", s.m.EtcdClientEndpoint), - ) - return ess -} - -func (s *keyStresser) ModifiedKeys() int64 { - return atomic.LoadInt64(&s.atomicModifiedKeys) -} - -type stressFunc func(ctx context.Context) (err error, modifiedKeys int64) - -type stressEntry struct { - weight float32 - f stressFunc -} - -type stressTable struct { - entries []stressEntry - sumWeights float32 -} - -func createStressTable(entries []stressEntry) *stressTable { - st := stressTable{entries: entries} - for _, entry := range st.entries { - st.sumWeights += entry.weight - } - return &st -} - -func (st *stressTable) choose() stressFunc { - v := rand.Float32() * st.sumWeights - var sum float32 - var idx int - for i := range st.entries { - sum += st.entries[i].weight - if sum >= v { - idx = i - break - } - } - return st.entries[idx].f -} - -func newStressPut(cli *clientv3.Client, keySuffixRange, keySize int) stressFunc { - return func(ctx context.Context) (error, int64) { - _, err := cli.Put( - ctx, - fmt.Sprintf("foo%016x", rand.Intn(keySuffixRange)), - string(randBytes(keySize)), - ) - return err, 1 - } -} - -func newStressTxn(cli *clientv3.Client, keyTxnSuffixRange, txnOps int) stressFunc { - keys := make([]string, keyTxnSuffixRange) - for i := range keys { - keys[i] = fmt.Sprintf("/k%03d", i) - } - return writeTxn(cli, keys, txnOps) -} - -func writeTxn(cli *clientv3.Client, keys []string, txnOps int) stressFunc { - return func(ctx context.Context) (error, int64) { - ks := make(map[string]struct{}, txnOps) - for len(ks) != txnOps { - ks[keys[rand.Intn(len(keys))]] = struct{}{} - } - selected := make([]string, 0, txnOps) - for k := range ks { - selected = append(selected, k) - } - com, delOp, putOp := getTxnOps(selected[0], "bar00") - thenOps := []clientv3.Op{delOp} - elseOps := []clientv3.Op{putOp} - for i := 1; i < txnOps; i++ { // nested txns - k, v := selected[i], fmt.Sprintf("bar%02d", i) - com, delOp, putOp = getTxnOps(k, v) - txnOp := clientv3.OpTxn( - []clientv3.Cmp{com}, - []clientv3.Op{delOp}, - []clientv3.Op{putOp}, - ) - thenOps = append(thenOps, txnOp) - elseOps = append(elseOps, txnOp) - } - _, err := cli.Txn(ctx). - If(com). - Then(thenOps...). - Else(elseOps...). - Commit() - return err, int64(txnOps) - } -} - -func getTxnOps(k, v string) ( - cmp clientv3.Cmp, - dop clientv3.Op, - pop clientv3.Op) { - // if key exists (version > 0) - cmp = clientv3.Compare(clientv3.Version(k), ">", 0) - dop = clientv3.OpDelete(k) - pop = clientv3.OpPut(k, v) - return cmp, dop, pop -} - -func newStressRange(cli *clientv3.Client, keySuffixRange int) stressFunc { - return func(ctx context.Context) (error, int64) { - _, err := cli.Get(ctx, fmt.Sprintf("foo%016x", rand.Intn(keySuffixRange))) - return err, 0 - } -} - -func newStressRangeInterval(cli *clientv3.Client, keySuffixRange int) stressFunc { - return func(ctx context.Context) (error, int64) { - start := rand.Intn(keySuffixRange) - end := start + 500 - _, err := cli.Get( - ctx, - fmt.Sprintf("foo%016x", start), - clientv3.WithRange(fmt.Sprintf("foo%016x", end)), - ) - return err, 0 - } -} - -func newStressDelete(cli *clientv3.Client, keySuffixRange int) stressFunc { - return func(ctx context.Context) (error, int64) { - _, err := cli.Delete(ctx, fmt.Sprintf("foo%016x", rand.Intn(keySuffixRange))) - return err, 1 - } -} - -func newStressDeleteInterval(cli *clientv3.Client, keySuffixRange int) stressFunc { - return func(ctx context.Context) (error, int64) { - start := rand.Intn(keySuffixRange) - end := start + 500 - resp, err := cli.Delete(ctx, - fmt.Sprintf("foo%016x", start), - clientv3.WithRange(fmt.Sprintf("foo%016x", end)), - ) - if err == nil { - return nil, resp.Deleted - } - return err, 0 - } -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/stresser_lease.go b/vendor/go.etcd.io/etcd/functional/tester/stresser_lease.go deleted file mode 100644 index 8510a0765366..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/stresser_lease.go +++ /dev/null @@ -1,487 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "context" - "fmt" - "math/rand" - "sync" - "sync/atomic" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - "github.com/coreos/etcd/functional/rpcpb" - - "go.uber.org/zap" - "golang.org/x/time/rate" - "google.golang.org/grpc" -) - -const ( - // time to live for lease - defaultTTL = 120 - defaultTTLShort = 2 -) - -type leaseStresser struct { - stype rpcpb.Stresser - lg *zap.Logger - - m *rpcpb.Member - cli *clientv3.Client - ctx context.Context - cancel func() - - rateLimiter *rate.Limiter - // atomicModifiedKey records the number of keys created and deleted during a test case - atomicModifiedKey int64 - numLeases int - keysPerLease int - - aliveLeases *atomicLeases - revokedLeases *atomicLeases - shortLivedLeases *atomicLeases - - runWg sync.WaitGroup - aliveWg sync.WaitGroup -} - -type atomicLeases struct { - // rwLock is used to protect read/write access of leases map - // which are accessed and modified by different go routines. - rwLock sync.RWMutex - leases map[int64]time.Time -} - -func (al *atomicLeases) add(leaseID int64, t time.Time) { - al.rwLock.Lock() - al.leases[leaseID] = t - al.rwLock.Unlock() -} - -func (al *atomicLeases) update(leaseID int64, t time.Time) { - al.rwLock.Lock() - _, ok := al.leases[leaseID] - if ok { - al.leases[leaseID] = t - } - al.rwLock.Unlock() -} - -func (al *atomicLeases) read(leaseID int64) (rv time.Time, ok bool) { - al.rwLock.RLock() - rv, ok = al.leases[leaseID] - al.rwLock.RUnlock() - return rv, ok -} - -func (al *atomicLeases) remove(leaseID int64) { - al.rwLock.Lock() - delete(al.leases, leaseID) - al.rwLock.Unlock() -} - -func (al *atomicLeases) getLeasesMap() map[int64]time.Time { - leasesCopy := make(map[int64]time.Time) - al.rwLock.RLock() - for k, v := range al.leases { - leasesCopy[k] = v - } - al.rwLock.RUnlock() - return leasesCopy -} - -func (ls *leaseStresser) setupOnce() error { - if ls.aliveLeases != nil { - return nil - } - if ls.numLeases == 0 { - panic("expect numLeases to be set") - } - if ls.keysPerLease == 0 { - panic("expect keysPerLease to be set") - } - - ls.aliveLeases = &atomicLeases{leases: make(map[int64]time.Time)} - return nil -} - -func (ls *leaseStresser) Stress() error { - ls.lg.Info( - "stress START", - zap.String("stress-type", ls.stype.String()), - zap.String("endpoint", ls.m.EtcdClientEndpoint), - ) - - if err := ls.setupOnce(); err != nil { - return err - } - - ctx, cancel := context.WithCancel(context.Background()) - ls.ctx = ctx - ls.cancel = cancel - - cli, err := ls.m.CreateEtcdClient(grpc.WithBackoffMaxDelay(1 * time.Second)) - if err != nil { - return fmt.Errorf("%v (%s)", err, ls.m.EtcdClientEndpoint) - } - ls.cli = cli - - ls.revokedLeases = &atomicLeases{leases: make(map[int64]time.Time)} - ls.shortLivedLeases = &atomicLeases{leases: make(map[int64]time.Time)} - - ls.runWg.Add(1) - go ls.run() - return nil -} - -func (ls *leaseStresser) run() { - defer ls.runWg.Done() - ls.restartKeepAlives() - for { - // the number of keys created and deleted is roughly 2x the number of created keys for an iteration. - // the rateLimiter therefore consumes 2x ls.numLeases*ls.keysPerLease tokens where each token represents a create/delete operation for key. - err := ls.rateLimiter.WaitN(ls.ctx, 2*ls.numLeases*ls.keysPerLease) - if err == context.Canceled { - return - } - - ls.lg.Debug( - "stress creating leases", - zap.String("stress-type", ls.stype.String()), - zap.String("endpoint", ls.m.EtcdClientEndpoint), - ) - ls.createLeases() - ls.lg.Debug( - "stress created leases", - zap.String("stress-type", ls.stype.String()), - zap.String("endpoint", ls.m.EtcdClientEndpoint), - ) - - ls.lg.Debug( - "stress dropped leases", - zap.String("stress-type", ls.stype.String()), - zap.String("endpoint", ls.m.EtcdClientEndpoint), - ) - ls.randomlyDropLeases() - ls.lg.Debug( - "stress dropped leases", - zap.String("stress-type", ls.stype.String()), - zap.String("endpoint", ls.m.EtcdClientEndpoint), - ) - } -} - -func (ls *leaseStresser) restartKeepAlives() { - for leaseID := range ls.aliveLeases.getLeasesMap() { - ls.aliveWg.Add(1) - go func(id int64) { - ls.keepLeaseAlive(id) - }(leaseID) - } -} - -func (ls *leaseStresser) createLeases() { - ls.createAliveLeases() - ls.createShortLivedLeases() -} - -func (ls *leaseStresser) createAliveLeases() { - neededLeases := ls.numLeases - len(ls.aliveLeases.getLeasesMap()) - var wg sync.WaitGroup - for i := 0; i < neededLeases; i++ { - wg.Add(1) - go func() { - defer wg.Done() - leaseID, err := ls.createLeaseWithKeys(defaultTTL) - if err != nil { - ls.lg.Debug( - "createLeaseWithKeys failed", - zap.String("endpoint", ls.m.EtcdClientEndpoint), - zap.Error(err), - ) - return - } - ls.aliveLeases.add(leaseID, time.Now()) - // keep track of all the keep lease alive go routines - ls.aliveWg.Add(1) - go ls.keepLeaseAlive(leaseID) - }() - } - wg.Wait() -} - -func (ls *leaseStresser) createShortLivedLeases() { - // one round of createLeases() might not create all the short lived leases we want due to falures. - // thus, we want to create remaining short lived leases in the future round. - neededLeases := ls.numLeases - len(ls.shortLivedLeases.getLeasesMap()) - var wg sync.WaitGroup - for i := 0; i < neededLeases; i++ { - wg.Add(1) - go func() { - defer wg.Done() - leaseID, err := ls.createLeaseWithKeys(defaultTTLShort) - if err != nil { - return - } - ls.shortLivedLeases.add(leaseID, time.Now()) - }() - } - wg.Wait() -} - -func (ls *leaseStresser) createLeaseWithKeys(ttl int64) (int64, error) { - leaseID, err := ls.createLease(ttl) - if err != nil { - ls.lg.Debug( - "createLease failed", - zap.String("stress-type", ls.stype.String()), - zap.String("endpoint", ls.m.EtcdClientEndpoint), - zap.Error(err), - ) - return -1, err - } - - ls.lg.Debug( - "createLease created lease", - zap.String("stress-type", ls.stype.String()), - zap.String("endpoint", ls.m.EtcdClientEndpoint), - zap.String("lease-id", fmt.Sprintf("%016x", leaseID)), - ) - if err := ls.attachKeysWithLease(leaseID); err != nil { - return -1, err - } - return leaseID, nil -} - -func (ls *leaseStresser) randomlyDropLeases() { - var wg sync.WaitGroup - for l := range ls.aliveLeases.getLeasesMap() { - wg.Add(1) - go func(leaseID int64) { - defer wg.Done() - dropped, err := ls.randomlyDropLease(leaseID) - // if randomlyDropLease encountered an error such as context is cancelled, remove the lease from aliveLeases - // because we can't tell whether the lease is dropped or not. - if err != nil { - ls.lg.Debug( - "randomlyDropLease failed", - zap.String("endpoint", ls.m.EtcdClientEndpoint), - zap.String("lease-id", fmt.Sprintf("%016x", leaseID)), - zap.Error(err), - ) - ls.aliveLeases.remove(leaseID) - return - } - if !dropped { - return - } - ls.lg.Debug( - "randomlyDropLease dropped a lease", - zap.String("stress-type", ls.stype.String()), - zap.String("endpoint", ls.m.EtcdClientEndpoint), - zap.String("lease-id", fmt.Sprintf("%016x", leaseID)), - ) - ls.revokedLeases.add(leaseID, time.Now()) - ls.aliveLeases.remove(leaseID) - }(l) - } - wg.Wait() -} - -func (ls *leaseStresser) createLease(ttl int64) (int64, error) { - resp, err := ls.cli.Grant(ls.ctx, ttl) - if err != nil { - return -1, err - } - return int64(resp.ID), nil -} - -func (ls *leaseStresser) keepLeaseAlive(leaseID int64) { - defer ls.aliveWg.Done() - ctx, cancel := context.WithCancel(ls.ctx) - stream, err := ls.cli.KeepAlive(ctx, clientv3.LeaseID(leaseID)) - defer func() { cancel() }() - for { - select { - case <-time.After(500 * time.Millisecond): - case <-ls.ctx.Done(): - ls.lg.Debug( - "keepLeaseAlive context canceled", - zap.String("stress-type", ls.stype.String()), - zap.String("endpoint", ls.m.EtcdClientEndpoint), - zap.String("lease-id", fmt.Sprintf("%016x", leaseID)), - zap.Error(ls.ctx.Err()), - ) - // it is possible that lease expires at invariant checking phase but not at keepLeaseAlive() phase. - // this scenerio is possible when alive lease is just about to expire when keepLeaseAlive() exists and expires at invariant checking phase. - // to circumvent that scenerio, we check each lease before keepalive loop exist to see if it has been renewed in last TTL/2 duration. - // if it is renewed, this means that invariant checking have at least ttl/2 time before lease exipres which is long enough for the checking to finish. - // if it is not renewed, we remove the lease from the alive map so that the lease doesn't exipre during invariant checking - renewTime, ok := ls.aliveLeases.read(leaseID) - if ok && renewTime.Add(defaultTTL/2*time.Second).Before(time.Now()) { - ls.aliveLeases.remove(leaseID) - ls.lg.Debug( - "keepLeaseAlive lease has not been renewed, dropped it", - zap.String("stress-type", ls.stype.String()), - zap.String("endpoint", ls.m.EtcdClientEndpoint), - zap.String("lease-id", fmt.Sprintf("%016x", leaseID)), - ) - } - return - } - - if err != nil { - ls.lg.Debug( - "keepLeaseAlive lease creates stream error", - zap.String("stress-type", ls.stype.String()), - zap.String("endpoint", ls.m.EtcdClientEndpoint), - zap.String("lease-id", fmt.Sprintf("%016x", leaseID)), - zap.Error(err), - ) - cancel() - ctx, cancel = context.WithCancel(ls.ctx) - stream, err = ls.cli.KeepAlive(ctx, clientv3.LeaseID(leaseID)) - cancel() - continue - } - if err != nil { - ls.lg.Debug( - "keepLeaseAlive failed to receive lease keepalive response", - zap.String("stress-type", ls.stype.String()), - zap.String("endpoint", ls.m.EtcdClientEndpoint), - zap.String("lease-id", fmt.Sprintf("%016x", leaseID)), - zap.Error(err), - ) - continue - } - - ls.lg.Debug( - "keepLeaseAlive waiting on lease stream", - zap.String("stress-type", ls.stype.String()), - zap.String("endpoint", ls.m.EtcdClientEndpoint), - zap.String("lease-id", fmt.Sprintf("%016x", leaseID)), - ) - leaseRenewTime := time.Now() - respRC := <-stream - if respRC == nil { - ls.lg.Debug( - "keepLeaseAlive received nil lease keepalive response", - zap.String("stress-type", ls.stype.String()), - zap.String("endpoint", ls.m.EtcdClientEndpoint), - zap.String("lease-id", fmt.Sprintf("%016x", leaseID)), - ) - continue - } - - // lease expires after TTL become 0 - // don't send keepalive if the lease has expired - if respRC.TTL <= 0 { - ls.lg.Debug( - "keepLeaseAlive stream received lease keepalive response TTL <= 0", - zap.String("stress-type", ls.stype.String()), - zap.String("endpoint", ls.m.EtcdClientEndpoint), - zap.String("lease-id", fmt.Sprintf("%016x", leaseID)), - zap.Int64("ttl", respRC.TTL), - ) - ls.aliveLeases.remove(leaseID) - return - } - // renew lease timestamp only if lease is present - ls.lg.Debug( - "keepLeaseAlive renewed a lease", - zap.String("stress-type", ls.stype.String()), - zap.String("endpoint", ls.m.EtcdClientEndpoint), - zap.String("lease-id", fmt.Sprintf("%016x", leaseID)), - ) - ls.aliveLeases.update(leaseID, leaseRenewTime) - } -} - -// attachKeysWithLease function attaches keys to the lease. -// the format of key is the concat of leaseID + '_' + '' -// e.g 5186835655248304152_0 for first created key and 5186835655248304152_1 for second created key -func (ls *leaseStresser) attachKeysWithLease(leaseID int64) error { - var txnPuts []clientv3.Op - for j := 0; j < ls.keysPerLease; j++ { - txnput := clientv3.OpPut( - fmt.Sprintf("%d%s%d", leaseID, "_", j), - fmt.Sprintf("bar"), - clientv3.WithLease(clientv3.LeaseID(leaseID)), - ) - txnPuts = append(txnPuts, txnput) - } - // keep retrying until lease is not found or ctx is being canceled - for ls.ctx.Err() == nil { - _, err := ls.cli.Txn(ls.ctx).Then(txnPuts...).Commit() - if err == nil { - // since all created keys will be deleted too, the number of operations on keys will be roughly 2x the number of created keys - atomic.AddInt64(&ls.atomicModifiedKey, 2*int64(ls.keysPerLease)) - return nil - } - if rpctypes.Error(err) == rpctypes.ErrLeaseNotFound { - return err - } - } - return ls.ctx.Err() -} - -// randomlyDropLease drops the lease only when the rand.Int(2) returns 1. -// This creates a 50/50 percents chance of dropping a lease -func (ls *leaseStresser) randomlyDropLease(leaseID int64) (bool, error) { - if rand.Intn(2) != 0 { - return false, nil - } - - // keep retrying until a lease is dropped or ctx is being canceled - for ls.ctx.Err() == nil { - _, err := ls.cli.Revoke(ls.ctx, clientv3.LeaseID(leaseID)) - if err == nil || rpctypes.Error(err) == rpctypes.ErrLeaseNotFound { - return true, nil - } - } - - ls.lg.Debug( - "randomlyDropLease error", - zap.String("stress-type", ls.stype.String()), - zap.String("endpoint", ls.m.EtcdClientEndpoint), - zap.String("lease-id", fmt.Sprintf("%016x", leaseID)), - zap.Error(ls.ctx.Err()), - ) - return false, ls.ctx.Err() -} - -func (ls *leaseStresser) Pause() map[string]int { - return ls.Close() -} - -func (ls *leaseStresser) Close() map[string]int { - ls.cancel() - ls.runWg.Wait() - ls.aliveWg.Wait() - ls.cli.Close() - ls.lg.Info( - "stress STOP", - zap.String("stress-type", ls.stype.String()), - zap.String("endpoint", ls.m.EtcdClientEndpoint), - ) - return nil -} - -func (ls *leaseStresser) ModifiedKeys() int64 { - return atomic.LoadInt64(&ls.atomicModifiedKey) -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/stresser_runner.go b/vendor/go.etcd.io/etcd/functional/tester/stresser_runner.go deleted file mode 100644 index 18487f402b72..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/stresser_runner.go +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "fmt" - "io/ioutil" - "os/exec" - "syscall" - - "github.com/coreos/etcd/functional/rpcpb" - - "go.uber.org/zap" - "golang.org/x/time/rate" -) - -type runnerStresser struct { - stype rpcpb.Stresser - etcdClientEndpoint string - lg *zap.Logger - - cmd *exec.Cmd - cmdStr string - args []string - rl *rate.Limiter - reqRate int - - errc chan error - donec chan struct{} -} - -func newRunnerStresser( - stype rpcpb.Stresser, - ep string, - lg *zap.Logger, - cmdStr string, - args []string, - rl *rate.Limiter, - reqRate int, -) *runnerStresser { - rl.SetLimit(rl.Limit() - rate.Limit(reqRate)) - return &runnerStresser{ - stype: stype, - etcdClientEndpoint: ep, - cmdStr: cmdStr, - args: args, - rl: rl, - reqRate: reqRate, - errc: make(chan error, 1), - donec: make(chan struct{}), - } -} - -func (rs *runnerStresser) setupOnce() (err error) { - if rs.cmd != nil { - return nil - } - - rs.cmd = exec.Command(rs.cmdStr, rs.args...) - stderr, err := rs.cmd.StderrPipe() - if err != nil { - return err - } - - go func() { - defer close(rs.donec) - out, err := ioutil.ReadAll(stderr) - if err != nil { - rs.errc <- err - } else { - rs.errc <- fmt.Errorf("(%v %v) stderr %v", rs.cmdStr, rs.args, string(out)) - } - }() - - return rs.cmd.Start() -} - -func (rs *runnerStresser) Stress() (err error) { - rs.lg.Info( - "stress START", - zap.String("stress-type", rs.stype.String()), - ) - if err = rs.setupOnce(); err != nil { - return err - } - return syscall.Kill(rs.cmd.Process.Pid, syscall.SIGCONT) -} - -func (rs *runnerStresser) Pause() map[string]int { - rs.lg.Info( - "stress STOP", - zap.String("stress-type", rs.stype.String()), - ) - syscall.Kill(rs.cmd.Process.Pid, syscall.SIGSTOP) - return nil -} - -func (rs *runnerStresser) Close() map[string]int { - syscall.Kill(rs.cmd.Process.Pid, syscall.SIGINT) - rs.cmd.Wait() - <-rs.donec - rs.rl.SetLimit(rs.rl.Limit() + rate.Limit(rs.reqRate)) - return nil -} - -func (rs *runnerStresser) ModifiedKeys() int64 { - return 1 -} diff --git a/vendor/go.etcd.io/etcd/functional/tester/utils.go b/vendor/go.etcd.io/etcd/functional/tester/utils.go deleted file mode 100644 index 74e34146d535..000000000000 --- a/vendor/go.etcd.io/etcd/functional/tester/utils.go +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tester - -import ( - "fmt" - "math/rand" - "net" - "net/url" - "strings" -) - -func isValidURL(u string) bool { - _, err := url.Parse(u) - return err == nil -} - -func getPort(addr string) (port string, err error) { - urlAddr, err := url.Parse(addr) - if err != nil { - return "", err - } - _, port, err = net.SplitHostPort(urlAddr.Host) - if err != nil { - return "", err - } - return port, nil -} - -func getSameValue(vals map[string]int64) bool { - var rv int64 - for _, v := range vals { - if rv == 0 { - rv = v - } - if rv != v { - return false - } - } - return true -} - -func max(n1, n2 int64) int64 { - if n1 > n2 { - return n1 - } - return n2 -} - -func errsToError(errs []error) error { - if len(errs) == 0 { - return nil - } - stringArr := make([]string, len(errs)) - for i, err := range errs { - stringArr[i] = err.Error() - } - return fmt.Errorf(strings.Join(stringArr, ", ")) -} - -func randBytes(size int) []byte { - data := make([]byte, size) - for i := 0; i < size; i++ { - data[i] = byte(int('a') + rand.Intn(26)) - } - return data -} diff --git a/vendor/go.etcd.io/etcd/integration/bridge.go b/vendor/go.etcd.io/etcd/integration/bridge.go deleted file mode 100644 index 9792ba89f942..000000000000 --- a/vendor/go.etcd.io/etcd/integration/bridge.go +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package integration - -import ( - "fmt" - "io" - "io/ioutil" - "net" - "sync" - - "github.com/coreos/etcd/pkg/transport" -) - -// bridge creates a unix socket bridge to another unix socket, making it possible -// to disconnect grpc network connections without closing the logical grpc connection. -type bridge struct { - inaddr string - outaddr string - l net.Listener - conns map[*bridgeConn]struct{} - - stopc chan struct{} - pausec chan struct{} - blackholec chan struct{} - wg sync.WaitGroup - - mu sync.Mutex -} - -func newBridge(addr string) (*bridge, error) { - b := &bridge{ - // bridge "port" is ("%05d%05d0", port, pid) since go1.8 expects the port to be a number - inaddr: addr + "0", - outaddr: addr, - conns: make(map[*bridgeConn]struct{}), - stopc: make(chan struct{}), - pausec: make(chan struct{}), - blackholec: make(chan struct{}), - } - close(b.pausec) - - l, err := transport.NewUnixListener(b.inaddr) - if err != nil { - return nil, fmt.Errorf("listen failed on socket %s (%v)", addr, err) - } - b.l = l - b.wg.Add(1) - go b.serveListen() - return b, nil -} - -func (b *bridge) URL() string { return "unix://" + b.inaddr } - -func (b *bridge) Close() { - b.l.Close() - b.mu.Lock() - select { - case <-b.stopc: - default: - close(b.stopc) - } - b.mu.Unlock() - b.wg.Wait() -} - -func (b *bridge) Reset() { - b.mu.Lock() - defer b.mu.Unlock() - for bc := range b.conns { - bc.Close() - } - b.conns = make(map[*bridgeConn]struct{}) -} - -func (b *bridge) Pause() { - b.mu.Lock() - b.pausec = make(chan struct{}) - b.mu.Unlock() -} - -func (b *bridge) Unpause() { - b.mu.Lock() - select { - case <-b.pausec: - default: - close(b.pausec) - } - b.mu.Unlock() -} - -func (b *bridge) serveListen() { - defer func() { - b.l.Close() - b.mu.Lock() - for bc := range b.conns { - bc.Close() - } - b.mu.Unlock() - b.wg.Done() - }() - - for { - inc, ierr := b.l.Accept() - if ierr != nil { - return - } - b.mu.Lock() - pausec := b.pausec - b.mu.Unlock() - select { - case <-b.stopc: - inc.Close() - return - case <-pausec: - } - - outc, oerr := net.Dial("unix", b.outaddr) - if oerr != nil { - inc.Close() - return - } - - bc := &bridgeConn{inc, outc, make(chan struct{})} - b.wg.Add(1) - b.mu.Lock() - b.conns[bc] = struct{}{} - go b.serveConn(bc) - b.mu.Unlock() - } -} - -func (b *bridge) serveConn(bc *bridgeConn) { - defer func() { - close(bc.donec) - bc.Close() - b.mu.Lock() - delete(b.conns, bc) - b.mu.Unlock() - b.wg.Done() - }() - - var wg sync.WaitGroup - wg.Add(2) - go func() { - b.ioCopy(bc, bc.out, bc.in) - bc.close() - wg.Done() - }() - go func() { - b.ioCopy(bc, bc.in, bc.out) - bc.close() - wg.Done() - }() - wg.Wait() -} - -type bridgeConn struct { - in net.Conn - out net.Conn - donec chan struct{} -} - -func (bc *bridgeConn) Close() { - bc.close() - <-bc.donec -} - -func (bc *bridgeConn) close() { - bc.in.Close() - bc.out.Close() -} - -func (b *bridge) Blackhole() { - b.mu.Lock() - close(b.blackholec) - b.mu.Unlock() -} - -func (b *bridge) Unblackhole() { - b.mu.Lock() - for bc := range b.conns { - bc.Close() - } - b.conns = make(map[*bridgeConn]struct{}) - b.blackholec = make(chan struct{}) - b.mu.Unlock() -} - -// ref. https://github.com/golang/go/blob/master/src/io/io.go copyBuffer -func (b *bridge) ioCopy(bc *bridgeConn, dst io.Writer, src io.Reader) (err error) { - buf := make([]byte, 32*1024) - for { - select { - case <-b.blackholec: - io.Copy(ioutil.Discard, src) - return nil - default: - } - nr, er := src.Read(buf) - if nr > 0 { - nw, ew := dst.Write(buf[0:nr]) - if ew != nil { - return ew - } - if nr != nw { - return io.ErrShortWrite - } - } - if er != nil { - err = er - break - } - } - return err -} diff --git a/vendor/go.etcd.io/etcd/integration/cluster.go b/vendor/go.etcd.io/etcd/integration/cluster.go deleted file mode 100644 index 923e20afa316..000000000000 --- a/vendor/go.etcd.io/etcd/integration/cluster.go +++ /dev/null @@ -1,1105 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package integration - -import ( - "context" - "crypto/tls" - "fmt" - "io/ioutil" - "math/rand" - "net" - "net/http" - "net/http/httptest" - "os" - "reflect" - "sort" - "strings" - "sync" - "sync/atomic" - "testing" - "time" - - "github.com/coreos/etcd/client" - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/embed" - "github.com/coreos/etcd/etcdserver" - "github.com/coreos/etcd/etcdserver/api/etcdhttp" - "github.com/coreos/etcd/etcdserver/api/v2http" - "github.com/coreos/etcd/etcdserver/api/v3client" - "github.com/coreos/etcd/etcdserver/api/v3election" - epb "github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb" - "github.com/coreos/etcd/etcdserver/api/v3lock" - lockpb "github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb" - "github.com/coreos/etcd/etcdserver/api/v3rpc" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/pkg/testutil" - "github.com/coreos/etcd/pkg/tlsutil" - "github.com/coreos/etcd/pkg/transport" - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/etcd/rafthttp" - - "github.com/coreos/pkg/capnslog" - "github.com/soheilhy/cmux" - "google.golang.org/grpc" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/keepalive" -) - -const ( - // RequestWaitTimeout is the time duration to wait for a request to go through or detect leader loss. - RequestWaitTimeout = 3 * time.Second - tickDuration = 10 * time.Millisecond - requestTimeout = 20 * time.Second - - clusterName = "etcd" - basePort = 21000 - UrlScheme = "unix" - UrlSchemeTLS = "unixs" -) - -var ( - electionTicks = 10 - - // integration test uses unique ports, counting up, to listen for each - // member, ensuring restarted members can listen on the same port again. - localListenCount int64 = 0 - - testTLSInfo = transport.TLSInfo{ - KeyFile: "./fixtures/server.key.insecure", - CertFile: "./fixtures/server.crt", - TrustedCAFile: "./fixtures/ca.crt", - ClientCertAuth: true, - } - - testTLSInfoExpired = transport.TLSInfo{ - KeyFile: "./fixtures-expired/server-key.pem", - CertFile: "./fixtures-expired/server.pem", - TrustedCAFile: "./fixtures-expired/etcd-root-ca.pem", - ClientCertAuth: true, - } - - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "integration") -) - -type ClusterConfig struct { - Size int - PeerTLS *transport.TLSInfo - ClientTLS *transport.TLSInfo - DiscoveryURL string - UseGRPC bool - QuotaBackendBytes int64 - MaxTxnOps uint - MaxRequestBytes uint - GRPCKeepAliveMinTime time.Duration - GRPCKeepAliveInterval time.Duration - GRPCKeepAliveTimeout time.Duration - // SkipCreatingClient to skip creating clients for each member. - SkipCreatingClient bool - - ClientMaxCallSendMsgSize int - ClientMaxCallRecvMsgSize int -} - -type cluster struct { - cfg *ClusterConfig - Members []*member -} - -func schemeFromTLSInfo(tls *transport.TLSInfo) string { - if tls == nil { - return UrlScheme - } - return UrlSchemeTLS -} - -func (c *cluster) fillClusterForMembers() error { - if c.cfg.DiscoveryURL != "" { - // cluster will be discovered - return nil - } - - addrs := make([]string, 0) - for _, m := range c.Members { - scheme := schemeFromTLSInfo(m.PeerTLSInfo) - for _, l := range m.PeerListeners { - addrs = append(addrs, fmt.Sprintf("%s=%s://%s", m.Name, scheme, l.Addr().String())) - } - } - clusterStr := strings.Join(addrs, ",") - var err error - for _, m := range c.Members { - m.InitialPeerURLsMap, err = types.NewURLsMap(clusterStr) - if err != nil { - return err - } - } - return nil -} - -func newCluster(t *testing.T, cfg *ClusterConfig) *cluster { - c := &cluster{cfg: cfg} - ms := make([]*member, cfg.Size) - for i := 0; i < cfg.Size; i++ { - ms[i] = c.mustNewMember(t) - } - c.Members = ms - if err := c.fillClusterForMembers(); err != nil { - t.Fatal(err) - } - - return c -} - -// NewCluster returns an unlaunched cluster of the given size which has been -// set to use static bootstrap. -func NewCluster(t *testing.T, size int) *cluster { - return newCluster(t, &ClusterConfig{Size: size}) -} - -// NewClusterByConfig returns an unlaunched cluster defined by a cluster configuration -func NewClusterByConfig(t *testing.T, cfg *ClusterConfig) *cluster { - return newCluster(t, cfg) -} - -func (c *cluster) Launch(t *testing.T) { - errc := make(chan error) - for _, m := range c.Members { - // Members are launched in separate goroutines because if they boot - // using discovery url, they have to wait for others to register to continue. - go func(m *member) { - errc <- m.Launch() - }(m) - } - for range c.Members { - if err := <-errc; err != nil { - t.Fatalf("error setting up member: %v", err) - } - } - // wait cluster to be stable to receive future client requests - c.waitMembersMatch(t, c.HTTPMembers()) - c.waitVersion() -} - -func (c *cluster) URL(i int) string { - return c.Members[i].ClientURLs[0].String() -} - -// URLs returns a list of all active client URLs in the cluster -func (c *cluster) URLs() []string { - return getMembersURLs(c.Members) -} - -func getMembersURLs(members []*member) []string { - urls := make([]string, 0) - for _, m := range members { - select { - case <-m.s.StopNotify(): - continue - default: - } - for _, u := range m.ClientURLs { - urls = append(urls, u.String()) - } - } - return urls -} - -// HTTPMembers returns a list of all active members as client.Members -func (c *cluster) HTTPMembers() []client.Member { - ms := []client.Member{} - for _, m := range c.Members { - pScheme := schemeFromTLSInfo(m.PeerTLSInfo) - cScheme := schemeFromTLSInfo(m.ClientTLSInfo) - cm := client.Member{Name: m.Name} - for _, ln := range m.PeerListeners { - cm.PeerURLs = append(cm.PeerURLs, pScheme+"://"+ln.Addr().String()) - } - for _, ln := range m.ClientListeners { - cm.ClientURLs = append(cm.ClientURLs, cScheme+"://"+ln.Addr().String()) - } - ms = append(ms, cm) - } - return ms -} - -func (c *cluster) mustNewMember(t *testing.T) *member { - m := mustNewMember(t, - memberConfig{ - name: c.name(rand.Int()), - peerTLS: c.cfg.PeerTLS, - clientTLS: c.cfg.ClientTLS, - quotaBackendBytes: c.cfg.QuotaBackendBytes, - maxTxnOps: c.cfg.MaxTxnOps, - maxRequestBytes: c.cfg.MaxRequestBytes, - grpcKeepAliveMinTime: c.cfg.GRPCKeepAliveMinTime, - grpcKeepAliveInterval: c.cfg.GRPCKeepAliveInterval, - grpcKeepAliveTimeout: c.cfg.GRPCKeepAliveTimeout, - clientMaxCallSendMsgSize: c.cfg.ClientMaxCallSendMsgSize, - clientMaxCallRecvMsgSize: c.cfg.ClientMaxCallRecvMsgSize, - }) - m.DiscoveryURL = c.cfg.DiscoveryURL - if c.cfg.UseGRPC { - if err := m.listenGRPC(); err != nil { - t.Fatal(err) - } - } - return m -} - -func (c *cluster) addMember(t *testing.T) { - m := c.mustNewMember(t) - - scheme := schemeFromTLSInfo(c.cfg.PeerTLS) - - // send add request to the cluster - var err error - for i := 0; i < len(c.Members); i++ { - clientURL := c.URL(i) - peerURL := scheme + "://" + m.PeerListeners[0].Addr().String() - if err = c.addMemberByURL(t, clientURL, peerURL); err == nil { - break - } - } - if err != nil { - t.Fatalf("add member failed on all members error: %v", err) - } - - m.InitialPeerURLsMap = types.URLsMap{} - for _, mm := range c.Members { - m.InitialPeerURLsMap[mm.Name] = mm.PeerURLs - } - m.InitialPeerURLsMap[m.Name] = m.PeerURLs - m.NewCluster = false - if err := m.Launch(); err != nil { - t.Fatal(err) - } - c.Members = append(c.Members, m) - // wait cluster to be stable to receive future client requests - c.waitMembersMatch(t, c.HTTPMembers()) -} - -func (c *cluster) addMemberByURL(t *testing.T, clientURL, peerURL string) error { - cc := MustNewHTTPClient(t, []string{clientURL}, c.cfg.ClientTLS) - ma := client.NewMembersAPI(cc) - ctx, cancel := context.WithTimeout(context.Background(), requestTimeout) - _, err := ma.Add(ctx, peerURL) - cancel() - if err != nil { - return err - } - - // wait for the add node entry applied in the cluster - members := append(c.HTTPMembers(), client.Member{PeerURLs: []string{peerURL}, ClientURLs: []string{}}) - c.waitMembersMatch(t, members) - return nil -} - -func (c *cluster) AddMember(t *testing.T) { - c.addMember(t) -} - -func (c *cluster) RemoveMember(t *testing.T, id uint64) { - if err := c.removeMember(t, id); err != nil { - t.Fatal(err) - } -} - -func (c *cluster) removeMember(t *testing.T, id uint64) error { - // send remove request to the cluster - cc := MustNewHTTPClient(t, c.URLs(), c.cfg.ClientTLS) - ma := client.NewMembersAPI(cc) - ctx, cancel := context.WithTimeout(context.Background(), requestTimeout) - err := ma.Remove(ctx, types.ID(id).String()) - cancel() - if err != nil { - return err - } - newMembers := make([]*member, 0) - for _, m := range c.Members { - if uint64(m.s.ID()) != id { - newMembers = append(newMembers, m) - } else { - select { - case <-m.s.StopNotify(): - m.Terminate(t) - // 1s stop delay + election timeout + 1s disk and network delay + connection write timeout - // TODO: remove connection write timeout by selecting on http response closeNotifier - // blocking on https://github.com/golang/go/issues/9524 - case <-time.After(time.Second + time.Duration(electionTicks)*tickDuration + time.Second + rafthttp.ConnWriteTimeout): - t.Fatalf("failed to remove member %s in time", m.s.ID()) - } - } - } - c.Members = newMembers - c.waitMembersMatch(t, c.HTTPMembers()) - return nil -} - -func (c *cluster) Terminate(t *testing.T) { - var wg sync.WaitGroup - wg.Add(len(c.Members)) - for _, m := range c.Members { - go func(mm *member) { - defer wg.Done() - mm.Terminate(t) - }(m) - } - wg.Wait() -} - -func (c *cluster) waitMembersMatch(t *testing.T, membs []client.Member) { - for _, u := range c.URLs() { - cc := MustNewHTTPClient(t, []string{u}, c.cfg.ClientTLS) - ma := client.NewMembersAPI(cc) - for { - ctx, cancel := context.WithTimeout(context.Background(), requestTimeout) - ms, err := ma.List(ctx) - cancel() - if err == nil && isMembersEqual(ms, membs) { - break - } - time.Sleep(tickDuration) - } - } -} - -func (c *cluster) WaitLeader(t *testing.T) int { return c.waitLeader(t, c.Members) } - -// waitLeader waits until given members agree on the same leader. -func (c *cluster) waitLeader(t *testing.T, membs []*member) int { - possibleLead := make(map[uint64]bool) - var lead uint64 - for _, m := range membs { - possibleLead[uint64(m.s.ID())] = true - } - cc := MustNewHTTPClient(t, getMembersURLs(membs), nil) - kapi := client.NewKeysAPI(cc) - - // ensure leader is up via linearizable get - for { - ctx, cancel := context.WithTimeout(context.Background(), 10*tickDuration+time.Second) - _, err := kapi.Get(ctx, "0", &client.GetOptions{Quorum: true}) - cancel() - if err == nil || strings.Contains(err.Error(), "Key not found") { - break - } - } - - for lead == 0 || !possibleLead[lead] { - lead = 0 - for _, m := range membs { - select { - case <-m.s.StopNotify(): - continue - default: - } - if lead != 0 && lead != m.s.Lead() { - lead = 0 - time.Sleep(10 * tickDuration) - break - } - lead = m.s.Lead() - } - } - - for i, m := range membs { - if uint64(m.s.ID()) == lead { - return i - } - } - - return -1 -} - -func (c *cluster) WaitNoLeader(t *testing.T) { c.waitNoLeader(t, c.Members) } - -// waitNoLeader waits until given members lose leader. -func (c *cluster) waitNoLeader(t *testing.T, membs []*member) { - noLeader := false - for !noLeader { - noLeader = true - for _, m := range membs { - select { - case <-m.s.StopNotify(): - continue - default: - } - if m.s.Lead() != 0 { - noLeader = false - time.Sleep(10 * tickDuration) - break - } - } - } -} - -func (c *cluster) waitVersion() { - for _, m := range c.Members { - for { - if m.s.ClusterVersion() != nil { - break - } - time.Sleep(tickDuration) - } - } -} - -func (c *cluster) name(i int) string { - return fmt.Sprint(i) -} - -// isMembersEqual checks whether two members equal except ID field. -// The given wmembs should always set ID field to empty string. -func isMembersEqual(membs []client.Member, wmembs []client.Member) bool { - sort.Sort(SortableMemberSliceByPeerURLs(membs)) - sort.Sort(SortableMemberSliceByPeerURLs(wmembs)) - for i := range membs { - membs[i].ID = "" - } - return reflect.DeepEqual(membs, wmembs) -} - -func newLocalListener(t *testing.T) net.Listener { - c := atomic.AddInt64(&localListenCount, 1) - // Go 1.8+ allows only numbers in port - addr := fmt.Sprintf("127.0.0.1:%05d%05d", c+basePort, os.Getpid()) - return NewListenerWithAddr(t, addr) -} - -func NewListenerWithAddr(t *testing.T, addr string) net.Listener { - l, err := transport.NewUnixListener(addr) - if err != nil { - t.Fatal(err) - } - return l -} - -type member struct { - etcdserver.ServerConfig - PeerListeners, ClientListeners []net.Listener - grpcListener net.Listener - // PeerTLSInfo enables peer TLS when set - PeerTLSInfo *transport.TLSInfo - // ClientTLSInfo enables client TLS when set - ClientTLSInfo *transport.TLSInfo - - raftHandler *testutil.PauseableHandler - s *etcdserver.EtcdServer - serverClosers []func() - - grpcServerOpts []grpc.ServerOption - grpcServer *grpc.Server - grpcServerPeer *grpc.Server - grpcAddr string - grpcBridge *bridge - - // serverClient is a clientv3 that directly calls the etcdserver. - serverClient *clientv3.Client - - keepDataDirTerminate bool - clientMaxCallSendMsgSize int - clientMaxCallRecvMsgSize int -} - -func (m *member) GRPCAddr() string { return m.grpcAddr } - -type memberConfig struct { - name string - peerTLS *transport.TLSInfo - clientTLS *transport.TLSInfo - quotaBackendBytes int64 - maxTxnOps uint - maxRequestBytes uint - grpcKeepAliveMinTime time.Duration - grpcKeepAliveInterval time.Duration - grpcKeepAliveTimeout time.Duration - clientMaxCallSendMsgSize int - clientMaxCallRecvMsgSize int -} - -// mustNewMember return an inited member with the given name. If peerTLS is -// set, it will use https scheme to communicate between peers. -func mustNewMember(t *testing.T, mcfg memberConfig) *member { - var err error - m := &member{} - - peerScheme := schemeFromTLSInfo(mcfg.peerTLS) - clientScheme := schemeFromTLSInfo(mcfg.clientTLS) - - pln := newLocalListener(t) - m.PeerListeners = []net.Listener{pln} - m.PeerURLs, err = types.NewURLs([]string{peerScheme + "://" + pln.Addr().String()}) - if err != nil { - t.Fatal(err) - } - m.PeerTLSInfo = mcfg.peerTLS - - cln := newLocalListener(t) - m.ClientListeners = []net.Listener{cln} - m.ClientURLs, err = types.NewURLs([]string{clientScheme + "://" + cln.Addr().String()}) - if err != nil { - t.Fatal(err) - } - m.ClientTLSInfo = mcfg.clientTLS - - m.Name = mcfg.name - - m.DataDir, err = ioutil.TempDir(os.TempDir(), "etcd") - if err != nil { - t.Fatal(err) - } - clusterStr := fmt.Sprintf("%s=%s://%s", mcfg.name, peerScheme, pln.Addr().String()) - m.InitialPeerURLsMap, err = types.NewURLsMap(clusterStr) - if err != nil { - t.Fatal(err) - } - m.InitialClusterToken = clusterName - m.NewCluster = true - m.BootstrapTimeout = 10 * time.Millisecond - if m.PeerTLSInfo != nil { - m.ServerConfig.PeerTLSInfo = *m.PeerTLSInfo - } - m.ElectionTicks = electionTicks - m.InitialElectionTickAdvance = true - m.TickMs = uint(tickDuration / time.Millisecond) - m.QuotaBackendBytes = mcfg.quotaBackendBytes - m.MaxTxnOps = mcfg.maxTxnOps - if m.MaxTxnOps == 0 { - m.MaxTxnOps = embed.DefaultMaxTxnOps - } - m.MaxRequestBytes = mcfg.maxRequestBytes - if m.MaxRequestBytes == 0 { - m.MaxRequestBytes = embed.DefaultMaxRequestBytes - } - m.AuthToken = "simple" // for the purpose of integration testing, simple token is enough - - m.grpcServerOpts = []grpc.ServerOption{} - if mcfg.grpcKeepAliveMinTime > time.Duration(0) { - m.grpcServerOpts = append(m.grpcServerOpts, grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{ - MinTime: mcfg.grpcKeepAliveMinTime, - PermitWithoutStream: false, - })) - } - if mcfg.grpcKeepAliveInterval > time.Duration(0) && - mcfg.grpcKeepAliveTimeout > time.Duration(0) { - m.grpcServerOpts = append(m.grpcServerOpts, grpc.KeepaliveParams(keepalive.ServerParameters{ - Time: mcfg.grpcKeepAliveInterval, - Timeout: mcfg.grpcKeepAliveTimeout, - })) - } - m.clientMaxCallSendMsgSize = mcfg.clientMaxCallSendMsgSize - m.clientMaxCallRecvMsgSize = mcfg.clientMaxCallRecvMsgSize - - m.InitialCorruptCheck = true - - return m -} - -// listenGRPC starts a grpc server over a unix domain socket on the member -func (m *member) listenGRPC() error { - // prefix with localhost so cert has right domain - m.grpcAddr = "localhost:" + m.Name - l, err := transport.NewUnixListener(m.grpcAddr) - if err != nil { - return fmt.Errorf("listen failed on grpc socket %s (%v)", m.grpcAddr, err) - } - m.grpcBridge, err = newBridge(m.grpcAddr) - if err != nil { - l.Close() - return err - } - m.grpcAddr = schemeFromTLSInfo(m.ClientTLSInfo) + "://" + m.grpcBridge.inaddr - m.grpcListener = l - return nil -} - -func (m *member) ElectionTimeout() time.Duration { - return time.Duration(m.s.Cfg.ElectionTicks*int(m.s.Cfg.TickMs)) * time.Millisecond -} - -func (m *member) ID() types.ID { return m.s.ID() } - -func (m *member) DropConnections() { m.grpcBridge.Reset() } -func (m *member) PauseConnections() { m.grpcBridge.Pause() } -func (m *member) UnpauseConnections() { m.grpcBridge.Unpause() } -func (m *member) Blackhole() { m.grpcBridge.Blackhole() } -func (m *member) Unblackhole() { m.grpcBridge.Unblackhole() } - -// NewClientV3 creates a new grpc client connection to the member -func NewClientV3(m *member) (*clientv3.Client, error) { - if m.grpcAddr == "" { - return nil, fmt.Errorf("member not configured for grpc") - } - - cfg := clientv3.Config{ - Endpoints: []string{m.grpcAddr}, - DialTimeout: 5 * time.Second, - MaxCallSendMsgSize: m.clientMaxCallSendMsgSize, - MaxCallRecvMsgSize: m.clientMaxCallRecvMsgSize, - } - - if m.ClientTLSInfo != nil { - tls, err := m.ClientTLSInfo.ClientConfig() - if err != nil { - return nil, err - } - cfg.TLS = tls - } - return newClientV3(cfg) -} - -// Clone returns a member with the same server configuration. The returned -// member will not set PeerListeners and ClientListeners. -func (m *member) Clone(t *testing.T) *member { - mm := &member{} - mm.ServerConfig = m.ServerConfig - - var err error - clientURLStrs := m.ClientURLs.StringSlice() - mm.ClientURLs, err = types.NewURLs(clientURLStrs) - if err != nil { - // this should never fail - panic(err) - } - peerURLStrs := m.PeerURLs.StringSlice() - mm.PeerURLs, err = types.NewURLs(peerURLStrs) - if err != nil { - // this should never fail - panic(err) - } - clusterStr := m.InitialPeerURLsMap.String() - mm.InitialPeerURLsMap, err = types.NewURLsMap(clusterStr) - if err != nil { - // this should never fail - panic(err) - } - mm.InitialClusterToken = m.InitialClusterToken - mm.ElectionTicks = m.ElectionTicks - mm.PeerTLSInfo = m.PeerTLSInfo - mm.ClientTLSInfo = m.ClientTLSInfo - return mm -} - -// Launch starts a member based on ServerConfig, PeerListeners -// and ClientListeners. -func (m *member) Launch() error { - plog.Printf("launching %s (%s)", m.Name, m.grpcAddr) - var err error - if m.s, err = etcdserver.NewServer(m.ServerConfig); err != nil { - return fmt.Errorf("failed to initialize the etcd server: %v", err) - } - m.s.SyncTicker = time.NewTicker(500 * time.Millisecond) - m.s.Start() - - var peerTLScfg *tls.Config - if m.PeerTLSInfo != nil && !m.PeerTLSInfo.Empty() { - if peerTLScfg, err = m.PeerTLSInfo.ServerConfig(); err != nil { - return err - } - } - - if m.grpcListener != nil { - var ( - tlscfg *tls.Config - ) - if m.ClientTLSInfo != nil && !m.ClientTLSInfo.Empty() { - tlscfg, err = m.ClientTLSInfo.ServerConfig() - if err != nil { - return err - } - } - m.grpcServer = v3rpc.Server(m.s, tlscfg, m.grpcServerOpts...) - m.grpcServerPeer = v3rpc.Server(m.s, peerTLScfg) - m.serverClient = v3client.New(m.s) - lockpb.RegisterLockServer(m.grpcServer, v3lock.NewLockServer(m.serverClient)) - epb.RegisterElectionServer(m.grpcServer, v3election.NewElectionServer(m.serverClient)) - go m.grpcServer.Serve(m.grpcListener) - } - - m.raftHandler = &testutil.PauseableHandler{Next: etcdhttp.NewPeerHandler(m.s)} - - h := (http.Handler)(m.raftHandler) - if m.grpcListener != nil { - h = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") { - m.grpcServerPeer.ServeHTTP(w, r) - } else { - m.raftHandler.ServeHTTP(w, r) - } - }) - } - - for _, ln := range m.PeerListeners { - cm := cmux.New(ln) - // don't hang on matcher after closing listener - cm.SetReadTimeout(time.Second) - - if m.grpcServer != nil { - grpcl := cm.Match(cmux.HTTP2()) - go m.grpcServerPeer.Serve(grpcl) - } - - // serve http1/http2 rafthttp/grpc - ll := cm.Match(cmux.Any()) - if peerTLScfg != nil { - if ll, err = transport.NewTLSListener(ll, m.PeerTLSInfo); err != nil { - return err - } - } - hs := &httptest.Server{ - Listener: ll, - Config: &http.Server{Handler: h, TLSConfig: peerTLScfg}, - TLS: peerTLScfg, - } - hs.Start() - - donec := make(chan struct{}) - go func() { - defer close(donec) - cm.Serve() - }() - closer := func() { - ll.Close() - hs.CloseClientConnections() - hs.Close() - <-donec - } - m.serverClosers = append(m.serverClosers, closer) - } - for _, ln := range m.ClientListeners { - hs := &httptest.Server{ - Listener: ln, - Config: &http.Server{Handler: v2http.NewClientHandler(m.s, m.ServerConfig.ReqTimeout())}, - } - if m.ClientTLSInfo == nil { - hs.Start() - } else { - info := m.ClientTLSInfo - hs.TLS, err = info.ServerConfig() - if err != nil { - return err - } - - // baseConfig is called on initial TLS handshake start. - // - // Previously, - // 1. Server has non-empty (*tls.Config).Certificates on client hello - // 2. Server calls (*tls.Config).GetCertificate iff: - // - Server's (*tls.Config).Certificates is not empty, or - // - Client supplies SNI; non-empty (*tls.ClientHelloInfo).ServerName - // - // When (*tls.Config).Certificates is always populated on initial handshake, - // client is expected to provide a valid matching SNI to pass the TLS - // verification, thus trigger server (*tls.Config).GetCertificate to reload - // TLS assets. However, a cert whose SAN field does not include domain names - // but only IP addresses, has empty (*tls.ClientHelloInfo).ServerName, thus - // it was never able to trigger TLS reload on initial handshake; first - // ceritifcate object was being used, never being updated. - // - // Now, (*tls.Config).Certificates is created empty on initial TLS client - // handshake, in order to trigger (*tls.Config).GetCertificate and populate - // rest of the certificates on every new TLS connection, even when client - // SNI is empty (e.g. cert only includes IPs). - // - // This introduces another problem with "httptest.Server": - // when server initial certificates are empty, certificates - // are overwritten by Go's internal test certs, which have - // different SAN fields (e.g. example.com). To work around, - // re-overwrite (*tls.Config).Certificates before starting - // test server. - tlsCert, err := tlsutil.NewCert(info.CertFile, info.KeyFile, nil) - if err != nil { - return err - } - hs.TLS.Certificates = []tls.Certificate{*tlsCert} - - hs.StartTLS() - } - closer := func() { - ln.Close() - hs.CloseClientConnections() - hs.Close() - } - m.serverClosers = append(m.serverClosers, closer) - } - - plog.Printf("launched %s (%s)", m.Name, m.grpcAddr) - return nil -} - -func (m *member) WaitOK(t *testing.T) { - cc := MustNewHTTPClient(t, []string{m.URL()}, m.ClientTLSInfo) - kapi := client.NewKeysAPI(cc) - for { - ctx, cancel := context.WithTimeout(context.Background(), requestTimeout) - _, err := kapi.Get(ctx, "/", nil) - if err != nil { - time.Sleep(tickDuration) - continue - } - cancel() - break - } - for m.s.Leader() == 0 { - time.Sleep(tickDuration) - } -} - -func (m *member) URL() string { return m.ClientURLs[0].String() } - -func (m *member) Pause() { - m.raftHandler.Pause() - m.s.PauseSending() -} - -func (m *member) Resume() { - m.raftHandler.Resume() - m.s.ResumeSending() -} - -// Close stops the member's etcdserver and closes its connections -func (m *member) Close() { - if m.grpcBridge != nil { - m.grpcBridge.Close() - m.grpcBridge = nil - } - if m.serverClient != nil { - m.serverClient.Close() - m.serverClient = nil - } - if m.grpcServer != nil { - m.grpcServer.Stop() - m.grpcServer.GracefulStop() - m.grpcServer = nil - m.grpcServerPeer.Stop() - m.grpcServerPeer.GracefulStop() - m.grpcServerPeer = nil - } - m.s.HardStop() - for _, f := range m.serverClosers { - f() - } -} - -// Stop stops the member, but the data dir of the member is preserved. -func (m *member) Stop(t *testing.T) { - plog.Printf("stopping %s (%s)", m.Name, m.grpcAddr) - m.Close() - m.serverClosers = nil - plog.Printf("stopped %s (%s)", m.Name, m.grpcAddr) -} - -// checkLeaderTransition waits for leader transition, returning the new leader ID. -func checkLeaderTransition(t *testing.T, m *member, oldLead uint64) uint64 { - interval := time.Duration(m.s.Cfg.TickMs) * time.Millisecond - for m.s.Lead() == 0 || (m.s.Lead() == oldLead) { - time.Sleep(interval) - } - return m.s.Lead() -} - -// StopNotify unblocks when a member stop completes -func (m *member) StopNotify() <-chan struct{} { - return m.s.StopNotify() -} - -// Restart starts the member using the preserved data dir. -func (m *member) Restart(t *testing.T) error { - plog.Printf("restarting %s (%s)", m.Name, m.grpcAddr) - newPeerListeners := make([]net.Listener, 0) - for _, ln := range m.PeerListeners { - newPeerListeners = append(newPeerListeners, NewListenerWithAddr(t, ln.Addr().String())) - } - m.PeerListeners = newPeerListeners - newClientListeners := make([]net.Listener, 0) - for _, ln := range m.ClientListeners { - newClientListeners = append(newClientListeners, NewListenerWithAddr(t, ln.Addr().String())) - } - m.ClientListeners = newClientListeners - - if m.grpcListener != nil { - if err := m.listenGRPC(); err != nil { - t.Fatal(err) - } - } - - err := m.Launch() - plog.Printf("restarted %s (%s)", m.Name, m.grpcAddr) - return err -} - -// Terminate stops the member and removes the data dir. -func (m *member) Terminate(t *testing.T) { - plog.Printf("terminating %s (%s)", m.Name, m.grpcAddr) - m.Close() - if !m.keepDataDirTerminate { - if err := os.RemoveAll(m.ServerConfig.DataDir); err != nil { - t.Fatal(err) - } - } - plog.Printf("terminated %s (%s)", m.Name, m.grpcAddr) -} - -// Metric gets the metric value for a member -func (m *member) Metric(metricName string) (string, error) { - cfgtls := transport.TLSInfo{} - tr, err := transport.NewTimeoutTransport(cfgtls, time.Second, time.Second, time.Second) - if err != nil { - return "", err - } - cli := &http.Client{Transport: tr} - resp, err := cli.Get(m.ClientURLs[0].String() + "/metrics") - if err != nil { - return "", err - } - defer resp.Body.Close() - b, rerr := ioutil.ReadAll(resp.Body) - if rerr != nil { - return "", rerr - } - lines := strings.Split(string(b), "\n") - for _, l := range lines { - if strings.HasPrefix(l, metricName) { - return strings.Split(l, " ")[1], nil - } - } - return "", nil -} - -// InjectPartition drops connections from m to others, vice versa. -func (m *member) InjectPartition(t *testing.T, others ...*member) { - for _, other := range others { - m.s.CutPeer(other.s.ID()) - other.s.CutPeer(m.s.ID()) - } -} - -// RecoverPartition recovers connections from m to others, vice versa. -func (m *member) RecoverPartition(t *testing.T, others ...*member) { - for _, other := range others { - m.s.MendPeer(other.s.ID()) - other.s.MendPeer(m.s.ID()) - } -} - -func MustNewHTTPClient(t *testing.T, eps []string, tls *transport.TLSInfo) client.Client { - cfgtls := transport.TLSInfo{} - if tls != nil { - cfgtls = *tls - } - cfg := client.Config{Transport: mustNewTransport(t, cfgtls), Endpoints: eps} - c, err := client.New(cfg) - if err != nil { - t.Fatal(err) - } - return c -} - -func mustNewTransport(t *testing.T, tlsInfo transport.TLSInfo) *http.Transport { - // tick in integration test is short, so 1s dial timeout could play well. - tr, err := transport.NewTimeoutTransport(tlsInfo, time.Second, rafthttp.ConnReadTimeout, rafthttp.ConnWriteTimeout) - if err != nil { - t.Fatal(err) - } - return tr -} - -type SortableMemberSliceByPeerURLs []client.Member - -func (p SortableMemberSliceByPeerURLs) Len() int { return len(p) } -func (p SortableMemberSliceByPeerURLs) Less(i, j int) bool { - return p[i].PeerURLs[0] < p[j].PeerURLs[0] -} -func (p SortableMemberSliceByPeerURLs) Swap(i, j int) { p[i], p[j] = p[j], p[i] } - -type ClusterV3 struct { - *cluster - - mu sync.Mutex - clients []*clientv3.Client -} - -// NewClusterV3 returns a launched cluster with a grpc client connection -// for each cluster member. -func NewClusterV3(t *testing.T, cfg *ClusterConfig) *ClusterV3 { - cfg.UseGRPC = true - if os.Getenv("CLIENT_DEBUG") != "" { - clientv3.SetLogger(grpclog.NewLoggerV2WithVerbosity(os.Stderr, os.Stderr, os.Stderr, 4)) - } - clus := &ClusterV3{ - cluster: NewClusterByConfig(t, cfg), - } - clus.Launch(t) - - if !cfg.SkipCreatingClient { - for _, m := range clus.Members { - client, err := NewClientV3(m) - if err != nil { - t.Fatalf("cannot create client: %v", err) - } - clus.clients = append(clus.clients, client) - } - } - - return clus -} - -func (c *ClusterV3) TakeClient(idx int) { - c.mu.Lock() - c.clients[idx] = nil - c.mu.Unlock() -} - -func (c *ClusterV3) Terminate(t *testing.T) { - c.mu.Lock() - for _, client := range c.clients { - if client == nil { - continue - } - if err := client.Close(); err != nil { - t.Error(err) - } - } - c.mu.Unlock() - c.cluster.Terminate(t) -} - -func (c *ClusterV3) RandClient() *clientv3.Client { - return c.clients[rand.Intn(len(c.clients))] -} - -func (c *ClusterV3) Client(i int) *clientv3.Client { - return c.clients[i] -} - -type grpcAPI struct { - // Cluster is the cluster API for the client's connection. - Cluster pb.ClusterClient - // KV is the keyvalue API for the client's connection. - KV pb.KVClient - // Lease is the lease API for the client's connection. - Lease pb.LeaseClient - // Watch is the watch API for the client's connection. - Watch pb.WatchClient - // Maintenance is the maintenance API for the client's connection. - Maintenance pb.MaintenanceClient - // Auth is the authentication API for the client's connection. - Auth pb.AuthClient - // Lock is the lock API for the client's connection. - Lock lockpb.LockClient - // Election is the election API for the client's connection. - Election epb.ElectionClient -} diff --git a/vendor/go.etcd.io/etcd/integration/cluster_direct.go b/vendor/go.etcd.io/etcd/integration/cluster_direct.go deleted file mode 100644 index ff97e6146edf..000000000000 --- a/vendor/go.etcd.io/etcd/integration/cluster_direct.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !cluster_proxy - -package integration - -import ( - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb" - "github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -func toGRPC(c *clientv3.Client) grpcAPI { - return grpcAPI{ - pb.NewClusterClient(c.ActiveConnection()), - pb.NewKVClient(c.ActiveConnection()), - pb.NewLeaseClient(c.ActiveConnection()), - pb.NewWatchClient(c.ActiveConnection()), - pb.NewMaintenanceClient(c.ActiveConnection()), - pb.NewAuthClient(c.ActiveConnection()), - v3lockpb.NewLockClient(c.ActiveConnection()), - v3electionpb.NewElectionClient(c.ActiveConnection()), - } -} - -func newClientV3(cfg clientv3.Config) (*clientv3.Client, error) { - return clientv3.New(cfg) -} diff --git a/vendor/go.etcd.io/etcd/integration/cluster_proxy.go b/vendor/go.etcd.io/etcd/integration/cluster_proxy.go deleted file mode 100644 index 1e8d8b572fb9..000000000000 --- a/vendor/go.etcd.io/etcd/integration/cluster_proxy.go +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build cluster_proxy - -package integration - -import ( - "sync" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/namespace" - "github.com/coreos/etcd/proxy/grpcproxy" - "github.com/coreos/etcd/proxy/grpcproxy/adapter" -) - -var ( - pmu sync.Mutex - proxies map[*clientv3.Client]grpcClientProxy = make(map[*clientv3.Client]grpcClientProxy) -) - -const proxyNamespace = "proxy-namespace" - -type grpcClientProxy struct { - grpc grpcAPI - wdonec <-chan struct{} - kvdonec <-chan struct{} - lpdonec <-chan struct{} -} - -func toGRPC(c *clientv3.Client) grpcAPI { - pmu.Lock() - defer pmu.Unlock() - - if v, ok := proxies[c]; ok { - return v.grpc - } - - // test namespacing proxy - c.KV = namespace.NewKV(c.KV, proxyNamespace) - c.Watcher = namespace.NewWatcher(c.Watcher, proxyNamespace) - c.Lease = namespace.NewLease(c.Lease, proxyNamespace) - // test coalescing/caching proxy - kvp, kvpch := grpcproxy.NewKvProxy(c) - wp, wpch := grpcproxy.NewWatchProxy(c) - lp, lpch := grpcproxy.NewLeaseProxy(c) - mp := grpcproxy.NewMaintenanceProxy(c) - clp, _ := grpcproxy.NewClusterProxy(c, "", "") // without registering proxy URLs - authp := grpcproxy.NewAuthProxy(c) - lockp := grpcproxy.NewLockProxy(c) - electp := grpcproxy.NewElectionProxy(c) - - grpc := grpcAPI{ - adapter.ClusterServerToClusterClient(clp), - adapter.KvServerToKvClient(kvp), - adapter.LeaseServerToLeaseClient(lp), - adapter.WatchServerToWatchClient(wp), - adapter.MaintenanceServerToMaintenanceClient(mp), - adapter.AuthServerToAuthClient(authp), - adapter.LockServerToLockClient(lockp), - adapter.ElectionServerToElectionClient(electp), - } - proxies[c] = grpcClientProxy{grpc: grpc, wdonec: wpch, kvdonec: kvpch, lpdonec: lpch} - return grpc -} - -type proxyCloser struct { - clientv3.Watcher - wdonec <-chan struct{} - kvdonec <-chan struct{} - lclose func() - lpdonec <-chan struct{} -} - -func (pc *proxyCloser) Close() error { - // client ctx is canceled before calling close, so kv and lp will close out - <-pc.kvdonec - err := pc.Watcher.Close() - <-pc.wdonec - pc.lclose() - <-pc.lpdonec - return err -} - -func newClientV3(cfg clientv3.Config) (*clientv3.Client, error) { - c, err := clientv3.New(cfg) - if err != nil { - return nil, err - } - rpc := toGRPC(c) - c.KV = clientv3.NewKVFromKVClient(rpc.KV, c) - pmu.Lock() - lc := c.Lease - c.Lease = clientv3.NewLeaseFromLeaseClient(rpc.Lease, c, cfg.DialTimeout) - c.Watcher = &proxyCloser{ - Watcher: clientv3.NewWatchFromWatchClient(rpc.Watch, c), - wdonec: proxies[c].wdonec, - kvdonec: proxies[c].kvdonec, - lclose: func() { lc.Close() }, - lpdonec: proxies[c].lpdonec, - } - pmu.Unlock() - return c, nil -} diff --git a/vendor/go.etcd.io/etcd/integration/doc.go b/vendor/go.etcd.io/etcd/integration/doc.go deleted file mode 100644 index fbf19d543687..000000000000 --- a/vendor/go.etcd.io/etcd/integration/doc.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package integration implements tests built upon embedded etcd, and focus on -etcd correctness. - -Features/goals of the integration tests: -1. test the whole code base except command-line parsing. -2. check internal data, including raft, store and etc. -3. based on goroutines, which is faster than process. -4. mainly tests user behavior and user-facing API. -*/ -package integration diff --git a/vendor/go.etcd.io/etcd/lease/doc.go b/vendor/go.etcd.io/etcd/lease/doc.go deleted file mode 100644 index a74eaf76fc59..000000000000 --- a/vendor/go.etcd.io/etcd/lease/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package lease provides an interface and implementation for time-limited leases over arbitrary resources. -package lease diff --git a/vendor/go.etcd.io/etcd/lease/leasehttp/doc.go b/vendor/go.etcd.io/etcd/lease/leasehttp/doc.go deleted file mode 100644 index 8177a37b663d..000000000000 --- a/vendor/go.etcd.io/etcd/lease/leasehttp/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package leasehttp serves lease renewals made through HTTP requests. -package leasehttp diff --git a/vendor/go.etcd.io/etcd/lease/leasehttp/http.go b/vendor/go.etcd.io/etcd/lease/leasehttp/http.go deleted file mode 100644 index ac2e7880e8a2..000000000000 --- a/vendor/go.etcd.io/etcd/lease/leasehttp/http.go +++ /dev/null @@ -1,247 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package leasehttp - -import ( - "bytes" - "context" - "errors" - "fmt" - "io/ioutil" - "net/http" - "time" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/lease/leasepb" - "github.com/coreos/etcd/pkg/httputil" -) - -var ( - LeasePrefix = "/leases" - LeaseInternalPrefix = "/leases/internal" - applyTimeout = time.Second - ErrLeaseHTTPTimeout = errors.New("waiting for node to catch up its applied index has timed out") -) - -// NewHandler returns an http Handler for lease renewals -func NewHandler(l lease.Lessor, waitch func() <-chan struct{}) http.Handler { - return &leaseHandler{l, waitch} -} - -type leaseHandler struct { - l lease.Lessor - waitch func() <-chan struct{} -} - -func (h *leaseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if r.Method != "POST" { - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return - } - - b, err := ioutil.ReadAll(r.Body) - if err != nil { - http.Error(w, "error reading body", http.StatusBadRequest) - return - } - - var v []byte - switch r.URL.Path { - case LeasePrefix: - lreq := pb.LeaseKeepAliveRequest{} - if err := lreq.Unmarshal(b); err != nil { - http.Error(w, "error unmarshalling request", http.StatusBadRequest) - return - } - select { - case <-h.waitch(): - case <-time.After(applyTimeout): - http.Error(w, ErrLeaseHTTPTimeout.Error(), http.StatusRequestTimeout) - return - } - ttl, err := h.l.Renew(lease.LeaseID(lreq.ID)) - if err != nil { - if err == lease.ErrLeaseNotFound { - http.Error(w, err.Error(), http.StatusNotFound) - return - } - - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - // TODO: fill out ResponseHeader - resp := &pb.LeaseKeepAliveResponse{ID: lreq.ID, TTL: ttl} - v, err = resp.Marshal() - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - case LeaseInternalPrefix: - lreq := leasepb.LeaseInternalRequest{} - if err := lreq.Unmarshal(b); err != nil { - http.Error(w, "error unmarshalling request", http.StatusBadRequest) - return - } - select { - case <-h.waitch(): - case <-time.After(applyTimeout): - http.Error(w, ErrLeaseHTTPTimeout.Error(), http.StatusRequestTimeout) - return - } - l := h.l.Lookup(lease.LeaseID(lreq.LeaseTimeToLiveRequest.ID)) - if l == nil { - http.Error(w, lease.ErrLeaseNotFound.Error(), http.StatusNotFound) - return - } - // TODO: fill out ResponseHeader - resp := &leasepb.LeaseInternalResponse{ - LeaseTimeToLiveResponse: &pb.LeaseTimeToLiveResponse{ - Header: &pb.ResponseHeader{}, - ID: lreq.LeaseTimeToLiveRequest.ID, - TTL: int64(l.Remaining().Seconds()), - GrantedTTL: l.TTL(), - }, - } - if lreq.LeaseTimeToLiveRequest.Keys { - ks := l.Keys() - kbs := make([][]byte, len(ks)) - for i := range ks { - kbs[i] = []byte(ks[i]) - } - resp.LeaseTimeToLiveResponse.Keys = kbs - } - - v, err = resp.Marshal() - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - default: - http.Error(w, fmt.Sprintf("unknown request path %q", r.URL.Path), http.StatusBadRequest) - return - } - - w.Header().Set("Content-Type", "application/protobuf") - w.Write(v) -} - -// RenewHTTP renews a lease at a given primary server. -// TODO: Batch request in future? -func RenewHTTP(ctx context.Context, id lease.LeaseID, url string, rt http.RoundTripper) (int64, error) { - // will post lreq protobuf to leader - lreq, err := (&pb.LeaseKeepAliveRequest{ID: int64(id)}).Marshal() - if err != nil { - return -1, err - } - - cc := &http.Client{Transport: rt} - req, err := http.NewRequest("POST", url, bytes.NewReader(lreq)) - if err != nil { - return -1, err - } - req.Header.Set("Content-Type", "application/protobuf") - req.Cancel = ctx.Done() - - resp, err := cc.Do(req) - if err != nil { - return -1, err - } - b, err := readResponse(resp) - if err != nil { - return -1, err - } - - if resp.StatusCode == http.StatusRequestTimeout { - return -1, ErrLeaseHTTPTimeout - } - - if resp.StatusCode == http.StatusNotFound { - return -1, lease.ErrLeaseNotFound - } - - if resp.StatusCode != http.StatusOK { - return -1, fmt.Errorf("lease: unknown error(%s)", string(b)) - } - - lresp := &pb.LeaseKeepAliveResponse{} - if err := lresp.Unmarshal(b); err != nil { - return -1, fmt.Errorf(`lease: %v. data = "%s"`, err, string(b)) - } - if lresp.ID != int64(id) { - return -1, fmt.Errorf("lease: renew id mismatch") - } - return lresp.TTL, nil -} - -// TimeToLiveHTTP retrieves lease information of the given lease ID. -func TimeToLiveHTTP(ctx context.Context, id lease.LeaseID, keys bool, url string, rt http.RoundTripper) (*leasepb.LeaseInternalResponse, error) { - // will post lreq protobuf to leader - lreq, err := (&leasepb.LeaseInternalRequest{ - LeaseTimeToLiveRequest: &pb.LeaseTimeToLiveRequest{ - ID: int64(id), - Keys: keys, - }, - }).Marshal() - if err != nil { - return nil, err - } - - req, err := http.NewRequest("POST", url, bytes.NewReader(lreq)) - if err != nil { - return nil, err - } - req.Header.Set("Content-Type", "application/protobuf") - - req = req.WithContext(ctx) - - cc := &http.Client{Transport: rt} - var b []byte - // buffer errc channel so that errc don't block inside the go routinue - resp, err := cc.Do(req) - if err != nil { - return nil, err - } - b, err = readResponse(resp) - if err != nil { - return nil, err - } - if resp.StatusCode == http.StatusRequestTimeout { - return nil, ErrLeaseHTTPTimeout - } - if resp.StatusCode == http.StatusNotFound { - return nil, lease.ErrLeaseNotFound - } - if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("lease: unknown error(%s)", string(b)) - } - - lresp := &leasepb.LeaseInternalResponse{} - if err := lresp.Unmarshal(b); err != nil { - return nil, fmt.Errorf(`lease: %v. data = "%s"`, err, string(b)) - } - if lresp.LeaseTimeToLiveResponse.ID != int64(id) { - return nil, fmt.Errorf("lease: renew id mismatch") - } - return lresp, nil -} - -func readResponse(resp *http.Response) (b []byte, err error) { - b, err = ioutil.ReadAll(resp.Body) - httputil.GracefulClose(resp) - return -} diff --git a/vendor/go.etcd.io/etcd/lease/leasepb/lease.pb.go b/vendor/go.etcd.io/etcd/lease/leasepb/lease.pb.go deleted file mode 100644 index 4ab937672776..000000000000 --- a/vendor/go.etcd.io/etcd/lease/leasepb/lease.pb.go +++ /dev/null @@ -1,591 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: lease.proto - -/* - Package leasepb is a generated protocol buffer package. - - It is generated from these files: - lease.proto - - It has these top-level messages: - Lease - LeaseInternalRequest - LeaseInternalResponse -*/ -package leasepb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - etcdserverpb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type Lease struct { - ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` - TTL int64 `protobuf:"varint,2,opt,name=TTL,proto3" json:"TTL,omitempty"` -} - -func (m *Lease) Reset() { *m = Lease{} } -func (m *Lease) String() string { return proto.CompactTextString(m) } -func (*Lease) ProtoMessage() {} -func (*Lease) Descriptor() ([]byte, []int) { return fileDescriptorLease, []int{0} } - -type LeaseInternalRequest struct { - LeaseTimeToLiveRequest *etcdserverpb.LeaseTimeToLiveRequest `protobuf:"bytes,1,opt,name=LeaseTimeToLiveRequest" json:"LeaseTimeToLiveRequest,omitempty"` -} - -func (m *LeaseInternalRequest) Reset() { *m = LeaseInternalRequest{} } -func (m *LeaseInternalRequest) String() string { return proto.CompactTextString(m) } -func (*LeaseInternalRequest) ProtoMessage() {} -func (*LeaseInternalRequest) Descriptor() ([]byte, []int) { return fileDescriptorLease, []int{1} } - -type LeaseInternalResponse struct { - LeaseTimeToLiveResponse *etcdserverpb.LeaseTimeToLiveResponse `protobuf:"bytes,1,opt,name=LeaseTimeToLiveResponse" json:"LeaseTimeToLiveResponse,omitempty"` -} - -func (m *LeaseInternalResponse) Reset() { *m = LeaseInternalResponse{} } -func (m *LeaseInternalResponse) String() string { return proto.CompactTextString(m) } -func (*LeaseInternalResponse) ProtoMessage() {} -func (*LeaseInternalResponse) Descriptor() ([]byte, []int) { return fileDescriptorLease, []int{2} } - -func init() { - proto.RegisterType((*Lease)(nil), "leasepb.Lease") - proto.RegisterType((*LeaseInternalRequest)(nil), "leasepb.LeaseInternalRequest") - proto.RegisterType((*LeaseInternalResponse)(nil), "leasepb.LeaseInternalResponse") -} -func (m *Lease) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Lease) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ID != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintLease(dAtA, i, uint64(m.ID)) - } - if m.TTL != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintLease(dAtA, i, uint64(m.TTL)) - } - return i, nil -} - -func (m *LeaseInternalRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseInternalRequest) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.LeaseTimeToLiveRequest != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintLease(dAtA, i, uint64(m.LeaseTimeToLiveRequest.Size())) - n1, err := m.LeaseTimeToLiveRequest.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - } - return i, nil -} - -func (m *LeaseInternalResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseInternalResponse) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.LeaseTimeToLiveResponse != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintLease(dAtA, i, uint64(m.LeaseTimeToLiveResponse.Size())) - n2, err := m.LeaseTimeToLiveResponse.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - } - return i, nil -} - -func encodeVarintLease(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *Lease) Size() (n int) { - var l int - _ = l - if m.ID != 0 { - n += 1 + sovLease(uint64(m.ID)) - } - if m.TTL != 0 { - n += 1 + sovLease(uint64(m.TTL)) - } - return n -} - -func (m *LeaseInternalRequest) Size() (n int) { - var l int - _ = l - if m.LeaseTimeToLiveRequest != nil { - l = m.LeaseTimeToLiveRequest.Size() - n += 1 + l + sovLease(uint64(l)) - } - return n -} - -func (m *LeaseInternalResponse) Size() (n int) { - var l int - _ = l - if m.LeaseTimeToLiveResponse != nil { - l = m.LeaseTimeToLiveResponse.Size() - n += 1 + l + sovLease(uint64(l)) - } - return n -} - -func sovLease(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozLease(x uint64) (n int) { - return sovLease(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Lease) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Lease: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Lease: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TTL", wireType) - } - m.TTL = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TTL |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipLease(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthLease - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseInternalRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseInternalRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseInternalRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field LeaseTimeToLiveRequest", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthLease - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.LeaseTimeToLiveRequest == nil { - m.LeaseTimeToLiveRequest = &etcdserverpb.LeaseTimeToLiveRequest{} - } - if err := m.LeaseTimeToLiveRequest.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipLease(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthLease - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseInternalResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseInternalResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseInternalResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field LeaseTimeToLiveResponse", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthLease - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.LeaseTimeToLiveResponse == nil { - m.LeaseTimeToLiveResponse = &etcdserverpb.LeaseTimeToLiveResponse{} - } - if err := m.LeaseTimeToLiveResponse.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipLease(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthLease - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipLease(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowLease - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowLease - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowLease - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthLease - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowLease - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipLease(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthLease = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowLease = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("lease.proto", fileDescriptorLease) } - -var fileDescriptorLease = []byte{ - // 233 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xce, 0x49, 0x4d, 0x2c, - 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x07, 0x73, 0x0a, 0x92, 0xa4, 0x44, 0xd2, - 0xf3, 0xd3, 0xf3, 0xc1, 0x62, 0xfa, 0x20, 0x16, 0x44, 0x5a, 0x4a, 0x2d, 0xb5, 0x24, 0x39, 0x45, - 0x1f, 0x44, 0x14, 0xa7, 0x16, 0x95, 0xa5, 0x16, 0x21, 0x31, 0x0b, 0x92, 0xf4, 0x8b, 0x0a, 0x92, - 0x21, 0xea, 0x94, 0x34, 0xb9, 0x58, 0x7d, 0x40, 0x06, 0x09, 0xf1, 0x71, 0x31, 0x79, 0xba, 0x48, - 0x30, 0x2a, 0x30, 0x6a, 0x30, 0x07, 0x31, 0x79, 0xba, 0x08, 0x09, 0x70, 0x31, 0x87, 0x84, 0xf8, - 0x48, 0x30, 0x81, 0x05, 0x40, 0x4c, 0xa5, 0x12, 0x2e, 0x11, 0xb0, 0x52, 0xcf, 0xbc, 0x92, 0xd4, - 0xa2, 0xbc, 0xc4, 0x9c, 0xa0, 0xd4, 0xc2, 0xd2, 0xd4, 0xe2, 0x12, 0xa1, 0x18, 0x2e, 0x31, 0xb0, - 0x78, 0x48, 0x66, 0x6e, 0x6a, 0x48, 0xbe, 0x4f, 0x66, 0x59, 0x2a, 0x54, 0x06, 0x6c, 0x1a, 0xb7, - 0x91, 0x8a, 0x1e, 0xb2, 0xdd, 0x7a, 0xd8, 0xd5, 0x06, 0xe1, 0x30, 0x43, 0xa9, 0x82, 0x4b, 0x14, - 0xcd, 0xd6, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, 0x54, 0xa1, 0x78, 0x2e, 0x71, 0x0c, 0x2d, 0x10, 0x29, - 0xa8, 0xbd, 0xaa, 0x04, 0xec, 0x85, 0x28, 0x0e, 0xc2, 0x65, 0x8a, 0x93, 0xc4, 0x89, 0x87, 0x72, - 0x0c, 0x17, 0x1e, 0xca, 0x31, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, - 0x72, 0x8c, 0x33, 0x1e, 0xcb, 0x31, 0x24, 0xb1, 0x81, 0xc3, 0xce, 0x18, 0x10, 0x00, 0x00, 0xff, - 0xff, 0x9f, 0xf2, 0x42, 0xe0, 0x91, 0x01, 0x00, 0x00, -} diff --git a/vendor/go.etcd.io/etcd/lease/lessor.go b/vendor/go.etcd.io/etcd/lease/lessor.go deleted file mode 100644 index 43f0503531fe..000000000000 --- a/vendor/go.etcd.io/etcd/lease/lessor.go +++ /dev/null @@ -1,680 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package lease - -import ( - "encoding/binary" - "errors" - "math" - "sort" - "sync" - "time" - - "github.com/coreos/etcd/lease/leasepb" - "github.com/coreos/etcd/mvcc/backend" -) - -// NoLease is a special LeaseID representing the absence of a lease. -const NoLease = LeaseID(0) - -// MaxLeaseTTL is the maximum lease TTL value -const MaxLeaseTTL = 9000000000 - -var ( - forever = time.Time{} - - leaseBucketName = []byte("lease") - - // maximum number of leases to revoke per second; configurable for tests - leaseRevokeRate = 1000 - - ErrNotPrimary = errors.New("not a primary lessor") - ErrLeaseNotFound = errors.New("lease not found") - ErrLeaseExists = errors.New("lease already exists") - ErrLeaseTTLTooLarge = errors.New("too large lease TTL") -) - -// TxnDelete is a TxnWrite that only permits deletes. Defined here -// to avoid circular dependency with mvcc. -type TxnDelete interface { - DeleteRange(key, end []byte) (n, rev int64) - End() -} - -// RangeDeleter is a TxnDelete constructor. -type RangeDeleter func() TxnDelete - -type LeaseID int64 - -// Lessor owns leases. It can grant, revoke, renew and modify leases for lessee. -type Lessor interface { - // SetRangeDeleter lets the lessor create TxnDeletes to the store. - // Lessor deletes the items in the revoked or expired lease by creating - // new TxnDeletes. - SetRangeDeleter(rd RangeDeleter) - - // Grant grants a lease that expires at least after TTL seconds. - Grant(id LeaseID, ttl int64) (*Lease, error) - // Revoke revokes a lease with given ID. The item attached to the - // given lease will be removed. If the ID does not exist, an error - // will be returned. - Revoke(id LeaseID) error - - // Attach attaches given leaseItem to the lease with given LeaseID. - // If the lease does not exist, an error will be returned. - Attach(id LeaseID, items []LeaseItem) error - - // GetLease returns LeaseID for given item. - // If no lease found, NoLease value will be returned. - GetLease(item LeaseItem) LeaseID - - // Detach detaches given leaseItem from the lease with given LeaseID. - // If the lease does not exist, an error will be returned. - Detach(id LeaseID, items []LeaseItem) error - - // Promote promotes the lessor to be the primary lessor. Primary lessor manages - // the expiration and renew of leases. - // Newly promoted lessor renew the TTL of all lease to extend + previous TTL. - Promote(extend time.Duration) - - // Demote demotes the lessor from being the primary lessor. - Demote() - - // Renew renews a lease with given ID. It returns the renewed TTL. If the ID does not exist, - // an error will be returned. - Renew(id LeaseID) (int64, error) - - // Lookup gives the lease at a given lease id, if any - Lookup(id LeaseID) *Lease - - // Leases lists all leases. - Leases() []*Lease - - // ExpiredLeasesC returns a chan that is used to receive expired leases. - ExpiredLeasesC() <-chan []*Lease - - // Recover recovers the lessor state from the given backend and RangeDeleter. - Recover(b backend.Backend, rd RangeDeleter) - - // Stop stops the lessor for managing leases. The behavior of calling Stop multiple - // times is undefined. - Stop() -} - -// lessor implements Lessor interface. -// TODO: use clockwork for testability. -type lessor struct { - mu sync.Mutex - - // demotec is set when the lessor is the primary. - // demotec will be closed if the lessor is demoted. - demotec chan struct{} - - // TODO: probably this should be a heap with a secondary - // id index. - // Now it is O(N) to loop over the leases to find expired ones. - // We want to make Grant, Revoke, and findExpiredLeases all O(logN) and - // Renew O(1). - // findExpiredLeases and Renew should be the most frequent operations. - leaseMap map[LeaseID]*Lease - - itemMap map[LeaseItem]LeaseID - - // When a lease expires, the lessor will delete the - // leased range (or key) by the RangeDeleter. - rd RangeDeleter - - // backend to persist leases. We only persist lease ID and expiry for now. - // The leased items can be recovered by iterating all the keys in kv. - b backend.Backend - - // minLeaseTTL is the minimum lease TTL that can be granted for a lease. Any - // requests for shorter TTLs are extended to the minimum TTL. - minLeaseTTL int64 - - expiredC chan []*Lease - // stopC is a channel whose closure indicates that the lessor should be stopped. - stopC chan struct{} - // doneC is a channel whose closure indicates that the lessor is stopped. - doneC chan struct{} -} - -func NewLessor(b backend.Backend, minLeaseTTL int64) Lessor { - return newLessor(b, minLeaseTTL) -} - -func newLessor(b backend.Backend, minLeaseTTL int64) *lessor { - l := &lessor{ - leaseMap: make(map[LeaseID]*Lease), - itemMap: make(map[LeaseItem]LeaseID), - b: b, - minLeaseTTL: minLeaseTTL, - // expiredC is a small buffered chan to avoid unnecessary blocking. - expiredC: make(chan []*Lease, 16), - stopC: make(chan struct{}), - doneC: make(chan struct{}), - } - l.initAndRecover() - - go l.runLoop() - - return l -} - -// isPrimary indicates if this lessor is the primary lessor. The primary -// lessor manages lease expiration and renew. -// -// in etcd, raft leader is the primary. Thus there might be two primary -// leaders at the same time (raft allows concurrent leader but with different term) -// for at most a leader election timeout. -// The old primary leader cannot affect the correctness since its proposal has a -// smaller term and will not be committed. -// -// TODO: raft follower do not forward lease management proposals. There might be a -// very small window (within second normally which depends on go scheduling) that -// a raft follow is the primary between the raft leader demotion and lessor demotion. -// Usually this should not be a problem. Lease should not be that sensitive to timing. -func (le *lessor) isPrimary() bool { - return le.demotec != nil -} - -func (le *lessor) SetRangeDeleter(rd RangeDeleter) { - le.mu.Lock() - defer le.mu.Unlock() - - le.rd = rd -} - -func (le *lessor) Grant(id LeaseID, ttl int64) (*Lease, error) { - if id == NoLease { - return nil, ErrLeaseNotFound - } - - if ttl > MaxLeaseTTL { - return nil, ErrLeaseTTLTooLarge - } - - // TODO: when lessor is under high load, it should give out lease - // with longer TTL to reduce renew load. - l := &Lease{ - ID: id, - ttl: ttl, - itemSet: make(map[LeaseItem]struct{}), - revokec: make(chan struct{}), - } - - le.mu.Lock() - defer le.mu.Unlock() - - if _, ok := le.leaseMap[id]; ok { - return nil, ErrLeaseExists - } - - if l.ttl < le.minLeaseTTL { - l.ttl = le.minLeaseTTL - } - - if le.isPrimary() { - l.refresh(0) - } else { - l.forever() - } - - le.leaseMap[id] = l - l.persistTo(le.b) - - return l, nil -} - -func (le *lessor) Revoke(id LeaseID) error { - le.mu.Lock() - - l := le.leaseMap[id] - if l == nil { - le.mu.Unlock() - return ErrLeaseNotFound - } - defer close(l.revokec) - // unlock before doing external work - le.mu.Unlock() - - if le.rd == nil { - return nil - } - - txn := le.rd() - - // sort keys so deletes are in same order among all members, - // otherwise the backened hashes will be different - keys := l.Keys() - sort.StringSlice(keys).Sort() - for _, key := range keys { - txn.DeleteRange([]byte(key), nil) - } - - le.mu.Lock() - defer le.mu.Unlock() - delete(le.leaseMap, l.ID) - // lease deletion needs to be in the same backend transaction with the - // kv deletion. Or we might end up with not executing the revoke or not - // deleting the keys if etcdserver fails in between. - le.b.BatchTx().UnsafeDelete(leaseBucketName, int64ToBytes(int64(l.ID))) - - txn.End() - return nil -} - -// Renew renews an existing lease. If the given lease does not exist or -// has expired, an error will be returned. -func (le *lessor) Renew(id LeaseID) (int64, error) { - le.mu.Lock() - - unlock := func() { le.mu.Unlock() } - defer func() { unlock() }() - - if !le.isPrimary() { - // forward renew request to primary instead of returning error. - return -1, ErrNotPrimary - } - - demotec := le.demotec - - l := le.leaseMap[id] - if l == nil { - return -1, ErrLeaseNotFound - } - - if l.expired() { - le.mu.Unlock() - unlock = func() {} - select { - // A expired lease might be pending for revoking or going through - // quorum to be revoked. To be accurate, renew request must wait for the - // deletion to complete. - case <-l.revokec: - return -1, ErrLeaseNotFound - // The expired lease might fail to be revoked if the primary changes. - // The caller will retry on ErrNotPrimary. - case <-demotec: - return -1, ErrNotPrimary - case <-le.stopC: - return -1, ErrNotPrimary - } - } - - l.refresh(0) - return l.ttl, nil -} - -func (le *lessor) Lookup(id LeaseID) *Lease { - le.mu.Lock() - defer le.mu.Unlock() - return le.leaseMap[id] -} - -func (le *lessor) unsafeLeases() []*Lease { - leases := make([]*Lease, 0, len(le.leaseMap)) - for _, l := range le.leaseMap { - leases = append(leases, l) - } - sort.Sort(leasesByExpiry(leases)) - return leases -} - -func (le *lessor) Leases() []*Lease { - le.mu.Lock() - ls := le.unsafeLeases() - le.mu.Unlock() - return ls -} - -func (le *lessor) Promote(extend time.Duration) { - le.mu.Lock() - defer le.mu.Unlock() - - le.demotec = make(chan struct{}) - - // refresh the expiries of all leases. - for _, l := range le.leaseMap { - l.refresh(extend) - } - - if len(le.leaseMap) < leaseRevokeRate { - // no possibility of lease pile-up - return - } - - // adjust expiries in case of overlap - leases := le.unsafeLeases() - - baseWindow := leases[0].Remaining() - nextWindow := baseWindow + time.Second - expires := 0 - // have fewer expires than the total revoke rate so piled up leases - // don't consume the entire revoke limit - targetExpiresPerSecond := (3 * leaseRevokeRate) / 4 - for _, l := range leases { - remaining := l.Remaining() - if remaining > nextWindow { - baseWindow = remaining - nextWindow = baseWindow + time.Second - expires = 1 - continue - } - expires++ - if expires <= targetExpiresPerSecond { - continue - } - rateDelay := float64(time.Second) * (float64(expires) / float64(targetExpiresPerSecond)) - // If leases are extended by n seconds, leases n seconds ahead of the - // base window should be extended by only one second. - rateDelay -= float64(remaining - baseWindow) - delay := time.Duration(rateDelay) - nextWindow = baseWindow + delay - l.refresh(delay + extend) - } -} - -type leasesByExpiry []*Lease - -func (le leasesByExpiry) Len() int { return len(le) } -func (le leasesByExpiry) Less(i, j int) bool { return le[i].Remaining() < le[j].Remaining() } -func (le leasesByExpiry) Swap(i, j int) { le[i], le[j] = le[j], le[i] } - -func (le *lessor) Demote() { - le.mu.Lock() - defer le.mu.Unlock() - - // set the expiries of all leases to forever - for _, l := range le.leaseMap { - l.forever() - } - - if le.demotec != nil { - close(le.demotec) - le.demotec = nil - } -} - -// Attach attaches items to the lease with given ID. When the lease -// expires, the attached items will be automatically removed. -// If the given lease does not exist, an error will be returned. -func (le *lessor) Attach(id LeaseID, items []LeaseItem) error { - le.mu.Lock() - defer le.mu.Unlock() - - l := le.leaseMap[id] - if l == nil { - return ErrLeaseNotFound - } - - l.mu.Lock() - for _, it := range items { - l.itemSet[it] = struct{}{} - le.itemMap[it] = id - } - l.mu.Unlock() - return nil -} - -func (le *lessor) GetLease(item LeaseItem) LeaseID { - le.mu.Lock() - id := le.itemMap[item] - le.mu.Unlock() - return id -} - -// Detach detaches items from the lease with given ID. -// If the given lease does not exist, an error will be returned. -func (le *lessor) Detach(id LeaseID, items []LeaseItem) error { - le.mu.Lock() - defer le.mu.Unlock() - - l := le.leaseMap[id] - if l == nil { - return ErrLeaseNotFound - } - - l.mu.Lock() - for _, it := range items { - delete(l.itemSet, it) - delete(le.itemMap, it) - } - l.mu.Unlock() - return nil -} - -func (le *lessor) Recover(b backend.Backend, rd RangeDeleter) { - le.mu.Lock() - defer le.mu.Unlock() - - le.b = b - le.rd = rd - le.leaseMap = make(map[LeaseID]*Lease) - le.itemMap = make(map[LeaseItem]LeaseID) - le.initAndRecover() -} - -func (le *lessor) ExpiredLeasesC() <-chan []*Lease { - return le.expiredC -} - -func (le *lessor) Stop() { - close(le.stopC) - <-le.doneC -} - -func (le *lessor) runLoop() { - defer close(le.doneC) - - for { - var ls []*Lease - - // rate limit - revokeLimit := leaseRevokeRate / 2 - - le.mu.Lock() - if le.isPrimary() { - ls = le.findExpiredLeases(revokeLimit) - } - le.mu.Unlock() - - if len(ls) != 0 { - select { - case <-le.stopC: - return - case le.expiredC <- ls: - default: - // the receiver of expiredC is probably busy handling - // other stuff - // let's try this next time after 500ms - } - } - - select { - case <-time.After(500 * time.Millisecond): - case <-le.stopC: - return - } - } -} - -// findExpiredLeases loops leases in the leaseMap until reaching expired limit -// and returns the expired leases that needed to be revoked. -func (le *lessor) findExpiredLeases(limit int) []*Lease { - leases := make([]*Lease, 0, 16) - - for _, l := range le.leaseMap { - // TODO: probably should change to <= 100-500 millisecond to - // make up committing latency. - if l.expired() { - leases = append(leases, l) - - // reach expired limit - if len(leases) == limit { - break - } - } - } - - return leases -} - -func (le *lessor) initAndRecover() { - tx := le.b.BatchTx() - tx.Lock() - - tx.UnsafeCreateBucket(leaseBucketName) - _, vs := tx.UnsafeRange(leaseBucketName, int64ToBytes(0), int64ToBytes(math.MaxInt64), 0) - // TODO: copy vs and do decoding outside tx lock if lock contention becomes an issue. - for i := range vs { - var lpb leasepb.Lease - err := lpb.Unmarshal(vs[i]) - if err != nil { - tx.Unlock() - panic("failed to unmarshal lease proto item") - } - ID := LeaseID(lpb.ID) - if lpb.TTL < le.minLeaseTTL { - lpb.TTL = le.minLeaseTTL - } - le.leaseMap[ID] = &Lease{ - ID: ID, - ttl: lpb.TTL, - // itemSet will be filled in when recover key-value pairs - // set expiry to forever, refresh when promoted - itemSet: make(map[LeaseItem]struct{}), - expiry: forever, - revokec: make(chan struct{}), - } - } - tx.Unlock() - - le.b.ForceCommit() -} - -type Lease struct { - ID LeaseID - ttl int64 // time to live in seconds - // expiryMu protects concurrent accesses to expiry - expiryMu sync.RWMutex - // expiry is time when lease should expire. no expiration when expiry.IsZero() is true - expiry time.Time - - // mu protects concurrent accesses to itemSet - mu sync.RWMutex - itemSet map[LeaseItem]struct{} - revokec chan struct{} -} - -func (l *Lease) expired() bool { - return l.Remaining() <= 0 -} - -func (l *Lease) persistTo(b backend.Backend) { - key := int64ToBytes(int64(l.ID)) - - lpb := leasepb.Lease{ID: int64(l.ID), TTL: int64(l.ttl)} - val, err := lpb.Marshal() - if err != nil { - panic("failed to marshal lease proto item") - } - - b.BatchTx().Lock() - b.BatchTx().UnsafePut(leaseBucketName, key, val) - b.BatchTx().Unlock() -} - -// TTL returns the TTL of the Lease. -func (l *Lease) TTL() int64 { - return l.ttl -} - -// refresh refreshes the expiry of the lease. -func (l *Lease) refresh(extend time.Duration) { - newExpiry := time.Now().Add(extend + time.Duration(l.ttl)*time.Second) - l.expiryMu.Lock() - defer l.expiryMu.Unlock() - l.expiry = newExpiry -} - -// forever sets the expiry of lease to be forever. -func (l *Lease) forever() { - l.expiryMu.Lock() - defer l.expiryMu.Unlock() - l.expiry = forever -} - -// Keys returns all the keys attached to the lease. -func (l *Lease) Keys() []string { - l.mu.RLock() - keys := make([]string, 0, len(l.itemSet)) - for k := range l.itemSet { - keys = append(keys, k.Key) - } - l.mu.RUnlock() - return keys -} - -// Remaining returns the remaining time of the lease. -func (l *Lease) Remaining() time.Duration { - l.expiryMu.RLock() - defer l.expiryMu.RUnlock() - if l.expiry.IsZero() { - return time.Duration(math.MaxInt64) - } - return time.Until(l.expiry) -} - -type LeaseItem struct { - Key string -} - -func int64ToBytes(n int64) []byte { - bytes := make([]byte, 8) - binary.BigEndian.PutUint64(bytes, uint64(n)) - return bytes -} - -// FakeLessor is a fake implementation of Lessor interface. -// Used for testing only. -type FakeLessor struct{} - -func (fl *FakeLessor) SetRangeDeleter(dr RangeDeleter) {} - -func (fl *FakeLessor) Grant(id LeaseID, ttl int64) (*Lease, error) { return nil, nil } - -func (fl *FakeLessor) Revoke(id LeaseID) error { return nil } - -func (fl *FakeLessor) Attach(id LeaseID, items []LeaseItem) error { return nil } - -func (fl *FakeLessor) GetLease(item LeaseItem) LeaseID { return 0 } -func (fl *FakeLessor) Detach(id LeaseID, items []LeaseItem) error { return nil } - -func (fl *FakeLessor) Promote(extend time.Duration) {} - -func (fl *FakeLessor) Demote() {} - -func (fl *FakeLessor) Renew(id LeaseID) (int64, error) { return 10, nil } - -func (fl *FakeLessor) Lookup(id LeaseID) *Lease { return nil } - -func (fl *FakeLessor) Leases() []*Lease { return nil } - -func (fl *FakeLessor) ExpiredLeasesC() <-chan []*Lease { return nil } - -func (fl *FakeLessor) Recover(b backend.Backend, rd RangeDeleter) {} - -func (fl *FakeLessor) Stop() {} diff --git a/vendor/go.etcd.io/etcd/mvcc/backend/backend.go b/vendor/go.etcd.io/etcd/mvcc/backend/backend.go deleted file mode 100644 index f7d9e60c2e7d..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/backend/backend.go +++ /dev/null @@ -1,464 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package backend - -import ( - "fmt" - "hash/crc32" - "io" - "io/ioutil" - "os" - "path/filepath" - "sync" - "sync/atomic" - "time" - - bolt "github.com/coreos/bbolt" - "github.com/coreos/pkg/capnslog" -) - -var ( - defaultBatchLimit = 10000 - defaultBatchInterval = 100 * time.Millisecond - - defragLimit = 10000 - - // initialMmapSize is the initial size of the mmapped region. Setting this larger than - // the potential max db size can prevent writer from blocking reader. - // This only works for linux. - initialMmapSize = uint64(10 * 1024 * 1024 * 1024) - - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "mvcc/backend") - - // minSnapshotWarningTimeout is the minimum threshold to trigger a long running snapshot warning. - minSnapshotWarningTimeout = time.Duration(30 * time.Second) -) - -type Backend interface { - ReadTx() ReadTx - BatchTx() BatchTx - - Snapshot() Snapshot - Hash(ignores map[IgnoreKey]struct{}) (uint32, error) - // Size returns the current size of the backend. - Size() int64 - // SizeInUse returns the current size of the backend logically in use. - // Since the backend can manage free space in a non-byte unit such as - // number of pages, the returned value can be not exactly accurate in bytes. - SizeInUse() int64 - Defrag() error - ForceCommit() - Close() error -} - -type Snapshot interface { - // Size gets the size of the snapshot. - Size() int64 - // WriteTo writes the snapshot into the given writer. - WriteTo(w io.Writer) (n int64, err error) - // Close closes the snapshot. - Close() error -} - -type backend struct { - // size and commits are used with atomic operations so they must be - // 64-bit aligned, otherwise 32-bit tests will crash - - // size is the number of bytes in the backend - size int64 - - // sizeInUse is the number of bytes actually used in the backend - sizeInUse int64 - - // commits counts number of commits since start - commits int64 - - mu sync.RWMutex - db *bolt.DB - - batchInterval time.Duration - batchLimit int - batchTx *batchTxBuffered - - readTx *readTx - - stopc chan struct{} - donec chan struct{} -} - -type BackendConfig struct { - // Path is the file path to the backend file. - Path string - // BatchInterval is the maximum time before flushing the BatchTx. - BatchInterval time.Duration - // BatchLimit is the maximum puts before flushing the BatchTx. - BatchLimit int - // MmapSize is the number of bytes to mmap for the backend. - MmapSize uint64 -} - -func DefaultBackendConfig() BackendConfig { - return BackendConfig{ - BatchInterval: defaultBatchInterval, - BatchLimit: defaultBatchLimit, - MmapSize: initialMmapSize, - } -} - -func New(bcfg BackendConfig) Backend { - return newBackend(bcfg) -} - -func NewDefaultBackend(path string) Backend { - bcfg := DefaultBackendConfig() - bcfg.Path = path - return newBackend(bcfg) -} - -func newBackend(bcfg BackendConfig) *backend { - bopts := &bolt.Options{} - if boltOpenOptions != nil { - *bopts = *boltOpenOptions - } - bopts.InitialMmapSize = bcfg.mmapSize() - - db, err := bolt.Open(bcfg.Path, 0600, bopts) - if err != nil { - plog.Panicf("cannot open database at %s (%v)", bcfg.Path, err) - } - - // In future, may want to make buffering optional for low-concurrency systems - // or dynamically swap between buffered/non-buffered depending on workload. - b := &backend{ - db: db, - - batchInterval: bcfg.BatchInterval, - batchLimit: bcfg.BatchLimit, - - readTx: &readTx{ - buf: txReadBuffer{ - txBuffer: txBuffer{make(map[string]*bucketBuffer)}, - }, - buckets: make(map[string]*bolt.Bucket), - }, - - stopc: make(chan struct{}), - donec: make(chan struct{}), - } - b.batchTx = newBatchTxBuffered(b) - go b.run() - return b -} - -// BatchTx returns the current batch tx in coalescer. The tx can be used for read and -// write operations. The write result can be retrieved within the same tx immediately. -// The write result is isolated with other txs until the current one get committed. -func (b *backend) BatchTx() BatchTx { - return b.batchTx -} - -func (b *backend) ReadTx() ReadTx { return b.readTx } - -// ForceCommit forces the current batching tx to commit. -func (b *backend) ForceCommit() { - b.batchTx.Commit() -} - -func (b *backend) Snapshot() Snapshot { - b.batchTx.Commit() - - b.mu.RLock() - defer b.mu.RUnlock() - tx, err := b.db.Begin(false) - if err != nil { - plog.Fatalf("cannot begin tx (%s)", err) - } - - stopc, donec := make(chan struct{}), make(chan struct{}) - dbBytes := tx.Size() - go func() { - defer close(donec) - // sendRateBytes is based on transferring snapshot data over a 1 gigabit/s connection - // assuming a min tcp throughput of 100MB/s. - var sendRateBytes int64 = 100 * 1024 * 1014 - warningTimeout := time.Duration(int64((float64(dbBytes) / float64(sendRateBytes)) * float64(time.Second))) - if warningTimeout < minSnapshotWarningTimeout { - warningTimeout = minSnapshotWarningTimeout - } - start := time.Now() - ticker := time.NewTicker(warningTimeout) - defer ticker.Stop() - for { - select { - case <-ticker.C: - plog.Warningf("snapshotting is taking more than %v seconds to finish transferring %v MB [started at %v]", time.Since(start).Seconds(), float64(dbBytes)/float64(1024*1014), start) - case <-stopc: - snapshotDurations.Observe(time.Since(start).Seconds()) - return - } - } - }() - - return &snapshot{tx, stopc, donec} -} - -type IgnoreKey struct { - Bucket string - Key string -} - -func (b *backend) Hash(ignores map[IgnoreKey]struct{}) (uint32, error) { - h := crc32.New(crc32.MakeTable(crc32.Castagnoli)) - - b.mu.RLock() - defer b.mu.RUnlock() - err := b.db.View(func(tx *bolt.Tx) error { - c := tx.Cursor() - for next, _ := c.First(); next != nil; next, _ = c.Next() { - b := tx.Bucket(next) - if b == nil { - return fmt.Errorf("cannot get hash of bucket %s", string(next)) - } - h.Write(next) - b.ForEach(func(k, v []byte) error { - bk := IgnoreKey{Bucket: string(next), Key: string(k)} - if _, ok := ignores[bk]; !ok { - h.Write(k) - h.Write(v) - } - return nil - }) - } - return nil - }) - - if err != nil { - return 0, err - } - - return h.Sum32(), nil -} - -func (b *backend) Size() int64 { - return atomic.LoadInt64(&b.size) -} - -func (b *backend) SizeInUse() int64 { - return atomic.LoadInt64(&b.sizeInUse) -} - -func (b *backend) run() { - defer close(b.donec) - t := time.NewTimer(b.batchInterval) - defer t.Stop() - for { - select { - case <-t.C: - case <-b.stopc: - b.batchTx.CommitAndStop() - return - } - b.batchTx.Commit() - t.Reset(b.batchInterval) - } -} - -func (b *backend) Close() error { - close(b.stopc) - <-b.donec - return b.db.Close() -} - -// Commits returns total number of commits since start -func (b *backend) Commits() int64 { - return atomic.LoadInt64(&b.commits) -} - -func (b *backend) Defrag() error { - return b.defrag() -} - -func (b *backend) defrag() error { - now := time.Now() - - // TODO: make this non-blocking? - // lock batchTx to ensure nobody is using previous tx, and then - // close previous ongoing tx. - b.batchTx.Lock() - defer b.batchTx.Unlock() - - // lock database after lock tx to avoid deadlock. - b.mu.Lock() - defer b.mu.Unlock() - - // block concurrent read requests while resetting tx - b.readTx.mu.Lock() - defer b.readTx.mu.Unlock() - - b.batchTx.unsafeCommit(true) - b.batchTx.tx = nil - - tmpdb, err := bolt.Open(b.db.Path()+".tmp", 0600, boltOpenOptions) - if err != nil { - return err - } - - err = defragdb(b.db, tmpdb, defragLimit) - - if err != nil { - tmpdb.Close() - os.RemoveAll(tmpdb.Path()) - return err - } - - dbp := b.db.Path() - tdbp := tmpdb.Path() - - err = b.db.Close() - if err != nil { - plog.Fatalf("cannot close database (%s)", err) - } - err = tmpdb.Close() - if err != nil { - plog.Fatalf("cannot close database (%s)", err) - } - err = os.Rename(tdbp, dbp) - if err != nil { - plog.Fatalf("cannot rename database (%s)", err) - } - - b.db, err = bolt.Open(dbp, 0600, boltOpenOptions) - if err != nil { - plog.Panicf("cannot open database at %s (%v)", dbp, err) - } - b.batchTx.tx, err = b.db.Begin(true) - if err != nil { - plog.Fatalf("cannot begin tx (%s)", err) - } - - b.readTx.reset() - b.readTx.tx = b.unsafeBegin(false) - - size := b.readTx.tx.Size() - db := b.db - atomic.StoreInt64(&b.size, size) - atomic.StoreInt64(&b.sizeInUse, size-(int64(db.Stats().FreePageN)*int64(db.Info().PageSize))) - - took := time.Since(now) - defragDurations.Observe(took.Seconds()) - - return nil -} - -func defragdb(odb, tmpdb *bolt.DB, limit int) error { - // open a tx on tmpdb for writes - tmptx, err := tmpdb.Begin(true) - if err != nil { - return err - } - - // open a tx on old db for read - tx, err := odb.Begin(false) - if err != nil { - return err - } - defer tx.Rollback() - - c := tx.Cursor() - - count := 0 - for next, _ := c.First(); next != nil; next, _ = c.Next() { - b := tx.Bucket(next) - if b == nil { - return fmt.Errorf("backend: cannot defrag bucket %s", string(next)) - } - - tmpb, berr := tmptx.CreateBucketIfNotExists(next) - if berr != nil { - return berr - } - tmpb.FillPercent = 0.9 // for seq write in for each - - b.ForEach(func(k, v []byte) error { - count++ - if count > limit { - err = tmptx.Commit() - if err != nil { - return err - } - tmptx, err = tmpdb.Begin(true) - if err != nil { - return err - } - tmpb = tmptx.Bucket(next) - tmpb.FillPercent = 0.9 // for seq write in for each - - count = 0 - } - return tmpb.Put(k, v) - }) - } - - return tmptx.Commit() -} - -func (b *backend) begin(write bool) *bolt.Tx { - b.mu.RLock() - tx := b.unsafeBegin(write) - b.mu.RUnlock() - - size := tx.Size() - db := tx.DB() - atomic.StoreInt64(&b.size, size) - atomic.StoreInt64(&b.sizeInUse, size-(int64(db.Stats().FreePageN)*int64(db.Info().PageSize))) - - return tx -} - -func (b *backend) unsafeBegin(write bool) *bolt.Tx { - tx, err := b.db.Begin(write) - if err != nil { - plog.Fatalf("cannot begin tx (%s)", err) - } - return tx -} - -// NewTmpBackend creates a backend implementation for testing. -func NewTmpBackend(batchInterval time.Duration, batchLimit int) (*backend, string) { - dir, err := ioutil.TempDir(os.TempDir(), "etcd_backend_test") - if err != nil { - plog.Fatal(err) - } - tmpPath := filepath.Join(dir, "database") - bcfg := DefaultBackendConfig() - bcfg.Path, bcfg.BatchInterval, bcfg.BatchLimit = tmpPath, batchInterval, batchLimit - return newBackend(bcfg), tmpPath -} - -func NewDefaultTmpBackend() (*backend, string) { - return NewTmpBackend(defaultBatchInterval, defaultBatchLimit) -} - -type snapshot struct { - *bolt.Tx - stopc chan struct{} - donec chan struct{} -} - -func (s *snapshot) Close() error { - close(s.stopc) - <-s.donec - return s.Tx.Rollback() -} diff --git a/vendor/go.etcd.io/etcd/mvcc/backend/batch_tx.go b/vendor/go.etcd.io/etcd/mvcc/backend/batch_tx.go deleted file mode 100644 index aed6893e41a1..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/backend/batch_tx.go +++ /dev/null @@ -1,254 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package backend - -import ( - "bytes" - "math" - "sync" - "sync/atomic" - "time" - - bolt "github.com/coreos/bbolt" -) - -type BatchTx interface { - ReadTx - UnsafeCreateBucket(name []byte) - UnsafePut(bucketName []byte, key []byte, value []byte) - UnsafeSeqPut(bucketName []byte, key []byte, value []byte) - UnsafeDelete(bucketName []byte, key []byte) - // Commit commits a previous tx and begins a new writable one. - Commit() - // CommitAndStop commits the previous tx and does not create a new one. - CommitAndStop() -} - -type batchTx struct { - sync.Mutex - tx *bolt.Tx - backend *backend - - pending int -} - -func (t *batchTx) UnsafeCreateBucket(name []byte) { - _, err := t.tx.CreateBucket(name) - if err != nil && err != bolt.ErrBucketExists { - plog.Fatalf("cannot create bucket %s (%v)", name, err) - } - t.pending++ -} - -// UnsafePut must be called holding the lock on the tx. -func (t *batchTx) UnsafePut(bucketName []byte, key []byte, value []byte) { - t.unsafePut(bucketName, key, value, false) -} - -// UnsafeSeqPut must be called holding the lock on the tx. -func (t *batchTx) UnsafeSeqPut(bucketName []byte, key []byte, value []byte) { - t.unsafePut(bucketName, key, value, true) -} - -func (t *batchTx) unsafePut(bucketName []byte, key []byte, value []byte, seq bool) { - bucket := t.tx.Bucket(bucketName) - if bucket == nil { - plog.Fatalf("bucket %s does not exist", bucketName) - } - if seq { - // it is useful to increase fill percent when the workloads are mostly append-only. - // this can delay the page split and reduce space usage. - bucket.FillPercent = 0.9 - } - if err := bucket.Put(key, value); err != nil { - plog.Fatalf("cannot put key into bucket (%v)", err) - } - t.pending++ -} - -// UnsafeRange must be called holding the lock on the tx. -func (t *batchTx) UnsafeRange(bucketName, key, endKey []byte, limit int64) ([][]byte, [][]byte) { - bucket := t.tx.Bucket(bucketName) - if bucket == nil { - plog.Fatalf("bucket %s does not exist", bucketName) - } - return unsafeRange(bucket.Cursor(), key, endKey, limit) -} - -func unsafeRange(c *bolt.Cursor, key, endKey []byte, limit int64) (keys [][]byte, vs [][]byte) { - if limit <= 0 { - limit = math.MaxInt64 - } - var isMatch func(b []byte) bool - if len(endKey) > 0 { - isMatch = func(b []byte) bool { return bytes.Compare(b, endKey) < 0 } - } else { - isMatch = func(b []byte) bool { return bytes.Equal(b, key) } - limit = 1 - } - for ck, cv := c.Seek(key); ck != nil && isMatch(ck); ck, cv = c.Next() { - vs = append(vs, cv) - keys = append(keys, ck) - if limit == int64(len(keys)) { - break - } - } - return keys, vs -} - -// UnsafeDelete must be called holding the lock on the tx. -func (t *batchTx) UnsafeDelete(bucketName []byte, key []byte) { - bucket := t.tx.Bucket(bucketName) - if bucket == nil { - plog.Fatalf("bucket %s does not exist", bucketName) - } - err := bucket.Delete(key) - if err != nil { - plog.Fatalf("cannot delete key from bucket (%v)", err) - } - t.pending++ -} - -// UnsafeForEach must be called holding the lock on the tx. -func (t *batchTx) UnsafeForEach(bucketName []byte, visitor func(k, v []byte) error) error { - return unsafeForEach(t.tx, bucketName, visitor) -} - -func unsafeForEach(tx *bolt.Tx, bucket []byte, visitor func(k, v []byte) error) error { - if b := tx.Bucket(bucket); b != nil { - return b.ForEach(visitor) - } - return nil -} - -// Commit commits a previous tx and begins a new writable one. -func (t *batchTx) Commit() { - t.Lock() - t.commit(false) - t.Unlock() -} - -// CommitAndStop commits the previous tx and does not create a new one. -func (t *batchTx) CommitAndStop() { - t.Lock() - t.commit(true) - t.Unlock() -} - -func (t *batchTx) Unlock() { - if t.pending >= t.backend.batchLimit { - t.commit(false) - } - t.Mutex.Unlock() -} - -func (t *batchTx) commit(stop bool) { - // commit the last tx - if t.tx != nil { - if t.pending == 0 && !stop { - return - } - - start := time.Now() - - // gofail: var beforeCommit struct{} - err := t.tx.Commit() - // gofail: var afterCommit struct{} - - commitDurations.Observe(time.Since(start).Seconds()) - atomic.AddInt64(&t.backend.commits, 1) - - t.pending = 0 - if err != nil { - plog.Fatalf("cannot commit tx (%s)", err) - } - } - if !stop { - t.tx = t.backend.begin(true) - } -} - -type batchTxBuffered struct { - batchTx - buf txWriteBuffer -} - -func newBatchTxBuffered(backend *backend) *batchTxBuffered { - tx := &batchTxBuffered{ - batchTx: batchTx{backend: backend}, - buf: txWriteBuffer{ - txBuffer: txBuffer{make(map[string]*bucketBuffer)}, - seq: true, - }, - } - tx.Commit() - return tx -} - -func (t *batchTxBuffered) Unlock() { - if t.pending != 0 { - t.backend.readTx.mu.Lock() - t.buf.writeback(&t.backend.readTx.buf) - t.backend.readTx.mu.Unlock() - if t.pending >= t.backend.batchLimit { - t.commit(false) - } - } - t.batchTx.Unlock() -} - -func (t *batchTxBuffered) Commit() { - t.Lock() - t.commit(false) - t.Unlock() -} - -func (t *batchTxBuffered) CommitAndStop() { - t.Lock() - t.commit(true) - t.Unlock() -} - -func (t *batchTxBuffered) commit(stop bool) { - // all read txs must be closed to acquire boltdb commit rwlock - t.backend.readTx.mu.Lock() - t.unsafeCommit(stop) - t.backend.readTx.mu.Unlock() -} - -func (t *batchTxBuffered) unsafeCommit(stop bool) { - if t.backend.readTx.tx != nil { - if err := t.backend.readTx.tx.Rollback(); err != nil { - plog.Fatalf("cannot rollback tx (%s)", err) - } - t.backend.readTx.reset() - } - - t.batchTx.commit(stop) - - if !stop { - t.backend.readTx.tx = t.backend.begin(false) - } -} - -func (t *batchTxBuffered) UnsafePut(bucketName []byte, key []byte, value []byte) { - t.batchTx.UnsafePut(bucketName, key, value) - t.buf.put(bucketName, key, value) -} - -func (t *batchTxBuffered) UnsafeSeqPut(bucketName []byte, key []byte, value []byte) { - t.batchTx.UnsafeSeqPut(bucketName, key, value) - t.buf.putSeq(bucketName, key, value) -} diff --git a/vendor/go.etcd.io/etcd/mvcc/backend/config_default.go b/vendor/go.etcd.io/etcd/mvcc/backend/config_default.go deleted file mode 100644 index edfed0025c6c..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/backend/config_default.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !linux,!windows - -package backend - -import bolt "github.com/coreos/bbolt" - -var boltOpenOptions *bolt.Options = nil - -func (bcfg *BackendConfig) mmapSize() int { return int(bcfg.MmapSize) } diff --git a/vendor/go.etcd.io/etcd/mvcc/backend/config_linux.go b/vendor/go.etcd.io/etcd/mvcc/backend/config_linux.go deleted file mode 100644 index b01785f3b339..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/backend/config_linux.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package backend - -import ( - "syscall" - - bolt "github.com/coreos/bbolt" -) - -// syscall.MAP_POPULATE on linux 2.6.23+ does sequential read-ahead -// which can speed up entire-database read with boltdb. We want to -// enable MAP_POPULATE for faster key-value store recovery in storage -// package. If your kernel version is lower than 2.6.23 -// (https://github.com/torvalds/linux/releases/tag/v2.6.23), mmap might -// silently ignore this flag. Please update your kernel to prevent this. -var boltOpenOptions = &bolt.Options{ - MmapFlags: syscall.MAP_POPULATE, - NoFreelistSync: true, -} - -func (bcfg *BackendConfig) mmapSize() int { return int(bcfg.MmapSize) } diff --git a/vendor/go.etcd.io/etcd/mvcc/backend/config_windows.go b/vendor/go.etcd.io/etcd/mvcc/backend/config_windows.go deleted file mode 100644 index 71d02700bcdc..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/backend/config_windows.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build windows - -package backend - -import bolt "github.com/coreos/bbolt" - -var boltOpenOptions *bolt.Options = nil - -// setting mmap size != 0 on windows will allocate the entire -// mmap size for the file, instead of growing it. So, force 0. - -func (bcfg *BackendConfig) mmapSize() int { return 0 } diff --git a/vendor/go.etcd.io/etcd/mvcc/backend/doc.go b/vendor/go.etcd.io/etcd/mvcc/backend/doc.go deleted file mode 100644 index 9cc42fa793cb..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/backend/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package backend defines a standard interface for etcd's backend MVCC storage. -package backend diff --git a/vendor/go.etcd.io/etcd/mvcc/backend/metrics.go b/vendor/go.etcd.io/etcd/mvcc/backend/metrics.go deleted file mode 100644 index 34157080499b..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/backend/metrics.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package backend - -import "github.com/prometheus/client_golang/prometheus" - -var ( - commitDurations = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "disk", - Name: "backend_commit_duration_seconds", - Help: "The latency distributions of commit called by backend.", - - // lowest bucket start of upper bound 0.001 sec (1 ms) with factor 2 - // highest bucket start of 0.001 sec * 2^13 == 8.192 sec - Buckets: prometheus.ExponentialBuckets(0.001, 2, 14), - }) - - defragDurations = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "disk", - Name: "backend_defrag_duration_seconds", - Help: "The latency distribution of backend defragmentation.", - - // 100 MB usually takes 1 sec, so start with 10 MB of 100 ms - // lowest bucket start of upper bound 0.1 sec (100 ms) with factor 2 - // highest bucket start of 0.1 sec * 2^12 == 409.6 sec - Buckets: prometheus.ExponentialBuckets(.1, 2, 13), - }) - - snapshotDurations = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "disk", - Name: "backend_snapshot_duration_seconds", - Help: "The latency distribution of backend snapshots.", - - // lowest bucket start of upper bound 0.01 sec (10 ms) with factor 2 - // highest bucket start of 0.01 sec * 2^16 == 655.36 sec - Buckets: prometheus.ExponentialBuckets(.01, 2, 17), - }) -) - -func init() { - prometheus.MustRegister(commitDurations) - prometheus.MustRegister(defragDurations) - prometheus.MustRegister(snapshotDurations) -} diff --git a/vendor/go.etcd.io/etcd/mvcc/backend/read_tx.go b/vendor/go.etcd.io/etcd/mvcc/backend/read_tx.go deleted file mode 100644 index 0536de70e2bf..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/backend/read_tx.go +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package backend - -import ( - "bytes" - "math" - "sync" - - bolt "github.com/coreos/bbolt" -) - -// safeRangeBucket is a hack to avoid inadvertently reading duplicate keys; -// overwrites on a bucket should only fetch with limit=1, but safeRangeBucket -// is known to never overwrite any key so range is safe. -var safeRangeBucket = []byte("key") - -type ReadTx interface { - Lock() - Unlock() - - UnsafeRange(bucketName []byte, key, endKey []byte, limit int64) (keys [][]byte, vals [][]byte) - UnsafeForEach(bucketName []byte, visitor func(k, v []byte) error) error -} - -type readTx struct { - // mu protects accesses to the txReadBuffer - mu sync.RWMutex - buf txReadBuffer - - // txmu protects accesses to buckets and tx on Range requests. - txmu sync.RWMutex - tx *bolt.Tx - buckets map[string]*bolt.Bucket -} - -func (rt *readTx) Lock() { rt.mu.RLock() } -func (rt *readTx) Unlock() { rt.mu.RUnlock() } - -func (rt *readTx) UnsafeRange(bucketName, key, endKey []byte, limit int64) ([][]byte, [][]byte) { - if endKey == nil { - // forbid duplicates for single keys - limit = 1 - } - if limit <= 0 { - limit = math.MaxInt64 - } - if limit > 1 && !bytes.Equal(bucketName, safeRangeBucket) { - panic("do not use unsafeRange on non-keys bucket") - } - keys, vals := rt.buf.Range(bucketName, key, endKey, limit) - if int64(len(keys)) == limit { - return keys, vals - } - - // find/cache bucket - bn := string(bucketName) - rt.txmu.RLock() - bucket, ok := rt.buckets[bn] - rt.txmu.RUnlock() - if !ok { - rt.txmu.Lock() - bucket = rt.tx.Bucket(bucketName) - rt.buckets[bn] = bucket - rt.txmu.Unlock() - } - - // ignore missing bucket since may have been created in this batch - if bucket == nil { - return keys, vals - } - rt.txmu.Lock() - c := bucket.Cursor() - rt.txmu.Unlock() - - k2, v2 := unsafeRange(c, key, endKey, limit-int64(len(keys))) - return append(k2, keys...), append(v2, vals...) -} - -func (rt *readTx) UnsafeForEach(bucketName []byte, visitor func(k, v []byte) error) error { - dups := make(map[string]struct{}) - getDups := func(k, v []byte) error { - dups[string(k)] = struct{}{} - return nil - } - visitNoDup := func(k, v []byte) error { - if _, ok := dups[string(k)]; ok { - return nil - } - return visitor(k, v) - } - if err := rt.buf.ForEach(bucketName, getDups); err != nil { - return err - } - rt.txmu.Lock() - err := unsafeForEach(rt.tx, bucketName, visitNoDup) - rt.txmu.Unlock() - if err != nil { - return err - } - return rt.buf.ForEach(bucketName, visitor) -} - -func (rt *readTx) reset() { - rt.buf.reset() - rt.buckets = make(map[string]*bolt.Bucket) - rt.tx = nil -} diff --git a/vendor/go.etcd.io/etcd/mvcc/backend/tx_buffer.go b/vendor/go.etcd.io/etcd/mvcc/backend/tx_buffer.go deleted file mode 100644 index 56e885dbfbc3..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/backend/tx_buffer.go +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package backend - -import ( - "bytes" - "sort" -) - -// txBuffer handles functionality shared between txWriteBuffer and txReadBuffer. -type txBuffer struct { - buckets map[string]*bucketBuffer -} - -func (txb *txBuffer) reset() { - for k, v := range txb.buckets { - if v.used == 0 { - // demote - delete(txb.buckets, k) - } - v.used = 0 - } -} - -// txWriteBuffer buffers writes of pending updates that have not yet committed. -type txWriteBuffer struct { - txBuffer - seq bool -} - -func (txw *txWriteBuffer) put(bucket, k, v []byte) { - txw.seq = false - txw.putSeq(bucket, k, v) -} - -func (txw *txWriteBuffer) putSeq(bucket, k, v []byte) { - b, ok := txw.buckets[string(bucket)] - if !ok { - b = newBucketBuffer() - txw.buckets[string(bucket)] = b - } - b.add(k, v) -} - -func (txw *txWriteBuffer) writeback(txr *txReadBuffer) { - for k, wb := range txw.buckets { - rb, ok := txr.buckets[k] - if !ok { - delete(txw.buckets, k) - txr.buckets[k] = wb - continue - } - if !txw.seq && wb.used > 1 { - // assume no duplicate keys - sort.Sort(wb) - } - rb.merge(wb) - } - txw.reset() -} - -// txReadBuffer accesses buffered updates. -type txReadBuffer struct{ txBuffer } - -func (txr *txReadBuffer) Range(bucketName, key, endKey []byte, limit int64) ([][]byte, [][]byte) { - if b := txr.buckets[string(bucketName)]; b != nil { - return b.Range(key, endKey, limit) - } - return nil, nil -} - -func (txr *txReadBuffer) ForEach(bucketName []byte, visitor func(k, v []byte) error) error { - if b := txr.buckets[string(bucketName)]; b != nil { - return b.ForEach(visitor) - } - return nil -} - -type kv struct { - key []byte - val []byte -} - -// bucketBuffer buffers key-value pairs that are pending commit. -type bucketBuffer struct { - buf []kv - // used tracks number of elements in use so buf can be reused without reallocation. - used int -} - -func newBucketBuffer() *bucketBuffer { - return &bucketBuffer{buf: make([]kv, 512), used: 0} -} - -func (bb *bucketBuffer) Range(key, endKey []byte, limit int64) (keys [][]byte, vals [][]byte) { - f := func(i int) bool { return bytes.Compare(bb.buf[i].key, key) >= 0 } - idx := sort.Search(bb.used, f) - if idx < 0 { - return nil, nil - } - if len(endKey) == 0 { - if bytes.Equal(key, bb.buf[idx].key) { - keys = append(keys, bb.buf[idx].key) - vals = append(vals, bb.buf[idx].val) - } - return keys, vals - } - if bytes.Compare(endKey, bb.buf[idx].key) <= 0 { - return nil, nil - } - for i := idx; i < bb.used && int64(len(keys)) < limit; i++ { - if bytes.Compare(endKey, bb.buf[i].key) <= 0 { - break - } - keys = append(keys, bb.buf[i].key) - vals = append(vals, bb.buf[i].val) - } - return keys, vals -} - -func (bb *bucketBuffer) ForEach(visitor func(k, v []byte) error) error { - for i := 0; i < bb.used; i++ { - if err := visitor(bb.buf[i].key, bb.buf[i].val); err != nil { - return err - } - } - return nil -} - -func (bb *bucketBuffer) add(k, v []byte) { - bb.buf[bb.used].key, bb.buf[bb.used].val = k, v - bb.used++ - if bb.used == len(bb.buf) { - buf := make([]kv, (3*len(bb.buf))/2) - copy(buf, bb.buf) - bb.buf = buf - } -} - -// merge merges data from bb into bbsrc. -func (bb *bucketBuffer) merge(bbsrc *bucketBuffer) { - for i := 0; i < bbsrc.used; i++ { - bb.add(bbsrc.buf[i].key, bbsrc.buf[i].val) - } - if bb.used == bbsrc.used { - return - } - if bytes.Compare(bb.buf[(bb.used-bbsrc.used)-1].key, bbsrc.buf[0].key) < 0 { - return - } - - sort.Stable(bb) - - // remove duplicates, using only newest update - widx := 0 - for ridx := 1; ridx < bb.used; ridx++ { - if !bytes.Equal(bb.buf[ridx].key, bb.buf[widx].key) { - widx++ - } - bb.buf[widx] = bb.buf[ridx] - } - bb.used = widx + 1 -} - -func (bb *bucketBuffer) Len() int { return bb.used } -func (bb *bucketBuffer) Less(i, j int) bool { - return bytes.Compare(bb.buf[i].key, bb.buf[j].key) < 0 -} -func (bb *bucketBuffer) Swap(i, j int) { bb.buf[i], bb.buf[j] = bb.buf[j], bb.buf[i] } diff --git a/vendor/go.etcd.io/etcd/mvcc/doc.go b/vendor/go.etcd.io/etcd/mvcc/doc.go deleted file mode 100644 index ad5be03086fb..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package mvcc defines etcd's stable MVCC storage. -package mvcc diff --git a/vendor/go.etcd.io/etcd/mvcc/index.go b/vendor/go.etcd.io/etcd/mvcc/index.go deleted file mode 100644 index b27a9e543395..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/index.go +++ /dev/null @@ -1,251 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "sort" - "sync" - - "github.com/google/btree" -) - -type index interface { - Get(key []byte, atRev int64) (rev, created revision, ver int64, err error) - Range(key, end []byte, atRev int64) ([][]byte, []revision) - Revisions(key, end []byte, atRev int64) []revision - Put(key []byte, rev revision) - Tombstone(key []byte, rev revision) error - RangeSince(key, end []byte, rev int64) []revision - Compact(rev int64) map[revision]struct{} - Keep(rev int64) map[revision]struct{} - Equal(b index) bool - - Insert(ki *keyIndex) - KeyIndex(ki *keyIndex) *keyIndex -} - -type treeIndex struct { - sync.RWMutex - tree *btree.BTree -} - -func newTreeIndex() index { - return &treeIndex{ - tree: btree.New(32), - } -} - -func (ti *treeIndex) Put(key []byte, rev revision) { - keyi := &keyIndex{key: key} - - ti.Lock() - defer ti.Unlock() - item := ti.tree.Get(keyi) - if item == nil { - keyi.put(rev.main, rev.sub) - ti.tree.ReplaceOrInsert(keyi) - return - } - okeyi := item.(*keyIndex) - okeyi.put(rev.main, rev.sub) -} - -func (ti *treeIndex) Get(key []byte, atRev int64) (modified, created revision, ver int64, err error) { - keyi := &keyIndex{key: key} - ti.RLock() - defer ti.RUnlock() - if keyi = ti.keyIndex(keyi); keyi == nil { - return revision{}, revision{}, 0, ErrRevisionNotFound - } - return keyi.get(atRev) -} - -func (ti *treeIndex) KeyIndex(keyi *keyIndex) *keyIndex { - ti.RLock() - defer ti.RUnlock() - return ti.keyIndex(keyi) -} - -func (ti *treeIndex) keyIndex(keyi *keyIndex) *keyIndex { - if item := ti.tree.Get(keyi); item != nil { - return item.(*keyIndex) - } - return nil -} - -func (ti *treeIndex) visit(key, end []byte, f func(ki *keyIndex)) { - keyi, endi := &keyIndex{key: key}, &keyIndex{key: end} - - ti.RLock() - defer ti.RUnlock() - - ti.tree.AscendGreaterOrEqual(keyi, func(item btree.Item) bool { - if len(endi.key) > 0 && !item.Less(endi) { - return false - } - f(item.(*keyIndex)) - return true - }) -} - -func (ti *treeIndex) Revisions(key, end []byte, atRev int64) (revs []revision) { - if end == nil { - rev, _, _, err := ti.Get(key, atRev) - if err != nil { - return nil - } - return []revision{rev} - } - ti.visit(key, end, func(ki *keyIndex) { - if rev, _, _, err := ki.get(atRev); err == nil { - revs = append(revs, rev) - } - }) - return revs -} - -func (ti *treeIndex) Range(key, end []byte, atRev int64) (keys [][]byte, revs []revision) { - if end == nil { - rev, _, _, err := ti.Get(key, atRev) - if err != nil { - return nil, nil - } - return [][]byte{key}, []revision{rev} - } - ti.visit(key, end, func(ki *keyIndex) { - if rev, _, _, err := ki.get(atRev); err == nil { - revs = append(revs, rev) - keys = append(keys, ki.key) - } - }) - return keys, revs -} - -func (ti *treeIndex) Tombstone(key []byte, rev revision) error { - keyi := &keyIndex{key: key} - - ti.Lock() - defer ti.Unlock() - item := ti.tree.Get(keyi) - if item == nil { - return ErrRevisionNotFound - } - - ki := item.(*keyIndex) - return ki.tombstone(rev.main, rev.sub) -} - -// RangeSince returns all revisions from key(including) to end(excluding) -// at or after the given rev. The returned slice is sorted in the order -// of revision. -func (ti *treeIndex) RangeSince(key, end []byte, rev int64) []revision { - keyi := &keyIndex{key: key} - - ti.RLock() - defer ti.RUnlock() - - if end == nil { - item := ti.tree.Get(keyi) - if item == nil { - return nil - } - keyi = item.(*keyIndex) - return keyi.since(rev) - } - - endi := &keyIndex{key: end} - var revs []revision - ti.tree.AscendGreaterOrEqual(keyi, func(item btree.Item) bool { - if len(endi.key) > 0 && !item.Less(endi) { - return false - } - curKeyi := item.(*keyIndex) - revs = append(revs, curKeyi.since(rev)...) - return true - }) - sort.Sort(revisions(revs)) - - return revs -} - -func (ti *treeIndex) Compact(rev int64) map[revision]struct{} { - available := make(map[revision]struct{}) - var emptyki []*keyIndex - plog.Printf("store.index: compact %d", rev) - // TODO: do not hold the lock for long time? - // This is probably OK. Compacting 10M keys takes O(10ms). - ti.Lock() - defer ti.Unlock() - ti.tree.Ascend(compactIndex(rev, available, &emptyki)) - for _, ki := range emptyki { - item := ti.tree.Delete(ki) - if item == nil { - plog.Panic("store.index: unexpected delete failure during compaction") - } - } - return available -} - -// Keep finds all revisions to be kept for a Compaction at the given rev. -func (ti *treeIndex) Keep(rev int64) map[revision]struct{} { - available := make(map[revision]struct{}) - ti.RLock() - defer ti.RUnlock() - ti.tree.Ascend(func(i btree.Item) bool { - keyi := i.(*keyIndex) - keyi.keep(rev, available) - return true - }) - return available -} - -func compactIndex(rev int64, available map[revision]struct{}, emptyki *[]*keyIndex) func(i btree.Item) bool { - return func(i btree.Item) bool { - keyi := i.(*keyIndex) - keyi.compact(rev, available) - if keyi.isEmpty() { - *emptyki = append(*emptyki, keyi) - } - return true - } -} - -func (ti *treeIndex) Equal(bi index) bool { - b := bi.(*treeIndex) - - if ti.tree.Len() != b.tree.Len() { - return false - } - - equal := true - - ti.tree.Ascend(func(item btree.Item) bool { - aki := item.(*keyIndex) - bki := b.tree.Get(item).(*keyIndex) - if !aki.equal(bki) { - equal = false - return false - } - return true - }) - - return equal -} - -func (ti *treeIndex) Insert(ki *keyIndex) { - ti.Lock() - defer ti.Unlock() - ti.tree.ReplaceOrInsert(ki) -} diff --git a/vendor/go.etcd.io/etcd/mvcc/key_index.go b/vendor/go.etcd.io/etcd/mvcc/key_index.go deleted file mode 100644 index 805922bfc9a3..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/key_index.go +++ /dev/null @@ -1,356 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "bytes" - "errors" - "fmt" - - "github.com/google/btree" -) - -var ( - ErrRevisionNotFound = errors.New("mvcc: revision not found") -) - -// keyIndex stores the revisions of a key in the backend. -// Each keyIndex has at least one key generation. -// Each generation might have several key versions. -// Tombstone on a key appends an tombstone version at the end -// of the current generation and creates a new empty generation. -// Each version of a key has an index pointing to the backend. -// -// For example: put(1.0);put(2.0);tombstone(3.0);put(4.0);tombstone(5.0) on key "foo" -// generate a keyIndex: -// key: "foo" -// rev: 5 -// generations: -// {empty} -// {4.0, 5.0(t)} -// {1.0, 2.0, 3.0(t)} -// -// Compact a keyIndex removes the versions with smaller or equal to -// rev except the largest one. If the generation becomes empty -// during compaction, it will be removed. if all the generations get -// removed, the keyIndex should be removed. -// -// For example: -// compact(2) on the previous example -// generations: -// {empty} -// {4.0, 5.0(t)} -// {2.0, 3.0(t)} -// -// compact(4) -// generations: -// {empty} -// {4.0, 5.0(t)} -// -// compact(5): -// generations: -// {empty} -> key SHOULD be removed. -// -// compact(6): -// generations: -// {empty} -> key SHOULD be removed. -type keyIndex struct { - key []byte - modified revision // the main rev of the last modification - generations []generation -} - -// put puts a revision to the keyIndex. -func (ki *keyIndex) put(main int64, sub int64) { - rev := revision{main: main, sub: sub} - - if !rev.GreaterThan(ki.modified) { - plog.Panicf("store.keyindex: put with unexpected smaller revision [%v / %v]", rev, ki.modified) - } - if len(ki.generations) == 0 { - ki.generations = append(ki.generations, generation{}) - } - g := &ki.generations[len(ki.generations)-1] - if len(g.revs) == 0 { // create a new key - keysGauge.Inc() - g.created = rev - } - g.revs = append(g.revs, rev) - g.ver++ - ki.modified = rev -} - -func (ki *keyIndex) restore(created, modified revision, ver int64) { - if len(ki.generations) != 0 { - plog.Panicf("store.keyindex: cannot restore non-empty keyIndex") - } - - ki.modified = modified - g := generation{created: created, ver: ver, revs: []revision{modified}} - ki.generations = append(ki.generations, g) - keysGauge.Inc() -} - -// tombstone puts a revision, pointing to a tombstone, to the keyIndex. -// It also creates a new empty generation in the keyIndex. -// It returns ErrRevisionNotFound when tombstone on an empty generation. -func (ki *keyIndex) tombstone(main int64, sub int64) error { - if ki.isEmpty() { - plog.Panicf("store.keyindex: unexpected tombstone on empty keyIndex %s", string(ki.key)) - } - if ki.generations[len(ki.generations)-1].isEmpty() { - return ErrRevisionNotFound - } - ki.put(main, sub) - ki.generations = append(ki.generations, generation{}) - keysGauge.Dec() - return nil -} - -// get gets the modified, created revision and version of the key that satisfies the given atRev. -// Rev must be higher than or equal to the given atRev. -func (ki *keyIndex) get(atRev int64) (modified, created revision, ver int64, err error) { - if ki.isEmpty() { - plog.Panicf("store.keyindex: unexpected get on empty keyIndex %s", string(ki.key)) - } - g := ki.findGeneration(atRev) - if g.isEmpty() { - return revision{}, revision{}, 0, ErrRevisionNotFound - } - - n := g.walk(func(rev revision) bool { return rev.main > atRev }) - if n != -1 { - return g.revs[n], g.created, g.ver - int64(len(g.revs)-n-1), nil - } - - return revision{}, revision{}, 0, ErrRevisionNotFound -} - -// since returns revisions since the given rev. Only the revision with the -// largest sub revision will be returned if multiple revisions have the same -// main revision. -func (ki *keyIndex) since(rev int64) []revision { - if ki.isEmpty() { - plog.Panicf("store.keyindex: unexpected get on empty keyIndex %s", string(ki.key)) - } - since := revision{rev, 0} - var gi int - // find the generations to start checking - for gi = len(ki.generations) - 1; gi > 0; gi-- { - g := ki.generations[gi] - if g.isEmpty() { - continue - } - if since.GreaterThan(g.created) { - break - } - } - - var revs []revision - var last int64 - for ; gi < len(ki.generations); gi++ { - for _, r := range ki.generations[gi].revs { - if since.GreaterThan(r) { - continue - } - if r.main == last { - // replace the revision with a new one that has higher sub value, - // because the original one should not be seen by external - revs[len(revs)-1] = r - continue - } - revs = append(revs, r) - last = r.main - } - } - return revs -} - -// compact compacts a keyIndex by removing the versions with smaller or equal -// revision than the given atRev except the largest one (If the largest one is -// a tombstone, it will not be kept). -// If a generation becomes empty during compaction, it will be removed. -func (ki *keyIndex) compact(atRev int64, available map[revision]struct{}) { - if ki.isEmpty() { - plog.Panicf("store.keyindex: unexpected compact on empty keyIndex %s", string(ki.key)) - } - - genIdx, revIndex := ki.doCompact(atRev, available) - - g := &ki.generations[genIdx] - if !g.isEmpty() { - // remove the previous contents. - if revIndex != -1 { - g.revs = g.revs[revIndex:] - } - // remove any tombstone - if len(g.revs) == 1 && genIdx != len(ki.generations)-1 { - delete(available, g.revs[0]) - genIdx++ - } - } - - // remove the previous generations. - ki.generations = ki.generations[genIdx:] -} - -// keep finds the revision to be kept if compact is called at given atRev. -func (ki *keyIndex) keep(atRev int64, available map[revision]struct{}) { - if ki.isEmpty() { - return - } - - genIdx, revIndex := ki.doCompact(atRev, available) - g := &ki.generations[genIdx] - if !g.isEmpty() { - // remove any tombstone - if revIndex == len(g.revs)-1 && genIdx != len(ki.generations)-1 { - delete(available, g.revs[revIndex]) - } - } -} - -func (ki *keyIndex) doCompact(atRev int64, available map[revision]struct{}) (genIdx int, revIndex int) { - // walk until reaching the first revision smaller or equal to "atRev", - // and add the revision to the available map - f := func(rev revision) bool { - if rev.main <= atRev { - available[rev] = struct{}{} - return false - } - return true - } - - genIdx, g := 0, &ki.generations[0] - // find first generation includes atRev or created after atRev - for genIdx < len(ki.generations)-1 { - if tomb := g.revs[len(g.revs)-1].main; tomb > atRev { - break - } - genIdx++ - g = &ki.generations[genIdx] - } - - revIndex = g.walk(f) - - return genIdx, revIndex -} - -func (ki *keyIndex) isEmpty() bool { - return len(ki.generations) == 1 && ki.generations[0].isEmpty() -} - -// findGeneration finds out the generation of the keyIndex that the -// given rev belongs to. If the given rev is at the gap of two generations, -// which means that the key does not exist at the given rev, it returns nil. -func (ki *keyIndex) findGeneration(rev int64) *generation { - lastg := len(ki.generations) - 1 - cg := lastg - - for cg >= 0 { - if len(ki.generations[cg].revs) == 0 { - cg-- - continue - } - g := ki.generations[cg] - if cg != lastg { - if tomb := g.revs[len(g.revs)-1].main; tomb <= rev { - return nil - } - } - if g.revs[0].main <= rev { - return &ki.generations[cg] - } - cg-- - } - return nil -} - -func (a *keyIndex) Less(b btree.Item) bool { - return bytes.Compare(a.key, b.(*keyIndex).key) == -1 -} - -func (a *keyIndex) equal(b *keyIndex) bool { - if !bytes.Equal(a.key, b.key) { - return false - } - if a.modified != b.modified { - return false - } - if len(a.generations) != len(b.generations) { - return false - } - for i := range a.generations { - ag, bg := a.generations[i], b.generations[i] - if !ag.equal(bg) { - return false - } - } - return true -} - -func (ki *keyIndex) String() string { - var s string - for _, g := range ki.generations { - s += g.String() - } - return s -} - -// generation contains multiple revisions of a key. -type generation struct { - ver int64 - created revision // when the generation is created (put in first revision). - revs []revision -} - -func (g *generation) isEmpty() bool { return g == nil || len(g.revs) == 0 } - -// walk walks through the revisions in the generation in descending order. -// It passes the revision to the given function. -// walk returns until: 1. it finishes walking all pairs 2. the function returns false. -// walk returns the position at where it stopped. If it stopped after -// finishing walking, -1 will be returned. -func (g *generation) walk(f func(rev revision) bool) int { - l := len(g.revs) - for i := range g.revs { - ok := f(g.revs[l-i-1]) - if !ok { - return l - i - 1 - } - } - return -1 -} - -func (g *generation) String() string { - return fmt.Sprintf("g: created[%d] ver[%d], revs %#v\n", g.created, g.ver, g.revs) -} - -func (a generation) equal(b generation) bool { - if a.ver != b.ver { - return false - } - if len(a.revs) != len(b.revs) { - return false - } - - for i := range a.revs { - ar, br := a.revs[i], b.revs[i] - if ar != br { - return false - } - } - return true -} diff --git a/vendor/go.etcd.io/etcd/mvcc/kv.go b/vendor/go.etcd.io/etcd/mvcc/kv.go deleted file mode 100644 index 2dad3ad8ef0a..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/kv.go +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -type RangeOptions struct { - Limit int64 - Rev int64 - Count bool -} - -type RangeResult struct { - KVs []mvccpb.KeyValue - Rev int64 - Count int -} - -type ReadView interface { - // FirstRev returns the first KV revision at the time of opening the txn. - // After a compaction, the first revision increases to the compaction - // revision. - FirstRev() int64 - - // Rev returns the revision of the KV at the time of opening the txn. - Rev() int64 - - // Range gets the keys in the range at rangeRev. - // The returned rev is the current revision of the KV when the operation is executed. - // If rangeRev <=0, range gets the keys at currentRev. - // If `end` is nil, the request returns the key. - // If `end` is not nil and not empty, it gets the keys in range [key, range_end). - // If `end` is not nil and empty, it gets the keys greater than or equal to key. - // Limit limits the number of keys returned. - // If the required rev is compacted, ErrCompacted will be returned. - Range(key, end []byte, ro RangeOptions) (r *RangeResult, err error) -} - -// TxnRead represents a read-only transaction with operations that will not -// block other read transactions. -type TxnRead interface { - ReadView - // End marks the transaction is complete and ready to commit. - End() -} - -type WriteView interface { - // DeleteRange deletes the given range from the store. - // A deleteRange increases the rev of the store if any key in the range exists. - // The number of key deleted will be returned. - // The returned rev is the current revision of the KV when the operation is executed. - // It also generates one event for each key delete in the event history. - // if the `end` is nil, deleteRange deletes the key. - // if the `end` is not nil, deleteRange deletes the keys in range [key, range_end). - DeleteRange(key, end []byte) (n, rev int64) - - // Put puts the given key, value into the store. Put also takes additional argument lease to - // attach a lease to a key-value pair as meta-data. KV implementation does not validate the lease - // id. - // A put also increases the rev of the store, and generates one event in the event history. - // The returned rev is the current revision of the KV when the operation is executed. - Put(key, value []byte, lease lease.LeaseID) (rev int64) -} - -// TxnWrite represents a transaction that can modify the store. -type TxnWrite interface { - TxnRead - WriteView - // Changes gets the changes made since opening the write txn. - Changes() []mvccpb.KeyValue -} - -// txnReadWrite coerces a read txn to a write, panicking on any write operation. -type txnReadWrite struct{ TxnRead } - -func (trw *txnReadWrite) DeleteRange(key, end []byte) (n, rev int64) { panic("unexpected DeleteRange") } -func (trw *txnReadWrite) Put(key, value []byte, lease lease.LeaseID) (rev int64) { - panic("unexpected Put") -} -func (trw *txnReadWrite) Changes() []mvccpb.KeyValue { return nil } - -func NewReadOnlyTxnWrite(txn TxnRead) TxnWrite { return &txnReadWrite{txn} } - -type KV interface { - ReadView - WriteView - - // Read creates a read transaction. - Read() TxnRead - - // Write creates a write transaction. - Write() TxnWrite - - // Hash computes the hash of the KV's backend. - Hash() (hash uint32, revision int64, err error) - - // HashByRev computes the hash of all MVCC revisions up to a given revision. - HashByRev(rev int64) (hash uint32, revision int64, compactRev int64, err error) - - // Compact frees all superseded keys with revisions less than rev. - Compact(rev int64) (<-chan struct{}, error) - - // Commit commits outstanding txns into the underlying backend. - Commit() - - // Restore restores the KV store from a backend. - Restore(b backend.Backend) error - Close() error -} - -// WatchableKV is a KV that can be watched. -type WatchableKV interface { - KV - Watchable -} - -// Watchable is the interface that wraps the NewWatchStream function. -type Watchable interface { - // NewWatchStream returns a WatchStream that can be used to - // watch events happened or happening on the KV. - NewWatchStream() WatchStream -} - -// ConsistentWatchableKV is a WatchableKV that understands the consistency -// algorithm and consistent index. -// If the consistent index of executing entry is not larger than the -// consistent index of ConsistentWatchableKV, all operations in -// this entry are skipped and return empty response. -type ConsistentWatchableKV interface { - WatchableKV - // ConsistentIndex returns the current consistent index of the KV. - ConsistentIndex() uint64 -} diff --git a/vendor/go.etcd.io/etcd/mvcc/kv_view.go b/vendor/go.etcd.io/etcd/mvcc/kv_view.go deleted file mode 100644 index f40ba8edc22b..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/kv_view.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "github.com/coreos/etcd/lease" -) - -type readView struct{ kv KV } - -func (rv *readView) FirstRev() int64 { - tr := rv.kv.Read() - defer tr.End() - return tr.FirstRev() -} - -func (rv *readView) Rev() int64 { - tr := rv.kv.Read() - defer tr.End() - return tr.Rev() -} - -func (rv *readView) Range(key, end []byte, ro RangeOptions) (r *RangeResult, err error) { - tr := rv.kv.Read() - defer tr.End() - return tr.Range(key, end, ro) -} - -type writeView struct{ kv KV } - -func (wv *writeView) DeleteRange(key, end []byte) (n, rev int64) { - tw := wv.kv.Write() - defer tw.End() - return tw.DeleteRange(key, end) -} - -func (wv *writeView) Put(key, value []byte, lease lease.LeaseID) (rev int64) { - tw := wv.kv.Write() - defer tw.End() - return tw.Put(key, value, lease) -} diff --git a/vendor/go.etcd.io/etcd/mvcc/kvstore.go b/vendor/go.etcd.io/etcd/mvcc/kvstore.go deleted file mode 100644 index dd9f04ae2113..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/kvstore.go +++ /dev/null @@ -1,510 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "context" - "encoding/binary" - "errors" - "hash/crc32" - "math" - "sync" - "sync/atomic" - "time" - - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/mvcc/mvccpb" - "github.com/coreos/etcd/pkg/schedule" - "github.com/coreos/pkg/capnslog" -) - -var ( - keyBucketName = []byte("key") - metaBucketName = []byte("meta") - - consistentIndexKeyName = []byte("consistent_index") - scheduledCompactKeyName = []byte("scheduledCompactRev") - finishedCompactKeyName = []byte("finishedCompactRev") - - ErrCompacted = errors.New("mvcc: required revision has been compacted") - ErrFutureRev = errors.New("mvcc: required revision is a future revision") - ErrCanceled = errors.New("mvcc: watcher is canceled") - ErrClosed = errors.New("mvcc: closed") - - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "mvcc") -) - -const ( - // markedRevBytesLen is the byte length of marked revision. - // The first `revBytesLen` bytes represents a normal revision. The last - // one byte is the mark. - markedRevBytesLen = revBytesLen + 1 - markBytePosition = markedRevBytesLen - 1 - markTombstone byte = 't' -) - -var restoreChunkKeys = 10000 // non-const for testing - -// ConsistentIndexGetter is an interface that wraps the Get method. -// Consistent index is the offset of an entry in a consistent replicated log. -type ConsistentIndexGetter interface { - // ConsistentIndex returns the consistent index of current executing entry. - ConsistentIndex() uint64 -} - -type store struct { - ReadView - WriteView - - // consistentIndex caches the "consistent_index" key's value. Accessed - // through atomics so must be 64-bit aligned. - consistentIndex uint64 - - // mu read locks for txns and write locks for non-txn store changes. - mu sync.RWMutex - - ig ConsistentIndexGetter - - b backend.Backend - kvindex index - - le lease.Lessor - - // revMuLock protects currentRev and compactMainRev. - // Locked at end of write txn and released after write txn unlock lock. - // Locked before locking read txn and released after locking. - revMu sync.RWMutex - // currentRev is the revision of the last completed transaction. - currentRev int64 - // compactMainRev is the main revision of the last compaction. - compactMainRev int64 - - // bytesBuf8 is a byte slice of length 8 - // to avoid a repetitive allocation in saveIndex. - bytesBuf8 []byte - - fifoSched schedule.Scheduler - - stopc chan struct{} -} - -// NewStore returns a new store. It is useful to create a store inside -// mvcc pkg. It should only be used for testing externally. -func NewStore(b backend.Backend, le lease.Lessor, ig ConsistentIndexGetter) *store { - s := &store{ - b: b, - ig: ig, - kvindex: newTreeIndex(), - - le: le, - - currentRev: 1, - compactMainRev: -1, - - bytesBuf8: make([]byte, 8), - fifoSched: schedule.NewFIFOScheduler(), - - stopc: make(chan struct{}), - } - s.ReadView = &readView{s} - s.WriteView = &writeView{s} - if s.le != nil { - s.le.SetRangeDeleter(func() lease.TxnDelete { return s.Write() }) - } - - tx := s.b.BatchTx() - tx.Lock() - tx.UnsafeCreateBucket(keyBucketName) - tx.UnsafeCreateBucket(metaBucketName) - tx.Unlock() - s.b.ForceCommit() - - if err := s.restore(); err != nil { - // TODO: return the error instead of panic here? - panic("failed to recover store from backend") - } - - return s -} - -func (s *store) compactBarrier(ctx context.Context, ch chan struct{}) { - if ctx == nil || ctx.Err() != nil { - s.mu.Lock() - select { - case <-s.stopc: - default: - f := func(ctx context.Context) { s.compactBarrier(ctx, ch) } - s.fifoSched.Schedule(f) - } - s.mu.Unlock() - return - } - close(ch) -} - -func (s *store) Hash() (hash uint32, revision int64, err error) { - start := time.Now() - - s.b.ForceCommit() - h, err := s.b.Hash(DefaultIgnores) - - hashDurations.Observe(time.Since(start).Seconds()) - return h, s.currentRev, err -} - -func (s *store) HashByRev(rev int64) (hash uint32, currentRev int64, compactRev int64, err error) { - start := time.Now() - - s.mu.RLock() - s.revMu.RLock() - compactRev, currentRev = s.compactMainRev, s.currentRev - s.revMu.RUnlock() - - if rev > 0 && rev <= compactRev { - s.mu.RUnlock() - return 0, 0, compactRev, ErrCompacted - } else if rev > 0 && rev > currentRev { - s.mu.RUnlock() - return 0, currentRev, 0, ErrFutureRev - } - - if rev == 0 { - rev = currentRev - } - keep := s.kvindex.Keep(rev) - - tx := s.b.ReadTx() - tx.Lock() - defer tx.Unlock() - s.mu.RUnlock() - - upper := revision{main: rev + 1} - lower := revision{main: compactRev + 1} - h := crc32.New(crc32.MakeTable(crc32.Castagnoli)) - - h.Write(keyBucketName) - err = tx.UnsafeForEach(keyBucketName, func(k, v []byte) error { - kr := bytesToRev(k) - if !upper.GreaterThan(kr) { - return nil - } - // skip revisions that are scheduled for deletion - // due to compacting; don't skip if there isn't one. - if lower.GreaterThan(kr) && len(keep) > 0 { - if _, ok := keep[kr]; !ok { - return nil - } - } - h.Write(k) - h.Write(v) - return nil - }) - hash = h.Sum32() - - hashRevDurations.Observe(time.Since(start).Seconds()) - return hash, currentRev, compactRev, err -} - -func (s *store) Compact(rev int64) (<-chan struct{}, error) { - s.mu.Lock() - defer s.mu.Unlock() - s.revMu.Lock() - defer s.revMu.Unlock() - - if rev <= s.compactMainRev { - ch := make(chan struct{}) - f := func(ctx context.Context) { s.compactBarrier(ctx, ch) } - s.fifoSched.Schedule(f) - return ch, ErrCompacted - } - if rev > s.currentRev { - return nil, ErrFutureRev - } - - start := time.Now() - - s.compactMainRev = rev - - rbytes := newRevBytes() - revToBytes(revision{main: rev}, rbytes) - - tx := s.b.BatchTx() - tx.Lock() - tx.UnsafePut(metaBucketName, scheduledCompactKeyName, rbytes) - tx.Unlock() - // ensure that desired compaction is persisted - s.b.ForceCommit() - - keep := s.kvindex.Compact(rev) - ch := make(chan struct{}) - var j = func(ctx context.Context) { - if ctx.Err() != nil { - s.compactBarrier(ctx, ch) - return - } - if !s.scheduleCompaction(rev, keep) { - s.compactBarrier(nil, ch) - return - } - close(ch) - } - - s.fifoSched.Schedule(j) - - indexCompactionPauseDurations.Observe(float64(time.Since(start) / time.Millisecond)) - return ch, nil -} - -// DefaultIgnores is a map of keys to ignore in hash checking. -var DefaultIgnores map[backend.IgnoreKey]struct{} - -func init() { - DefaultIgnores = map[backend.IgnoreKey]struct{}{ - // consistent index might be changed due to v2 internal sync, which - // is not controllable by the user. - {Bucket: string(metaBucketName), Key: string(consistentIndexKeyName)}: {}, - } -} - -func (s *store) Commit() { - s.mu.Lock() - defer s.mu.Unlock() - - tx := s.b.BatchTx() - tx.Lock() - s.saveIndex(tx) - tx.Unlock() - s.b.ForceCommit() -} - -func (s *store) Restore(b backend.Backend) error { - s.mu.Lock() - defer s.mu.Unlock() - - close(s.stopc) - s.fifoSched.Stop() - - atomic.StoreUint64(&s.consistentIndex, 0) - s.b = b - s.kvindex = newTreeIndex() - s.currentRev = 1 - s.compactMainRev = -1 - s.fifoSched = schedule.NewFIFOScheduler() - s.stopc = make(chan struct{}) - - return s.restore() -} - -func (s *store) restore() error { - b := s.b - - reportDbTotalSizeInBytesMu.Lock() - reportDbTotalSizeInBytes = func() float64 { return float64(b.Size()) } - reportDbTotalSizeInBytesMu.Unlock() - reportDbTotalSizeInUseInBytesMu.Lock() - reportDbTotalSizeInUseInBytes = func() float64 { return float64(b.SizeInUse()) } - reportDbTotalSizeInUseInBytesMu.Unlock() - - min, max := newRevBytes(), newRevBytes() - revToBytes(revision{main: 1}, min) - revToBytes(revision{main: math.MaxInt64, sub: math.MaxInt64}, max) - - keyToLease := make(map[string]lease.LeaseID) - - // restore index - tx := s.b.BatchTx() - tx.Lock() - - _, finishedCompactBytes := tx.UnsafeRange(metaBucketName, finishedCompactKeyName, nil, 0) - if len(finishedCompactBytes) != 0 { - s.compactMainRev = bytesToRev(finishedCompactBytes[0]).main - plog.Printf("restore compact to %d", s.compactMainRev) - } - _, scheduledCompactBytes := tx.UnsafeRange(metaBucketName, scheduledCompactKeyName, nil, 0) - scheduledCompact := int64(0) - if len(scheduledCompactBytes) != 0 { - scheduledCompact = bytesToRev(scheduledCompactBytes[0]).main - } - - // index keys concurrently as they're loaded in from tx - keysGauge.Set(0) - rkvc, revc := restoreIntoIndex(s.kvindex) - for { - keys, vals := tx.UnsafeRange(keyBucketName, min, max, int64(restoreChunkKeys)) - if len(keys) == 0 { - break - } - // rkvc blocks if the total pending keys exceeds the restore - // chunk size to keep keys from consuming too much memory. - restoreChunk(rkvc, keys, vals, keyToLease) - if len(keys) < restoreChunkKeys { - // partial set implies final set - break - } - // next set begins after where this one ended - newMin := bytesToRev(keys[len(keys)-1][:revBytesLen]) - newMin.sub++ - revToBytes(newMin, min) - } - close(rkvc) - s.currentRev = <-revc - - // keys in the range [compacted revision -N, compaction] might all be deleted due to compaction. - // the correct revision should be set to compaction revision in the case, not the largest revision - // we have seen. - if s.currentRev < s.compactMainRev { - s.currentRev = s.compactMainRev - } - if scheduledCompact <= s.compactMainRev { - scheduledCompact = 0 - } - - for key, lid := range keyToLease { - if s.le == nil { - panic("no lessor to attach lease") - } - err := s.le.Attach(lid, []lease.LeaseItem{{Key: key}}) - if err != nil { - plog.Errorf("unexpected Attach error: %v", err) - } - } - - tx.Unlock() - - if scheduledCompact != 0 { - s.Compact(scheduledCompact) - plog.Printf("resume scheduled compaction at %d", scheduledCompact) - } - - return nil -} - -type revKeyValue struct { - key []byte - kv mvccpb.KeyValue - kstr string -} - -func restoreIntoIndex(idx index) (chan<- revKeyValue, <-chan int64) { - rkvc, revc := make(chan revKeyValue, restoreChunkKeys), make(chan int64, 1) - go func() { - currentRev := int64(1) - defer func() { revc <- currentRev }() - // restore the tree index from streaming the unordered index. - kiCache := make(map[string]*keyIndex, restoreChunkKeys) - for rkv := range rkvc { - ki, ok := kiCache[rkv.kstr] - // purge kiCache if many keys but still missing in the cache - if !ok && len(kiCache) >= restoreChunkKeys { - i := 10 - for k := range kiCache { - delete(kiCache, k) - if i--; i == 0 { - break - } - } - } - // cache miss, fetch from tree index if there - if !ok { - ki = &keyIndex{key: rkv.kv.Key} - if idxKey := idx.KeyIndex(ki); idxKey != nil { - kiCache[rkv.kstr], ki = idxKey, idxKey - ok = true - } - } - rev := bytesToRev(rkv.key) - currentRev = rev.main - if ok { - if isTombstone(rkv.key) { - ki.tombstone(rev.main, rev.sub) - continue - } - ki.put(rev.main, rev.sub) - } else if !isTombstone(rkv.key) { - ki.restore(revision{rkv.kv.CreateRevision, 0}, rev, rkv.kv.Version) - idx.Insert(ki) - kiCache[rkv.kstr] = ki - } - } - }() - return rkvc, revc -} - -func restoreChunk(kvc chan<- revKeyValue, keys, vals [][]byte, keyToLease map[string]lease.LeaseID) { - for i, key := range keys { - rkv := revKeyValue{key: key} - if err := rkv.kv.Unmarshal(vals[i]); err != nil { - plog.Fatalf("cannot unmarshal event: %v", err) - } - rkv.kstr = string(rkv.kv.Key) - if isTombstone(key) { - delete(keyToLease, rkv.kstr) - } else if lid := lease.LeaseID(rkv.kv.Lease); lid != lease.NoLease { - keyToLease[rkv.kstr] = lid - } else { - delete(keyToLease, rkv.kstr) - } - kvc <- rkv - } -} - -func (s *store) Close() error { - close(s.stopc) - s.fifoSched.Stop() - return nil -} - -func (s *store) saveIndex(tx backend.BatchTx) { - if s.ig == nil { - return - } - bs := s.bytesBuf8 - ci := s.ig.ConsistentIndex() - binary.BigEndian.PutUint64(bs, ci) - // put the index into the underlying backend - // tx has been locked in TxnBegin, so there is no need to lock it again - tx.UnsafePut(metaBucketName, consistentIndexKeyName, bs) - atomic.StoreUint64(&s.consistentIndex, ci) -} - -func (s *store) ConsistentIndex() uint64 { - if ci := atomic.LoadUint64(&s.consistentIndex); ci > 0 { - return ci - } - tx := s.b.BatchTx() - tx.Lock() - defer tx.Unlock() - _, vs := tx.UnsafeRange(metaBucketName, consistentIndexKeyName, nil, 0) - if len(vs) == 0 { - return 0 - } - v := binary.BigEndian.Uint64(vs[0]) - atomic.StoreUint64(&s.consistentIndex, v) - return v -} - -// appendMarkTombstone appends tombstone mark to normal revision bytes. -func appendMarkTombstone(b []byte) []byte { - if len(b) != revBytesLen { - plog.Panicf("cannot append mark to non normal revision bytes") - } - return append(b, markTombstone) -} - -// isTombstone checks whether the revision bytes is a tombstone. -func isTombstone(b []byte) bool { - return len(b) == markedRevBytesLen && b[markBytePosition] == markTombstone -} diff --git a/vendor/go.etcd.io/etcd/mvcc/kvstore_compaction.go b/vendor/go.etcd.io/etcd/mvcc/kvstore_compaction.go deleted file mode 100644 index 082a33f0e5d0..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/kvstore_compaction.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "encoding/binary" - "time" -) - -func (s *store) scheduleCompaction(compactMainRev int64, keep map[revision]struct{}) bool { - totalStart := time.Now() - defer func() { dbCompactionTotalDurations.Observe(float64(time.Since(totalStart) / time.Millisecond)) }() - keyCompactions := 0 - defer func() { dbCompactionKeysCounter.Add(float64(keyCompactions)) }() - - end := make([]byte, 8) - binary.BigEndian.PutUint64(end, uint64(compactMainRev+1)) - - batchsize := int64(10000) - last := make([]byte, 8+1+8) - for { - var rev revision - - start := time.Now() - tx := s.b.BatchTx() - tx.Lock() - - keys, _ := tx.UnsafeRange(keyBucketName, last, end, batchsize) - for _, key := range keys { - rev = bytesToRev(key) - if _, ok := keep[rev]; !ok { - tx.UnsafeDelete(keyBucketName, key) - keyCompactions++ - } - } - - if len(keys) < int(batchsize) { - rbytes := make([]byte, 8+1+8) - revToBytes(revision{main: compactMainRev}, rbytes) - tx.UnsafePut(metaBucketName, finishedCompactKeyName, rbytes) - tx.Unlock() - plog.Printf("finished scheduled compaction at %d (took %v)", compactMainRev, time.Since(totalStart)) - return true - } - - // update last - revToBytes(revision{main: rev.main, sub: rev.sub + 1}, last) - tx.Unlock() - dbCompactionPauseDurations.Observe(float64(time.Since(start) / time.Millisecond)) - - select { - case <-time.After(100 * time.Millisecond): - case <-s.stopc: - return false - } - } -} diff --git a/vendor/go.etcd.io/etcd/mvcc/kvstore_txn.go b/vendor/go.etcd.io/etcd/mvcc/kvstore_txn.go deleted file mode 100644 index 8896fb86dbf2..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/kvstore_txn.go +++ /dev/null @@ -1,253 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -type storeTxnRead struct { - s *store - tx backend.ReadTx - - firstRev int64 - rev int64 -} - -func (s *store) Read() TxnRead { - s.mu.RLock() - tx := s.b.ReadTx() - s.revMu.RLock() - tx.Lock() - firstRev, rev := s.compactMainRev, s.currentRev - s.revMu.RUnlock() - return newMetricsTxnRead(&storeTxnRead{s, tx, firstRev, rev}) -} - -func (tr *storeTxnRead) FirstRev() int64 { return tr.firstRev } -func (tr *storeTxnRead) Rev() int64 { return tr.rev } - -func (tr *storeTxnRead) Range(key, end []byte, ro RangeOptions) (r *RangeResult, err error) { - return tr.rangeKeys(key, end, tr.Rev(), ro) -} - -func (tr *storeTxnRead) End() { - tr.tx.Unlock() - tr.s.mu.RUnlock() -} - -type storeTxnWrite struct { - storeTxnRead - tx backend.BatchTx - // beginRev is the revision where the txn begins; it will write to the next revision. - beginRev int64 - changes []mvccpb.KeyValue -} - -func (s *store) Write() TxnWrite { - s.mu.RLock() - tx := s.b.BatchTx() - tx.Lock() - tw := &storeTxnWrite{ - storeTxnRead: storeTxnRead{s, tx, 0, 0}, - tx: tx, - beginRev: s.currentRev, - changes: make([]mvccpb.KeyValue, 0, 4), - } - return newMetricsTxnWrite(tw) -} - -func (tw *storeTxnWrite) Rev() int64 { return tw.beginRev } - -func (tw *storeTxnWrite) Range(key, end []byte, ro RangeOptions) (r *RangeResult, err error) { - rev := tw.beginRev - if len(tw.changes) > 0 { - rev++ - } - return tw.rangeKeys(key, end, rev, ro) -} - -func (tw *storeTxnWrite) DeleteRange(key, end []byte) (int64, int64) { - if n := tw.deleteRange(key, end); n != 0 || len(tw.changes) > 0 { - return n, int64(tw.beginRev + 1) - } - return 0, int64(tw.beginRev) -} - -func (tw *storeTxnWrite) Put(key, value []byte, lease lease.LeaseID) int64 { - tw.put(key, value, lease) - return int64(tw.beginRev + 1) -} - -func (tw *storeTxnWrite) End() { - // only update index if the txn modifies the mvcc state. - if len(tw.changes) != 0 { - tw.s.saveIndex(tw.tx) - // hold revMu lock to prevent new read txns from opening until writeback. - tw.s.revMu.Lock() - tw.s.currentRev++ - } - tw.tx.Unlock() - if len(tw.changes) != 0 { - tw.s.revMu.Unlock() - } - tw.s.mu.RUnlock() -} - -func (tr *storeTxnRead) rangeKeys(key, end []byte, curRev int64, ro RangeOptions) (*RangeResult, error) { - rev := ro.Rev - if rev > curRev { - return &RangeResult{KVs: nil, Count: -1, Rev: curRev}, ErrFutureRev - } - if rev <= 0 { - rev = curRev - } - if rev < tr.s.compactMainRev { - return &RangeResult{KVs: nil, Count: -1, Rev: 0}, ErrCompacted - } - - revpairs := tr.s.kvindex.Revisions(key, end, int64(rev)) - if len(revpairs) == 0 { - return &RangeResult{KVs: nil, Count: 0, Rev: curRev}, nil - } - if ro.Count { - return &RangeResult{KVs: nil, Count: len(revpairs), Rev: curRev}, nil - } - - limit := int(ro.Limit) - if limit <= 0 || limit > len(revpairs) { - limit = len(revpairs) - } - - kvs := make([]mvccpb.KeyValue, limit) - revBytes := newRevBytes() - for i, revpair := range revpairs[:len(kvs)] { - revToBytes(revpair, revBytes) - _, vs := tr.tx.UnsafeRange(keyBucketName, revBytes, nil, 0) - if len(vs) != 1 { - plog.Fatalf("range cannot find rev (%d,%d)", revpair.main, revpair.sub) - } - if err := kvs[i].Unmarshal(vs[0]); err != nil { - plog.Fatalf("cannot unmarshal event: %v", err) - } - } - return &RangeResult{KVs: kvs, Count: len(revpairs), Rev: curRev}, nil -} - -func (tw *storeTxnWrite) put(key, value []byte, leaseID lease.LeaseID) { - rev := tw.beginRev + 1 - c := rev - oldLease := lease.NoLease - - // if the key exists before, use its previous created and - // get its previous leaseID - _, created, ver, err := tw.s.kvindex.Get(key, rev) - if err == nil { - c = created.main - oldLease = tw.s.le.GetLease(lease.LeaseItem{Key: string(key)}) - } - - ibytes := newRevBytes() - idxRev := revision{main: rev, sub: int64(len(tw.changes))} - revToBytes(idxRev, ibytes) - - ver = ver + 1 - kv := mvccpb.KeyValue{ - Key: key, - Value: value, - CreateRevision: c, - ModRevision: rev, - Version: ver, - Lease: int64(leaseID), - } - - d, err := kv.Marshal() - if err != nil { - plog.Fatalf("cannot marshal event: %v", err) - } - - tw.tx.UnsafeSeqPut(keyBucketName, ibytes, d) - tw.s.kvindex.Put(key, idxRev) - tw.changes = append(tw.changes, kv) - - if oldLease != lease.NoLease { - if tw.s.le == nil { - panic("no lessor to detach lease") - } - err = tw.s.le.Detach(oldLease, []lease.LeaseItem{{Key: string(key)}}) - if err != nil { - plog.Errorf("unexpected error from lease detach: %v", err) - } - } - if leaseID != lease.NoLease { - if tw.s.le == nil { - panic("no lessor to attach lease") - } - err = tw.s.le.Attach(leaseID, []lease.LeaseItem{{Key: string(key)}}) - if err != nil { - panic("unexpected error from lease Attach") - } - } -} - -func (tw *storeTxnWrite) deleteRange(key, end []byte) int64 { - rrev := tw.beginRev - if len(tw.changes) > 0 { - rrev += 1 - } - keys, revs := tw.s.kvindex.Range(key, end, rrev) - if len(keys) == 0 { - return 0 - } - for i, key := range keys { - tw.delete(key, revs[i]) - } - return int64(len(keys)) -} - -func (tw *storeTxnWrite) delete(key []byte, rev revision) { - ibytes := newRevBytes() - idxRev := revision{main: tw.beginRev + 1, sub: int64(len(tw.changes))} - revToBytes(idxRev, ibytes) - ibytes = appendMarkTombstone(ibytes) - - kv := mvccpb.KeyValue{Key: key} - - d, err := kv.Marshal() - if err != nil { - plog.Fatalf("cannot marshal event: %v", err) - } - - tw.tx.UnsafeSeqPut(keyBucketName, ibytes, d) - err = tw.s.kvindex.Tombstone(key, idxRev) - if err != nil { - plog.Fatalf("cannot tombstone an existing key (%s): %v", string(key), err) - } - tw.changes = append(tw.changes, kv) - - item := lease.LeaseItem{Key: string(key)} - leaseID := tw.s.le.GetLease(item) - - if leaseID != lease.NoLease { - err = tw.s.le.Detach(leaseID, []lease.LeaseItem{item}) - if err != nil { - plog.Errorf("cannot detach %v", err) - } - } -} - -func (tw *storeTxnWrite) Changes() []mvccpb.KeyValue { return tw.changes } diff --git a/vendor/go.etcd.io/etcd/mvcc/metrics.go b/vendor/go.etcd.io/etcd/mvcc/metrics.go deleted file mode 100644 index b753310cff03..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/metrics.go +++ /dev/null @@ -1,239 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "sync" - - "github.com/prometheus/client_golang/prometheus" -) - -var ( - rangeCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "range_total", - Help: "Total number of ranges seen by this member.", - }) - - putCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "put_total", - Help: "Total number of puts seen by this member.", - }) - - deleteCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "delete_total", - Help: "Total number of deletes seen by this member.", - }) - - txnCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "txn_total", - Help: "Total number of txns seen by this member.", - }) - - keysGauge = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "keys_total", - Help: "Total number of keys.", - }) - - watchStreamGauge = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "watch_stream_total", - Help: "Total number of watch streams.", - }) - - watcherGauge = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "watcher_total", - Help: "Total number of watchers.", - }) - - slowWatcherGauge = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "slow_watcher_total", - Help: "Total number of unsynced slow watchers.", - }) - - totalEventsCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "events_total", - Help: "Total number of events sent by this member.", - }) - - pendingEventsGauge = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "pending_events_total", - Help: "Total number of pending events to be sent.", - }) - - indexCompactionPauseDurations = prometheus.NewHistogram( - prometheus.HistogramOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "index_compaction_pause_duration_milliseconds", - Help: "Bucketed histogram of index compaction pause duration.", - // 0.5ms -> 1second - Buckets: prometheus.ExponentialBuckets(0.5, 2, 12), - }) - - dbCompactionPauseDurations = prometheus.NewHistogram( - prometheus.HistogramOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "db_compaction_pause_duration_milliseconds", - Help: "Bucketed histogram of db compaction pause duration.", - // 1ms -> 4second - Buckets: prometheus.ExponentialBuckets(1, 2, 13), - }) - - dbCompactionTotalDurations = prometheus.NewHistogram( - prometheus.HistogramOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "db_compaction_total_duration_milliseconds", - Help: "Bucketed histogram of db compaction total duration.", - // 100ms -> 800second - Buckets: prometheus.ExponentialBuckets(100, 2, 14), - }) - - dbCompactionKeysCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "db_compaction_keys_total", - Help: "Total number of db keys compacted.", - }) - - dbTotalSizeDebugging = prometheus.NewGaugeFunc(prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "db_total_size_in_bytes", - Help: "Total size of the underlying database physically allocated in bytes. Use etcd_mvcc_db_total_size_in_bytes", - }, - func() float64 { - reportDbTotalSizeInBytesMu.RLock() - defer reportDbTotalSizeInBytesMu.RUnlock() - return reportDbTotalSizeInBytes() - }, - ) - dbTotalSize = prometheus.NewGaugeFunc(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "mvcc", - Name: "db_total_size_in_bytes", - Help: "Total size of the underlying database physically allocated in bytes.", - }, - func() float64 { - reportDbTotalSizeInBytesMu.RLock() - defer reportDbTotalSizeInBytesMu.RUnlock() - return reportDbTotalSizeInBytes() - }, - ) - // overridden by mvcc initialization - reportDbTotalSizeInBytesMu sync.RWMutex - reportDbTotalSizeInBytes = func() float64 { return 0 } - - dbTotalSizeInUse = prometheus.NewGaugeFunc(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "mvcc", - Name: "db_total_size_in_use_in_bytes", - Help: "Total size of the underlying database logically in use in bytes.", - }, - func() float64 { - reportDbTotalSizeInUseInBytesMu.RLock() - defer reportDbTotalSizeInUseInBytesMu.RUnlock() - return reportDbTotalSizeInUseInBytes() - }, - ) - // overridden by mvcc initialization - reportDbTotalSizeInUseInBytesMu sync.RWMutex - reportDbTotalSizeInUseInBytes func() float64 = func() float64 { return 0 } - - hashDurations = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "mvcc", - Name: "hash_duration_seconds", - Help: "The latency distribution of storage hash operation.", - - // 100 MB usually takes 100 ms, so start with 10 MB of 10 ms - // lowest bucket start of upper bound 0.01 sec (10 ms) with factor 2 - // highest bucket start of 0.01 sec * 2^14 == 163.84 sec - Buckets: prometheus.ExponentialBuckets(.01, 2, 15), - }) - - hashRevDurations = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "mvcc", - Name: "hash_rev_duration_seconds", - Help: "The latency distribution of storage hash by revision operation.", - - // 100 MB usually takes 100 ms, so start with 10 MB of 10 ms - // lowest bucket start of upper bound 0.01 sec (10 ms) with factor 2 - // highest bucket start of 0.01 sec * 2^14 == 163.84 sec - Buckets: prometheus.ExponentialBuckets(.01, 2, 15), - }) -) - -func init() { - prometheus.MustRegister(rangeCounter) - prometheus.MustRegister(putCounter) - prometheus.MustRegister(deleteCounter) - prometheus.MustRegister(txnCounter) - prometheus.MustRegister(keysGauge) - prometheus.MustRegister(watchStreamGauge) - prometheus.MustRegister(watcherGauge) - prometheus.MustRegister(slowWatcherGauge) - prometheus.MustRegister(totalEventsCounter) - prometheus.MustRegister(pendingEventsGauge) - prometheus.MustRegister(indexCompactionPauseDurations) - prometheus.MustRegister(dbCompactionPauseDurations) - prometheus.MustRegister(dbCompactionTotalDurations) - prometheus.MustRegister(dbCompactionKeysCounter) - prometheus.MustRegister(dbTotalSizeDebugging) - prometheus.MustRegister(dbTotalSize) - prometheus.MustRegister(dbTotalSizeInUse) - prometheus.MustRegister(hashDurations) - prometheus.MustRegister(hashRevDurations) -} - -// ReportEventReceived reports that an event is received. -// This function should be called when the external systems received an -// event from mvcc.Watcher. -func ReportEventReceived(n int) { - pendingEventsGauge.Sub(float64(n)) - totalEventsCounter.Add(float64(n)) -} diff --git a/vendor/go.etcd.io/etcd/mvcc/metrics_txn.go b/vendor/go.etcd.io/etcd/mvcc/metrics_txn.go deleted file mode 100644 index 911d64875d78..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/metrics_txn.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "github.com/coreos/etcd/lease" -) - -type metricsTxnWrite struct { - TxnWrite - ranges uint - puts uint - deletes uint -} - -func newMetricsTxnRead(tr TxnRead) TxnRead { - return &metricsTxnWrite{&txnReadWrite{tr}, 0, 0, 0} -} - -func newMetricsTxnWrite(tw TxnWrite) TxnWrite { - return &metricsTxnWrite{tw, 0, 0, 0} -} - -func (tw *metricsTxnWrite) Range(key, end []byte, ro RangeOptions) (*RangeResult, error) { - tw.ranges++ - return tw.TxnWrite.Range(key, end, ro) -} - -func (tw *metricsTxnWrite) DeleteRange(key, end []byte) (n, rev int64) { - tw.deletes++ - return tw.TxnWrite.DeleteRange(key, end) -} - -func (tw *metricsTxnWrite) Put(key, value []byte, lease lease.LeaseID) (rev int64) { - tw.puts++ - return tw.TxnWrite.Put(key, value, lease) -} - -func (tw *metricsTxnWrite) End() { - defer tw.TxnWrite.End() - if sum := tw.ranges + tw.puts + tw.deletes; sum > 1 { - txnCounter.Inc() - } - rangeCounter.Add(float64(tw.ranges)) - putCounter.Add(float64(tw.puts)) - deleteCounter.Add(float64(tw.deletes)) -} diff --git a/vendor/go.etcd.io/etcd/mvcc/mvccpb/kv.pb.go b/vendor/go.etcd.io/etcd/mvcc/mvccpb/kv.pb.go deleted file mode 100644 index 23fe337a59bf..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/mvccpb/kv.pb.go +++ /dev/null @@ -1,718 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: kv.proto - -/* - Package mvccpb is a generated protocol buffer package. - - It is generated from these files: - kv.proto - - It has these top-level messages: - KeyValue - Event -*/ -package mvccpb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type Event_EventType int32 - -const ( - PUT Event_EventType = 0 - DELETE Event_EventType = 1 -) - -var Event_EventType_name = map[int32]string{ - 0: "PUT", - 1: "DELETE", -} -var Event_EventType_value = map[string]int32{ - "PUT": 0, - "DELETE": 1, -} - -func (x Event_EventType) String() string { - return proto.EnumName(Event_EventType_name, int32(x)) -} -func (Event_EventType) EnumDescriptor() ([]byte, []int) { return fileDescriptorKv, []int{1, 0} } - -type KeyValue struct { - // key is the key in bytes. An empty key is not allowed. - Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - // create_revision is the revision of last creation on this key. - CreateRevision int64 `protobuf:"varint,2,opt,name=create_revision,json=createRevision,proto3" json:"create_revision,omitempty"` - // mod_revision is the revision of last modification on this key. - ModRevision int64 `protobuf:"varint,3,opt,name=mod_revision,json=modRevision,proto3" json:"mod_revision,omitempty"` - // version is the version of the key. A deletion resets - // the version to zero and any modification of the key - // increases its version. - Version int64 `protobuf:"varint,4,opt,name=version,proto3" json:"version,omitempty"` - // value is the value held by the key, in bytes. - Value []byte `protobuf:"bytes,5,opt,name=value,proto3" json:"value,omitempty"` - // lease is the ID of the lease that attached to key. - // When the attached lease expires, the key will be deleted. - // If lease is 0, then no lease is attached to the key. - Lease int64 `protobuf:"varint,6,opt,name=lease,proto3" json:"lease,omitempty"` -} - -func (m *KeyValue) Reset() { *m = KeyValue{} } -func (m *KeyValue) String() string { return proto.CompactTextString(m) } -func (*KeyValue) ProtoMessage() {} -func (*KeyValue) Descriptor() ([]byte, []int) { return fileDescriptorKv, []int{0} } - -type Event struct { - // type is the kind of event. If type is a PUT, it indicates - // new data has been stored to the key. If type is a DELETE, - // it indicates the key was deleted. - Type Event_EventType `protobuf:"varint,1,opt,name=type,proto3,enum=mvccpb.Event_EventType" json:"type,omitempty"` - // kv holds the KeyValue for the event. - // A PUT event contains current kv pair. - // A PUT event with kv.Version=1 indicates the creation of a key. - // A DELETE/EXPIRE event contains the deleted key with - // its modification revision set to the revision of deletion. - Kv *KeyValue `protobuf:"bytes,2,opt,name=kv" json:"kv,omitempty"` - // prev_kv holds the key-value pair before the event happens. - PrevKv *KeyValue `protobuf:"bytes,3,opt,name=prev_kv,json=prevKv" json:"prev_kv,omitempty"` -} - -func (m *Event) Reset() { *m = Event{} } -func (m *Event) String() string { return proto.CompactTextString(m) } -func (*Event) ProtoMessage() {} -func (*Event) Descriptor() ([]byte, []int) { return fileDescriptorKv, []int{1} } - -func init() { - proto.RegisterType((*KeyValue)(nil), "mvccpb.KeyValue") - proto.RegisterType((*Event)(nil), "mvccpb.Event") - proto.RegisterEnum("mvccpb.Event_EventType", Event_EventType_name, Event_EventType_value) -} -func (m *KeyValue) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *KeyValue) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Key) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintKv(dAtA, i, uint64(len(m.Key))) - i += copy(dAtA[i:], m.Key) - } - if m.CreateRevision != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintKv(dAtA, i, uint64(m.CreateRevision)) - } - if m.ModRevision != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintKv(dAtA, i, uint64(m.ModRevision)) - } - if m.Version != 0 { - dAtA[i] = 0x20 - i++ - i = encodeVarintKv(dAtA, i, uint64(m.Version)) - } - if len(m.Value) > 0 { - dAtA[i] = 0x2a - i++ - i = encodeVarintKv(dAtA, i, uint64(len(m.Value))) - i += copy(dAtA[i:], m.Value) - } - if m.Lease != 0 { - dAtA[i] = 0x30 - i++ - i = encodeVarintKv(dAtA, i, uint64(m.Lease)) - } - return i, nil -} - -func (m *Event) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Event) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Type != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintKv(dAtA, i, uint64(m.Type)) - } - if m.Kv != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintKv(dAtA, i, uint64(m.Kv.Size())) - n1, err := m.Kv.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - } - if m.PrevKv != nil { - dAtA[i] = 0x1a - i++ - i = encodeVarintKv(dAtA, i, uint64(m.PrevKv.Size())) - n2, err := m.PrevKv.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - } - return i, nil -} - -func encodeVarintKv(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *KeyValue) Size() (n int) { - var l int - _ = l - l = len(m.Key) - if l > 0 { - n += 1 + l + sovKv(uint64(l)) - } - if m.CreateRevision != 0 { - n += 1 + sovKv(uint64(m.CreateRevision)) - } - if m.ModRevision != 0 { - n += 1 + sovKv(uint64(m.ModRevision)) - } - if m.Version != 0 { - n += 1 + sovKv(uint64(m.Version)) - } - l = len(m.Value) - if l > 0 { - n += 1 + l + sovKv(uint64(l)) - } - if m.Lease != 0 { - n += 1 + sovKv(uint64(m.Lease)) - } - return n -} - -func (m *Event) Size() (n int) { - var l int - _ = l - if m.Type != 0 { - n += 1 + sovKv(uint64(m.Type)) - } - if m.Kv != nil { - l = m.Kv.Size() - n += 1 + l + sovKv(uint64(l)) - } - if m.PrevKv != nil { - l = m.PrevKv.Size() - n += 1 + l + sovKv(uint64(l)) - } - return n -} - -func sovKv(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozKv(x uint64) (n int) { - return sovKv(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *KeyValue) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: KeyValue: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: KeyValue: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthKv - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CreateRevision", wireType) - } - m.CreateRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.CreateRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ModRevision", wireType) - } - m.ModRevision = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ModRevision |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) - } - m.Version = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Version |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthKv - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...) - if m.Value == nil { - m.Value = []byte{} - } - iNdEx = postIndex - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Lease", wireType) - } - m.Lease = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Lease |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipKv(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthKv - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Event) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Event: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Event: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= (Event_EventType(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Kv", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthKv - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Kv == nil { - m.Kv = &KeyValue{} - } - if err := m.Kv.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PrevKv", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthKv - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.PrevKv == nil { - m.PrevKv = &KeyValue{} - } - if err := m.PrevKv.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipKv(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthKv - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipKv(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowKv - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowKv - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowKv - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthKv - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowKv - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipKv(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthKv = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowKv = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("kv.proto", fileDescriptorKv) } - -var fileDescriptorKv = []byte{ - // 303 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0x41, 0x4e, 0xc2, 0x40, - 0x14, 0x86, 0x3b, 0x14, 0x0a, 0x3e, 0x08, 0x36, 0x13, 0x12, 0x27, 0x2e, 0x26, 0x95, 0x8d, 0x18, - 0x13, 0x4c, 0xf0, 0x06, 0xc6, 0xae, 0x70, 0x61, 0x1a, 0x74, 0x4b, 0x4a, 0x79, 0x21, 0xa4, 0x94, - 0x69, 0x4a, 0x9d, 0xa4, 0x37, 0x71, 0xef, 0xde, 0x73, 0xb0, 0xe4, 0x08, 0x52, 0x2f, 0x62, 0xfa, - 0xc6, 0xe2, 0xc6, 0xcd, 0xe4, 0xfd, 0xff, 0xff, 0x65, 0xe6, 0x7f, 0x03, 0x9d, 0x58, 0x8f, 0xd3, - 0x4c, 0xe5, 0x8a, 0x3b, 0x89, 0x8e, 0xa2, 0x74, 0x71, 0x39, 0x58, 0xa9, 0x95, 0x22, 0xeb, 0xae, - 0x9a, 0x4c, 0x3a, 0xfc, 0x64, 0xd0, 0x99, 0x62, 0xf1, 0x1a, 0x6e, 0xde, 0x90, 0xbb, 0x60, 0xc7, - 0x58, 0x08, 0xe6, 0xb1, 0x51, 0x2f, 0xa8, 0x46, 0x7e, 0x0d, 0xe7, 0x51, 0x86, 0x61, 0x8e, 0xf3, - 0x0c, 0xf5, 0x7a, 0xb7, 0x56, 0x5b, 0xd1, 0xf0, 0xd8, 0xc8, 0x0e, 0xfa, 0xc6, 0x0e, 0x7e, 0x5d, - 0x7e, 0x05, 0xbd, 0x44, 0x2d, 0xff, 0x28, 0x9b, 0xa8, 0x6e, 0xa2, 0x96, 0x27, 0x44, 0x40, 0x5b, - 0x63, 0x46, 0x69, 0x93, 0xd2, 0x5a, 0xf2, 0x01, 0xb4, 0x74, 0x55, 0x40, 0xb4, 0xe8, 0x65, 0x23, - 0x2a, 0x77, 0x83, 0xe1, 0x0e, 0x85, 0x43, 0xb4, 0x11, 0xc3, 0x0f, 0x06, 0x2d, 0x5f, 0xe3, 0x36, - 0xe7, 0xb7, 0xd0, 0xcc, 0x8b, 0x14, 0xa9, 0x6e, 0x7f, 0x72, 0x31, 0x36, 0x7b, 0x8e, 0x29, 0x34, - 0xe7, 0xac, 0x48, 0x31, 0x20, 0x88, 0x7b, 0xd0, 0x88, 0x35, 0x75, 0xef, 0x4e, 0xdc, 0x1a, 0xad, - 0x17, 0x0f, 0x1a, 0xb1, 0xe6, 0x37, 0xd0, 0x4e, 0x33, 0xd4, 0xf3, 0x58, 0x53, 0xf9, 0xff, 0x30, - 0xa7, 0x02, 0xa6, 0x7a, 0xe8, 0xc1, 0xd9, 0xe9, 0x7e, 0xde, 0x06, 0xfb, 0xf9, 0x65, 0xe6, 0x5a, - 0x1c, 0xc0, 0x79, 0xf4, 0x9f, 0xfc, 0x99, 0xef, 0xb2, 0x07, 0xb1, 0x3f, 0x4a, 0xeb, 0x70, 0x94, - 0xd6, 0xbe, 0x94, 0xec, 0x50, 0x4a, 0xf6, 0x55, 0x4a, 0xf6, 0xfe, 0x2d, 0xad, 0x85, 0x43, 0xff, - 0x7e, 0xff, 0x13, 0x00, 0x00, 0xff, 0xff, 0xb5, 0x45, 0x92, 0x5d, 0xa1, 0x01, 0x00, 0x00, -} diff --git a/vendor/go.etcd.io/etcd/mvcc/revision.go b/vendor/go.etcd.io/etcd/mvcc/revision.go deleted file mode 100644 index 5fa35a1c2a26..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/revision.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import "encoding/binary" - -// revBytesLen is the byte length of a normal revision. -// First 8 bytes is the revision.main in big-endian format. The 9th byte -// is a '_'. The last 8 bytes is the revision.sub in big-endian format. -const revBytesLen = 8 + 1 + 8 - -// A revision indicates modification of the key-value space. -// The set of changes that share same main revision changes the key-value space atomically. -type revision struct { - // main is the main revision of a set of changes that happen atomically. - main int64 - - // sub is the the sub revision of a change in a set of changes that happen - // atomically. Each change has different increasing sub revision in that - // set. - sub int64 -} - -func (a revision) GreaterThan(b revision) bool { - if a.main > b.main { - return true - } - if a.main < b.main { - return false - } - return a.sub > b.sub -} - -func newRevBytes() []byte { - return make([]byte, revBytesLen, markedRevBytesLen) -} - -func revToBytes(rev revision, bytes []byte) { - binary.BigEndian.PutUint64(bytes, uint64(rev.main)) - bytes[8] = '_' - binary.BigEndian.PutUint64(bytes[9:], uint64(rev.sub)) -} - -func bytesToRev(bytes []byte) revision { - return revision{ - main: int64(binary.BigEndian.Uint64(bytes[0:8])), - sub: int64(binary.BigEndian.Uint64(bytes[9:])), - } -} - -type revisions []revision - -func (a revisions) Len() int { return len(a) } -func (a revisions) Less(i, j int) bool { return a[j].GreaterThan(a[i]) } -func (a revisions) Swap(i, j int) { a[i], a[j] = a[j], a[i] } diff --git a/vendor/go.etcd.io/etcd/mvcc/util.go b/vendor/go.etcd.io/etcd/mvcc/util.go deleted file mode 100644 index 8a0df0bfcc37..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/util.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "encoding/binary" - - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -func UpdateConsistentIndex(be backend.Backend, index uint64) { - tx := be.BatchTx() - tx.Lock() - defer tx.Unlock() - - var oldi uint64 - _, vs := tx.UnsafeRange(metaBucketName, consistentIndexKeyName, nil, 0) - if len(vs) != 0 { - oldi = binary.BigEndian.Uint64(vs[0]) - } - - if index <= oldi { - return - } - - bs := make([]byte, 8) - binary.BigEndian.PutUint64(bs, index) - tx.UnsafePut(metaBucketName, consistentIndexKeyName, bs) -} - -func WriteKV(be backend.Backend, kv mvccpb.KeyValue) { - ibytes := newRevBytes() - revToBytes(revision{main: kv.ModRevision}, ibytes) - - d, err := kv.Marshal() - if err != nil { - plog.Fatalf("cannot marshal event: %v", err) - } - - be.BatchTx().Lock() - be.BatchTx().UnsafePut(keyBucketName, ibytes, d) - be.BatchTx().Unlock() -} diff --git a/vendor/go.etcd.io/etcd/mvcc/watchable_store.go b/vendor/go.etcd.io/etcd/mvcc/watchable_store.go deleted file mode 100644 index 78df19326b95..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/watchable_store.go +++ /dev/null @@ -1,534 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "sync" - "time" - - "github.com/coreos/etcd/lease" - "github.com/coreos/etcd/mvcc/backend" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -// non-const so modifiable by tests -var ( - // chanBufLen is the length of the buffered chan - // for sending out watched events. - // TODO: find a good buf value. 1024 is just a random one that - // seems to be reasonable. - chanBufLen = 1024 - - // maxWatchersPerSync is the number of watchers to sync in a single batch - maxWatchersPerSync = 512 -) - -type watchable interface { - watch(key, end []byte, startRev int64, id WatchID, ch chan<- WatchResponse, fcs ...FilterFunc) (*watcher, cancelFunc) - progress(w *watcher) - rev() int64 -} - -type watchableStore struct { - *store - - // mu protects watcher groups and batches. It should never be locked - // before locking store.mu to avoid deadlock. - mu sync.RWMutex - - // victims are watcher batches that were blocked on the watch channel - victims []watcherBatch - victimc chan struct{} - - // contains all unsynced watchers that needs to sync with events that have happened - unsynced watcherGroup - - // contains all synced watchers that are in sync with the progress of the store. - // The key of the map is the key that the watcher watches on. - synced watcherGroup - - stopc chan struct{} - wg sync.WaitGroup -} - -// cancelFunc updates unsynced and synced maps when running -// cancel operations. -type cancelFunc func() - -func New(b backend.Backend, le lease.Lessor, ig ConsistentIndexGetter) ConsistentWatchableKV { - return newWatchableStore(b, le, ig) -} - -func newWatchableStore(b backend.Backend, le lease.Lessor, ig ConsistentIndexGetter) *watchableStore { - s := &watchableStore{ - store: NewStore(b, le, ig), - victimc: make(chan struct{}, 1), - unsynced: newWatcherGroup(), - synced: newWatcherGroup(), - stopc: make(chan struct{}), - } - s.store.ReadView = &readView{s} - s.store.WriteView = &writeView{s} - if s.le != nil { - // use this store as the deleter so revokes trigger watch events - s.le.SetRangeDeleter(func() lease.TxnDelete { return s.Write() }) - } - s.wg.Add(2) - go s.syncWatchersLoop() - go s.syncVictimsLoop() - return s -} - -func (s *watchableStore) Close() error { - close(s.stopc) - s.wg.Wait() - return s.store.Close() -} - -func (s *watchableStore) NewWatchStream() WatchStream { - watchStreamGauge.Inc() - return &watchStream{ - watchable: s, - ch: make(chan WatchResponse, chanBufLen), - cancels: make(map[WatchID]cancelFunc), - watchers: make(map[WatchID]*watcher), - } -} - -func (s *watchableStore) watch(key, end []byte, startRev int64, id WatchID, ch chan<- WatchResponse, fcs ...FilterFunc) (*watcher, cancelFunc) { - wa := &watcher{ - key: key, - end: end, - minRev: startRev, - id: id, - ch: ch, - fcs: fcs, - } - - s.mu.Lock() - s.revMu.RLock() - synced := startRev > s.store.currentRev || startRev == 0 - if synced { - wa.minRev = s.store.currentRev + 1 - if startRev > wa.minRev { - wa.minRev = startRev - } - } - if synced { - s.synced.add(wa) - } else { - slowWatcherGauge.Inc() - s.unsynced.add(wa) - } - s.revMu.RUnlock() - s.mu.Unlock() - - watcherGauge.Inc() - - return wa, func() { s.cancelWatcher(wa) } -} - -// cancelWatcher removes references of the watcher from the watchableStore -func (s *watchableStore) cancelWatcher(wa *watcher) { - for { - s.mu.Lock() - if s.unsynced.delete(wa) { - slowWatcherGauge.Dec() - break - } else if s.synced.delete(wa) { - break - } else if wa.compacted { - break - } else if wa.ch == nil { - // already canceled (e.g., cancel/close race) - break - } - - if !wa.victim { - panic("watcher not victim but not in watch groups") - } - - var victimBatch watcherBatch - for _, wb := range s.victims { - if wb[wa] != nil { - victimBatch = wb - break - } - } - if victimBatch != nil { - slowWatcherGauge.Dec() - delete(victimBatch, wa) - break - } - - // victim being processed so not accessible; retry - s.mu.Unlock() - time.Sleep(time.Millisecond) - } - - watcherGauge.Dec() - wa.ch = nil - s.mu.Unlock() -} - -func (s *watchableStore) Restore(b backend.Backend) error { - s.mu.Lock() - defer s.mu.Unlock() - err := s.store.Restore(b) - if err != nil { - return err - } - - for wa := range s.synced.watchers { - wa.restore = true - s.unsynced.add(wa) - } - s.synced = newWatcherGroup() - return nil -} - -// syncWatchersLoop syncs the watcher in the unsynced map every 100ms. -func (s *watchableStore) syncWatchersLoop() { - defer s.wg.Done() - - for { - s.mu.RLock() - st := time.Now() - lastUnsyncedWatchers := s.unsynced.size() - s.mu.RUnlock() - - unsyncedWatchers := 0 - if lastUnsyncedWatchers > 0 { - unsyncedWatchers = s.syncWatchers() - } - syncDuration := time.Since(st) - - waitDuration := 100 * time.Millisecond - // more work pending? - if unsyncedWatchers != 0 && lastUnsyncedWatchers > unsyncedWatchers { - // be fair to other store operations by yielding time taken - waitDuration = syncDuration - } - - select { - case <-time.After(waitDuration): - case <-s.stopc: - return - } - } -} - -// syncVictimsLoop tries to write precomputed watcher responses to -// watchers that had a blocked watcher channel -func (s *watchableStore) syncVictimsLoop() { - defer s.wg.Done() - - for { - for s.moveVictims() != 0 { - // try to update all victim watchers - } - s.mu.RLock() - isEmpty := len(s.victims) == 0 - s.mu.RUnlock() - - var tickc <-chan time.Time - if !isEmpty { - tickc = time.After(10 * time.Millisecond) - } - - select { - case <-tickc: - case <-s.victimc: - case <-s.stopc: - return - } - } -} - -// moveVictims tries to update watches with already pending event data -func (s *watchableStore) moveVictims() (moved int) { - s.mu.Lock() - victims := s.victims - s.victims = nil - s.mu.Unlock() - - var newVictim watcherBatch - for _, wb := range victims { - // try to send responses again - for w, eb := range wb { - // watcher has observed the store up to, but not including, w.minRev - rev := w.minRev - 1 - if w.send(WatchResponse{WatchID: w.id, Events: eb.evs, Revision: rev}) { - pendingEventsGauge.Add(float64(len(eb.evs))) - } else { - if newVictim == nil { - newVictim = make(watcherBatch) - } - newVictim[w] = eb - continue - } - moved++ - } - - // assign completed victim watchers to unsync/sync - s.mu.Lock() - s.store.revMu.RLock() - curRev := s.store.currentRev - for w, eb := range wb { - if newVictim != nil && newVictim[w] != nil { - // couldn't send watch response; stays victim - continue - } - w.victim = false - if eb.moreRev != 0 { - w.minRev = eb.moreRev - } - if w.minRev <= curRev { - s.unsynced.add(w) - } else { - slowWatcherGauge.Dec() - s.synced.add(w) - } - } - s.store.revMu.RUnlock() - s.mu.Unlock() - } - - if len(newVictim) > 0 { - s.mu.Lock() - s.victims = append(s.victims, newVictim) - s.mu.Unlock() - } - - return moved -} - -// syncWatchers syncs unsynced watchers by: -// 1. choose a set of watchers from the unsynced watcher group -// 2. iterate over the set to get the minimum revision and remove compacted watchers -// 3. use minimum revision to get all key-value pairs and send those events to watchers -// 4. remove synced watchers in set from unsynced group and move to synced group -func (s *watchableStore) syncWatchers() int { - s.mu.Lock() - defer s.mu.Unlock() - - if s.unsynced.size() == 0 { - return 0 - } - - s.store.revMu.RLock() - defer s.store.revMu.RUnlock() - - // in order to find key-value pairs from unsynced watchers, we need to - // find min revision index, and these revisions can be used to - // query the backend store of key-value pairs - curRev := s.store.currentRev - compactionRev := s.store.compactMainRev - - wg, minRev := s.unsynced.choose(maxWatchersPerSync, curRev, compactionRev) - minBytes, maxBytes := newRevBytes(), newRevBytes() - revToBytes(revision{main: minRev}, minBytes) - revToBytes(revision{main: curRev + 1}, maxBytes) - - // UnsafeRange returns keys and values. And in boltdb, keys are revisions. - // values are actual key-value pairs in backend. - tx := s.store.b.ReadTx() - tx.Lock() - revs, vs := tx.UnsafeRange(keyBucketName, minBytes, maxBytes, 0) - evs := kvsToEvents(wg, revs, vs) - tx.Unlock() - - var victims watcherBatch - wb := newWatcherBatch(wg, evs) - for w := range wg.watchers { - w.minRev = curRev + 1 - - eb, ok := wb[w] - if !ok { - // bring un-notified watcher to synced - s.synced.add(w) - s.unsynced.delete(w) - continue - } - - if eb.moreRev != 0 { - w.minRev = eb.moreRev - } - - if w.send(WatchResponse{WatchID: w.id, Events: eb.evs, Revision: curRev}) { - pendingEventsGauge.Add(float64(len(eb.evs))) - } else { - if victims == nil { - victims = make(watcherBatch) - } - w.victim = true - } - - if w.victim { - victims[w] = eb - } else { - if eb.moreRev != 0 { - // stay unsynced; more to read - continue - } - s.synced.add(w) - } - s.unsynced.delete(w) - } - s.addVictim(victims) - - vsz := 0 - for _, v := range s.victims { - vsz += len(v) - } - slowWatcherGauge.Set(float64(s.unsynced.size() + vsz)) - - return s.unsynced.size() -} - -// kvsToEvents gets all events for the watchers from all key-value pairs -func kvsToEvents(wg *watcherGroup, revs, vals [][]byte) (evs []mvccpb.Event) { - for i, v := range vals { - var kv mvccpb.KeyValue - if err := kv.Unmarshal(v); err != nil { - plog.Panicf("cannot unmarshal event: %v", err) - } - - if !wg.contains(string(kv.Key)) { - continue - } - - ty := mvccpb.PUT - if isTombstone(revs[i]) { - ty = mvccpb.DELETE - // patch in mod revision so watchers won't skip - kv.ModRevision = bytesToRev(revs[i]).main - } - evs = append(evs, mvccpb.Event{Kv: &kv, Type: ty}) - } - return evs -} - -// notify notifies the fact that given event at the given rev just happened to -// watchers that watch on the key of the event. -func (s *watchableStore) notify(rev int64, evs []mvccpb.Event) { - var victim watcherBatch - for w, eb := range newWatcherBatch(&s.synced, evs) { - if eb.revs != 1 { - plog.Panicf("unexpected multiple revisions in notification") - } - if w.send(WatchResponse{WatchID: w.id, Events: eb.evs, Revision: rev}) { - pendingEventsGauge.Add(float64(len(eb.evs))) - } else { - // move slow watcher to victims - w.minRev = rev + 1 - if victim == nil { - victim = make(watcherBatch) - } - w.victim = true - victim[w] = eb - s.synced.delete(w) - slowWatcherGauge.Inc() - } - } - s.addVictim(victim) -} - -func (s *watchableStore) addVictim(victim watcherBatch) { - if victim == nil { - return - } - s.victims = append(s.victims, victim) - select { - case s.victimc <- struct{}{}: - default: - } -} - -func (s *watchableStore) rev() int64 { return s.store.Rev() } - -func (s *watchableStore) progress(w *watcher) { - s.mu.RLock() - defer s.mu.RUnlock() - - if _, ok := s.synced.watchers[w]; ok { - w.send(WatchResponse{WatchID: w.id, Revision: s.rev()}) - // If the ch is full, this watcher is receiving events. - // We do not need to send progress at all. - } -} - -type watcher struct { - // the watcher key - key []byte - // end indicates the end of the range to watch. - // If end is set, the watcher is on a range. - end []byte - - // victim is set when ch is blocked and undergoing victim processing - victim bool - - // compacted is set when the watcher is removed because of compaction - compacted bool - - // restore is true when the watcher is being restored from leader snapshot - // which means that this watcher has just been moved from "synced" to "unsynced" - // watcher group, possibly with a future revision when it was first added - // to the synced watcher - // "unsynced" watcher revision must always be <= current revision, - // except when the watcher were to be moved from "synced" watcher group - restore bool - - // minRev is the minimum revision update the watcher will accept - minRev int64 - id WatchID - - fcs []FilterFunc - // a chan to send out the watch response. - // The chan might be shared with other watchers. - ch chan<- WatchResponse -} - -func (w *watcher) send(wr WatchResponse) bool { - progressEvent := len(wr.Events) == 0 - - if len(w.fcs) != 0 { - ne := make([]mvccpb.Event, 0, len(wr.Events)) - for i := range wr.Events { - filtered := false - for _, filter := range w.fcs { - if filter(wr.Events[i]) { - filtered = true - break - } - } - if !filtered { - ne = append(ne, wr.Events[i]) - } - } - wr.Events = ne - } - - // if all events are filtered out, we should send nothing. - if !progressEvent && len(wr.Events) == 0 { - return true - } - select { - case w.ch <- wr: - return true - default: - return false - } -} diff --git a/vendor/go.etcd.io/etcd/mvcc/watchable_store_txn.go b/vendor/go.etcd.io/etcd/mvcc/watchable_store_txn.go deleted file mode 100644 index 5c5bfda13413..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/watchable_store_txn.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "github.com/coreos/etcd/mvcc/mvccpb" -) - -func (tw *watchableStoreTxnWrite) End() { - changes := tw.Changes() - if len(changes) == 0 { - tw.TxnWrite.End() - return - } - - rev := tw.Rev() + 1 - evs := make([]mvccpb.Event, len(changes)) - for i, change := range changes { - evs[i].Kv = &changes[i] - if change.CreateRevision == 0 { - evs[i].Type = mvccpb.DELETE - evs[i].Kv.ModRevision = rev - } else { - evs[i].Type = mvccpb.PUT - } - } - - // end write txn under watchable store lock so the updates are visible - // when asynchronous event posting checks the current store revision - tw.s.mu.Lock() - tw.s.notify(rev, evs) - tw.TxnWrite.End() - tw.s.mu.Unlock() -} - -type watchableStoreTxnWrite struct { - TxnWrite - s *watchableStore -} - -func (s *watchableStore) Write() TxnWrite { return &watchableStoreTxnWrite{s.store.Write(), s} } diff --git a/vendor/go.etcd.io/etcd/mvcc/watcher.go b/vendor/go.etcd.io/etcd/mvcc/watcher.go deleted file mode 100644 index bc0c6322fd1f..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/watcher.go +++ /dev/null @@ -1,180 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "bytes" - "errors" - "sync" - - "github.com/coreos/etcd/mvcc/mvccpb" -) - -var ( - ErrWatcherNotExist = errors.New("mvcc: watcher does not exist") -) - -type WatchID int64 - -// FilterFunc returns true if the given event should be filtered out. -type FilterFunc func(e mvccpb.Event) bool - -type WatchStream interface { - // Watch creates a watcher. The watcher watches the events happening or - // happened on the given key or range [key, end) from the given startRev. - // - // The whole event history can be watched unless compacted. - // If `startRev` <=0, watch observes events after currentRev. - // - // The returned `id` is the ID of this watcher. It appears as WatchID - // in events that are sent to the created watcher through stream channel. - // - Watch(key, end []byte, startRev int64, fcs ...FilterFunc) WatchID - - // Chan returns a chan. All watch response will be sent to the returned chan. - Chan() <-chan WatchResponse - - // RequestProgress requests the progress of the watcher with given ID. The response - // will only be sent if the watcher is currently synced. - // The responses will be sent through the WatchRespone Chan attached - // with this stream to ensure correct ordering. - // The responses contains no events. The revision in the response is the progress - // of the watchers since the watcher is currently synced. - RequestProgress(id WatchID) - - // Cancel cancels a watcher by giving its ID. If watcher does not exist, an error will be - // returned. - Cancel(id WatchID) error - - // Close closes Chan and release all related resources. - Close() - - // Rev returns the current revision of the KV the stream watches on. - Rev() int64 -} - -type WatchResponse struct { - // WatchID is the WatchID of the watcher this response sent to. - WatchID WatchID - - // Events contains all the events that needs to send. - Events []mvccpb.Event - - // Revision is the revision of the KV when the watchResponse is created. - // For a normal response, the revision should be the same as the last - // modified revision inside Events. For a delayed response to a unsynced - // watcher, the revision is greater than the last modified revision - // inside Events. - Revision int64 - - // CompactRevision is set when the watcher is cancelled due to compaction. - CompactRevision int64 -} - -// watchStream contains a collection of watchers that share -// one streaming chan to send out watched events and other control events. -type watchStream struct { - watchable watchable - ch chan WatchResponse - - mu sync.Mutex // guards fields below it - // nextID is the ID pre-allocated for next new watcher in this stream - nextID WatchID - closed bool - cancels map[WatchID]cancelFunc - watchers map[WatchID]*watcher -} - -// Watch creates a new watcher in the stream and returns its WatchID. -// TODO: return error if ws is closed? -func (ws *watchStream) Watch(key, end []byte, startRev int64, fcs ...FilterFunc) WatchID { - // prevent wrong range where key >= end lexicographically - // watch request with 'WithFromKey' has empty-byte range end - if len(end) != 0 && bytes.Compare(key, end) != -1 { - return -1 - } - - ws.mu.Lock() - defer ws.mu.Unlock() - if ws.closed { - return -1 - } - - id := ws.nextID - ws.nextID++ - - w, c := ws.watchable.watch(key, end, startRev, id, ws.ch, fcs...) - - ws.cancels[id] = c - ws.watchers[id] = w - return id -} - -func (ws *watchStream) Chan() <-chan WatchResponse { - return ws.ch -} - -func (ws *watchStream) Cancel(id WatchID) error { - ws.mu.Lock() - cancel, ok := ws.cancels[id] - w := ws.watchers[id] - ok = ok && !ws.closed - ws.mu.Unlock() - - if !ok { - return ErrWatcherNotExist - } - cancel() - - ws.mu.Lock() - // The watch isn't removed until cancel so that if Close() is called, - // it will wait for the cancel. Otherwise, Close() could close the - // watch channel while the store is still posting events. - if ww := ws.watchers[id]; ww == w { - delete(ws.cancels, id) - delete(ws.watchers, id) - } - ws.mu.Unlock() - - return nil -} - -func (ws *watchStream) Close() { - ws.mu.Lock() - defer ws.mu.Unlock() - - for _, cancel := range ws.cancels { - cancel() - } - ws.closed = true - close(ws.ch) - watchStreamGauge.Dec() -} - -func (ws *watchStream) Rev() int64 { - ws.mu.Lock() - defer ws.mu.Unlock() - return ws.watchable.rev() -} - -func (ws *watchStream) RequestProgress(id WatchID) { - ws.mu.Lock() - w, ok := ws.watchers[id] - ws.mu.Unlock() - if !ok { - return - } - ws.watchable.progress(w) -} diff --git a/vendor/go.etcd.io/etcd/mvcc/watcher_group.go b/vendor/go.etcd.io/etcd/mvcc/watcher_group.go deleted file mode 100644 index b65c7bc5eb7e..000000000000 --- a/vendor/go.etcd.io/etcd/mvcc/watcher_group.go +++ /dev/null @@ -1,292 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "fmt" - "math" - - "github.com/coreos/etcd/mvcc/mvccpb" - "github.com/coreos/etcd/pkg/adt" -) - -var ( - // watchBatchMaxRevs is the maximum distinct revisions that - // may be sent to an unsynced watcher at a time. Declared as - // var instead of const for testing purposes. - watchBatchMaxRevs = 1000 -) - -type eventBatch struct { - // evs is a batch of revision-ordered events - evs []mvccpb.Event - // revs is the minimum unique revisions observed for this batch - revs int - // moreRev is first revision with more events following this batch - moreRev int64 -} - -func (eb *eventBatch) add(ev mvccpb.Event) { - if eb.revs > watchBatchMaxRevs { - // maxed out batch size - return - } - - if len(eb.evs) == 0 { - // base case - eb.revs = 1 - eb.evs = append(eb.evs, ev) - return - } - - // revision accounting - ebRev := eb.evs[len(eb.evs)-1].Kv.ModRevision - evRev := ev.Kv.ModRevision - if evRev > ebRev { - eb.revs++ - if eb.revs > watchBatchMaxRevs { - eb.moreRev = evRev - return - } - } - - eb.evs = append(eb.evs, ev) -} - -type watcherBatch map[*watcher]*eventBatch - -func (wb watcherBatch) add(w *watcher, ev mvccpb.Event) { - eb := wb[w] - if eb == nil { - eb = &eventBatch{} - wb[w] = eb - } - eb.add(ev) -} - -// newWatcherBatch maps watchers to their matched events. It enables quick -// events look up by watcher. -func newWatcherBatch(wg *watcherGroup, evs []mvccpb.Event) watcherBatch { - if len(wg.watchers) == 0 { - return nil - } - - wb := make(watcherBatch) - for _, ev := range evs { - for w := range wg.watcherSetByKey(string(ev.Kv.Key)) { - if ev.Kv.ModRevision >= w.minRev { - // don't double notify - wb.add(w, ev) - } - } - } - return wb -} - -type watcherSet map[*watcher]struct{} - -func (w watcherSet) add(wa *watcher) { - if _, ok := w[wa]; ok { - panic("add watcher twice!") - } - w[wa] = struct{}{} -} - -func (w watcherSet) union(ws watcherSet) { - for wa := range ws { - w.add(wa) - } -} - -func (w watcherSet) delete(wa *watcher) { - if _, ok := w[wa]; !ok { - panic("removing missing watcher!") - } - delete(w, wa) -} - -type watcherSetByKey map[string]watcherSet - -func (w watcherSetByKey) add(wa *watcher) { - set := w[string(wa.key)] - if set == nil { - set = make(watcherSet) - w[string(wa.key)] = set - } - set.add(wa) -} - -func (w watcherSetByKey) delete(wa *watcher) bool { - k := string(wa.key) - if v, ok := w[k]; ok { - if _, ok := v[wa]; ok { - delete(v, wa) - if len(v) == 0 { - // remove the set; nothing left - delete(w, k) - } - return true - } - } - return false -} - -// watcherGroup is a collection of watchers organized by their ranges -type watcherGroup struct { - // keyWatchers has the watchers that watch on a single key - keyWatchers watcherSetByKey - // ranges has the watchers that watch a range; it is sorted by interval - ranges adt.IntervalTree - // watchers is the set of all watchers - watchers watcherSet -} - -func newWatcherGroup() watcherGroup { - return watcherGroup{ - keyWatchers: make(watcherSetByKey), - watchers: make(watcherSet), - } -} - -// add puts a watcher in the group. -func (wg *watcherGroup) add(wa *watcher) { - wg.watchers.add(wa) - if wa.end == nil { - wg.keyWatchers.add(wa) - return - } - - // interval already registered? - ivl := adt.NewStringAffineInterval(string(wa.key), string(wa.end)) - if iv := wg.ranges.Find(ivl); iv != nil { - iv.Val.(watcherSet).add(wa) - return - } - - // not registered, put in interval tree - ws := make(watcherSet) - ws.add(wa) - wg.ranges.Insert(ivl, ws) -} - -// contains is whether the given key has a watcher in the group. -func (wg *watcherGroup) contains(key string) bool { - _, ok := wg.keyWatchers[key] - return ok || wg.ranges.Intersects(adt.NewStringAffinePoint(key)) -} - -// size gives the number of unique watchers in the group. -func (wg *watcherGroup) size() int { return len(wg.watchers) } - -// delete removes a watcher from the group. -func (wg *watcherGroup) delete(wa *watcher) bool { - if _, ok := wg.watchers[wa]; !ok { - return false - } - wg.watchers.delete(wa) - if wa.end == nil { - wg.keyWatchers.delete(wa) - return true - } - - ivl := adt.NewStringAffineInterval(string(wa.key), string(wa.end)) - iv := wg.ranges.Find(ivl) - if iv == nil { - return false - } - - ws := iv.Val.(watcherSet) - delete(ws, wa) - if len(ws) == 0 { - // remove interval missing watchers - if ok := wg.ranges.Delete(ivl); !ok { - panic("could not remove watcher from interval tree") - } - } - - return true -} - -// choose selects watchers from the watcher group to update -func (wg *watcherGroup) choose(maxWatchers int, curRev, compactRev int64) (*watcherGroup, int64) { - if len(wg.watchers) < maxWatchers { - return wg, wg.chooseAll(curRev, compactRev) - } - ret := newWatcherGroup() - for w := range wg.watchers { - if maxWatchers <= 0 { - break - } - maxWatchers-- - ret.add(w) - } - return &ret, ret.chooseAll(curRev, compactRev) -} - -func (wg *watcherGroup) chooseAll(curRev, compactRev int64) int64 { - minRev := int64(math.MaxInt64) - for w := range wg.watchers { - if w.minRev > curRev { - // after network partition, possibly choosing future revision watcher from restore operation - // with watch key "proxy-namespace__lostleader" and revision "math.MaxInt64 - 2" - // do not panic when such watcher had been moved from "synced" watcher during restore operation - if !w.restore { - panic(fmt.Errorf("watcher minimum revision %d should not exceed current revision %d", w.minRev, curRev)) - } - - // mark 'restore' done, since it's chosen - w.restore = false - } - if w.minRev < compactRev { - select { - case w.ch <- WatchResponse{WatchID: w.id, CompactRevision: compactRev}: - w.compacted = true - wg.delete(w) - default: - // retry next time - } - continue - } - if minRev > w.minRev { - minRev = w.minRev - } - } - return minRev -} - -// watcherSetByKey gets the set of watchers that receive events on the given key. -func (wg *watcherGroup) watcherSetByKey(key string) watcherSet { - wkeys := wg.keyWatchers[key] - wranges := wg.ranges.Stab(adt.NewStringAffinePoint(key)) - - // zero-copy cases - switch { - case len(wranges) == 0: - // no need to merge ranges or copy; reuse single-key set - return wkeys - case len(wranges) == 0 && len(wkeys) == 0: - return nil - case len(wranges) == 1 && len(wkeys) == 0: - return wranges[0].Val.(watcherSet) - } - - // copy case - ret := make(watcherSet) - ret.union(wg.keyWatchers[key]) - for _, item := range wranges { - ret.union(item.Val.(watcherSet)) - } - return ret -} diff --git a/vendor/go.etcd.io/etcd/pkg/adt/doc.go b/vendor/go.etcd.io/etcd/pkg/adt/doc.go deleted file mode 100644 index 1a9559145b31..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/adt/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package adt implements useful abstract data types. -package adt diff --git a/vendor/go.etcd.io/etcd/pkg/adt/interval_tree.go b/vendor/go.etcd.io/etcd/pkg/adt/interval_tree.go deleted file mode 100644 index ec302e4a7a96..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/adt/interval_tree.go +++ /dev/null @@ -1,599 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adt - -import ( - "bytes" - "math" -) - -// Comparable is an interface for trichotomic comparisons. -type Comparable interface { - // Compare gives the result of a 3-way comparison - // a.Compare(b) = 1 => a > b - // a.Compare(b) = 0 => a == b - // a.Compare(b) = -1 => a < b - Compare(c Comparable) int -} - -type rbcolor int - -const ( - black rbcolor = iota - red -) - -// Interval implements a Comparable interval [begin, end) -// TODO: support different sorts of intervals: (a,b), [a,b], (a, b] -type Interval struct { - Begin Comparable - End Comparable -} - -// Compare on an interval gives == if the interval overlaps. -func (ivl *Interval) Compare(c Comparable) int { - ivl2 := c.(*Interval) - ivbCmpBegin := ivl.Begin.Compare(ivl2.Begin) - ivbCmpEnd := ivl.Begin.Compare(ivl2.End) - iveCmpBegin := ivl.End.Compare(ivl2.Begin) - - // ivl is left of ivl2 - if ivbCmpBegin < 0 && iveCmpBegin <= 0 { - return -1 - } - - // iv is right of iv2 - if ivbCmpEnd >= 0 { - return 1 - } - - return 0 -} - -type intervalNode struct { - // iv is the interval-value pair entry. - iv IntervalValue - // max endpoint of all descendent nodes. - max Comparable - // left and right are sorted by low endpoint of key interval - left, right *intervalNode - // parent is the direct ancestor of the node - parent *intervalNode - c rbcolor -} - -func (x *intervalNode) color() rbcolor { - if x == nil { - return black - } - return x.c -} - -func (n *intervalNode) height() int { - if n == nil { - return 0 - } - ld := n.left.height() - rd := n.right.height() - if ld < rd { - return rd + 1 - } - return ld + 1 -} - -func (x *intervalNode) min() *intervalNode { - for x.left != nil { - x = x.left - } - return x -} - -// successor is the next in-order node in the tree -func (x *intervalNode) successor() *intervalNode { - if x.right != nil { - return x.right.min() - } - y := x.parent - for y != nil && x == y.right { - x = y - y = y.parent - } - return y -} - -// updateMax updates the maximum values for a node and its ancestors -func (x *intervalNode) updateMax() { - for x != nil { - oldmax := x.max - max := x.iv.Ivl.End - if x.left != nil && x.left.max.Compare(max) > 0 { - max = x.left.max - } - if x.right != nil && x.right.max.Compare(max) > 0 { - max = x.right.max - } - if oldmax.Compare(max) == 0 { - break - } - x.max = max - x = x.parent - } -} - -type nodeVisitor func(n *intervalNode) bool - -// visit will call a node visitor on each node that overlaps the given interval -func (x *intervalNode) visit(iv *Interval, nv nodeVisitor) bool { - if x == nil { - return true - } - v := iv.Compare(&x.iv.Ivl) - switch { - case v < 0: - if !x.left.visit(iv, nv) { - return false - } - case v > 0: - maxiv := Interval{x.iv.Ivl.Begin, x.max} - if maxiv.Compare(iv) == 0 { - if !x.left.visit(iv, nv) || !x.right.visit(iv, nv) { - return false - } - } - default: - if !x.left.visit(iv, nv) || !nv(x) || !x.right.visit(iv, nv) { - return false - } - } - return true -} - -type IntervalValue struct { - Ivl Interval - Val interface{} -} - -// IntervalTree represents a (mostly) textbook implementation of the -// "Introduction to Algorithms" (Cormen et al, 2nd ed.) chapter 13 red-black tree -// and chapter 14.3 interval tree with search supporting "stabbing queries". -type IntervalTree struct { - root *intervalNode - count int -} - -// Delete removes the node with the given interval from the tree, returning -// true if a node is in fact removed. -func (ivt *IntervalTree) Delete(ivl Interval) bool { - z := ivt.find(ivl) - if z == nil { - return false - } - - y := z - if z.left != nil && z.right != nil { - y = z.successor() - } - - x := y.left - if x == nil { - x = y.right - } - if x != nil { - x.parent = y.parent - } - - if y.parent == nil { - ivt.root = x - } else { - if y == y.parent.left { - y.parent.left = x - } else { - y.parent.right = x - } - y.parent.updateMax() - } - if y != z { - z.iv = y.iv - z.updateMax() - } - - if y.color() == black && x != nil { - ivt.deleteFixup(x) - } - - ivt.count-- - return true -} - -func (ivt *IntervalTree) deleteFixup(x *intervalNode) { - for x != ivt.root && x.color() == black && x.parent != nil { - if x == x.parent.left { - w := x.parent.right - if w.color() == red { - w.c = black - x.parent.c = red - ivt.rotateLeft(x.parent) - w = x.parent.right - } - if w == nil { - break - } - if w.left.color() == black && w.right.color() == black { - w.c = red - x = x.parent - } else { - if w.right.color() == black { - w.left.c = black - w.c = red - ivt.rotateRight(w) - w = x.parent.right - } - w.c = x.parent.color() - x.parent.c = black - w.right.c = black - ivt.rotateLeft(x.parent) - x = ivt.root - } - } else { - // same as above but with left and right exchanged - w := x.parent.left - if w.color() == red { - w.c = black - x.parent.c = red - ivt.rotateRight(x.parent) - w = x.parent.left - } - if w == nil { - break - } - if w.left.color() == black && w.right.color() == black { - w.c = red - x = x.parent - } else { - if w.left.color() == black { - w.right.c = black - w.c = red - ivt.rotateLeft(w) - w = x.parent.left - } - w.c = x.parent.color() - x.parent.c = black - w.left.c = black - ivt.rotateRight(x.parent) - x = ivt.root - } - } - } - if x != nil { - x.c = black - } -} - -// Insert adds a node with the given interval into the tree. -func (ivt *IntervalTree) Insert(ivl Interval, val interface{}) { - var y *intervalNode - z := &intervalNode{iv: IntervalValue{ivl, val}, max: ivl.End, c: red} - x := ivt.root - for x != nil { - y = x - if z.iv.Ivl.Begin.Compare(x.iv.Ivl.Begin) < 0 { - x = x.left - } else { - x = x.right - } - } - - z.parent = y - if y == nil { - ivt.root = z - } else { - if z.iv.Ivl.Begin.Compare(y.iv.Ivl.Begin) < 0 { - y.left = z - } else { - y.right = z - } - y.updateMax() - } - z.c = red - ivt.insertFixup(z) - ivt.count++ -} - -func (ivt *IntervalTree) insertFixup(z *intervalNode) { - for z.parent != nil && z.parent.parent != nil && z.parent.color() == red { - if z.parent == z.parent.parent.left { - y := z.parent.parent.right - if y.color() == red { - y.c = black - z.parent.c = black - z.parent.parent.c = red - z = z.parent.parent - } else { - if z == z.parent.right { - z = z.parent - ivt.rotateLeft(z) - } - z.parent.c = black - z.parent.parent.c = red - ivt.rotateRight(z.parent.parent) - } - } else { - // same as then with left/right exchanged - y := z.parent.parent.left - if y.color() == red { - y.c = black - z.parent.c = black - z.parent.parent.c = red - z = z.parent.parent - } else { - if z == z.parent.left { - z = z.parent - ivt.rotateRight(z) - } - z.parent.c = black - z.parent.parent.c = red - ivt.rotateLeft(z.parent.parent) - } - } - } - ivt.root.c = black -} - -// rotateLeft moves x so it is left of its right child -func (ivt *IntervalTree) rotateLeft(x *intervalNode) { - y := x.right - x.right = y.left - if y.left != nil { - y.left.parent = x - } - x.updateMax() - ivt.replaceParent(x, y) - y.left = x - y.updateMax() -} - -// rotateLeft moves x so it is right of its left child -func (ivt *IntervalTree) rotateRight(x *intervalNode) { - if x == nil { - return - } - y := x.left - x.left = y.right - if y.right != nil { - y.right.parent = x - } - x.updateMax() - ivt.replaceParent(x, y) - y.right = x - y.updateMax() -} - -// replaceParent replaces x's parent with y -func (ivt *IntervalTree) replaceParent(x *intervalNode, y *intervalNode) { - y.parent = x.parent - if x.parent == nil { - ivt.root = y - } else { - if x == x.parent.left { - x.parent.left = y - } else { - x.parent.right = y - } - x.parent.updateMax() - } - x.parent = y -} - -// Len gives the number of elements in the tree -func (ivt *IntervalTree) Len() int { return ivt.count } - -// Height is the number of levels in the tree; one node has height 1. -func (ivt *IntervalTree) Height() int { return ivt.root.height() } - -// MaxHeight is the expected maximum tree height given the number of nodes -func (ivt *IntervalTree) MaxHeight() int { - return int((2 * math.Log2(float64(ivt.Len()+1))) + 0.5) -} - -// IntervalVisitor is used on tree searches; return false to stop searching. -type IntervalVisitor func(n *IntervalValue) bool - -// Visit calls a visitor function on every tree node intersecting the given interval. -// It will visit each interval [x, y) in ascending order sorted on x. -func (ivt *IntervalTree) Visit(ivl Interval, ivv IntervalVisitor) { - ivt.root.visit(&ivl, func(n *intervalNode) bool { return ivv(&n.iv) }) -} - -// find the exact node for a given interval -func (ivt *IntervalTree) find(ivl Interval) (ret *intervalNode) { - f := func(n *intervalNode) bool { - if n.iv.Ivl != ivl { - return true - } - ret = n - return false - } - ivt.root.visit(&ivl, f) - return ret -} - -// Find gets the IntervalValue for the node matching the given interval -func (ivt *IntervalTree) Find(ivl Interval) (ret *IntervalValue) { - n := ivt.find(ivl) - if n == nil { - return nil - } - return &n.iv -} - -// Intersects returns true if there is some tree node intersecting the given interval. -func (ivt *IntervalTree) Intersects(iv Interval) bool { - x := ivt.root - for x != nil && iv.Compare(&x.iv.Ivl) != 0 { - if x.left != nil && x.left.max.Compare(iv.Begin) > 0 { - x = x.left - } else { - x = x.right - } - } - return x != nil -} - -// Contains returns true if the interval tree's keys cover the entire given interval. -func (ivt *IntervalTree) Contains(ivl Interval) bool { - var maxEnd, minBegin Comparable - - isContiguous := true - ivt.Visit(ivl, func(n *IntervalValue) bool { - if minBegin == nil { - minBegin = n.Ivl.Begin - maxEnd = n.Ivl.End - return true - } - if maxEnd.Compare(n.Ivl.Begin) < 0 { - isContiguous = false - return false - } - if n.Ivl.End.Compare(maxEnd) > 0 { - maxEnd = n.Ivl.End - } - return true - }) - - return isContiguous && minBegin != nil && maxEnd.Compare(ivl.End) >= 0 && minBegin.Compare(ivl.Begin) <= 0 -} - -// Stab returns a slice with all elements in the tree intersecting the interval. -func (ivt *IntervalTree) Stab(iv Interval) (ivs []*IntervalValue) { - if ivt.count == 0 { - return nil - } - f := func(n *IntervalValue) bool { ivs = append(ivs, n); return true } - ivt.Visit(iv, f) - return ivs -} - -// Union merges a given interval tree into the receiver. -func (ivt *IntervalTree) Union(inIvt IntervalTree, ivl Interval) { - f := func(n *IntervalValue) bool { - ivt.Insert(n.Ivl, n.Val) - return true - } - inIvt.Visit(ivl, f) -} - -type StringComparable string - -func (s StringComparable) Compare(c Comparable) int { - sc := c.(StringComparable) - if s < sc { - return -1 - } - if s > sc { - return 1 - } - return 0 -} - -func NewStringInterval(begin, end string) Interval { - return Interval{StringComparable(begin), StringComparable(end)} -} - -func NewStringPoint(s string) Interval { - return Interval{StringComparable(s), StringComparable(s + "\x00")} -} - -// StringAffineComparable treats "" as > all other strings -type StringAffineComparable string - -func (s StringAffineComparable) Compare(c Comparable) int { - sc := c.(StringAffineComparable) - - if len(s) == 0 { - if len(sc) == 0 { - return 0 - } - return 1 - } - if len(sc) == 0 { - return -1 - } - - if s < sc { - return -1 - } - if s > sc { - return 1 - } - return 0 -} - -func NewStringAffineInterval(begin, end string) Interval { - return Interval{StringAffineComparable(begin), StringAffineComparable(end)} -} -func NewStringAffinePoint(s string) Interval { - return NewStringAffineInterval(s, s+"\x00") -} - -func NewInt64Interval(a int64, b int64) Interval { - return Interval{Int64Comparable(a), Int64Comparable(b)} -} - -func NewInt64Point(a int64) Interval { - return Interval{Int64Comparable(a), Int64Comparable(a + 1)} -} - -type Int64Comparable int64 - -func (v Int64Comparable) Compare(c Comparable) int { - vc := c.(Int64Comparable) - cmp := v - vc - if cmp < 0 { - return -1 - } - if cmp > 0 { - return 1 - } - return 0 -} - -// BytesAffineComparable treats empty byte arrays as > all other byte arrays -type BytesAffineComparable []byte - -func (b BytesAffineComparable) Compare(c Comparable) int { - bc := c.(BytesAffineComparable) - - if len(b) == 0 { - if len(bc) == 0 { - return 0 - } - return 1 - } - if len(bc) == 0 { - return -1 - } - - return bytes.Compare(b, bc) -} - -func NewBytesAffineInterval(begin, end []byte) Interval { - return Interval{BytesAffineComparable(begin), BytesAffineComparable(end)} -} -func NewBytesAffinePoint(b []byte) Interval { - be := make([]byte, len(b)+1) - copy(be, b) - be[len(b)] = 0 - return NewBytesAffineInterval(b, be) -} diff --git a/vendor/go.etcd.io/etcd/pkg/contention/contention.go b/vendor/go.etcd.io/etcd/pkg/contention/contention.go deleted file mode 100644 index 26ce9a2f3473..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/contention/contention.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package contention - -import ( - "sync" - "time" -) - -// TimeoutDetector detects routine starvations by -// observing the actual time duration to finish an action -// or between two events that should happen in a fixed -// interval. If the observed duration is longer than -// the expectation, the detector will report the result. -type TimeoutDetector struct { - mu sync.Mutex // protects all - maxDuration time.Duration - // map from event to time - // time is the last seen time of the event. - records map[uint64]time.Time -} - -// NewTimeoutDetector creates the TimeoutDetector. -func NewTimeoutDetector(maxDuration time.Duration) *TimeoutDetector { - return &TimeoutDetector{ - maxDuration: maxDuration, - records: make(map[uint64]time.Time), - } -} - -// Reset resets the NewTimeoutDetector. -func (td *TimeoutDetector) Reset() { - td.mu.Lock() - defer td.mu.Unlock() - - td.records = make(map[uint64]time.Time) -} - -// Observe observes an event for given id. It returns false and exceeded duration -// if the interval is longer than the expectation. -func (td *TimeoutDetector) Observe(which uint64) (bool, time.Duration) { - td.mu.Lock() - defer td.mu.Unlock() - - ok := true - now := time.Now() - exceed := time.Duration(0) - - if pt, found := td.records[which]; found { - exceed = now.Sub(pt) - td.maxDuration - if exceed > 0 { - ok = false - } - } - td.records[which] = now - return ok, exceed -} diff --git a/vendor/go.etcd.io/etcd/pkg/contention/doc.go b/vendor/go.etcd.io/etcd/pkg/contention/doc.go deleted file mode 100644 index daf452219e07..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/contention/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package contention provides facilities for detecting system contention. -package contention diff --git a/vendor/go.etcd.io/etcd/pkg/cpuutil/doc.go b/vendor/go.etcd.io/etcd/pkg/cpuutil/doc.go deleted file mode 100644 index 0323b2d34c64..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/cpuutil/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package cpuutil provides facilities for detecting cpu-specific features. -package cpuutil diff --git a/vendor/go.etcd.io/etcd/pkg/cpuutil/endian.go b/vendor/go.etcd.io/etcd/pkg/cpuutil/endian.go deleted file mode 100644 index 6ab898d4b596..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/cpuutil/endian.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package cpuutil - -import ( - "encoding/binary" - "unsafe" -) - -const intWidth int = int(unsafe.Sizeof(0)) - -var byteOrder binary.ByteOrder - -// ByteOrder returns the byte order for the CPU's native endianness. -func ByteOrder() binary.ByteOrder { return byteOrder } - -func init() { - var i int = 0x1 - if v := (*[intWidth]byte)(unsafe.Pointer(&i)); v[0] == 0 { - byteOrder = binary.BigEndian - } else { - byteOrder = binary.LittleEndian - } -} diff --git a/vendor/go.etcd.io/etcd/pkg/crc/crc.go b/vendor/go.etcd.io/etcd/pkg/crc/crc.go deleted file mode 100644 index 4b998a48455f..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/crc/crc.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package crc provides utility function for cyclic redundancy check -// algorithms. -package crc - -import ( - "hash" - "hash/crc32" -) - -// The size of a CRC-32 checksum in bytes. -const Size = 4 - -type digest struct { - crc uint32 - tab *crc32.Table -} - -// New creates a new hash.Hash32 computing the CRC-32 checksum -// using the polynomial represented by the Table. -// Modified by xiangli to take a prevcrc. -func New(prev uint32, tab *crc32.Table) hash.Hash32 { return &digest{prev, tab} } - -func (d *digest) Size() int { return Size } - -func (d *digest) BlockSize() int { return 1 } - -func (d *digest) Reset() { d.crc = 0 } - -func (d *digest) Write(p []byte) (n int, err error) { - d.crc = crc32.Update(d.crc, d.tab, p) - return len(p), nil -} - -func (d *digest) Sum32() uint32 { return d.crc } - -func (d *digest) Sum(in []byte) []byte { - s := d.Sum32() - return append(in, byte(s>>24), byte(s>>16), byte(s>>8), byte(s)) -} diff --git a/vendor/go.etcd.io/etcd/pkg/debugutil/doc.go b/vendor/go.etcd.io/etcd/pkg/debugutil/doc.go deleted file mode 100644 index 74499eb2737e..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/debugutil/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package debugutil includes utility functions for debugging. -package debugutil diff --git a/vendor/go.etcd.io/etcd/pkg/debugutil/pprof.go b/vendor/go.etcd.io/etcd/pkg/debugutil/pprof.go deleted file mode 100644 index 8d5544a3dcac..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/debugutil/pprof.go +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package debugutil - -import ( - "net/http" - "net/http/pprof" - "runtime" -) - -const HTTPPrefixPProf = "/debug/pprof" - -// PProfHandlers returns a map of pprof handlers keyed by the HTTP path. -func PProfHandlers() map[string]http.Handler { - // set only when there's no existing setting - if runtime.SetMutexProfileFraction(-1) == 0 { - // 1 out of 5 mutex events are reported, on average - runtime.SetMutexProfileFraction(5) - } - - m := make(map[string]http.Handler) - - m[HTTPPrefixPProf+"/"] = http.HandlerFunc(pprof.Index) - m[HTTPPrefixPProf+"/profile"] = http.HandlerFunc(pprof.Profile) - m[HTTPPrefixPProf+"/symbol"] = http.HandlerFunc(pprof.Symbol) - m[HTTPPrefixPProf+"/cmdline"] = http.HandlerFunc(pprof.Cmdline) - m[HTTPPrefixPProf+"/trace "] = http.HandlerFunc(pprof.Trace) - m[HTTPPrefixPProf+"/heap"] = pprof.Handler("heap") - m[HTTPPrefixPProf+"/goroutine"] = pprof.Handler("goroutine") - m[HTTPPrefixPProf+"/threadcreate"] = pprof.Handler("threadcreate") - m[HTTPPrefixPProf+"/block"] = pprof.Handler("block") - m[HTTPPrefixPProf+"/mutex"] = pprof.Handler("mutex") - - return m -} diff --git a/vendor/go.etcd.io/etcd/pkg/expect/expect.go b/vendor/go.etcd.io/etcd/pkg/expect/expect.go deleted file mode 100644 index e0227986b987..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/expect/expect.go +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package expect implements a small expect-style interface -package expect - -import ( - "bufio" - "fmt" - "io" - "os" - "os/exec" - "strings" - "sync" - "syscall" - - "github.com/kr/pty" -) - -type ExpectProcess struct { - cmd *exec.Cmd - fpty *os.File - wg sync.WaitGroup - - cond *sync.Cond // for broadcasting updates are available - mu sync.Mutex // protects lines and err - lines []string - count int // increment whenever new line gets added - err error - - // StopSignal is the signal Stop sends to the process; defaults to SIGKILL. - StopSignal os.Signal -} - -// NewExpect creates a new process for expect testing. -func NewExpect(name string, arg ...string) (ep *ExpectProcess, err error) { - // if env[] is nil, use current system env - return NewExpectWithEnv(name, arg, nil) -} - -// NewExpectWithEnv creates a new process with user defined env variables for expect testing. -func NewExpectWithEnv(name string, args []string, env []string) (ep *ExpectProcess, err error) { - cmd := exec.Command(name, args...) - cmd.Env = env - ep = &ExpectProcess{ - cmd: cmd, - StopSignal: syscall.SIGKILL, - } - ep.cond = sync.NewCond(&ep.mu) - ep.cmd.Stderr = ep.cmd.Stdout - ep.cmd.Stdin = nil - - if ep.fpty, err = pty.Start(ep.cmd); err != nil { - return nil, err - } - - ep.wg.Add(1) - go ep.read() - return ep, nil -} - -func (ep *ExpectProcess) read() { - defer ep.wg.Done() - printDebugLines := os.Getenv("EXPECT_DEBUG") != "" - r := bufio.NewReader(ep.fpty) - for ep.err == nil { - l, rerr := r.ReadString('\n') - ep.mu.Lock() - ep.err = rerr - if l != "" { - if printDebugLines { - fmt.Printf("%s-%d: %s", ep.cmd.Path, ep.cmd.Process.Pid, l) - } - ep.lines = append(ep.lines, l) - ep.count++ - if len(ep.lines) == 1 { - ep.cond.Signal() - } - } - ep.mu.Unlock() - } - ep.cond.Signal() -} - -// ExpectFunc returns the first line satisfying the function f. -func (ep *ExpectProcess) ExpectFunc(f func(string) bool) (string, error) { - ep.mu.Lock() - for { - for len(ep.lines) == 0 && ep.err == nil { - ep.cond.Wait() - } - if len(ep.lines) == 0 { - break - } - l := ep.lines[0] - ep.lines = ep.lines[1:] - if f(l) { - ep.mu.Unlock() - return l, nil - } - } - ep.mu.Unlock() - return "", ep.err -} - -// Expect returns the first line containing the given string. -func (ep *ExpectProcess) Expect(s string) (string, error) { - return ep.ExpectFunc(func(txt string) bool { return strings.Contains(txt, s) }) -} - -// LineCount returns the number of recorded lines since -// the beginning of the process. -func (ep *ExpectProcess) LineCount() int { - ep.mu.Lock() - defer ep.mu.Unlock() - return ep.count -} - -// Stop kills the expect process and waits for it to exit. -func (ep *ExpectProcess) Stop() error { return ep.close(true) } - -// Signal sends a signal to the expect process -func (ep *ExpectProcess) Signal(sig os.Signal) error { - return ep.cmd.Process.Signal(sig) -} - -// Close waits for the expect process to exit. -func (ep *ExpectProcess) Close() error { return ep.close(false) } - -func (ep *ExpectProcess) close(kill bool) error { - if ep.cmd == nil { - return ep.err - } - if kill { - ep.Signal(ep.StopSignal) - } - - err := ep.cmd.Wait() - ep.fpty.Close() - ep.wg.Wait() - - if err != nil { - ep.err = err - if !kill && strings.Contains(err.Error(), "exit status") { - // non-zero exit code - err = nil - } else if kill && strings.Contains(err.Error(), "signal:") { - err = nil - } - } - ep.cmd = nil - return err -} - -func (ep *ExpectProcess) Send(command string) error { - _, err := io.WriteString(ep.fpty, command) - return err -} diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/dir_unix.go b/vendor/go.etcd.io/etcd/pkg/fileutil/dir_unix.go deleted file mode 100644 index 58a77dfc1a99..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/dir_unix.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !windows - -package fileutil - -import "os" - -// OpenDir opens a directory for syncing. -func OpenDir(path string) (*os.File, error) { return os.Open(path) } diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/dir_windows.go b/vendor/go.etcd.io/etcd/pkg/fileutil/dir_windows.go deleted file mode 100644 index c123395c0040..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/dir_windows.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build windows - -package fileutil - -import ( - "os" - "syscall" -) - -// OpenDir opens a directory in windows with write access for syncing. -func OpenDir(path string) (*os.File, error) { - fd, err := openDir(path) - if err != nil { - return nil, err - } - return os.NewFile(uintptr(fd), path), nil -} - -func openDir(path string) (fd syscall.Handle, err error) { - if len(path) == 0 { - return syscall.InvalidHandle, syscall.ERROR_FILE_NOT_FOUND - } - pathp, err := syscall.UTF16PtrFromString(path) - if err != nil { - return syscall.InvalidHandle, err - } - access := uint32(syscall.GENERIC_READ | syscall.GENERIC_WRITE) - sharemode := uint32(syscall.FILE_SHARE_READ | syscall.FILE_SHARE_WRITE) - createmode := uint32(syscall.OPEN_EXISTING) - fl := uint32(syscall.FILE_FLAG_BACKUP_SEMANTICS) - return syscall.CreateFile(pathp, access, sharemode, nil, createmode, fl, 0) -} diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/fileutil.go b/vendor/go.etcd.io/etcd/pkg/fileutil/fileutil.go deleted file mode 100644 index fce5126c6956..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/fileutil.go +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package fileutil implements utility functions related to files and paths. -package fileutil - -import ( - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "sort" - - "github.com/coreos/pkg/capnslog" -) - -const ( - // PrivateFileMode grants owner to read/write a file. - PrivateFileMode = 0600 - // PrivateDirMode grants owner to make/remove files inside the directory. - PrivateDirMode = 0700 -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "pkg/fileutil") -) - -// IsDirWriteable checks if dir is writable by writing and removing a file -// to dir. It returns nil if dir is writable. -func IsDirWriteable(dir string) error { - f := filepath.Join(dir, ".touch") - if err := ioutil.WriteFile(f, []byte(""), PrivateFileMode); err != nil { - return err - } - return os.Remove(f) -} - -// ReadDir returns the filenames in the given directory in sorted order. -func ReadDir(dirpath string) ([]string, error) { - dir, err := os.Open(dirpath) - if err != nil { - return nil, err - } - defer dir.Close() - names, err := dir.Readdirnames(-1) - if err != nil { - return nil, err - } - sort.Strings(names) - return names, nil -} - -// TouchDirAll is similar to os.MkdirAll. It creates directories with 0700 permission if any directory -// does not exists. TouchDirAll also ensures the given directory is writable. -func TouchDirAll(dir string) error { - // If path is already a directory, MkdirAll does nothing - // and returns nil. - err := os.MkdirAll(dir, PrivateDirMode) - if err != nil { - // if mkdirAll("a/text") and "text" is not - // a directory, this will return syscall.ENOTDIR - return err - } - return IsDirWriteable(dir) -} - -// CreateDirAll is similar to TouchDirAll but returns error -// if the deepest directory was not empty. -func CreateDirAll(dir string) error { - err := TouchDirAll(dir) - if err == nil { - var ns []string - ns, err = ReadDir(dir) - if err != nil { - return err - } - if len(ns) != 0 { - err = fmt.Errorf("expected %q to be empty, got %q", dir, ns) - } - } - return err -} - -func Exist(name string) bool { - _, err := os.Stat(name) - return err == nil -} - -// ZeroToEnd zeros a file starting from SEEK_CUR to its SEEK_END. May temporarily -// shorten the length of the file. -func ZeroToEnd(f *os.File) error { - // TODO: support FALLOC_FL_ZERO_RANGE - off, err := f.Seek(0, io.SeekCurrent) - if err != nil { - return err - } - lenf, lerr := f.Seek(0, io.SeekEnd) - if lerr != nil { - return lerr - } - if err = f.Truncate(off); err != nil { - return err - } - // make sure blocks remain allocated - if err = Preallocate(f, lenf, true); err != nil { - return err - } - _, err = f.Seek(off, io.SeekStart) - return err -} diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/lock.go b/vendor/go.etcd.io/etcd/pkg/fileutil/lock.go deleted file mode 100644 index 338627f43c88..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/lock.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fileutil - -import ( - "errors" - "os" -) - -var ( - ErrLocked = errors.New("fileutil: file already locked") -) - -type LockedFile struct{ *os.File } diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/lock_flock.go b/vendor/go.etcd.io/etcd/pkg/fileutil/lock_flock.go deleted file mode 100644 index 542550bc8a96..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/lock_flock.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !windows,!plan9,!solaris - -package fileutil - -import ( - "os" - "syscall" -) - -func flockTryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - f, err := os.OpenFile(path, flag, perm) - if err != nil { - return nil, err - } - if err = syscall.Flock(int(f.Fd()), syscall.LOCK_EX|syscall.LOCK_NB); err != nil { - f.Close() - if err == syscall.EWOULDBLOCK { - err = ErrLocked - } - return nil, err - } - return &LockedFile{f}, nil -} - -func flockLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - f, err := os.OpenFile(path, flag, perm) - if err != nil { - return nil, err - } - if err = syscall.Flock(int(f.Fd()), syscall.LOCK_EX); err != nil { - f.Close() - return nil, err - } - return &LockedFile{f}, err -} diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/lock_linux.go b/vendor/go.etcd.io/etcd/pkg/fileutil/lock_linux.go deleted file mode 100644 index 939fea623818..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/lock_linux.go +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build linux - -package fileutil - -import ( - "io" - "os" - "syscall" -) - -// This used to call syscall.Flock() but that call fails with EBADF on NFS. -// An alternative is lockf() which works on NFS but that call lets a process lock -// the same file twice. Instead, use Linux's non-standard open file descriptor -// locks which will block if the process already holds the file lock. -// -// constants from /usr/include/bits/fcntl-linux.h -const ( - F_OFD_GETLK = 37 - F_OFD_SETLK = 37 - F_OFD_SETLKW = 38 -) - -var ( - wrlck = syscall.Flock_t{ - Type: syscall.F_WRLCK, - Whence: int16(io.SeekStart), - Start: 0, - Len: 0, - } - - linuxTryLockFile = flockTryLockFile - linuxLockFile = flockLockFile -) - -func init() { - // use open file descriptor locks if the system supports it - getlk := syscall.Flock_t{Type: syscall.F_RDLCK} - if err := syscall.FcntlFlock(0, F_OFD_GETLK, &getlk); err == nil { - linuxTryLockFile = ofdTryLockFile - linuxLockFile = ofdLockFile - } -} - -func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - return linuxTryLockFile(path, flag, perm) -} - -func ofdTryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - f, err := os.OpenFile(path, flag, perm) - if err != nil { - return nil, err - } - - flock := wrlck - if err = syscall.FcntlFlock(f.Fd(), F_OFD_SETLK, &flock); err != nil { - f.Close() - if err == syscall.EWOULDBLOCK { - err = ErrLocked - } - return nil, err - } - return &LockedFile{f}, nil -} - -func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - return linuxLockFile(path, flag, perm) -} - -func ofdLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - f, err := os.OpenFile(path, flag, perm) - if err != nil { - return nil, err - } - - flock := wrlck - err = syscall.FcntlFlock(f.Fd(), F_OFD_SETLKW, &flock) - - if err != nil { - f.Close() - return nil, err - } - return &LockedFile{f}, err -} diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/lock_plan9.go b/vendor/go.etcd.io/etcd/pkg/fileutil/lock_plan9.go deleted file mode 100644 index fee6a7c8f466..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/lock_plan9.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fileutil - -import ( - "os" - "syscall" - "time" -) - -func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - if err := os.Chmod(path, syscall.DMEXCL|PrivateFileMode); err != nil { - return nil, err - } - f, err := os.Open(path, flag, perm) - if err != nil { - return nil, ErrLocked - } - return &LockedFile{f}, nil -} - -func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - if err := os.Chmod(path, syscall.DMEXCL|PrivateFileMode); err != nil { - return nil, err - } - for { - f, err := os.OpenFile(path, flag, perm) - if err == nil { - return &LockedFile{f}, nil - } - time.Sleep(10 * time.Millisecond) - } -} diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/lock_solaris.go b/vendor/go.etcd.io/etcd/pkg/fileutil/lock_solaris.go deleted file mode 100644 index 352ca5590d13..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/lock_solaris.go +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build solaris - -package fileutil - -import ( - "os" - "syscall" -) - -func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - var lock syscall.Flock_t - lock.Start = 0 - lock.Len = 0 - lock.Pid = 0 - lock.Type = syscall.F_WRLCK - lock.Whence = 0 - lock.Pid = 0 - f, err := os.OpenFile(path, flag, perm) - if err != nil { - return nil, err - } - if err := syscall.FcntlFlock(f.Fd(), syscall.F_SETLK, &lock); err != nil { - f.Close() - if err == syscall.EAGAIN { - err = ErrLocked - } - return nil, err - } - return &LockedFile{f}, nil -} - -func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - var lock syscall.Flock_t - lock.Start = 0 - lock.Len = 0 - lock.Pid = 0 - lock.Type = syscall.F_WRLCK - lock.Whence = 0 - f, err := os.OpenFile(path, flag, perm) - if err != nil { - return nil, err - } - if err = syscall.FcntlFlock(f.Fd(), syscall.F_SETLKW, &lock); err != nil { - f.Close() - return nil, err - } - return &LockedFile{f}, nil -} diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/lock_unix.go b/vendor/go.etcd.io/etcd/pkg/fileutil/lock_unix.go deleted file mode 100644 index ed01164de6e4..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/lock_unix.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !windows,!plan9,!solaris,!linux - -package fileutil - -import ( - "os" -) - -func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - return flockTryLockFile(path, flag, perm) -} - -func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - return flockLockFile(path, flag, perm) -} diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/lock_windows.go b/vendor/go.etcd.io/etcd/pkg/fileutil/lock_windows.go deleted file mode 100644 index b1817230a3cf..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/lock_windows.go +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build windows - -package fileutil - -import ( - "errors" - "fmt" - "os" - "syscall" - "unsafe" -) - -var ( - modkernel32 = syscall.NewLazyDLL("kernel32.dll") - procLockFileEx = modkernel32.NewProc("LockFileEx") - - errLocked = errors.New("The process cannot access the file because another process has locked a portion of the file.") -) - -const ( - // https://msdn.microsoft.com/en-us/library/windows/desktop/aa365203(v=vs.85).aspx - LOCKFILE_EXCLUSIVE_LOCK = 2 - LOCKFILE_FAIL_IMMEDIATELY = 1 - - // see https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx - errLockViolation syscall.Errno = 0x21 -) - -func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - f, err := open(path, flag, perm) - if err != nil { - return nil, err - } - if err := lockFile(syscall.Handle(f.Fd()), LOCKFILE_FAIL_IMMEDIATELY); err != nil { - f.Close() - return nil, err - } - return &LockedFile{f}, nil -} - -func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - f, err := open(path, flag, perm) - if err != nil { - return nil, err - } - if err := lockFile(syscall.Handle(f.Fd()), 0); err != nil { - f.Close() - return nil, err - } - return &LockedFile{f}, nil -} - -func open(path string, flag int, perm os.FileMode) (*os.File, error) { - if path == "" { - return nil, fmt.Errorf("cannot open empty filename") - } - var access uint32 - switch flag { - case syscall.O_RDONLY: - access = syscall.GENERIC_READ - case syscall.O_WRONLY: - access = syscall.GENERIC_WRITE - case syscall.O_RDWR: - access = syscall.GENERIC_READ | syscall.GENERIC_WRITE - case syscall.O_WRONLY | syscall.O_CREAT: - access = syscall.GENERIC_ALL - default: - panic(fmt.Errorf("flag %v is not supported", flag)) - } - fd, err := syscall.CreateFile(&(syscall.StringToUTF16(path)[0]), - access, - syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE, - nil, - syscall.OPEN_ALWAYS, - syscall.FILE_ATTRIBUTE_NORMAL, - 0) - if err != nil { - return nil, err - } - return os.NewFile(uintptr(fd), path), nil -} - -func lockFile(fd syscall.Handle, flags uint32) error { - var flag uint32 = LOCKFILE_EXCLUSIVE_LOCK - flag |= flags - if fd == syscall.InvalidHandle { - return nil - } - err := lockFileEx(fd, flag, 1, 0, &syscall.Overlapped{}) - if err == nil { - return nil - } else if err.Error() == errLocked.Error() { - return ErrLocked - } else if err != errLockViolation { - return err - } - return nil -} - -func lockFileEx(h syscall.Handle, flags, locklow, lockhigh uint32, ol *syscall.Overlapped) (err error) { - var reserved uint32 = 0 - r1, _, e1 := syscall.Syscall6(procLockFileEx.Addr(), 6, uintptr(h), uintptr(flags), uintptr(reserved), uintptr(locklow), uintptr(lockhigh), uintptr(unsafe.Pointer(ol))) - if r1 == 0 { - if e1 != 0 { - err = error(e1) - } else { - err = syscall.EINVAL - } - } - return err -} diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/preallocate.go b/vendor/go.etcd.io/etcd/pkg/fileutil/preallocate.go deleted file mode 100644 index c747b7cf81f9..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/preallocate.go +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fileutil - -import ( - "io" - "os" -) - -// Preallocate tries to allocate the space for given -// file. This operation is only supported on linux by a -// few filesystems (btrfs, ext4, etc.). -// If the operation is unsupported, no error will be returned. -// Otherwise, the error encountered will be returned. -func Preallocate(f *os.File, sizeInBytes int64, extendFile bool) error { - if sizeInBytes == 0 { - // fallocate will return EINVAL if length is 0; skip - return nil - } - if extendFile { - return preallocExtend(f, sizeInBytes) - } - return preallocFixed(f, sizeInBytes) -} - -func preallocExtendTrunc(f *os.File, sizeInBytes int64) error { - curOff, err := f.Seek(0, io.SeekCurrent) - if err != nil { - return err - } - size, err := f.Seek(sizeInBytes, io.SeekEnd) - if err != nil { - return err - } - if _, err = f.Seek(curOff, io.SeekStart); err != nil { - return err - } - if sizeInBytes > size { - return nil - } - return f.Truncate(sizeInBytes) -} diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/preallocate_darwin.go b/vendor/go.etcd.io/etcd/pkg/fileutil/preallocate_darwin.go deleted file mode 100644 index 5a6dccfa796f..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/preallocate_darwin.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build darwin - -package fileutil - -import ( - "os" - "syscall" - "unsafe" -) - -func preallocExtend(f *os.File, sizeInBytes int64) error { - if err := preallocFixed(f, sizeInBytes); err != nil { - return err - } - return preallocExtendTrunc(f, sizeInBytes) -} - -func preallocFixed(f *os.File, sizeInBytes int64) error { - // allocate all requested space or no space at all - // TODO: allocate contiguous space on disk with F_ALLOCATECONTIG flag - fstore := &syscall.Fstore_t{ - Flags: syscall.F_ALLOCATEALL, - Posmode: syscall.F_PEOFPOSMODE, - Length: sizeInBytes} - p := unsafe.Pointer(fstore) - _, _, errno := syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), uintptr(syscall.F_PREALLOCATE), uintptr(p)) - if errno == 0 || errno == syscall.ENOTSUP { - return nil - } - - // wrong argument to fallocate syscall - if errno == syscall.EINVAL { - // filesystem "st_blocks" are allocated in the units of - // "Allocation Block Size" (run "diskutil info /" command) - var stat syscall.Stat_t - syscall.Fstat(int(f.Fd()), &stat) - - // syscall.Statfs_t.Bsize is "optimal transfer block size" - // and contains matching 4096 value when latest OS X kernel - // supports 4,096 KB filesystem block size - var statfs syscall.Statfs_t - syscall.Fstatfs(int(f.Fd()), &statfs) - blockSize := int64(statfs.Bsize) - - if stat.Blocks*blockSize >= sizeInBytes { - // enough blocks are already allocated - return nil - } - } - return errno -} diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/preallocate_unix.go b/vendor/go.etcd.io/etcd/pkg/fileutil/preallocate_unix.go deleted file mode 100644 index 50bd84f02ada..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/preallocate_unix.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build linux - -package fileutil - -import ( - "os" - "syscall" -) - -func preallocExtend(f *os.File, sizeInBytes int64) error { - // use mode = 0 to change size - err := syscall.Fallocate(int(f.Fd()), 0, 0, sizeInBytes) - if err != nil { - errno, ok := err.(syscall.Errno) - // not supported; fallback - // fallocate EINTRs frequently in some environments; fallback - if ok && (errno == syscall.ENOTSUP || errno == syscall.EINTR) { - return preallocExtendTrunc(f, sizeInBytes) - } - } - return err -} - -func preallocFixed(f *os.File, sizeInBytes int64) error { - // use mode = 1 to keep size; see FALLOC_FL_KEEP_SIZE - err := syscall.Fallocate(int(f.Fd()), 1, 0, sizeInBytes) - if err != nil { - errno, ok := err.(syscall.Errno) - // treat not supported as nil error - if ok && errno == syscall.ENOTSUP { - return nil - } - } - return err -} diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/preallocate_unsupported.go b/vendor/go.etcd.io/etcd/pkg/fileutil/preallocate_unsupported.go deleted file mode 100644 index 162fbc5f7826..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/preallocate_unsupported.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !linux,!darwin - -package fileutil - -import "os" - -func preallocExtend(f *os.File, sizeInBytes int64) error { - return preallocExtendTrunc(f, sizeInBytes) -} - -func preallocFixed(f *os.File, sizeInBytes int64) error { return nil } diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/purge.go b/vendor/go.etcd.io/etcd/pkg/fileutil/purge.go deleted file mode 100644 index 92fceab017f3..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/purge.go +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fileutil - -import ( - "os" - "path/filepath" - "sort" - "strings" - "time" -) - -func PurgeFile(dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) <-chan error { - return purgeFile(dirname, suffix, max, interval, stop, nil) -} - -// purgeFile is the internal implementation for PurgeFile which can post purged files to purgec if non-nil. -func purgeFile(dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}, purgec chan<- string) <-chan error { - errC := make(chan error, 1) - go func() { - for { - fnames, err := ReadDir(dirname) - if err != nil { - errC <- err - return - } - newfnames := make([]string, 0) - for _, fname := range fnames { - if strings.HasSuffix(fname, suffix) { - newfnames = append(newfnames, fname) - } - } - sort.Strings(newfnames) - fnames = newfnames - for len(newfnames) > int(max) { - f := filepath.Join(dirname, newfnames[0]) - l, err := TryLockFile(f, os.O_WRONLY, PrivateFileMode) - if err != nil { - break - } - if err = os.Remove(f); err != nil { - errC <- err - return - } - if err = l.Close(); err != nil { - plog.Errorf("error unlocking %s when purging file (%v)", l.Name(), err) - errC <- err - return - } - plog.Infof("purged file %s successfully", f) - newfnames = newfnames[1:] - } - if purgec != nil { - for i := 0; i < len(fnames)-len(newfnames); i++ { - purgec <- fnames[i] - } - } - select { - case <-time.After(interval): - case <-stop: - return - } - } - }() - return errC -} diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/sync.go b/vendor/go.etcd.io/etcd/pkg/fileutil/sync.go deleted file mode 100644 index 54dd41f4f351..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/sync.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !linux,!darwin - -package fileutil - -import "os" - -// Fsync is a wrapper around file.Sync(). Special handling is needed on darwin platform. -func Fsync(f *os.File) error { - return f.Sync() -} - -// Fdatasync is a wrapper around file.Sync(). Special handling is needed on linux platform. -func Fdatasync(f *os.File) error { - return f.Sync() -} diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/sync_darwin.go b/vendor/go.etcd.io/etcd/pkg/fileutil/sync_darwin.go deleted file mode 100644 index c2f39bf204d2..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/sync_darwin.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build darwin - -package fileutil - -import ( - "os" - "syscall" -) - -// Fsync on HFS/OSX flushes the data on to the physical drive but the drive -// may not write it to the persistent media for quite sometime and it may be -// written in out-of-order sequence. Using F_FULLFSYNC ensures that the -// physical drive's buffer will also get flushed to the media. -func Fsync(f *os.File) error { - _, _, errno := syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), uintptr(syscall.F_FULLFSYNC), uintptr(0)) - if errno == 0 { - return nil - } - return errno -} - -// Fdatasync on darwin platform invokes fcntl(F_FULLFSYNC) for actual persistence -// on physical drive media. -func Fdatasync(f *os.File) error { - return Fsync(f) -} diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/sync_linux.go b/vendor/go.etcd.io/etcd/pkg/fileutil/sync_linux.go deleted file mode 100644 index 1bbced915e9b..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/sync_linux.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build linux - -package fileutil - -import ( - "os" - "syscall" -) - -// Fsync is a wrapper around file.Sync(). Special handling is needed on darwin platform. -func Fsync(f *os.File) error { - return f.Sync() -} - -// Fdatasync is similar to fsync(), but does not flush modified metadata -// unless that metadata is needed in order to allow a subsequent data retrieval -// to be correctly handled. -func Fdatasync(f *os.File) error { - return syscall.Fdatasync(int(f.Fd())) -} diff --git a/vendor/go.etcd.io/etcd/pkg/flags/flag.go b/vendor/go.etcd.io/etcd/pkg/flags/flag.go deleted file mode 100644 index 69c464118548..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/flags/flag.go +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package flags implements command-line flag parsing. -package flags - -import ( - "flag" - "fmt" - "net/url" - "os" - "strings" - - "github.com/coreos/pkg/capnslog" - "github.com/spf13/pflag" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "pkg/flags") -) - -// DeprecatedFlag encapsulates a flag that may have been previously valid but -// is now deprecated. If a DeprecatedFlag is set, an error occurs. -type DeprecatedFlag struct { - Name string -} - -func (f *DeprecatedFlag) Set(_ string) error { - return fmt.Errorf(`flag "-%s" is no longer supported.`, f.Name) -} - -func (f *DeprecatedFlag) String() string { - return "" -} - -// IgnoredFlag encapsulates a flag that may have been previously valid but is -// now ignored. If an IgnoredFlag is set, a warning is printed and -// operation continues. -type IgnoredFlag struct { - Name string -} - -// IsBoolFlag is defined to allow the flag to be defined without an argument -func (f *IgnoredFlag) IsBoolFlag() bool { - return true -} - -func (f *IgnoredFlag) Set(s string) error { - plog.Warningf(`flag "-%s" is no longer supported - ignoring.`, f.Name) - return nil -} - -func (f *IgnoredFlag) String() string { - return "" -} - -// SetFlagsFromEnv parses all registered flags in the given flagset, -// and if they are not already set it attempts to set their values from -// environment variables. Environment variables take the name of the flag but -// are UPPERCASE, have the given prefix and any dashes are replaced by -// underscores - for example: some-flag => ETCD_SOME_FLAG -func SetFlagsFromEnv(prefix string, fs *flag.FlagSet) error { - var err error - alreadySet := make(map[string]bool) - fs.Visit(func(f *flag.Flag) { - alreadySet[FlagToEnv(prefix, f.Name)] = true - }) - usedEnvKey := make(map[string]bool) - fs.VisitAll(func(f *flag.Flag) { - if serr := setFlagFromEnv(fs, prefix, f.Name, usedEnvKey, alreadySet, true); serr != nil { - err = serr - } - }) - verifyEnv(prefix, usedEnvKey, alreadySet) - return err -} - -// SetPflagsFromEnv is similar to SetFlagsFromEnv. However, the accepted flagset type is pflag.FlagSet -// and it does not do any logging. -func SetPflagsFromEnv(prefix string, fs *pflag.FlagSet) error { - var err error - alreadySet := make(map[string]bool) - usedEnvKey := make(map[string]bool) - fs.VisitAll(func(f *pflag.Flag) { - if f.Changed { - alreadySet[FlagToEnv(prefix, f.Name)] = true - } - if serr := setFlagFromEnv(fs, prefix, f.Name, usedEnvKey, alreadySet, false); serr != nil { - err = serr - } - }) - verifyEnv(prefix, usedEnvKey, alreadySet) - return err -} - -// FlagToEnv converts flag string to upper-case environment variable key string. -func FlagToEnv(prefix, name string) string { - return prefix + "_" + strings.ToUpper(strings.Replace(name, "-", "_", -1)) -} - -func verifyEnv(prefix string, usedEnvKey, alreadySet map[string]bool) { - for _, env := range os.Environ() { - kv := strings.SplitN(env, "=", 2) - if len(kv) != 2 { - plog.Warningf("found invalid env %s", env) - } - if usedEnvKey[kv[0]] { - continue - } - if alreadySet[kv[0]] { - // TODO: exit with error in v3.4 - plog.Warningf("recognized environment variable %s, but unused: shadowed by corresponding flag", kv[0]) - continue - } - if strings.HasPrefix(env, prefix+"_") { - plog.Warningf("unrecognized environment variable %s", env) - } - } -} - -type flagSetter interface { - Set(fk string, fv string) error -} - -func setFlagFromEnv(fs flagSetter, prefix, fname string, usedEnvKey, alreadySet map[string]bool, log bool) error { - key := FlagToEnv(prefix, fname) - if !alreadySet[key] { - val := os.Getenv(key) - if val != "" { - usedEnvKey[key] = true - if serr := fs.Set(fname, val); serr != nil { - return fmt.Errorf("invalid value %q for %s: %v", val, key, serr) - } - if log { - plog.Infof("recognized and used environment variable %s=%s", key, val) - } - } - } - return nil -} - -// URLsFromFlag returns a slices from url got from the flag. -func URLsFromFlag(fs *flag.FlagSet, urlsFlagName string) []url.URL { - return []url.URL(*fs.Lookup(urlsFlagName).Value.(*URLsValue)) -} - -func IsSet(fs *flag.FlagSet, name string) bool { - set := false - fs.Visit(func(f *flag.Flag) { - if f.Name == name { - set = true - } - }) - return set -} diff --git a/vendor/go.etcd.io/etcd/pkg/flags/strings.go b/vendor/go.etcd.io/etcd/pkg/flags/strings.go deleted file mode 100644 index 89bdf950661a..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/flags/strings.go +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package flags - -import ( - "errors" - "flag" - "sort" - "strings" -) - -// NewStringsFlag creates a new string flag for which any one of the given -// strings is a valid value, and any other value is an error. -// -// valids[0] will be default value. Caller must be sure len(valids)!=0 or -// it will panic. -func NewStringsFlag(valids ...string) *StringsFlag { - return &StringsFlag{Values: valids, val: valids[0]} -} - -// StringsFlag implements the flag.Value interface. -type StringsFlag struct { - Values []string - val string -} - -// Set verifies the argument to be a valid member of the allowed values -// before setting the underlying flag value. -func (ss *StringsFlag) Set(s string) error { - for _, v := range ss.Values { - if s == v { - ss.val = s - return nil - } - } - return errors.New("invalid value") -} - -// String returns the set value (if any) of the StringsFlag -func (ss *StringsFlag) String() string { - return ss.val -} - -// StringsValueV2 wraps "sort.StringSlice". -type StringsValueV2 sort.StringSlice - -// Set parses a command line set of strings, separated by comma. -// Implements "flag.Value" interface. -func (ss *StringsValueV2) Set(s string) error { - *ss = strings.Split(s, ",") - return nil -} - -// String implements "flag.Value" interface. -func (ss *StringsValueV2) String() string { return strings.Join(*ss, ",") } - -// NewStringsValueV2 implements string slice as "flag.Value" interface. -// Given value is to be separated by comma. -func NewStringsValueV2(s string) (ss *StringsValueV2) { - if s == "" { - return &StringsValueV2{} - } - ss = new(StringsValueV2) - if err := ss.Set(s); err != nil { - plog.Panicf("new StringsValueV2 should never fail: %v", err) - } - return ss -} - -// StringsFromFlagV2 returns a string slice from the flag. -func StringsFromFlagV2(fs *flag.FlagSet, flagName string) []string { - return []string(*fs.Lookup(flagName).Value.(*StringsValueV2)) -} diff --git a/vendor/go.etcd.io/etcd/pkg/flags/urls.go b/vendor/go.etcd.io/etcd/pkg/flags/urls.go deleted file mode 100644 index 6383d7e92574..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/flags/urls.go +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package flags - -import ( - "strings" - - "github.com/coreos/etcd/pkg/types" -) - -type URLsValue types.URLs - -// Set parses a command line set of URLs formatted like: -// http://127.0.0.1:2380,http://10.1.1.2:80 -func (us *URLsValue) Set(s string) error { - strs := strings.Split(s, ",") - nus, err := types.NewURLs(strs) - if err != nil { - return err - } - - *us = URLsValue(nus) - return nil -} - -func (us *URLsValue) String() string { - all := make([]string, len(*us)) - for i, u := range *us { - all[i] = u.String() - } - return strings.Join(all, ",") -} - -func NewURLsValue(init string) *URLsValue { - v := &URLsValue{} - if err := v.Set(init); err != nil { - plog.Panicf("new URLsValue should never fail: %v", err) - } - return v -} diff --git a/vendor/go.etcd.io/etcd/pkg/httputil/httputil.go b/vendor/go.etcd.io/etcd/pkg/httputil/httputil.go deleted file mode 100644 index 09f44e7c71d9..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/httputil/httputil.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// borrowed from golang/net/context/ctxhttp/cancelreq.go - -// Package httputil provides HTTP utility functions. -package httputil - -import ( - "io" - "io/ioutil" - "net/http" -) - -// GracefulClose drains http.Response.Body until it hits EOF -// and closes it. This prevents TCP/TLS connections from closing, -// therefore available for reuse. -func GracefulClose(resp *http.Response) { - io.Copy(ioutil.Discard, resp.Body) - resp.Body.Close() -} diff --git a/vendor/go.etcd.io/etcd/pkg/idutil/id.go b/vendor/go.etcd.io/etcd/pkg/idutil/id.go deleted file mode 100644 index 2da210626571..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/idutil/id.go +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package idutil implements utility functions for generating unique, -// randomized ids. -package idutil - -import ( - "math" - "sync" - "time" -) - -const ( - tsLen = 5 * 8 - cntLen = 8 - suffixLen = tsLen + cntLen -) - -// Generator generates unique identifiers based on counters, timestamps, and -// a node member ID. -// -// The initial id is in this format: -// High order 2 bytes are from memberID, next 5 bytes are from timestamp, -// and low order one byte is a counter. -// | prefix | suffix | -// | 2 bytes | 5 bytes | 1 byte | -// | memberID | timestamp | cnt | -// -// The timestamp 5 bytes is different when the machine is restart -// after 1 ms and before 35 years. -// -// It increases suffix to generate the next id. -// The count field may overflow to timestamp field, which is intentional. -// It helps to extend the event window to 2^56. This doesn't break that -// id generated after restart is unique because etcd throughput is << -// 256req/ms(250k reqs/second). -type Generator struct { - mu sync.Mutex - // high order 2 bytes - prefix uint64 - // low order 6 bytes - suffix uint64 -} - -func NewGenerator(memberID uint16, now time.Time) *Generator { - prefix := uint64(memberID) << suffixLen - unixMilli := uint64(now.UnixNano()) / uint64(time.Millisecond/time.Nanosecond) - suffix := lowbit(unixMilli, tsLen) << cntLen - return &Generator{ - prefix: prefix, - suffix: suffix, - } -} - -// Next generates a id that is unique. -func (g *Generator) Next() uint64 { - g.mu.Lock() - defer g.mu.Unlock() - g.suffix++ - id := g.prefix | lowbit(g.suffix, suffixLen) - return id -} - -func lowbit(x uint64, n uint) uint64 { - return x & (math.MaxUint64 >> (64 - n)) -} diff --git a/vendor/go.etcd.io/etcd/pkg/ioutil/pagewriter.go b/vendor/go.etcd.io/etcd/pkg/ioutil/pagewriter.go deleted file mode 100644 index 72de1593d3ad..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/ioutil/pagewriter.go +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ioutil - -import ( - "io" -) - -var defaultBufferBytes = 128 * 1024 - -// PageWriter implements the io.Writer interface so that writes will -// either be in page chunks or from flushing. -type PageWriter struct { - w io.Writer - // pageOffset tracks the page offset of the base of the buffer - pageOffset int - // pageBytes is the number of bytes per page - pageBytes int - // bufferedBytes counts the number of bytes pending for write in the buffer - bufferedBytes int - // buf holds the write buffer - buf []byte - // bufWatermarkBytes is the number of bytes the buffer can hold before it needs - // to be flushed. It is less than len(buf) so there is space for slack writes - // to bring the writer to page alignment. - bufWatermarkBytes int -} - -// NewPageWriter creates a new PageWriter. pageBytes is the number of bytes -// to write per page. pageOffset is the starting offset of io.Writer. -func NewPageWriter(w io.Writer, pageBytes, pageOffset int) *PageWriter { - return &PageWriter{ - w: w, - pageOffset: pageOffset, - pageBytes: pageBytes, - buf: make([]byte, defaultBufferBytes+pageBytes), - bufWatermarkBytes: defaultBufferBytes, - } -} - -func (pw *PageWriter) Write(p []byte) (n int, err error) { - if len(p)+pw.bufferedBytes <= pw.bufWatermarkBytes { - // no overflow - copy(pw.buf[pw.bufferedBytes:], p) - pw.bufferedBytes += len(p) - return len(p), nil - } - // complete the slack page in the buffer if unaligned - slack := pw.pageBytes - ((pw.pageOffset + pw.bufferedBytes) % pw.pageBytes) - if slack != pw.pageBytes { - partial := slack > len(p) - if partial { - // not enough data to complete the slack page - slack = len(p) - } - // special case: writing to slack page in buffer - copy(pw.buf[pw.bufferedBytes:], p[:slack]) - pw.bufferedBytes += slack - n = slack - p = p[slack:] - if partial { - // avoid forcing an unaligned flush - return n, nil - } - } - // buffer contents are now page-aligned; clear out - if err = pw.Flush(); err != nil { - return n, err - } - // directly write all complete pages without copying - if len(p) > pw.pageBytes { - pages := len(p) / pw.pageBytes - c, werr := pw.w.Write(p[:pages*pw.pageBytes]) - n += c - if werr != nil { - return n, werr - } - p = p[pages*pw.pageBytes:] - } - // write remaining tail to buffer - c, werr := pw.Write(p) - n += c - return n, werr -} - -func (pw *PageWriter) Flush() error { - if pw.bufferedBytes == 0 { - return nil - } - _, err := pw.w.Write(pw.buf[:pw.bufferedBytes]) - pw.pageOffset = (pw.pageOffset + pw.bufferedBytes) % pw.pageBytes - pw.bufferedBytes = 0 - return err -} diff --git a/vendor/go.etcd.io/etcd/pkg/ioutil/readcloser.go b/vendor/go.etcd.io/etcd/pkg/ioutil/readcloser.go deleted file mode 100644 index d3efcfe3d5a6..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/ioutil/readcloser.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ioutil - -import ( - "fmt" - "io" -) - -// ReaderAndCloser implements io.ReadCloser interface by combining -// reader and closer together. -type ReaderAndCloser struct { - io.Reader - io.Closer -} - -var ( - ErrShortRead = fmt.Errorf("ioutil: short read") - ErrExpectEOF = fmt.Errorf("ioutil: expect EOF") -) - -// NewExactReadCloser returns a ReadCloser that returns errors if the underlying -// reader does not read back exactly the requested number of bytes. -func NewExactReadCloser(rc io.ReadCloser, totalBytes int64) io.ReadCloser { - return &exactReadCloser{rc: rc, totalBytes: totalBytes} -} - -type exactReadCloser struct { - rc io.ReadCloser - br int64 - totalBytes int64 -} - -func (e *exactReadCloser) Read(p []byte) (int, error) { - n, err := e.rc.Read(p) - e.br += int64(n) - if e.br > e.totalBytes { - return 0, ErrExpectEOF - } - if e.br < e.totalBytes && n == 0 { - return 0, ErrShortRead - } - return n, err -} - -func (e *exactReadCloser) Close() error { - if err := e.rc.Close(); err != nil { - return err - } - if e.br < e.totalBytes { - return ErrShortRead - } - return nil -} diff --git a/vendor/go.etcd.io/etcd/pkg/ioutil/reader.go b/vendor/go.etcd.io/etcd/pkg/ioutil/reader.go deleted file mode 100644 index 0703ed476d80..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/ioutil/reader.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package ioutil implements I/O utility functions. -package ioutil - -import "io" - -// NewLimitedBufferReader returns a reader that reads from the given reader -// but limits the amount of data returned to at most n bytes. -func NewLimitedBufferReader(r io.Reader, n int) io.Reader { - return &limitedBufferReader{ - r: r, - n: n, - } -} - -type limitedBufferReader struct { - r io.Reader - n int -} - -func (r *limitedBufferReader) Read(p []byte) (n int, err error) { - np := p - if len(np) > r.n { - np = np[:r.n] - } - return r.r.Read(np) -} diff --git a/vendor/go.etcd.io/etcd/pkg/ioutil/util.go b/vendor/go.etcd.io/etcd/pkg/ioutil/util.go deleted file mode 100644 index 192ad888c241..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/ioutil/util.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ioutil - -import ( - "io" - "os" - - "github.com/coreos/etcd/pkg/fileutil" -) - -// WriteAndSyncFile behaves just like ioutil.WriteFile in the standard library, -// but calls Sync before closing the file. WriteAndSyncFile guarantees the data -// is synced if there is no error returned. -func WriteAndSyncFile(filename string, data []byte, perm os.FileMode) error { - f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm) - if err != nil { - return err - } - n, err := f.Write(data) - if err == nil && n < len(data) { - err = io.ErrShortWrite - } - if err == nil { - err = fileutil.Fsync(f) - } - if err1 := f.Close(); err == nil { - err = err1 - } - return err -} diff --git a/vendor/go.etcd.io/etcd/pkg/logutil/merge_logger.go b/vendor/go.etcd.io/etcd/pkg/logutil/merge_logger.go deleted file mode 100644 index cc750f4d3d63..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/logutil/merge_logger.go +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package logutil includes utilities to facilitate logging. -package logutil - -import ( - "fmt" - "sync" - "time" - - "github.com/coreos/pkg/capnslog" -) - -var ( - defaultMergePeriod = time.Second - defaultTimeOutputScale = 10 * time.Millisecond - - outputInterval = time.Second -) - -// line represents a log line that can be printed out -// through capnslog.PackageLogger. -type line struct { - level capnslog.LogLevel - str string -} - -func (l line) append(s string) line { - return line{ - level: l.level, - str: l.str + " " + s, - } -} - -// status represents the merge status of a line. -type status struct { - period time.Duration - - start time.Time // start time of latest merge period - count int // number of merged lines from starting -} - -func (s *status) isInMergePeriod(now time.Time) bool { - return s.period == 0 || s.start.Add(s.period).After(now) -} - -func (s *status) isEmpty() bool { return s.count == 0 } - -func (s *status) summary(now time.Time) string { - ts := s.start.Round(defaultTimeOutputScale) - took := now.Round(defaultTimeOutputScale).Sub(ts) - return fmt.Sprintf("[merged %d repeated lines in %s]", s.count, took) -} - -func (s *status) reset(now time.Time) { - s.start = now - s.count = 0 -} - -// MergeLogger supports merge logging, which merges repeated log lines -// and prints summary log lines instead. -// -// For merge logging, MergeLogger prints out the line when the line appears -// at the first time. MergeLogger holds the same log line printed within -// defaultMergePeriod, and prints out summary log line at the end of defaultMergePeriod. -// It stops merging when the line doesn't appear within the -// defaultMergePeriod. -type MergeLogger struct { - *capnslog.PackageLogger - - mu sync.Mutex // protect statusm - statusm map[line]*status -} - -func NewMergeLogger(logger *capnslog.PackageLogger) *MergeLogger { - l := &MergeLogger{ - PackageLogger: logger, - statusm: make(map[line]*status), - } - go l.outputLoop() - return l -} - -func (l *MergeLogger) MergeInfo(entries ...interface{}) { - l.merge(line{ - level: capnslog.INFO, - str: fmt.Sprint(entries...), - }) -} - -func (l *MergeLogger) MergeInfof(format string, args ...interface{}) { - l.merge(line{ - level: capnslog.INFO, - str: fmt.Sprintf(format, args...), - }) -} - -func (l *MergeLogger) MergeNotice(entries ...interface{}) { - l.merge(line{ - level: capnslog.NOTICE, - str: fmt.Sprint(entries...), - }) -} - -func (l *MergeLogger) MergeNoticef(format string, args ...interface{}) { - l.merge(line{ - level: capnslog.NOTICE, - str: fmt.Sprintf(format, args...), - }) -} - -func (l *MergeLogger) MergeWarning(entries ...interface{}) { - l.merge(line{ - level: capnslog.WARNING, - str: fmt.Sprint(entries...), - }) -} - -func (l *MergeLogger) MergeWarningf(format string, args ...interface{}) { - l.merge(line{ - level: capnslog.WARNING, - str: fmt.Sprintf(format, args...), - }) -} - -func (l *MergeLogger) MergeError(entries ...interface{}) { - l.merge(line{ - level: capnslog.ERROR, - str: fmt.Sprint(entries...), - }) -} - -func (l *MergeLogger) MergeErrorf(format string, args ...interface{}) { - l.merge(line{ - level: capnslog.ERROR, - str: fmt.Sprintf(format, args...), - }) -} - -func (l *MergeLogger) merge(ln line) { - l.mu.Lock() - - // increase count if the logger is merging the line - if status, ok := l.statusm[ln]; ok { - status.count++ - l.mu.Unlock() - return - } - - // initialize status of the line - l.statusm[ln] = &status{ - period: defaultMergePeriod, - start: time.Now(), - } - // release the lock before IO operation - l.mu.Unlock() - // print out the line at its first time - l.PackageLogger.Logf(ln.level, ln.str) -} - -func (l *MergeLogger) outputLoop() { - for now := range time.Tick(outputInterval) { - var outputs []line - - l.mu.Lock() - for ln, status := range l.statusm { - if status.isInMergePeriod(now) { - continue - } - if status.isEmpty() { - delete(l.statusm, ln) - continue - } - outputs = append(outputs, ln.append(status.summary(now))) - status.reset(now) - } - l.mu.Unlock() - - for _, o := range outputs { - l.PackageLogger.Logf(o.level, o.str) - } - } -} diff --git a/vendor/go.etcd.io/etcd/pkg/mock/mockstorage/doc.go b/vendor/go.etcd.io/etcd/pkg/mock/mockstorage/doc.go deleted file mode 100644 index b298ab48ca82..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/mock/mockstorage/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package mockstorage provides mock implementations for etcdserver's storage interface. -package mockstorage diff --git a/vendor/go.etcd.io/etcd/pkg/mock/mockstorage/storage_recorder.go b/vendor/go.etcd.io/etcd/pkg/mock/mockstorage/storage_recorder.go deleted file mode 100644 index 4ecab9831b3d..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/mock/mockstorage/storage_recorder.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mockstorage - -import ( - "github.com/coreos/etcd/pkg/testutil" - "github.com/coreos/etcd/raft" - "github.com/coreos/etcd/raft/raftpb" -) - -type storageRecorder struct { - testutil.Recorder - dbPath string // must have '/' suffix if set -} - -func NewStorageRecorder(db string) *storageRecorder { - return &storageRecorder{&testutil.RecorderBuffered{}, db} -} - -func NewStorageRecorderStream(db string) *storageRecorder { - return &storageRecorder{testutil.NewRecorderStream(), db} -} - -func (p *storageRecorder) Save(st raftpb.HardState, ents []raftpb.Entry) error { - p.Record(testutil.Action{Name: "Save"}) - return nil -} - -func (p *storageRecorder) SaveSnap(st raftpb.Snapshot) error { - if !raft.IsEmptySnap(st) { - p.Record(testutil.Action{Name: "SaveSnap"}) - } - return nil -} - -func (p *storageRecorder) Close() error { return nil } diff --git a/vendor/go.etcd.io/etcd/pkg/mock/mockstore/doc.go b/vendor/go.etcd.io/etcd/pkg/mock/mockstore/doc.go deleted file mode 100644 index e74cebea2cd3..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/mock/mockstore/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package mockstore provides mock structures for the etcd store package. -package mockstore diff --git a/vendor/go.etcd.io/etcd/pkg/mock/mockstore/store_recorder.go b/vendor/go.etcd.io/etcd/pkg/mock/mockstore/store_recorder.go deleted file mode 100644 index 4dad19ee52d5..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/mock/mockstore/store_recorder.go +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mockstore - -import ( - "time" - - "github.com/coreos/etcd/pkg/testutil" - "github.com/coreos/etcd/store" -) - -// StoreRecorder provides a Store interface with a testutil.Recorder -type StoreRecorder struct { - store.Store - testutil.Recorder -} - -// storeRecorder records all the methods it receives. -// storeRecorder DOES NOT work as a actual store. -// It always returns invalid empty response and no error. -type storeRecorder struct { - store.Store - testutil.Recorder -} - -func NewNop() store.Store { return &storeRecorder{Recorder: &testutil.RecorderBuffered{}} } -func NewRecorder() *StoreRecorder { - sr := &storeRecorder{Recorder: &testutil.RecorderBuffered{}} - return &StoreRecorder{Store: sr, Recorder: sr.Recorder} -} -func NewRecorderStream() *StoreRecorder { - sr := &storeRecorder{Recorder: testutil.NewRecorderStream()} - return &StoreRecorder{Store: sr, Recorder: sr.Recorder} -} - -func (s *storeRecorder) Version() int { return 0 } -func (s *storeRecorder) Index() uint64 { return 0 } -func (s *storeRecorder) Get(path string, recursive, sorted bool) (*store.Event, error) { - s.Record(testutil.Action{ - Name: "Get", - Params: []interface{}{path, recursive, sorted}, - }) - return &store.Event{}, nil -} -func (s *storeRecorder) Set(path string, dir bool, val string, expireOpts store.TTLOptionSet) (*store.Event, error) { - s.Record(testutil.Action{ - Name: "Set", - Params: []interface{}{path, dir, val, expireOpts}, - }) - return &store.Event{}, nil -} -func (s *storeRecorder) Update(path, val string, expireOpts store.TTLOptionSet) (*store.Event, error) { - s.Record(testutil.Action{ - Name: "Update", - Params: []interface{}{path, val, expireOpts}, - }) - return &store.Event{}, nil -} -func (s *storeRecorder) Create(path string, dir bool, val string, uniq bool, expireOpts store.TTLOptionSet) (*store.Event, error) { - s.Record(testutil.Action{ - Name: "Create", - Params: []interface{}{path, dir, val, uniq, expireOpts}, - }) - return &store.Event{}, nil -} -func (s *storeRecorder) CompareAndSwap(path, prevVal string, prevIdx uint64, val string, expireOpts store.TTLOptionSet) (*store.Event, error) { - s.Record(testutil.Action{ - Name: "CompareAndSwap", - Params: []interface{}{path, prevVal, prevIdx, val, expireOpts}, - }) - return &store.Event{}, nil -} -func (s *storeRecorder) Delete(path string, dir, recursive bool) (*store.Event, error) { - s.Record(testutil.Action{ - Name: "Delete", - Params: []interface{}{path, dir, recursive}, - }) - return &store.Event{}, nil -} -func (s *storeRecorder) CompareAndDelete(path, prevVal string, prevIdx uint64) (*store.Event, error) { - s.Record(testutil.Action{ - Name: "CompareAndDelete", - Params: []interface{}{path, prevVal, prevIdx}, - }) - return &store.Event{}, nil -} -func (s *storeRecorder) Watch(_ string, _, _ bool, _ uint64) (store.Watcher, error) { - s.Record(testutil.Action{Name: "Watch"}) - return store.NewNopWatcher(), nil -} -func (s *storeRecorder) Save() ([]byte, error) { - s.Record(testutil.Action{Name: "Save"}) - return nil, nil -} -func (s *storeRecorder) Recovery(b []byte) error { - s.Record(testutil.Action{Name: "Recovery"}) - return nil -} - -func (s *storeRecorder) SaveNoCopy() ([]byte, error) { - s.Record(testutil.Action{Name: "SaveNoCopy"}) - return nil, nil -} - -func (s *storeRecorder) Clone() store.Store { - s.Record(testutil.Action{Name: "Clone"}) - return s -} - -func (s *storeRecorder) JsonStats() []byte { return nil } -func (s *storeRecorder) DeleteExpiredKeys(cutoff time.Time) { - s.Record(testutil.Action{ - Name: "DeleteExpiredKeys", - Params: []interface{}{cutoff}, - }) -} - -func (s *storeRecorder) HasTTLKeys() bool { - s.Record(testutil.Action{ - Name: "HasTTLKeys", - }) - return true -} - -// errStoreRecorder is a storeRecorder, but returns the given error on -// Get, Watch methods. -type errStoreRecorder struct { - storeRecorder - err error -} - -func NewErrRecorder(err error) *StoreRecorder { - sr := &errStoreRecorder{err: err} - sr.Recorder = &testutil.RecorderBuffered{} - return &StoreRecorder{Store: sr, Recorder: sr.Recorder} -} - -func (s *errStoreRecorder) Get(path string, recursive, sorted bool) (*store.Event, error) { - s.storeRecorder.Get(path, recursive, sorted) - return nil, s.err -} -func (s *errStoreRecorder) Watch(path string, recursive, sorted bool, index uint64) (store.Watcher, error) { - s.storeRecorder.Watch(path, recursive, sorted, index) - return nil, s.err -} diff --git a/vendor/go.etcd.io/etcd/pkg/mock/mockwait/doc.go b/vendor/go.etcd.io/etcd/pkg/mock/mockwait/doc.go deleted file mode 100644 index ac3c5d273146..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/mock/mockwait/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package mockwait provides mock implementations for pkg/wait. -package mockwait diff --git a/vendor/go.etcd.io/etcd/pkg/mock/mockwait/wait_recorder.go b/vendor/go.etcd.io/etcd/pkg/mock/mockwait/wait_recorder.go deleted file mode 100644 index f9c820092f08..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/mock/mockwait/wait_recorder.go +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mockwait - -import ( - "github.com/coreos/etcd/pkg/testutil" - "github.com/coreos/etcd/pkg/wait" -) - -type WaitRecorder struct { - wait.Wait - testutil.Recorder -} - -type waitRecorder struct { - testutil.RecorderBuffered -} - -func NewRecorder() *WaitRecorder { - wr := &waitRecorder{} - return &WaitRecorder{Wait: wr, Recorder: wr} -} -func NewNop() wait.Wait { return NewRecorder() } - -func (w *waitRecorder) Register(id uint64) <-chan interface{} { - w.Record(testutil.Action{Name: "Register"}) - return nil -} -func (w *waitRecorder) Trigger(id uint64, x interface{}) { - w.Record(testutil.Action{Name: "Trigger"}) -} - -func (w *waitRecorder) IsRegistered(id uint64) bool { - panic("waitRecorder.IsRegistered() shouldn't be called") -} diff --git a/vendor/go.etcd.io/etcd/pkg/netutil/isolate_linux.go b/vendor/go.etcd.io/etcd/pkg/netutil/isolate_linux.go deleted file mode 100644 index 418580ac48de..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/netutil/isolate_linux.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package netutil - -import ( - "fmt" - "os/exec" -) - -// DropPort drops all tcp packets that are received from the given port and sent to the given port. -func DropPort(port int) error { - cmdStr := fmt.Sprintf("sudo iptables -A OUTPUT -p tcp --destination-port %d -j DROP", port) - if _, err := exec.Command("/bin/sh", "-c", cmdStr).Output(); err != nil { - return err - } - cmdStr = fmt.Sprintf("sudo iptables -A INPUT -p tcp --destination-port %d -j DROP", port) - _, err := exec.Command("/bin/sh", "-c", cmdStr).Output() - return err -} - -// RecoverPort stops dropping tcp packets at given port. -func RecoverPort(port int) error { - cmdStr := fmt.Sprintf("sudo iptables -D OUTPUT -p tcp --destination-port %d -j DROP", port) - if _, err := exec.Command("/bin/sh", "-c", cmdStr).Output(); err != nil { - return err - } - cmdStr = fmt.Sprintf("sudo iptables -D INPUT -p tcp --destination-port %d -j DROP", port) - _, err := exec.Command("/bin/sh", "-c", cmdStr).Output() - return err -} - -// SetLatency adds latency in millisecond scale with random variations. -func SetLatency(ms, rv int) error { - ifces, err := GetDefaultInterfaces() - if err != nil { - return err - } - - if rv > ms { - rv = 1 - } - for ifce := range ifces { - cmdStr := fmt.Sprintf("sudo tc qdisc add dev %s root netem delay %dms %dms distribution normal", ifce, ms, rv) - _, err = exec.Command("/bin/sh", "-c", cmdStr).Output() - if err != nil { - // the rule has already been added. Overwrite it. - cmdStr = fmt.Sprintf("sudo tc qdisc change dev %s root netem delay %dms %dms distribution normal", ifce, ms, rv) - _, err = exec.Command("/bin/sh", "-c", cmdStr).Output() - if err != nil { - return err - } - } - } - return nil -} - -// RemoveLatency resets latency configurations. -func RemoveLatency() error { - ifces, err := GetDefaultInterfaces() - if err != nil { - return err - } - for ifce := range ifces { - _, err = exec.Command("/bin/sh", "-c", fmt.Sprintf("sudo tc qdisc del dev %s root netem", ifce)).Output() - if err != nil { - return err - } - } - return nil -} diff --git a/vendor/go.etcd.io/etcd/pkg/netutil/isolate_stub.go b/vendor/go.etcd.io/etcd/pkg/netutil/isolate_stub.go deleted file mode 100644 index 7f4c3e67c2ad..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/netutil/isolate_stub.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !linux - -package netutil - -func DropPort(port int) error { return nil } - -func RecoverPort(port int) error { return nil } - -func SetLatency(ms, rv int) error { return nil } - -func RemoveLatency() error { return nil } diff --git a/vendor/go.etcd.io/etcd/pkg/netutil/netutil.go b/vendor/go.etcd.io/etcd/pkg/netutil/netutil.go deleted file mode 100644 index e3db8c50a0df..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/netutil/netutil.go +++ /dev/null @@ -1,187 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package netutil implements network-related utility functions. -package netutil - -import ( - "context" - "fmt" - "net" - "net/url" - "reflect" - "sort" - "time" - - "github.com/coreos/etcd/pkg/types" - "github.com/coreos/pkg/capnslog" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "pkg/netutil") - - // indirection for testing - resolveTCPAddr = resolveTCPAddrDefault -) - -const retryInterval = time.Second - -// taken from go's ResolveTCP code but uses configurable ctx -func resolveTCPAddrDefault(ctx context.Context, addr string) (*net.TCPAddr, error) { - host, port, serr := net.SplitHostPort(addr) - if serr != nil { - return nil, serr - } - portnum, perr := net.DefaultResolver.LookupPort(ctx, "tcp", port) - if perr != nil { - return nil, perr - } - - var ips []net.IPAddr - if ip := net.ParseIP(host); ip != nil { - ips = []net.IPAddr{{IP: ip}} - } else { - // Try as a DNS name. - ipss, err := net.DefaultResolver.LookupIPAddr(ctx, host) - if err != nil { - return nil, err - } - ips = ipss - } - // randomize? - ip := ips[0] - return &net.TCPAddr{IP: ip.IP, Port: portnum, Zone: ip.Zone}, nil -} - -// resolveTCPAddrs is a convenience wrapper for net.ResolveTCPAddr. -// resolveTCPAddrs return a new set of url.URLs, in which all DNS hostnames -// are resolved. -func resolveTCPAddrs(ctx context.Context, urls [][]url.URL) ([][]url.URL, error) { - newurls := make([][]url.URL, 0) - for _, us := range urls { - nus := make([]url.URL, len(us)) - for i, u := range us { - nu, err := url.Parse(u.String()) - if err != nil { - return nil, fmt.Errorf("failed to parse %q (%v)", u.String(), err) - } - nus[i] = *nu - } - for i, u := range nus { - h, err := resolveURL(ctx, u) - if err != nil { - return nil, fmt.Errorf("failed to resolve %q (%v)", u.String(), err) - } - if h != "" { - nus[i].Host = h - } - } - newurls = append(newurls, nus) - } - return newurls, nil -} - -func resolveURL(ctx context.Context, u url.URL) (string, error) { - if u.Scheme == "unix" || u.Scheme == "unixs" { - // unix sockets don't resolve over TCP - return "", nil - } - host, _, err := net.SplitHostPort(u.Host) - if err != nil { - plog.Errorf("could not parse url %s during tcp resolving", u.Host) - return "", err - } - if host == "localhost" || net.ParseIP(host) != nil { - return "", nil - } - for ctx.Err() == nil { - tcpAddr, err := resolveTCPAddr(ctx, u.Host) - if err == nil { - plog.Infof("resolving %s to %s", u.Host, tcpAddr.String()) - return tcpAddr.String(), nil - } - plog.Warningf("failed resolving host %s (%v); retrying in %v", u.Host, err, retryInterval) - select { - case <-ctx.Done(): - plog.Errorf("could not resolve host %s", u.Host) - return "", err - case <-time.After(retryInterval): - } - } - return "", ctx.Err() -} - -// urlsEqual checks equality of url.URLS between two arrays. -// This check pass even if an URL is in hostname and opposite is in IP address. -func urlsEqual(ctx context.Context, a []url.URL, b []url.URL) (bool, error) { - if len(a) != len(b) { - return false, fmt.Errorf("len(%q) != len(%q)", urlsToStrings(a), urlsToStrings(b)) - } - urls, err := resolveTCPAddrs(ctx, [][]url.URL{a, b}) - if err != nil { - return false, err - } - preva, prevb := a, b - a, b = urls[0], urls[1] - sort.Sort(types.URLs(a)) - sort.Sort(types.URLs(b)) - for i := range a { - if !reflect.DeepEqual(a[i], b[i]) { - return false, fmt.Errorf("%q(resolved from %q) != %q(resolved from %q)", - a[i].String(), preva[i].String(), - b[i].String(), prevb[i].String(), - ) - } - } - return true, nil -} - -// URLStringsEqual returns "true" if given URLs are valid -// and resolved to same IP addresses. Otherwise, return "false" -// and error, if any. -func URLStringsEqual(ctx context.Context, a []string, b []string) (bool, error) { - if len(a) != len(b) { - return false, fmt.Errorf("len(%q) != len(%q)", a, b) - } - urlsA := make([]url.URL, 0) - for _, str := range a { - u, err := url.Parse(str) - if err != nil { - return false, fmt.Errorf("failed to parse %q", str) - } - urlsA = append(urlsA, *u) - } - urlsB := make([]url.URL, 0) - for _, str := range b { - u, err := url.Parse(str) - if err != nil { - return false, fmt.Errorf("failed to parse %q", str) - } - urlsB = append(urlsB, *u) - } - return urlsEqual(ctx, urlsA, urlsB) -} - -func urlsToStrings(us []url.URL) []string { - rs := make([]string, len(us)) - for i := range us { - rs[i] = us[i].String() - } - return rs -} - -func IsNetworkTimeoutError(err error) bool { - nerr, ok := err.(net.Error) - return ok && nerr.Timeout() -} diff --git a/vendor/go.etcd.io/etcd/pkg/netutil/routes.go b/vendor/go.etcd.io/etcd/pkg/netutil/routes.go deleted file mode 100644 index 3eb6a19ec844..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/netutil/routes.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !linux - -package netutil - -import ( - "fmt" - "runtime" -) - -// GetDefaultHost fetches the a resolvable name that corresponds -// to the machine's default routable interface -func GetDefaultHost() (string, error) { - return "", fmt.Errorf("default host not supported on %s_%s", runtime.GOOS, runtime.GOARCH) -} - -// GetDefaultInterfaces fetches the device name of default routable interface. -func GetDefaultInterfaces() (map[string]uint8, error) { - return nil, fmt.Errorf("default host not supported on %s_%s", runtime.GOOS, runtime.GOARCH) -} diff --git a/vendor/go.etcd.io/etcd/pkg/netutil/routes_linux.go b/vendor/go.etcd.io/etcd/pkg/netutil/routes_linux.go deleted file mode 100644 index 797baeb482ae..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/netutil/routes_linux.go +++ /dev/null @@ -1,250 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build linux - -package netutil - -import ( - "bytes" - "encoding/binary" - "fmt" - "net" - "sort" - "syscall" - - "github.com/coreos/etcd/pkg/cpuutil" -) - -var errNoDefaultRoute = fmt.Errorf("could not find default route") -var errNoDefaultHost = fmt.Errorf("could not find default host") -var errNoDefaultInterface = fmt.Errorf("could not find default interface") - -// GetDefaultHost obtains the first IP address of machine from the routing table and returns the IP address as string. -// An IPv4 address is preferred to an IPv6 address for backward compatibility. -func GetDefaultHost() (string, error) { - rmsgs, rerr := getDefaultRoutes() - if rerr != nil { - return "", rerr - } - - // prioritize IPv4 - if rmsg, ok := rmsgs[syscall.AF_INET]; ok { - if host, err := chooseHost(syscall.AF_INET, rmsg); host != "" || err != nil { - return host, err - } - delete(rmsgs, syscall.AF_INET) - } - - // sort so choice is deterministic - var families []int - for family := range rmsgs { - families = append(families, int(family)) - } - sort.Ints(families) - - for _, f := range families { - family := uint8(f) - if host, err := chooseHost(family, rmsgs[family]); host != "" || err != nil { - return host, err - } - } - - return "", errNoDefaultHost -} - -func chooseHost(family uint8, rmsg *syscall.NetlinkMessage) (string, error) { - host, oif, err := parsePREFSRC(rmsg) - if host != "" || err != nil { - return host, err - } - - // prefsrc not detected, fall back to getting address from iface - ifmsg, ierr := getIfaceAddr(oif, family) - if ierr != nil { - return "", ierr - } - - attrs, aerr := syscall.ParseNetlinkRouteAttr(ifmsg) - if aerr != nil { - return "", aerr - } - - for _, attr := range attrs { - // search for RTA_DST because ipv6 doesn't have RTA_SRC - if attr.Attr.Type == syscall.RTA_DST { - return net.IP(attr.Value).String(), nil - } - } - - return "", nil -} - -func getDefaultRoutes() (map[uint8]*syscall.NetlinkMessage, error) { - dat, err := syscall.NetlinkRIB(syscall.RTM_GETROUTE, syscall.AF_UNSPEC) - if err != nil { - return nil, err - } - - msgs, msgErr := syscall.ParseNetlinkMessage(dat) - if msgErr != nil { - return nil, msgErr - } - - routes := make(map[uint8]*syscall.NetlinkMessage) - rtmsg := syscall.RtMsg{} - for _, m := range msgs { - if m.Header.Type != syscall.RTM_NEWROUTE { - continue - } - buf := bytes.NewBuffer(m.Data[:syscall.SizeofRtMsg]) - if rerr := binary.Read(buf, cpuutil.ByteOrder(), &rtmsg); rerr != nil { - continue - } - if rtmsg.Dst_len == 0 && rtmsg.Table == syscall.RT_TABLE_MAIN { - // zero-length Dst_len implies default route - msg := m - routes[rtmsg.Family] = &msg - } - } - - if len(routes) > 0 { - return routes, nil - } - - return nil, errNoDefaultRoute -} - -// Used to get an address of interface. -func getIfaceAddr(idx uint32, family uint8) (*syscall.NetlinkMessage, error) { - dat, err := syscall.NetlinkRIB(syscall.RTM_GETADDR, int(family)) - if err != nil { - return nil, err - } - - msgs, msgErr := syscall.ParseNetlinkMessage(dat) - if msgErr != nil { - return nil, msgErr - } - - ifaddrmsg := syscall.IfAddrmsg{} - for _, m := range msgs { - if m.Header.Type != syscall.RTM_NEWADDR { - continue - } - buf := bytes.NewBuffer(m.Data[:syscall.SizeofIfAddrmsg]) - if rerr := binary.Read(buf, cpuutil.ByteOrder(), &ifaddrmsg); rerr != nil { - continue - } - if ifaddrmsg.Index == idx { - return &m, nil - } - } - - return nil, fmt.Errorf("could not find address for interface index %v", idx) - -} - -// Used to get a name of interface. -func getIfaceLink(idx uint32) (*syscall.NetlinkMessage, error) { - dat, err := syscall.NetlinkRIB(syscall.RTM_GETLINK, syscall.AF_UNSPEC) - if err != nil { - return nil, err - } - - msgs, msgErr := syscall.ParseNetlinkMessage(dat) - if msgErr != nil { - return nil, msgErr - } - - ifinfomsg := syscall.IfInfomsg{} - for _, m := range msgs { - if m.Header.Type != syscall.RTM_NEWLINK { - continue - } - buf := bytes.NewBuffer(m.Data[:syscall.SizeofIfInfomsg]) - if rerr := binary.Read(buf, cpuutil.ByteOrder(), &ifinfomsg); rerr != nil { - continue - } - if ifinfomsg.Index == int32(idx) { - return &m, nil - } - } - - return nil, fmt.Errorf("could not find link for interface index %v", idx) -} - -// GetDefaultInterfaces gets names of interfaces and returns a map[interface]families. -func GetDefaultInterfaces() (map[string]uint8, error) { - interfaces := make(map[string]uint8) - rmsgs, rerr := getDefaultRoutes() - if rerr != nil { - return interfaces, rerr - } - - for family, rmsg := range rmsgs { - _, oif, err := parsePREFSRC(rmsg) - if err != nil { - return interfaces, err - } - - ifmsg, ierr := getIfaceLink(oif) - if ierr != nil { - return interfaces, ierr - } - - attrs, aerr := syscall.ParseNetlinkRouteAttr(ifmsg) - if aerr != nil { - return interfaces, aerr - } - - for _, attr := range attrs { - if attr.Attr.Type == syscall.IFLA_IFNAME { - // key is an interface name - // possible values: 2 - AF_INET, 10 - AF_INET6, 12 - dualstack - interfaces[string(attr.Value[:len(attr.Value)-1])] += family - } - } - } - if len(interfaces) > 0 { - return interfaces, nil - } - return interfaces, errNoDefaultInterface -} - -// parsePREFSRC returns preferred source address and output interface index (RTA_OIF). -func parsePREFSRC(m *syscall.NetlinkMessage) (host string, oif uint32, err error) { - var attrs []syscall.NetlinkRouteAttr - attrs, err = syscall.ParseNetlinkRouteAttr(m) - if err != nil { - return "", 0, err - } - - for _, attr := range attrs { - if attr.Attr.Type == syscall.RTA_PREFSRC { - host = net.IP(attr.Value).String() - } - if attr.Attr.Type == syscall.RTA_OIF { - oif = cpuutil.ByteOrder().Uint32(attr.Value) - } - if host != "" && oif != uint32(0) { - break - } - } - - if oif == 0 { - err = errNoDefaultRoute - } - return host, oif, err -} diff --git a/vendor/go.etcd.io/etcd/pkg/osutil/interrupt_unix.go b/vendor/go.etcd.io/etcd/pkg/osutil/interrupt_unix.go deleted file mode 100644 index b9feaffc952e..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/osutil/interrupt_unix.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !windows,!plan9 - -package osutil - -import ( - "os" - "os/signal" - "sync" - "syscall" -) - -// InterruptHandler is a function that is called on receiving a -// SIGTERM or SIGINT signal. -type InterruptHandler func() - -var ( - interruptRegisterMu, interruptExitMu sync.Mutex - // interruptHandlers holds all registered InterruptHandlers in order - // they will be executed. - interruptHandlers = []InterruptHandler{} -) - -// RegisterInterruptHandler registers a new InterruptHandler. Handlers registered -// after interrupt handing was initiated will not be executed. -func RegisterInterruptHandler(h InterruptHandler) { - interruptRegisterMu.Lock() - defer interruptRegisterMu.Unlock() - interruptHandlers = append(interruptHandlers, h) -} - -// HandleInterrupts calls the handler functions on receiving a SIGINT or SIGTERM. -func HandleInterrupts() { - notifier := make(chan os.Signal, 1) - signal.Notify(notifier, syscall.SIGINT, syscall.SIGTERM) - - go func() { - sig := <-notifier - - interruptRegisterMu.Lock() - ihs := make([]InterruptHandler, len(interruptHandlers)) - copy(ihs, interruptHandlers) - interruptRegisterMu.Unlock() - - interruptExitMu.Lock() - - plog.Noticef("received %v signal, shutting down...", sig) - - for _, h := range ihs { - h() - } - signal.Stop(notifier) - pid := syscall.Getpid() - // exit directly if it is the "init" process, since the kernel will not help to kill pid 1. - if pid == 1 { - os.Exit(0) - } - setDflSignal(sig.(syscall.Signal)) - syscall.Kill(pid, sig.(syscall.Signal)) - }() -} - -// Exit relays to os.Exit if no interrupt handlers are running, blocks otherwise. -func Exit(code int) { - interruptExitMu.Lock() - os.Exit(code) -} diff --git a/vendor/go.etcd.io/etcd/pkg/osutil/interrupt_windows.go b/vendor/go.etcd.io/etcd/pkg/osutil/interrupt_windows.go deleted file mode 100644 index 013ae88e1a7f..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/osutil/interrupt_windows.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build windows - -package osutil - -import "os" - -type InterruptHandler func() - -// RegisterInterruptHandler is a no-op on windows -func RegisterInterruptHandler(h InterruptHandler) {} - -// HandleInterrupts is a no-op on windows -func HandleInterrupts() {} - -// Exit calls os.Exit -func Exit(code int) { - os.Exit(code) -} diff --git a/vendor/go.etcd.io/etcd/pkg/osutil/osutil.go b/vendor/go.etcd.io/etcd/pkg/osutil/osutil.go deleted file mode 100644 index ef38280e7139..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/osutil/osutil.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package osutil implements operating system-related utility functions. -package osutil - -import ( - "os" - "strings" - - "github.com/coreos/pkg/capnslog" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "pkg/osutil") - - // support to override setting SIG_DFL so tests don't terminate early - setDflSignal = dflSignal -) - -func Unsetenv(key string) error { - envs := os.Environ() - os.Clearenv() - for _, e := range envs { - strs := strings.SplitN(e, "=", 2) - if strs[0] == key { - continue - } - if err := os.Setenv(strs[0], strs[1]); err != nil { - return err - } - } - return nil -} diff --git a/vendor/go.etcd.io/etcd/pkg/osutil/signal.go b/vendor/go.etcd.io/etcd/pkg/osutil/signal.go deleted file mode 100644 index 687397fdd5b8..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/osutil/signal.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !linux cov - -package osutil - -import "syscall" - -func dflSignal(sig syscall.Signal) { /* nop */ } diff --git a/vendor/go.etcd.io/etcd/pkg/osutil/signal_linux.go b/vendor/go.etcd.io/etcd/pkg/osutil/signal_linux.go deleted file mode 100644 index b94d80c58bd4..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/osutil/signal_linux.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build linux,!cov - -package osutil - -import ( - "syscall" - "unsafe" -) - -// dflSignal sets the given signal to SIG_DFL -func dflSignal(sig syscall.Signal) { - // clearing out the sigact sets the signal to SIG_DFL - var sigactBuf [32]uint64 - ptr := unsafe.Pointer(&sigactBuf) - syscall.Syscall6(uintptr(syscall.SYS_RT_SIGACTION), uintptr(sig), uintptr(ptr), 0, 8, 0, 0) -} diff --git a/vendor/go.etcd.io/etcd/pkg/pathutil/path.go b/vendor/go.etcd.io/etcd/pkg/pathutil/path.go deleted file mode 100644 index f26254ba933e..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/pathutil/path.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package pathutil implements utility functions for handling slash-separated -// paths. -package pathutil - -import "path" - -// CanonicalURLPath returns the canonical url path for p, which follows the rules: -// 1. the path always starts with "/" -// 2. replace multiple slashes with a single slash -// 3. replace each '.' '..' path name element with equivalent one -// 4. keep the trailing slash -// The function is borrowed from stdlib http.cleanPath in server.go. -func CanonicalURLPath(p string) string { - if p == "" { - return "/" - } - if p[0] != '/' { - p = "/" + p - } - np := path.Clean(p) - // path.Clean removes trailing slash except for root, - // put the trailing slash back if necessary. - if p[len(p)-1] == '/' && np != "/" { - np += "/" - } - return np -} diff --git a/vendor/go.etcd.io/etcd/pkg/pbutil/pbutil.go b/vendor/go.etcd.io/etcd/pkg/pbutil/pbutil.go deleted file mode 100644 index d70f98dd82fe..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/pbutil/pbutil.go +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package pbutil defines interfaces for handling Protocol Buffer objects. -package pbutil - -import "github.com/coreos/pkg/capnslog" - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "pkg/pbutil") -) - -type Marshaler interface { - Marshal() (data []byte, err error) -} - -type Unmarshaler interface { - Unmarshal(data []byte) error -} - -func MustMarshal(m Marshaler) []byte { - d, err := m.Marshal() - if err != nil { - plog.Panicf("marshal should never fail (%v)", err) - } - return d -} - -func MustUnmarshal(um Unmarshaler, data []byte) { - if err := um.Unmarshal(data); err != nil { - plog.Panicf("unmarshal should never fail (%v)", err) - } -} - -func MaybeUnmarshal(um Unmarshaler, data []byte) bool { - if err := um.Unmarshal(data); err != nil { - return false - } - return true -} - -func GetBool(v *bool) (vv bool, set bool) { - if v == nil { - return false, false - } - return *v, true -} - -func Boolp(b bool) *bool { return &b } diff --git a/vendor/go.etcd.io/etcd/pkg/proxy/doc.go b/vendor/go.etcd.io/etcd/pkg/proxy/doc.go deleted file mode 100644 index fc81aa20b7a1..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/proxy/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package proxy implements proxy servers for network fault testing. -package proxy diff --git a/vendor/go.etcd.io/etcd/pkg/proxy/server.go b/vendor/go.etcd.io/etcd/pkg/proxy/server.go deleted file mode 100644 index 311af966f220..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/proxy/server.go +++ /dev/null @@ -1,949 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package proxy - -import ( - "fmt" - "io" - mrand "math/rand" - "net" - "net/http" - "net/url" - "strings" - "sync" - "time" - - "github.com/coreos/etcd/pkg/transport" - - humanize "github.com/dustin/go-humanize" - "go.uber.org/zap" -) - -// Server defines proxy server layer that simulates common network faults, -// such as latency spikes, packet drop/corruption, etc.. -type Server interface { - // From returns proxy source address in "scheme://host:port" format. - From() string - // To returns proxy destination address in "scheme://host:port" format. - To() string - - // Ready returns when proxy is ready to serve. - Ready() <-chan struct{} - // Done returns when proxy has been closed. - Done() <-chan struct{} - // Error sends errors while serving proxy. - Error() <-chan error - // Close closes listener and transport. - Close() error - - // DelayAccept adds latency ± random variable to accepting new incoming connections. - DelayAccept(latency, rv time.Duration) - // UndelayAccept removes sending latencies. - UndelayAccept() - // LatencyAccept returns current latency on accepting new incoming connections. - LatencyAccept() time.Duration - // DelayTx adds latency ± random variable to "sending" layer. - DelayTx(latency, rv time.Duration) - // UndelayTx removes sending latencies. - UndelayTx() - // LatencyTx returns current send latency. - LatencyTx() time.Duration - // DelayRx adds latency ± random variable to "receiving" layer. - DelayRx(latency, rv time.Duration) - // UndelayRx removes "receiving" latencies. - UndelayRx() - // LatencyRx returns current receive latency. - LatencyRx() time.Duration - - // PauseAccept stops accepting new connections. - PauseAccept() - // UnpauseAccept removes pause operation on accepting new connections. - UnpauseAccept() - // PauseTx stops "forwarding" packets. - PauseTx() - // UnpauseTx removes "forwarding" pause operation. - UnpauseTx() - // PauseRx stops "receiving" packets to client. - PauseRx() - // UnpauseRx removes "receiving" pause operation. - UnpauseRx() - - // BlackholeTx drops all incoming packets before "forwarding". - BlackholeTx() - // UnblackholeTx removes blackhole operation on "sending". - UnblackholeTx() - // BlackholeRx drops all incoming packets to client. - BlackholeRx() - // UnblackholeRx removes blackhole operation on "receiving". - UnblackholeRx() - - // CorruptTx corrupts incoming packets from the listener. - CorruptTx(f func(data []byte) []byte) - // UncorruptTx removes corrupt operation on "forwarding". - UncorruptTx() - // CorruptRx corrupts incoming packets to client. - CorruptRx(f func(data []byte) []byte) - // UncorruptRx removes corrupt operation on "receiving". - UncorruptRx() - - // ResetListener closes and restarts listener. - ResetListener() error -} - -type proxyServer struct { - lg *zap.Logger - - from, to url.URL - tlsInfo transport.TLSInfo - dialTimeout time.Duration - bufferSize int - retryInterval time.Duration - - readyc chan struct{} - donec chan struct{} - errc chan error - - closeOnce sync.Once - closeWg sync.WaitGroup - - listenerMu sync.RWMutex - listener net.Listener - - latencyAcceptMu sync.RWMutex - latencyAccept time.Duration - latencyTxMu sync.RWMutex - latencyTx time.Duration - latencyRxMu sync.RWMutex - latencyRx time.Duration - - corruptTxMu sync.RWMutex - corruptTx func(data []byte) []byte - corruptRxMu sync.RWMutex - corruptRx func(data []byte) []byte - - acceptMu sync.Mutex - pauseAcceptc chan struct{} - txMu sync.Mutex - pauseTxc chan struct{} - blackholeTxc chan struct{} - rxMu sync.Mutex - pauseRxc chan struct{} - blackholeRxc chan struct{} -} - -// ServerConfig defines proxy server configuration. -type ServerConfig struct { - Logger *zap.Logger - From url.URL - To url.URL - TLSInfo transport.TLSInfo - DialTimeout time.Duration - BufferSize int - RetryInterval time.Duration -} - -var ( - defaultDialTimeout = 3 * time.Second - defaultBufferSize = 48 * 1024 - defaultRetryInterval = 10 * time.Millisecond - defaultLogger *zap.Logger -) - -func init() { - var err error - defaultLogger, err = zap.NewProduction() - if err != nil { - panic(err) - } -} - -// NewServer returns a proxy implementation with no iptables/tc dependencies. -// The proxy layer overhead is <1ms. -func NewServer(cfg ServerConfig) Server { - p := &proxyServer{ - lg: cfg.Logger, - - from: cfg.From, - to: cfg.To, - tlsInfo: cfg.TLSInfo, - dialTimeout: cfg.DialTimeout, - bufferSize: cfg.BufferSize, - retryInterval: cfg.RetryInterval, - - readyc: make(chan struct{}), - donec: make(chan struct{}), - errc: make(chan error, 16), - - pauseAcceptc: make(chan struct{}), - pauseTxc: make(chan struct{}), - blackholeTxc: make(chan struct{}), - pauseRxc: make(chan struct{}), - blackholeRxc: make(chan struct{}), - } - if p.dialTimeout == 0 { - p.dialTimeout = defaultDialTimeout - } - if p.bufferSize == 0 { - p.bufferSize = defaultBufferSize - } - if p.retryInterval == 0 { - p.retryInterval = defaultRetryInterval - } - if p.lg == nil { - p.lg = defaultLogger - } - close(p.pauseAcceptc) - close(p.pauseTxc) - close(p.pauseRxc) - - if strings.HasPrefix(p.from.Scheme, "http") { - p.from.Scheme = "tcp" - } - if strings.HasPrefix(p.to.Scheme, "http") { - p.to.Scheme = "tcp" - } - - var ln net.Listener - var err error - if !p.tlsInfo.Empty() { - ln, err = transport.NewListener(p.from.Host, p.from.Scheme, &p.tlsInfo) - } else { - ln, err = net.Listen(p.from.Scheme, p.from.Host) - } - if err != nil { - p.errc <- err - p.Close() - return p - } - p.listener = ln - - p.closeWg.Add(1) - go p.listenAndServe() - - p.lg.Info("started proxying", zap.String("from", p.From()), zap.String("to", p.To())) - return p -} - -func (p *proxyServer) From() string { - return fmt.Sprintf("%s://%s", p.from.Scheme, p.from.Host) -} - -func (p *proxyServer) To() string { - return fmt.Sprintf("%s://%s", p.to.Scheme, p.to.Host) -} - -// TODO: implement packet reordering from multiple TCP connections -// buffer packets per connection for awhile, reorder before transmit -// - https://github.com/coreos/etcd/issues/5614 -// - https://github.com/coreos/etcd/pull/6918#issuecomment-264093034 - -func (p *proxyServer) listenAndServe() { - defer p.closeWg.Done() - - p.lg.Info("proxy is listening on", zap.String("from", p.From())) - close(p.readyc) - - for { - p.acceptMu.Lock() - pausec := p.pauseAcceptc - p.acceptMu.Unlock() - select { - case <-pausec: - case <-p.donec: - return - } - - p.latencyAcceptMu.RLock() - lat := p.latencyAccept - p.latencyAcceptMu.RUnlock() - if lat > 0 { - select { - case <-time.After(lat): - case <-p.donec: - return - } - } - - p.listenerMu.RLock() - ln := p.listener - p.listenerMu.RUnlock() - - in, err := ln.Accept() - if err != nil { - select { - case p.errc <- err: - select { - case <-p.donec: - return - default: - } - case <-p.donec: - return - } - p.lg.Debug("listener accept error", zap.Error(err)) - - if strings.HasSuffix(err.Error(), "use of closed network connection") { - select { - case <-time.After(p.retryInterval): - case <-p.donec: - return - } - p.lg.Debug("listener is closed; retry listening on", zap.String("from", p.From())) - - if err = p.ResetListener(); err != nil { - select { - case p.errc <- err: - select { - case <-p.donec: - return - default: - } - case <-p.donec: - return - } - p.lg.Warn("failed to reset listener", zap.Error(err)) - } - } - - continue - } - - var out net.Conn - if !p.tlsInfo.Empty() { - var tp *http.Transport - tp, err = transport.NewTransport(p.tlsInfo, p.dialTimeout) - if err != nil { - select { - case p.errc <- err: - select { - case <-p.donec: - return - default: - } - case <-p.donec: - return - } - continue - } - out, err = tp.Dial(p.to.Scheme, p.to.Host) - } else { - out, err = net.Dial(p.to.Scheme, p.to.Host) - } - if err != nil { - select { - case p.errc <- err: - select { - case <-p.donec: - return - default: - } - case <-p.donec: - return - } - p.lg.Debug("failed to dial", zap.Error(err)) - continue - } - - go func() { - // read incoming bytes from listener, dispatch to outgoing connection - p.transmit(out, in) - out.Close() - in.Close() - }() - go func() { - // read response from outgoing connection, write back to listener - p.receive(in, out) - in.Close() - out.Close() - }() - } -} - -func (p *proxyServer) transmit(dst io.Writer, src io.Reader) { p.ioCopy(dst, src, true) } -func (p *proxyServer) receive(dst io.Writer, src io.Reader) { p.ioCopy(dst, src, false) } -func (p *proxyServer) ioCopy(dst io.Writer, src io.Reader, proxySend bool) { - buf := make([]byte, p.bufferSize) - for { - nr, err := src.Read(buf) - if err != nil { - if err == io.EOF { - return - } - // connection already closed - if strings.HasSuffix(err.Error(), "read: connection reset by peer") { - return - } - if strings.HasSuffix(err.Error(), "use of closed network connection") { - return - } - select { - case p.errc <- err: - select { - case <-p.donec: - return - default: - } - case <-p.donec: - return - } - p.lg.Debug("failed to read", zap.Error(err)) - return - } - if nr == 0 { - return - } - data := buf[:nr] - - var pausec chan struct{} - var blackholec chan struct{} - if proxySend { - p.txMu.Lock() - pausec = p.pauseTxc - blackholec = p.blackholeTxc - p.txMu.Unlock() - } else { - p.rxMu.Lock() - pausec = p.pauseRxc - blackholec = p.blackholeRxc - p.rxMu.Unlock() - } - select { - case <-pausec: - case <-p.donec: - return - } - blackholed := false - select { - case <-blackholec: - blackholed = true - case <-p.donec: - return - default: - } - if blackholed { - if proxySend { - p.lg.Debug( - "dropped", - zap.String("data-size", humanize.Bytes(uint64(nr))), - zap.String("from", p.From()), - zap.String("to", p.To()), - ) - } else { - p.lg.Debug( - "dropped", - zap.String("data-size", humanize.Bytes(uint64(nr))), - zap.String("from", p.To()), - zap.String("to", p.From()), - ) - } - continue - } - - var lat time.Duration - if proxySend { - p.latencyTxMu.RLock() - lat = p.latencyTx - p.latencyTxMu.RUnlock() - } else { - p.latencyRxMu.RLock() - lat = p.latencyRx - p.latencyRxMu.RUnlock() - } - if lat > 0 { - select { - case <-time.After(lat): - case <-p.donec: - return - } - } - - if proxySend { - p.corruptTxMu.RLock() - if p.corruptTx != nil { - data = p.corruptTx(data) - } - p.corruptTxMu.RUnlock() - } else { - p.corruptRxMu.RLock() - if p.corruptRx != nil { - data = p.corruptRx(data) - } - p.corruptRxMu.RUnlock() - } - - var nw int - nw, err = dst.Write(data) - if err != nil { - if err == io.EOF { - return - } - select { - case p.errc <- err: - select { - case <-p.donec: - return - default: - } - case <-p.donec: - return - } - if proxySend { - p.lg.Debug("failed to write while sending", zap.Error(err)) - } else { - p.lg.Debug("failed to write while receiving", zap.Error(err)) - } - return - } - - if nr != nw { - select { - case p.errc <- io.ErrShortWrite: - select { - case <-p.donec: - return - default: - } - case <-p.donec: - return - } - if proxySend { - p.lg.Debug( - "failed to write while sending; read/write bytes are different", - zap.Int("read-bytes", nr), - zap.Int("write-bytes", nw), - zap.Error(io.ErrShortWrite), - ) - } else { - p.lg.Debug( - "failed to write while receiving; read/write bytes are different", - zap.Int("read-bytes", nr), - zap.Int("write-bytes", nw), - zap.Error(io.ErrShortWrite), - ) - } - return - } - - if proxySend { - p.lg.Debug( - "transmitted", - zap.String("data-size", humanize.Bytes(uint64(nr))), - zap.String("from", p.From()), - zap.String("to", p.To()), - ) - } else { - p.lg.Debug( - "received", - zap.String("data-size", humanize.Bytes(uint64(nr))), - zap.String("from", p.To()), - zap.String("to", p.From()), - ) - } - - } -} - -func (p *proxyServer) Ready() <-chan struct{} { return p.readyc } -func (p *proxyServer) Done() <-chan struct{} { return p.donec } -func (p *proxyServer) Error() <-chan error { return p.errc } -func (p *proxyServer) Close() (err error) { - p.closeOnce.Do(func() { - close(p.donec) - p.listenerMu.Lock() - if p.listener != nil { - err = p.listener.Close() - p.lg.Info( - "closed proxy listener", - zap.String("from", p.From()), - zap.String("to", p.To()), - ) - } - p.lg.Sync() - p.listenerMu.Unlock() - }) - p.closeWg.Wait() - return err -} - -func (p *proxyServer) DelayAccept(latency, rv time.Duration) { - if latency <= 0 { - return - } - d := computeLatency(latency, rv) - p.latencyAcceptMu.Lock() - p.latencyAccept = d - p.latencyAcceptMu.Unlock() - - p.lg.Info( - "set accept latency", - zap.Duration("latency", d), - zap.Duration("given-latency", latency), - zap.Duration("given-latency-random-variable", rv), - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) UndelayAccept() { - p.latencyAcceptMu.Lock() - d := p.latencyAccept - p.latencyAccept = 0 - p.latencyAcceptMu.Unlock() - - p.lg.Info( - "removed accept latency", - zap.Duration("latency", d), - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) LatencyAccept() time.Duration { - p.latencyAcceptMu.RLock() - d := p.latencyAccept - p.latencyAcceptMu.RUnlock() - return d -} - -func (p *proxyServer) DelayTx(latency, rv time.Duration) { - if latency <= 0 { - return - } - d := computeLatency(latency, rv) - p.latencyTxMu.Lock() - p.latencyTx = d - p.latencyTxMu.Unlock() - - p.lg.Info( - "set transmit latency", - zap.Duration("latency", d), - zap.Duration("given-latency", latency), - zap.Duration("given-latency-random-variable", rv), - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) UndelayTx() { - p.latencyTxMu.Lock() - d := p.latencyTx - p.latencyTx = 0 - p.latencyTxMu.Unlock() - - p.lg.Info( - "removed transmit latency", - zap.Duration("latency", d), - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) LatencyTx() time.Duration { - p.latencyTxMu.RLock() - d := p.latencyTx - p.latencyTxMu.RUnlock() - return d -} - -func (p *proxyServer) DelayRx(latency, rv time.Duration) { - if latency <= 0 { - return - } - d := computeLatency(latency, rv) - p.latencyRxMu.Lock() - p.latencyRx = d - p.latencyRxMu.Unlock() - - p.lg.Info( - "set receive latency", - zap.Duration("latency", d), - zap.Duration("given-latency", latency), - zap.Duration("given-latency-random-variable", rv), - zap.String("from", p.To()), - zap.String("to", p.From()), - ) -} - -func (p *proxyServer) UndelayRx() { - p.latencyRxMu.Lock() - d := p.latencyRx - p.latencyRx = 0 - p.latencyRxMu.Unlock() - - p.lg.Info( - "removed receive latency", - zap.Duration("latency", d), - zap.String("from", p.To()), - zap.String("to", p.From()), - ) -} - -func (p *proxyServer) LatencyRx() time.Duration { - p.latencyRxMu.RLock() - d := p.latencyRx - p.latencyRxMu.RUnlock() - return d -} - -func computeLatency(lat, rv time.Duration) time.Duration { - if rv == 0 { - return lat - } - if rv < 0 { - rv *= -1 - } - if rv > lat { - rv = lat / 10 - } - now := time.Now() - mrand.Seed(int64(now.Nanosecond())) - sign := 1 - if now.Second()%2 == 0 { - sign = -1 - } - return lat + time.Duration(int64(sign)*mrand.Int63n(rv.Nanoseconds())) -} - -func (p *proxyServer) PauseAccept() { - p.acceptMu.Lock() - p.pauseAcceptc = make(chan struct{}) - p.acceptMu.Unlock() - - p.lg.Info( - "paused accepting new connections", - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) UnpauseAccept() { - p.acceptMu.Lock() - select { - case <-p.pauseAcceptc: // already unpaused - case <-p.donec: - p.acceptMu.Unlock() - return - default: - close(p.pauseAcceptc) - } - p.acceptMu.Unlock() - - p.lg.Info( - "unpaused accepting new connections", - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) PauseTx() { - p.txMu.Lock() - p.pauseTxc = make(chan struct{}) - p.txMu.Unlock() - - p.lg.Info( - "paused transmit listen", - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) UnpauseTx() { - p.txMu.Lock() - select { - case <-p.pauseTxc: // already unpaused - case <-p.donec: - p.txMu.Unlock() - return - default: - close(p.pauseTxc) - } - p.txMu.Unlock() - - p.lg.Info( - "unpaused transmit listen", - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) PauseRx() { - p.rxMu.Lock() - p.pauseRxc = make(chan struct{}) - p.rxMu.Unlock() - - p.lg.Info( - "paused receive listen", - zap.String("from", p.To()), - zap.String("to", p.From()), - ) -} - -func (p *proxyServer) UnpauseRx() { - p.rxMu.Lock() - select { - case <-p.pauseRxc: // already unpaused - case <-p.donec: - p.rxMu.Unlock() - return - default: - close(p.pauseRxc) - } - p.rxMu.Unlock() - - p.lg.Info( - "unpaused receive listen", - zap.String("from", p.To()), - zap.String("to", p.From()), - ) -} - -func (p *proxyServer) BlackholeTx() { - p.txMu.Lock() - select { - case <-p.blackholeTxc: // already blackholed - case <-p.donec: - p.txMu.Unlock() - return - default: - close(p.blackholeTxc) - } - p.txMu.Unlock() - - p.lg.Info( - "blackholed transmit", - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) UnblackholeTx() { - p.txMu.Lock() - p.blackholeTxc = make(chan struct{}) - p.txMu.Unlock() - - p.lg.Info( - "unblackholed transmit", - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) BlackholeRx() { - p.rxMu.Lock() - select { - case <-p.blackholeRxc: // already blackholed - case <-p.donec: - p.rxMu.Unlock() - return - default: - close(p.blackholeRxc) - } - p.rxMu.Unlock() - - p.lg.Info( - "blackholed receive", - zap.String("from", p.To()), - zap.String("to", p.From()), - ) -} - -func (p *proxyServer) UnblackholeRx() { - p.rxMu.Lock() - p.blackholeRxc = make(chan struct{}) - p.rxMu.Unlock() - - p.lg.Info( - "unblackholed receive", - zap.String("from", p.To()), - zap.String("to", p.From()), - ) -} - -func (p *proxyServer) CorruptTx(f func([]byte) []byte) { - p.corruptTxMu.Lock() - p.corruptTx = f - p.corruptTxMu.Unlock() - - p.lg.Info( - "corrupting transmit", - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) UncorruptTx() { - p.corruptTxMu.Lock() - p.corruptTx = nil - p.corruptTxMu.Unlock() - - p.lg.Info( - "stopped corrupting transmit", - zap.String("from", p.From()), - zap.String("to", p.To()), - ) -} - -func (p *proxyServer) CorruptRx(f func([]byte) []byte) { - p.corruptRxMu.Lock() - p.corruptRx = f - p.corruptRxMu.Unlock() - p.lg.Info( - "corrupting receive", - zap.String("from", p.To()), - zap.String("to", p.From()), - ) -} - -func (p *proxyServer) UncorruptRx() { - p.corruptRxMu.Lock() - p.corruptRx = nil - p.corruptRxMu.Unlock() - - p.lg.Info( - "stopped corrupting receive", - zap.String("from", p.To()), - zap.String("to", p.From()), - ) -} - -func (p *proxyServer) ResetListener() error { - p.listenerMu.Lock() - defer p.listenerMu.Unlock() - - if err := p.listener.Close(); err != nil { - // already closed - if !strings.HasSuffix(err.Error(), "use of closed network connection") { - return err - } - } - - var ln net.Listener - var err error - if !p.tlsInfo.Empty() { - ln, err = transport.NewListener(p.from.Host, p.from.Scheme, &p.tlsInfo) - } else { - ln, err = net.Listen(p.from.Scheme, p.from.Host) - } - if err != nil { - return err - } - p.listener = ln - - p.lg.Info( - "reset listener on", - zap.String("from", p.From()), - ) - return nil -} diff --git a/vendor/go.etcd.io/etcd/pkg/report/doc.go b/vendor/go.etcd.io/etcd/pkg/report/doc.go deleted file mode 100644 index 1ebd119f5d53..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/report/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package report generates human-readable benchmark reports. -package report diff --git a/vendor/go.etcd.io/etcd/pkg/report/report.go b/vendor/go.etcd.io/etcd/pkg/report/report.go deleted file mode 100644 index 36d09b9d5087..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/report/report.go +++ /dev/null @@ -1,278 +0,0 @@ -// Copyright 2014 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// the file is borrowed from github.com/rakyll/boom/boomer/print.go - -package report - -import ( - "fmt" - "math" - "sort" - "strings" - "time" -) - -const ( - barChar = "∎" -) - -// Result describes the timings for an operation. -type Result struct { - Start time.Time - End time.Time - Err error - Weight float64 -} - -func (res *Result) Duration() time.Duration { return res.End.Sub(res.Start) } - -type report struct { - results chan Result - precision string - - stats Stats - sps *secondPoints -} - -// Stats exposes results raw data. -type Stats struct { - AvgTotal float64 - Fastest float64 - Slowest float64 - Average float64 - Stddev float64 - RPS float64 - Total time.Duration - ErrorDist map[string]int - Lats []float64 - TimeSeries TimeSeries -} - -func (s *Stats) copy() Stats { - ss := *s - ss.ErrorDist = copyMap(ss.ErrorDist) - ss.Lats = copyFloats(ss.Lats) - return ss -} - -// Report processes a result stream until it is closed, then produces a -// string with information about the consumed result data. -type Report interface { - Results() chan<- Result - - // Run returns results in print-friendly format. - Run() <-chan string - - // Stats returns results in raw data. - Stats() <-chan Stats -} - -func NewReport(precision string) Report { return newReport(precision) } - -func newReport(precision string) *report { - r := &report{ - results: make(chan Result, 16), - precision: precision, - } - r.stats.ErrorDist = make(map[string]int) - return r -} - -func NewReportSample(precision string) Report { - r := NewReport(precision).(*report) - r.sps = newSecondPoints() - return r -} - -func (r *report) Results() chan<- Result { return r.results } - -func (r *report) Run() <-chan string { - donec := make(chan string, 1) - go func() { - defer close(donec) - r.processResults() - donec <- r.String() - }() - return donec -} - -func (r *report) Stats() <-chan Stats { - donec := make(chan Stats, 1) - go func() { - defer close(donec) - r.processResults() - s := r.stats.copy() - if r.sps != nil { - s.TimeSeries = r.sps.getTimeSeries() - } - donec <- s - }() - return donec -} - -func copyMap(m map[string]int) (c map[string]int) { - c = make(map[string]int, len(m)) - for k, v := range m { - c[k] = v - } - return c -} - -func copyFloats(s []float64) (c []float64) { - c = make([]float64, len(s)) - copy(c, s) - return c -} - -func (r *report) String() (s string) { - if len(r.stats.Lats) > 0 { - s += fmt.Sprintf("\nSummary:\n") - s += fmt.Sprintf(" Total:\t%s.\n", r.sec2str(r.stats.Total.Seconds())) - s += fmt.Sprintf(" Slowest:\t%s.\n", r.sec2str(r.stats.Slowest)) - s += fmt.Sprintf(" Fastest:\t%s.\n", r.sec2str(r.stats.Fastest)) - s += fmt.Sprintf(" Average:\t%s.\n", r.sec2str(r.stats.Average)) - s += fmt.Sprintf(" Stddev:\t%s.\n", r.sec2str(r.stats.Stddev)) - s += fmt.Sprintf(" Requests/sec:\t"+r.precision+"\n", r.stats.RPS) - s += r.histogram() - s += r.sprintLatencies() - if r.sps != nil { - s += fmt.Sprintf("%v\n", r.sps.getTimeSeries()) - } - } - if len(r.stats.ErrorDist) > 0 { - s += r.errors() - } - return s -} - -func (r *report) sec2str(sec float64) string { return fmt.Sprintf(r.precision+" secs", sec) } - -type reportRate struct{ *report } - -func NewReportRate(precision string) Report { - return &reportRate{NewReport(precision).(*report)} -} - -func (r *reportRate) String() string { - return fmt.Sprintf(" Requests/sec:\t"+r.precision+"\n", r.stats.RPS) -} - -func (r *report) processResult(res *Result) { - if res.Err != nil { - r.stats.ErrorDist[res.Err.Error()]++ - return - } - dur := res.Duration() - r.stats.Lats = append(r.stats.Lats, dur.Seconds()) - r.stats.AvgTotal += dur.Seconds() - if r.sps != nil { - r.sps.Add(res.Start, dur) - } -} - -func (r *report) processResults() { - st := time.Now() - for res := range r.results { - r.processResult(&res) - } - r.stats.Total = time.Since(st) - - r.stats.RPS = float64(len(r.stats.Lats)) / r.stats.Total.Seconds() - r.stats.Average = r.stats.AvgTotal / float64(len(r.stats.Lats)) - for i := range r.stats.Lats { - dev := r.stats.Lats[i] - r.stats.Average - r.stats.Stddev += dev * dev - } - r.stats.Stddev = math.Sqrt(r.stats.Stddev / float64(len(r.stats.Lats))) - sort.Float64s(r.stats.Lats) - if len(r.stats.Lats) > 0 { - r.stats.Fastest = r.stats.Lats[0] - r.stats.Slowest = r.stats.Lats[len(r.stats.Lats)-1] - } -} - -var pctls = []float64{10, 25, 50, 75, 90, 95, 99, 99.9} - -// Percentiles returns percentile distribution of float64 slice. -func Percentiles(nums []float64) (pcs []float64, data []float64) { - return pctls, percentiles(nums) -} - -func percentiles(nums []float64) (data []float64) { - data = make([]float64, len(pctls)) - j := 0 - n := len(nums) - for i := 0; i < n && j < len(pctls); i++ { - current := float64(i) * 100.0 / float64(n) - if current >= pctls[j] { - data[j] = nums[i] - j++ - } - } - return data -} - -func (r *report) sprintLatencies() string { - data := percentiles(r.stats.Lats) - s := fmt.Sprintf("\nLatency distribution:\n") - for i := 0; i < len(pctls); i++ { - if data[i] > 0 { - s += fmt.Sprintf(" %v%% in %s.\n", pctls[i], r.sec2str(data[i])) - } - } - return s -} - -func (r *report) histogram() string { - bc := 10 - buckets := make([]float64, bc+1) - counts := make([]int, bc+1) - bs := (r.stats.Slowest - r.stats.Fastest) / float64(bc) - for i := 0; i < bc; i++ { - buckets[i] = r.stats.Fastest + bs*float64(i) - } - buckets[bc] = r.stats.Slowest - var bi int - var max int - for i := 0; i < len(r.stats.Lats); { - if r.stats.Lats[i] <= buckets[bi] { - i++ - counts[bi]++ - if max < counts[bi] { - max = counts[bi] - } - } else if bi < len(buckets)-1 { - bi++ - } - } - s := fmt.Sprintf("\nResponse time histogram:\n") - for i := 0; i < len(buckets); i++ { - // Normalize bar lengths. - var barLen int - if max > 0 { - barLen = counts[i] * 40 / max - } - s += fmt.Sprintf(" "+r.precision+" [%v]\t|%v\n", buckets[i], counts[i], strings.Repeat(barChar, barLen)) - } - return s -} - -func (r *report) errors() string { - s := fmt.Sprintf("\nError distribution:\n") - for err, num := range r.stats.ErrorDist { - s += fmt.Sprintf(" [%d]\t%s\n", num, err) - } - return s -} diff --git a/vendor/go.etcd.io/etcd/pkg/report/timeseries.go b/vendor/go.etcd.io/etcd/pkg/report/timeseries.go deleted file mode 100644 index bc1493b2c27a..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/report/timeseries.go +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package report - -import ( - "bytes" - "encoding/csv" - "fmt" - "log" - "math" - "sort" - "sync" - "time" -) - -type DataPoint struct { - Timestamp int64 - MinLatency time.Duration - AvgLatency time.Duration - MaxLatency time.Duration - ThroughPut int64 -} - -type TimeSeries []DataPoint - -func (t TimeSeries) Swap(i, j int) { t[i], t[j] = t[j], t[i] } -func (t TimeSeries) Len() int { return len(t) } -func (t TimeSeries) Less(i, j int) bool { return t[i].Timestamp < t[j].Timestamp } - -type secondPoint struct { - minLatency time.Duration - maxLatency time.Duration - totalLatency time.Duration - count int64 -} - -type secondPoints struct { - mu sync.Mutex - tm map[int64]secondPoint -} - -func newSecondPoints() *secondPoints { - return &secondPoints{tm: make(map[int64]secondPoint)} -} - -func (sp *secondPoints) Add(ts time.Time, lat time.Duration) { - sp.mu.Lock() - defer sp.mu.Unlock() - - tk := ts.Unix() - if v, ok := sp.tm[tk]; !ok { - sp.tm[tk] = secondPoint{minLatency: lat, maxLatency: lat, totalLatency: lat, count: 1} - } else { - if lat != time.Duration(0) { - v.minLatency = minDuration(v.minLatency, lat) - } - v.maxLatency = maxDuration(v.maxLatency, lat) - v.totalLatency += lat - v.count++ - sp.tm[tk] = v - } -} - -func (sp *secondPoints) getTimeSeries() TimeSeries { - sp.mu.Lock() - defer sp.mu.Unlock() - - var ( - minTs int64 = math.MaxInt64 - maxTs int64 = -1 - ) - for k := range sp.tm { - if minTs > k { - minTs = k - } - if maxTs < k { - maxTs = k - } - } - for ti := minTs; ti < maxTs; ti++ { - if _, ok := sp.tm[ti]; !ok { // fill-in empties - sp.tm[ti] = secondPoint{totalLatency: 0, count: 0} - } - } - - var ( - tslice = make(TimeSeries, len(sp.tm)) - i int - ) - for k, v := range sp.tm { - var lat time.Duration - if v.count > 0 { - lat = time.Duration(v.totalLatency) / time.Duration(v.count) - } - tslice[i] = DataPoint{ - Timestamp: k, - MinLatency: v.minLatency, - AvgLatency: lat, - MaxLatency: v.maxLatency, - ThroughPut: v.count, - } - i++ - } - - sort.Sort(tslice) - return tslice -} - -func (t TimeSeries) String() string { - buf := new(bytes.Buffer) - wr := csv.NewWriter(buf) - if err := wr.Write([]string{"UNIX-SECOND", "MIN-LATENCY-MS", "AVG-LATENCY-MS", "MAX-LATENCY-MS", "AVG-THROUGHPUT"}); err != nil { - log.Fatal(err) - } - rows := [][]string{} - for i := range t { - row := []string{ - fmt.Sprintf("%d", t[i].Timestamp), - t[i].MinLatency.String(), - t[i].AvgLatency.String(), - t[i].MaxLatency.String(), - fmt.Sprintf("%d", t[i].ThroughPut), - } - rows = append(rows, row) - } - if err := wr.WriteAll(rows); err != nil { - log.Fatal(err) - } - wr.Flush() - if err := wr.Error(); err != nil { - log.Fatal(err) - } - return fmt.Sprintf("\nSample in one second (unix latency throughput):\n%s", buf.String()) -} - -func minDuration(a, b time.Duration) time.Duration { - if a < b { - return a - } - return b -} - -func maxDuration(a, b time.Duration) time.Duration { - if a > b { - return a - } - return b -} diff --git a/vendor/go.etcd.io/etcd/pkg/report/weighted.go b/vendor/go.etcd.io/etcd/pkg/report/weighted.go deleted file mode 100644 index 411214f6d165..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/report/weighted.go +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// the file is borrowed from github.com/rakyll/boom/boomer/print.go - -package report - -import ( - "time" -) - -type weightedReport struct { - baseReport Report - - report *report - results chan Result - weightTotal float64 -} - -// NewWeightedReport returns a report that includes -// both weighted and unweighted statistics. -func NewWeightedReport(r Report, precision string) Report { - return &weightedReport{ - baseReport: r, - report: newReport(precision), - results: make(chan Result, 16), - } -} - -func (wr *weightedReport) Results() chan<- Result { return wr.results } - -func (wr *weightedReport) Run() <-chan string { - donec := make(chan string, 2) - go func() { - defer close(donec) - basec, rc := make(chan string, 1), make(chan Stats, 1) - go func() { basec <- (<-wr.baseReport.Run()) }() - go func() { rc <- (<-wr.report.Stats()) }() - go wr.processResults() - wr.report.stats = wr.reweighStat(<-rc) - donec <- wr.report.String() - donec <- (<-basec) - }() - return donec -} - -func (wr *weightedReport) Stats() <-chan Stats { - donec := make(chan Stats, 2) - go func() { - defer close(donec) - basec, rc := make(chan Stats, 1), make(chan Stats, 1) - go func() { basec <- (<-wr.baseReport.Stats()) }() - go func() { rc <- (<-wr.report.Stats()) }() - go wr.processResults() - donec <- wr.reweighStat(<-rc) - donec <- (<-basec) - }() - return donec -} - -func (wr *weightedReport) processResults() { - defer close(wr.report.results) - defer close(wr.baseReport.Results()) - for res := range wr.results { - wr.processResult(res) - wr.baseReport.Results() <- res - } -} - -func (wr *weightedReport) processResult(res Result) { - if res.Err != nil { - wr.report.results <- res - return - } - if res.Weight == 0 { - res.Weight = 1.0 - } - wr.weightTotal += res.Weight - res.End = res.Start.Add(time.Duration(float64(res.End.Sub(res.Start)) / res.Weight)) - res.Weight = 1.0 - wr.report.results <- res -} - -func (wr *weightedReport) reweighStat(s Stats) Stats { - weightCoef := wr.weightTotal / float64(len(s.Lats)) - // weight > 1 => processing more than one request - s.RPS *= weightCoef - s.AvgTotal *= weightCoef * weightCoef - return s -} diff --git a/vendor/go.etcd.io/etcd/pkg/runtime/fds_linux.go b/vendor/go.etcd.io/etcd/pkg/runtime/fds_linux.go deleted file mode 100644 index 8e9359db28ca..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/runtime/fds_linux.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package runtime implements utility functions for runtime systems. -package runtime - -import ( - "io/ioutil" - "syscall" -) - -func FDLimit() (uint64, error) { - var rlimit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit); err != nil { - return 0, err - } - return rlimit.Cur, nil -} - -func FDUsage() (uint64, error) { - fds, err := ioutil.ReadDir("/proc/self/fd") - if err != nil { - return 0, err - } - return uint64(len(fds)), nil -} diff --git a/vendor/go.etcd.io/etcd/pkg/runtime/fds_other.go b/vendor/go.etcd.io/etcd/pkg/runtime/fds_other.go deleted file mode 100644 index 0cbdb88c7a60..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/runtime/fds_other.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !linux - -package runtime - -import ( - "fmt" - "runtime" -) - -func FDLimit() (uint64, error) { - return 0, fmt.Errorf("cannot get FDLimit on %s", runtime.GOOS) -} - -func FDUsage() (uint64, error) { - return 0, fmt.Errorf("cannot get FDUsage on %s", runtime.GOOS) -} diff --git a/vendor/go.etcd.io/etcd/pkg/schedule/doc.go b/vendor/go.etcd.io/etcd/pkg/schedule/doc.go deleted file mode 100644 index cca2c75fb6a9..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/schedule/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package schedule provides mechanisms and policies for scheduling units of work. -package schedule diff --git a/vendor/go.etcd.io/etcd/pkg/schedule/schedule.go b/vendor/go.etcd.io/etcd/pkg/schedule/schedule.go deleted file mode 100644 index 234d01989dfb..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/schedule/schedule.go +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package schedule - -import ( - "context" - "sync" -) - -type Job func(context.Context) - -// Scheduler can schedule jobs. -type Scheduler interface { - // Schedule asks the scheduler to schedule a job defined by the given func. - // Schedule to a stopped scheduler might panic. - Schedule(j Job) - - // Pending returns number of pending jobs - Pending() int - - // Scheduled returns the number of scheduled jobs (excluding pending jobs) - Scheduled() int - - // Finished returns the number of finished jobs - Finished() int - - // WaitFinish waits until at least n job are finished and all pending jobs are finished. - WaitFinish(n int) - - // Stop stops the scheduler. - Stop() -} - -type fifo struct { - mu sync.Mutex - - resume chan struct{} - scheduled int - finished int - pendings []Job - - ctx context.Context - cancel context.CancelFunc - - finishCond *sync.Cond - donec chan struct{} -} - -// NewFIFOScheduler returns a Scheduler that schedules jobs in FIFO -// order sequentially -func NewFIFOScheduler() Scheduler { - f := &fifo{ - resume: make(chan struct{}, 1), - donec: make(chan struct{}, 1), - } - f.finishCond = sync.NewCond(&f.mu) - f.ctx, f.cancel = context.WithCancel(context.Background()) - go f.run() - return f -} - -// Schedule schedules a job that will be ran in FIFO order sequentially. -func (f *fifo) Schedule(j Job) { - f.mu.Lock() - defer f.mu.Unlock() - - if f.cancel == nil { - panic("schedule: schedule to stopped scheduler") - } - - if len(f.pendings) == 0 { - select { - case f.resume <- struct{}{}: - default: - } - } - f.pendings = append(f.pendings, j) -} - -func (f *fifo) Pending() int { - f.mu.Lock() - defer f.mu.Unlock() - return len(f.pendings) -} - -func (f *fifo) Scheduled() int { - f.mu.Lock() - defer f.mu.Unlock() - return f.scheduled -} - -func (f *fifo) Finished() int { - f.finishCond.L.Lock() - defer f.finishCond.L.Unlock() - return f.finished -} - -func (f *fifo) WaitFinish(n int) { - f.finishCond.L.Lock() - for f.finished < n || len(f.pendings) != 0 { - f.finishCond.Wait() - } - f.finishCond.L.Unlock() -} - -// Stop stops the scheduler and cancels all pending jobs. -func (f *fifo) Stop() { - f.mu.Lock() - f.cancel() - f.cancel = nil - f.mu.Unlock() - <-f.donec -} - -func (f *fifo) run() { - // TODO: recover from job panic? - defer func() { - close(f.donec) - close(f.resume) - }() - - for { - var todo Job - f.mu.Lock() - if len(f.pendings) != 0 { - f.scheduled++ - todo = f.pendings[0] - } - f.mu.Unlock() - if todo == nil { - select { - case <-f.resume: - case <-f.ctx.Done(): - f.mu.Lock() - pendings := f.pendings - f.pendings = nil - f.mu.Unlock() - // clean up pending jobs - for _, todo := range pendings { - todo(f.ctx) - } - return - } - } else { - todo(f.ctx) - f.finishCond.L.Lock() - f.finished++ - f.pendings = f.pendings[1:] - f.finishCond.Broadcast() - f.finishCond.L.Unlock() - } - } -} diff --git a/vendor/go.etcd.io/etcd/pkg/srv/srv.go b/vendor/go.etcd.io/etcd/pkg/srv/srv.go deleted file mode 100644 index 600061ce8ea8..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/srv/srv.go +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package srv looks up DNS SRV records. -package srv - -import ( - "fmt" - "net" - "net/url" - "strings" - - "github.com/coreos/etcd/pkg/types" -) - -var ( - // indirection for testing - lookupSRV = net.LookupSRV // net.DefaultResolver.LookupSRV when ctxs don't conflict - resolveTCPAddr = net.ResolveTCPAddr -) - -// GetCluster gets the cluster information via DNS discovery. -// Also sees each entry as a separate instance. -func GetCluster(service, name, dns string, apurls types.URLs) ([]string, error) { - tempName := int(0) - tcp2ap := make(map[string]url.URL) - - // First, resolve the apurls - for _, url := range apurls { - tcpAddr, err := resolveTCPAddr("tcp", url.Host) - if err != nil { - return nil, err - } - tcp2ap[tcpAddr.String()] = url - } - - stringParts := []string{} - updateNodeMap := func(service, scheme string) error { - _, addrs, err := lookupSRV(service, "tcp", dns) - if err != nil { - return err - } - for _, srv := range addrs { - port := fmt.Sprintf("%d", srv.Port) - host := net.JoinHostPort(srv.Target, port) - tcpAddr, terr := resolveTCPAddr("tcp", host) - if terr != nil { - err = terr - continue - } - n := "" - url, ok := tcp2ap[tcpAddr.String()] - if ok { - n = name - } - if n == "" { - n = fmt.Sprintf("%d", tempName) - tempName++ - } - // SRV records have a trailing dot but URL shouldn't. - shortHost := strings.TrimSuffix(srv.Target, ".") - urlHost := net.JoinHostPort(shortHost, port) - if ok && url.Scheme != scheme { - err = fmt.Errorf("bootstrap at %s from DNS for %s has scheme mismatch with expected peer %s", scheme+"://"+urlHost, service, url.String()) - } else { - stringParts = append(stringParts, fmt.Sprintf("%s=%s://%s", n, scheme, urlHost)) - } - } - if len(stringParts) == 0 { - return err - } - return nil - } - - failCount := 0 - err := updateNodeMap(service+"-ssl", "https") - srvErr := make([]string, 2) - if err != nil { - srvErr[0] = fmt.Sprintf("error querying DNS SRV records for _%s-ssl %s", service, err) - failCount++ - } - err = updateNodeMap(service, "http") - if err != nil { - srvErr[1] = fmt.Sprintf("error querying DNS SRV records for _%s %s", service, err) - failCount++ - } - if failCount == 2 { - return nil, fmt.Errorf("srv: too many errors querying DNS SRV records (%q, %q)", srvErr[0], srvErr[1]) - } - return stringParts, nil -} - -type SRVClients struct { - Endpoints []string - SRVs []*net.SRV -} - -// GetClient looks up the client endpoints for a service and domain. -func GetClient(service, domain string) (*SRVClients, error) { - var urls []*url.URL - var srvs []*net.SRV - - updateURLs := func(service, scheme string) error { - _, addrs, err := lookupSRV(service, "tcp", domain) - if err != nil { - return err - } - for _, srv := range addrs { - urls = append(urls, &url.URL{ - Scheme: scheme, - Host: net.JoinHostPort(srv.Target, fmt.Sprintf("%d", srv.Port)), - }) - } - srvs = append(srvs, addrs...) - return nil - } - - errHTTPS := updateURLs(service+"-ssl", "https") - errHTTP := updateURLs(service, "http") - - if errHTTPS != nil && errHTTP != nil { - return nil, fmt.Errorf("dns lookup errors: %s and %s", errHTTPS, errHTTP) - } - - endpoints := make([]string, len(urls)) - for i := range urls { - endpoints[i] = urls[i].String() - } - return &SRVClients{Endpoints: endpoints, SRVs: srvs}, nil -} diff --git a/vendor/go.etcd.io/etcd/pkg/stringutil/stringutil.go b/vendor/go.etcd.io/etcd/pkg/stringutil/stringutil.go deleted file mode 100644 index 44d637c20a32..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/stringutil/stringutil.go +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package stringutil exports string utility functions. -package stringutil - -import "math/rand" - -const ( - chars = "abcdefghijklmnopqrstuvwxyz0123456789" -) - -// UniqueStrings returns a slice of randomly generated unique strings. -func UniqueStrings(maxlen uint, n int) []string { - exist := make(map[string]bool) - ss := make([]string, 0) - - for len(ss) < n { - s := randomString(maxlen) - if !exist[s] { - exist[s] = true - ss = append(ss, s) - } - } - - return ss -} - -// RandomStrings returns a slice of randomly generated strings. -func RandomStrings(maxlen uint, n int) []string { - ss := make([]string, 0) - for i := 0; i < n; i++ { - ss = append(ss, randomString(maxlen)) - } - return ss -} - -func randomString(l uint) string { - s := make([]byte, l) - for i := 0; i < int(l); i++ { - s[i] = chars[rand.Intn(len(chars))] - } - return string(s) -} diff --git a/vendor/go.etcd.io/etcd/pkg/testutil/assert.go b/vendor/go.etcd.io/etcd/pkg/testutil/assert.go deleted file mode 100644 index 9cf03457d52f..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/testutil/assert.go +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package testutil - -import ( - "fmt" - "reflect" - "testing" -) - -func AssertEqual(t *testing.T, e, a interface{}, msg ...string) { - if (e == nil || a == nil) && (isNil(e) && isNil(a)) { - return - } - if reflect.DeepEqual(e, a) { - return - } - s := "" - if len(msg) > 1 { - s = msg[0] + ": " - } - s = fmt.Sprintf("%sexpected %+v, got %+v", s, e, a) - FatalStack(t, s) -} - -func AssertNil(t *testing.T, v interface{}) { - AssertEqual(t, nil, v) -} - -func AssertNotNil(t *testing.T, v interface{}) { - if v == nil { - t.Fatalf("expected non-nil, got %+v", v) - } -} - -func AssertTrue(t *testing.T, v bool, msg ...string) { - AssertEqual(t, true, v, msg...) -} - -func AssertFalse(t *testing.T, v bool, msg ...string) { - AssertEqual(t, false, v, msg...) -} - -func isNil(v interface{}) bool { - if v == nil { - return true - } - rv := reflect.ValueOf(v) - return rv.Kind() != reflect.Struct && rv.IsNil() -} diff --git a/vendor/go.etcd.io/etcd/pkg/testutil/leak.go b/vendor/go.etcd.io/etcd/pkg/testutil/leak.go deleted file mode 100644 index 2ebae1e6e887..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/testutil/leak.go +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package testutil - -import ( - "fmt" - "net/http" - "os" - "regexp" - "runtime" - "sort" - "strings" - "testing" - "time" -) - -/* -CheckLeakedGoroutine verifies tests do not leave any leaky -goroutines. It returns true when there are goroutines still -running(leaking) after all tests. - - import "github.com/coreos/etcd/pkg/testutil" - - func TestMain(m *testing.M) { - v := m.Run() - if v == 0 && testutil.CheckLeakedGoroutine() { - os.Exit(1) - } - os.Exit(v) - } - - func TestSample(t *testing.T) { - defer testutil.AfterTest(t) - ... - } - -*/ -func CheckLeakedGoroutine() bool { - if testing.Short() { - // not counting goroutines for leakage in -short mode - return false - } - gs := interestingGoroutines() - if len(gs) == 0 { - return false - } - - stackCount := make(map[string]int) - re := regexp.MustCompile(`\(0[0-9a-fx, ]*\)`) - for _, g := range gs { - // strip out pointer arguments in first function of stack dump - normalized := string(re.ReplaceAll([]byte(g), []byte("(...)"))) - stackCount[normalized]++ - } - - fmt.Fprintf(os.Stderr, "Too many goroutines running after all test(s).\n") - for stack, count := range stackCount { - fmt.Fprintf(os.Stderr, "%d instances of:\n%s\n", count, stack) - } - return true -} - -// CheckAfterTest returns an error if AfterTest would fail with an error. -func CheckAfterTest(d time.Duration) error { - http.DefaultTransport.(*http.Transport).CloseIdleConnections() - if testing.Short() { - return nil - } - var bad string - badSubstring := map[string]string{ - ").writeLoop(": "a Transport", - "created by net/http/httptest.(*Server).Start": "an httptest.Server", - "timeoutHandler": "a TimeoutHandler", - "net.(*netFD).connect(": "a timing out dial", - ").noteClientGone(": "a closenotifier sender", - ").readLoop(": "a Transport", - ".grpc": "a gRPC resource", - } - - var stacks string - begin := time.Now() - for time.Since(begin) < d { - bad = "" - stacks = strings.Join(interestingGoroutines(), "\n\n") - for substr, what := range badSubstring { - if strings.Contains(stacks, substr) { - bad = what - } - } - if bad == "" { - return nil - } - // Bad stuff found, but goroutines might just still be - // shutting down, so give it some time. - time.Sleep(50 * time.Millisecond) - } - return fmt.Errorf("appears to have leaked %s:\n%s", bad, stacks) -} - -// AfterTest is meant to run in a defer that executes after a test completes. -// It will detect common goroutine leaks, retrying in case there are goroutines -// not synchronously torn down, and fail the test if any goroutines are stuck. -func AfterTest(t *testing.T) { - if err := CheckAfterTest(300 * time.Millisecond); err != nil { - t.Errorf("Test %v", err) - } -} - -func interestingGoroutines() (gs []string) { - buf := make([]byte, 2<<20) - buf = buf[:runtime.Stack(buf, true)] - for _, g := range strings.Split(string(buf), "\n\n") { - sl := strings.SplitN(g, "\n", 2) - if len(sl) != 2 { - continue - } - stack := strings.TrimSpace(sl[1]) - if stack == "" || - strings.Contains(stack, "sync.(*WaitGroup).Done") || - strings.Contains(stack, "os.(*file).close") || - strings.Contains(stack, "created by os/signal.init") || - strings.Contains(stack, "runtime/panic.go") || - strings.Contains(stack, "created by testing.RunTests") || - strings.Contains(stack, "testing.Main(") || - strings.Contains(stack, "runtime.goexit") || - strings.Contains(stack, "github.com/coreos/etcd/pkg/testutil.interestingGoroutines") || - strings.Contains(stack, "github.com/coreos/etcd/pkg/logutil.(*MergeLogger).outputLoop") || - strings.Contains(stack, "github.com/golang/glog.(*loggingT).flushDaemon") || - strings.Contains(stack, "created by runtime.gc") || - strings.Contains(stack, "runtime.MHeap_Scavenger") { - continue - } - gs = append(gs, stack) - } - sort.Strings(gs) - return gs -} diff --git a/vendor/go.etcd.io/etcd/pkg/testutil/pauseable_handler.go b/vendor/go.etcd.io/etcd/pkg/testutil/pauseable_handler.go deleted file mode 100644 index e0d6aca26df7..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/testutil/pauseable_handler.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package testutil - -import ( - "net/http" - "sync" -) - -type PauseableHandler struct { - Next http.Handler - mu sync.Mutex - paused bool -} - -func (ph *PauseableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - ph.mu.Lock() - paused := ph.paused - ph.mu.Unlock() - if !paused { - ph.Next.ServeHTTP(w, r) - } else { - hj, ok := w.(http.Hijacker) - if !ok { - panic("webserver doesn't support hijacking") - } - conn, _, err := hj.Hijack() - if err != nil { - panic(err.Error()) - } - conn.Close() - } -} - -func (ph *PauseableHandler) Pause() { - ph.mu.Lock() - defer ph.mu.Unlock() - ph.paused = true -} - -func (ph *PauseableHandler) Resume() { - ph.mu.Lock() - defer ph.mu.Unlock() - ph.paused = false -} diff --git a/vendor/go.etcd.io/etcd/pkg/testutil/recorder.go b/vendor/go.etcd.io/etcd/pkg/testutil/recorder.go deleted file mode 100644 index bdbbd8cc5d52..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/testutil/recorder.go +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package testutil - -import ( - "errors" - "fmt" - "sync" - "time" -) - -type Action struct { - Name string - Params []interface{} -} - -type Recorder interface { - // Record publishes an Action (e.g., function call) which will - // be reflected by Wait() or Chan() - Record(a Action) - // Wait waits until at least n Actions are available or returns with error - Wait(n int) ([]Action, error) - // Action returns immediately available Actions - Action() []Action - // Chan returns the channel for actions published by Record - Chan() <-chan Action -} - -// RecorderBuffered appends all Actions to a slice -type RecorderBuffered struct { - sync.Mutex - actions []Action -} - -func (r *RecorderBuffered) Record(a Action) { - r.Lock() - r.actions = append(r.actions, a) - r.Unlock() -} -func (r *RecorderBuffered) Action() []Action { - r.Lock() - cpy := make([]Action, len(r.actions)) - copy(cpy, r.actions) - r.Unlock() - return cpy -} -func (r *RecorderBuffered) Wait(n int) (acts []Action, err error) { - // legacy racey behavior - WaitSchedule() - acts = r.Action() - if len(acts) < n { - err = newLenErr(n, len(acts)) - } - return acts, err -} - -func (r *RecorderBuffered) Chan() <-chan Action { - ch := make(chan Action) - go func() { - acts := r.Action() - for i := range acts { - ch <- acts[i] - } - close(ch) - }() - return ch -} - -// RecorderStream writes all Actions to an unbuffered channel -type recorderStream struct { - ch chan Action -} - -func NewRecorderStream() Recorder { - return &recorderStream{ch: make(chan Action)} -} - -func (r *recorderStream) Record(a Action) { - r.ch <- a -} - -func (r *recorderStream) Action() (acts []Action) { - for { - select { - case act := <-r.ch: - acts = append(acts, act) - default: - return acts - } - } -} - -func (r *recorderStream) Chan() <-chan Action { - return r.ch -} - -func (r *recorderStream) Wait(n int) ([]Action, error) { - acts := make([]Action, n) - timeoutC := time.After(5 * time.Second) - for i := 0; i < n; i++ { - select { - case acts[i] = <-r.ch: - case <-timeoutC: - acts = acts[:i] - return acts, newLenErr(n, i) - } - } - // extra wait to catch any Action spew - select { - case act := <-r.ch: - acts = append(acts, act) - case <-time.After(10 * time.Millisecond): - } - return acts, nil -} - -func newLenErr(expected int, actual int) error { - s := fmt.Sprintf("len(actions) = %d, expected >= %d", actual, expected) - return errors.New(s) -} diff --git a/vendor/go.etcd.io/etcd/pkg/testutil/testutil.go b/vendor/go.etcd.io/etcd/pkg/testutil/testutil.go deleted file mode 100644 index 0e02ddc0db73..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/testutil/testutil.go +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package testutil provides test utility functions. -package testutil - -import ( - "net/url" - "runtime" - "testing" - "time" -) - -// WaitSchedule briefly sleeps in order to invoke the go scheduler. -// TODO: improve this when we are able to know the schedule or status of target go-routine. -func WaitSchedule() { - time.Sleep(10 * time.Millisecond) -} - -func MustNewURLs(t *testing.T, urls []string) []url.URL { - if urls == nil { - return nil - } - var us []url.URL - for _, url := range urls { - u := MustNewURL(t, url) - us = append(us, *u) - } - return us -} - -func MustNewURL(t *testing.T, s string) *url.URL { - u, err := url.Parse(s) - if err != nil { - t.Fatalf("parse %v error: %v", s, err) - } - return u -} - -// FatalStack helps to fatal the test and print out the stacks of all running goroutines. -func FatalStack(t *testing.T, s string) { - stackTrace := make([]byte, 1024*1024) - n := runtime.Stack(stackTrace, true) - t.Error(string(stackTrace[:n])) - t.Fatalf(s) -} - -// ConditionFunc returns true when a condition is met. -type ConditionFunc func() (bool, error) - -// Poll calls a condition function repeatedly on a polling interval until it returns true, returns an error -// or the timeout is reached. If the condition function returns true or an error before the timeout, Poll -// immediately returns with the true value or the error. If the timeout is exceeded, Poll returns false. -func Poll(interval time.Duration, timeout time.Duration, condition ConditionFunc) (bool, error) { - timeoutCh := time.After(timeout) - ticker := time.NewTicker(interval) - defer ticker.Stop() - - for { - select { - case <-timeoutCh: - return false, nil - case <-ticker.C: - success, err := condition() - if err != nil { - return false, err - } - if success { - return true, nil - } - } - } -} diff --git a/vendor/go.etcd.io/etcd/pkg/tlsutil/cipher_suites.go b/vendor/go.etcd.io/etcd/pkg/tlsutil/cipher_suites.go deleted file mode 100644 index b5916bb54dce..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/tlsutil/cipher_suites.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tlsutil - -import "crypto/tls" - -// cipher suites implemented by Go -// https://github.com/golang/go/blob/dev.boringcrypto.go1.10/src/crypto/tls/cipher_suites.go -var cipherSuites = map[string]uint16{ - "TLS_RSA_WITH_RC4_128_SHA": tls.TLS_RSA_WITH_RC4_128_SHA, - "TLS_RSA_WITH_3DES_EDE_CBC_SHA": tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA, - "TLS_RSA_WITH_AES_128_CBC_SHA": tls.TLS_RSA_WITH_AES_128_CBC_SHA, - "TLS_RSA_WITH_AES_256_CBC_SHA": tls.TLS_RSA_WITH_AES_256_CBC_SHA, - "TLS_RSA_WITH_AES_128_CBC_SHA256": tls.TLS_RSA_WITH_AES_128_CBC_SHA256, - "TLS_RSA_WITH_AES_128_GCM_SHA256": tls.TLS_RSA_WITH_AES_128_GCM_SHA256, - "TLS_RSA_WITH_AES_256_GCM_SHA384": tls.TLS_RSA_WITH_AES_256_GCM_SHA384, - "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA": tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, - "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA": tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, - "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA": tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, - "TLS_ECDHE_RSA_WITH_RC4_128_SHA": tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA, - "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, - "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, - "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, - "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256": tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, - "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256": tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, - "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256": tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, - "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256": tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, - "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384": tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, - "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384": tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, - "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305": tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, - "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305": tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, -} - -// GetCipherSuite returns the corresponding cipher suite, -// and boolean value if it is supported. -func GetCipherSuite(s string) (uint16, bool) { - v, ok := cipherSuites[s] - return v, ok -} diff --git a/vendor/go.etcd.io/etcd/pkg/tlsutil/doc.go b/vendor/go.etcd.io/etcd/pkg/tlsutil/doc.go deleted file mode 100644 index 3b6aa670bafe..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/tlsutil/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package tlsutil provides utility functions for handling TLS. -package tlsutil diff --git a/vendor/go.etcd.io/etcd/pkg/tlsutil/tlsutil.go b/vendor/go.etcd.io/etcd/pkg/tlsutil/tlsutil.go deleted file mode 100644 index 79b1f632ed51..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/tlsutil/tlsutil.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tlsutil - -import ( - "crypto/tls" - "crypto/x509" - "encoding/pem" - "io/ioutil" -) - -// NewCertPool creates x509 certPool with provided CA files. -func NewCertPool(CAFiles []string) (*x509.CertPool, error) { - certPool := x509.NewCertPool() - - for _, CAFile := range CAFiles { - pemByte, err := ioutil.ReadFile(CAFile) - if err != nil { - return nil, err - } - - for { - var block *pem.Block - block, pemByte = pem.Decode(pemByte) - if block == nil { - break - } - cert, err := x509.ParseCertificate(block.Bytes) - if err != nil { - return nil, err - } - certPool.AddCert(cert) - } - } - - return certPool, nil -} - -// NewCert generates TLS cert by using the given cert,key and parse function. -func NewCert(certfile, keyfile string, parseFunc func([]byte, []byte) (tls.Certificate, error)) (*tls.Certificate, error) { - cert, err := ioutil.ReadFile(certfile) - if err != nil { - return nil, err - } - - key, err := ioutil.ReadFile(keyfile) - if err != nil { - return nil, err - } - - if parseFunc == nil { - parseFunc = tls.X509KeyPair - } - - tlsCert, err := parseFunc(cert, key) - if err != nil { - return nil, err - } - return &tlsCert, nil -} diff --git a/vendor/go.etcd.io/etcd/pkg/transport/doc.go b/vendor/go.etcd.io/etcd/pkg/transport/doc.go deleted file mode 100644 index 37658ce591a4..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/transport/doc.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package transport implements various HTTP transport utilities based on Go -// net package. -package transport diff --git a/vendor/go.etcd.io/etcd/pkg/transport/keepalive_listener.go b/vendor/go.etcd.io/etcd/pkg/transport/keepalive_listener.go deleted file mode 100644 index 4ff8e7f0010c..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/transport/keepalive_listener.go +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "crypto/tls" - "fmt" - "net" - "time" -) - -type keepAliveConn interface { - SetKeepAlive(bool) error - SetKeepAlivePeriod(d time.Duration) error -} - -// NewKeepAliveListener returns a listener that listens on the given address. -// Be careful when wrap around KeepAliveListener with another Listener if TLSInfo is not nil. -// Some pkgs (like go/http) might expect Listener to return TLSConn type to start TLS handshake. -// http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html -func NewKeepAliveListener(l net.Listener, scheme string, tlscfg *tls.Config) (net.Listener, error) { - if scheme == "https" { - if tlscfg == nil { - return nil, fmt.Errorf("cannot listen on TLS for given listener: KeyFile and CertFile are not presented") - } - return newTLSKeepaliveListener(l, tlscfg), nil - } - - return &keepaliveListener{ - Listener: l, - }, nil -} - -type keepaliveListener struct{ net.Listener } - -func (kln *keepaliveListener) Accept() (net.Conn, error) { - c, err := kln.Listener.Accept() - if err != nil { - return nil, err - } - kac := c.(keepAliveConn) - // detection time: tcp_keepalive_time + tcp_keepalive_probes + tcp_keepalive_intvl - // default on linux: 30 + 8 * 30 - // default on osx: 30 + 8 * 75 - kac.SetKeepAlive(true) - kac.SetKeepAlivePeriod(30 * time.Second) - return c, nil -} - -// A tlsKeepaliveListener implements a network listener (net.Listener) for TLS connections. -type tlsKeepaliveListener struct { - net.Listener - config *tls.Config -} - -// Accept waits for and returns the next incoming TLS connection. -// The returned connection c is a *tls.Conn. -func (l *tlsKeepaliveListener) Accept() (c net.Conn, err error) { - c, err = l.Listener.Accept() - if err != nil { - return - } - kac := c.(keepAliveConn) - // detection time: tcp_keepalive_time + tcp_keepalive_probes + tcp_keepalive_intvl - // default on linux: 30 + 8 * 30 - // default on osx: 30 + 8 * 75 - kac.SetKeepAlive(true) - kac.SetKeepAlivePeriod(30 * time.Second) - c = tls.Server(c, l.config) - return c, nil -} - -// NewListener creates a Listener which accepts connections from an inner -// Listener and wraps each connection with Server. -// The configuration config must be non-nil and must have -// at least one certificate. -func newTLSKeepaliveListener(inner net.Listener, config *tls.Config) net.Listener { - l := &tlsKeepaliveListener{} - l.Listener = inner - l.config = config - return l -} diff --git a/vendor/go.etcd.io/etcd/pkg/transport/limit_listen.go b/vendor/go.etcd.io/etcd/pkg/transport/limit_listen.go deleted file mode 100644 index 930c542066f8..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/transport/limit_listen.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2013 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package transport provides network utility functions, complementing the more -// common ones in the net package. -package transport - -import ( - "errors" - "net" - "sync" - "time" -) - -var ( - ErrNotTCP = errors.New("only tcp connections have keepalive") -) - -// LimitListener returns a Listener that accepts at most n simultaneous -// connections from the provided Listener. -func LimitListener(l net.Listener, n int) net.Listener { - return &limitListener{l, make(chan struct{}, n)} -} - -type limitListener struct { - net.Listener - sem chan struct{} -} - -func (l *limitListener) acquire() { l.sem <- struct{}{} } -func (l *limitListener) release() { <-l.sem } - -func (l *limitListener) Accept() (net.Conn, error) { - l.acquire() - c, err := l.Listener.Accept() - if err != nil { - l.release() - return nil, err - } - return &limitListenerConn{Conn: c, release: l.release}, nil -} - -type limitListenerConn struct { - net.Conn - releaseOnce sync.Once - release func() -} - -func (l *limitListenerConn) Close() error { - err := l.Conn.Close() - l.releaseOnce.Do(l.release) - return err -} - -func (l *limitListenerConn) SetKeepAlive(doKeepAlive bool) error { - tcpc, ok := l.Conn.(*net.TCPConn) - if !ok { - return ErrNotTCP - } - return tcpc.SetKeepAlive(doKeepAlive) -} - -func (l *limitListenerConn) SetKeepAlivePeriod(d time.Duration) error { - tcpc, ok := l.Conn.(*net.TCPConn) - if !ok { - return ErrNotTCP - } - return tcpc.SetKeepAlivePeriod(d) -} diff --git a/vendor/go.etcd.io/etcd/pkg/transport/listener.go b/vendor/go.etcd.io/etcd/pkg/transport/listener.go deleted file mode 100644 index 48655063f6f2..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/transport/listener.go +++ /dev/null @@ -1,289 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "crypto/ecdsa" - "crypto/elliptic" - "crypto/rand" - "crypto/tls" - "crypto/x509" - "crypto/x509/pkix" - "encoding/pem" - "errors" - "fmt" - "math/big" - "net" - "os" - "path/filepath" - "strings" - "time" - - "github.com/coreos/etcd/pkg/tlsutil" -) - -func NewListener(addr, scheme string, tlsinfo *TLSInfo) (l net.Listener, err error) { - if l, err = newListener(addr, scheme); err != nil { - return nil, err - } - return wrapTLS(addr, scheme, tlsinfo, l) -} - -func newListener(addr string, scheme string) (net.Listener, error) { - if scheme == "unix" || scheme == "unixs" { - // unix sockets via unix://laddr - return NewUnixListener(addr) - } - return net.Listen("tcp", addr) -} - -func wrapTLS(addr, scheme string, tlsinfo *TLSInfo, l net.Listener) (net.Listener, error) { - if scheme != "https" && scheme != "unixs" { - return l, nil - } - return newTLSListener(l, tlsinfo, checkSAN) -} - -type TLSInfo struct { - CertFile string - KeyFile string - CAFile string // TODO: deprecate this in v4 - TrustedCAFile string - ClientCertAuth bool - CRLFile string - InsecureSkipVerify bool - - // ServerName ensures the cert matches the given host in case of discovery / virtual hosting - ServerName string - - // HandshakeFailure is optionally called when a connection fails to handshake. The - // connection will be closed immediately afterwards. - HandshakeFailure func(*tls.Conn, error) - - // CipherSuites is a list of supported cipher suites. - // If empty, Go auto-populates it by default. - // Note that cipher suites are prioritized in the given order. - CipherSuites []uint16 - - selfCert bool - - // parseFunc exists to simplify testing. Typically, parseFunc - // should be left nil. In that case, tls.X509KeyPair will be used. - parseFunc func([]byte, []byte) (tls.Certificate, error) - - // AllowedCN is a CN which must be provided by a client. - AllowedCN string -} - -func (info TLSInfo) String() string { - return fmt.Sprintf("cert = %s, key = %s, ca = %s, trusted-ca = %s, client-cert-auth = %v, crl-file = %s", info.CertFile, info.KeyFile, info.CAFile, info.TrustedCAFile, info.ClientCertAuth, info.CRLFile) -} - -func (info TLSInfo) Empty() bool { - return info.CertFile == "" && info.KeyFile == "" -} - -func SelfCert(dirpath string, hosts []string) (info TLSInfo, err error) { - if err = os.MkdirAll(dirpath, 0700); err != nil { - return - } - - certPath := filepath.Join(dirpath, "cert.pem") - keyPath := filepath.Join(dirpath, "key.pem") - _, errcert := os.Stat(certPath) - _, errkey := os.Stat(keyPath) - if errcert == nil && errkey == nil { - info.CertFile = certPath - info.KeyFile = keyPath - info.selfCert = true - return - } - - serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) - serialNumber, err := rand.Int(rand.Reader, serialNumberLimit) - if err != nil { - return - } - - tmpl := x509.Certificate{ - SerialNumber: serialNumber, - Subject: pkix.Name{Organization: []string{"etcd"}}, - NotBefore: time.Now(), - NotAfter: time.Now().Add(365 * (24 * time.Hour)), - - KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, - ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, - BasicConstraintsValid: true, - } - - for _, host := range hosts { - h, _, _ := net.SplitHostPort(host) - if ip := net.ParseIP(h); ip != nil { - tmpl.IPAddresses = append(tmpl.IPAddresses, ip) - } else { - tmpl.DNSNames = append(tmpl.DNSNames, h) - } - } - - priv, err := ecdsa.GenerateKey(elliptic.P521(), rand.Reader) - if err != nil { - return - } - - derBytes, err := x509.CreateCertificate(rand.Reader, &tmpl, &tmpl, &priv.PublicKey, priv) - if err != nil { - return - } - - certOut, err := os.Create(certPath) - if err != nil { - return - } - pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}) - certOut.Close() - - b, err := x509.MarshalECPrivateKey(priv) - if err != nil { - return - } - keyOut, err := os.OpenFile(keyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) - if err != nil { - return - } - pem.Encode(keyOut, &pem.Block{Type: "EC PRIVATE KEY", Bytes: b}) - keyOut.Close() - - return SelfCert(dirpath, hosts) -} - -func (info TLSInfo) baseConfig() (*tls.Config, error) { - if info.KeyFile == "" || info.CertFile == "" { - return nil, fmt.Errorf("KeyFile and CertFile must both be present[key: %v, cert: %v]", info.KeyFile, info.CertFile) - } - - _, err := tlsutil.NewCert(info.CertFile, info.KeyFile, info.parseFunc) - if err != nil { - return nil, err - } - - cfg := &tls.Config{ - MinVersion: tls.VersionTLS12, - ServerName: info.ServerName, - } - - if len(info.CipherSuites) > 0 { - cfg.CipherSuites = info.CipherSuites - } - - if info.AllowedCN != "" { - cfg.VerifyPeerCertificate = func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error { - for _, chains := range verifiedChains { - if len(chains) != 0 { - if info.AllowedCN == chains[0].Subject.CommonName { - return nil - } - } - } - return errors.New("CommonName authentication failed") - } - } - - // this only reloads certs when there's a client request - // TODO: support server-side refresh (e.g. inotify, SIGHUP), caching - cfg.GetCertificate = func(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error) { - return tlsutil.NewCert(info.CertFile, info.KeyFile, info.parseFunc) - } - cfg.GetClientCertificate = func(unused *tls.CertificateRequestInfo) (*tls.Certificate, error) { - return tlsutil.NewCert(info.CertFile, info.KeyFile, info.parseFunc) - } - return cfg, nil -} - -// cafiles returns a list of CA file paths. -func (info TLSInfo) cafiles() []string { - cs := make([]string, 0) - if info.CAFile != "" { - cs = append(cs, info.CAFile) - } - if info.TrustedCAFile != "" { - cs = append(cs, info.TrustedCAFile) - } - return cs -} - -// ServerConfig generates a tls.Config object for use by an HTTP server. -func (info TLSInfo) ServerConfig() (*tls.Config, error) { - cfg, err := info.baseConfig() - if err != nil { - return nil, err - } - - cfg.ClientAuth = tls.NoClientCert - if info.CAFile != "" || info.ClientCertAuth { - cfg.ClientAuth = tls.RequireAndVerifyClientCert - } - - CAFiles := info.cafiles() - if len(CAFiles) > 0 { - cp, err := tlsutil.NewCertPool(CAFiles) - if err != nil { - return nil, err - } - cfg.ClientCAs = cp - } - - // "h2" NextProtos is necessary for enabling HTTP2 for go's HTTP server - cfg.NextProtos = []string{"h2"} - - return cfg, nil -} - -// ClientConfig generates a tls.Config object for use by an HTTP client. -func (info TLSInfo) ClientConfig() (*tls.Config, error) { - var cfg *tls.Config - var err error - - if !info.Empty() { - cfg, err = info.baseConfig() - if err != nil { - return nil, err - } - } else { - cfg = &tls.Config{ServerName: info.ServerName} - } - cfg.InsecureSkipVerify = info.InsecureSkipVerify - - CAFiles := info.cafiles() - if len(CAFiles) > 0 { - cfg.RootCAs, err = tlsutil.NewCertPool(CAFiles) - if err != nil { - return nil, err - } - } - - if info.selfCert { - cfg.InsecureSkipVerify = true - } - return cfg, nil -} - -// IsClosedConnError returns true if the error is from closing listener, cmux. -// copied from golang.org/x/net/http2/http2.go -func IsClosedConnError(err error) bool { - // 'use of closed network connection' (Go <=1.8) - // 'use of closed file or network connection' (Go >1.8, internal/poll.ErrClosing) - // 'mux: listener closed' (cmux.ErrListenerClosed) - return err != nil && strings.Contains(err.Error(), "closed") -} diff --git a/vendor/go.etcd.io/etcd/pkg/transport/listener_tls.go b/vendor/go.etcd.io/etcd/pkg/transport/listener_tls.go deleted file mode 100644 index 6f1600945cc6..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/transport/listener_tls.go +++ /dev/null @@ -1,272 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "context" - "crypto/tls" - "crypto/x509" - "fmt" - "io/ioutil" - "net" - "strings" - "sync" -) - -// tlsListener overrides a TLS listener so it will reject client -// certificates with insufficient SAN credentials or CRL revoked -// certificates. -type tlsListener struct { - net.Listener - connc chan net.Conn - donec chan struct{} - err error - handshakeFailure func(*tls.Conn, error) - check tlsCheckFunc -} - -type tlsCheckFunc func(context.Context, *tls.Conn) error - -// NewTLSListener handshakes TLS connections and performs optional CRL checking. -func NewTLSListener(l net.Listener, tlsinfo *TLSInfo) (net.Listener, error) { - check := func(context.Context, *tls.Conn) error { return nil } - return newTLSListener(l, tlsinfo, check) -} - -func newTLSListener(l net.Listener, tlsinfo *TLSInfo, check tlsCheckFunc) (net.Listener, error) { - if tlsinfo == nil || tlsinfo.Empty() { - l.Close() - return nil, fmt.Errorf("cannot listen on TLS for %s: KeyFile and CertFile are not presented", l.Addr().String()) - } - tlscfg, err := tlsinfo.ServerConfig() - if err != nil { - return nil, err - } - - hf := tlsinfo.HandshakeFailure - if hf == nil { - hf = func(*tls.Conn, error) {} - } - - if len(tlsinfo.CRLFile) > 0 { - prevCheck := check - check = func(ctx context.Context, tlsConn *tls.Conn) error { - if err := prevCheck(ctx, tlsConn); err != nil { - return err - } - st := tlsConn.ConnectionState() - if certs := st.PeerCertificates; len(certs) > 0 { - return checkCRL(tlsinfo.CRLFile, certs) - } - return nil - } - } - - tlsl := &tlsListener{ - Listener: tls.NewListener(l, tlscfg), - connc: make(chan net.Conn), - donec: make(chan struct{}), - handshakeFailure: hf, - check: check, - } - go tlsl.acceptLoop() - return tlsl, nil -} - -func (l *tlsListener) Accept() (net.Conn, error) { - select { - case conn := <-l.connc: - return conn, nil - case <-l.donec: - return nil, l.err - } -} - -func checkSAN(ctx context.Context, tlsConn *tls.Conn) error { - st := tlsConn.ConnectionState() - if certs := st.PeerCertificates; len(certs) > 0 { - addr := tlsConn.RemoteAddr().String() - return checkCertSAN(ctx, certs[0], addr) - } - return nil -} - -// acceptLoop launches each TLS handshake in a separate goroutine -// to prevent a hanging TLS connection from blocking other connections. -func (l *tlsListener) acceptLoop() { - var wg sync.WaitGroup - var pendingMu sync.Mutex - - pending := make(map[net.Conn]struct{}) - ctx, cancel := context.WithCancel(context.Background()) - defer func() { - cancel() - pendingMu.Lock() - for c := range pending { - c.Close() - } - pendingMu.Unlock() - wg.Wait() - close(l.donec) - }() - - for { - conn, err := l.Listener.Accept() - if err != nil { - l.err = err - return - } - - pendingMu.Lock() - pending[conn] = struct{}{} - pendingMu.Unlock() - - wg.Add(1) - go func() { - defer func() { - if conn != nil { - conn.Close() - } - wg.Done() - }() - - tlsConn := conn.(*tls.Conn) - herr := tlsConn.Handshake() - pendingMu.Lock() - delete(pending, conn) - pendingMu.Unlock() - - if herr != nil { - l.handshakeFailure(tlsConn, herr) - return - } - if err := l.check(ctx, tlsConn); err != nil { - l.handshakeFailure(tlsConn, err) - return - } - - select { - case l.connc <- tlsConn: - conn = nil - case <-ctx.Done(): - } - }() - } -} - -func checkCRL(crlPath string, cert []*x509.Certificate) error { - // TODO: cache - crlBytes, err := ioutil.ReadFile(crlPath) - if err != nil { - return err - } - certList, err := x509.ParseCRL(crlBytes) - if err != nil { - return err - } - revokedSerials := make(map[string]struct{}) - for _, rc := range certList.TBSCertList.RevokedCertificates { - revokedSerials[string(rc.SerialNumber.Bytes())] = struct{}{} - } - for _, c := range cert { - serial := string(c.SerialNumber.Bytes()) - if _, ok := revokedSerials[serial]; ok { - return fmt.Errorf("transport: certificate serial %x revoked", serial) - } - } - return nil -} - -func checkCertSAN(ctx context.Context, cert *x509.Certificate, remoteAddr string) error { - if len(cert.IPAddresses) == 0 && len(cert.DNSNames) == 0 { - return nil - } - h, _, herr := net.SplitHostPort(remoteAddr) - if herr != nil { - return herr - } - if len(cert.IPAddresses) > 0 { - cerr := cert.VerifyHostname(h) - if cerr == nil { - return nil - } - if len(cert.DNSNames) == 0 { - return cerr - } - } - if len(cert.DNSNames) > 0 { - ok, err := isHostInDNS(ctx, h, cert.DNSNames) - if ok { - return nil - } - errStr := "" - if err != nil { - errStr = " (" + err.Error() + ")" - } - return fmt.Errorf("tls: %q does not match any of DNSNames %q"+errStr, h, cert.DNSNames) - } - return nil -} - -func isHostInDNS(ctx context.Context, host string, dnsNames []string) (ok bool, err error) { - // reverse lookup - wildcards, names := []string{}, []string{} - for _, dns := range dnsNames { - if strings.HasPrefix(dns, "*.") { - wildcards = append(wildcards, dns[1:]) - } else { - names = append(names, dns) - } - } - lnames, lerr := net.DefaultResolver.LookupAddr(ctx, host) - for _, name := range lnames { - // strip trailing '.' from PTR record - if name[len(name)-1] == '.' { - name = name[:len(name)-1] - } - for _, wc := range wildcards { - if strings.HasSuffix(name, wc) { - return true, nil - } - } - for _, n := range names { - if n == name { - return true, nil - } - } - } - err = lerr - - // forward lookup - for _, dns := range names { - addrs, lerr := net.DefaultResolver.LookupHost(ctx, dns) - if lerr != nil { - err = lerr - continue - } - for _, addr := range addrs { - if addr == host { - return true, nil - } - } - } - return false, err -} - -func (l *tlsListener) Close() error { - err := l.Listener.Close() - <-l.donec - return err -} diff --git a/vendor/go.etcd.io/etcd/pkg/transport/timeout_conn.go b/vendor/go.etcd.io/etcd/pkg/transport/timeout_conn.go deleted file mode 100644 index 7e8c02030fed..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/transport/timeout_conn.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "net" - "time" -) - -type timeoutConn struct { - net.Conn - wtimeoutd time.Duration - rdtimeoutd time.Duration -} - -func (c timeoutConn) Write(b []byte) (n int, err error) { - if c.wtimeoutd > 0 { - if err := c.SetWriteDeadline(time.Now().Add(c.wtimeoutd)); err != nil { - return 0, err - } - } - return c.Conn.Write(b) -} - -func (c timeoutConn) Read(b []byte) (n int, err error) { - if c.rdtimeoutd > 0 { - if err := c.SetReadDeadline(time.Now().Add(c.rdtimeoutd)); err != nil { - return 0, err - } - } - return c.Conn.Read(b) -} diff --git a/vendor/go.etcd.io/etcd/pkg/transport/timeout_dialer.go b/vendor/go.etcd.io/etcd/pkg/transport/timeout_dialer.go deleted file mode 100644 index 6ae39ecfc9b3..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/transport/timeout_dialer.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "net" - "time" -) - -type rwTimeoutDialer struct { - wtimeoutd time.Duration - rdtimeoutd time.Duration - net.Dialer -} - -func (d *rwTimeoutDialer) Dial(network, address string) (net.Conn, error) { - conn, err := d.Dialer.Dial(network, address) - tconn := &timeoutConn{ - rdtimeoutd: d.rdtimeoutd, - wtimeoutd: d.wtimeoutd, - Conn: conn, - } - return tconn, err -} diff --git a/vendor/go.etcd.io/etcd/pkg/transport/timeout_listener.go b/vendor/go.etcd.io/etcd/pkg/transport/timeout_listener.go deleted file mode 100644 index b35e04955bb0..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/transport/timeout_listener.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "net" - "time" -) - -// NewTimeoutListener returns a listener that listens on the given address. -// If read/write on the accepted connection blocks longer than its time limit, -// it will return timeout error. -func NewTimeoutListener(addr string, scheme string, tlsinfo *TLSInfo, rdtimeoutd, wtimeoutd time.Duration) (net.Listener, error) { - ln, err := newListener(addr, scheme) - if err != nil { - return nil, err - } - ln = &rwTimeoutListener{ - Listener: ln, - rdtimeoutd: rdtimeoutd, - wtimeoutd: wtimeoutd, - } - if ln, err = wrapTLS(addr, scheme, tlsinfo, ln); err != nil { - return nil, err - } - return ln, nil -} - -type rwTimeoutListener struct { - net.Listener - wtimeoutd time.Duration - rdtimeoutd time.Duration -} - -func (rwln *rwTimeoutListener) Accept() (net.Conn, error) { - c, err := rwln.Listener.Accept() - if err != nil { - return nil, err - } - return timeoutConn{ - Conn: c, - wtimeoutd: rwln.wtimeoutd, - rdtimeoutd: rwln.rdtimeoutd, - }, nil -} diff --git a/vendor/go.etcd.io/etcd/pkg/transport/timeout_transport.go b/vendor/go.etcd.io/etcd/pkg/transport/timeout_transport.go deleted file mode 100644 index ea16b4c0f869..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/transport/timeout_transport.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "net" - "net/http" - "time" -) - -// NewTimeoutTransport returns a transport created using the given TLS info. -// If read/write on the created connection blocks longer than its time limit, -// it will return timeout error. -// If read/write timeout is set, transport will not be able to reuse connection. -func NewTimeoutTransport(info TLSInfo, dialtimeoutd, rdtimeoutd, wtimeoutd time.Duration) (*http.Transport, error) { - tr, err := NewTransport(info, dialtimeoutd) - if err != nil { - return nil, err - } - - if rdtimeoutd != 0 || wtimeoutd != 0 { - // the timed out connection will timeout soon after it is idle. - // it should not be put back to http transport as an idle connection for future usage. - tr.MaxIdleConnsPerHost = -1 - } else { - // allow more idle connections between peers to avoid unnecessary port allocation. - tr.MaxIdleConnsPerHost = 1024 - } - - tr.Dial = (&rwTimeoutDialer{ - Dialer: net.Dialer{ - Timeout: dialtimeoutd, - KeepAlive: 30 * time.Second, - }, - rdtimeoutd: rdtimeoutd, - wtimeoutd: wtimeoutd, - }).Dial - return tr, nil -} diff --git a/vendor/go.etcd.io/etcd/pkg/transport/tls.go b/vendor/go.etcd.io/etcd/pkg/transport/tls.go deleted file mode 100644 index 62fe0d385195..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/transport/tls.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "fmt" - "strings" - "time" -) - -// ValidateSecureEndpoints scans the given endpoints against tls info, returning only those -// endpoints that could be validated as secure. -func ValidateSecureEndpoints(tlsInfo TLSInfo, eps []string) ([]string, error) { - t, err := NewTransport(tlsInfo, 5*time.Second) - if err != nil { - return nil, err - } - var errs []string - var endpoints []string - for _, ep := range eps { - if !strings.HasPrefix(ep, "https://") { - errs = append(errs, fmt.Sprintf("%q is insecure", ep)) - continue - } - conn, cerr := t.Dial("tcp", ep[len("https://"):]) - if cerr != nil { - errs = append(errs, fmt.Sprintf("%q failed to dial (%v)", ep, cerr)) - continue - } - conn.Close() - endpoints = append(endpoints, ep) - } - if len(errs) != 0 { - err = fmt.Errorf("%s", strings.Join(errs, ",")) - } - return endpoints, err -} diff --git a/vendor/go.etcd.io/etcd/pkg/transport/transport.go b/vendor/go.etcd.io/etcd/pkg/transport/transport.go deleted file mode 100644 index 4a7fe69d2e19..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/transport/transport.go +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "net" - "net/http" - "strings" - "time" -) - -type unixTransport struct{ *http.Transport } - -func NewTransport(info TLSInfo, dialtimeoutd time.Duration) (*http.Transport, error) { - cfg, err := info.ClientConfig() - if err != nil { - return nil, err - } - - t := &http.Transport{ - Proxy: http.ProxyFromEnvironment, - Dial: (&net.Dialer{ - Timeout: dialtimeoutd, - // value taken from http.DefaultTransport - KeepAlive: 30 * time.Second, - }).Dial, - // value taken from http.DefaultTransport - TLSHandshakeTimeout: 10 * time.Second, - TLSClientConfig: cfg, - } - - dialer := (&net.Dialer{ - Timeout: dialtimeoutd, - KeepAlive: 30 * time.Second, - }) - dial := func(net, addr string) (net.Conn, error) { - return dialer.Dial("unix", addr) - } - - tu := &http.Transport{ - Proxy: http.ProxyFromEnvironment, - Dial: dial, - TLSHandshakeTimeout: 10 * time.Second, - TLSClientConfig: cfg, - } - ut := &unixTransport{tu} - - t.RegisterProtocol("unix", ut) - t.RegisterProtocol("unixs", ut) - - return t, nil -} - -func (urt *unixTransport) RoundTrip(req *http.Request) (*http.Response, error) { - url := *req.URL - req.URL = &url - req.URL.Scheme = strings.Replace(req.URL.Scheme, "unix", "http", 1) - return urt.Transport.RoundTrip(req) -} diff --git a/vendor/go.etcd.io/etcd/pkg/transport/unix_listener.go b/vendor/go.etcd.io/etcd/pkg/transport/unix_listener.go deleted file mode 100644 index 123e2036f0f0..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/transport/unix_listener.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "net" - "os" -) - -type unixListener struct{ net.Listener } - -func NewUnixListener(addr string) (net.Listener, error) { - if err := os.Remove(addr); err != nil && !os.IsNotExist(err) { - return nil, err - } - l, err := net.Listen("unix", addr) - if err != nil { - return nil, err - } - return &unixListener{l}, nil -} - -func (ul *unixListener) Close() error { - if err := os.Remove(ul.Addr().String()); err != nil && !os.IsNotExist(err) { - return err - } - return ul.Listener.Close() -} diff --git a/vendor/go.etcd.io/etcd/pkg/types/doc.go b/vendor/go.etcd.io/etcd/pkg/types/doc.go deleted file mode 100644 index de8ef0bd7126..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/types/doc.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package types declares various data types and implements type-checking -// functions. -package types diff --git a/vendor/go.etcd.io/etcd/pkg/types/id.go b/vendor/go.etcd.io/etcd/pkg/types/id.go deleted file mode 100644 index 1b042d9ce652..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/types/id.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package types - -import ( - "strconv" -) - -// ID represents a generic identifier which is canonically -// stored as a uint64 but is typically represented as a -// base-16 string for input/output -type ID uint64 - -func (i ID) String() string { - return strconv.FormatUint(uint64(i), 16) -} - -// IDFromString attempts to create an ID from a base-16 string. -func IDFromString(s string) (ID, error) { - i, err := strconv.ParseUint(s, 16, 64) - return ID(i), err -} - -// IDSlice implements the sort interface -type IDSlice []ID - -func (p IDSlice) Len() int { return len(p) } -func (p IDSlice) Less(i, j int) bool { return uint64(p[i]) < uint64(p[j]) } -func (p IDSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } diff --git a/vendor/go.etcd.io/etcd/pkg/types/set.go b/vendor/go.etcd.io/etcd/pkg/types/set.go deleted file mode 100644 index c111b0c0c0bb..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/types/set.go +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package types - -import ( - "reflect" - "sort" - "sync" -) - -type Set interface { - Add(string) - Remove(string) - Contains(string) bool - Equals(Set) bool - Length() int - Values() []string - Copy() Set - Sub(Set) Set -} - -func NewUnsafeSet(values ...string) *unsafeSet { - set := &unsafeSet{make(map[string]struct{})} - for _, v := range values { - set.Add(v) - } - return set -} - -func NewThreadsafeSet(values ...string) *tsafeSet { - us := NewUnsafeSet(values...) - return &tsafeSet{us, sync.RWMutex{}} -} - -type unsafeSet struct { - d map[string]struct{} -} - -// Add adds a new value to the set (no-op if the value is already present) -func (us *unsafeSet) Add(value string) { - us.d[value] = struct{}{} -} - -// Remove removes the given value from the set -func (us *unsafeSet) Remove(value string) { - delete(us.d, value) -} - -// Contains returns whether the set contains the given value -func (us *unsafeSet) Contains(value string) (exists bool) { - _, exists = us.d[value] - return exists -} - -// ContainsAll returns whether the set contains all given values -func (us *unsafeSet) ContainsAll(values []string) bool { - for _, s := range values { - if !us.Contains(s) { - return false - } - } - return true -} - -// Equals returns whether the contents of two sets are identical -func (us *unsafeSet) Equals(other Set) bool { - v1 := sort.StringSlice(us.Values()) - v2 := sort.StringSlice(other.Values()) - v1.Sort() - v2.Sort() - return reflect.DeepEqual(v1, v2) -} - -// Length returns the number of elements in the set -func (us *unsafeSet) Length() int { - return len(us.d) -} - -// Values returns the values of the Set in an unspecified order. -func (us *unsafeSet) Values() (values []string) { - values = make([]string, 0) - for val := range us.d { - values = append(values, val) - } - return values -} - -// Copy creates a new Set containing the values of the first -func (us *unsafeSet) Copy() Set { - cp := NewUnsafeSet() - for val := range us.d { - cp.Add(val) - } - - return cp -} - -// Sub removes all elements in other from the set -func (us *unsafeSet) Sub(other Set) Set { - oValues := other.Values() - result := us.Copy().(*unsafeSet) - - for _, val := range oValues { - if _, ok := result.d[val]; !ok { - continue - } - delete(result.d, val) - } - - return result -} - -type tsafeSet struct { - us *unsafeSet - m sync.RWMutex -} - -func (ts *tsafeSet) Add(value string) { - ts.m.Lock() - defer ts.m.Unlock() - ts.us.Add(value) -} - -func (ts *tsafeSet) Remove(value string) { - ts.m.Lock() - defer ts.m.Unlock() - ts.us.Remove(value) -} - -func (ts *tsafeSet) Contains(value string) (exists bool) { - ts.m.RLock() - defer ts.m.RUnlock() - return ts.us.Contains(value) -} - -func (ts *tsafeSet) Equals(other Set) bool { - ts.m.RLock() - defer ts.m.RUnlock() - return ts.us.Equals(other) -} - -func (ts *tsafeSet) Length() int { - ts.m.RLock() - defer ts.m.RUnlock() - return ts.us.Length() -} - -func (ts *tsafeSet) Values() (values []string) { - ts.m.RLock() - defer ts.m.RUnlock() - return ts.us.Values() -} - -func (ts *tsafeSet) Copy() Set { - ts.m.RLock() - defer ts.m.RUnlock() - usResult := ts.us.Copy().(*unsafeSet) - return &tsafeSet{usResult, sync.RWMutex{}} -} - -func (ts *tsafeSet) Sub(other Set) Set { - ts.m.RLock() - defer ts.m.RUnlock() - usResult := ts.us.Sub(other).(*unsafeSet) - return &tsafeSet{usResult, sync.RWMutex{}} -} diff --git a/vendor/go.etcd.io/etcd/pkg/types/slice.go b/vendor/go.etcd.io/etcd/pkg/types/slice.go deleted file mode 100644 index 0dd9ca798ae4..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/types/slice.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package types - -// Uint64Slice implements sort interface -type Uint64Slice []uint64 - -func (p Uint64Slice) Len() int { return len(p) } -func (p Uint64Slice) Less(i, j int) bool { return p[i] < p[j] } -func (p Uint64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } diff --git a/vendor/go.etcd.io/etcd/pkg/types/urls.go b/vendor/go.etcd.io/etcd/pkg/types/urls.go deleted file mode 100644 index 9e5d03ff6457..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/types/urls.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package types - -import ( - "errors" - "fmt" - "net" - "net/url" - "sort" - "strings" -) - -type URLs []url.URL - -func NewURLs(strs []string) (URLs, error) { - all := make([]url.URL, len(strs)) - if len(all) == 0 { - return nil, errors.New("no valid URLs given") - } - for i, in := range strs { - in = strings.TrimSpace(in) - u, err := url.Parse(in) - if err != nil { - return nil, err - } - if u.Scheme != "http" && u.Scheme != "https" && u.Scheme != "unix" && u.Scheme != "unixs" { - return nil, fmt.Errorf("URL scheme must be http, https, unix, or unixs: %s", in) - } - if _, _, err := net.SplitHostPort(u.Host); err != nil { - return nil, fmt.Errorf(`URL address does not have the form "host:port": %s`, in) - } - if u.Path != "" { - return nil, fmt.Errorf("URL must not contain a path: %s", in) - } - all[i] = *u - } - us := URLs(all) - us.Sort() - - return us, nil -} - -func MustNewURLs(strs []string) URLs { - urls, err := NewURLs(strs) - if err != nil { - panic(err) - } - return urls -} - -func (us URLs) String() string { - return strings.Join(us.StringSlice(), ",") -} - -func (us *URLs) Sort() { - sort.Sort(us) -} -func (us URLs) Len() int { return len(us) } -func (us URLs) Less(i, j int) bool { return us[i].String() < us[j].String() } -func (us URLs) Swap(i, j int) { us[i], us[j] = us[j], us[i] } - -func (us URLs) StringSlice() []string { - out := make([]string, len(us)) - for i := range us { - out[i] = us[i].String() - } - - return out -} diff --git a/vendor/go.etcd.io/etcd/pkg/types/urlsmap.go b/vendor/go.etcd.io/etcd/pkg/types/urlsmap.go deleted file mode 100644 index 47690cc381a3..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/types/urlsmap.go +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package types - -import ( - "fmt" - "sort" - "strings" -) - -// URLsMap is a map from a name to its URLs. -type URLsMap map[string]URLs - -// NewURLsMap returns a URLsMap instantiated from the given string, -// which consists of discovery-formatted names-to-URLs, like: -// mach0=http://1.1.1.1:2380,mach0=http://2.2.2.2::2380,mach1=http://3.3.3.3:2380,mach2=http://4.4.4.4:2380 -func NewURLsMap(s string) (URLsMap, error) { - m := parse(s) - - cl := URLsMap{} - for name, urls := range m { - us, err := NewURLs(urls) - if err != nil { - return nil, err - } - cl[name] = us - } - return cl, nil -} - -// NewURLsMapFromStringMap takes a map of strings and returns a URLsMap. The -// string values in the map can be multiple values separated by the sep string. -func NewURLsMapFromStringMap(m map[string]string, sep string) (URLsMap, error) { - var err error - um := URLsMap{} - for k, v := range m { - um[k], err = NewURLs(strings.Split(v, sep)) - if err != nil { - return nil, err - } - } - return um, nil -} - -// String turns URLsMap into discovery-formatted name-to-URLs sorted by name. -func (c URLsMap) String() string { - var pairs []string - for name, urls := range c { - for _, url := range urls { - pairs = append(pairs, fmt.Sprintf("%s=%s", name, url.String())) - } - } - sort.Strings(pairs) - return strings.Join(pairs, ",") -} - -// URLs returns a list of all URLs. -// The returned list is sorted in ascending lexicographical order. -func (c URLsMap) URLs() []string { - var urls []string - for _, us := range c { - for _, u := range us { - urls = append(urls, u.String()) - } - } - sort.Strings(urls) - return urls -} - -// Len returns the size of URLsMap. -func (c URLsMap) Len() int { - return len(c) -} - -// parse parses the given string and returns a map listing the values specified for each key. -func parse(s string) map[string][]string { - m := make(map[string][]string) - for s != "" { - key := s - if i := strings.IndexAny(key, ","); i >= 0 { - key, s = key[:i], key[i+1:] - } else { - s = "" - } - if key == "" { - continue - } - value := "" - if i := strings.Index(key, "="); i >= 0 { - key, value = key[:i], key[i+1:] - } - m[key] = append(m[key], value) - } - return m -} diff --git a/vendor/go.etcd.io/etcd/pkg/wait/wait.go b/vendor/go.etcd.io/etcd/pkg/wait/wait.go deleted file mode 100644 index 9b1df419e292..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/wait/wait.go +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package wait provides utility functions for polling, listening using Go -// channel. -package wait - -import ( - "log" - "sync" -) - -// Wait is an interface that provides the ability to wait and trigger events that -// are associated with IDs. -type Wait interface { - // Register waits returns a chan that waits on the given ID. - // The chan will be triggered when Trigger is called with - // the same ID. - Register(id uint64) <-chan interface{} - // Trigger triggers the waiting chans with the given ID. - Trigger(id uint64, x interface{}) - IsRegistered(id uint64) bool -} - -type list struct { - l sync.RWMutex - m map[uint64]chan interface{} -} - -// New creates a Wait. -func New() Wait { - return &list{m: make(map[uint64]chan interface{})} -} - -func (w *list) Register(id uint64) <-chan interface{} { - w.l.Lock() - defer w.l.Unlock() - ch := w.m[id] - if ch == nil { - ch = make(chan interface{}, 1) - w.m[id] = ch - } else { - log.Panicf("dup id %x", id) - } - return ch -} - -func (w *list) Trigger(id uint64, x interface{}) { - w.l.Lock() - ch := w.m[id] - delete(w.m, id) - w.l.Unlock() - if ch != nil { - ch <- x - close(ch) - } -} - -func (w *list) IsRegistered(id uint64) bool { - w.l.RLock() - defer w.l.RUnlock() - _, ok := w.m[id] - return ok -} - -type waitWithResponse struct { - ch <-chan interface{} -} - -func NewWithResponse(ch <-chan interface{}) Wait { - return &waitWithResponse{ch: ch} -} - -func (w *waitWithResponse) Register(id uint64) <-chan interface{} { - return w.ch -} -func (w *waitWithResponse) Trigger(id uint64, x interface{}) {} -func (w *waitWithResponse) IsRegistered(id uint64) bool { - panic("waitWithResponse.IsRegistered() shouldn't be called") -} diff --git a/vendor/go.etcd.io/etcd/pkg/wait/wait_time.go b/vendor/go.etcd.io/etcd/pkg/wait/wait_time.go deleted file mode 100644 index 297e48a47d76..000000000000 --- a/vendor/go.etcd.io/etcd/pkg/wait/wait_time.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wait - -import "sync" - -type WaitTime interface { - // Wait returns a chan that waits on the given logical deadline. - // The chan will be triggered when Trigger is called with a - // deadline that is later than the one it is waiting for. - Wait(deadline uint64) <-chan struct{} - // Trigger triggers all the waiting chans with an earlier logical deadline. - Trigger(deadline uint64) -} - -var closec chan struct{} - -func init() { closec = make(chan struct{}); close(closec) } - -type timeList struct { - l sync.Mutex - lastTriggerDeadline uint64 - m map[uint64]chan struct{} -} - -func NewTimeList() *timeList { - return &timeList{m: make(map[uint64]chan struct{})} -} - -func (tl *timeList) Wait(deadline uint64) <-chan struct{} { - tl.l.Lock() - defer tl.l.Unlock() - if tl.lastTriggerDeadline >= deadline { - return closec - } - ch := tl.m[deadline] - if ch == nil { - ch = make(chan struct{}) - tl.m[deadline] = ch - } - return ch -} - -func (tl *timeList) Trigger(deadline uint64) { - tl.l.Lock() - defer tl.l.Unlock() - tl.lastTriggerDeadline = deadline - for t, ch := range tl.m { - if t <= deadline { - delete(tl.m, t) - close(ch) - } - } -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/auth_client_adapter.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/auth_client_adapter.go deleted file mode 100644 index 33dc91f013f9..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/auth_client_adapter.go +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - grpc "google.golang.org/grpc" -) - -type as2ac struct{ as pb.AuthServer } - -func AuthServerToAuthClient(as pb.AuthServer) pb.AuthClient { - return &as2ac{as} -} - -func (s *as2ac) AuthEnable(ctx context.Context, in *pb.AuthEnableRequest, opts ...grpc.CallOption) (*pb.AuthEnableResponse, error) { - return s.as.AuthEnable(ctx, in) -} - -func (s *as2ac) AuthDisable(ctx context.Context, in *pb.AuthDisableRequest, opts ...grpc.CallOption) (*pb.AuthDisableResponse, error) { - return s.as.AuthDisable(ctx, in) -} - -func (s *as2ac) Authenticate(ctx context.Context, in *pb.AuthenticateRequest, opts ...grpc.CallOption) (*pb.AuthenticateResponse, error) { - return s.as.Authenticate(ctx, in) -} - -func (s *as2ac) RoleAdd(ctx context.Context, in *pb.AuthRoleAddRequest, opts ...grpc.CallOption) (*pb.AuthRoleAddResponse, error) { - return s.as.RoleAdd(ctx, in) -} - -func (s *as2ac) RoleDelete(ctx context.Context, in *pb.AuthRoleDeleteRequest, opts ...grpc.CallOption) (*pb.AuthRoleDeleteResponse, error) { - return s.as.RoleDelete(ctx, in) -} - -func (s *as2ac) RoleGet(ctx context.Context, in *pb.AuthRoleGetRequest, opts ...grpc.CallOption) (*pb.AuthRoleGetResponse, error) { - return s.as.RoleGet(ctx, in) -} - -func (s *as2ac) RoleList(ctx context.Context, in *pb.AuthRoleListRequest, opts ...grpc.CallOption) (*pb.AuthRoleListResponse, error) { - return s.as.RoleList(ctx, in) -} - -func (s *as2ac) RoleRevokePermission(ctx context.Context, in *pb.AuthRoleRevokePermissionRequest, opts ...grpc.CallOption) (*pb.AuthRoleRevokePermissionResponse, error) { - return s.as.RoleRevokePermission(ctx, in) -} - -func (s *as2ac) RoleGrantPermission(ctx context.Context, in *pb.AuthRoleGrantPermissionRequest, opts ...grpc.CallOption) (*pb.AuthRoleGrantPermissionResponse, error) { - return s.as.RoleGrantPermission(ctx, in) -} - -func (s *as2ac) UserDelete(ctx context.Context, in *pb.AuthUserDeleteRequest, opts ...grpc.CallOption) (*pb.AuthUserDeleteResponse, error) { - return s.as.UserDelete(ctx, in) -} - -func (s *as2ac) UserAdd(ctx context.Context, in *pb.AuthUserAddRequest, opts ...grpc.CallOption) (*pb.AuthUserAddResponse, error) { - return s.as.UserAdd(ctx, in) -} - -func (s *as2ac) UserGet(ctx context.Context, in *pb.AuthUserGetRequest, opts ...grpc.CallOption) (*pb.AuthUserGetResponse, error) { - return s.as.UserGet(ctx, in) -} - -func (s *as2ac) UserList(ctx context.Context, in *pb.AuthUserListRequest, opts ...grpc.CallOption) (*pb.AuthUserListResponse, error) { - return s.as.UserList(ctx, in) -} - -func (s *as2ac) UserGrantRole(ctx context.Context, in *pb.AuthUserGrantRoleRequest, opts ...grpc.CallOption) (*pb.AuthUserGrantRoleResponse, error) { - return s.as.UserGrantRole(ctx, in) -} - -func (s *as2ac) UserRevokeRole(ctx context.Context, in *pb.AuthUserRevokeRoleRequest, opts ...grpc.CallOption) (*pb.AuthUserRevokeRoleResponse, error) { - return s.as.UserRevokeRole(ctx, in) -} - -func (s *as2ac) UserChangePassword(ctx context.Context, in *pb.AuthUserChangePasswordRequest, opts ...grpc.CallOption) (*pb.AuthUserChangePasswordResponse, error) { - return s.as.UserChangePassword(ctx, in) -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/chan_stream.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/chan_stream.go deleted file mode 100644 index 82e34119311f..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/chan_stream.go +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - "google.golang.org/grpc" - "google.golang.org/grpc/metadata" -) - -// chanServerStream implements grpc.ServerStream with a chanStream -type chanServerStream struct { - headerc chan<- metadata.MD - trailerc chan<- metadata.MD - grpc.Stream - - headers []metadata.MD -} - -func (ss *chanServerStream) SendHeader(md metadata.MD) error { - if ss.headerc == nil { - return errAlreadySentHeader - } - outmd := make(map[string][]string) - for _, h := range append(ss.headers, md) { - for k, v := range h { - outmd[k] = v - } - } - select { - case ss.headerc <- outmd: - ss.headerc = nil - ss.headers = nil - return nil - case <-ss.Context().Done(): - } - return ss.Context().Err() -} - -func (ss *chanServerStream) SetHeader(md metadata.MD) error { - if ss.headerc == nil { - return errAlreadySentHeader - } - ss.headers = append(ss.headers, md) - return nil -} - -func (ss *chanServerStream) SetTrailer(md metadata.MD) { - ss.trailerc <- md -} - -// chanClientStream implements grpc.ClientStream with a chanStream -type chanClientStream struct { - headerc <-chan metadata.MD - trailerc <-chan metadata.MD - *chanStream -} - -func (cs *chanClientStream) Header() (metadata.MD, error) { - select { - case md := <-cs.headerc: - return md, nil - case <-cs.Context().Done(): - } - return nil, cs.Context().Err() -} - -func (cs *chanClientStream) Trailer() metadata.MD { - select { - case md := <-cs.trailerc: - return md - case <-cs.Context().Done(): - return nil - } -} - -func (cs *chanClientStream) CloseSend() error { - close(cs.chanStream.sendc) - return nil -} - -// chanStream implements grpc.Stream using channels -type chanStream struct { - recvc <-chan interface{} - sendc chan<- interface{} - ctx context.Context - cancel context.CancelFunc -} - -func (s *chanStream) Context() context.Context { return s.ctx } - -func (s *chanStream) SendMsg(m interface{}) error { - select { - case s.sendc <- m: - if err, ok := m.(error); ok { - return err - } - return nil - case <-s.ctx.Done(): - } - return s.ctx.Err() -} - -func (s *chanStream) RecvMsg(m interface{}) error { - v := m.(*interface{}) - for { - select { - case msg, ok := <-s.recvc: - if !ok { - return grpc.ErrClientConnClosing - } - if err, ok := msg.(error); ok { - return err - } - *v = msg - return nil - case <-s.ctx.Done(): - } - if len(s.recvc) == 0 { - // prioritize any pending recv messages over canceled context - break - } - } - return s.ctx.Err() -} - -func newPipeStream(ctx context.Context, ssHandler func(chanServerStream) error) chanClientStream { - // ch1 is buffered so server can send error on close - ch1, ch2 := make(chan interface{}, 1), make(chan interface{}) - headerc, trailerc := make(chan metadata.MD, 1), make(chan metadata.MD, 1) - - cctx, ccancel := context.WithCancel(ctx) - cli := &chanStream{recvc: ch1, sendc: ch2, ctx: cctx, cancel: ccancel} - cs := chanClientStream{headerc, trailerc, cli} - - sctx, scancel := context.WithCancel(ctx) - srv := &chanStream{recvc: ch2, sendc: ch1, ctx: sctx, cancel: scancel} - ss := chanServerStream{headerc, trailerc, srv, nil} - - go func() { - if err := ssHandler(ss); err != nil { - select { - case srv.sendc <- err: - case <-sctx.Done(): - case <-cctx.Done(): - } - } - scancel() - ccancel() - }() - return cs -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/cluster_client_adapter.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/cluster_client_adapter.go deleted file mode 100644 index 6c0340998b9c..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/cluster_client_adapter.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" -) - -type cls2clc struct{ cls pb.ClusterServer } - -func ClusterServerToClusterClient(cls pb.ClusterServer) pb.ClusterClient { - return &cls2clc{cls} -} - -func (s *cls2clc) MemberList(ctx context.Context, r *pb.MemberListRequest, opts ...grpc.CallOption) (*pb.MemberListResponse, error) { - return s.cls.MemberList(ctx, r) -} - -func (s *cls2clc) MemberAdd(ctx context.Context, r *pb.MemberAddRequest, opts ...grpc.CallOption) (*pb.MemberAddResponse, error) { - return s.cls.MemberAdd(ctx, r) -} - -func (s *cls2clc) MemberUpdate(ctx context.Context, r *pb.MemberUpdateRequest, opts ...grpc.CallOption) (*pb.MemberUpdateResponse, error) { - return s.cls.MemberUpdate(ctx, r) -} - -func (s *cls2clc) MemberRemove(ctx context.Context, r *pb.MemberRemoveRequest, opts ...grpc.CallOption) (*pb.MemberRemoveResponse, error) { - return s.cls.MemberRemove(ctx, r) -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/doc.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/doc.go deleted file mode 100644 index 7170be233046..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/doc.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package adapter provides gRPC adapters between client and server -// gRPC interfaces without needing to go through a gRPC connection. -package adapter diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/election_client_adapter.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/election_client_adapter.go deleted file mode 100644 index a2ebf138f3be..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/election_client_adapter.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - "github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb" - - "google.golang.org/grpc" -) - -type es2ec struct{ es v3electionpb.ElectionServer } - -func ElectionServerToElectionClient(es v3electionpb.ElectionServer) v3electionpb.ElectionClient { - return &es2ec{es} -} - -func (s *es2ec) Campaign(ctx context.Context, r *v3electionpb.CampaignRequest, opts ...grpc.CallOption) (*v3electionpb.CampaignResponse, error) { - return s.es.Campaign(ctx, r) -} - -func (s *es2ec) Proclaim(ctx context.Context, r *v3electionpb.ProclaimRequest, opts ...grpc.CallOption) (*v3electionpb.ProclaimResponse, error) { - return s.es.Proclaim(ctx, r) -} - -func (s *es2ec) Leader(ctx context.Context, r *v3electionpb.LeaderRequest, opts ...grpc.CallOption) (*v3electionpb.LeaderResponse, error) { - return s.es.Leader(ctx, r) -} - -func (s *es2ec) Resign(ctx context.Context, r *v3electionpb.ResignRequest, opts ...grpc.CallOption) (*v3electionpb.ResignResponse, error) { - return s.es.Resign(ctx, r) -} - -func (s *es2ec) Observe(ctx context.Context, in *v3electionpb.LeaderRequest, opts ...grpc.CallOption) (v3electionpb.Election_ObserveClient, error) { - cs := newPipeStream(ctx, func(ss chanServerStream) error { - return s.es.Observe(in, &es2ecServerStream{ss}) - }) - return &es2ecClientStream{cs}, nil -} - -// es2ecClientStream implements Election_ObserveClient -type es2ecClientStream struct{ chanClientStream } - -// es2ecServerStream implements Election_ObserveServer -type es2ecServerStream struct{ chanServerStream } - -func (s *es2ecClientStream) Send(rr *v3electionpb.LeaderRequest) error { - return s.SendMsg(rr) -} -func (s *es2ecClientStream) Recv() (*v3electionpb.LeaderResponse, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*v3electionpb.LeaderResponse), nil -} - -func (s *es2ecServerStream) Send(rr *v3electionpb.LeaderResponse) error { - return s.SendMsg(rr) -} -func (s *es2ecServerStream) Recv() (*v3electionpb.LeaderRequest, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*v3electionpb.LeaderRequest), nil -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/kv_client_adapter.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/kv_client_adapter.go deleted file mode 100644 index acd5673d0058..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/kv_client_adapter.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - grpc "google.golang.org/grpc" -) - -type kvs2kvc struct{ kvs pb.KVServer } - -func KvServerToKvClient(kvs pb.KVServer) pb.KVClient { - return &kvs2kvc{kvs} -} - -func (s *kvs2kvc) Range(ctx context.Context, in *pb.RangeRequest, opts ...grpc.CallOption) (*pb.RangeResponse, error) { - return s.kvs.Range(ctx, in) -} - -func (s *kvs2kvc) Put(ctx context.Context, in *pb.PutRequest, opts ...grpc.CallOption) (*pb.PutResponse, error) { - return s.kvs.Put(ctx, in) -} - -func (s *kvs2kvc) DeleteRange(ctx context.Context, in *pb.DeleteRangeRequest, opts ...grpc.CallOption) (*pb.DeleteRangeResponse, error) { - return s.kvs.DeleteRange(ctx, in) -} - -func (s *kvs2kvc) Txn(ctx context.Context, in *pb.TxnRequest, opts ...grpc.CallOption) (*pb.TxnResponse, error) { - return s.kvs.Txn(ctx, in) -} - -func (s *kvs2kvc) Compact(ctx context.Context, in *pb.CompactionRequest, opts ...grpc.CallOption) (*pb.CompactionResponse, error) { - return s.kvs.Compact(ctx, in) -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/lease_client_adapter.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/lease_client_adapter.go deleted file mode 100644 index 84c48b591b04..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/lease_client_adapter.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" -) - -type ls2lc struct { - leaseServer pb.LeaseServer -} - -func LeaseServerToLeaseClient(ls pb.LeaseServer) pb.LeaseClient { - return &ls2lc{ls} -} - -func (c *ls2lc) LeaseGrant(ctx context.Context, in *pb.LeaseGrantRequest, opts ...grpc.CallOption) (*pb.LeaseGrantResponse, error) { - return c.leaseServer.LeaseGrant(ctx, in) -} - -func (c *ls2lc) LeaseRevoke(ctx context.Context, in *pb.LeaseRevokeRequest, opts ...grpc.CallOption) (*pb.LeaseRevokeResponse, error) { - return c.leaseServer.LeaseRevoke(ctx, in) -} - -func (c *ls2lc) LeaseKeepAlive(ctx context.Context, opts ...grpc.CallOption) (pb.Lease_LeaseKeepAliveClient, error) { - cs := newPipeStream(ctx, func(ss chanServerStream) error { - return c.leaseServer.LeaseKeepAlive(&ls2lcServerStream{ss}) - }) - return &ls2lcClientStream{cs}, nil -} - -func (c *ls2lc) LeaseTimeToLive(ctx context.Context, in *pb.LeaseTimeToLiveRequest, opts ...grpc.CallOption) (*pb.LeaseTimeToLiveResponse, error) { - return c.leaseServer.LeaseTimeToLive(ctx, in) -} - -func (c *ls2lc) LeaseLeases(ctx context.Context, in *pb.LeaseLeasesRequest, opts ...grpc.CallOption) (*pb.LeaseLeasesResponse, error) { - return c.leaseServer.LeaseLeases(ctx, in) -} - -// ls2lcClientStream implements Lease_LeaseKeepAliveClient -type ls2lcClientStream struct{ chanClientStream } - -// ls2lcServerStream implements Lease_LeaseKeepAliveServer -type ls2lcServerStream struct{ chanServerStream } - -func (s *ls2lcClientStream) Send(rr *pb.LeaseKeepAliveRequest) error { - return s.SendMsg(rr) -} -func (s *ls2lcClientStream) Recv() (*pb.LeaseKeepAliveResponse, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*pb.LeaseKeepAliveResponse), nil -} - -func (s *ls2lcServerStream) Send(rr *pb.LeaseKeepAliveResponse) error { - return s.SendMsg(rr) -} -func (s *ls2lcServerStream) Recv() (*pb.LeaseKeepAliveRequest, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*pb.LeaseKeepAliveRequest), nil -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/lock_client_adapter.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/lock_client_adapter.go deleted file mode 100644 index 9ce7913a3ba0..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/lock_client_adapter.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - "github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb" - - "google.golang.org/grpc" -) - -type ls2lsc struct{ ls v3lockpb.LockServer } - -func LockServerToLockClient(ls v3lockpb.LockServer) v3lockpb.LockClient { - return &ls2lsc{ls} -} - -func (s *ls2lsc) Lock(ctx context.Context, r *v3lockpb.LockRequest, opts ...grpc.CallOption) (*v3lockpb.LockResponse, error) { - return s.ls.Lock(ctx, r) -} - -func (s *ls2lsc) Unlock(ctx context.Context, r *v3lockpb.UnlockRequest, opts ...grpc.CallOption) (*v3lockpb.UnlockResponse, error) { - return s.ls.Unlock(ctx, r) -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/maintenance_client_adapter.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/maintenance_client_adapter.go deleted file mode 100644 index 92d9dfd204ef..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/maintenance_client_adapter.go +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" -) - -type mts2mtc struct{ mts pb.MaintenanceServer } - -func MaintenanceServerToMaintenanceClient(mts pb.MaintenanceServer) pb.MaintenanceClient { - return &mts2mtc{mts} -} - -func (s *mts2mtc) Alarm(ctx context.Context, r *pb.AlarmRequest, opts ...grpc.CallOption) (*pb.AlarmResponse, error) { - return s.mts.Alarm(ctx, r) -} - -func (s *mts2mtc) Status(ctx context.Context, r *pb.StatusRequest, opts ...grpc.CallOption) (*pb.StatusResponse, error) { - return s.mts.Status(ctx, r) -} - -func (s *mts2mtc) Defragment(ctx context.Context, dr *pb.DefragmentRequest, opts ...grpc.CallOption) (*pb.DefragmentResponse, error) { - return s.mts.Defragment(ctx, dr) -} - -func (s *mts2mtc) Hash(ctx context.Context, r *pb.HashRequest, opts ...grpc.CallOption) (*pb.HashResponse, error) { - return s.mts.Hash(ctx, r) -} - -func (s *mts2mtc) HashKV(ctx context.Context, r *pb.HashKVRequest, opts ...grpc.CallOption) (*pb.HashKVResponse, error) { - return s.mts.HashKV(ctx, r) -} - -func (s *mts2mtc) MoveLeader(ctx context.Context, r *pb.MoveLeaderRequest, opts ...grpc.CallOption) (*pb.MoveLeaderResponse, error) { - return s.mts.MoveLeader(ctx, r) -} - -func (s *mts2mtc) Snapshot(ctx context.Context, in *pb.SnapshotRequest, opts ...grpc.CallOption) (pb.Maintenance_SnapshotClient, error) { - cs := newPipeStream(ctx, func(ss chanServerStream) error { - return s.mts.Snapshot(in, &ss2scServerStream{ss}) - }) - return &ss2scClientStream{cs}, nil -} - -// ss2scClientStream implements Maintenance_SnapshotClient -type ss2scClientStream struct{ chanClientStream } - -// ss2scServerStream implements Maintenance_SnapshotServer -type ss2scServerStream struct{ chanServerStream } - -func (s *ss2scClientStream) Send(rr *pb.SnapshotRequest) error { - return s.SendMsg(rr) -} -func (s *ss2scClientStream) Recv() (*pb.SnapshotResponse, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*pb.SnapshotResponse), nil -} - -func (s *ss2scServerStream) Send(rr *pb.SnapshotResponse) error { - return s.SendMsg(rr) -} -func (s *ss2scServerStream) Recv() (*pb.SnapshotRequest, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*pb.SnapshotRequest), nil -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/watch_client_adapter.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/watch_client_adapter.go deleted file mode 100644 index afe61e837b56..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/adapter/watch_client_adapter.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - "errors" - - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "google.golang.org/grpc" -) - -var errAlreadySentHeader = errors.New("adapter: already sent header") - -type ws2wc struct{ wserv pb.WatchServer } - -func WatchServerToWatchClient(wserv pb.WatchServer) pb.WatchClient { - return &ws2wc{wserv} -} - -func (s *ws2wc) Watch(ctx context.Context, opts ...grpc.CallOption) (pb.Watch_WatchClient, error) { - cs := newPipeStream(ctx, func(ss chanServerStream) error { - return s.wserv.Watch(&ws2wcServerStream{ss}) - }) - return &ws2wcClientStream{cs}, nil -} - -// ws2wcClientStream implements Watch_WatchClient -type ws2wcClientStream struct{ chanClientStream } - -// ws2wcServerStream implements Watch_WatchServer -type ws2wcServerStream struct{ chanServerStream } - -func (s *ws2wcClientStream) Send(wr *pb.WatchRequest) error { - return s.SendMsg(wr) -} -func (s *ws2wcClientStream) Recv() (*pb.WatchResponse, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*pb.WatchResponse), nil -} - -func (s *ws2wcServerStream) Send(wr *pb.WatchResponse) error { - return s.SendMsg(wr) -} -func (s *ws2wcServerStream) Recv() (*pb.WatchRequest, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*pb.WatchRequest), nil -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/auth.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/auth.go deleted file mode 100644 index 0ed8d246d2bd..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/auth.go +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - - "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -type AuthProxy struct { - client *clientv3.Client -} - -func NewAuthProxy(c *clientv3.Client) pb.AuthServer { - return &AuthProxy{client: c} -} - -func (ap *AuthProxy) AuthEnable(ctx context.Context, r *pb.AuthEnableRequest) (*pb.AuthEnableResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).AuthEnable(ctx, r) -} - -func (ap *AuthProxy) AuthDisable(ctx context.Context, r *pb.AuthDisableRequest) (*pb.AuthDisableResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).AuthDisable(ctx, r) -} - -func (ap *AuthProxy) Authenticate(ctx context.Context, r *pb.AuthenticateRequest) (*pb.AuthenticateResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).Authenticate(ctx, r) -} - -func (ap *AuthProxy) RoleAdd(ctx context.Context, r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).RoleAdd(ctx, r) -} - -func (ap *AuthProxy) RoleDelete(ctx context.Context, r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).RoleDelete(ctx, r) -} - -func (ap *AuthProxy) RoleGet(ctx context.Context, r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).RoleGet(ctx, r) -} - -func (ap *AuthProxy) RoleList(ctx context.Context, r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).RoleList(ctx, r) -} - -func (ap *AuthProxy) RoleRevokePermission(ctx context.Context, r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).RoleRevokePermission(ctx, r) -} - -func (ap *AuthProxy) RoleGrantPermission(ctx context.Context, r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).RoleGrantPermission(ctx, r) -} - -func (ap *AuthProxy) UserAdd(ctx context.Context, r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).UserAdd(ctx, r) -} - -func (ap *AuthProxy) UserDelete(ctx context.Context, r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).UserDelete(ctx, r) -} - -func (ap *AuthProxy) UserGet(ctx context.Context, r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).UserGet(ctx, r) -} - -func (ap *AuthProxy) UserList(ctx context.Context, r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).UserList(ctx, r) -} - -func (ap *AuthProxy) UserGrantRole(ctx context.Context, r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).UserGrantRole(ctx, r) -} - -func (ap *AuthProxy) UserRevokeRole(ctx context.Context, r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).UserRevokeRole(ctx, r) -} - -func (ap *AuthProxy) UserChangePassword(ctx context.Context, r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) { - conn := ap.client.ActiveConnection() - return pb.NewAuthClient(conn).UserChangePassword(ctx, r) -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/cache/store.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/cache/store.go deleted file mode 100644 index 5765228e50f2..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/cache/store.go +++ /dev/null @@ -1,171 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package cache exports functionality for efficiently caching and mapping -// `RangeRequest`s to corresponding `RangeResponse`s. -package cache - -import ( - "errors" - "sync" - - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/pkg/adt" - "github.com/golang/groupcache/lru" -) - -var ( - DefaultMaxEntries = 2048 - ErrCompacted = rpctypes.ErrGRPCCompacted -) - -type Cache interface { - Add(req *pb.RangeRequest, resp *pb.RangeResponse) - Get(req *pb.RangeRequest) (*pb.RangeResponse, error) - Compact(revision int64) - Invalidate(key []byte, endkey []byte) - Size() int - Close() -} - -// keyFunc returns the key of a request, which is used to look up its caching response in the cache. -func keyFunc(req *pb.RangeRequest) string { - // TODO: use marshalTo to reduce allocation - b, err := req.Marshal() - if err != nil { - panic(err) - } - return string(b) -} - -func NewCache(maxCacheEntries int) Cache { - return &cache{ - lru: lru.New(maxCacheEntries), - compactedRev: -1, - } -} - -func (c *cache) Close() {} - -// cache implements Cache -type cache struct { - mu sync.RWMutex - lru *lru.Cache - - // a reverse index for cache invalidation - cachedRanges adt.IntervalTree - - compactedRev int64 -} - -// Add adds the response of a request to the cache if its revision is larger than the compacted revision of the cache. -func (c *cache) Add(req *pb.RangeRequest, resp *pb.RangeResponse) { - key := keyFunc(req) - - c.mu.Lock() - defer c.mu.Unlock() - - if req.Revision > c.compactedRev { - c.lru.Add(key, resp) - } - // we do not need to invalidate a request with a revision specified. - // so we do not need to add it into the reverse index. - if req.Revision != 0 { - return - } - - var ( - iv *adt.IntervalValue - ivl adt.Interval - ) - if len(req.RangeEnd) != 0 { - ivl = adt.NewStringAffineInterval(string(req.Key), string(req.RangeEnd)) - } else { - ivl = adt.NewStringAffinePoint(string(req.Key)) - } - - iv = c.cachedRanges.Find(ivl) - - if iv == nil { - val := map[string]struct{}{key: {}} - c.cachedRanges.Insert(ivl, val) - } else { - val := iv.Val.(map[string]struct{}) - val[key] = struct{}{} - iv.Val = val - } -} - -// Get looks up the caching response for a given request. -// Get is also responsible for lazy eviction when accessing compacted entries. -func (c *cache) Get(req *pb.RangeRequest) (*pb.RangeResponse, error) { - key := keyFunc(req) - - c.mu.Lock() - defer c.mu.Unlock() - - if req.Revision > 0 && req.Revision < c.compactedRev { - c.lru.Remove(key) - return nil, ErrCompacted - } - - if resp, ok := c.lru.Get(key); ok { - return resp.(*pb.RangeResponse), nil - } - return nil, errors.New("not exist") -} - -// Invalidate invalidates the cache entries that intersecting with the given range from key to endkey. -func (c *cache) Invalidate(key, endkey []byte) { - c.mu.Lock() - defer c.mu.Unlock() - - var ( - ivs []*adt.IntervalValue - ivl adt.Interval - ) - if len(endkey) == 0 { - ivl = adt.NewStringAffinePoint(string(key)) - } else { - ivl = adt.NewStringAffineInterval(string(key), string(endkey)) - } - - ivs = c.cachedRanges.Stab(ivl) - for _, iv := range ivs { - keys := iv.Val.(map[string]struct{}) - for key := range keys { - c.lru.Remove(key) - } - } - // delete after removing all keys since it is destructive to 'ivs' - c.cachedRanges.Delete(ivl) -} - -// Compact invalidate all caching response before the given rev. -// Replace with the invalidation is lazy. The actual removal happens when the entries is accessed. -func (c *cache) Compact(revision int64) { - c.mu.Lock() - defer c.mu.Unlock() - - if revision > c.compactedRev { - c.compactedRev = revision - } -} - -func (c *cache) Size() int { - c.mu.RLock() - defer c.mu.RUnlock() - return c.lru.Len() -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/cluster.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/cluster.go deleted file mode 100644 index 6e8d3c85bfba..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/cluster.go +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - "fmt" - "os" - "sync" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/naming" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "golang.org/x/time/rate" - gnaming "google.golang.org/grpc/naming" -) - -// allow maximum 1 retry per second -const resolveRetryRate = 1 - -type clusterProxy struct { - clus clientv3.Cluster - ctx context.Context - gr *naming.GRPCResolver - - // advertise client URL - advaddr string - prefix string - - umu sync.RWMutex - umap map[string]gnaming.Update -} - -// NewClusterProxy takes optional prefix to fetch grpc-proxy member endpoints. -// The returned channel is closed when there is grpc-proxy endpoint registered -// and the client's context is canceled so the 'register' loop returns. -func NewClusterProxy(c *clientv3.Client, advaddr string, prefix string) (pb.ClusterServer, <-chan struct{}) { - cp := &clusterProxy{ - clus: c.Cluster, - ctx: c.Ctx(), - gr: &naming.GRPCResolver{Client: c}, - - advaddr: advaddr, - prefix: prefix, - umap: make(map[string]gnaming.Update), - } - - donec := make(chan struct{}) - if advaddr != "" && prefix != "" { - go func() { - defer close(donec) - cp.resolve(prefix) - }() - return cp, donec - } - - close(donec) - return cp, donec -} - -func (cp *clusterProxy) resolve(prefix string) { - rm := rate.NewLimiter(rate.Limit(resolveRetryRate), resolveRetryRate) - for rm.Wait(cp.ctx) == nil { - wa, err := cp.gr.Resolve(prefix) - if err != nil { - plog.Warningf("failed to resolve %q (%v)", prefix, err) - continue - } - cp.monitor(wa) - } -} - -func (cp *clusterProxy) monitor(wa gnaming.Watcher) { - for cp.ctx.Err() == nil { - ups, err := wa.Next() - if err != nil { - plog.Warningf("clusterProxy watcher error (%v)", err) - if rpctypes.ErrorDesc(err) == naming.ErrWatcherClosed.Error() { - return - } - } - - cp.umu.Lock() - for i := range ups { - switch ups[i].Op { - case gnaming.Add: - cp.umap[ups[i].Addr] = *ups[i] - case gnaming.Delete: - delete(cp.umap, ups[i].Addr) - } - } - cp.umu.Unlock() - } -} - -func (cp *clusterProxy) MemberAdd(ctx context.Context, r *pb.MemberAddRequest) (*pb.MemberAddResponse, error) { - mresp, err := cp.clus.MemberAdd(ctx, r.PeerURLs) - if err != nil { - return nil, err - } - resp := (pb.MemberAddResponse)(*mresp) - return &resp, err -} - -func (cp *clusterProxy) MemberRemove(ctx context.Context, r *pb.MemberRemoveRequest) (*pb.MemberRemoveResponse, error) { - mresp, err := cp.clus.MemberRemove(ctx, r.ID) - if err != nil { - return nil, err - } - resp := (pb.MemberRemoveResponse)(*mresp) - return &resp, err -} - -func (cp *clusterProxy) MemberUpdate(ctx context.Context, r *pb.MemberUpdateRequest) (*pb.MemberUpdateResponse, error) { - mresp, err := cp.clus.MemberUpdate(ctx, r.ID, r.PeerURLs) - if err != nil { - return nil, err - } - resp := (pb.MemberUpdateResponse)(*mresp) - return &resp, err -} - -func (cp *clusterProxy) membersFromUpdates() ([]*pb.Member, error) { - cp.umu.RLock() - defer cp.umu.RUnlock() - mbs := make([]*pb.Member, 0, len(cp.umap)) - for addr, upt := range cp.umap { - m, err := decodeMeta(fmt.Sprint(upt.Metadata)) - if err != nil { - return nil, err - } - mbs = append(mbs, &pb.Member{Name: m.Name, ClientURLs: []string{addr}}) - } - return mbs, nil -} - -// MemberList wraps member list API with following rules: -// - If 'advaddr' is not empty and 'prefix' is not empty, return registered member lists via resolver -// - If 'advaddr' is not empty and 'prefix' is not empty and registered grpc-proxy members haven't been fetched, return the 'advaddr' -// - If 'advaddr' is not empty and 'prefix' is empty, return 'advaddr' without forcing it to 'register' -// - If 'advaddr' is empty, forward to member list API -func (cp *clusterProxy) MemberList(ctx context.Context, r *pb.MemberListRequest) (*pb.MemberListResponse, error) { - if cp.advaddr != "" { - if cp.prefix != "" { - mbs, err := cp.membersFromUpdates() - if err != nil { - return nil, err - } - if len(mbs) > 0 { - return &pb.MemberListResponse{Members: mbs}, nil - } - } - // prefix is empty or no grpc-proxy members haven't been registered - hostname, _ := os.Hostname() - return &pb.MemberListResponse{Members: []*pb.Member{{Name: hostname, ClientURLs: []string{cp.advaddr}}}}, nil - } - mresp, err := cp.clus.MemberList(ctx) - if err != nil { - return nil, err - } - resp := (pb.MemberListResponse)(*mresp) - return &resp, err -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/doc.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/doc.go deleted file mode 100644 index fc022e3c57e7..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package grpcproxy is an OSI level 7 proxy for etcd v3 API requests. -package grpcproxy diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/election.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/election.go deleted file mode 100644 index 4b4a4cc42109..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/election.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2017 The etcd Lockors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb" -) - -type electionProxy struct { - client *clientv3.Client -} - -func NewElectionProxy(client *clientv3.Client) v3electionpb.ElectionServer { - return &electionProxy{client: client} -} - -func (ep *electionProxy) Campaign(ctx context.Context, req *v3electionpb.CampaignRequest) (*v3electionpb.CampaignResponse, error) { - return v3electionpb.NewElectionClient(ep.client.ActiveConnection()).Campaign(ctx, req) -} - -func (ep *electionProxy) Proclaim(ctx context.Context, req *v3electionpb.ProclaimRequest) (*v3electionpb.ProclaimResponse, error) { - return v3electionpb.NewElectionClient(ep.client.ActiveConnection()).Proclaim(ctx, req) -} - -func (ep *electionProxy) Leader(ctx context.Context, req *v3electionpb.LeaderRequest) (*v3electionpb.LeaderResponse, error) { - return v3electionpb.NewElectionClient(ep.client.ActiveConnection()).Leader(ctx, req) -} - -func (ep *electionProxy) Observe(req *v3electionpb.LeaderRequest, s v3electionpb.Election_ObserveServer) error { - conn := ep.client.ActiveConnection() - ctx, cancel := context.WithCancel(s.Context()) - defer cancel() - sc, err := v3electionpb.NewElectionClient(conn).Observe(ctx, req) - if err != nil { - return err - } - for { - rr, err := sc.Recv() - if err != nil { - return err - } - if err = s.Send(rr); err != nil { - return err - } - } -} - -func (ep *electionProxy) Resign(ctx context.Context, req *v3electionpb.ResignRequest) (*v3electionpb.ResignResponse, error) { - return v3electionpb.NewElectionClient(ep.client.ActiveConnection()).Resign(ctx, req) -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/health.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/health.go deleted file mode 100644 index e5e91f29bb3c..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/health.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - "net/http" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/etcdhttp" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" -) - -// HandleHealth registers health handler on '/health'. -func HandleHealth(mux *http.ServeMux, c *clientv3.Client) { - mux.Handle(etcdhttp.PathHealth, etcdhttp.NewHealthHandler(func() etcdhttp.Health { return checkHealth(c) })) -} - -func checkHealth(c *clientv3.Client) etcdhttp.Health { - h := etcdhttp.Health{Health: "false"} - ctx, cancel := context.WithTimeout(c.Ctx(), time.Second) - _, err := c.Get(ctx, "a") - cancel() - if err == nil || err == rpctypes.ErrPermissionDenied { - h.Health = "true" - } - return h -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/kv.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/kv.go deleted file mode 100644 index 1c9860f98af3..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/kv.go +++ /dev/null @@ -1,232 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - - "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/proxy/grpcproxy/cache" -) - -type kvProxy struct { - kv clientv3.KV - cache cache.Cache -} - -func NewKvProxy(c *clientv3.Client) (pb.KVServer, <-chan struct{}) { - kv := &kvProxy{ - kv: c.KV, - cache: cache.NewCache(cache.DefaultMaxEntries), - } - donec := make(chan struct{}) - close(donec) - return kv, donec -} - -func (p *kvProxy) Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, error) { - if r.Serializable { - resp, err := p.cache.Get(r) - switch err { - case nil: - cacheHits.Inc() - return resp, nil - case cache.ErrCompacted: - cacheHits.Inc() - return nil, err - } - - cachedMisses.Inc() - } - - resp, err := p.kv.Do(ctx, RangeRequestToOp(r)) - if err != nil { - return nil, err - } - - // cache linearizable as serializable - req := *r - req.Serializable = true - gresp := (*pb.RangeResponse)(resp.Get()) - p.cache.Add(&req, gresp) - cacheKeys.Set(float64(p.cache.Size())) - - return gresp, nil -} - -func (p *kvProxy) Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error) { - p.cache.Invalidate(r.Key, nil) - cacheKeys.Set(float64(p.cache.Size())) - - resp, err := p.kv.Do(ctx, PutRequestToOp(r)) - return (*pb.PutResponse)(resp.Put()), err -} - -func (p *kvProxy) DeleteRange(ctx context.Context, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) { - p.cache.Invalidate(r.Key, r.RangeEnd) - cacheKeys.Set(float64(p.cache.Size())) - - resp, err := p.kv.Do(ctx, DelRequestToOp(r)) - return (*pb.DeleteRangeResponse)(resp.Del()), err -} - -func (p *kvProxy) txnToCache(reqs []*pb.RequestOp, resps []*pb.ResponseOp) { - for i := range resps { - switch tv := resps[i].Response.(type) { - case *pb.ResponseOp_ResponsePut: - p.cache.Invalidate(reqs[i].GetRequestPut().Key, nil) - case *pb.ResponseOp_ResponseDeleteRange: - rdr := reqs[i].GetRequestDeleteRange() - p.cache.Invalidate(rdr.Key, rdr.RangeEnd) - case *pb.ResponseOp_ResponseRange: - req := *(reqs[i].GetRequestRange()) - req.Serializable = true - p.cache.Add(&req, tv.ResponseRange) - } - } -} - -func (p *kvProxy) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error) { - op := TxnRequestToOp(r) - opResp, err := p.kv.Do(ctx, op) - if err != nil { - return nil, err - } - resp := opResp.Txn() - - // txn may claim an outdated key is updated; be safe and invalidate - for _, cmp := range r.Compare { - p.cache.Invalidate(cmp.Key, cmp.RangeEnd) - } - // update any fetched keys - if resp.Succeeded { - p.txnToCache(r.Success, resp.Responses) - } else { - p.txnToCache(r.Failure, resp.Responses) - } - - cacheKeys.Set(float64(p.cache.Size())) - - return (*pb.TxnResponse)(resp), nil -} - -func (p *kvProxy) Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error) { - var opts []clientv3.CompactOption - if r.Physical { - opts = append(opts, clientv3.WithCompactPhysical()) - } - - resp, err := p.kv.Compact(ctx, r.Revision, opts...) - if err == nil { - p.cache.Compact(r.Revision) - } - - cacheKeys.Set(float64(p.cache.Size())) - - return (*pb.CompactionResponse)(resp), err -} - -func requestOpToOp(union *pb.RequestOp) clientv3.Op { - switch tv := union.Request.(type) { - case *pb.RequestOp_RequestRange: - if tv.RequestRange != nil { - return RangeRequestToOp(tv.RequestRange) - } - case *pb.RequestOp_RequestPut: - if tv.RequestPut != nil { - return PutRequestToOp(tv.RequestPut) - } - case *pb.RequestOp_RequestDeleteRange: - if tv.RequestDeleteRange != nil { - return DelRequestToOp(tv.RequestDeleteRange) - } - case *pb.RequestOp_RequestTxn: - if tv.RequestTxn != nil { - return TxnRequestToOp(tv.RequestTxn) - } - } - panic("unknown request") -} - -func RangeRequestToOp(r *pb.RangeRequest) clientv3.Op { - opts := []clientv3.OpOption{} - if len(r.RangeEnd) != 0 { - opts = append(opts, clientv3.WithRange(string(r.RangeEnd))) - } - opts = append(opts, clientv3.WithRev(r.Revision)) - opts = append(opts, clientv3.WithLimit(r.Limit)) - opts = append(opts, clientv3.WithSort( - clientv3.SortTarget(r.SortTarget), - clientv3.SortOrder(r.SortOrder)), - ) - opts = append(opts, clientv3.WithMaxCreateRev(r.MaxCreateRevision)) - opts = append(opts, clientv3.WithMinCreateRev(r.MinCreateRevision)) - opts = append(opts, clientv3.WithMaxModRev(r.MaxModRevision)) - opts = append(opts, clientv3.WithMinModRev(r.MinModRevision)) - if r.CountOnly { - opts = append(opts, clientv3.WithCountOnly()) - } - if r.KeysOnly { - opts = append(opts, clientv3.WithKeysOnly()) - } - if r.Serializable { - opts = append(opts, clientv3.WithSerializable()) - } - - return clientv3.OpGet(string(r.Key), opts...) -} - -func PutRequestToOp(r *pb.PutRequest) clientv3.Op { - opts := []clientv3.OpOption{} - opts = append(opts, clientv3.WithLease(clientv3.LeaseID(r.Lease))) - if r.IgnoreValue { - opts = append(opts, clientv3.WithIgnoreValue()) - } - if r.IgnoreLease { - opts = append(opts, clientv3.WithIgnoreLease()) - } - if r.PrevKv { - opts = append(opts, clientv3.WithPrevKV()) - } - return clientv3.OpPut(string(r.Key), string(r.Value), opts...) -} - -func DelRequestToOp(r *pb.DeleteRangeRequest) clientv3.Op { - opts := []clientv3.OpOption{} - if len(r.RangeEnd) != 0 { - opts = append(opts, clientv3.WithRange(string(r.RangeEnd))) - } - if r.PrevKv { - opts = append(opts, clientv3.WithPrevKV()) - } - return clientv3.OpDelete(string(r.Key), opts...) -} - -func TxnRequestToOp(r *pb.TxnRequest) clientv3.Op { - cmps := make([]clientv3.Cmp, len(r.Compare)) - thenops := make([]clientv3.Op, len(r.Success)) - elseops := make([]clientv3.Op, len(r.Failure)) - for i := range r.Compare { - cmps[i] = (clientv3.Cmp)(*r.Compare[i]) - } - for i := range r.Success { - thenops[i] = requestOpToOp(r.Success[i]) - } - for i := range r.Failure { - elseops[i] = requestOpToOp(r.Failure[i]) - } - return clientv3.OpTxn(cmps, thenops, elseops) -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/leader.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/leader.go deleted file mode 100644 index 042c949b7080..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/leader.go +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - "math" - "sync" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - - "golang.org/x/time/rate" - "google.golang.org/grpc" -) - -const ( - lostLeaderKey = "__lostleader" // watched to detect leader loss - retryPerSecond = 10 -) - -type leader struct { - ctx context.Context - w clientv3.Watcher - // mu protects leaderc updates. - mu sync.RWMutex - leaderc chan struct{} - disconnc chan struct{} - donec chan struct{} -} - -func newLeader(ctx context.Context, w clientv3.Watcher) *leader { - l := &leader{ - ctx: clientv3.WithRequireLeader(ctx), - w: w, - leaderc: make(chan struct{}), - disconnc: make(chan struct{}), - donec: make(chan struct{}), - } - // begin assuming leader is lost - close(l.leaderc) - go l.recvLoop() - return l -} - -func (l *leader) recvLoop() { - defer close(l.donec) - - limiter := rate.NewLimiter(rate.Limit(retryPerSecond), retryPerSecond) - rev := int64(math.MaxInt64 - 2) - for limiter.Wait(l.ctx) == nil { - wch := l.w.Watch(l.ctx, lostLeaderKey, clientv3.WithRev(rev), clientv3.WithCreatedNotify()) - cresp, ok := <-wch - if !ok { - l.loseLeader() - continue - } - if cresp.Err() != nil { - l.loseLeader() - if rpctypes.ErrorDesc(cresp.Err()) == grpc.ErrClientConnClosing.Error() { - close(l.disconnc) - return - } - continue - } - l.gotLeader() - <-wch - l.loseLeader() - } -} - -func (l *leader) loseLeader() { - l.mu.RLock() - defer l.mu.RUnlock() - select { - case <-l.leaderc: - default: - close(l.leaderc) - } -} - -// gotLeader will force update the leadership status to having a leader. -func (l *leader) gotLeader() { - l.mu.Lock() - defer l.mu.Unlock() - select { - case <-l.leaderc: - l.leaderc = make(chan struct{}) - default: - } -} - -func (l *leader) disconnectNotify() <-chan struct{} { return l.disconnc } - -func (l *leader) stopNotify() <-chan struct{} { return l.donec } - -// lostNotify returns a channel that is closed if there has been -// a leader loss not yet followed by a leader reacquire. -func (l *leader) lostNotify() <-chan struct{} { - l.mu.RLock() - defer l.mu.RUnlock() - return l.leaderc -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/lease.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/lease.go deleted file mode 100644 index 65f68b0ea0ca..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/lease.go +++ /dev/null @@ -1,382 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - "io" - "sync" - "sync/atomic" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" - "google.golang.org/grpc/metadata" -) - -type leaseProxy struct { - // leaseClient handles req from LeaseGrant() that requires a lease ID. - leaseClient pb.LeaseClient - - lessor clientv3.Lease - - ctx context.Context - - leader *leader - - // mu protects adding outstanding leaseProxyStream through wg. - mu sync.RWMutex - - // wg waits until all outstanding leaseProxyStream quit. - wg sync.WaitGroup -} - -func NewLeaseProxy(c *clientv3.Client) (pb.LeaseServer, <-chan struct{}) { - cctx, cancel := context.WithCancel(c.Ctx()) - lp := &leaseProxy{ - leaseClient: pb.NewLeaseClient(c.ActiveConnection()), - lessor: c.Lease, - ctx: cctx, - leader: newLeader(c.Ctx(), c.Watcher), - } - ch := make(chan struct{}) - go func() { - defer close(ch) - <-lp.leader.stopNotify() - lp.mu.Lock() - select { - case <-lp.ctx.Done(): - case <-lp.leader.disconnectNotify(): - cancel() - } - <-lp.ctx.Done() - lp.mu.Unlock() - lp.wg.Wait() - }() - return lp, ch -} - -func (lp *leaseProxy) LeaseGrant(ctx context.Context, cr *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - rp, err := lp.leaseClient.LeaseGrant(ctx, cr, grpc.FailFast(false)) - if err != nil { - return nil, err - } - lp.leader.gotLeader() - return rp, nil -} - -func (lp *leaseProxy) LeaseRevoke(ctx context.Context, rr *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) { - r, err := lp.lessor.Revoke(ctx, clientv3.LeaseID(rr.ID)) - if err != nil { - return nil, err - } - lp.leader.gotLeader() - return (*pb.LeaseRevokeResponse)(r), nil -} - -func (lp *leaseProxy) LeaseTimeToLive(ctx context.Context, rr *pb.LeaseTimeToLiveRequest) (*pb.LeaseTimeToLiveResponse, error) { - var ( - r *clientv3.LeaseTimeToLiveResponse - err error - ) - if rr.Keys { - r, err = lp.lessor.TimeToLive(ctx, clientv3.LeaseID(rr.ID), clientv3.WithAttachedKeys()) - } else { - r, err = lp.lessor.TimeToLive(ctx, clientv3.LeaseID(rr.ID)) - } - if err != nil { - return nil, err - } - rp := &pb.LeaseTimeToLiveResponse{ - Header: r.ResponseHeader, - ID: int64(r.ID), - TTL: r.TTL, - GrantedTTL: r.GrantedTTL, - Keys: r.Keys, - } - return rp, err -} - -func (lp *leaseProxy) LeaseLeases(ctx context.Context, rr *pb.LeaseLeasesRequest) (*pb.LeaseLeasesResponse, error) { - r, err := lp.lessor.Leases(ctx) - if err != nil { - return nil, err - } - leases := make([]*pb.LeaseStatus, len(r.Leases)) - for i := range r.Leases { - leases[i] = &pb.LeaseStatus{ID: int64(r.Leases[i].ID)} - } - rp := &pb.LeaseLeasesResponse{ - Header: r.ResponseHeader, - Leases: leases, - } - return rp, err -} - -func (lp *leaseProxy) LeaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) error { - lp.mu.Lock() - select { - case <-lp.ctx.Done(): - lp.mu.Unlock() - return lp.ctx.Err() - default: - lp.wg.Add(1) - } - lp.mu.Unlock() - - ctx, cancel := context.WithCancel(stream.Context()) - lps := leaseProxyStream{ - stream: stream, - lessor: lp.lessor, - keepAliveLeases: make(map[int64]*atomicCounter), - respc: make(chan *pb.LeaseKeepAliveResponse), - ctx: ctx, - cancel: cancel, - } - - errc := make(chan error, 2) - - var lostLeaderC <-chan struct{} - if md, ok := metadata.FromOutgoingContext(stream.Context()); ok { - v := md[rpctypes.MetadataRequireLeaderKey] - if len(v) > 0 && v[0] == rpctypes.MetadataHasLeader { - lostLeaderC = lp.leader.lostNotify() - // if leader is known to be lost at creation time, avoid - // letting events through at all - select { - case <-lostLeaderC: - lp.wg.Done() - return rpctypes.ErrNoLeader - default: - } - } - } - stopc := make(chan struct{}, 3) - go func() { - defer func() { stopc <- struct{}{} }() - if err := lps.recvLoop(); err != nil { - errc <- err - } - }() - - go func() { - defer func() { stopc <- struct{}{} }() - if err := lps.sendLoop(); err != nil { - errc <- err - } - }() - - // tears down LeaseKeepAlive stream if leader goes down or entire leaseProxy is terminated. - go func() { - defer func() { stopc <- struct{}{} }() - select { - case <-lostLeaderC: - case <-ctx.Done(): - case <-lp.ctx.Done(): - } - }() - - var err error - select { - case <-stopc: - stopc <- struct{}{} - case err = <-errc: - } - cancel() - - // recv/send may only shutdown after function exits; - // this goroutine notifies lease proxy that the stream is through - go func() { - <-stopc - <-stopc - <-stopc - lps.close() - close(errc) - lp.wg.Done() - }() - - select { - case <-lostLeaderC: - return rpctypes.ErrNoLeader - case <-lp.leader.disconnectNotify(): - return grpc.ErrClientConnClosing - default: - if err != nil { - return err - } - return ctx.Err() - } -} - -type leaseProxyStream struct { - stream pb.Lease_LeaseKeepAliveServer - - lessor clientv3.Lease - // wg tracks keepAliveLoop goroutines - wg sync.WaitGroup - // mu protects keepAliveLeases - mu sync.RWMutex - // keepAliveLeases tracks how many outstanding keepalive requests which need responses are on a lease. - keepAliveLeases map[int64]*atomicCounter - // respc receives lease keepalive responses from etcd backend - respc chan *pb.LeaseKeepAliveResponse - - ctx context.Context - cancel context.CancelFunc -} - -func (lps *leaseProxyStream) recvLoop() error { - for { - rr, err := lps.stream.Recv() - if err == io.EOF { - return nil - } - if err != nil { - return err - } - lps.mu.Lock() - neededResps, ok := lps.keepAliveLeases[rr.ID] - if !ok { - neededResps = &atomicCounter{} - lps.keepAliveLeases[rr.ID] = neededResps - lps.wg.Add(1) - go func() { - defer lps.wg.Done() - if err := lps.keepAliveLoop(rr.ID, neededResps); err != nil { - lps.cancel() - } - }() - } - neededResps.add(1) - lps.mu.Unlock() - } -} - -func (lps *leaseProxyStream) keepAliveLoop(leaseID int64, neededResps *atomicCounter) error { - cctx, ccancel := context.WithCancel(lps.ctx) - defer ccancel() - respc, err := lps.lessor.KeepAlive(cctx, clientv3.LeaseID(leaseID)) - if err != nil { - return err - } - // ticker expires when loop hasn't received keepalive within TTL - var ticker <-chan time.Time - for { - select { - case <-ticker: - lps.mu.Lock() - // if there are outstanding keepAlive reqs at the moment of ticker firing, - // don't close keepAliveLoop(), let it continuing to process the KeepAlive reqs. - if neededResps.get() > 0 { - lps.mu.Unlock() - ticker = nil - continue - } - delete(lps.keepAliveLeases, leaseID) - lps.mu.Unlock() - return nil - case rp, ok := <-respc: - if !ok { - lps.mu.Lock() - delete(lps.keepAliveLeases, leaseID) - lps.mu.Unlock() - if neededResps.get() == 0 { - return nil - } - ttlResp, err := lps.lessor.TimeToLive(cctx, clientv3.LeaseID(leaseID)) - if err != nil { - return err - } - r := &pb.LeaseKeepAliveResponse{ - Header: ttlResp.ResponseHeader, - ID: int64(ttlResp.ID), - TTL: ttlResp.TTL, - } - for neededResps.get() > 0 { - select { - case lps.respc <- r: - neededResps.add(-1) - case <-lps.ctx.Done(): - return nil - } - } - return nil - } - if neededResps.get() == 0 { - continue - } - ticker = time.After(time.Duration(rp.TTL) * time.Second) - r := &pb.LeaseKeepAliveResponse{ - Header: rp.ResponseHeader, - ID: int64(rp.ID), - TTL: rp.TTL, - } - lps.replyToClient(r, neededResps) - } - } -} - -func (lps *leaseProxyStream) replyToClient(r *pb.LeaseKeepAliveResponse, neededResps *atomicCounter) { - timer := time.After(500 * time.Millisecond) - for neededResps.get() > 0 { - select { - case lps.respc <- r: - neededResps.add(-1) - case <-timer: - return - case <-lps.ctx.Done(): - return - } - } -} - -func (lps *leaseProxyStream) sendLoop() error { - for { - select { - case lrp, ok := <-lps.respc: - if !ok { - return nil - } - if err := lps.stream.Send(lrp); err != nil { - return err - } - case <-lps.ctx.Done(): - return lps.ctx.Err() - } - } -} - -func (lps *leaseProxyStream) close() { - lps.cancel() - lps.wg.Wait() - // only close respc channel if all the keepAliveLoop() goroutines have finished - // this ensures those goroutines don't send resp to a closed resp channel - close(lps.respc) -} - -type atomicCounter struct { - counter int64 -} - -func (ac *atomicCounter) add(delta int64) { - atomic.AddInt64(&ac.counter, delta) -} - -func (ac *atomicCounter) get() int64 { - return atomic.LoadInt64(&ac.counter) -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/lock.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/lock.go deleted file mode 100644 index ceef26f0a0f6..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/lock.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2017 The etcd Lockors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb" -) - -type lockProxy struct { - client *clientv3.Client -} - -func NewLockProxy(client *clientv3.Client) v3lockpb.LockServer { - return &lockProxy{client: client} -} - -func (lp *lockProxy) Lock(ctx context.Context, req *v3lockpb.LockRequest) (*v3lockpb.LockResponse, error) { - return v3lockpb.NewLockClient(lp.client.ActiveConnection()).Lock(ctx, req) -} - -func (lp *lockProxy) Unlock(ctx context.Context, req *v3lockpb.UnlockRequest) (*v3lockpb.UnlockResponse, error) { - return v3lockpb.NewLockClient(lp.client.ActiveConnection()).Unlock(ctx, req) -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/logger.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/logger.go deleted file mode 100644 index c2d818043955..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/logger.go +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import "github.com/coreos/pkg/capnslog" - -var plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "grpcproxy") diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/maintenance.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/maintenance.go deleted file mode 100644 index 291e8e3088f5..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/maintenance.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - "io" - - "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -type maintenanceProxy struct { - client *clientv3.Client -} - -func NewMaintenanceProxy(c *clientv3.Client) pb.MaintenanceServer { - return &maintenanceProxy{ - client: c, - } -} - -func (mp *maintenanceProxy) Defragment(ctx context.Context, dr *pb.DefragmentRequest) (*pb.DefragmentResponse, error) { - conn := mp.client.ActiveConnection() - return pb.NewMaintenanceClient(conn).Defragment(ctx, dr) -} - -func (mp *maintenanceProxy) Snapshot(sr *pb.SnapshotRequest, stream pb.Maintenance_SnapshotServer) error { - conn := mp.client.ActiveConnection() - ctx, cancel := context.WithCancel(stream.Context()) - defer cancel() - - ctx = withClientAuthToken(ctx, stream.Context()) - - sc, err := pb.NewMaintenanceClient(conn).Snapshot(ctx, sr) - if err != nil { - return err - } - - for { - rr, err := sc.Recv() - if err != nil { - if err == io.EOF { - return nil - } - return err - } - err = stream.Send(rr) - if err != nil { - return err - } - } -} - -func (mp *maintenanceProxy) Hash(ctx context.Context, r *pb.HashRequest) (*pb.HashResponse, error) { - conn := mp.client.ActiveConnection() - return pb.NewMaintenanceClient(conn).Hash(ctx, r) -} - -func (mp *maintenanceProxy) HashKV(ctx context.Context, r *pb.HashKVRequest) (*pb.HashKVResponse, error) { - conn := mp.client.ActiveConnection() - return pb.NewMaintenanceClient(conn).HashKV(ctx, r) -} - -func (mp *maintenanceProxy) Alarm(ctx context.Context, r *pb.AlarmRequest) (*pb.AlarmResponse, error) { - conn := mp.client.ActiveConnection() - return pb.NewMaintenanceClient(conn).Alarm(ctx, r) -} - -func (mp *maintenanceProxy) Status(ctx context.Context, r *pb.StatusRequest) (*pb.StatusResponse, error) { - conn := mp.client.ActiveConnection() - return pb.NewMaintenanceClient(conn).Status(ctx, r) -} - -func (mp *maintenanceProxy) MoveLeader(ctx context.Context, r *pb.MoveLeaderRequest) (*pb.MoveLeaderResponse, error) { - conn := mp.client.ActiveConnection() - return pb.NewMaintenanceClient(conn).MoveLeader(ctx, r) -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/metrics.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/metrics.go deleted file mode 100644 index ebb82bb727d8..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/metrics.go +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "fmt" - "io/ioutil" - "math/rand" - "net/http" - "strings" - "time" - - "github.com/coreos/etcd/etcdserver/api/etcdhttp" - "github.com/prometheus/client_golang/prometheus" -) - -var ( - watchersCoalescing = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "grpc_proxy", - Name: "watchers_coalescing_total", - Help: "Total number of current watchers coalescing", - }) - eventsCoalescing = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "grpc_proxy", - Name: "events_coalescing_total", - Help: "Total number of events coalescing", - }) - cacheKeys = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "grpc_proxy", - Name: "cache_keys_total", - Help: "Total number of keys/ranges cached", - }) - cacheHits = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "grpc_proxy", - Name: "cache_hits_total", - Help: "Total number of cache hits", - }) - cachedMisses = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "grpc_proxy", - Name: "cache_misses_total", - Help: "Total number of cache misses", - }) -) - -func init() { - prometheus.MustRegister(watchersCoalescing) - prometheus.MustRegister(eventsCoalescing) - prometheus.MustRegister(cacheKeys) - prometheus.MustRegister(cacheHits) - prometheus.MustRegister(cachedMisses) -} - -// HandleMetrics performs a GET request against etcd endpoint and returns '/metrics'. -func HandleMetrics(mux *http.ServeMux, c *http.Client, eps []string) { - // random shuffle endpoints - r := rand.New(rand.NewSource(int64(time.Now().Nanosecond()))) - if len(eps) > 1 { - eps = shuffleEndpoints(r, eps) - } - - pathMetrics := etcdhttp.PathMetrics - mux.HandleFunc(pathMetrics, func(w http.ResponseWriter, r *http.Request) { - target := fmt.Sprintf("%s%s", eps[0], pathMetrics) - if !strings.HasPrefix(target, "http") { - scheme := "http" - if r.TLS != nil { - scheme = "https" - } - target = fmt.Sprintf("%s://%s", scheme, target) - } - - resp, err := c.Get(target) - if err != nil { - http.Error(w, "Internal server error", http.StatusInternalServerError) - } - defer resp.Body.Close() - w.Header().Set("Content-Type", "text/plain; version=0.0.4") - body, _ := ioutil.ReadAll(resp.Body) - fmt.Fprintf(w, "%s", body) - }) -} - -func shuffleEndpoints(r *rand.Rand, eps []string) []string { - // copied from Go 1.9<= rand.Rand.Perm - n := len(eps) - p := make([]int, n) - for i := 0; i < n; i++ { - j := r.Intn(i + 1) - p[i] = p[j] - p[j] = i - } - neps := make([]string, n) - for i, k := range p { - neps[i] = eps[k] - } - return neps -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/register.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/register.go deleted file mode 100644 index 598c71f07aef..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/register.go +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "encoding/json" - "os" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/concurrency" - "github.com/coreos/etcd/clientv3/naming" - - "golang.org/x/time/rate" - gnaming "google.golang.org/grpc/naming" -) - -// allow maximum 1 retry per second -const registerRetryRate = 1 - -// Register registers itself as a grpc-proxy server by writing prefixed-key -// with session of specified TTL (in seconds). The returned channel is closed -// when the client's context is canceled. -func Register(c *clientv3.Client, prefix string, addr string, ttl int) <-chan struct{} { - rm := rate.NewLimiter(rate.Limit(registerRetryRate), registerRetryRate) - - donec := make(chan struct{}) - go func() { - defer close(donec) - - for rm.Wait(c.Ctx()) == nil { - ss, err := registerSession(c, prefix, addr, ttl) - if err != nil { - plog.Warningf("failed to create a session %v", err) - continue - } - select { - case <-c.Ctx().Done(): - ss.Close() - return - - case <-ss.Done(): - plog.Warning("session expired; possible network partition or server restart") - plog.Warning("creating a new session to rejoin") - continue - } - } - }() - - return donec -} - -func registerSession(c *clientv3.Client, prefix string, addr string, ttl int) (*concurrency.Session, error) { - ss, err := concurrency.NewSession(c, concurrency.WithTTL(ttl)) - if err != nil { - return nil, err - } - - gr := &naming.GRPCResolver{Client: c} - if err = gr.Update(c.Ctx(), prefix, gnaming.Update{Op: gnaming.Add, Addr: addr, Metadata: getMeta()}, clientv3.WithLease(ss.Lease())); err != nil { - return nil, err - } - - plog.Infof("registered %q with %d-second lease", addr, ttl) - return ss, nil -} - -// meta represents metadata of proxy register. -type meta struct { - Name string `json:"name"` -} - -func getMeta() string { - hostname, _ := os.Hostname() - bts, _ := json.Marshal(meta{Name: hostname}) - return string(bts) -} - -func decodeMeta(s string) (meta, error) { - m := meta{} - err := json.Unmarshal([]byte(s), &m) - return m, err -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/util.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/util.go deleted file mode 100644 index 2b226fa74ebf..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/util.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - - "google.golang.org/grpc" - "google.golang.org/grpc/metadata" -) - -func getAuthTokenFromClient(ctx context.Context) string { - md, ok := metadata.FromIncomingContext(ctx) - if ok { - ts, ok := md["token"] - if ok { - return ts[0] - } - } - return "" -} - -func withClientAuthToken(ctx context.Context, ctxWithToken context.Context) context.Context { - token := getAuthTokenFromClient(ctxWithToken) - if token != "" { - ctx = context.WithValue(ctx, "token", token) - } - return ctx -} - -type proxyTokenCredential struct { - token string -} - -func (cred *proxyTokenCredential) RequireTransportSecurity() bool { - return false -} - -func (cred *proxyTokenCredential) GetRequestMetadata(ctx context.Context, s ...string) (map[string]string, error) { - return map[string]string{ - "token": cred.token, - }, nil -} - -func AuthUnaryClientInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { - token := getAuthTokenFromClient(ctx) - if token != "" { - tokenCred := &proxyTokenCredential{token} - opts = append(opts, grpc.PerRPCCredentials(tokenCred)) - } - return invoker(ctx, method, req, reply, cc, opts...) -} - -func AuthStreamClientInterceptor(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) { - tokenif := ctx.Value("token") - if tokenif != nil { - tokenCred := &proxyTokenCredential{tokenif.(string)} - opts = append(opts, grpc.PerRPCCredentials(tokenCred)) - } - return streamer(ctx, desc, cc, method, opts...) -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/watch.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/watch.go deleted file mode 100644 index 603095f27f1c..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/watch.go +++ /dev/null @@ -1,298 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - "sync" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/etcdserver/api/v3rpc" - "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - - "google.golang.org/grpc" - "google.golang.org/grpc/metadata" -) - -type watchProxy struct { - cw clientv3.Watcher - ctx context.Context - - leader *leader - - ranges *watchRanges - - // mu protects adding outstanding watch servers through wg. - mu sync.Mutex - - // wg waits until all outstanding watch servers quit. - wg sync.WaitGroup - - // kv is used for permission checking - kv clientv3.KV -} - -func NewWatchProxy(c *clientv3.Client) (pb.WatchServer, <-chan struct{}) { - cctx, cancel := context.WithCancel(c.Ctx()) - wp := &watchProxy{ - cw: c.Watcher, - ctx: cctx, - leader: newLeader(c.Ctx(), c.Watcher), - - kv: c.KV, // for permission checking - } - wp.ranges = newWatchRanges(wp) - ch := make(chan struct{}) - go func() { - defer close(ch) - <-wp.leader.stopNotify() - wp.mu.Lock() - select { - case <-wp.ctx.Done(): - case <-wp.leader.disconnectNotify(): - cancel() - } - <-wp.ctx.Done() - wp.mu.Unlock() - wp.wg.Wait() - wp.ranges.stop() - }() - return wp, ch -} - -func (wp *watchProxy) Watch(stream pb.Watch_WatchServer) (err error) { - wp.mu.Lock() - select { - case <-wp.ctx.Done(): - wp.mu.Unlock() - select { - case <-wp.leader.disconnectNotify(): - return grpc.ErrClientConnClosing - default: - return wp.ctx.Err() - } - default: - wp.wg.Add(1) - } - wp.mu.Unlock() - - ctx, cancel := context.WithCancel(stream.Context()) - wps := &watchProxyStream{ - ranges: wp.ranges, - watchers: make(map[int64]*watcher), - stream: stream, - watchCh: make(chan *pb.WatchResponse, 1024), - ctx: ctx, - cancel: cancel, - kv: wp.kv, - } - - var lostLeaderC <-chan struct{} - if md, ok := metadata.FromOutgoingContext(stream.Context()); ok { - v := md[rpctypes.MetadataRequireLeaderKey] - if len(v) > 0 && v[0] == rpctypes.MetadataHasLeader { - lostLeaderC = wp.leader.lostNotify() - // if leader is known to be lost at creation time, avoid - // letting events through at all - select { - case <-lostLeaderC: - wp.wg.Done() - return rpctypes.ErrNoLeader - default: - } - } - } - - // post to stopc => terminate server stream; can't use a waitgroup - // since all goroutines will only terminate after Watch() exits. - stopc := make(chan struct{}, 3) - go func() { - defer func() { stopc <- struct{}{} }() - wps.recvLoop() - }() - go func() { - defer func() { stopc <- struct{}{} }() - wps.sendLoop() - }() - // tear down watch if leader goes down or entire watch proxy is terminated - go func() { - defer func() { stopc <- struct{}{} }() - select { - case <-lostLeaderC: - case <-ctx.Done(): - case <-wp.ctx.Done(): - } - }() - - <-stopc - cancel() - - // recv/send may only shutdown after function exits; - // goroutine notifies proxy that stream is through - go func() { - <-stopc - <-stopc - wps.close() - wp.wg.Done() - }() - - select { - case <-lostLeaderC: - return rpctypes.ErrNoLeader - case <-wp.leader.disconnectNotify(): - return grpc.ErrClientConnClosing - default: - return wps.ctx.Err() - } -} - -// watchProxyStream forwards etcd watch events to a proxied client stream. -type watchProxyStream struct { - ranges *watchRanges - - // mu protects watchers and nextWatcherID - mu sync.Mutex - // watchers receive events from watch broadcast. - watchers map[int64]*watcher - // nextWatcherID is the id to assign the next watcher on this stream. - nextWatcherID int64 - - stream pb.Watch_WatchServer - - // watchCh receives watch responses from the watchers. - watchCh chan *pb.WatchResponse - - ctx context.Context - cancel context.CancelFunc - - // kv is used for permission checking - kv clientv3.KV -} - -func (wps *watchProxyStream) close() { - var wg sync.WaitGroup - wps.cancel() - wps.mu.Lock() - wg.Add(len(wps.watchers)) - for _, wpsw := range wps.watchers { - go func(w *watcher) { - wps.ranges.delete(w) - wg.Done() - }(wpsw) - } - wps.watchers = nil - wps.mu.Unlock() - - wg.Wait() - - close(wps.watchCh) -} - -func (wps *watchProxyStream) checkPermissionForWatch(key, rangeEnd []byte) error { - if len(key) == 0 { - // If the length of the key is 0, we need to obtain full range. - // look at clientv3.WithPrefix() - key = []byte{0} - rangeEnd = []byte{0} - } - req := &pb.RangeRequest{ - Serializable: true, - Key: key, - RangeEnd: rangeEnd, - CountOnly: true, - Limit: 1, - } - _, err := wps.kv.Do(wps.ctx, RangeRequestToOp(req)) - return err -} - -func (wps *watchProxyStream) recvLoop() error { - for { - req, err := wps.stream.Recv() - if err != nil { - return err - } - switch uv := req.RequestUnion.(type) { - case *pb.WatchRequest_CreateRequest: - cr := uv.CreateRequest - - if err = wps.checkPermissionForWatch(cr.Key, cr.RangeEnd); err != nil && err == rpctypes.ErrPermissionDenied { - // Return WatchResponse which is caused by permission checking if and only if - // the error is permission denied. For other errors (e.g. timeout or connection closed), - // the permission checking mechanism should do nothing for preserving error code. - wps.watchCh <- &pb.WatchResponse{Header: &pb.ResponseHeader{}, WatchId: -1, Created: true, Canceled: true} - continue - } - - w := &watcher{ - wr: watchRange{string(cr.Key), string(cr.RangeEnd)}, - id: wps.nextWatcherID, - wps: wps, - - nextrev: cr.StartRevision, - progress: cr.ProgressNotify, - prevKV: cr.PrevKv, - filters: v3rpc.FiltersFromRequest(cr), - } - if !w.wr.valid() { - w.post(&pb.WatchResponse{WatchId: -1, Created: true, Canceled: true}) - continue - } - wps.nextWatcherID++ - w.nextrev = cr.StartRevision - wps.watchers[w.id] = w - wps.ranges.add(w) - case *pb.WatchRequest_CancelRequest: - wps.delete(uv.CancelRequest.WatchId) - default: - panic("not implemented") - } - } -} - -func (wps *watchProxyStream) sendLoop() { - for { - select { - case wresp, ok := <-wps.watchCh: - if !ok { - return - } - if err := wps.stream.Send(wresp); err != nil { - return - } - case <-wps.ctx.Done(): - return - } - } -} - -func (wps *watchProxyStream) delete(id int64) { - wps.mu.Lock() - defer wps.mu.Unlock() - - w, ok := wps.watchers[id] - if !ok { - return - } - wps.ranges.delete(w) - delete(wps.watchers, id) - resp := &pb.WatchResponse{ - Header: &w.lastHeader, - WatchId: id, - Canceled: true, - } - wps.watchCh <- resp -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/watch_broadcast.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/watch_broadcast.go deleted file mode 100644 index 46e56c79a9d8..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/watch_broadcast.go +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "context" - "sync" - - "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" -) - -// watchBroadcast broadcasts a server watcher to many client watchers. -type watchBroadcast struct { - // cancel stops the underlying etcd server watcher and closes ch. - cancel context.CancelFunc - donec chan struct{} - - // mu protects rev and receivers. - mu sync.RWMutex - // nextrev is the minimum expected next revision of the watcher on ch. - nextrev int64 - // receivers contains all the client-side watchers to serve. - receivers map[*watcher]struct{} - // responses counts the number of responses - responses int -} - -func newWatchBroadcast(wp *watchProxy, w *watcher, update func(*watchBroadcast)) *watchBroadcast { - cctx, cancel := context.WithCancel(wp.ctx) - wb := &watchBroadcast{ - cancel: cancel, - nextrev: w.nextrev, - receivers: make(map[*watcher]struct{}), - donec: make(chan struct{}), - } - wb.add(w) - go func() { - defer close(wb.donec) - - opts := []clientv3.OpOption{ - clientv3.WithRange(w.wr.end), - clientv3.WithProgressNotify(), - clientv3.WithRev(wb.nextrev), - clientv3.WithPrevKV(), - clientv3.WithCreatedNotify(), - } - - cctx = withClientAuthToken(cctx, w.wps.stream.Context()) - - wch := wp.cw.Watch(cctx, w.wr.key, opts...) - - for wr := range wch { - wb.bcast(wr) - update(wb) - } - }() - return wb -} - -func (wb *watchBroadcast) bcast(wr clientv3.WatchResponse) { - wb.mu.Lock() - defer wb.mu.Unlock() - // watchers start on the given revision, if any; ignore header rev on create - if wb.responses > 0 || wb.nextrev == 0 { - wb.nextrev = wr.Header.Revision + 1 - } - wb.responses++ - for r := range wb.receivers { - r.send(wr) - } - if len(wb.receivers) > 0 { - eventsCoalescing.Add(float64(len(wb.receivers) - 1)) - } -} - -// add puts a watcher into receiving a broadcast if its revision at least -// meets the broadcast revision. Returns true if added. -func (wb *watchBroadcast) add(w *watcher) bool { - wb.mu.Lock() - defer wb.mu.Unlock() - if wb.nextrev > w.nextrev || (wb.nextrev == 0 && w.nextrev != 0) { - // wb is too far ahead, w will miss events - // or wb is being established with a current watcher - return false - } - if wb.responses == 0 { - // Newly created; create event will be sent by etcd. - wb.receivers[w] = struct{}{} - return true - } - // already sent by etcd; emulate create event - ok := w.post(&pb.WatchResponse{ - Header: &pb.ResponseHeader{ - // todo: fill in ClusterId - // todo: fill in MemberId: - Revision: w.nextrev, - // todo: fill in RaftTerm: - }, - WatchId: w.id, - Created: true, - }) - if !ok { - return false - } - wb.receivers[w] = struct{}{} - watchersCoalescing.Inc() - - return true -} -func (wb *watchBroadcast) delete(w *watcher) { - wb.mu.Lock() - defer wb.mu.Unlock() - if _, ok := wb.receivers[w]; !ok { - panic("deleting missing watcher from broadcast") - } - delete(wb.receivers, w) - if len(wb.receivers) > 0 { - // do not dec the only left watcher for coalescing. - watchersCoalescing.Dec() - } -} - -func (wb *watchBroadcast) size() int { - wb.mu.RLock() - defer wb.mu.RUnlock() - return len(wb.receivers) -} - -func (wb *watchBroadcast) empty() bool { return wb.size() == 0 } - -func (wb *watchBroadcast) stop() { - if !wb.empty() { - // do not dec the only left watcher for coalescing. - watchersCoalescing.Sub(float64(wb.size() - 1)) - } - - wb.cancel() - <-wb.donec -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/watch_broadcasts.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/watch_broadcasts.go deleted file mode 100644 index 8fe9e5f512e5..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/watch_broadcasts.go +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "sync" -) - -type watchBroadcasts struct { - wp *watchProxy - - // mu protects bcasts and watchers from the coalesce loop. - mu sync.Mutex - bcasts map[*watchBroadcast]struct{} - watchers map[*watcher]*watchBroadcast - - updatec chan *watchBroadcast - donec chan struct{} -} - -// maxCoalesceRecievers prevents a popular watchBroadcast from being coalseced. -const maxCoalesceReceivers = 5 - -func newWatchBroadcasts(wp *watchProxy) *watchBroadcasts { - wbs := &watchBroadcasts{ - wp: wp, - bcasts: make(map[*watchBroadcast]struct{}), - watchers: make(map[*watcher]*watchBroadcast), - updatec: make(chan *watchBroadcast, 1), - donec: make(chan struct{}), - } - go func() { - defer close(wbs.donec) - for wb := range wbs.updatec { - wbs.coalesce(wb) - } - }() - return wbs -} - -func (wbs *watchBroadcasts) coalesce(wb *watchBroadcast) { - if wb.size() >= maxCoalesceReceivers { - return - } - wbs.mu.Lock() - for wbswb := range wbs.bcasts { - if wbswb == wb { - continue - } - wb.mu.Lock() - wbswb.mu.Lock() - // 1. check if wbswb is behind wb so it won't skip any events in wb - // 2. ensure wbswb started; nextrev == 0 may mean wbswb is waiting - // for a current watcher and expects a create event from the server. - if wb.nextrev >= wbswb.nextrev && wbswb.responses > 0 { - for w := range wb.receivers { - wbswb.receivers[w] = struct{}{} - wbs.watchers[w] = wbswb - } - wb.receivers = nil - } - wbswb.mu.Unlock() - wb.mu.Unlock() - if wb.empty() { - delete(wbs.bcasts, wb) - wb.stop() - break - } - } - wbs.mu.Unlock() -} - -func (wbs *watchBroadcasts) add(w *watcher) { - wbs.mu.Lock() - defer wbs.mu.Unlock() - // find fitting bcast - for wb := range wbs.bcasts { - if wb.add(w) { - wbs.watchers[w] = wb - return - } - } - // no fit; create a bcast - wb := newWatchBroadcast(wbs.wp, w, wbs.update) - wbs.watchers[w] = wb - wbs.bcasts[wb] = struct{}{} -} - -// delete removes a watcher and returns the number of remaining watchers. -func (wbs *watchBroadcasts) delete(w *watcher) int { - wbs.mu.Lock() - defer wbs.mu.Unlock() - - wb, ok := wbs.watchers[w] - if !ok { - panic("deleting missing watcher from broadcasts") - } - delete(wbs.watchers, w) - wb.delete(w) - if wb.empty() { - delete(wbs.bcasts, wb) - wb.stop() - } - return len(wbs.bcasts) -} - -func (wbs *watchBroadcasts) stop() { - wbs.mu.Lock() - for wb := range wbs.bcasts { - wb.stop() - } - wbs.bcasts = nil - close(wbs.updatec) - wbs.mu.Unlock() - <-wbs.donec -} - -func (wbs *watchBroadcasts) update(wb *watchBroadcast) { - select { - case wbs.updatec <- wb: - default: - } -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/watch_ranges.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/watch_ranges.go deleted file mode 100644 index 31c6b5925eae..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/watch_ranges.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "sync" -) - -// watchRanges tracks all open watches for the proxy. -type watchRanges struct { - wp *watchProxy - - mu sync.Mutex - bcasts map[watchRange]*watchBroadcasts -} - -func newWatchRanges(wp *watchProxy) *watchRanges { - return &watchRanges{ - wp: wp, - bcasts: make(map[watchRange]*watchBroadcasts), - } -} - -func (wrs *watchRanges) add(w *watcher) { - wrs.mu.Lock() - defer wrs.mu.Unlock() - - if wbs := wrs.bcasts[w.wr]; wbs != nil { - wbs.add(w) - return - } - wbs := newWatchBroadcasts(wrs.wp) - wrs.bcasts[w.wr] = wbs - wbs.add(w) -} - -func (wrs *watchRanges) delete(w *watcher) { - wrs.mu.Lock() - defer wrs.mu.Unlock() - wbs, ok := wrs.bcasts[w.wr] - if !ok { - panic("deleting missing range") - } - if wbs.delete(w) == 0 { - wbs.stop() - delete(wrs.bcasts, w.wr) - } -} - -func (wrs *watchRanges) stop() { - wrs.mu.Lock() - defer wrs.mu.Unlock() - for _, wb := range wrs.bcasts { - wb.stop() - } - wrs.bcasts = nil -} diff --git a/vendor/go.etcd.io/etcd/proxy/grpcproxy/watcher.go b/vendor/go.etcd.io/etcd/proxy/grpcproxy/watcher.go deleted file mode 100644 index 1a497462f99b..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/grpcproxy/watcher.go +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpcproxy - -import ( - "time" - - "github.com/coreos/etcd/clientv3" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" - "github.com/coreos/etcd/mvcc" - "github.com/coreos/etcd/mvcc/mvccpb" -) - -type watchRange struct { - key, end string -} - -func (wr *watchRange) valid() bool { - return len(wr.end) == 0 || wr.end > wr.key || (wr.end[0] == 0 && len(wr.end) == 1) -} - -type watcher struct { - // user configuration - - wr watchRange - filters []mvcc.FilterFunc - progress bool - prevKV bool - - // id is the id returned to the client on its watch stream. - id int64 - // nextrev is the minimum expected next event revision. - nextrev int64 - // lastHeader has the last header sent over the stream. - lastHeader pb.ResponseHeader - - // wps is the parent. - wps *watchProxyStream -} - -// send filters out repeated events by discarding revisions older -// than the last one sent over the watch channel. -func (w *watcher) send(wr clientv3.WatchResponse) { - if wr.IsProgressNotify() && !w.progress { - return - } - if w.nextrev > wr.Header.Revision && len(wr.Events) > 0 { - return - } - if w.nextrev == 0 { - // current watch; expect updates following this revision - w.nextrev = wr.Header.Revision + 1 - } - - events := make([]*mvccpb.Event, 0, len(wr.Events)) - - var lastRev int64 - for i := range wr.Events { - ev := (*mvccpb.Event)(wr.Events[i]) - if ev.Kv.ModRevision < w.nextrev { - continue - } else { - // We cannot update w.rev here. - // txn can have multiple events with the same rev. - // If w.nextrev updates here, it would skip events in the same txn. - lastRev = ev.Kv.ModRevision - } - - filtered := false - for _, filter := range w.filters { - if filter(*ev) { - filtered = true - break - } - } - if filtered { - continue - } - - if !w.prevKV { - evCopy := *ev - evCopy.PrevKv = nil - ev = &evCopy - } - events = append(events, ev) - } - - if lastRev >= w.nextrev { - w.nextrev = lastRev + 1 - } - - // all events are filtered out? - if !wr.IsProgressNotify() && !wr.Created && len(events) == 0 && wr.CompactRevision == 0 { - return - } - - w.lastHeader = wr.Header - w.post(&pb.WatchResponse{ - Header: &wr.Header, - Created: wr.Created, - CompactRevision: wr.CompactRevision, - Canceled: wr.Canceled, - WatchId: w.id, - Events: events, - }) -} - -// post puts a watch response on the watcher's proxy stream channel -func (w *watcher) post(wr *pb.WatchResponse) bool { - select { - case w.wps.watchCh <- wr: - case <-time.After(50 * time.Millisecond): - w.wps.cancel() - return false - } - return true -} diff --git a/vendor/go.etcd.io/etcd/proxy/httpproxy/director.go b/vendor/go.etcd.io/etcd/proxy/httpproxy/director.go deleted file mode 100644 index d414501335dd..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/httpproxy/director.go +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package httpproxy - -import ( - "math/rand" - "net/url" - "sync" - "time" -) - -// defaultRefreshInterval is the default proxyRefreshIntervalMs value -// as in etcdmain/config.go. -const defaultRefreshInterval = 30000 * time.Millisecond - -var once sync.Once - -func init() { - rand.Seed(time.Now().UnixNano()) -} - -func newDirector(urlsFunc GetProxyURLs, failureWait time.Duration, refreshInterval time.Duration) *director { - d := &director{ - uf: urlsFunc, - failureWait: failureWait, - } - d.refresh() - go func() { - // In order to prevent missing proxy endpoints in the first try: - // when given refresh interval of defaultRefreshInterval or greater - // and whenever there is no available proxy endpoints, - // give 1-second refreshInterval. - for { - es := d.endpoints() - ri := refreshInterval - if ri >= defaultRefreshInterval { - if len(es) == 0 { - ri = time.Second - } - } - if len(es) > 0 { - once.Do(func() { - var sl []string - for _, e := range es { - sl = append(sl, e.URL.String()) - } - plog.Infof("endpoints found %q", sl) - }) - } - time.Sleep(ri) - d.refresh() - } - }() - return d -} - -type director struct { - sync.Mutex - ep []*endpoint - uf GetProxyURLs - failureWait time.Duration -} - -func (d *director) refresh() { - urls := d.uf() - d.Lock() - defer d.Unlock() - var endpoints []*endpoint - for _, u := range urls { - uu, err := url.Parse(u) - if err != nil { - plog.Printf("upstream URL invalid: %v", err) - continue - } - endpoints = append(endpoints, newEndpoint(*uu, d.failureWait)) - } - - // shuffle array to avoid connections being "stuck" to a single endpoint - for i := range endpoints { - j := rand.Intn(i + 1) - endpoints[i], endpoints[j] = endpoints[j], endpoints[i] - } - - d.ep = endpoints -} - -func (d *director) endpoints() []*endpoint { - d.Lock() - defer d.Unlock() - filtered := make([]*endpoint, 0) - for _, ep := range d.ep { - if ep.Available { - filtered = append(filtered, ep) - } - } - - return filtered -} - -func newEndpoint(u url.URL, failureWait time.Duration) *endpoint { - ep := endpoint{ - URL: u, - Available: true, - failFunc: timedUnavailabilityFunc(failureWait), - } - - return &ep -} - -type endpoint struct { - sync.Mutex - - URL url.URL - Available bool - - failFunc func(ep *endpoint) -} - -func (ep *endpoint) Failed() { - ep.Lock() - if !ep.Available { - ep.Unlock() - return - } - - ep.Available = false - ep.Unlock() - - plog.Printf("marked endpoint %s unavailable", ep.URL.String()) - - if ep.failFunc == nil { - plog.Printf("no failFunc defined, endpoint %s will be unavailable forever.", ep.URL.String()) - return - } - - ep.failFunc(ep) -} - -func timedUnavailabilityFunc(wait time.Duration) func(*endpoint) { - return func(ep *endpoint) { - time.AfterFunc(wait, func() { - ep.Available = true - plog.Printf("marked endpoint %s available, to retest connectivity", ep.URL.String()) - }) - } -} diff --git a/vendor/go.etcd.io/etcd/proxy/httpproxy/doc.go b/vendor/go.etcd.io/etcd/proxy/httpproxy/doc.go deleted file mode 100644 index 7a45099120cb..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/httpproxy/doc.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package httpproxy implements etcd httpproxy. The etcd proxy acts as a reverse -// http proxy forwarding client requests to active etcd cluster members, and does -// not participate in consensus. -package httpproxy diff --git a/vendor/go.etcd.io/etcd/proxy/httpproxy/metrics.go b/vendor/go.etcd.io/etcd/proxy/httpproxy/metrics.go deleted file mode 100644 index f71258cba57b..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/httpproxy/metrics.go +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package httpproxy - -import ( - "net/http" - "strconv" - "time" - - "github.com/prometheus/client_golang/prometheus" -) - -var ( - requestsIncoming = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "proxy", - Name: "requests_total", - Help: "Counter requests incoming by method.", - }, []string{"method"}) - - requestsHandled = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "proxy", - Name: "handled_total", - Help: "Counter of requests fully handled (by authoratitave servers)", - }, []string{"method", "code"}) - - requestsDropped = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "proxy", - Name: "dropped_total", - Help: "Counter of requests dropped on the proxy.", - }, []string{"method", "proxying_error"}) - - requestsHandlingTime = prometheus.NewHistogramVec( - prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "proxy", - Name: "handling_duration_seconds", - Help: "Bucketed histogram of handling time of successful events (non-watches), by method " + - "(GET/PUT etc.).", - Buckets: prometheus.ExponentialBuckets(0.0005, 2, 13), - }, []string{"method"}) -) - -type forwardingError string - -const ( - zeroEndpoints forwardingError = "zero_endpoints" - failedSendingRequest forwardingError = "failed_sending_request" - failedGettingResponse forwardingError = "failed_getting_response" -) - -func init() { - prometheus.MustRegister(requestsIncoming) - prometheus.MustRegister(requestsHandled) - prometheus.MustRegister(requestsDropped) - prometheus.MustRegister(requestsHandlingTime) -} - -func reportIncomingRequest(request *http.Request) { - requestsIncoming.WithLabelValues(request.Method).Inc() -} - -func reportRequestHandled(request *http.Request, response *http.Response, startTime time.Time) { - method := request.Method - requestsHandled.WithLabelValues(method, strconv.Itoa(response.StatusCode)).Inc() - requestsHandlingTime.WithLabelValues(method).Observe(time.Since(startTime).Seconds()) -} - -func reportRequestDropped(request *http.Request, err forwardingError) { - requestsDropped.WithLabelValues(request.Method, string(err)).Inc() -} diff --git a/vendor/go.etcd.io/etcd/proxy/httpproxy/proxy.go b/vendor/go.etcd.io/etcd/proxy/httpproxy/proxy.go deleted file mode 100644 index 3cd3161f3461..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/httpproxy/proxy.go +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package httpproxy - -import ( - "encoding/json" - "net/http" - "strings" - "time" - - "golang.org/x/net/http2" -) - -const ( - // DefaultMaxIdleConnsPerHost indicates the default maximum idle connection - // count maintained between proxy and each member. We set it to 128 to - // let proxy handle 128 concurrent requests in long term smoothly. - // If the number of concurrent requests is bigger than this value, - // proxy needs to create one new connection when handling each request in - // the delta, which is bad because the creation consumes resource and - // may eat up ephemeral ports. - DefaultMaxIdleConnsPerHost = 128 -) - -// GetProxyURLs is a function which should return the current set of URLs to -// which client requests should be proxied. This function will be queried -// periodically by the proxy Handler to refresh the set of available -// backends. -type GetProxyURLs func() []string - -// NewHandler creates a new HTTP handler, listening on the given transport, -// which will proxy requests to an etcd cluster. -// The handler will periodically update its view of the cluster. -func NewHandler(t *http.Transport, urlsFunc GetProxyURLs, failureWait time.Duration, refreshInterval time.Duration) http.Handler { - if t.TLSClientConfig != nil { - // Enable http2, see Issue 5033. - err := http2.ConfigureTransport(t) - if err != nil { - plog.Infof("Error enabling Transport HTTP/2 support: %v", err) - } - } - - p := &reverseProxy{ - director: newDirector(urlsFunc, failureWait, refreshInterval), - transport: t, - } - - mux := http.NewServeMux() - mux.Handle("/", p) - mux.HandleFunc("/v2/config/local/proxy", p.configHandler) - - return mux -} - -// NewReadonlyHandler wraps the given HTTP handler to allow only GET requests -func NewReadonlyHandler(hdlr http.Handler) http.Handler { - readonly := readonlyHandlerFunc(hdlr) - return http.HandlerFunc(readonly) -} - -func readonlyHandlerFunc(next http.Handler) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, req *http.Request) { - if req.Method != "GET" { - w.WriteHeader(http.StatusNotImplemented) - return - } - - next.ServeHTTP(w, req) - } -} - -func (p *reverseProxy) configHandler(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET") { - return - } - - eps := p.director.endpoints() - epstr := make([]string, len(eps)) - for i, e := range eps { - epstr[i] = e.URL.String() - } - - proxyConfig := struct { - Endpoints []string `json:"endpoints"` - }{ - Endpoints: epstr, - } - - json.NewEncoder(w).Encode(proxyConfig) -} - -// allowMethod verifies that the given method is one of the allowed methods, -// and if not, it writes an error to w. A boolean is returned indicating -// whether or not the method is allowed. -func allowMethod(w http.ResponseWriter, m string, ms ...string) bool { - for _, meth := range ms { - if m == meth { - return true - } - } - w.Header().Set("Allow", strings.Join(ms, ",")) - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return false -} diff --git a/vendor/go.etcd.io/etcd/proxy/httpproxy/reverse.go b/vendor/go.etcd.io/etcd/proxy/httpproxy/reverse.go deleted file mode 100644 index 2ecff3aaea94..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/httpproxy/reverse.go +++ /dev/null @@ -1,208 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package httpproxy - -import ( - "bytes" - "context" - "fmt" - "io" - "io/ioutil" - "net" - "net/http" - "net/url" - "strings" - "sync/atomic" - "time" - - "github.com/coreos/etcd/etcdserver/api/v2http/httptypes" - "github.com/coreos/pkg/capnslog" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "proxy/httpproxy") - - // Hop-by-hop headers. These are removed when sent to the backend. - // http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html - // This list of headers borrowed from stdlib httputil.ReverseProxy - singleHopHeaders = []string{ - "Connection", - "Keep-Alive", - "Proxy-Authenticate", - "Proxy-Authorization", - "Te", // canonicalized version of "TE" - "Trailers", - "Transfer-Encoding", - "Upgrade", - } -) - -func removeSingleHopHeaders(hdrs *http.Header) { - for _, h := range singleHopHeaders { - hdrs.Del(h) - } -} - -type reverseProxy struct { - director *director - transport http.RoundTripper -} - -func (p *reverseProxy) ServeHTTP(rw http.ResponseWriter, clientreq *http.Request) { - reportIncomingRequest(clientreq) - proxyreq := new(http.Request) - *proxyreq = *clientreq - startTime := time.Now() - - var ( - proxybody []byte - err error - ) - - if clientreq.Body != nil { - proxybody, err = ioutil.ReadAll(clientreq.Body) - if err != nil { - msg := fmt.Sprintf("failed to read request body: %v", err) - plog.Println(msg) - e := httptypes.NewHTTPError(http.StatusInternalServerError, "httpproxy: "+msg) - if we := e.WriteTo(rw); we != nil { - plog.Debugf("error writing HTTPError (%v) to %s", we, clientreq.RemoteAddr) - } - return - } - } - - // deep-copy the headers, as these will be modified below - proxyreq.Header = make(http.Header) - copyHeader(proxyreq.Header, clientreq.Header) - - normalizeRequest(proxyreq) - removeSingleHopHeaders(&proxyreq.Header) - maybeSetForwardedFor(proxyreq) - - endpoints := p.director.endpoints() - if len(endpoints) == 0 { - msg := "zero endpoints currently available" - reportRequestDropped(clientreq, zeroEndpoints) - - // TODO: limit the rate of the error logging. - plog.Println(msg) - e := httptypes.NewHTTPError(http.StatusServiceUnavailable, "httpproxy: "+msg) - if we := e.WriteTo(rw); we != nil { - plog.Debugf("error writing HTTPError (%v) to %s", we, clientreq.RemoteAddr) - } - return - } - - var requestClosed int32 - completeCh := make(chan bool, 1) - closeNotifier, ok := rw.(http.CloseNotifier) - ctx, cancel := context.WithCancel(context.Background()) - proxyreq = proxyreq.WithContext(ctx) - defer cancel() - if ok { - closeCh := closeNotifier.CloseNotify() - go func() { - select { - case <-closeCh: - atomic.StoreInt32(&requestClosed, 1) - plog.Printf("client %v closed request prematurely", clientreq.RemoteAddr) - cancel() - case <-completeCh: - } - }() - - defer func() { - completeCh <- true - }() - } - - var res *http.Response - - for _, ep := range endpoints { - if proxybody != nil { - proxyreq.Body = ioutil.NopCloser(bytes.NewBuffer(proxybody)) - } - redirectRequest(proxyreq, ep.URL) - - res, err = p.transport.RoundTrip(proxyreq) - if atomic.LoadInt32(&requestClosed) == 1 { - return - } - if err != nil { - reportRequestDropped(clientreq, failedSendingRequest) - plog.Printf("failed to direct request to %s: %v", ep.URL.String(), err) - ep.Failed() - continue - } - - break - } - - if res == nil { - // TODO: limit the rate of the error logging. - msg := fmt.Sprintf("unable to get response from %d endpoint(s)", len(endpoints)) - reportRequestDropped(clientreq, failedGettingResponse) - plog.Println(msg) - e := httptypes.NewHTTPError(http.StatusBadGateway, "httpproxy: "+msg) - if we := e.WriteTo(rw); we != nil { - plog.Debugf("error writing HTTPError (%v) to %s", we, clientreq.RemoteAddr) - } - return - } - - defer res.Body.Close() - reportRequestHandled(clientreq, res, startTime) - removeSingleHopHeaders(&res.Header) - copyHeader(rw.Header(), res.Header) - - rw.WriteHeader(res.StatusCode) - io.Copy(rw, res.Body) -} - -func copyHeader(dst, src http.Header) { - for k, vv := range src { - for _, v := range vv { - dst.Add(k, v) - } - } -} - -func redirectRequest(req *http.Request, loc url.URL) { - req.URL.Scheme = loc.Scheme - req.URL.Host = loc.Host -} - -func normalizeRequest(req *http.Request) { - req.Proto = "HTTP/1.1" - req.ProtoMajor = 1 - req.ProtoMinor = 1 - req.Close = false -} - -func maybeSetForwardedFor(req *http.Request) { - clientIP, _, err := net.SplitHostPort(req.RemoteAddr) - if err != nil { - return - } - - // If we aren't the first proxy retain prior - // X-Forwarded-For information as a comma+space - // separated list and fold multiple headers into one. - if prior, ok := req.Header["X-Forwarded-For"]; ok { - clientIP = strings.Join(prior, ", ") + ", " + clientIP - } - req.Header.Set("X-Forwarded-For", clientIP) -} diff --git a/vendor/go.etcd.io/etcd/proxy/tcpproxy/doc.go b/vendor/go.etcd.io/etcd/proxy/tcpproxy/doc.go deleted file mode 100644 index 6889cacb63ef..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/tcpproxy/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package tcpproxy is an OSI level 4 proxy for routing etcd clients to etcd servers. -package tcpproxy diff --git a/vendor/go.etcd.io/etcd/proxy/tcpproxy/userspace.go b/vendor/go.etcd.io/etcd/proxy/tcpproxy/userspace.go deleted file mode 100644 index 6dc1d1d6d92a..000000000000 --- a/vendor/go.etcd.io/etcd/proxy/tcpproxy/userspace.go +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tcpproxy - -import ( - "fmt" - "io" - "math/rand" - "net" - "sync" - "time" - - "github.com/coreos/pkg/capnslog" -) - -var ( - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "proxy/tcpproxy") -) - -type remote struct { - mu sync.Mutex - srv *net.SRV - addr string - inactive bool -} - -func (r *remote) inactivate() { - r.mu.Lock() - defer r.mu.Unlock() - r.inactive = true -} - -func (r *remote) tryReactivate() error { - conn, err := net.Dial("tcp", r.addr) - if err != nil { - return err - } - conn.Close() - r.mu.Lock() - defer r.mu.Unlock() - r.inactive = false - return nil -} - -func (r *remote) isActive() bool { - r.mu.Lock() - defer r.mu.Unlock() - return !r.inactive -} - -type TCPProxy struct { - Listener net.Listener - Endpoints []*net.SRV - MonitorInterval time.Duration - - donec chan struct{} - - mu sync.Mutex // guards the following fields - remotes []*remote - pickCount int // for round robin -} - -func (tp *TCPProxy) Run() error { - tp.donec = make(chan struct{}) - if tp.MonitorInterval == 0 { - tp.MonitorInterval = 5 * time.Minute - } - for _, srv := range tp.Endpoints { - addr := fmt.Sprintf("%s:%d", srv.Target, srv.Port) - tp.remotes = append(tp.remotes, &remote{srv: srv, addr: addr}) - } - - eps := []string{} - for _, ep := range tp.Endpoints { - eps = append(eps, fmt.Sprintf("%s:%d", ep.Target, ep.Port)) - } - plog.Printf("ready to proxy client requests to %+v", eps) - - go tp.runMonitor() - for { - in, err := tp.Listener.Accept() - if err != nil { - return err - } - - go tp.serve(in) - } -} - -func (tp *TCPProxy) pick() *remote { - var weighted []*remote - var unweighted []*remote - - bestPr := uint16(65535) - w := 0 - // find best priority class - for _, r := range tp.remotes { - switch { - case !r.isActive(): - case r.srv.Priority < bestPr: - bestPr = r.srv.Priority - w = 0 - weighted = nil - unweighted = []*remote{r} - fallthrough - case r.srv.Priority == bestPr: - if r.srv.Weight > 0 { - weighted = append(weighted, r) - w += int(r.srv.Weight) - } else { - unweighted = append(unweighted, r) - } - } - } - if weighted != nil { - if len(unweighted) > 0 && rand.Intn(100) == 1 { - // In the presence of records containing weights greater - // than 0, records with weight 0 should have a very small - // chance of being selected. - r := unweighted[tp.pickCount%len(unweighted)] - tp.pickCount++ - return r - } - // choose a uniform random number between 0 and the sum computed - // (inclusive), and select the RR whose running sum value is the - // first in the selected order - choose := rand.Intn(w) - for i := 0; i < len(weighted); i++ { - choose -= int(weighted[i].srv.Weight) - if choose <= 0 { - return weighted[i] - } - } - } - if unweighted != nil { - for i := 0; i < len(tp.remotes); i++ { - picked := tp.remotes[tp.pickCount%len(tp.remotes)] - tp.pickCount++ - if picked.isActive() { - return picked - } - } - } - return nil -} - -func (tp *TCPProxy) serve(in net.Conn) { - var ( - err error - out net.Conn - ) - - for { - tp.mu.Lock() - remote := tp.pick() - tp.mu.Unlock() - if remote == nil { - break - } - // TODO: add timeout - out, err = net.Dial("tcp", remote.addr) - if err == nil { - break - } - remote.inactivate() - plog.Warningf("deactivated endpoint [%s] due to %v for %v", remote.addr, err, tp.MonitorInterval) - } - - if out == nil { - in.Close() - return - } - - go func() { - io.Copy(in, out) - in.Close() - out.Close() - }() - - io.Copy(out, in) - out.Close() - in.Close() -} - -func (tp *TCPProxy) runMonitor() { - for { - select { - case <-time.After(tp.MonitorInterval): - tp.mu.Lock() - for _, rem := range tp.remotes { - if rem.isActive() { - continue - } - go func(r *remote) { - if err := r.tryReactivate(); err != nil { - plog.Warningf("failed to activate endpoint [%s] due to %v (stay inactive for another %v)", r.addr, err, tp.MonitorInterval) - } else { - plog.Printf("activated %s", r.addr) - } - }(rem) - } - tp.mu.Unlock() - case <-tp.donec: - return - } - } -} - -func (tp *TCPProxy) Stop() { - // graceful shutdown? - // shutdown current connections? - tp.Listener.Close() - close(tp.donec) -} diff --git a/vendor/go.etcd.io/etcd/raft/doc.go b/vendor/go.etcd.io/etcd/raft/doc.go deleted file mode 100644 index b55c591ff5d7..000000000000 --- a/vendor/go.etcd.io/etcd/raft/doc.go +++ /dev/null @@ -1,300 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package raft sends and receives messages in the Protocol Buffer format -defined in the raftpb package. - -Raft is a protocol with which a cluster of nodes can maintain a replicated state machine. -The state machine is kept in sync through the use of a replicated log. -For more details on Raft, see "In Search of an Understandable Consensus Algorithm" -(https://ramcloud.stanford.edu/raft.pdf) by Diego Ongaro and John Ousterhout. - -A simple example application, _raftexample_, is also available to help illustrate -how to use this package in practice: -https://github.com/coreos/etcd/tree/master/contrib/raftexample - -Usage - -The primary object in raft is a Node. You either start a Node from scratch -using raft.StartNode or start a Node from some initial state using raft.RestartNode. - -To start a node from scratch: - - storage := raft.NewMemoryStorage() - c := &Config{ - ID: 0x01, - ElectionTick: 10, - HeartbeatTick: 1, - Storage: storage, - MaxSizePerMsg: 4096, - MaxInflightMsgs: 256, - } - n := raft.StartNode(c, []raft.Peer{{ID: 0x02}, {ID: 0x03}}) - -To restart a node from previous state: - - storage := raft.NewMemoryStorage() - - // recover the in-memory storage from persistent - // snapshot, state and entries. - storage.ApplySnapshot(snapshot) - storage.SetHardState(state) - storage.Append(entries) - - c := &Config{ - ID: 0x01, - ElectionTick: 10, - HeartbeatTick: 1, - Storage: storage, - MaxSizePerMsg: 4096, - MaxInflightMsgs: 256, - } - - // restart raft without peer information. - // peer information is already included in the storage. - n := raft.RestartNode(c) - -Now that you are holding onto a Node you have a few responsibilities: - -First, you must read from the Node.Ready() channel and process the updates -it contains. These steps may be performed in parallel, except as noted in step -2. - -1. Write HardState, Entries, and Snapshot to persistent storage if they are -not empty. Note that when writing an Entry with Index i, any -previously-persisted entries with Index >= i must be discarded. - -2. Send all Messages to the nodes named in the To field. It is important that -no messages be sent until the latest HardState has been persisted to disk, -and all Entries written by any previous Ready batch (Messages may be sent while -entries from the same batch are being persisted). To reduce the I/O latency, an -optimization can be applied to make leader write to disk in parallel with its -followers (as explained at section 10.2.1 in Raft thesis). If any Message has type -MsgSnap, call Node.ReportSnapshot() after it has been sent (these messages may be -large). - -Note: Marshalling messages is not thread-safe; it is important that you -make sure that no new entries are persisted while marshalling. -The easiest way to achieve this is to serialise the messages directly inside -your main raft loop. - -3. Apply Snapshot (if any) and CommittedEntries to the state machine. -If any committed Entry has Type EntryConfChange, call Node.ApplyConfChange() -to apply it to the node. The configuration change may be cancelled at this point -by setting the NodeID field to zero before calling ApplyConfChange -(but ApplyConfChange must be called one way or the other, and the decision to cancel -must be based solely on the state machine and not external information such as -the observed health of the node). - -4. Call Node.Advance() to signal readiness for the next batch of updates. -This may be done at any time after step 1, although all updates must be processed -in the order they were returned by Ready. - -Second, all persisted log entries must be made available via an -implementation of the Storage interface. The provided MemoryStorage -type can be used for this (if you repopulate its state upon a -restart), or you can supply your own disk-backed implementation. - -Third, when you receive a message from another node, pass it to Node.Step: - - func recvRaftRPC(ctx context.Context, m raftpb.Message) { - n.Step(ctx, m) - } - -Finally, you need to call Node.Tick() at regular intervals (probably -via a time.Ticker). Raft has two important timeouts: heartbeat and the -election timeout. However, internally to the raft package time is -represented by an abstract "tick". - -The total state machine handling loop will look something like this: - - for { - select { - case <-s.Ticker: - n.Tick() - case rd := <-s.Node.Ready(): - saveToStorage(rd.State, rd.Entries, rd.Snapshot) - send(rd.Messages) - if !raft.IsEmptySnap(rd.Snapshot) { - processSnapshot(rd.Snapshot) - } - for _, entry := range rd.CommittedEntries { - process(entry) - if entry.Type == raftpb.EntryConfChange { - var cc raftpb.ConfChange - cc.Unmarshal(entry.Data) - s.Node.ApplyConfChange(cc) - } - } - s.Node.Advance() - case <-s.done: - return - } - } - -To propose changes to the state machine from your node take your application -data, serialize it into a byte slice and call: - - n.Propose(ctx, data) - -If the proposal is committed, data will appear in committed entries with type -raftpb.EntryNormal. There is no guarantee that a proposed command will be -committed; you may have to re-propose after a timeout. - -To add or remove node in a cluster, build ConfChange struct 'cc' and call: - - n.ProposeConfChange(ctx, cc) - -After config change is committed, some committed entry with type -raftpb.EntryConfChange will be returned. You must apply it to node through: - - var cc raftpb.ConfChange - cc.Unmarshal(data) - n.ApplyConfChange(cc) - -Note: An ID represents a unique node in a cluster for all time. A -given ID MUST be used only once even if the old node has been removed. -This means that for example IP addresses make poor node IDs since they -may be reused. Node IDs must be non-zero. - -Implementation notes - -This implementation is up to date with the final Raft thesis -(https://ramcloud.stanford.edu/~ongaro/thesis.pdf), although our -implementation of the membership change protocol differs somewhat from -that described in chapter 4. The key invariant that membership changes -happen one node at a time is preserved, but in our implementation the -membership change takes effect when its entry is applied, not when it -is added to the log (so the entry is committed under the old -membership instead of the new). This is equivalent in terms of safety, -since the old and new configurations are guaranteed to overlap. - -To ensure that we do not attempt to commit two membership changes at -once by matching log positions (which would be unsafe since they -should have different quorum requirements), we simply disallow any -proposed membership change while any uncommitted change appears in -the leader's log. - -This approach introduces a problem when you try to remove a member -from a two-member cluster: If one of the members dies before the -other one receives the commit of the confchange entry, then the member -cannot be removed any more since the cluster cannot make progress. -For this reason it is highly recommended to use three or more nodes in -every cluster. - -MessageType - -Package raft sends and receives message in Protocol Buffer format (defined -in raftpb package). Each state (follower, candidate, leader) implements its -own 'step' method ('stepFollower', 'stepCandidate', 'stepLeader') when -advancing with the given raftpb.Message. Each step is determined by its -raftpb.MessageType. Note that every step is checked by one common method -'Step' that safety-checks the terms of node and incoming message to prevent -stale log entries: - - 'MsgHup' is used for election. If a node is a follower or candidate, the - 'tick' function in 'raft' struct is set as 'tickElection'. If a follower or - candidate has not received any heartbeat before the election timeout, it - passes 'MsgHup' to its Step method and becomes (or remains) a candidate to - start a new election. - - 'MsgBeat' is an internal type that signals the leader to send a heartbeat of - the 'MsgHeartbeat' type. If a node is a leader, the 'tick' function in - the 'raft' struct is set as 'tickHeartbeat', and triggers the leader to - send periodic 'MsgHeartbeat' messages to its followers. - - 'MsgProp' proposes to append data to its log entries. This is a special - type to redirect proposals to leader. Therefore, send method overwrites - raftpb.Message's term with its HardState's term to avoid attaching its - local term to 'MsgProp'. When 'MsgProp' is passed to the leader's 'Step' - method, the leader first calls the 'appendEntry' method to append entries - to its log, and then calls 'bcastAppend' method to send those entries to - its peers. When passed to candidate, 'MsgProp' is dropped. When passed to - follower, 'MsgProp' is stored in follower's mailbox(msgs) by the send - method. It is stored with sender's ID and later forwarded to leader by - rafthttp package. - - 'MsgApp' contains log entries to replicate. A leader calls bcastAppend, - which calls sendAppend, which sends soon-to-be-replicated logs in 'MsgApp' - type. When 'MsgApp' is passed to candidate's Step method, candidate reverts - back to follower, because it indicates that there is a valid leader sending - 'MsgApp' messages. Candidate and follower respond to this message in - 'MsgAppResp' type. - - 'MsgAppResp' is response to log replication request('MsgApp'). When - 'MsgApp' is passed to candidate or follower's Step method, it responds by - calling 'handleAppendEntries' method, which sends 'MsgAppResp' to raft - mailbox. - - 'MsgVote' requests votes for election. When a node is a follower or - candidate and 'MsgHup' is passed to its Step method, then the node calls - 'campaign' method to campaign itself to become a leader. Once 'campaign' - method is called, the node becomes candidate and sends 'MsgVote' to peers - in cluster to request votes. When passed to leader or candidate's Step - method and the message's Term is lower than leader's or candidate's, - 'MsgVote' will be rejected ('MsgVoteResp' is returned with Reject true). - If leader or candidate receives 'MsgVote' with higher term, it will revert - back to follower. When 'MsgVote' is passed to follower, it votes for the - sender only when sender's last term is greater than MsgVote's term or - sender's last term is equal to MsgVote's term but sender's last committed - index is greater than or equal to follower's. - - 'MsgVoteResp' contains responses from voting request. When 'MsgVoteResp' is - passed to candidate, the candidate calculates how many votes it has won. If - it's more than majority (quorum), it becomes leader and calls 'bcastAppend'. - If candidate receives majority of votes of denials, it reverts back to - follower. - - 'MsgPreVote' and 'MsgPreVoteResp' are used in an optional two-phase election - protocol. When Config.PreVote is true, a pre-election is carried out first - (using the same rules as a regular election), and no node increases its term - number unless the pre-election indicates that the campaigining node would win. - This minimizes disruption when a partitioned node rejoins the cluster. - - 'MsgSnap' requests to install a snapshot message. When a node has just - become a leader or the leader receives 'MsgProp' message, it calls - 'bcastAppend' method, which then calls 'sendAppend' method to each - follower. In 'sendAppend', if a leader fails to get term or entries, - the leader requests snapshot by sending 'MsgSnap' type message. - - 'MsgSnapStatus' tells the result of snapshot install message. When a - follower rejected 'MsgSnap', it indicates the snapshot request with - 'MsgSnap' had failed from network issues which causes the network layer - to fail to send out snapshots to its followers. Then leader considers - follower's progress as probe. When 'MsgSnap' were not rejected, it - indicates that the snapshot succeeded and the leader sets follower's - progress to probe and resumes its log replication. - - 'MsgHeartbeat' sends heartbeat from leader. When 'MsgHeartbeat' is passed - to candidate and message's term is higher than candidate's, the candidate - reverts back to follower and updates its committed index from the one in - this heartbeat. And it sends the message to its mailbox. When - 'MsgHeartbeat' is passed to follower's Step method and message's term is - higher than follower's, the follower updates its leaderID with the ID - from the message. - - 'MsgHeartbeatResp' is a response to 'MsgHeartbeat'. When 'MsgHeartbeatResp' - is passed to leader's Step method, the leader knows which follower - responded. And only when the leader's last committed index is greater than - follower's Match index, the leader runs 'sendAppend` method. - - 'MsgUnreachable' tells that request(message) wasn't delivered. When - 'MsgUnreachable' is passed to leader's Step method, the leader discovers - that the follower that sent this 'MsgUnreachable' is not reachable, often - indicating 'MsgApp' is lost. When follower's progress state is replicate, - the leader sets it back to probe. - -*/ -package raft diff --git a/vendor/go.etcd.io/etcd/raft/log.go b/vendor/go.etcd.io/etcd/raft/log.go deleted file mode 100644 index c3036d3c90dd..000000000000 --- a/vendor/go.etcd.io/etcd/raft/log.go +++ /dev/null @@ -1,358 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "fmt" - "log" - - pb "github.com/coreos/etcd/raft/raftpb" -) - -type raftLog struct { - // storage contains all stable entries since the last snapshot. - storage Storage - - // unstable contains all unstable entries and snapshot. - // they will be saved into storage. - unstable unstable - - // committed is the highest log position that is known to be in - // stable storage on a quorum of nodes. - committed uint64 - // applied is the highest log position that the application has - // been instructed to apply to its state machine. - // Invariant: applied <= committed - applied uint64 - - logger Logger -} - -// newLog returns log using the given storage. It recovers the log to the state -// that it just commits and applies the latest snapshot. -func newLog(storage Storage, logger Logger) *raftLog { - if storage == nil { - log.Panic("storage must not be nil") - } - log := &raftLog{ - storage: storage, - logger: logger, - } - firstIndex, err := storage.FirstIndex() - if err != nil { - panic(err) // TODO(bdarnell) - } - lastIndex, err := storage.LastIndex() - if err != nil { - panic(err) // TODO(bdarnell) - } - log.unstable.offset = lastIndex + 1 - log.unstable.logger = logger - // Initialize our committed and applied pointers to the time of the last compaction. - log.committed = firstIndex - 1 - log.applied = firstIndex - 1 - - return log -} - -func (l *raftLog) String() string { - return fmt.Sprintf("committed=%d, applied=%d, unstable.offset=%d, len(unstable.Entries)=%d", l.committed, l.applied, l.unstable.offset, len(l.unstable.entries)) -} - -// maybeAppend returns (0, false) if the entries cannot be appended. Otherwise, -// it returns (last index of new entries, true). -func (l *raftLog) maybeAppend(index, logTerm, committed uint64, ents ...pb.Entry) (lastnewi uint64, ok bool) { - if l.matchTerm(index, logTerm) { - lastnewi = index + uint64(len(ents)) - ci := l.findConflict(ents) - switch { - case ci == 0: - case ci <= l.committed: - l.logger.Panicf("entry %d conflict with committed entry [committed(%d)]", ci, l.committed) - default: - offset := index + 1 - l.append(ents[ci-offset:]...) - } - l.commitTo(min(committed, lastnewi)) - return lastnewi, true - } - return 0, false -} - -func (l *raftLog) append(ents ...pb.Entry) uint64 { - if len(ents) == 0 { - return l.lastIndex() - } - if after := ents[0].Index - 1; after < l.committed { - l.logger.Panicf("after(%d) is out of range [committed(%d)]", after, l.committed) - } - l.unstable.truncateAndAppend(ents) - return l.lastIndex() -} - -// findConflict finds the index of the conflict. -// It returns the first pair of conflicting entries between the existing -// entries and the given entries, if there are any. -// If there is no conflicting entries, and the existing entries contains -// all the given entries, zero will be returned. -// If there is no conflicting entries, but the given entries contains new -// entries, the index of the first new entry will be returned. -// An entry is considered to be conflicting if it has the same index but -// a different term. -// The first entry MUST have an index equal to the argument 'from'. -// The index of the given entries MUST be continuously increasing. -func (l *raftLog) findConflict(ents []pb.Entry) uint64 { - for _, ne := range ents { - if !l.matchTerm(ne.Index, ne.Term) { - if ne.Index <= l.lastIndex() { - l.logger.Infof("found conflict at index %d [existing term: %d, conflicting term: %d]", - ne.Index, l.zeroTermOnErrCompacted(l.term(ne.Index)), ne.Term) - } - return ne.Index - } - } - return 0 -} - -func (l *raftLog) unstableEntries() []pb.Entry { - if len(l.unstable.entries) == 0 { - return nil - } - return l.unstable.entries -} - -// nextEnts returns all the available entries for execution. -// If applied is smaller than the index of snapshot, it returns all committed -// entries after the index of snapshot. -func (l *raftLog) nextEnts() (ents []pb.Entry) { - off := max(l.applied+1, l.firstIndex()) - if l.committed+1 > off { - ents, err := l.slice(off, l.committed+1, noLimit) - if err != nil { - l.logger.Panicf("unexpected error when getting unapplied entries (%v)", err) - } - return ents - } - return nil -} - -// hasNextEnts returns if there is any available entries for execution. This -// is a fast check without heavy raftLog.slice() in raftLog.nextEnts(). -func (l *raftLog) hasNextEnts() bool { - off := max(l.applied+1, l.firstIndex()) - return l.committed+1 > off -} - -func (l *raftLog) snapshot() (pb.Snapshot, error) { - if l.unstable.snapshot != nil { - return *l.unstable.snapshot, nil - } - return l.storage.Snapshot() -} - -func (l *raftLog) firstIndex() uint64 { - if i, ok := l.unstable.maybeFirstIndex(); ok { - return i - } - index, err := l.storage.FirstIndex() - if err != nil { - panic(err) // TODO(bdarnell) - } - return index -} - -func (l *raftLog) lastIndex() uint64 { - if i, ok := l.unstable.maybeLastIndex(); ok { - return i - } - i, err := l.storage.LastIndex() - if err != nil { - panic(err) // TODO(bdarnell) - } - return i -} - -func (l *raftLog) commitTo(tocommit uint64) { - // never decrease commit - if l.committed < tocommit { - if l.lastIndex() < tocommit { - l.logger.Panicf("tocommit(%d) is out of range [lastIndex(%d)]. Was the raft log corrupted, truncated, or lost?", tocommit, l.lastIndex()) - } - l.committed = tocommit - } -} - -func (l *raftLog) appliedTo(i uint64) { - if i == 0 { - return - } - if l.committed < i || i < l.applied { - l.logger.Panicf("applied(%d) is out of range [prevApplied(%d), committed(%d)]", i, l.applied, l.committed) - } - l.applied = i -} - -func (l *raftLog) stableTo(i, t uint64) { l.unstable.stableTo(i, t) } - -func (l *raftLog) stableSnapTo(i uint64) { l.unstable.stableSnapTo(i) } - -func (l *raftLog) lastTerm() uint64 { - t, err := l.term(l.lastIndex()) - if err != nil { - l.logger.Panicf("unexpected error when getting the last term (%v)", err) - } - return t -} - -func (l *raftLog) term(i uint64) (uint64, error) { - // the valid term range is [index of dummy entry, last index] - dummyIndex := l.firstIndex() - 1 - if i < dummyIndex || i > l.lastIndex() { - // TODO: return an error instead? - return 0, nil - } - - if t, ok := l.unstable.maybeTerm(i); ok { - return t, nil - } - - t, err := l.storage.Term(i) - if err == nil { - return t, nil - } - if err == ErrCompacted || err == ErrUnavailable { - return 0, err - } - panic(err) // TODO(bdarnell) -} - -func (l *raftLog) entries(i, maxsize uint64) ([]pb.Entry, error) { - if i > l.lastIndex() { - return nil, nil - } - return l.slice(i, l.lastIndex()+1, maxsize) -} - -// allEntries returns all entries in the log. -func (l *raftLog) allEntries() []pb.Entry { - ents, err := l.entries(l.firstIndex(), noLimit) - if err == nil { - return ents - } - if err == ErrCompacted { // try again if there was a racing compaction - return l.allEntries() - } - // TODO (xiangli): handle error? - panic(err) -} - -// isUpToDate determines if the given (lastIndex,term) log is more up-to-date -// by comparing the index and term of the last entries in the existing logs. -// If the logs have last entries with different terms, then the log with the -// later term is more up-to-date. If the logs end with the same term, then -// whichever log has the larger lastIndex is more up-to-date. If the logs are -// the same, the given log is up-to-date. -func (l *raftLog) isUpToDate(lasti, term uint64) bool { - return term > l.lastTerm() || (term == l.lastTerm() && lasti >= l.lastIndex()) -} - -func (l *raftLog) matchTerm(i, term uint64) bool { - t, err := l.term(i) - if err != nil { - return false - } - return t == term -} - -func (l *raftLog) maybeCommit(maxIndex, term uint64) bool { - if maxIndex > l.committed && l.zeroTermOnErrCompacted(l.term(maxIndex)) == term { - l.commitTo(maxIndex) - return true - } - return false -} - -func (l *raftLog) restore(s pb.Snapshot) { - l.logger.Infof("log [%s] starts to restore snapshot [index: %d, term: %d]", l, s.Metadata.Index, s.Metadata.Term) - l.committed = s.Metadata.Index - l.unstable.restore(s) -} - -// slice returns a slice of log entries from lo through hi-1, inclusive. -func (l *raftLog) slice(lo, hi, maxSize uint64) ([]pb.Entry, error) { - err := l.mustCheckOutOfBounds(lo, hi) - if err != nil { - return nil, err - } - if lo == hi { - return nil, nil - } - var ents []pb.Entry - if lo < l.unstable.offset { - storedEnts, err := l.storage.Entries(lo, min(hi, l.unstable.offset), maxSize) - if err == ErrCompacted { - return nil, err - } else if err == ErrUnavailable { - l.logger.Panicf("entries[%d:%d) is unavailable from storage", lo, min(hi, l.unstable.offset)) - } else if err != nil { - panic(err) // TODO(bdarnell) - } - - // check if ents has reached the size limitation - if uint64(len(storedEnts)) < min(hi, l.unstable.offset)-lo { - return storedEnts, nil - } - - ents = storedEnts - } - if hi > l.unstable.offset { - unstable := l.unstable.slice(max(lo, l.unstable.offset), hi) - if len(ents) > 0 { - ents = append([]pb.Entry{}, ents...) - ents = append(ents, unstable...) - } else { - ents = unstable - } - } - return limitSize(ents, maxSize), nil -} - -// l.firstIndex <= lo <= hi <= l.firstIndex + len(l.entries) -func (l *raftLog) mustCheckOutOfBounds(lo, hi uint64) error { - if lo > hi { - l.logger.Panicf("invalid slice %d > %d", lo, hi) - } - fi := l.firstIndex() - if lo < fi { - return ErrCompacted - } - - length := l.lastIndex() + 1 - fi - if lo < fi || hi > fi+length { - l.logger.Panicf("slice[%d,%d) out of bound [%d,%d]", lo, hi, fi, l.lastIndex()) - } - return nil -} - -func (l *raftLog) zeroTermOnErrCompacted(t uint64, err error) uint64 { - if err == nil { - return t - } - if err == ErrCompacted { - return 0 - } - l.logger.Panicf("unexpected error (%v)", err) - return 0 -} diff --git a/vendor/go.etcd.io/etcd/raft/log_unstable.go b/vendor/go.etcd.io/etcd/raft/log_unstable.go deleted file mode 100644 index 263af9ce405e..000000000000 --- a/vendor/go.etcd.io/etcd/raft/log_unstable.go +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import pb "github.com/coreos/etcd/raft/raftpb" - -// unstable.entries[i] has raft log position i+unstable.offset. -// Note that unstable.offset may be less than the highest log -// position in storage; this means that the next write to storage -// might need to truncate the log before persisting unstable.entries. -type unstable struct { - // the incoming unstable snapshot, if any. - snapshot *pb.Snapshot - // all entries that have not yet been written to storage. - entries []pb.Entry - offset uint64 - - logger Logger -} - -// maybeFirstIndex returns the index of the first possible entry in entries -// if it has a snapshot. -func (u *unstable) maybeFirstIndex() (uint64, bool) { - if u.snapshot != nil { - return u.snapshot.Metadata.Index + 1, true - } - return 0, false -} - -// maybeLastIndex returns the last index if it has at least one -// unstable entry or snapshot. -func (u *unstable) maybeLastIndex() (uint64, bool) { - if l := len(u.entries); l != 0 { - return u.offset + uint64(l) - 1, true - } - if u.snapshot != nil { - return u.snapshot.Metadata.Index, true - } - return 0, false -} - -// maybeTerm returns the term of the entry at index i, if there -// is any. -func (u *unstable) maybeTerm(i uint64) (uint64, bool) { - if i < u.offset { - if u.snapshot == nil { - return 0, false - } - if u.snapshot.Metadata.Index == i { - return u.snapshot.Metadata.Term, true - } - return 0, false - } - - last, ok := u.maybeLastIndex() - if !ok { - return 0, false - } - if i > last { - return 0, false - } - return u.entries[i-u.offset].Term, true -} - -func (u *unstable) stableTo(i, t uint64) { - gt, ok := u.maybeTerm(i) - if !ok { - return - } - // if i < offset, term is matched with the snapshot - // only update the unstable entries if term is matched with - // an unstable entry. - if gt == t && i >= u.offset { - u.entries = u.entries[i+1-u.offset:] - u.offset = i + 1 - u.shrinkEntriesArray() - } -} - -// shrinkEntriesArray discards the underlying array used by the entries slice -// if most of it isn't being used. This avoids holding references to a bunch of -// potentially large entries that aren't needed anymore. Simply clearing the -// entries wouldn't be safe because clients might still be using them. -func (u *unstable) shrinkEntriesArray() { - // We replace the array if we're using less than half of the space in - // it. This number is fairly arbitrary, chosen as an attempt to balance - // memory usage vs number of allocations. It could probably be improved - // with some focused tuning. - const lenMultiple = 2 - if len(u.entries) == 0 { - u.entries = nil - } else if len(u.entries)*lenMultiple < cap(u.entries) { - newEntries := make([]pb.Entry, len(u.entries)) - copy(newEntries, u.entries) - u.entries = newEntries - } -} - -func (u *unstable) stableSnapTo(i uint64) { - if u.snapshot != nil && u.snapshot.Metadata.Index == i { - u.snapshot = nil - } -} - -func (u *unstable) restore(s pb.Snapshot) { - u.offset = s.Metadata.Index + 1 - u.entries = nil - u.snapshot = &s -} - -func (u *unstable) truncateAndAppend(ents []pb.Entry) { - after := ents[0].Index - switch { - case after == u.offset+uint64(len(u.entries)): - // after is the next index in the u.entries - // directly append - u.entries = append(u.entries, ents...) - case after <= u.offset: - u.logger.Infof("replace the unstable entries from index %d", after) - // The log is being truncated to before our current offset - // portion, so set the offset and replace the entries - u.offset = after - u.entries = ents - default: - // truncate to after and copy to u.entries - // then append - u.logger.Infof("truncate the unstable entries before index %d", after) - u.entries = append([]pb.Entry{}, u.slice(u.offset, after)...) - u.entries = append(u.entries, ents...) - } -} - -func (u *unstable) slice(lo uint64, hi uint64) []pb.Entry { - u.mustCheckOutOfBounds(lo, hi) - return u.entries[lo-u.offset : hi-u.offset] -} - -// u.offset <= lo <= hi <= u.offset+len(u.offset) -func (u *unstable) mustCheckOutOfBounds(lo, hi uint64) { - if lo > hi { - u.logger.Panicf("invalid unstable.slice %d > %d", lo, hi) - } - upper := u.offset + uint64(len(u.entries)) - if lo < u.offset || hi > upper { - u.logger.Panicf("unstable.slice[%d,%d) out of bound [%d,%d]", lo, hi, u.offset, upper) - } -} diff --git a/vendor/go.etcd.io/etcd/raft/logger.go b/vendor/go.etcd.io/etcd/raft/logger.go deleted file mode 100644 index 92e55b373e1d..000000000000 --- a/vendor/go.etcd.io/etcd/raft/logger.go +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "fmt" - "io/ioutil" - "log" - "os" -) - -type Logger interface { - Debug(v ...interface{}) - Debugf(format string, v ...interface{}) - - Error(v ...interface{}) - Errorf(format string, v ...interface{}) - - Info(v ...interface{}) - Infof(format string, v ...interface{}) - - Warning(v ...interface{}) - Warningf(format string, v ...interface{}) - - Fatal(v ...interface{}) - Fatalf(format string, v ...interface{}) - - Panic(v ...interface{}) - Panicf(format string, v ...interface{}) -} - -func SetLogger(l Logger) { raftLogger = l } - -var ( - defaultLogger = &DefaultLogger{Logger: log.New(os.Stderr, "raft", log.LstdFlags)} - discardLogger = &DefaultLogger{Logger: log.New(ioutil.Discard, "", 0)} - raftLogger = Logger(defaultLogger) -) - -const ( - calldepth = 2 -) - -// DefaultLogger is a default implementation of the Logger interface. -type DefaultLogger struct { - *log.Logger - debug bool -} - -func (l *DefaultLogger) EnableTimestamps() { - l.SetFlags(l.Flags() | log.Ldate | log.Ltime) -} - -func (l *DefaultLogger) EnableDebug() { - l.debug = true -} - -func (l *DefaultLogger) Debug(v ...interface{}) { - if l.debug { - l.Output(calldepth, header("DEBUG", fmt.Sprint(v...))) - } -} - -func (l *DefaultLogger) Debugf(format string, v ...interface{}) { - if l.debug { - l.Output(calldepth, header("DEBUG", fmt.Sprintf(format, v...))) - } -} - -func (l *DefaultLogger) Info(v ...interface{}) { - l.Output(calldepth, header("INFO", fmt.Sprint(v...))) -} - -func (l *DefaultLogger) Infof(format string, v ...interface{}) { - l.Output(calldepth, header("INFO", fmt.Sprintf(format, v...))) -} - -func (l *DefaultLogger) Error(v ...interface{}) { - l.Output(calldepth, header("ERROR", fmt.Sprint(v...))) -} - -func (l *DefaultLogger) Errorf(format string, v ...interface{}) { - l.Output(calldepth, header("ERROR", fmt.Sprintf(format, v...))) -} - -func (l *DefaultLogger) Warning(v ...interface{}) { - l.Output(calldepth, header("WARN", fmt.Sprint(v...))) -} - -func (l *DefaultLogger) Warningf(format string, v ...interface{}) { - l.Output(calldepth, header("WARN", fmt.Sprintf(format, v...))) -} - -func (l *DefaultLogger) Fatal(v ...interface{}) { - l.Output(calldepth, header("FATAL", fmt.Sprint(v...))) - os.Exit(1) -} - -func (l *DefaultLogger) Fatalf(format string, v ...interface{}) { - l.Output(calldepth, header("FATAL", fmt.Sprintf(format, v...))) - os.Exit(1) -} - -func (l *DefaultLogger) Panic(v ...interface{}) { - l.Logger.Panic(v) -} - -func (l *DefaultLogger) Panicf(format string, v ...interface{}) { - l.Logger.Panicf(format, v...) -} - -func header(lvl, msg string) string { - return fmt.Sprintf("%s: %s", lvl, msg) -} diff --git a/vendor/go.etcd.io/etcd/raft/node.go b/vendor/go.etcd.io/etcd/raft/node.go deleted file mode 100644 index 33a9db840012..000000000000 --- a/vendor/go.etcd.io/etcd/raft/node.go +++ /dev/null @@ -1,539 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "context" - "errors" - - pb "github.com/coreos/etcd/raft/raftpb" -) - -type SnapshotStatus int - -const ( - SnapshotFinish SnapshotStatus = 1 - SnapshotFailure SnapshotStatus = 2 -) - -var ( - emptyState = pb.HardState{} - - // ErrStopped is returned by methods on Nodes that have been stopped. - ErrStopped = errors.New("raft: stopped") -) - -// SoftState provides state that is useful for logging and debugging. -// The state is volatile and does not need to be persisted to the WAL. -type SoftState struct { - Lead uint64 // must use atomic operations to access; keep 64-bit aligned. - RaftState StateType -} - -func (a *SoftState) equal(b *SoftState) bool { - return a.Lead == b.Lead && a.RaftState == b.RaftState -} - -// Ready encapsulates the entries and messages that are ready to read, -// be saved to stable storage, committed or sent to other peers. -// All fields in Ready are read-only. -type Ready struct { - // The current volatile state of a Node. - // SoftState will be nil if there is no update. - // It is not required to consume or store SoftState. - *SoftState - - // The current state of a Node to be saved to stable storage BEFORE - // Messages are sent. - // HardState will be equal to empty state if there is no update. - pb.HardState - - // ReadStates can be used for node to serve linearizable read requests locally - // when its applied index is greater than the index in ReadState. - // Note that the readState will be returned when raft receives msgReadIndex. - // The returned is only valid for the request that requested to read. - ReadStates []ReadState - - // Entries specifies entries to be saved to stable storage BEFORE - // Messages are sent. - Entries []pb.Entry - - // Snapshot specifies the snapshot to be saved to stable storage. - Snapshot pb.Snapshot - - // CommittedEntries specifies entries to be committed to a - // store/state-machine. These have previously been committed to stable - // store. - CommittedEntries []pb.Entry - - // Messages specifies outbound messages to be sent AFTER Entries are - // committed to stable storage. - // If it contains a MsgSnap message, the application MUST report back to raft - // when the snapshot has been received or has failed by calling ReportSnapshot. - Messages []pb.Message - - // MustSync indicates whether the HardState and Entries must be synchronously - // written to disk or if an asynchronous write is permissible. - MustSync bool -} - -func isHardStateEqual(a, b pb.HardState) bool { - return a.Term == b.Term && a.Vote == b.Vote && a.Commit == b.Commit -} - -// IsEmptyHardState returns true if the given HardState is empty. -func IsEmptyHardState(st pb.HardState) bool { - return isHardStateEqual(st, emptyState) -} - -// IsEmptySnap returns true if the given Snapshot is empty. -func IsEmptySnap(sp pb.Snapshot) bool { - return sp.Metadata.Index == 0 -} - -func (rd Ready) containsUpdates() bool { - return rd.SoftState != nil || !IsEmptyHardState(rd.HardState) || - !IsEmptySnap(rd.Snapshot) || len(rd.Entries) > 0 || - len(rd.CommittedEntries) > 0 || len(rd.Messages) > 0 || len(rd.ReadStates) != 0 -} - -// Node represents a node in a raft cluster. -type Node interface { - // Tick increments the internal logical clock for the Node by a single tick. Election - // timeouts and heartbeat timeouts are in units of ticks. - Tick() - // Campaign causes the Node to transition to candidate state and start campaigning to become leader. - Campaign(ctx context.Context) error - // Propose proposes that data be appended to the log. - Propose(ctx context.Context, data []byte) error - // ProposeConfChange proposes config change. - // At most one ConfChange can be in the process of going through consensus. - // Application needs to call ApplyConfChange when applying EntryConfChange type entry. - ProposeConfChange(ctx context.Context, cc pb.ConfChange) error - // Step advances the state machine using the given message. ctx.Err() will be returned, if any. - Step(ctx context.Context, msg pb.Message) error - - // Ready returns a channel that returns the current point-in-time state. - // Users of the Node must call Advance after retrieving the state returned by Ready. - // - // NOTE: No committed entries from the next Ready may be applied until all committed entries - // and snapshots from the previous one have finished. - Ready() <-chan Ready - - // Advance notifies the Node that the application has saved progress up to the last Ready. - // It prepares the node to return the next available Ready. - // - // The application should generally call Advance after it applies the entries in last Ready. - // - // However, as an optimization, the application may call Advance while it is applying the - // commands. For example. when the last Ready contains a snapshot, the application might take - // a long time to apply the snapshot data. To continue receiving Ready without blocking raft - // progress, it can call Advance before finishing applying the last ready. - Advance() - // ApplyConfChange applies config change to the local node. - // Returns an opaque ConfState protobuf which must be recorded - // in snapshots. Will never return nil; it returns a pointer only - // to match MemoryStorage.Compact. - ApplyConfChange(cc pb.ConfChange) *pb.ConfState - - // TransferLeadership attempts to transfer leadership to the given transferee. - TransferLeadership(ctx context.Context, lead, transferee uint64) - - // ReadIndex request a read state. The read state will be set in the ready. - // Read state has a read index. Once the application advances further than the read - // index, any linearizable read requests issued before the read request can be - // processed safely. The read state will have the same rctx attached. - ReadIndex(ctx context.Context, rctx []byte) error - - // Status returns the current status of the raft state machine. - Status() Status - // ReportUnreachable reports the given node is not reachable for the last send. - ReportUnreachable(id uint64) - // ReportSnapshot reports the status of the sent snapshot. - ReportSnapshot(id uint64, status SnapshotStatus) - // Stop performs any necessary termination of the Node. - Stop() -} - -type Peer struct { - ID uint64 - Context []byte -} - -// StartNode returns a new Node given configuration and a list of raft peers. -// It appends a ConfChangeAddNode entry for each given peer to the initial log. -func StartNode(c *Config, peers []Peer) Node { - r := newRaft(c) - // become the follower at term 1 and apply initial configuration - // entries of term 1 - r.becomeFollower(1, None) - for _, peer := range peers { - cc := pb.ConfChange{Type: pb.ConfChangeAddNode, NodeID: peer.ID, Context: peer.Context} - d, err := cc.Marshal() - if err != nil { - panic("unexpected marshal error") - } - e := pb.Entry{Type: pb.EntryConfChange, Term: 1, Index: r.raftLog.lastIndex() + 1, Data: d} - r.raftLog.append(e) - } - // Mark these initial entries as committed. - // TODO(bdarnell): These entries are still unstable; do we need to preserve - // the invariant that committed < unstable? - r.raftLog.committed = r.raftLog.lastIndex() - // Now apply them, mainly so that the application can call Campaign - // immediately after StartNode in tests. Note that these nodes will - // be added to raft twice: here and when the application's Ready - // loop calls ApplyConfChange. The calls to addNode must come after - // all calls to raftLog.append so progress.next is set after these - // bootstrapping entries (it is an error if we try to append these - // entries since they have already been committed). - // We do not set raftLog.applied so the application will be able - // to observe all conf changes via Ready.CommittedEntries. - for _, peer := range peers { - r.addNode(peer.ID) - } - - n := newNode() - n.logger = c.Logger - go n.run(r) - return &n -} - -// RestartNode is similar to StartNode but does not take a list of peers. -// The current membership of the cluster will be restored from the Storage. -// If the caller has an existing state machine, pass in the last log index that -// has been applied to it; otherwise use zero. -func RestartNode(c *Config) Node { - r := newRaft(c) - - n := newNode() - n.logger = c.Logger - go n.run(r) - return &n -} - -// node is the canonical implementation of the Node interface -type node struct { - propc chan pb.Message - recvc chan pb.Message - confc chan pb.ConfChange - confstatec chan pb.ConfState - readyc chan Ready - advancec chan struct{} - tickc chan struct{} - done chan struct{} - stop chan struct{} - status chan chan Status - - logger Logger -} - -func newNode() node { - return node{ - propc: make(chan pb.Message), - recvc: make(chan pb.Message), - confc: make(chan pb.ConfChange), - confstatec: make(chan pb.ConfState), - readyc: make(chan Ready), - advancec: make(chan struct{}), - // make tickc a buffered chan, so raft node can buffer some ticks when the node - // is busy processing raft messages. Raft node will resume process buffered - // ticks when it becomes idle. - tickc: make(chan struct{}, 128), - done: make(chan struct{}), - stop: make(chan struct{}), - status: make(chan chan Status), - } -} - -func (n *node) Stop() { - select { - case n.stop <- struct{}{}: - // Not already stopped, so trigger it - case <-n.done: - // Node has already been stopped - no need to do anything - return - } - // Block until the stop has been acknowledged by run() - <-n.done -} - -func (n *node) run(r *raft) { - var propc chan pb.Message - var readyc chan Ready - var advancec chan struct{} - var prevLastUnstablei, prevLastUnstablet uint64 - var havePrevLastUnstablei bool - var prevSnapi uint64 - var rd Ready - - lead := None - prevSoftSt := r.softState() - prevHardSt := emptyState - - for { - if advancec != nil { - readyc = nil - } else { - rd = newReady(r, prevSoftSt, prevHardSt) - if rd.containsUpdates() { - readyc = n.readyc - } else { - readyc = nil - } - } - - if lead != r.lead { - if r.hasLeader() { - if lead == None { - r.logger.Infof("raft.node: %x elected leader %x at term %d", r.id, r.lead, r.Term) - } else { - r.logger.Infof("raft.node: %x changed leader from %x to %x at term %d", r.id, lead, r.lead, r.Term) - } - propc = n.propc - } else { - r.logger.Infof("raft.node: %x lost leader %x at term %d", r.id, lead, r.Term) - propc = nil - } - lead = r.lead - } - - select { - // TODO: maybe buffer the config propose if there exists one (the way - // described in raft dissertation) - // Currently it is dropped in Step silently. - case m := <-propc: - m.From = r.id - r.Step(m) - case m := <-n.recvc: - // filter out response message from unknown From. - if pr := r.getProgress(m.From); pr != nil || !IsResponseMsg(m.Type) { - r.Step(m) // raft never returns an error - } - case cc := <-n.confc: - if cc.NodeID == None { - r.resetPendingConf() - select { - case n.confstatec <- pb.ConfState{Nodes: r.nodes()}: - case <-n.done: - } - break - } - switch cc.Type { - case pb.ConfChangeAddNode: - r.addNode(cc.NodeID) - case pb.ConfChangeAddLearnerNode: - r.addLearner(cc.NodeID) - case pb.ConfChangeRemoveNode: - // block incoming proposal when local node is - // removed - if cc.NodeID == r.id { - propc = nil - } - r.removeNode(cc.NodeID) - case pb.ConfChangeUpdateNode: - r.resetPendingConf() - default: - panic("unexpected conf type") - } - select { - case n.confstatec <- pb.ConfState{Nodes: r.nodes()}: - case <-n.done: - } - case <-n.tickc: - r.tick() - case readyc <- rd: - if rd.SoftState != nil { - prevSoftSt = rd.SoftState - } - if len(rd.Entries) > 0 { - prevLastUnstablei = rd.Entries[len(rd.Entries)-1].Index - prevLastUnstablet = rd.Entries[len(rd.Entries)-1].Term - havePrevLastUnstablei = true - } - if !IsEmptyHardState(rd.HardState) { - prevHardSt = rd.HardState - } - if !IsEmptySnap(rd.Snapshot) { - prevSnapi = rd.Snapshot.Metadata.Index - } - - r.msgs = nil - r.readStates = nil - advancec = n.advancec - case <-advancec: - if prevHardSt.Commit != 0 { - r.raftLog.appliedTo(prevHardSt.Commit) - } - if havePrevLastUnstablei { - r.raftLog.stableTo(prevLastUnstablei, prevLastUnstablet) - havePrevLastUnstablei = false - } - r.raftLog.stableSnapTo(prevSnapi) - advancec = nil - case c := <-n.status: - c <- getStatus(r) - case <-n.stop: - close(n.done) - return - } - } -} - -// Tick increments the internal logical clock for this Node. Election timeouts -// and heartbeat timeouts are in units of ticks. -func (n *node) Tick() { - select { - case n.tickc <- struct{}{}: - case <-n.done: - default: - n.logger.Warningf("A tick missed to fire. Node blocks too long!") - } -} - -func (n *node) Campaign(ctx context.Context) error { return n.step(ctx, pb.Message{Type: pb.MsgHup}) } - -func (n *node) Propose(ctx context.Context, data []byte) error { - return n.step(ctx, pb.Message{Type: pb.MsgProp, Entries: []pb.Entry{{Data: data}}}) -} - -func (n *node) Step(ctx context.Context, m pb.Message) error { - // ignore unexpected local messages receiving over network - if IsLocalMsg(m.Type) { - // TODO: return an error? - return nil - } - return n.step(ctx, m) -} - -func (n *node) ProposeConfChange(ctx context.Context, cc pb.ConfChange) error { - data, err := cc.Marshal() - if err != nil { - return err - } - return n.Step(ctx, pb.Message{Type: pb.MsgProp, Entries: []pb.Entry{{Type: pb.EntryConfChange, Data: data}}}) -} - -// Step advances the state machine using msgs. The ctx.Err() will be returned, -// if any. -func (n *node) step(ctx context.Context, m pb.Message) error { - ch := n.recvc - if m.Type == pb.MsgProp { - ch = n.propc - } - - select { - case ch <- m: - return nil - case <-ctx.Done(): - return ctx.Err() - case <-n.done: - return ErrStopped - } -} - -func (n *node) Ready() <-chan Ready { return n.readyc } - -func (n *node) Advance() { - select { - case n.advancec <- struct{}{}: - case <-n.done: - } -} - -func (n *node) ApplyConfChange(cc pb.ConfChange) *pb.ConfState { - var cs pb.ConfState - select { - case n.confc <- cc: - case <-n.done: - } - select { - case cs = <-n.confstatec: - case <-n.done: - } - return &cs -} - -func (n *node) Status() Status { - c := make(chan Status) - select { - case n.status <- c: - return <-c - case <-n.done: - return Status{} - } -} - -func (n *node) ReportUnreachable(id uint64) { - select { - case n.recvc <- pb.Message{Type: pb.MsgUnreachable, From: id}: - case <-n.done: - } -} - -func (n *node) ReportSnapshot(id uint64, status SnapshotStatus) { - rej := status == SnapshotFailure - - select { - case n.recvc <- pb.Message{Type: pb.MsgSnapStatus, From: id, Reject: rej}: - case <-n.done: - } -} - -func (n *node) TransferLeadership(ctx context.Context, lead, transferee uint64) { - select { - // manually set 'from' and 'to', so that leader can voluntarily transfers its leadership - case n.recvc <- pb.Message{Type: pb.MsgTransferLeader, From: transferee, To: lead}: - case <-n.done: - case <-ctx.Done(): - } -} - -func (n *node) ReadIndex(ctx context.Context, rctx []byte) error { - return n.step(ctx, pb.Message{Type: pb.MsgReadIndex, Entries: []pb.Entry{{Data: rctx}}}) -} - -func newReady(r *raft, prevSoftSt *SoftState, prevHardSt pb.HardState) Ready { - rd := Ready{ - Entries: r.raftLog.unstableEntries(), - CommittedEntries: r.raftLog.nextEnts(), - Messages: r.msgs, - } - if softSt := r.softState(); !softSt.equal(prevSoftSt) { - rd.SoftState = softSt - } - if hardSt := r.hardState(); !isHardStateEqual(hardSt, prevHardSt) { - rd.HardState = hardSt - } - if r.raftLog.unstable.snapshot != nil { - rd.Snapshot = *r.raftLog.unstable.snapshot - } - if len(r.readStates) != 0 { - rd.ReadStates = r.readStates - } - rd.MustSync = MustSync(rd.HardState, prevHardSt, len(rd.Entries)) - return rd -} - -// MustSync returns true if the hard state and count of Raft entries indicate -// that a synchronous write to persistent storage is required. -func MustSync(st, prevst pb.HardState, entsnum int) bool { - // Persistent state on all servers: - // (Updated on stable storage before responding to RPCs) - // currentTerm - // votedFor - // log entries[] - return entsnum != 0 || st.Vote != prevst.Vote || st.Term != prevst.Term -} diff --git a/vendor/go.etcd.io/etcd/raft/progress.go b/vendor/go.etcd.io/etcd/raft/progress.go deleted file mode 100644 index ef3787db65d3..000000000000 --- a/vendor/go.etcd.io/etcd/raft/progress.go +++ /dev/null @@ -1,284 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import "fmt" - -const ( - ProgressStateProbe ProgressStateType = iota - ProgressStateReplicate - ProgressStateSnapshot -) - -type ProgressStateType uint64 - -var prstmap = [...]string{ - "ProgressStateProbe", - "ProgressStateReplicate", - "ProgressStateSnapshot", -} - -func (st ProgressStateType) String() string { return prstmap[uint64(st)] } - -// Progress represents a follower’s progress in the view of the leader. Leader maintains -// progresses of all followers, and sends entries to the follower based on its progress. -type Progress struct { - Match, Next uint64 - // State defines how the leader should interact with the follower. - // - // When in ProgressStateProbe, leader sends at most one replication message - // per heartbeat interval. It also probes actual progress of the follower. - // - // When in ProgressStateReplicate, leader optimistically increases next - // to the latest entry sent after sending replication message. This is - // an optimized state for fast replicating log entries to the follower. - // - // When in ProgressStateSnapshot, leader should have sent out snapshot - // before and stops sending any replication message. - State ProgressStateType - - // Paused is used in ProgressStateProbe. - // When Paused is true, raft should pause sending replication message to this peer. - Paused bool - // PendingSnapshot is used in ProgressStateSnapshot. - // If there is a pending snapshot, the pendingSnapshot will be set to the - // index of the snapshot. If pendingSnapshot is set, the replication process of - // this Progress will be paused. raft will not resend snapshot until the pending one - // is reported to be failed. - PendingSnapshot uint64 - - // RecentActive is true if the progress is recently active. Receiving any messages - // from the corresponding follower indicates the progress is active. - // RecentActive can be reset to false after an election timeout. - RecentActive bool - - // inflights is a sliding window for the inflight messages. - // Each inflight message contains one or more log entries. - // The max number of entries per message is defined in raft config as MaxSizePerMsg. - // Thus inflight effectively limits both the number of inflight messages - // and the bandwidth each Progress can use. - // When inflights is full, no more message should be sent. - // When a leader sends out a message, the index of the last - // entry should be added to inflights. The index MUST be added - // into inflights in order. - // When a leader receives a reply, the previous inflights should - // be freed by calling inflights.freeTo with the index of the last - // received entry. - ins *inflights - - // IsLearner is true if this progress is tracked for a learner. - IsLearner bool -} - -func (pr *Progress) resetState(state ProgressStateType) { - pr.Paused = false - pr.PendingSnapshot = 0 - pr.State = state - pr.ins.reset() -} - -func (pr *Progress) becomeProbe() { - // If the original state is ProgressStateSnapshot, progress knows that - // the pending snapshot has been sent to this peer successfully, then - // probes from pendingSnapshot + 1. - if pr.State == ProgressStateSnapshot { - pendingSnapshot := pr.PendingSnapshot - pr.resetState(ProgressStateProbe) - pr.Next = max(pr.Match+1, pendingSnapshot+1) - } else { - pr.resetState(ProgressStateProbe) - pr.Next = pr.Match + 1 - } -} - -func (pr *Progress) becomeReplicate() { - pr.resetState(ProgressStateReplicate) - pr.Next = pr.Match + 1 -} - -func (pr *Progress) becomeSnapshot(snapshoti uint64) { - pr.resetState(ProgressStateSnapshot) - pr.PendingSnapshot = snapshoti -} - -// maybeUpdate returns false if the given n index comes from an outdated message. -// Otherwise it updates the progress and returns true. -func (pr *Progress) maybeUpdate(n uint64) bool { - var updated bool - if pr.Match < n { - pr.Match = n - updated = true - pr.resume() - } - if pr.Next < n+1 { - pr.Next = n + 1 - } - return updated -} - -func (pr *Progress) optimisticUpdate(n uint64) { pr.Next = n + 1 } - -// maybeDecrTo returns false if the given to index comes from an out of order message. -// Otherwise it decreases the progress next index to min(rejected, last) and returns true. -func (pr *Progress) maybeDecrTo(rejected, last uint64) bool { - if pr.State == ProgressStateReplicate { - // the rejection must be stale if the progress has matched and "rejected" - // is smaller than "match". - if rejected <= pr.Match { - return false - } - // directly decrease next to match + 1 - pr.Next = pr.Match + 1 - return true - } - - // the rejection must be stale if "rejected" does not match next - 1 - if pr.Next-1 != rejected { - return false - } - - if pr.Next = min(rejected, last+1); pr.Next < 1 { - pr.Next = 1 - } - pr.resume() - return true -} - -func (pr *Progress) pause() { pr.Paused = true } -func (pr *Progress) resume() { pr.Paused = false } - -// IsPaused returns whether sending log entries to this node has been -// paused. A node may be paused because it has rejected recent -// MsgApps, is currently waiting for a snapshot, or has reached the -// MaxInflightMsgs limit. -func (pr *Progress) IsPaused() bool { - switch pr.State { - case ProgressStateProbe: - return pr.Paused - case ProgressStateReplicate: - return pr.ins.full() - case ProgressStateSnapshot: - return true - default: - panic("unexpected state") - } -} - -func (pr *Progress) snapshotFailure() { pr.PendingSnapshot = 0 } - -// needSnapshotAbort returns true if snapshot progress's Match -// is equal or higher than the pendingSnapshot. -func (pr *Progress) needSnapshotAbort() bool { - return pr.State == ProgressStateSnapshot && pr.Match >= pr.PendingSnapshot -} - -func (pr *Progress) String() string { - return fmt.Sprintf("next = %d, match = %d, state = %s, waiting = %v, pendingSnapshot = %d", pr.Next, pr.Match, pr.State, pr.IsPaused(), pr.PendingSnapshot) -} - -type inflights struct { - // the starting index in the buffer - start int - // number of inflights in the buffer - count int - - // the size of the buffer - size int - - // buffer contains the index of the last entry - // inside one message. - buffer []uint64 -} - -func newInflights(size int) *inflights { - return &inflights{ - size: size, - } -} - -// add adds an inflight into inflights -func (in *inflights) add(inflight uint64) { - if in.full() { - panic("cannot add into a full inflights") - } - next := in.start + in.count - size := in.size - if next >= size { - next -= size - } - if next >= len(in.buffer) { - in.growBuf() - } - in.buffer[next] = inflight - in.count++ -} - -// grow the inflight buffer by doubling up to inflights.size. We grow on demand -// instead of preallocating to inflights.size to handle systems which have -// thousands of Raft groups per process. -func (in *inflights) growBuf() { - newSize := len(in.buffer) * 2 - if newSize == 0 { - newSize = 1 - } else if newSize > in.size { - newSize = in.size - } - newBuffer := make([]uint64, newSize) - copy(newBuffer, in.buffer) - in.buffer = newBuffer -} - -// freeTo frees the inflights smaller or equal to the given `to` flight. -func (in *inflights) freeTo(to uint64) { - if in.count == 0 || to < in.buffer[in.start] { - // out of the left side of the window - return - } - - idx := in.start - var i int - for i = 0; i < in.count; i++ { - if to < in.buffer[idx] { // found the first large inflight - break - } - - // increase index and maybe rotate - size := in.size - if idx++; idx >= size { - idx -= size - } - } - // free i inflights and set new start index - in.count -= i - in.start = idx - if in.count == 0 { - // inflights is empty, reset the start index so that we don't grow the - // buffer unnecessarily. - in.start = 0 - } -} - -func (in *inflights) freeFirstOne() { in.freeTo(in.buffer[in.start]) } - -// full returns true if the inflights is full. -func (in *inflights) full() bool { - return in.count == in.size -} - -// resets frees all inflights. -func (in *inflights) reset() { - in.count = 0 - in.start = 0 -} diff --git a/vendor/go.etcd.io/etcd/raft/raft.go b/vendor/go.etcd.io/etcd/raft/raft.go deleted file mode 100644 index b4c0f0248ca2..000000000000 --- a/vendor/go.etcd.io/etcd/raft/raft.go +++ /dev/null @@ -1,1406 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "bytes" - "errors" - "fmt" - "math" - "math/rand" - "sort" - "strings" - "sync" - "time" - - pb "github.com/coreos/etcd/raft/raftpb" -) - -// None is a placeholder node ID used when there is no leader. -const None uint64 = 0 -const noLimit = math.MaxUint64 - -// Possible values for StateType. -const ( - StateFollower StateType = iota - StateCandidate - StateLeader - StatePreCandidate - numStates -) - -type ReadOnlyOption int - -const ( - // ReadOnlySafe guarantees the linearizability of the read only request by - // communicating with the quorum. It is the default and suggested option. - ReadOnlySafe ReadOnlyOption = iota - // ReadOnlyLeaseBased ensures linearizability of the read only request by - // relying on the leader lease. It can be affected by clock drift. - // If the clock drift is unbounded, leader might keep the lease longer than it - // should (clock can move backward/pause without any bound). ReadIndex is not safe - // in that case. - ReadOnlyLeaseBased -) - -// Possible values for CampaignType -const ( - // campaignPreElection represents the first phase of a normal election when - // Config.PreVote is true. - campaignPreElection CampaignType = "CampaignPreElection" - // campaignElection represents a normal (time-based) election (the second phase - // of the election when Config.PreVote is true). - campaignElection CampaignType = "CampaignElection" - // campaignTransfer represents the type of leader transfer - campaignTransfer CampaignType = "CampaignTransfer" -) - -// lockedRand is a small wrapper around rand.Rand to provide -// synchronization. Only the methods needed by the code are exposed -// (e.g. Intn). -type lockedRand struct { - mu sync.Mutex - rand *rand.Rand -} - -func (r *lockedRand) Intn(n int) int { - r.mu.Lock() - v := r.rand.Intn(n) - r.mu.Unlock() - return v -} - -var globalRand = &lockedRand{ - rand: rand.New(rand.NewSource(time.Now().UnixNano())), -} - -// CampaignType represents the type of campaigning -// the reason we use the type of string instead of uint64 -// is because it's simpler to compare and fill in raft entries -type CampaignType string - -// StateType represents the role of a node in a cluster. -type StateType uint64 - -var stmap = [...]string{ - "StateFollower", - "StateCandidate", - "StateLeader", - "StatePreCandidate", -} - -func (st StateType) String() string { - return stmap[uint64(st)] -} - -// Config contains the parameters to start a raft. -type Config struct { - // ID is the identity of the local raft. ID cannot be 0. - ID uint64 - - // peers contains the IDs of all nodes (including self) in the raft cluster. It - // should only be set when starting a new raft cluster. Restarting raft from - // previous configuration will panic if peers is set. peer is private and only - // used for testing right now. - peers []uint64 - - // learners contains the IDs of all leaner nodes (including self if the local node is a leaner) in the raft cluster. - // learners only receives entries from the leader node. It does not vote or promote itself. - learners []uint64 - - // ElectionTick is the number of Node.Tick invocations that must pass between - // elections. That is, if a follower does not receive any message from the - // leader of current term before ElectionTick has elapsed, it will become - // candidate and start an election. ElectionTick must be greater than - // HeartbeatTick. We suggest ElectionTick = 10 * HeartbeatTick to avoid - // unnecessary leader switching. - ElectionTick int - // HeartbeatTick is the number of Node.Tick invocations that must pass between - // heartbeats. That is, a leader sends heartbeat messages to maintain its - // leadership every HeartbeatTick ticks. - HeartbeatTick int - - // Storage is the storage for raft. raft generates entries and states to be - // stored in storage. raft reads the persisted entries and states out of - // Storage when it needs. raft reads out the previous state and configuration - // out of storage when restarting. - Storage Storage - // Applied is the last applied index. It should only be set when restarting - // raft. raft will not return entries to the application smaller or equal to - // Applied. If Applied is unset when restarting, raft might return previous - // applied entries. This is a very application dependent configuration. - Applied uint64 - - // MaxSizePerMsg limits the max size of each append message. Smaller value - // lowers the raft recovery cost(initial probing and message lost during normal - // operation). On the other side, it might affect the throughput during normal - // replication. Note: math.MaxUint64 for unlimited, 0 for at most one entry per - // message. - MaxSizePerMsg uint64 - // MaxInflightMsgs limits the max number of in-flight append messages during - // optimistic replication phase. The application transportation layer usually - // has its own sending buffer over TCP/UDP. Setting MaxInflightMsgs to avoid - // overflowing that sending buffer. TODO (xiangli): feedback to application to - // limit the proposal rate? - MaxInflightMsgs int - - // CheckQuorum specifies if the leader should check quorum activity. Leader - // steps down when quorum is not active for an electionTimeout. - CheckQuorum bool - - // PreVote enables the Pre-Vote algorithm described in raft thesis section - // 9.6. This prevents disruption when a node that has been partitioned away - // rejoins the cluster. - PreVote bool - - // ReadOnlyOption specifies how the read only request is processed. - // - // ReadOnlySafe guarantees the linearizability of the read only request by - // communicating with the quorum. It is the default and suggested option. - // - // ReadOnlyLeaseBased ensures linearizability of the read only request by - // relying on the leader lease. It can be affected by clock drift. - // If the clock drift is unbounded, leader might keep the lease longer than it - // should (clock can move backward/pause without any bound). ReadIndex is not safe - // in that case. - // CheckQuorum MUST be enabled if ReadOnlyOption is ReadOnlyLeaseBased. - ReadOnlyOption ReadOnlyOption - - // Logger is the logger used for raft log. For multinode which can host - // multiple raft group, each raft group can have its own logger - Logger Logger - - // DisableProposalForwarding set to true means that followers will drop - // proposals, rather than forwarding them to the leader. One use case for - // this feature would be in a situation where the Raft leader is used to - // compute the data of a proposal, for example, adding a timestamp from a - // hybrid logical clock to data in a monotonically increasing way. Forwarding - // should be disabled to prevent a follower with an innaccurate hybrid - // logical clock from assigning the timestamp and then forwarding the data - // to the leader. - DisableProposalForwarding bool -} - -func (c *Config) validate() error { - if c.ID == None { - return errors.New("cannot use none as id") - } - - if c.HeartbeatTick <= 0 { - return errors.New("heartbeat tick must be greater than 0") - } - - if c.ElectionTick <= c.HeartbeatTick { - return errors.New("election tick must be greater than heartbeat tick") - } - - if c.Storage == nil { - return errors.New("storage cannot be nil") - } - - if c.MaxInflightMsgs <= 0 { - return errors.New("max inflight messages must be greater than 0") - } - - if c.Logger == nil { - c.Logger = raftLogger - } - - if c.ReadOnlyOption == ReadOnlyLeaseBased && !c.CheckQuorum { - return errors.New("CheckQuorum must be enabled when ReadOnlyOption is ReadOnlyLeaseBased") - } - - return nil -} - -type raft struct { - id uint64 - - Term uint64 - Vote uint64 - - readStates []ReadState - - // the log - raftLog *raftLog - - maxInflight int - maxMsgSize uint64 - prs map[uint64]*Progress - learnerPrs map[uint64]*Progress - - state StateType - - // isLearner is true if the local raft node is a learner. - isLearner bool - - votes map[uint64]bool - - msgs []pb.Message - - // the leader id - lead uint64 - // leadTransferee is id of the leader transfer target when its value is not zero. - // Follow the procedure defined in raft thesis 3.10. - leadTransferee uint64 - // New configuration is ignored if there exists unapplied configuration. - pendingConf bool - - readOnly *readOnly - - // number of ticks since it reached last electionTimeout when it is leader - // or candidate. - // number of ticks since it reached last electionTimeout or received a - // valid message from current leader when it is a follower. - electionElapsed int - - // number of ticks since it reached last heartbeatTimeout. - // only leader keeps heartbeatElapsed. - heartbeatElapsed int - - checkQuorum bool - preVote bool - - heartbeatTimeout int - electionTimeout int - // randomizedElectionTimeout is a random number between - // [electiontimeout, 2 * electiontimeout - 1]. It gets reset - // when raft changes its state to follower or candidate. - randomizedElectionTimeout int - disableProposalForwarding bool - - tick func() - step stepFunc - - logger Logger -} - -func newRaft(c *Config) *raft { - if err := c.validate(); err != nil { - panic(err.Error()) - } - raftlog := newLog(c.Storage, c.Logger) - hs, cs, err := c.Storage.InitialState() - if err != nil { - panic(err) // TODO(bdarnell) - } - peers := c.peers - learners := c.learners - if len(cs.Nodes) > 0 || len(cs.Learners) > 0 { - if len(peers) > 0 || len(learners) > 0 { - // TODO(bdarnell): the peers argument is always nil except in - // tests; the argument should be removed and these tests should be - // updated to specify their nodes through a snapshot. - panic("cannot specify both newRaft(peers, learners) and ConfState.(Nodes, Learners)") - } - peers = cs.Nodes - learners = cs.Learners - } - r := &raft{ - id: c.ID, - lead: None, - isLearner: false, - raftLog: raftlog, - maxMsgSize: c.MaxSizePerMsg, - maxInflight: c.MaxInflightMsgs, - prs: make(map[uint64]*Progress), - learnerPrs: make(map[uint64]*Progress), - electionTimeout: c.ElectionTick, - heartbeatTimeout: c.HeartbeatTick, - logger: c.Logger, - checkQuorum: c.CheckQuorum, - preVote: c.PreVote, - readOnly: newReadOnly(c.ReadOnlyOption), - disableProposalForwarding: c.DisableProposalForwarding, - } - for _, p := range peers { - r.prs[p] = &Progress{Next: 1, ins: newInflights(r.maxInflight)} - } - for _, p := range learners { - if _, ok := r.prs[p]; ok { - panic(fmt.Sprintf("node %x is in both learner and peer list", p)) - } - r.learnerPrs[p] = &Progress{Next: 1, ins: newInflights(r.maxInflight), IsLearner: true} - if r.id == p { - r.isLearner = true - } - } - - if !isHardStateEqual(hs, emptyState) { - r.loadState(hs) - } - if c.Applied > 0 { - raftlog.appliedTo(c.Applied) - } - r.becomeFollower(r.Term, None) - - var nodesStrs []string - for _, n := range r.nodes() { - nodesStrs = append(nodesStrs, fmt.Sprintf("%x", n)) - } - - r.logger.Infof("newRaft %x [peers: [%s], term: %d, commit: %d, applied: %d, lastindex: %d, lastterm: %d]", - r.id, strings.Join(nodesStrs, ","), r.Term, r.raftLog.committed, r.raftLog.applied, r.raftLog.lastIndex(), r.raftLog.lastTerm()) - return r -} - -func (r *raft) hasLeader() bool { return r.lead != None } - -func (r *raft) softState() *SoftState { return &SoftState{Lead: r.lead, RaftState: r.state} } - -func (r *raft) hardState() pb.HardState { - return pb.HardState{ - Term: r.Term, - Vote: r.Vote, - Commit: r.raftLog.committed, - } -} - -func (r *raft) quorum() int { return len(r.prs)/2 + 1 } - -func (r *raft) nodes() []uint64 { - nodes := make([]uint64, 0, len(r.prs)+len(r.learnerPrs)) - for id := range r.prs { - nodes = append(nodes, id) - } - for id := range r.learnerPrs { - nodes = append(nodes, id) - } - sort.Sort(uint64Slice(nodes)) - return nodes -} - -// send persists state to stable storage and then sends to its mailbox. -func (r *raft) send(m pb.Message) { - m.From = r.id - if m.Type == pb.MsgVote || m.Type == pb.MsgVoteResp || m.Type == pb.MsgPreVote || m.Type == pb.MsgPreVoteResp { - if m.Term == 0 { - // All {pre-,}campaign messages need to have the term set when - // sending. - // - MsgVote: m.Term is the term the node is campaigning for, - // non-zero as we increment the term when campaigning. - // - MsgVoteResp: m.Term is the new r.Term if the MsgVote was - // granted, non-zero for the same reason MsgVote is - // - MsgPreVote: m.Term is the term the node will campaign, - // non-zero as we use m.Term to indicate the next term we'll be - // campaigning for - // - MsgPreVoteResp: m.Term is the term received in the original - // MsgPreVote if the pre-vote was granted, non-zero for the - // same reasons MsgPreVote is - panic(fmt.Sprintf("term should be set when sending %s", m.Type)) - } - } else { - if m.Term != 0 { - panic(fmt.Sprintf("term should not be set when sending %s (was %d)", m.Type, m.Term)) - } - // do not attach term to MsgProp, MsgReadIndex - // proposals are a way to forward to the leader and - // should be treated as local message. - // MsgReadIndex is also forwarded to leader. - if m.Type != pb.MsgProp && m.Type != pb.MsgReadIndex { - m.Term = r.Term - } - } - r.msgs = append(r.msgs, m) -} - -func (r *raft) getProgress(id uint64) *Progress { - if pr, ok := r.prs[id]; ok { - return pr - } - - return r.learnerPrs[id] -} - -// sendAppend sends RPC, with entries to the given peer. -func (r *raft) sendAppend(to uint64) { - pr := r.getProgress(to) - if pr.IsPaused() { - return - } - m := pb.Message{} - m.To = to - - term, errt := r.raftLog.term(pr.Next - 1) - ents, erre := r.raftLog.entries(pr.Next, r.maxMsgSize) - - if errt != nil || erre != nil { // send snapshot if we failed to get term or entries - if !pr.RecentActive { - r.logger.Debugf("ignore sending snapshot to %x since it is not recently active", to) - return - } - - m.Type = pb.MsgSnap - snapshot, err := r.raftLog.snapshot() - if err != nil { - if err == ErrSnapshotTemporarilyUnavailable { - r.logger.Debugf("%x failed to send snapshot to %x because snapshot is temporarily unavailable", r.id, to) - return - } - panic(err) // TODO(bdarnell) - } - if IsEmptySnap(snapshot) { - panic("need non-empty snapshot") - } - m.Snapshot = snapshot - sindex, sterm := snapshot.Metadata.Index, snapshot.Metadata.Term - r.logger.Debugf("%x [firstindex: %d, commit: %d] sent snapshot[index: %d, term: %d] to %x [%s]", - r.id, r.raftLog.firstIndex(), r.raftLog.committed, sindex, sterm, to, pr) - pr.becomeSnapshot(sindex) - r.logger.Debugf("%x paused sending replication messages to %x [%s]", r.id, to, pr) - } else { - m.Type = pb.MsgApp - m.Index = pr.Next - 1 - m.LogTerm = term - m.Entries = ents - m.Commit = r.raftLog.committed - if n := len(m.Entries); n != 0 { - switch pr.State { - // optimistically increase the next when in ProgressStateReplicate - case ProgressStateReplicate: - last := m.Entries[n-1].Index - pr.optimisticUpdate(last) - pr.ins.add(last) - case ProgressStateProbe: - pr.pause() - default: - r.logger.Panicf("%x is sending append in unhandled state %s", r.id, pr.State) - } - } - } - r.send(m) -} - -// sendHeartbeat sends an empty MsgApp -func (r *raft) sendHeartbeat(to uint64, ctx []byte) { - // Attach the commit as min(to.matched, r.committed). - // When the leader sends out heartbeat message, - // the receiver(follower) might not be matched with the leader - // or it might not have all the committed entries. - // The leader MUST NOT forward the follower's commit to - // an unmatched index. - commit := min(r.getProgress(to).Match, r.raftLog.committed) - m := pb.Message{ - To: to, - Type: pb.MsgHeartbeat, - Commit: commit, - Context: ctx, - } - - r.send(m) -} - -func (r *raft) forEachProgress(f func(id uint64, pr *Progress)) { - for id, pr := range r.prs { - f(id, pr) - } - - for id, pr := range r.learnerPrs { - f(id, pr) - } -} - -// bcastAppend sends RPC, with entries to all peers that are not up-to-date -// according to the progress recorded in r.prs. -func (r *raft) bcastAppend() { - r.forEachProgress(func(id uint64, _ *Progress) { - if id == r.id { - return - } - - r.sendAppend(id) - }) -} - -// bcastHeartbeat sends RPC, without entries to all the peers. -func (r *raft) bcastHeartbeat() { - lastCtx := r.readOnly.lastPendingRequestCtx() - if len(lastCtx) == 0 { - r.bcastHeartbeatWithCtx(nil) - } else { - r.bcastHeartbeatWithCtx([]byte(lastCtx)) - } -} - -func (r *raft) bcastHeartbeatWithCtx(ctx []byte) { - r.forEachProgress(func(id uint64, _ *Progress) { - if id == r.id { - return - } - r.sendHeartbeat(id, ctx) - }) -} - -// maybeCommit attempts to advance the commit index. Returns true if -// the commit index changed (in which case the caller should call -// r.bcastAppend). -func (r *raft) maybeCommit() bool { - // TODO(bmizerany): optimize.. Currently naive - mis := make(uint64Slice, 0, len(r.prs)) - for _, p := range r.prs { - mis = append(mis, p.Match) - } - sort.Sort(sort.Reverse(mis)) - mci := mis[r.quorum()-1] - return r.raftLog.maybeCommit(mci, r.Term) -} - -func (r *raft) reset(term uint64) { - if r.Term != term { - r.Term = term - r.Vote = None - } - r.lead = None - - r.electionElapsed = 0 - r.heartbeatElapsed = 0 - r.resetRandomizedElectionTimeout() - - r.abortLeaderTransfer() - - r.votes = make(map[uint64]bool) - r.forEachProgress(func(id uint64, pr *Progress) { - *pr = Progress{Next: r.raftLog.lastIndex() + 1, ins: newInflights(r.maxInflight), IsLearner: pr.IsLearner} - if id == r.id { - pr.Match = r.raftLog.lastIndex() - } - }) - - r.pendingConf = false - r.readOnly = newReadOnly(r.readOnly.option) -} - -func (r *raft) appendEntry(es ...pb.Entry) { - li := r.raftLog.lastIndex() - for i := range es { - es[i].Term = r.Term - es[i].Index = li + 1 + uint64(i) - } - r.raftLog.append(es...) - r.getProgress(r.id).maybeUpdate(r.raftLog.lastIndex()) - // Regardless of maybeCommit's return, our caller will call bcastAppend. - r.maybeCommit() -} - -// tickElection is run by followers and candidates after r.electionTimeout. -func (r *raft) tickElection() { - r.electionElapsed++ - - if r.promotable() && r.pastElectionTimeout() { - r.electionElapsed = 0 - r.Step(pb.Message{From: r.id, Type: pb.MsgHup}) - } -} - -// tickHeartbeat is run by leaders to send a MsgBeat after r.heartbeatTimeout. -func (r *raft) tickHeartbeat() { - r.heartbeatElapsed++ - r.electionElapsed++ - - if r.electionElapsed >= r.electionTimeout { - r.electionElapsed = 0 - if r.checkQuorum { - r.Step(pb.Message{From: r.id, Type: pb.MsgCheckQuorum}) - } - // If current leader cannot transfer leadership in electionTimeout, it becomes leader again. - if r.state == StateLeader && r.leadTransferee != None { - r.abortLeaderTransfer() - } - } - - if r.state != StateLeader { - return - } - - if r.heartbeatElapsed >= r.heartbeatTimeout { - r.heartbeatElapsed = 0 - r.Step(pb.Message{From: r.id, Type: pb.MsgBeat}) - } -} - -func (r *raft) becomeFollower(term uint64, lead uint64) { - r.step = stepFollower - r.reset(term) - r.tick = r.tickElection - r.lead = lead - r.state = StateFollower - r.logger.Infof("%x became follower at term %d", r.id, r.Term) -} - -func (r *raft) becomeCandidate() { - // TODO(xiangli) remove the panic when the raft implementation is stable - if r.state == StateLeader { - panic("invalid transition [leader -> candidate]") - } - r.step = stepCandidate - r.reset(r.Term + 1) - r.tick = r.tickElection - r.Vote = r.id - r.state = StateCandidate - r.logger.Infof("%x became candidate at term %d", r.id, r.Term) -} - -func (r *raft) becomePreCandidate() { - // TODO(xiangli) remove the panic when the raft implementation is stable - if r.state == StateLeader { - panic("invalid transition [leader -> pre-candidate]") - } - // Becoming a pre-candidate changes our step functions and state, - // but doesn't change anything else. In particular it does not increase - // r.Term or change r.Vote. - r.step = stepCandidate - r.votes = make(map[uint64]bool) - r.tick = r.tickElection - r.state = StatePreCandidate - r.logger.Infof("%x became pre-candidate at term %d", r.id, r.Term) -} - -func (r *raft) becomeLeader() { - // TODO(xiangli) remove the panic when the raft implementation is stable - if r.state == StateFollower { - panic("invalid transition [follower -> leader]") - } - r.step = stepLeader - r.reset(r.Term) - r.tick = r.tickHeartbeat - r.lead = r.id - r.state = StateLeader - ents, err := r.raftLog.entries(r.raftLog.committed+1, noLimit) - if err != nil { - r.logger.Panicf("unexpected error getting uncommitted entries (%v)", err) - } - - nconf := numOfPendingConf(ents) - if nconf > 1 { - panic("unexpected multiple uncommitted config entry") - } - if nconf == 1 { - r.pendingConf = true - } - - r.appendEntry(pb.Entry{Data: nil}) - r.logger.Infof("%x became leader at term %d", r.id, r.Term) -} - -func (r *raft) campaign(t CampaignType) { - var term uint64 - var voteMsg pb.MessageType - if t == campaignPreElection { - r.becomePreCandidate() - voteMsg = pb.MsgPreVote - // PreVote RPCs are sent for the next term before we've incremented r.Term. - term = r.Term + 1 - } else { - r.becomeCandidate() - voteMsg = pb.MsgVote - term = r.Term - } - if r.quorum() == r.poll(r.id, voteRespMsgType(voteMsg), true) { - // We won the election after voting for ourselves (which must mean that - // this is a single-node cluster). Advance to the next state. - if t == campaignPreElection { - r.campaign(campaignElection) - } else { - r.becomeLeader() - } - return - } - for id := range r.prs { - if id == r.id { - continue - } - r.logger.Infof("%x [logterm: %d, index: %d] sent %s request to %x at term %d", - r.id, r.raftLog.lastTerm(), r.raftLog.lastIndex(), voteMsg, id, r.Term) - - var ctx []byte - if t == campaignTransfer { - ctx = []byte(t) - } - r.send(pb.Message{Term: term, To: id, Type: voteMsg, Index: r.raftLog.lastIndex(), LogTerm: r.raftLog.lastTerm(), Context: ctx}) - } -} - -func (r *raft) poll(id uint64, t pb.MessageType, v bool) (granted int) { - if v { - r.logger.Infof("%x received %s from %x at term %d", r.id, t, id, r.Term) - } else { - r.logger.Infof("%x received %s rejection from %x at term %d", r.id, t, id, r.Term) - } - if _, ok := r.votes[id]; !ok { - r.votes[id] = v - } - for _, vv := range r.votes { - if vv { - granted++ - } - } - return granted -} - -func (r *raft) Step(m pb.Message) error { - // Handle the message term, which may result in our stepping down to a follower. - switch { - case m.Term == 0: - // local message - case m.Term > r.Term: - if m.Type == pb.MsgVote || m.Type == pb.MsgPreVote { - force := bytes.Equal(m.Context, []byte(campaignTransfer)) - inLease := r.checkQuorum && r.lead != None && r.electionElapsed < r.electionTimeout - if !force && inLease { - // If a server receives a RequestVote request within the minimum election timeout - // of hearing from a current leader, it does not update its term or grant its vote - r.logger.Infof("%x [logterm: %d, index: %d, vote: %x] ignored %s from %x [logterm: %d, index: %d] at term %d: lease is not expired (remaining ticks: %d)", - r.id, r.raftLog.lastTerm(), r.raftLog.lastIndex(), r.Vote, m.Type, m.From, m.LogTerm, m.Index, r.Term, r.electionTimeout-r.electionElapsed) - return nil - } - } - switch { - case m.Type == pb.MsgPreVote: - // Never change our term in response to a PreVote - case m.Type == pb.MsgPreVoteResp && !m.Reject: - // We send pre-vote requests with a term in our future. If the - // pre-vote is granted, we will increment our term when we get a - // quorum. If it is not, the term comes from the node that - // rejected our vote so we should become a follower at the new - // term. - default: - r.logger.Infof("%x [term: %d] received a %s message with higher term from %x [term: %d]", - r.id, r.Term, m.Type, m.From, m.Term) - if m.Type == pb.MsgApp || m.Type == pb.MsgHeartbeat || m.Type == pb.MsgSnap { - r.becomeFollower(m.Term, m.From) - } else { - r.becomeFollower(m.Term, None) - } - } - - case m.Term < r.Term: - if r.checkQuorum && (m.Type == pb.MsgHeartbeat || m.Type == pb.MsgApp) { - // We have received messages from a leader at a lower term. It is possible - // that these messages were simply delayed in the network, but this could - // also mean that this node has advanced its term number during a network - // partition, and it is now unable to either win an election or to rejoin - // the majority on the old term. If checkQuorum is false, this will be - // handled by incrementing term numbers in response to MsgVote with a - // higher term, but if checkQuorum is true we may not advance the term on - // MsgVote and must generate other messages to advance the term. The net - // result of these two features is to minimize the disruption caused by - // nodes that have been removed from the cluster's configuration: a - // removed node will send MsgVotes (or MsgPreVotes) which will be ignored, - // but it will not receive MsgApp or MsgHeartbeat, so it will not create - // disruptive term increases - r.send(pb.Message{To: m.From, Type: pb.MsgAppResp}) - } else { - // ignore other cases - r.logger.Infof("%x [term: %d] ignored a %s message with lower term from %x [term: %d]", - r.id, r.Term, m.Type, m.From, m.Term) - } - return nil - } - - switch m.Type { - case pb.MsgHup: - if r.state != StateLeader { - ents, err := r.raftLog.slice(r.raftLog.applied+1, r.raftLog.committed+1, noLimit) - if err != nil { - r.logger.Panicf("unexpected error getting unapplied entries (%v)", err) - } - if n := numOfPendingConf(ents); n != 0 && r.raftLog.committed > r.raftLog.applied { - r.logger.Warningf("%x cannot campaign at term %d since there are still %d pending configuration changes to apply", r.id, r.Term, n) - return nil - } - - r.logger.Infof("%x is starting a new election at term %d", r.id, r.Term) - if r.preVote { - r.campaign(campaignPreElection) - } else { - r.campaign(campaignElection) - } - } else { - r.logger.Debugf("%x ignoring MsgHup because already leader", r.id) - } - - case pb.MsgVote, pb.MsgPreVote: - if r.isLearner { - // TODO: learner may need to vote, in case of node down when confchange. - r.logger.Infof("%x [logterm: %d, index: %d, vote: %x] ignored %s from %x [logterm: %d, index: %d] at term %d: learner can not vote", - r.id, r.raftLog.lastTerm(), r.raftLog.lastIndex(), r.Vote, m.Type, m.From, m.LogTerm, m.Index, r.Term) - return nil - } - // The m.Term > r.Term clause is for MsgPreVote. For MsgVote m.Term should - // always equal r.Term. - if (r.Vote == None || m.Term > r.Term || r.Vote == m.From) && r.raftLog.isUpToDate(m.Index, m.LogTerm) { - r.logger.Infof("%x [logterm: %d, index: %d, vote: %x] cast %s for %x [logterm: %d, index: %d] at term %d", - r.id, r.raftLog.lastTerm(), r.raftLog.lastIndex(), r.Vote, m.Type, m.From, m.LogTerm, m.Index, r.Term) - // When responding to Msg{Pre,}Vote messages we include the term - // from the message, not the local term. To see why consider the - // case where a single node was previously partitioned away and - // it's local term is now of date. If we include the local term - // (recall that for pre-votes we don't update the local term), the - // (pre-)campaigning node on the other end will proceed to ignore - // the message (it ignores all out of date messages). - // The term in the original message and current local term are the - // same in the case of regular votes, but different for pre-votes. - r.send(pb.Message{To: m.From, Term: m.Term, Type: voteRespMsgType(m.Type)}) - if m.Type == pb.MsgVote { - // Only record real votes. - r.electionElapsed = 0 - r.Vote = m.From - } - } else { - r.logger.Infof("%x [logterm: %d, index: %d, vote: %x] rejected %s from %x [logterm: %d, index: %d] at term %d", - r.id, r.raftLog.lastTerm(), r.raftLog.lastIndex(), r.Vote, m.Type, m.From, m.LogTerm, m.Index, r.Term) - r.send(pb.Message{To: m.From, Term: r.Term, Type: voteRespMsgType(m.Type), Reject: true}) - } - - default: - r.step(r, m) - } - return nil -} - -type stepFunc func(r *raft, m pb.Message) - -func stepLeader(r *raft, m pb.Message) { - // These message types do not require any progress for m.From. - switch m.Type { - case pb.MsgBeat: - r.bcastHeartbeat() - return - case pb.MsgCheckQuorum: - if !r.checkQuorumActive() { - r.logger.Warningf("%x stepped down to follower since quorum is not active", r.id) - r.becomeFollower(r.Term, None) - } - return - case pb.MsgProp: - if len(m.Entries) == 0 { - r.logger.Panicf("%x stepped empty MsgProp", r.id) - } - if _, ok := r.prs[r.id]; !ok { - // If we are not currently a member of the range (i.e. this node - // was removed from the configuration while serving as leader), - // drop any new proposals. - return - } - if r.leadTransferee != None { - r.logger.Debugf("%x [term %d] transfer leadership to %x is in progress; dropping proposal", r.id, r.Term, r.leadTransferee) - return - } - - for i, e := range m.Entries { - if e.Type == pb.EntryConfChange { - if r.pendingConf { - r.logger.Infof("propose conf %s ignored since pending unapplied configuration", e.String()) - m.Entries[i] = pb.Entry{Type: pb.EntryNormal} - } - r.pendingConf = true - } - } - r.appendEntry(m.Entries...) - r.bcastAppend() - return - case pb.MsgReadIndex: - if r.quorum() > 1 { - if r.raftLog.zeroTermOnErrCompacted(r.raftLog.term(r.raftLog.committed)) != r.Term { - // Reject read only request when this leader has not committed any log entry at its term. - return - } - - // thinking: use an interally defined context instead of the user given context. - // We can express this in terms of the term and index instead of a user-supplied value. - // This would allow multiple reads to piggyback on the same message. - switch r.readOnly.option { - case ReadOnlySafe: - r.readOnly.addRequest(r.raftLog.committed, m) - r.bcastHeartbeatWithCtx(m.Entries[0].Data) - case ReadOnlyLeaseBased: - ri := r.raftLog.committed - if m.From == None || m.From == r.id { // from local member - r.readStates = append(r.readStates, ReadState{Index: r.raftLog.committed, RequestCtx: m.Entries[0].Data}) - } else { - r.send(pb.Message{To: m.From, Type: pb.MsgReadIndexResp, Index: ri, Entries: m.Entries}) - } - } - } else { - r.readStates = append(r.readStates, ReadState{Index: r.raftLog.committed, RequestCtx: m.Entries[0].Data}) - } - - return - } - - // All other message types require a progress for m.From (pr). - pr := r.getProgress(m.From) - if pr == nil { - r.logger.Debugf("%x no progress available for %x", r.id, m.From) - return - } - switch m.Type { - case pb.MsgAppResp: - pr.RecentActive = true - - if m.Reject { - r.logger.Debugf("%x received msgApp rejection(lastindex: %d) from %x for index %d", - r.id, m.RejectHint, m.From, m.Index) - if pr.maybeDecrTo(m.Index, m.RejectHint) { - r.logger.Debugf("%x decreased progress of %x to [%s]", r.id, m.From, pr) - if pr.State == ProgressStateReplicate { - pr.becomeProbe() - } - r.sendAppend(m.From) - } - } else { - oldPaused := pr.IsPaused() - if pr.maybeUpdate(m.Index) { - switch { - case pr.State == ProgressStateProbe: - pr.becomeReplicate() - case pr.State == ProgressStateSnapshot && pr.needSnapshotAbort(): - r.logger.Debugf("%x snapshot aborted, resumed sending replication messages to %x [%s]", r.id, m.From, pr) - pr.becomeProbe() - case pr.State == ProgressStateReplicate: - pr.ins.freeTo(m.Index) - } - - if r.maybeCommit() { - r.bcastAppend() - } else if oldPaused { - // update() reset the wait state on this node. If we had delayed sending - // an update before, send it now. - r.sendAppend(m.From) - } - // Transfer leadership is in progress. - if m.From == r.leadTransferee && pr.Match == r.raftLog.lastIndex() { - r.logger.Infof("%x sent MsgTimeoutNow to %x after received MsgAppResp", r.id, m.From) - r.sendTimeoutNow(m.From) - } - } - } - case pb.MsgHeartbeatResp: - pr.RecentActive = true - pr.resume() - - // free one slot for the full inflights window to allow progress. - if pr.State == ProgressStateReplicate && pr.ins.full() { - pr.ins.freeFirstOne() - } - if pr.Match < r.raftLog.lastIndex() { - r.sendAppend(m.From) - } - - if r.readOnly.option != ReadOnlySafe || len(m.Context) == 0 { - return - } - - ackCount := r.readOnly.recvAck(m) - if ackCount < r.quorum() { - return - } - - rss := r.readOnly.advance(m) - for _, rs := range rss { - req := rs.req - if req.From == None || req.From == r.id { // from local member - r.readStates = append(r.readStates, ReadState{Index: rs.index, RequestCtx: req.Entries[0].Data}) - } else { - r.send(pb.Message{To: req.From, Type: pb.MsgReadIndexResp, Index: rs.index, Entries: req.Entries}) - } - } - case pb.MsgSnapStatus: - if pr.State != ProgressStateSnapshot { - return - } - if !m.Reject { - pr.becomeProbe() - r.logger.Debugf("%x snapshot succeeded, resumed sending replication messages to %x [%s]", r.id, m.From, pr) - } else { - pr.snapshotFailure() - pr.becomeProbe() - r.logger.Debugf("%x snapshot failed, resumed sending replication messages to %x [%s]", r.id, m.From, pr) - } - // If snapshot finish, wait for the msgAppResp from the remote node before sending - // out the next msgApp. - // If snapshot failure, wait for a heartbeat interval before next try - pr.pause() - case pb.MsgUnreachable: - // During optimistic replication, if the remote becomes unreachable, - // there is huge probability that a MsgApp is lost. - if pr.State == ProgressStateReplicate { - pr.becomeProbe() - } - r.logger.Debugf("%x failed to send message to %x because it is unreachable [%s]", r.id, m.From, pr) - case pb.MsgTransferLeader: - if pr.IsLearner { - r.logger.Debugf("%x is learner. Ignored transferring leadership", r.id) - return - } - leadTransferee := m.From - lastLeadTransferee := r.leadTransferee - if lastLeadTransferee != None { - if lastLeadTransferee == leadTransferee { - r.logger.Infof("%x [term %d] transfer leadership to %x is in progress, ignores request to same node %x", - r.id, r.Term, leadTransferee, leadTransferee) - return - } - r.abortLeaderTransfer() - r.logger.Infof("%x [term %d] abort previous transferring leadership to %x", r.id, r.Term, lastLeadTransferee) - } - if leadTransferee == r.id { - r.logger.Debugf("%x is already leader. Ignored transferring leadership to self", r.id) - return - } - // Transfer leadership to third party. - r.logger.Infof("%x [term %d] starts to transfer leadership to %x", r.id, r.Term, leadTransferee) - // Transfer leadership should be finished in one electionTimeout, so reset r.electionElapsed. - r.electionElapsed = 0 - r.leadTransferee = leadTransferee - if pr.Match == r.raftLog.lastIndex() { - r.sendTimeoutNow(leadTransferee) - r.logger.Infof("%x sends MsgTimeoutNow to %x immediately as %x already has up-to-date log", r.id, leadTransferee, leadTransferee) - } else { - r.sendAppend(leadTransferee) - } - } -} - -// stepCandidate is shared by StateCandidate and StatePreCandidate; the difference is -// whether they respond to MsgVoteResp or MsgPreVoteResp. -func stepCandidate(r *raft, m pb.Message) { - // Only handle vote responses corresponding to our candidacy (while in - // StateCandidate, we may get stale MsgPreVoteResp messages in this term from - // our pre-candidate state). - var myVoteRespType pb.MessageType - if r.state == StatePreCandidate { - myVoteRespType = pb.MsgPreVoteResp - } else { - myVoteRespType = pb.MsgVoteResp - } - switch m.Type { - case pb.MsgProp: - r.logger.Infof("%x no leader at term %d; dropping proposal", r.id, r.Term) - return - case pb.MsgApp: - r.becomeFollower(r.Term, m.From) - r.handleAppendEntries(m) - case pb.MsgHeartbeat: - r.becomeFollower(r.Term, m.From) - r.handleHeartbeat(m) - case pb.MsgSnap: - r.becomeFollower(m.Term, m.From) - r.handleSnapshot(m) - case myVoteRespType: - gr := r.poll(m.From, m.Type, !m.Reject) - r.logger.Infof("%x [quorum:%d] has received %d %s votes and %d vote rejections", r.id, r.quorum(), gr, m.Type, len(r.votes)-gr) - switch r.quorum() { - case gr: - if r.state == StatePreCandidate { - r.campaign(campaignElection) - } else { - r.becomeLeader() - r.bcastAppend() - } - case len(r.votes) - gr: - r.becomeFollower(r.Term, None) - } - case pb.MsgTimeoutNow: - r.logger.Debugf("%x [term %d state %v] ignored MsgTimeoutNow from %x", r.id, r.Term, r.state, m.From) - } -} - -func stepFollower(r *raft, m pb.Message) { - switch m.Type { - case pb.MsgProp: - if r.lead == None { - r.logger.Infof("%x no leader at term %d; dropping proposal", r.id, r.Term) - return - } else if r.disableProposalForwarding { - r.logger.Infof("%x not forwarding to leader %x at term %d; dropping proposal", r.id, r.lead, r.Term) - return - } - m.To = r.lead - r.send(m) - case pb.MsgApp: - r.electionElapsed = 0 - r.lead = m.From - r.handleAppendEntries(m) - case pb.MsgHeartbeat: - r.electionElapsed = 0 - r.lead = m.From - r.handleHeartbeat(m) - case pb.MsgSnap: - r.electionElapsed = 0 - r.lead = m.From - r.handleSnapshot(m) - case pb.MsgTransferLeader: - if r.lead == None { - r.logger.Infof("%x no leader at term %d; dropping leader transfer msg", r.id, r.Term) - return - } - m.To = r.lead - r.send(m) - case pb.MsgTimeoutNow: - if r.promotable() { - r.logger.Infof("%x [term %d] received MsgTimeoutNow from %x and starts an election to get leadership.", r.id, r.Term, m.From) - // Leadership transfers never use pre-vote even if r.preVote is true; we - // know we are not recovering from a partition so there is no need for the - // extra round trip. - r.campaign(campaignTransfer) - } else { - r.logger.Infof("%x received MsgTimeoutNow from %x but is not promotable", r.id, m.From) - } - case pb.MsgReadIndex: - if r.lead == None { - r.logger.Infof("%x no leader at term %d; dropping index reading msg", r.id, r.Term) - return - } - m.To = r.lead - r.send(m) - case pb.MsgReadIndexResp: - if len(m.Entries) != 1 { - r.logger.Errorf("%x invalid format of MsgReadIndexResp from %x, entries count: %d", r.id, m.From, len(m.Entries)) - return - } - r.readStates = append(r.readStates, ReadState{Index: m.Index, RequestCtx: m.Entries[0].Data}) - } -} - -func (r *raft) handleAppendEntries(m pb.Message) { - if m.Index < r.raftLog.committed { - r.send(pb.Message{To: m.From, Type: pb.MsgAppResp, Index: r.raftLog.committed}) - return - } - - if mlastIndex, ok := r.raftLog.maybeAppend(m.Index, m.LogTerm, m.Commit, m.Entries...); ok { - r.send(pb.Message{To: m.From, Type: pb.MsgAppResp, Index: mlastIndex}) - } else { - r.logger.Debugf("%x [logterm: %d, index: %d] rejected msgApp [logterm: %d, index: %d] from %x", - r.id, r.raftLog.zeroTermOnErrCompacted(r.raftLog.term(m.Index)), m.Index, m.LogTerm, m.Index, m.From) - r.send(pb.Message{To: m.From, Type: pb.MsgAppResp, Index: m.Index, Reject: true, RejectHint: r.raftLog.lastIndex()}) - } -} - -func (r *raft) handleHeartbeat(m pb.Message) { - r.raftLog.commitTo(m.Commit) - r.send(pb.Message{To: m.From, Type: pb.MsgHeartbeatResp, Context: m.Context}) -} - -func (r *raft) handleSnapshot(m pb.Message) { - sindex, sterm := m.Snapshot.Metadata.Index, m.Snapshot.Metadata.Term - if r.restore(m.Snapshot) { - r.logger.Infof("%x [commit: %d] restored snapshot [index: %d, term: %d]", - r.id, r.raftLog.committed, sindex, sterm) - r.send(pb.Message{To: m.From, Type: pb.MsgAppResp, Index: r.raftLog.lastIndex()}) - } else { - r.logger.Infof("%x [commit: %d] ignored snapshot [index: %d, term: %d]", - r.id, r.raftLog.committed, sindex, sterm) - r.send(pb.Message{To: m.From, Type: pb.MsgAppResp, Index: r.raftLog.committed}) - } -} - -// restore recovers the state machine from a snapshot. It restores the log and the -// configuration of state machine. -func (r *raft) restore(s pb.Snapshot) bool { - if s.Metadata.Index <= r.raftLog.committed { - return false - } - if r.raftLog.matchTerm(s.Metadata.Index, s.Metadata.Term) { - r.logger.Infof("%x [commit: %d, lastindex: %d, lastterm: %d] fast-forwarded commit to snapshot [index: %d, term: %d]", - r.id, r.raftLog.committed, r.raftLog.lastIndex(), r.raftLog.lastTerm(), s.Metadata.Index, s.Metadata.Term) - r.raftLog.commitTo(s.Metadata.Index) - return false - } - - // The normal peer can't become learner. - if !r.isLearner { - for _, id := range s.Metadata.ConfState.Learners { - if id == r.id { - r.logger.Errorf("%x can't become learner when restores snapshot [index: %d, term: %d]", r.id, s.Metadata.Index, s.Metadata.Term) - return false - } - } - } - - r.logger.Infof("%x [commit: %d, lastindex: %d, lastterm: %d] starts to restore snapshot [index: %d, term: %d]", - r.id, r.raftLog.committed, r.raftLog.lastIndex(), r.raftLog.lastTerm(), s.Metadata.Index, s.Metadata.Term) - - r.raftLog.restore(s) - r.prs = make(map[uint64]*Progress) - r.learnerPrs = make(map[uint64]*Progress) - r.restoreNode(s.Metadata.ConfState.Nodes, false) - r.restoreNode(s.Metadata.ConfState.Learners, true) - return true -} - -func (r *raft) restoreNode(nodes []uint64, isLearner bool) { - for _, n := range nodes { - match, next := uint64(0), r.raftLog.lastIndex()+1 - if n == r.id { - match = next - 1 - r.isLearner = isLearner - } - r.setProgress(n, match, next, isLearner) - r.logger.Infof("%x restored progress of %x [%s]", r.id, n, r.getProgress(n)) - } -} - -// promotable indicates whether state machine can be promoted to leader, -// which is true when its own id is in progress list. -func (r *raft) promotable() bool { - _, ok := r.prs[r.id] - return ok -} - -func (r *raft) addNode(id uint64) { - r.addNodeOrLearnerNode(id, false) -} - -func (r *raft) addLearner(id uint64) { - r.addNodeOrLearnerNode(id, true) -} - -func (r *raft) addNodeOrLearnerNode(id uint64, isLearner bool) { - r.pendingConf = false - pr := r.getProgress(id) - if pr == nil { - r.setProgress(id, 0, r.raftLog.lastIndex()+1, isLearner) - } else { - if isLearner && !pr.IsLearner { - // can only change Learner to Voter - r.logger.Infof("%x ignored addLeaner: do not support changing %x from raft peer to learner.", r.id, id) - return - } - - if isLearner == pr.IsLearner { - // Ignore any redundant addNode calls (which can happen because the - // initial bootstrapping entries are applied twice). - return - } - - // change Learner to Voter, use origin Learner progress - delete(r.learnerPrs, id) - pr.IsLearner = false - r.prs[id] = pr - } - - if r.id == id { - r.isLearner = isLearner - } - - // When a node is first added, we should mark it as recently active. - // Otherwise, CheckQuorum may cause us to step down if it is invoked - // before the added node has a chance to communicate with us. - pr = r.getProgress(id) - pr.RecentActive = true -} - -func (r *raft) removeNode(id uint64) { - r.delProgress(id) - r.pendingConf = false - - // do not try to commit or abort transferring if there is no nodes in the cluster. - if len(r.prs) == 0 && len(r.learnerPrs) == 0 { - return - } - - // The quorum size is now smaller, so see if any pending entries can - // be committed. - if r.maybeCommit() { - r.bcastAppend() - } - // If the removed node is the leadTransferee, then abort the leadership transferring. - if r.state == StateLeader && r.leadTransferee == id { - r.abortLeaderTransfer() - } -} - -func (r *raft) resetPendingConf() { r.pendingConf = false } - -func (r *raft) setProgress(id, match, next uint64, isLearner bool) { - if !isLearner { - delete(r.learnerPrs, id) - r.prs[id] = &Progress{Next: next, Match: match, ins: newInflights(r.maxInflight)} - return - } - - if _, ok := r.prs[id]; ok { - panic(fmt.Sprintf("%x unexpected changing from voter to learner for %x", r.id, id)) - } - r.learnerPrs[id] = &Progress{Next: next, Match: match, ins: newInflights(r.maxInflight), IsLearner: true} -} - -func (r *raft) delProgress(id uint64) { - delete(r.prs, id) - delete(r.learnerPrs, id) -} - -func (r *raft) loadState(state pb.HardState) { - if state.Commit < r.raftLog.committed || state.Commit > r.raftLog.lastIndex() { - r.logger.Panicf("%x state.commit %d is out of range [%d, %d]", r.id, state.Commit, r.raftLog.committed, r.raftLog.lastIndex()) - } - r.raftLog.committed = state.Commit - r.Term = state.Term - r.Vote = state.Vote -} - -// pastElectionTimeout returns true iff r.electionElapsed is greater -// than or equal to the randomized election timeout in -// [electiontimeout, 2 * electiontimeout - 1]. -func (r *raft) pastElectionTimeout() bool { - return r.electionElapsed >= r.randomizedElectionTimeout -} - -func (r *raft) resetRandomizedElectionTimeout() { - r.randomizedElectionTimeout = r.electionTimeout + globalRand.Intn(r.electionTimeout) -} - -// checkQuorumActive returns true if the quorum is active from -// the view of the local raft state machine. Otherwise, it returns -// false. -// checkQuorumActive also resets all RecentActive to false. -func (r *raft) checkQuorumActive() bool { - var act int - - r.forEachProgress(func(id uint64, pr *Progress) { - if id == r.id { // self is always active - act++ - return - } - - if pr.RecentActive && !pr.IsLearner { - act++ - } - - pr.RecentActive = false - }) - - return act >= r.quorum() -} - -func (r *raft) sendTimeoutNow(to uint64) { - r.send(pb.Message{To: to, Type: pb.MsgTimeoutNow}) -} - -func (r *raft) abortLeaderTransfer() { - r.leadTransferee = None -} - -func numOfPendingConf(ents []pb.Entry) int { - n := 0 - for i := range ents { - if ents[i].Type == pb.EntryConfChange { - n++ - } - } - return n -} diff --git a/vendor/go.etcd.io/etcd/raft/raftpb/raft.pb.go b/vendor/go.etcd.io/etcd/raft/raftpb/raft.pb.go deleted file mode 100644 index fd9ee3729ecb..000000000000 --- a/vendor/go.etcd.io/etcd/raft/raftpb/raft.pb.go +++ /dev/null @@ -1,2004 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: raft.proto - -/* - Package raftpb is a generated protocol buffer package. - - It is generated from these files: - raft.proto - - It has these top-level messages: - Entry - SnapshotMetadata - Snapshot - Message - HardState - ConfState - ConfChange -*/ -package raftpb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type EntryType int32 - -const ( - EntryNormal EntryType = 0 - EntryConfChange EntryType = 1 -) - -var EntryType_name = map[int32]string{ - 0: "EntryNormal", - 1: "EntryConfChange", -} -var EntryType_value = map[string]int32{ - "EntryNormal": 0, - "EntryConfChange": 1, -} - -func (x EntryType) Enum() *EntryType { - p := new(EntryType) - *p = x - return p -} -func (x EntryType) String() string { - return proto.EnumName(EntryType_name, int32(x)) -} -func (x *EntryType) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(EntryType_value, data, "EntryType") - if err != nil { - return err - } - *x = EntryType(value) - return nil -} -func (EntryType) EnumDescriptor() ([]byte, []int) { return fileDescriptorRaft, []int{0} } - -type MessageType int32 - -const ( - MsgHup MessageType = 0 - MsgBeat MessageType = 1 - MsgProp MessageType = 2 - MsgApp MessageType = 3 - MsgAppResp MessageType = 4 - MsgVote MessageType = 5 - MsgVoteResp MessageType = 6 - MsgSnap MessageType = 7 - MsgHeartbeat MessageType = 8 - MsgHeartbeatResp MessageType = 9 - MsgUnreachable MessageType = 10 - MsgSnapStatus MessageType = 11 - MsgCheckQuorum MessageType = 12 - MsgTransferLeader MessageType = 13 - MsgTimeoutNow MessageType = 14 - MsgReadIndex MessageType = 15 - MsgReadIndexResp MessageType = 16 - MsgPreVote MessageType = 17 - MsgPreVoteResp MessageType = 18 -) - -var MessageType_name = map[int32]string{ - 0: "MsgHup", - 1: "MsgBeat", - 2: "MsgProp", - 3: "MsgApp", - 4: "MsgAppResp", - 5: "MsgVote", - 6: "MsgVoteResp", - 7: "MsgSnap", - 8: "MsgHeartbeat", - 9: "MsgHeartbeatResp", - 10: "MsgUnreachable", - 11: "MsgSnapStatus", - 12: "MsgCheckQuorum", - 13: "MsgTransferLeader", - 14: "MsgTimeoutNow", - 15: "MsgReadIndex", - 16: "MsgReadIndexResp", - 17: "MsgPreVote", - 18: "MsgPreVoteResp", -} -var MessageType_value = map[string]int32{ - "MsgHup": 0, - "MsgBeat": 1, - "MsgProp": 2, - "MsgApp": 3, - "MsgAppResp": 4, - "MsgVote": 5, - "MsgVoteResp": 6, - "MsgSnap": 7, - "MsgHeartbeat": 8, - "MsgHeartbeatResp": 9, - "MsgUnreachable": 10, - "MsgSnapStatus": 11, - "MsgCheckQuorum": 12, - "MsgTransferLeader": 13, - "MsgTimeoutNow": 14, - "MsgReadIndex": 15, - "MsgReadIndexResp": 16, - "MsgPreVote": 17, - "MsgPreVoteResp": 18, -} - -func (x MessageType) Enum() *MessageType { - p := new(MessageType) - *p = x - return p -} -func (x MessageType) String() string { - return proto.EnumName(MessageType_name, int32(x)) -} -func (x *MessageType) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(MessageType_value, data, "MessageType") - if err != nil { - return err - } - *x = MessageType(value) - return nil -} -func (MessageType) EnumDescriptor() ([]byte, []int) { return fileDescriptorRaft, []int{1} } - -type ConfChangeType int32 - -const ( - ConfChangeAddNode ConfChangeType = 0 - ConfChangeRemoveNode ConfChangeType = 1 - ConfChangeUpdateNode ConfChangeType = 2 - ConfChangeAddLearnerNode ConfChangeType = 3 -) - -var ConfChangeType_name = map[int32]string{ - 0: "ConfChangeAddNode", - 1: "ConfChangeRemoveNode", - 2: "ConfChangeUpdateNode", - 3: "ConfChangeAddLearnerNode", -} -var ConfChangeType_value = map[string]int32{ - "ConfChangeAddNode": 0, - "ConfChangeRemoveNode": 1, - "ConfChangeUpdateNode": 2, - "ConfChangeAddLearnerNode": 3, -} - -func (x ConfChangeType) Enum() *ConfChangeType { - p := new(ConfChangeType) - *p = x - return p -} -func (x ConfChangeType) String() string { - return proto.EnumName(ConfChangeType_name, int32(x)) -} -func (x *ConfChangeType) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(ConfChangeType_value, data, "ConfChangeType") - if err != nil { - return err - } - *x = ConfChangeType(value) - return nil -} -func (ConfChangeType) EnumDescriptor() ([]byte, []int) { return fileDescriptorRaft, []int{2} } - -type Entry struct { - Term uint64 `protobuf:"varint,2,opt,name=Term" json:"Term"` - Index uint64 `protobuf:"varint,3,opt,name=Index" json:"Index"` - Type EntryType `protobuf:"varint,1,opt,name=Type,enum=raftpb.EntryType" json:"Type"` - Data []byte `protobuf:"bytes,4,opt,name=Data" json:"Data,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Entry) Reset() { *m = Entry{} } -func (m *Entry) String() string { return proto.CompactTextString(m) } -func (*Entry) ProtoMessage() {} -func (*Entry) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{0} } - -type SnapshotMetadata struct { - ConfState ConfState `protobuf:"bytes,1,opt,name=conf_state,json=confState" json:"conf_state"` - Index uint64 `protobuf:"varint,2,opt,name=index" json:"index"` - Term uint64 `protobuf:"varint,3,opt,name=term" json:"term"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *SnapshotMetadata) Reset() { *m = SnapshotMetadata{} } -func (m *SnapshotMetadata) String() string { return proto.CompactTextString(m) } -func (*SnapshotMetadata) ProtoMessage() {} -func (*SnapshotMetadata) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{1} } - -type Snapshot struct { - Data []byte `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"` - Metadata SnapshotMetadata `protobuf:"bytes,2,opt,name=metadata" json:"metadata"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Snapshot) Reset() { *m = Snapshot{} } -func (m *Snapshot) String() string { return proto.CompactTextString(m) } -func (*Snapshot) ProtoMessage() {} -func (*Snapshot) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{2} } - -type Message struct { - Type MessageType `protobuf:"varint,1,opt,name=type,enum=raftpb.MessageType" json:"type"` - To uint64 `protobuf:"varint,2,opt,name=to" json:"to"` - From uint64 `protobuf:"varint,3,opt,name=from" json:"from"` - Term uint64 `protobuf:"varint,4,opt,name=term" json:"term"` - LogTerm uint64 `protobuf:"varint,5,opt,name=logTerm" json:"logTerm"` - Index uint64 `protobuf:"varint,6,opt,name=index" json:"index"` - Entries []Entry `protobuf:"bytes,7,rep,name=entries" json:"entries"` - Commit uint64 `protobuf:"varint,8,opt,name=commit" json:"commit"` - Snapshot Snapshot `protobuf:"bytes,9,opt,name=snapshot" json:"snapshot"` - Reject bool `protobuf:"varint,10,opt,name=reject" json:"reject"` - RejectHint uint64 `protobuf:"varint,11,opt,name=rejectHint" json:"rejectHint"` - Context []byte `protobuf:"bytes,12,opt,name=context" json:"context,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Message) Reset() { *m = Message{} } -func (m *Message) String() string { return proto.CompactTextString(m) } -func (*Message) ProtoMessage() {} -func (*Message) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{3} } - -type HardState struct { - Term uint64 `protobuf:"varint,1,opt,name=term" json:"term"` - Vote uint64 `protobuf:"varint,2,opt,name=vote" json:"vote"` - Commit uint64 `protobuf:"varint,3,opt,name=commit" json:"commit"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *HardState) Reset() { *m = HardState{} } -func (m *HardState) String() string { return proto.CompactTextString(m) } -func (*HardState) ProtoMessage() {} -func (*HardState) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{4} } - -type ConfState struct { - Nodes []uint64 `protobuf:"varint,1,rep,name=nodes" json:"nodes,omitempty"` - Learners []uint64 `protobuf:"varint,2,rep,name=learners" json:"learners,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *ConfState) Reset() { *m = ConfState{} } -func (m *ConfState) String() string { return proto.CompactTextString(m) } -func (*ConfState) ProtoMessage() {} -func (*ConfState) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{5} } - -type ConfChange struct { - ID uint64 `protobuf:"varint,1,opt,name=ID" json:"ID"` - Type ConfChangeType `protobuf:"varint,2,opt,name=Type,enum=raftpb.ConfChangeType" json:"Type"` - NodeID uint64 `protobuf:"varint,3,opt,name=NodeID" json:"NodeID"` - Context []byte `protobuf:"bytes,4,opt,name=Context" json:"Context,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *ConfChange) Reset() { *m = ConfChange{} } -func (m *ConfChange) String() string { return proto.CompactTextString(m) } -func (*ConfChange) ProtoMessage() {} -func (*ConfChange) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{6} } - -func init() { - proto.RegisterType((*Entry)(nil), "raftpb.Entry") - proto.RegisterType((*SnapshotMetadata)(nil), "raftpb.SnapshotMetadata") - proto.RegisterType((*Snapshot)(nil), "raftpb.Snapshot") - proto.RegisterType((*Message)(nil), "raftpb.Message") - proto.RegisterType((*HardState)(nil), "raftpb.HardState") - proto.RegisterType((*ConfState)(nil), "raftpb.ConfState") - proto.RegisterType((*ConfChange)(nil), "raftpb.ConfChange") - proto.RegisterEnum("raftpb.EntryType", EntryType_name, EntryType_value) - proto.RegisterEnum("raftpb.MessageType", MessageType_name, MessageType_value) - proto.RegisterEnum("raftpb.ConfChangeType", ConfChangeType_name, ConfChangeType_value) -} -func (m *Entry) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Entry) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Type)) - dAtA[i] = 0x10 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Term)) - dAtA[i] = 0x18 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Index)) - if m.Data != nil { - dAtA[i] = 0x22 - i++ - i = encodeVarintRaft(dAtA, i, uint64(len(m.Data))) - i += copy(dAtA[i:], m.Data) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *SnapshotMetadata) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SnapshotMetadata) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - dAtA[i] = 0xa - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.ConfState.Size())) - n1, err := m.ConfState.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - dAtA[i] = 0x10 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Index)) - dAtA[i] = 0x18 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Term)) - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *Snapshot) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Snapshot) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Data != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRaft(dAtA, i, uint64(len(m.Data))) - i += copy(dAtA[i:], m.Data) - } - dAtA[i] = 0x12 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Metadata.Size())) - n2, err := m.Metadata.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *Message) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Message) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Type)) - dAtA[i] = 0x10 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.To)) - dAtA[i] = 0x18 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.From)) - dAtA[i] = 0x20 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Term)) - dAtA[i] = 0x28 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.LogTerm)) - dAtA[i] = 0x30 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Index)) - if len(m.Entries) > 0 { - for _, msg := range m.Entries { - dAtA[i] = 0x3a - i++ - i = encodeVarintRaft(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - dAtA[i] = 0x40 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Commit)) - dAtA[i] = 0x4a - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Snapshot.Size())) - n3, err := m.Snapshot.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n3 - dAtA[i] = 0x50 - i++ - if m.Reject { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - dAtA[i] = 0x58 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.RejectHint)) - if m.Context != nil { - dAtA[i] = 0x62 - i++ - i = encodeVarintRaft(dAtA, i, uint64(len(m.Context))) - i += copy(dAtA[i:], m.Context) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *HardState) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *HardState) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Term)) - dAtA[i] = 0x10 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Vote)) - dAtA[i] = 0x18 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Commit)) - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *ConfState) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ConfState) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Nodes) > 0 { - for _, num := range m.Nodes { - dAtA[i] = 0x8 - i++ - i = encodeVarintRaft(dAtA, i, uint64(num)) - } - } - if len(m.Learners) > 0 { - for _, num := range m.Learners { - dAtA[i] = 0x10 - i++ - i = encodeVarintRaft(dAtA, i, uint64(num)) - } - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *ConfChange) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ConfChange) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.ID)) - dAtA[i] = 0x10 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Type)) - dAtA[i] = 0x18 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.NodeID)) - if m.Context != nil { - dAtA[i] = 0x22 - i++ - i = encodeVarintRaft(dAtA, i, uint64(len(m.Context))) - i += copy(dAtA[i:], m.Context) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func encodeVarintRaft(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *Entry) Size() (n int) { - var l int - _ = l - n += 1 + sovRaft(uint64(m.Type)) - n += 1 + sovRaft(uint64(m.Term)) - n += 1 + sovRaft(uint64(m.Index)) - if m.Data != nil { - l = len(m.Data) - n += 1 + l + sovRaft(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *SnapshotMetadata) Size() (n int) { - var l int - _ = l - l = m.ConfState.Size() - n += 1 + l + sovRaft(uint64(l)) - n += 1 + sovRaft(uint64(m.Index)) - n += 1 + sovRaft(uint64(m.Term)) - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *Snapshot) Size() (n int) { - var l int - _ = l - if m.Data != nil { - l = len(m.Data) - n += 1 + l + sovRaft(uint64(l)) - } - l = m.Metadata.Size() - n += 1 + l + sovRaft(uint64(l)) - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *Message) Size() (n int) { - var l int - _ = l - n += 1 + sovRaft(uint64(m.Type)) - n += 1 + sovRaft(uint64(m.To)) - n += 1 + sovRaft(uint64(m.From)) - n += 1 + sovRaft(uint64(m.Term)) - n += 1 + sovRaft(uint64(m.LogTerm)) - n += 1 + sovRaft(uint64(m.Index)) - if len(m.Entries) > 0 { - for _, e := range m.Entries { - l = e.Size() - n += 1 + l + sovRaft(uint64(l)) - } - } - n += 1 + sovRaft(uint64(m.Commit)) - l = m.Snapshot.Size() - n += 1 + l + sovRaft(uint64(l)) - n += 2 - n += 1 + sovRaft(uint64(m.RejectHint)) - if m.Context != nil { - l = len(m.Context) - n += 1 + l + sovRaft(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *HardState) Size() (n int) { - var l int - _ = l - n += 1 + sovRaft(uint64(m.Term)) - n += 1 + sovRaft(uint64(m.Vote)) - n += 1 + sovRaft(uint64(m.Commit)) - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *ConfState) Size() (n int) { - var l int - _ = l - if len(m.Nodes) > 0 { - for _, e := range m.Nodes { - n += 1 + sovRaft(uint64(e)) - } - } - if len(m.Learners) > 0 { - for _, e := range m.Learners { - n += 1 + sovRaft(uint64(e)) - } - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *ConfChange) Size() (n int) { - var l int - _ = l - n += 1 + sovRaft(uint64(m.ID)) - n += 1 + sovRaft(uint64(m.Type)) - n += 1 + sovRaft(uint64(m.NodeID)) - if m.Context != nil { - l = len(m.Context) - n += 1 + l + sovRaft(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func sovRaft(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozRaft(x uint64) (n int) { - return sovRaft(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Entry) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Entry: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Entry: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= (EntryType(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType) - } - m.Term = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Term |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) - } - m.Index = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Index |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *SnapshotMetadata) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SnapshotMetadata: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SnapshotMetadata: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ConfState", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.ConfState.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) - } - m.Index = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Index |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType) - } - m.Term = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Term |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Snapshot) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Snapshot: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Snapshot: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Metadata", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Metadata.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Message) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Message: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Message: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= (MessageType(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field To", wireType) - } - m.To = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.To |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field From", wireType) - } - m.From = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.From |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType) - } - m.Term = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Term |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field LogTerm", wireType) - } - m.LogTerm = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.LogTerm |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) - } - m.Index = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Index |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Entries", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Entries = append(m.Entries, Entry{}) - if err := m.Entries[len(m.Entries)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Commit", wireType) - } - m.Commit = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Commit |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 9: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Snapshot", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Snapshot.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 10: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Reject", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Reject = bool(v != 0) - case 11: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RejectHint", wireType) - } - m.RejectHint = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RejectHint |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 12: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Context", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Context = append(m.Context[:0], dAtA[iNdEx:postIndex]...) - if m.Context == nil { - m.Context = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *HardState) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: HardState: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HardState: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType) - } - m.Term = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Term |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Vote", wireType) - } - m.Vote = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Vote |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Commit", wireType) - } - m.Commit = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Commit |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ConfState) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ConfState: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ConfState: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType == 0 { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Nodes = append(m.Nodes, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + packedLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - for iNdEx < postIndex { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Nodes = append(m.Nodes, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field Nodes", wireType) - } - case 2: - if wireType == 0 { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Learners = append(m.Learners, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + packedLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - for iNdEx < postIndex { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Learners = append(m.Learners, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field Learners", wireType) - } - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ConfChange) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ConfChange: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ConfChange: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= (ConfChangeType(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field NodeID", wireType) - } - m.NodeID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.NodeID |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Context", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Context = append(m.Context[:0], dAtA[iNdEx:postIndex]...) - if m.Context == nil { - m.Context = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipRaft(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaft - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaft - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaft - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthRaft - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaft - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipRaft(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthRaft = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowRaft = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("raft.proto", fileDescriptorRaft) } - -var fileDescriptorRaft = []byte{ - // 815 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x54, 0xcd, 0x6e, 0x23, 0x45, - 0x10, 0xf6, 0x8c, 0xc7, 0x7f, 0x35, 0x8e, 0xd3, 0xa9, 0x35, 0xa8, 0x15, 0x45, 0xc6, 0xb2, 0x38, - 0x58, 0x41, 0x1b, 0x20, 0x07, 0x0e, 0x48, 0x1c, 0x36, 0x09, 0x52, 0x22, 0xad, 0xa3, 0xc5, 0x9b, - 0xe5, 0x80, 0x84, 0x50, 0xc7, 0x53, 0x9e, 0x18, 0x32, 0xd3, 0xa3, 0x9e, 0xf6, 0xb2, 0xb9, 0x20, - 0x1e, 0x80, 0x07, 0xe0, 0xc2, 0xfb, 0xe4, 0xb8, 0x12, 0x77, 0xc4, 0x86, 0x17, 0x41, 0xdd, 0xd3, - 0x63, 0xcf, 0x24, 0xb7, 0xae, 0xef, 0xab, 0xae, 0xfa, 0xea, 0xeb, 0x9a, 0x01, 0x50, 0x62, 0xa9, - 0x8f, 0x32, 0x25, 0xb5, 0xc4, 0xb6, 0x39, 0x67, 0xd7, 0xfb, 0xc3, 0x58, 0xc6, 0xd2, 0x42, 0x9f, - 0x9b, 0x53, 0xc1, 0x4e, 0x7e, 0x83, 0xd6, 0xb7, 0xa9, 0x56, 0x77, 0xf8, 0x19, 0x04, 0x57, 0x77, - 0x19, 0x71, 0x6f, 0xec, 0x4d, 0x07, 0xc7, 0x7b, 0x47, 0xc5, 0xad, 0x23, 0x4b, 0x1a, 0xe2, 0x24, - 0xb8, 0xff, 0xe7, 0x93, 0xc6, 0xdc, 0x26, 0x21, 0x87, 0xe0, 0x8a, 0x54, 0xc2, 0xfd, 0xb1, 0x37, - 0x0d, 0x36, 0x0c, 0xa9, 0x04, 0xf7, 0xa1, 0x75, 0x91, 0x46, 0xf4, 0x8e, 0x37, 0x2b, 0x54, 0x01, - 0x21, 0x42, 0x70, 0x26, 0xb4, 0xe0, 0xc1, 0xd8, 0x9b, 0xf6, 0xe7, 0xf6, 0x3c, 0xf9, 0xdd, 0x03, - 0xf6, 0x3a, 0x15, 0x59, 0x7e, 0x23, 0xf5, 0x8c, 0xb4, 0x88, 0x84, 0x16, 0xf8, 0x15, 0xc0, 0x42, - 0xa6, 0xcb, 0x9f, 0x72, 0x2d, 0x74, 0xa1, 0x28, 0xdc, 0x2a, 0x3a, 0x95, 0xe9, 0xf2, 0xb5, 0x21, - 0x5c, 0xf1, 0xde, 0xa2, 0x04, 0x4c, 0xf3, 0x95, 0x6d, 0x5e, 0xd5, 0x55, 0x40, 0x46, 0xb2, 0x36, - 0x92, 0xab, 0xba, 0x2c, 0x32, 0xf9, 0x01, 0xba, 0xa5, 0x02, 0x23, 0xd1, 0x28, 0xb0, 0x3d, 0xfb, - 0x73, 0x7b, 0xc6, 0xaf, 0xa1, 0x9b, 0x38, 0x65, 0xb6, 0x70, 0x78, 0xcc, 0x4b, 0x2d, 0x8f, 0x95, - 0xbb, 0xba, 0x9b, 0xfc, 0xc9, 0x5f, 0x4d, 0xe8, 0xcc, 0x28, 0xcf, 0x45, 0x4c, 0xf8, 0x1c, 0x02, - 0xbd, 0x75, 0xf8, 0x59, 0x59, 0xc3, 0xd1, 0x55, 0x8f, 0x4d, 0x1a, 0x0e, 0xc1, 0xd7, 0xb2, 0x36, - 0x89, 0xaf, 0xa5, 0x19, 0x63, 0xa9, 0xe4, 0xa3, 0x31, 0x0c, 0xb2, 0x19, 0x30, 0x78, 0x3c, 0x20, - 0x8e, 0xa0, 0x73, 0x2b, 0x63, 0xfb, 0x60, 0xad, 0x0a, 0x59, 0x82, 0x5b, 0xdb, 0xda, 0x4f, 0x6d, - 0x7b, 0x0e, 0x1d, 0x4a, 0xb5, 0x5a, 0x51, 0xce, 0x3b, 0xe3, 0xe6, 0x34, 0x3c, 0xde, 0xa9, 0x6d, - 0x46, 0x59, 0xca, 0xe5, 0xe0, 0x01, 0xb4, 0x17, 0x32, 0x49, 0x56, 0x9a, 0x77, 0x2b, 0xb5, 0x1c, - 0x86, 0xc7, 0xd0, 0xcd, 0x9d, 0x63, 0xbc, 0x67, 0x9d, 0x64, 0x8f, 0x9d, 0x2c, 0x1d, 0x2c, 0xf3, - 0x4c, 0x45, 0x45, 0x3f, 0xd3, 0x42, 0x73, 0x18, 0x7b, 0xd3, 0x6e, 0x59, 0xb1, 0xc0, 0xf0, 0x53, - 0x80, 0xe2, 0x74, 0xbe, 0x4a, 0x35, 0x0f, 0x2b, 0x3d, 0x2b, 0x38, 0x72, 0xe8, 0x2c, 0x64, 0xaa, - 0xe9, 0x9d, 0xe6, 0x7d, 0xfb, 0xb0, 0x65, 0x38, 0xf9, 0x11, 0x7a, 0xe7, 0x42, 0x45, 0xc5, 0xfa, - 0x94, 0x0e, 0x7a, 0x4f, 0x1c, 0xe4, 0x10, 0xbc, 0x95, 0x9a, 0xea, 0xfb, 0x6e, 0x90, 0xca, 0xc0, - 0xcd, 0xa7, 0x03, 0x4f, 0xbe, 0x81, 0xde, 0x66, 0x5d, 0x71, 0x08, 0xad, 0x54, 0x46, 0x94, 0x73, - 0x6f, 0xdc, 0x9c, 0x06, 0xf3, 0x22, 0xc0, 0x7d, 0xe8, 0xde, 0x92, 0x50, 0x29, 0xa9, 0x9c, 0xfb, - 0x96, 0xd8, 0xc4, 0x93, 0x3f, 0x3c, 0x00, 0x73, 0xff, 0xf4, 0x46, 0xa4, 0xb1, 0xdd, 0x88, 0x8b, - 0xb3, 0x9a, 0x3a, 0xff, 0xe2, 0x0c, 0xbf, 0x70, 0x1f, 0xae, 0x6f, 0xd7, 0xea, 0xe3, 0xea, 0x67, - 0x52, 0xdc, 0x7b, 0xf2, 0xf5, 0x1e, 0x40, 0xfb, 0x52, 0x46, 0x74, 0x71, 0x56, 0xd7, 0x5c, 0x60, - 0xc6, 0xac, 0x53, 0x67, 0x56, 0xf1, 0xa1, 0x96, 0xe1, 0xe1, 0x97, 0xd0, 0xdb, 0xfc, 0x0e, 0x70, - 0x17, 0x42, 0x1b, 0x5c, 0x4a, 0x95, 0x88, 0x5b, 0xd6, 0xc0, 0x67, 0xb0, 0x6b, 0x81, 0x6d, 0x63, - 0xe6, 0x1d, 0xfe, 0xed, 0x43, 0x58, 0x59, 0x70, 0x04, 0x68, 0xcf, 0xf2, 0xf8, 0x7c, 0x9d, 0xb1, - 0x06, 0x86, 0xd0, 0x99, 0xe5, 0xf1, 0x09, 0x09, 0xcd, 0x3c, 0x17, 0xbc, 0x52, 0x32, 0x63, 0xbe, - 0xcb, 0x7a, 0x91, 0x65, 0xac, 0x89, 0x03, 0x80, 0xe2, 0x3c, 0xa7, 0x3c, 0x63, 0x81, 0x4b, 0xfc, - 0x5e, 0x6a, 0x62, 0x2d, 0x23, 0xc2, 0x05, 0x96, 0x6d, 0x3b, 0xd6, 0x2c, 0x13, 0xeb, 0x20, 0x83, - 0xbe, 0x69, 0x46, 0x42, 0xe9, 0x6b, 0xd3, 0xa5, 0x8b, 0x43, 0x60, 0x55, 0xc4, 0x5e, 0xea, 0x21, - 0xc2, 0x60, 0x96, 0xc7, 0x6f, 0x52, 0x45, 0x62, 0x71, 0x23, 0xae, 0x6f, 0x89, 0x01, 0xee, 0xc1, - 0x8e, 0x2b, 0x64, 0x1e, 0x6f, 0x9d, 0xb3, 0xd0, 0xa5, 0x9d, 0xde, 0xd0, 0xe2, 0x97, 0xef, 0xd6, - 0x52, 0xad, 0x13, 0xd6, 0xc7, 0x8f, 0x60, 0x6f, 0x96, 0xc7, 0x57, 0x4a, 0xa4, 0xf9, 0x92, 0xd4, - 0x4b, 0x12, 0x11, 0x29, 0xb6, 0xe3, 0x6e, 0x5f, 0xad, 0x12, 0x92, 0x6b, 0x7d, 0x29, 0x7f, 0x65, - 0x03, 0x27, 0x66, 0x4e, 0x22, 0xb2, 0x3f, 0x43, 0xb6, 0xeb, 0xc4, 0x6c, 0x10, 0x2b, 0x86, 0xb9, - 0x79, 0x5f, 0x29, 0xb2, 0x23, 0xee, 0xb9, 0xae, 0x2e, 0xb6, 0x39, 0x78, 0x78, 0x07, 0x83, 0xfa, - 0xf3, 0x1a, 0x1d, 0x5b, 0xe4, 0x45, 0x14, 0x99, 0xb7, 0x64, 0x0d, 0xe4, 0x30, 0xdc, 0xc2, 0x73, - 0x4a, 0xe4, 0x5b, 0xb2, 0x8c, 0x57, 0x67, 0xde, 0x64, 0x91, 0xd0, 0x05, 0xe3, 0xe3, 0x01, 0xf0, - 0x5a, 0xa9, 0x97, 0xc5, 0x36, 0x5a, 0xb6, 0x79, 0xc2, 0xef, 0x3f, 0x8c, 0x1a, 0xef, 0x3f, 0x8c, - 0x1a, 0xf7, 0x0f, 0x23, 0xef, 0xfd, 0xc3, 0xc8, 0xfb, 0xf7, 0x61, 0xe4, 0xfd, 0xf9, 0xdf, 0xa8, - 0xf1, 0x7f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x86, 0x52, 0x5b, 0xe0, 0x74, 0x06, 0x00, 0x00, -} diff --git a/vendor/go.etcd.io/etcd/raft/rawnode.go b/vendor/go.etcd.io/etcd/raft/rawnode.go deleted file mode 100644 index 925cb851c4ad..000000000000 --- a/vendor/go.etcd.io/etcd/raft/rawnode.go +++ /dev/null @@ -1,266 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "errors" - - pb "github.com/coreos/etcd/raft/raftpb" -) - -// ErrStepLocalMsg is returned when try to step a local raft message -var ErrStepLocalMsg = errors.New("raft: cannot step raft local message") - -// ErrStepPeerNotFound is returned when try to step a response message -// but there is no peer found in raft.prs for that node. -var ErrStepPeerNotFound = errors.New("raft: cannot step as peer not found") - -// RawNode is a thread-unsafe Node. -// The methods of this struct correspond to the methods of Node and are described -// more fully there. -type RawNode struct { - raft *raft - prevSoftSt *SoftState - prevHardSt pb.HardState -} - -func (rn *RawNode) newReady() Ready { - return newReady(rn.raft, rn.prevSoftSt, rn.prevHardSt) -} - -func (rn *RawNode) commitReady(rd Ready) { - if rd.SoftState != nil { - rn.prevSoftSt = rd.SoftState - } - if !IsEmptyHardState(rd.HardState) { - rn.prevHardSt = rd.HardState - } - if rn.prevHardSt.Commit != 0 { - // In most cases, prevHardSt and rd.HardState will be the same - // because when there are new entries to apply we just sent a - // HardState with an updated Commit value. However, on initial - // startup the two are different because we don't send a HardState - // until something changes, but we do send any un-applied but - // committed entries (and previously-committed entries may be - // incorporated into the snapshot, even if rd.CommittedEntries is - // empty). Therefore we mark all committed entries as applied - // whether they were included in rd.HardState or not. - rn.raft.raftLog.appliedTo(rn.prevHardSt.Commit) - } - if len(rd.Entries) > 0 { - e := rd.Entries[len(rd.Entries)-1] - rn.raft.raftLog.stableTo(e.Index, e.Term) - } - if !IsEmptySnap(rd.Snapshot) { - rn.raft.raftLog.stableSnapTo(rd.Snapshot.Metadata.Index) - } - if len(rd.ReadStates) != 0 { - rn.raft.readStates = nil - } -} - -// NewRawNode returns a new RawNode given configuration and a list of raft peers. -func NewRawNode(config *Config, peers []Peer) (*RawNode, error) { - if config.ID == 0 { - panic("config.ID must not be zero") - } - r := newRaft(config) - rn := &RawNode{ - raft: r, - } - lastIndex, err := config.Storage.LastIndex() - if err != nil { - panic(err) // TODO(bdarnell) - } - // If the log is empty, this is a new RawNode (like StartNode); otherwise it's - // restoring an existing RawNode (like RestartNode). - // TODO(bdarnell): rethink RawNode initialization and whether the application needs - // to be able to tell us when it expects the RawNode to exist. - if lastIndex == 0 { - r.becomeFollower(1, None) - ents := make([]pb.Entry, len(peers)) - for i, peer := range peers { - cc := pb.ConfChange{Type: pb.ConfChangeAddNode, NodeID: peer.ID, Context: peer.Context} - data, err := cc.Marshal() - if err != nil { - panic("unexpected marshal error") - } - - ents[i] = pb.Entry{Type: pb.EntryConfChange, Term: 1, Index: uint64(i + 1), Data: data} - } - r.raftLog.append(ents...) - r.raftLog.committed = uint64(len(ents)) - for _, peer := range peers { - r.addNode(peer.ID) - } - } - - // Set the initial hard and soft states after performing all initialization. - rn.prevSoftSt = r.softState() - if lastIndex == 0 { - rn.prevHardSt = emptyState - } else { - rn.prevHardSt = r.hardState() - } - - return rn, nil -} - -// Tick advances the internal logical clock by a single tick. -func (rn *RawNode) Tick() { - rn.raft.tick() -} - -// TickQuiesced advances the internal logical clock by a single tick without -// performing any other state machine processing. It allows the caller to avoid -// periodic heartbeats and elections when all of the peers in a Raft group are -// known to be at the same state. Expected usage is to periodically invoke Tick -// or TickQuiesced depending on whether the group is "active" or "quiesced". -// -// WARNING: Be very careful about using this method as it subverts the Raft -// state machine. You should probably be using Tick instead. -func (rn *RawNode) TickQuiesced() { - rn.raft.electionElapsed++ -} - -// Campaign causes this RawNode to transition to candidate state. -func (rn *RawNode) Campaign() error { - return rn.raft.Step(pb.Message{ - Type: pb.MsgHup, - }) -} - -// Propose proposes data be appended to the raft log. -func (rn *RawNode) Propose(data []byte) error { - return rn.raft.Step(pb.Message{ - Type: pb.MsgProp, - From: rn.raft.id, - Entries: []pb.Entry{ - {Data: data}, - }}) -} - -// ProposeConfChange proposes a config change. -func (rn *RawNode) ProposeConfChange(cc pb.ConfChange) error { - data, err := cc.Marshal() - if err != nil { - return err - } - return rn.raft.Step(pb.Message{ - Type: pb.MsgProp, - Entries: []pb.Entry{ - {Type: pb.EntryConfChange, Data: data}, - }, - }) -} - -// ApplyConfChange applies a config change to the local node. -func (rn *RawNode) ApplyConfChange(cc pb.ConfChange) *pb.ConfState { - if cc.NodeID == None { - rn.raft.resetPendingConf() - return &pb.ConfState{Nodes: rn.raft.nodes()} - } - switch cc.Type { - case pb.ConfChangeAddNode: - rn.raft.addNode(cc.NodeID) - case pb.ConfChangeAddLearnerNode: - rn.raft.addLearner(cc.NodeID) - case pb.ConfChangeRemoveNode: - rn.raft.removeNode(cc.NodeID) - case pb.ConfChangeUpdateNode: - rn.raft.resetPendingConf() - default: - panic("unexpected conf type") - } - return &pb.ConfState{Nodes: rn.raft.nodes()} -} - -// Step advances the state machine using the given message. -func (rn *RawNode) Step(m pb.Message) error { - // ignore unexpected local messages receiving over network - if IsLocalMsg(m.Type) { - return ErrStepLocalMsg - } - if pr := rn.raft.getProgress(m.From); pr != nil || !IsResponseMsg(m.Type) { - return rn.raft.Step(m) - } - return ErrStepPeerNotFound -} - -// Ready returns the current point-in-time state of this RawNode. -func (rn *RawNode) Ready() Ready { - rd := rn.newReady() - rn.raft.msgs = nil - return rd -} - -// HasReady called when RawNode user need to check if any Ready pending. -// Checking logic in this method should be consistent with Ready.containsUpdates(). -func (rn *RawNode) HasReady() bool { - r := rn.raft - if !r.softState().equal(rn.prevSoftSt) { - return true - } - if hardSt := r.hardState(); !IsEmptyHardState(hardSt) && !isHardStateEqual(hardSt, rn.prevHardSt) { - return true - } - if r.raftLog.unstable.snapshot != nil && !IsEmptySnap(*r.raftLog.unstable.snapshot) { - return true - } - if len(r.msgs) > 0 || len(r.raftLog.unstableEntries()) > 0 || r.raftLog.hasNextEnts() { - return true - } - if len(r.readStates) != 0 { - return true - } - return false -} - -// Advance notifies the RawNode that the application has applied and saved progress in the -// last Ready results. -func (rn *RawNode) Advance(rd Ready) { - rn.commitReady(rd) -} - -// Status returns the current status of the given group. -func (rn *RawNode) Status() *Status { - status := getStatus(rn.raft) - return &status -} - -// ReportUnreachable reports the given node is not reachable for the last send. -func (rn *RawNode) ReportUnreachable(id uint64) { - _ = rn.raft.Step(pb.Message{Type: pb.MsgUnreachable, From: id}) -} - -// ReportSnapshot reports the status of the sent snapshot. -func (rn *RawNode) ReportSnapshot(id uint64, status SnapshotStatus) { - rej := status == SnapshotFailure - - _ = rn.raft.Step(pb.Message{Type: pb.MsgSnapStatus, From: id, Reject: rej}) -} - -// TransferLeader tries to transfer leadership to the given transferee. -func (rn *RawNode) TransferLeader(transferee uint64) { - _ = rn.raft.Step(pb.Message{Type: pb.MsgTransferLeader, From: transferee}) -} - -// ReadIndex requests a read state. The read state will be set in ready. -// Read State has a read index. Once the application advances further than the read -// index, any linearizable read requests issued before the read request can be -// processed safely. The read state will have the same rctx attached. -func (rn *RawNode) ReadIndex(rctx []byte) { - _ = rn.raft.Step(pb.Message{Type: pb.MsgReadIndex, Entries: []pb.Entry{{Data: rctx}}}) -} diff --git a/vendor/go.etcd.io/etcd/raft/read_only.go b/vendor/go.etcd.io/etcd/raft/read_only.go deleted file mode 100644 index ae746fa73eb3..000000000000 --- a/vendor/go.etcd.io/etcd/raft/read_only.go +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import pb "github.com/coreos/etcd/raft/raftpb" - -// ReadState provides state for read only query. -// It's caller's responsibility to call ReadIndex first before getting -// this state from ready, it's also caller's duty to differentiate if this -// state is what it requests through RequestCtx, eg. given a unique id as -// RequestCtx -type ReadState struct { - Index uint64 - RequestCtx []byte -} - -type readIndexStatus struct { - req pb.Message - index uint64 - acks map[uint64]struct{} -} - -type readOnly struct { - option ReadOnlyOption - pendingReadIndex map[string]*readIndexStatus - readIndexQueue []string -} - -func newReadOnly(option ReadOnlyOption) *readOnly { - return &readOnly{ - option: option, - pendingReadIndex: make(map[string]*readIndexStatus), - } -} - -// addRequest adds a read only reuqest into readonly struct. -// `index` is the commit index of the raft state machine when it received -// the read only request. -// `m` is the original read only request message from the local or remote node. -func (ro *readOnly) addRequest(index uint64, m pb.Message) { - ctx := string(m.Entries[0].Data) - if _, ok := ro.pendingReadIndex[ctx]; ok { - return - } - ro.pendingReadIndex[ctx] = &readIndexStatus{index: index, req: m, acks: make(map[uint64]struct{})} - ro.readIndexQueue = append(ro.readIndexQueue, ctx) -} - -// recvAck notifies the readonly struct that the raft state machine received -// an acknowledgment of the heartbeat that attached with the read only request -// context. -func (ro *readOnly) recvAck(m pb.Message) int { - rs, ok := ro.pendingReadIndex[string(m.Context)] - if !ok { - return 0 - } - - rs.acks[m.From] = struct{}{} - // add one to include an ack from local node - return len(rs.acks) + 1 -} - -// advance advances the read only request queue kept by the readonly struct. -// It dequeues the requests until it finds the read only request that has -// the same context as the given `m`. -func (ro *readOnly) advance(m pb.Message) []*readIndexStatus { - var ( - i int - found bool - ) - - ctx := string(m.Context) - rss := []*readIndexStatus{} - - for _, okctx := range ro.readIndexQueue { - i++ - rs, ok := ro.pendingReadIndex[okctx] - if !ok { - panic("cannot find corresponding read state from pending map") - } - rss = append(rss, rs) - if okctx == ctx { - found = true - break - } - } - - if found { - ro.readIndexQueue = ro.readIndexQueue[i:] - for _, rs := range rss { - delete(ro.pendingReadIndex, string(rs.req.Entries[0].Data)) - } - return rss - } - - return nil -} - -// lastPendingRequestCtx returns the context of the last pending read only -// request in readonly struct. -func (ro *readOnly) lastPendingRequestCtx() string { - if len(ro.readIndexQueue) == 0 { - return "" - } - return ro.readIndexQueue[len(ro.readIndexQueue)-1] -} diff --git a/vendor/go.etcd.io/etcd/raft/status.go b/vendor/go.etcd.io/etcd/raft/status.go deleted file mode 100644 index f4d3d86a4e39..000000000000 --- a/vendor/go.etcd.io/etcd/raft/status.go +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "fmt" - - pb "github.com/coreos/etcd/raft/raftpb" -) - -type Status struct { - ID uint64 - - pb.HardState - SoftState - - Applied uint64 - Progress map[uint64]Progress - - LeadTransferee uint64 -} - -// getStatus gets a copy of the current raft status. -func getStatus(r *raft) Status { - s := Status{ - ID: r.id, - LeadTransferee: r.leadTransferee, - } - - s.HardState = r.hardState() - s.SoftState = *r.softState() - - s.Applied = r.raftLog.applied - - if s.RaftState == StateLeader { - s.Progress = make(map[uint64]Progress) - for id, p := range r.prs { - s.Progress[id] = *p - } - - for id, p := range r.learnerPrs { - s.Progress[id] = *p - } - } - - return s -} - -// MarshalJSON translates the raft status into JSON. -// TODO: try to simplify this by introducing ID type into raft -func (s Status) MarshalJSON() ([]byte, error) { - j := fmt.Sprintf(`{"id":"%x","term":%d,"vote":"%x","commit":%d,"lead":"%x","raftState":%q,"applied":%d,"progress":{`, - s.ID, s.Term, s.Vote, s.Commit, s.Lead, s.RaftState, s.Applied) - - if len(s.Progress) == 0 { - j += "}," - } else { - for k, v := range s.Progress { - subj := fmt.Sprintf(`"%x":{"match":%d,"next":%d,"state":%q},`, k, v.Match, v.Next, v.State) - j += subj - } - // remove the trailing "," - j = j[:len(j)-1] + "}," - } - - j += fmt.Sprintf(`"leadtransferee":"%x"}`, s.LeadTransferee) - return []byte(j), nil -} - -func (s Status) String() string { - b, err := s.MarshalJSON() - if err != nil { - raftLogger.Panicf("unexpected error: %v", err) - } - return string(b) -} diff --git a/vendor/go.etcd.io/etcd/raft/storage.go b/vendor/go.etcd.io/etcd/raft/storage.go deleted file mode 100644 index 69c3a7d90338..000000000000 --- a/vendor/go.etcd.io/etcd/raft/storage.go +++ /dev/null @@ -1,271 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "errors" - "sync" - - pb "github.com/coreos/etcd/raft/raftpb" -) - -// ErrCompacted is returned by Storage.Entries/Compact when a requested -// index is unavailable because it predates the last snapshot. -var ErrCompacted = errors.New("requested index is unavailable due to compaction") - -// ErrSnapOutOfDate is returned by Storage.CreateSnapshot when a requested -// index is older than the existing snapshot. -var ErrSnapOutOfDate = errors.New("requested index is older than the existing snapshot") - -// ErrUnavailable is returned by Storage interface when the requested log entries -// are unavailable. -var ErrUnavailable = errors.New("requested entry at index is unavailable") - -// ErrSnapshotTemporarilyUnavailable is returned by the Storage interface when the required -// snapshot is temporarily unavailable. -var ErrSnapshotTemporarilyUnavailable = errors.New("snapshot is temporarily unavailable") - -// Storage is an interface that may be implemented by the application -// to retrieve log entries from storage. -// -// If any Storage method returns an error, the raft instance will -// become inoperable and refuse to participate in elections; the -// application is responsible for cleanup and recovery in this case. -type Storage interface { - // InitialState returns the saved HardState and ConfState information. - InitialState() (pb.HardState, pb.ConfState, error) - // Entries returns a slice of log entries in the range [lo,hi). - // MaxSize limits the total size of the log entries returned, but - // Entries returns at least one entry if any. - Entries(lo, hi, maxSize uint64) ([]pb.Entry, error) - // Term returns the term of entry i, which must be in the range - // [FirstIndex()-1, LastIndex()]. The term of the entry before - // FirstIndex is retained for matching purposes even though the - // rest of that entry may not be available. - Term(i uint64) (uint64, error) - // LastIndex returns the index of the last entry in the log. - LastIndex() (uint64, error) - // FirstIndex returns the index of the first log entry that is - // possibly available via Entries (older entries have been incorporated - // into the latest Snapshot; if storage only contains the dummy entry the - // first log entry is not available). - FirstIndex() (uint64, error) - // Snapshot returns the most recent snapshot. - // If snapshot is temporarily unavailable, it should return ErrSnapshotTemporarilyUnavailable, - // so raft state machine could know that Storage needs some time to prepare - // snapshot and call Snapshot later. - Snapshot() (pb.Snapshot, error) -} - -// MemoryStorage implements the Storage interface backed by an -// in-memory array. -type MemoryStorage struct { - // Protects access to all fields. Most methods of MemoryStorage are - // run on the raft goroutine, but Append() is run on an application - // goroutine. - sync.Mutex - - hardState pb.HardState - snapshot pb.Snapshot - // ents[i] has raft log position i+snapshot.Metadata.Index - ents []pb.Entry -} - -// NewMemoryStorage creates an empty MemoryStorage. -func NewMemoryStorage() *MemoryStorage { - return &MemoryStorage{ - // When starting from scratch populate the list with a dummy entry at term zero. - ents: make([]pb.Entry, 1), - } -} - -// InitialState implements the Storage interface. -func (ms *MemoryStorage) InitialState() (pb.HardState, pb.ConfState, error) { - return ms.hardState, ms.snapshot.Metadata.ConfState, nil -} - -// SetHardState saves the current HardState. -func (ms *MemoryStorage) SetHardState(st pb.HardState) error { - ms.Lock() - defer ms.Unlock() - ms.hardState = st - return nil -} - -// Entries implements the Storage interface. -func (ms *MemoryStorage) Entries(lo, hi, maxSize uint64) ([]pb.Entry, error) { - ms.Lock() - defer ms.Unlock() - offset := ms.ents[0].Index - if lo <= offset { - return nil, ErrCompacted - } - if hi > ms.lastIndex()+1 { - raftLogger.Panicf("entries' hi(%d) is out of bound lastindex(%d)", hi, ms.lastIndex()) - } - // only contains dummy entries. - if len(ms.ents) == 1 { - return nil, ErrUnavailable - } - - ents := ms.ents[lo-offset : hi-offset] - return limitSize(ents, maxSize), nil -} - -// Term implements the Storage interface. -func (ms *MemoryStorage) Term(i uint64) (uint64, error) { - ms.Lock() - defer ms.Unlock() - offset := ms.ents[0].Index - if i < offset { - return 0, ErrCompacted - } - if int(i-offset) >= len(ms.ents) { - return 0, ErrUnavailable - } - return ms.ents[i-offset].Term, nil -} - -// LastIndex implements the Storage interface. -func (ms *MemoryStorage) LastIndex() (uint64, error) { - ms.Lock() - defer ms.Unlock() - return ms.lastIndex(), nil -} - -func (ms *MemoryStorage) lastIndex() uint64 { - return ms.ents[0].Index + uint64(len(ms.ents)) - 1 -} - -// FirstIndex implements the Storage interface. -func (ms *MemoryStorage) FirstIndex() (uint64, error) { - ms.Lock() - defer ms.Unlock() - return ms.firstIndex(), nil -} - -func (ms *MemoryStorage) firstIndex() uint64 { - return ms.ents[0].Index + 1 -} - -// Snapshot implements the Storage interface. -func (ms *MemoryStorage) Snapshot() (pb.Snapshot, error) { - ms.Lock() - defer ms.Unlock() - return ms.snapshot, nil -} - -// ApplySnapshot overwrites the contents of this Storage object with -// those of the given snapshot. -func (ms *MemoryStorage) ApplySnapshot(snap pb.Snapshot) error { - ms.Lock() - defer ms.Unlock() - - //handle check for old snapshot being applied - msIndex := ms.snapshot.Metadata.Index - snapIndex := snap.Metadata.Index - if msIndex >= snapIndex { - return ErrSnapOutOfDate - } - - ms.snapshot = snap - ms.ents = []pb.Entry{{Term: snap.Metadata.Term, Index: snap.Metadata.Index}} - return nil -} - -// CreateSnapshot makes a snapshot which can be retrieved with Snapshot() and -// can be used to reconstruct the state at that point. -// If any configuration changes have been made since the last compaction, -// the result of the last ApplyConfChange must be passed in. -func (ms *MemoryStorage) CreateSnapshot(i uint64, cs *pb.ConfState, data []byte) (pb.Snapshot, error) { - ms.Lock() - defer ms.Unlock() - if i <= ms.snapshot.Metadata.Index { - return pb.Snapshot{}, ErrSnapOutOfDate - } - - offset := ms.ents[0].Index - if i > ms.lastIndex() { - raftLogger.Panicf("snapshot %d is out of bound lastindex(%d)", i, ms.lastIndex()) - } - - ms.snapshot.Metadata.Index = i - ms.snapshot.Metadata.Term = ms.ents[i-offset].Term - if cs != nil { - ms.snapshot.Metadata.ConfState = *cs - } - ms.snapshot.Data = data - return ms.snapshot, nil -} - -// Compact discards all log entries prior to compactIndex. -// It is the application's responsibility to not attempt to compact an index -// greater than raftLog.applied. -func (ms *MemoryStorage) Compact(compactIndex uint64) error { - ms.Lock() - defer ms.Unlock() - offset := ms.ents[0].Index - if compactIndex <= offset { - return ErrCompacted - } - if compactIndex > ms.lastIndex() { - raftLogger.Panicf("compact %d is out of bound lastindex(%d)", compactIndex, ms.lastIndex()) - } - - i := compactIndex - offset - ents := make([]pb.Entry, 1, 1+uint64(len(ms.ents))-i) - ents[0].Index = ms.ents[i].Index - ents[0].Term = ms.ents[i].Term - ents = append(ents, ms.ents[i+1:]...) - ms.ents = ents - return nil -} - -// Append the new entries to storage. -// TODO (xiangli): ensure the entries are continuous and -// entries[0].Index > ms.entries[0].Index -func (ms *MemoryStorage) Append(entries []pb.Entry) error { - if len(entries) == 0 { - return nil - } - - ms.Lock() - defer ms.Unlock() - - first := ms.firstIndex() - last := entries[0].Index + uint64(len(entries)) - 1 - - // shortcut if there is no new entry. - if last < first { - return nil - } - // truncate compacted entries - if first > entries[0].Index { - entries = entries[first-entries[0].Index:] - } - - offset := entries[0].Index - ms.ents[0].Index - switch { - case uint64(len(ms.ents)) > offset: - ms.ents = append([]pb.Entry{}, ms.ents[:offset]...) - ms.ents = append(ms.ents, entries...) - case uint64(len(ms.ents)) == offset: - ms.ents = append(ms.ents, entries...) - default: - raftLogger.Panicf("missing log entry [last: %d, append at: %d]", - ms.lastIndex(), entries[0].Index) - } - return nil -} diff --git a/vendor/go.etcd.io/etcd/raft/util.go b/vendor/go.etcd.io/etcd/raft/util.go deleted file mode 100644 index f4141fe65ddf..000000000000 --- a/vendor/go.etcd.io/etcd/raft/util.go +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "bytes" - "fmt" - - pb "github.com/coreos/etcd/raft/raftpb" -) - -func (st StateType) MarshalJSON() ([]byte, error) { - return []byte(fmt.Sprintf("%q", st.String())), nil -} - -// uint64Slice implements sort interface -type uint64Slice []uint64 - -func (p uint64Slice) Len() int { return len(p) } -func (p uint64Slice) Less(i, j int) bool { return p[i] < p[j] } -func (p uint64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } - -func min(a, b uint64) uint64 { - if a > b { - return b - } - return a -} - -func max(a, b uint64) uint64 { - if a > b { - return a - } - return b -} - -func IsLocalMsg(msgt pb.MessageType) bool { - return msgt == pb.MsgHup || msgt == pb.MsgBeat || msgt == pb.MsgUnreachable || - msgt == pb.MsgSnapStatus || msgt == pb.MsgCheckQuorum -} - -func IsResponseMsg(msgt pb.MessageType) bool { - return msgt == pb.MsgAppResp || msgt == pb.MsgVoteResp || msgt == pb.MsgHeartbeatResp || msgt == pb.MsgUnreachable || msgt == pb.MsgPreVoteResp -} - -// voteResponseType maps vote and prevote message types to their corresponding responses. -func voteRespMsgType(msgt pb.MessageType) pb.MessageType { - switch msgt { - case pb.MsgVote: - return pb.MsgVoteResp - case pb.MsgPreVote: - return pb.MsgPreVoteResp - default: - panic(fmt.Sprintf("not a vote message: %s", msgt)) - } -} - -// EntryFormatter can be implemented by the application to provide human-readable formatting -// of entry data. Nil is a valid EntryFormatter and will use a default format. -type EntryFormatter func([]byte) string - -// DescribeMessage returns a concise human-readable description of a -// Message for debugging. -func DescribeMessage(m pb.Message, f EntryFormatter) string { - var buf bytes.Buffer - fmt.Fprintf(&buf, "%x->%x %v Term:%d Log:%d/%d", m.From, m.To, m.Type, m.Term, m.LogTerm, m.Index) - if m.Reject { - fmt.Fprintf(&buf, " Rejected") - if m.RejectHint != 0 { - fmt.Fprintf(&buf, "(Hint:%d)", m.RejectHint) - } - } - if m.Commit != 0 { - fmt.Fprintf(&buf, " Commit:%d", m.Commit) - } - if len(m.Entries) > 0 { - fmt.Fprintf(&buf, " Entries:[") - for i, e := range m.Entries { - if i != 0 { - buf.WriteString(", ") - } - buf.WriteString(DescribeEntry(e, f)) - } - fmt.Fprintf(&buf, "]") - } - if !IsEmptySnap(m.Snapshot) { - fmt.Fprintf(&buf, " Snapshot:%v", m.Snapshot) - } - return buf.String() -} - -// DescribeEntry returns a concise human-readable description of an -// Entry for debugging. -func DescribeEntry(e pb.Entry, f EntryFormatter) string { - var formatted string - if e.Type == pb.EntryNormal && f != nil { - formatted = f(e.Data) - } else { - formatted = fmt.Sprintf("%q", e.Data) - } - return fmt.Sprintf("%d/%d %s %s", e.Term, e.Index, e.Type, formatted) -} - -func limitSize(ents []pb.Entry, maxSize uint64) []pb.Entry { - if len(ents) == 0 { - return ents - } - size := ents[0].Size() - var limit int - for limit = 1; limit < len(ents); limit++ { - size += ents[limit].Size() - if uint64(size) > maxSize { - break - } - } - return ents[:limit] -} diff --git a/vendor/go.etcd.io/etcd/version/version.go b/vendor/go.etcd.io/etcd/version/version.go deleted file mode 100644 index c2bf7cfd5612..000000000000 --- a/vendor/go.etcd.io/etcd/version/version.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package version implements etcd version parsing and contains latest version -// information. -package version - -import ( - "fmt" - "strings" - - "github.com/coreos/go-semver/semver" -) - -var ( - // MinClusterVersion is the min cluster version this etcd binary is compatible with. - MinClusterVersion = "3.0.0" - Version = "3.3.13" - APIVersion = "unknown" - - // Git SHA Value will be set during build - GitSHA = "Not provided (use ./build instead of go build)" -) - -func init() { - ver, err := semver.NewVersion(Version) - if err == nil { - APIVersion = fmt.Sprintf("%d.%d", ver.Major, ver.Minor) - } -} - -type Versions struct { - Server string `json:"etcdserver"` - Cluster string `json:"etcdcluster"` - // TODO: raft state machine version -} - -// Cluster only keeps the major.minor. -func Cluster(v string) string { - vs := strings.Split(v, ".") - if len(vs) <= 2 { - return v - } - return fmt.Sprintf("%s.%s", vs[0], vs[1]) -} diff --git a/vendor/go.etcd.io/etcd/wal/decoder.go b/vendor/go.etcd.io/etcd/wal/decoder.go deleted file mode 100644 index 6a217f897b01..000000000000 --- a/vendor/go.etcd.io/etcd/wal/decoder.go +++ /dev/null @@ -1,188 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import ( - "bufio" - "encoding/binary" - "hash" - "io" - "sync" - - "github.com/coreos/etcd/pkg/crc" - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/wal/walpb" -) - -const minSectorSize = 512 - -// frameSizeBytes is frame size in bytes, including record size and padding size. -const frameSizeBytes = 8 - -type decoder struct { - mu sync.Mutex - brs []*bufio.Reader - - // lastValidOff file offset following the last valid decoded record - lastValidOff int64 - crc hash.Hash32 -} - -func newDecoder(r ...io.Reader) *decoder { - readers := make([]*bufio.Reader, len(r)) - for i := range r { - readers[i] = bufio.NewReader(r[i]) - } - return &decoder{ - brs: readers, - crc: crc.New(0, crcTable), - } -} - -func (d *decoder) decode(rec *walpb.Record) error { - rec.Reset() - d.mu.Lock() - defer d.mu.Unlock() - return d.decodeRecord(rec) -} - -func (d *decoder) decodeRecord(rec *walpb.Record) error { - if len(d.brs) == 0 { - return io.EOF - } - - l, err := readInt64(d.brs[0]) - if err == io.EOF || (err == nil && l == 0) { - // hit end of file or preallocated space - d.brs = d.brs[1:] - if len(d.brs) == 0 { - return io.EOF - } - d.lastValidOff = 0 - return d.decodeRecord(rec) - } - if err != nil { - return err - } - - recBytes, padBytes := decodeFrameSize(l) - - data := make([]byte, recBytes+padBytes) - if _, err = io.ReadFull(d.brs[0], data); err != nil { - // ReadFull returns io.EOF only if no bytes were read - // the decoder should treat this as an ErrUnexpectedEOF instead. - if err == io.EOF { - err = io.ErrUnexpectedEOF - } - return err - } - if err := rec.Unmarshal(data[:recBytes]); err != nil { - if d.isTornEntry(data) { - return io.ErrUnexpectedEOF - } - return err - } - - // skip crc checking if the record type is crcType - if rec.Type != crcType { - d.crc.Write(rec.Data) - if err := rec.Validate(d.crc.Sum32()); err != nil { - if d.isTornEntry(data) { - return io.ErrUnexpectedEOF - } - return err - } - } - // record decoded as valid; point last valid offset to end of record - d.lastValidOff += frameSizeBytes + recBytes + padBytes - return nil -} - -func decodeFrameSize(lenField int64) (recBytes int64, padBytes int64) { - // the record size is stored in the lower 56 bits of the 64-bit length - recBytes = int64(uint64(lenField) & ^(uint64(0xff) << 56)) - // non-zero padding is indicated by set MSb / a negative length - if lenField < 0 { - // padding is stored in lower 3 bits of length MSB - padBytes = int64((uint64(lenField) >> 56) & 0x7) - } - return recBytes, padBytes -} - -// isTornEntry determines whether the last entry of the WAL was partially written -// and corrupted because of a torn write. -func (d *decoder) isTornEntry(data []byte) bool { - if len(d.brs) != 1 { - return false - } - - fileOff := d.lastValidOff + frameSizeBytes - curOff := 0 - chunks := [][]byte{} - // split data on sector boundaries - for curOff < len(data) { - chunkLen := int(minSectorSize - (fileOff % minSectorSize)) - if chunkLen > len(data)-curOff { - chunkLen = len(data) - curOff - } - chunks = append(chunks, data[curOff:curOff+chunkLen]) - fileOff += int64(chunkLen) - curOff += chunkLen - } - - // if any data for a sector chunk is all 0, it's a torn write - for _, sect := range chunks { - isZero := true - for _, v := range sect { - if v != 0 { - isZero = false - break - } - } - if isZero { - return true - } - } - return false -} - -func (d *decoder) updateCRC(prevCrc uint32) { - d.crc = crc.New(prevCrc, crcTable) -} - -func (d *decoder) lastCRC() uint32 { - return d.crc.Sum32() -} - -func (d *decoder) lastOffset() int64 { return d.lastValidOff } - -func mustUnmarshalEntry(d []byte) raftpb.Entry { - var e raftpb.Entry - pbutil.MustUnmarshal(&e, d) - return e -} - -func mustUnmarshalState(d []byte) raftpb.HardState { - var s raftpb.HardState - pbutil.MustUnmarshal(&s, d) - return s -} - -func readInt64(r io.Reader) (int64, error) { - var n int64 - err := binary.Read(r, binary.LittleEndian, &n) - return n, err -} diff --git a/vendor/go.etcd.io/etcd/wal/doc.go b/vendor/go.etcd.io/etcd/wal/doc.go deleted file mode 100644 index a3abd69613d4..000000000000 --- a/vendor/go.etcd.io/etcd/wal/doc.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package wal provides an implementation of a write ahead log that is used by -etcd. - -A WAL is created at a particular directory and is made up of a number of -segmented WAL files. Inside of each file the raft state and entries are appended -to it with the Save method: - - metadata := []byte{} - w, err := wal.Create("/var/lib/etcd", metadata) - ... - err := w.Save(s, ents) - -After saving a raft snapshot to disk, SaveSnapshot method should be called to -record it. So WAL can match with the saved snapshot when restarting. - - err := w.SaveSnapshot(walpb.Snapshot{Index: 10, Term: 2}) - -When a user has finished using a WAL it must be closed: - - w.Close() - -Each WAL file is a stream of WAL records. A WAL record is a length field and a wal record -protobuf. The record protobuf contains a CRC, a type, and a data payload. The length field is a -64-bit packed structure holding the length of the remaining logical record data in its lower -56 bits and its physical padding in the first three bits of the most significant byte. Each -record is 8-byte aligned so that the length field is never torn. The CRC contains the CRC32 -value of all record protobufs preceding the current record. - -WAL files are placed inside of the directory in the following format: -$seq-$index.wal - -The first WAL file to be created will be 0000000000000000-0000000000000000.wal -indicating an initial sequence of 0 and an initial raft index of 0. The first -entry written to WAL MUST have raft index 0. - -WAL will cut its current tail wal file if its size exceeds 64MB. This will increment an internal -sequence number and cause a new file to be created. If the last raft index saved -was 0x20 and this is the first time cut has been called on this WAL then the sequence will -increment from 0x0 to 0x1. The new file will be: 0000000000000001-0000000000000021.wal. -If a second cut issues 0x10 entries with incremental index later then the file will be called: -0000000000000002-0000000000000031.wal. - -At a later time a WAL can be opened at a particular snapshot. If there is no -snapshot, an empty snapshot should be passed in. - - w, err := wal.Open("/var/lib/etcd", walpb.Snapshot{Index: 10, Term: 2}) - ... - -The snapshot must have been written to the WAL. - -Additional items cannot be Saved to this WAL until all of the items from the given -snapshot to the end of the WAL are read first: - - metadata, state, ents, err := w.ReadAll() - -This will give you the metadata, the last raft.State and the slice of -raft.Entry items in the log. - -*/ -package wal diff --git a/vendor/go.etcd.io/etcd/wal/encoder.go b/vendor/go.etcd.io/etcd/wal/encoder.go deleted file mode 100644 index e8040b8dff13..000000000000 --- a/vendor/go.etcd.io/etcd/wal/encoder.go +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import ( - "encoding/binary" - "hash" - "io" - "os" - "sync" - - "github.com/coreos/etcd/pkg/crc" - "github.com/coreos/etcd/pkg/ioutil" - "github.com/coreos/etcd/wal/walpb" -) - -// walPageBytes is the alignment for flushing records to the backing Writer. -// It should be a multiple of the minimum sector size so that WAL can safely -// distinguish between torn writes and ordinary data corruption. -const walPageBytes = 8 * minSectorSize - -type encoder struct { - mu sync.Mutex - bw *ioutil.PageWriter - - crc hash.Hash32 - buf []byte - uint64buf []byte -} - -func newEncoder(w io.Writer, prevCrc uint32, pageOffset int) *encoder { - return &encoder{ - bw: ioutil.NewPageWriter(w, walPageBytes, pageOffset), - crc: crc.New(prevCrc, crcTable), - // 1MB buffer - buf: make([]byte, 1024*1024), - uint64buf: make([]byte, 8), - } -} - -// newFileEncoder creates a new encoder with current file offset for the page writer. -func newFileEncoder(f *os.File, prevCrc uint32) (*encoder, error) { - offset, err := f.Seek(0, io.SeekCurrent) - if err != nil { - return nil, err - } - return newEncoder(f, prevCrc, int(offset)), nil -} - -func (e *encoder) encode(rec *walpb.Record) error { - e.mu.Lock() - defer e.mu.Unlock() - - e.crc.Write(rec.Data) - rec.Crc = e.crc.Sum32() - var ( - data []byte - err error - n int - ) - - if rec.Size() > len(e.buf) { - data, err = rec.Marshal() - if err != nil { - return err - } - } else { - n, err = rec.MarshalTo(e.buf) - if err != nil { - return err - } - data = e.buf[:n] - } - - lenField, padBytes := encodeFrameSize(len(data)) - if err = writeUint64(e.bw, lenField, e.uint64buf); err != nil { - return err - } - - if padBytes != 0 { - data = append(data, make([]byte, padBytes)...) - } - _, err = e.bw.Write(data) - return err -} - -func encodeFrameSize(dataBytes int) (lenField uint64, padBytes int) { - lenField = uint64(dataBytes) - // force 8 byte alignment so length never gets a torn write - padBytes = (8 - (dataBytes % 8)) % 8 - if padBytes != 0 { - lenField |= uint64(0x80|padBytes) << 56 - } - return lenField, padBytes -} - -func (e *encoder) flush() error { - e.mu.Lock() - defer e.mu.Unlock() - return e.bw.Flush() -} - -func writeUint64(w io.Writer, n uint64, buf []byte) error { - // http://golang.org/src/encoding/binary/binary.go - binary.LittleEndian.PutUint64(buf, n) - _, err := w.Write(buf) - return err -} diff --git a/vendor/go.etcd.io/etcd/wal/file_pipeline.go b/vendor/go.etcd.io/etcd/wal/file_pipeline.go deleted file mode 100644 index 3a1c57c1c960..000000000000 --- a/vendor/go.etcd.io/etcd/wal/file_pipeline.go +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import ( - "fmt" - "os" - "path/filepath" - - "github.com/coreos/etcd/pkg/fileutil" -) - -// filePipeline pipelines allocating disk space -type filePipeline struct { - // dir to put files - dir string - // size of files to make, in bytes - size int64 - // count number of files generated - count int - - filec chan *fileutil.LockedFile - errc chan error - donec chan struct{} -} - -func newFilePipeline(dir string, fileSize int64) *filePipeline { - fp := &filePipeline{ - dir: dir, - size: fileSize, - filec: make(chan *fileutil.LockedFile), - errc: make(chan error, 1), - donec: make(chan struct{}), - } - go fp.run() - return fp -} - -// Open returns a fresh file for writing. Rename the file before calling -// Open again or there will be file collisions. -func (fp *filePipeline) Open() (f *fileutil.LockedFile, err error) { - select { - case f = <-fp.filec: - case err = <-fp.errc: - } - return f, err -} - -func (fp *filePipeline) Close() error { - close(fp.donec) - return <-fp.errc -} - -func (fp *filePipeline) alloc() (f *fileutil.LockedFile, err error) { - // count % 2 so this file isn't the same as the one last published - fpath := filepath.Join(fp.dir, fmt.Sprintf("%d.tmp", fp.count%2)) - if f, err = fileutil.LockFile(fpath, os.O_CREATE|os.O_WRONLY, fileutil.PrivateFileMode); err != nil { - return nil, err - } - if err = fileutil.Preallocate(f.File, fp.size, true); err != nil { - plog.Errorf("failed to allocate space when creating new wal file (%v)", err) - f.Close() - return nil, err - } - fp.count++ - return f, nil -} - -func (fp *filePipeline) run() { - defer close(fp.errc) - for { - f, err := fp.alloc() - if err != nil { - fp.errc <- err - return - } - select { - case fp.filec <- f: - case <-fp.donec: - os.Remove(f.Name()) - f.Close() - return - } - } -} diff --git a/vendor/go.etcd.io/etcd/wal/metrics.go b/vendor/go.etcd.io/etcd/wal/metrics.go deleted file mode 100644 index 9e089d380f9b..000000000000 --- a/vendor/go.etcd.io/etcd/wal/metrics.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import "github.com/prometheus/client_golang/prometheus" - -var ( - syncDurations = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "disk", - Name: "wal_fsync_duration_seconds", - Help: "The latency distributions of fsync called by wal.", - Buckets: prometheus.ExponentialBuckets(0.001, 2, 14), - }) -) - -func init() { - prometheus.MustRegister(syncDurations) -} diff --git a/vendor/go.etcd.io/etcd/wal/repair.go b/vendor/go.etcd.io/etcd/wal/repair.go deleted file mode 100644 index 091036b57b9a..000000000000 --- a/vendor/go.etcd.io/etcd/wal/repair.go +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import ( - "io" - "os" - "path/filepath" - - "github.com/coreos/etcd/pkg/fileutil" - "github.com/coreos/etcd/wal/walpb" -) - -// Repair tries to repair ErrUnexpectedEOF in the -// last wal file by truncating. -func Repair(dirpath string) bool { - f, err := openLast(dirpath) - if err != nil { - return false - } - defer f.Close() - - rec := &walpb.Record{} - decoder := newDecoder(f) - for { - lastOffset := decoder.lastOffset() - err := decoder.decode(rec) - switch err { - case nil: - // update crc of the decoder when necessary - switch rec.Type { - case crcType: - crc := decoder.crc.Sum32() - // current crc of decoder must match the crc of the record. - // do no need to match 0 crc, since the decoder is a new one at this case. - if crc != 0 && rec.Validate(crc) != nil { - return false - } - decoder.updateCRC(rec.Crc) - } - continue - case io.EOF: - return true - case io.ErrUnexpectedEOF: - plog.Noticef("repairing %v", f.Name()) - bf, bferr := os.Create(f.Name() + ".broken") - if bferr != nil { - plog.Errorf("could not repair %v, failed to create backup file", f.Name()) - return false - } - defer bf.Close() - - if _, err = f.Seek(0, io.SeekStart); err != nil { - plog.Errorf("could not repair %v, failed to read file", f.Name()) - return false - } - - if _, err = io.Copy(bf, f); err != nil { - plog.Errorf("could not repair %v, failed to copy file", f.Name()) - return false - } - - if err = f.Truncate(int64(lastOffset)); err != nil { - plog.Errorf("could not repair %v, failed to truncate file", f.Name()) - return false - } - if err = fileutil.Fsync(f.File); err != nil { - plog.Errorf("could not repair %v, failed to sync file", f.Name()) - return false - } - return true - default: - plog.Errorf("could not repair error (%v)", err) - return false - } - } -} - -// openLast opens the last wal file for read and write. -func openLast(dirpath string) (*fileutil.LockedFile, error) { - names, err := readWalNames(dirpath) - if err != nil { - return nil, err - } - last := filepath.Join(dirpath, names[len(names)-1]) - return fileutil.LockFile(last, os.O_RDWR, fileutil.PrivateFileMode) -} diff --git a/vendor/go.etcd.io/etcd/wal/util.go b/vendor/go.etcd.io/etcd/wal/util.go deleted file mode 100644 index 5c56e228872d..000000000000 --- a/vendor/go.etcd.io/etcd/wal/util.go +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import ( - "errors" - "fmt" - "strings" - - "github.com/coreos/etcd/pkg/fileutil" -) - -var ( - badWalName = errors.New("bad wal name") -) - -func Exist(dirpath string) bool { - names, err := fileutil.ReadDir(dirpath) - if err != nil { - return false - } - return len(names) != 0 -} - -// searchIndex returns the last array index of names whose raft index section is -// equal to or smaller than the given index. -// The given names MUST be sorted. -func searchIndex(names []string, index uint64) (int, bool) { - for i := len(names) - 1; i >= 0; i-- { - name := names[i] - _, curIndex, err := parseWalName(name) - if err != nil { - plog.Panicf("parse correct name should never fail: %v", err) - } - if index >= curIndex { - return i, true - } - } - return -1, false -} - -// names should have been sorted based on sequence number. -// isValidSeq checks whether seq increases continuously. -func isValidSeq(names []string) bool { - var lastSeq uint64 - for _, name := range names { - curSeq, _, err := parseWalName(name) - if err != nil { - plog.Panicf("parse correct name should never fail: %v", err) - } - if lastSeq != 0 && lastSeq != curSeq-1 { - return false - } - lastSeq = curSeq - } - return true -} -func readWalNames(dirpath string) ([]string, error) { - names, err := fileutil.ReadDir(dirpath) - if err != nil { - return nil, err - } - wnames := checkWalNames(names) - if len(wnames) == 0 { - return nil, ErrFileNotFound - } - return wnames, nil -} - -func checkWalNames(names []string) []string { - wnames := make([]string, 0) - for _, name := range names { - if _, _, err := parseWalName(name); err != nil { - // don't complain about left over tmp files - if !strings.HasSuffix(name, ".tmp") { - plog.Warningf("ignored file %v in wal", name) - } - continue - } - wnames = append(wnames, name) - } - return wnames -} - -func parseWalName(str string) (seq, index uint64, err error) { - if !strings.HasSuffix(str, ".wal") { - return 0, 0, badWalName - } - _, err = fmt.Sscanf(str, "%016x-%016x.wal", &seq, &index) - return seq, index, err -} - -func walName(seq, index uint64) string { - return fmt.Sprintf("%016x-%016x.wal", seq, index) -} diff --git a/vendor/go.etcd.io/etcd/wal/wal.go b/vendor/go.etcd.io/etcd/wal/wal.go deleted file mode 100644 index ef63b52ccbcd..000000000000 --- a/vendor/go.etcd.io/etcd/wal/wal.go +++ /dev/null @@ -1,772 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import ( - "bytes" - "errors" - "fmt" - "hash/crc32" - "io" - "os" - "path/filepath" - "sync" - "time" - - "github.com/coreos/etcd/pkg/fileutil" - "github.com/coreos/etcd/pkg/pbutil" - "github.com/coreos/etcd/raft" - "github.com/coreos/etcd/raft/raftpb" - "github.com/coreos/etcd/wal/walpb" - - "github.com/coreos/pkg/capnslog" -) - -const ( - metadataType int64 = iota + 1 - entryType - stateType - crcType - snapshotType - - // warnSyncDuration is the amount of time allotted to an fsync before - // logging a warning - warnSyncDuration = time.Second -) - -var ( - // SegmentSizeBytes is the preallocated size of each wal segment file. - // The actual size might be larger than this. In general, the default - // value should be used, but this is defined as an exported variable - // so that tests can set a different segment size. - SegmentSizeBytes int64 = 64 * 1000 * 1000 // 64MB - - plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "wal") - - ErrMetadataConflict = errors.New("wal: conflicting metadata found") - ErrFileNotFound = errors.New("wal: file not found") - ErrCRCMismatch = errors.New("wal: crc mismatch") - ErrSnapshotMismatch = errors.New("wal: snapshot mismatch") - ErrSnapshotNotFound = errors.New("wal: snapshot not found") - crcTable = crc32.MakeTable(crc32.Castagnoli) -) - -// WAL is a logical representation of the stable storage. -// WAL is either in read mode or append mode but not both. -// A newly created WAL is in append mode, and ready for appending records. -// A just opened WAL is in read mode, and ready for reading records. -// The WAL will be ready for appending after reading out all the previous records. -type WAL struct { - dir string // the living directory of the underlay files - - // dirFile is a fd for the wal directory for syncing on Rename - dirFile *os.File - - metadata []byte // metadata recorded at the head of each WAL - state raftpb.HardState // hardstate recorded at the head of WAL - - start walpb.Snapshot // snapshot to start reading - decoder *decoder // decoder to decode records - readClose func() error // closer for decode reader - - mu sync.Mutex - enti uint64 // index of the last entry saved to the wal - encoder *encoder // encoder to encode records - - locks []*fileutil.LockedFile // the locked files the WAL holds (the name is increasing) - fp *filePipeline -} - -// Create creates a WAL ready for appending records. The given metadata is -// recorded at the head of each WAL file, and can be retrieved with ReadAll. -func Create(dirpath string, metadata []byte) (*WAL, error) { - if Exist(dirpath) { - return nil, os.ErrExist - } - - // keep temporary wal directory so WAL initialization appears atomic - tmpdirpath := filepath.Clean(dirpath) + ".tmp" - if fileutil.Exist(tmpdirpath) { - if err := os.RemoveAll(tmpdirpath); err != nil { - return nil, err - } - } - if err := fileutil.CreateDirAll(tmpdirpath); err != nil { - return nil, err - } - - p := filepath.Join(tmpdirpath, walName(0, 0)) - f, err := fileutil.LockFile(p, os.O_WRONLY|os.O_CREATE, fileutil.PrivateFileMode) - if err != nil { - return nil, err - } - if _, err = f.Seek(0, io.SeekEnd); err != nil { - return nil, err - } - if err = fileutil.Preallocate(f.File, SegmentSizeBytes, true); err != nil { - return nil, err - } - - w := &WAL{ - dir: dirpath, - metadata: metadata, - } - w.encoder, err = newFileEncoder(f.File, 0) - if err != nil { - return nil, err - } - w.locks = append(w.locks, f) - if err = w.saveCrc(0); err != nil { - return nil, err - } - if err = w.encoder.encode(&walpb.Record{Type: metadataType, Data: metadata}); err != nil { - return nil, err - } - if err = w.SaveSnapshot(walpb.Snapshot{}); err != nil { - return nil, err - } - - if w, err = w.renameWal(tmpdirpath); err != nil { - return nil, err - } - - // directory was renamed; sync parent dir to persist rename - pdir, perr := fileutil.OpenDir(filepath.Dir(w.dir)) - if perr != nil { - return nil, perr - } - if perr = fileutil.Fsync(pdir); perr != nil { - return nil, perr - } - if perr = pdir.Close(); err != nil { - return nil, perr - } - - return w, nil -} - -func (w *WAL) renameWal(tmpdirpath string) (*WAL, error) { - if err := os.RemoveAll(w.dir); err != nil { - return nil, err - } - // On non-Windows platforms, hold the lock while renaming. Releasing - // the lock and trying to reacquire it quickly can be flaky because - // it's possible the process will fork to spawn a process while this is - // happening. The fds are set up as close-on-exec by the Go runtime, - // but there is a window between the fork and the exec where another - // process holds the lock. - if err := os.Rename(tmpdirpath, w.dir); err != nil { - if _, ok := err.(*os.LinkError); ok { - return w.renameWalUnlock(tmpdirpath) - } - return nil, err - } - w.fp = newFilePipeline(w.dir, SegmentSizeBytes) - df, err := fileutil.OpenDir(w.dir) - w.dirFile = df - return w, err -} - -func (w *WAL) renameWalUnlock(tmpdirpath string) (*WAL, error) { - // rename of directory with locked files doesn't work on windows/cifs; - // close the WAL to release the locks so the directory can be renamed. - plog.Infof("releasing file lock to rename %q to %q", tmpdirpath, w.dir) - w.Close() - if err := os.Rename(tmpdirpath, w.dir); err != nil { - return nil, err - } - // reopen and relock - newWAL, oerr := Open(w.dir, walpb.Snapshot{}) - if oerr != nil { - return nil, oerr - } - if _, _, _, err := newWAL.ReadAll(); err != nil { - newWAL.Close() - return nil, err - } - return newWAL, nil -} - -// Open opens the WAL at the given snap. -// The snap SHOULD have been previously saved to the WAL, or the following -// ReadAll will fail. -// The returned WAL is ready to read and the first record will be the one after -// the given snap. The WAL cannot be appended to before reading out all of its -// previous records. -func Open(dirpath string, snap walpb.Snapshot) (*WAL, error) { - w, err := openAtIndex(dirpath, snap, true) - if err != nil { - return nil, err - } - if w.dirFile, err = fileutil.OpenDir(w.dir); err != nil { - return nil, err - } - return w, nil -} - -// OpenForRead only opens the wal files for read. -// Write on a read only wal panics. -func OpenForRead(dirpath string, snap walpb.Snapshot) (*WAL, error) { - return openAtIndex(dirpath, snap, false) -} - -func openAtIndex(dirpath string, snap walpb.Snapshot, write bool) (*WAL, error) { - names, nameIndex, err := selectWALFiles(dirpath, snap) - if err != nil { - return nil, err - } - - rs, ls, closer, err := openWALFiles(dirpath, names, nameIndex, write) - if err != nil { - return nil, err - } - - // create a WAL ready for reading - w := &WAL{ - dir: dirpath, - start: snap, - decoder: newDecoder(rs...), - readClose: closer, - locks: ls, - } - - if write { - // write reuses the file descriptors from read; don't close so - // WAL can append without dropping the file lock - w.readClose = nil - if _, _, err := parseWalName(filepath.Base(w.tail().Name())); err != nil { - closer() - return nil, err - } - w.fp = newFilePipeline(w.dir, SegmentSizeBytes) - } - - return w, nil -} - -func selectWALFiles(dirpath string, snap walpb.Snapshot) ([]string, int, error) { - names, err := readWalNames(dirpath) - if err != nil { - return nil, -1, err - } - - nameIndex, ok := searchIndex(names, snap.Index) - if !ok || !isValidSeq(names[nameIndex:]) { - err = ErrFileNotFound - return nil, -1, err - } - - return names, nameIndex, nil -} - -func openWALFiles(dirpath string, names []string, nameIndex int, write bool) ([]io.Reader, []*fileutil.LockedFile, func() error, error) { - rcs := make([]io.ReadCloser, 0) - rs := make([]io.Reader, 0) - ls := make([]*fileutil.LockedFile, 0) - for _, name := range names[nameIndex:] { - p := filepath.Join(dirpath, name) - if write { - l, err := fileutil.TryLockFile(p, os.O_RDWR, fileutil.PrivateFileMode) - if err != nil { - closeAll(rcs...) - return nil, nil, nil, err - } - ls = append(ls, l) - rcs = append(rcs, l) - } else { - rf, err := os.OpenFile(p, os.O_RDONLY, fileutil.PrivateFileMode) - if err != nil { - closeAll(rcs...) - return nil, nil, nil, err - } - ls = append(ls, nil) - rcs = append(rcs, rf) - } - rs = append(rs, rcs[len(rcs)-1]) - } - - closer := func() error { return closeAll(rcs...) } - - return rs, ls, closer, nil -} - -// ReadAll reads out records of the current WAL. -// If opened in write mode, it must read out all records until EOF. Or an error -// will be returned. -// If opened in read mode, it will try to read all records if possible. -// If it cannot read out the expected snap, it will return ErrSnapshotNotFound. -// If loaded snap doesn't match with the expected one, it will return -// all the records and error ErrSnapshotMismatch. -// TODO: detect not-last-snap error. -// TODO: maybe loose the checking of match. -// After ReadAll, the WAL will be ready for appending new records. -func (w *WAL) ReadAll() (metadata []byte, state raftpb.HardState, ents []raftpb.Entry, err error) { - w.mu.Lock() - defer w.mu.Unlock() - - rec := &walpb.Record{} - decoder := w.decoder - - var match bool - for err = decoder.decode(rec); err == nil; err = decoder.decode(rec) { - switch rec.Type { - case entryType: - e := mustUnmarshalEntry(rec.Data) - if e.Index > w.start.Index { - ents = append(ents[:e.Index-w.start.Index-1], e) - } - w.enti = e.Index - case stateType: - state = mustUnmarshalState(rec.Data) - case metadataType: - if metadata != nil && !bytes.Equal(metadata, rec.Data) { - state.Reset() - return nil, state, nil, ErrMetadataConflict - } - metadata = rec.Data - case crcType: - crc := decoder.crc.Sum32() - // current crc of decoder must match the crc of the record. - // do no need to match 0 crc, since the decoder is a new one at this case. - if crc != 0 && rec.Validate(crc) != nil { - state.Reset() - return nil, state, nil, ErrCRCMismatch - } - decoder.updateCRC(rec.Crc) - case snapshotType: - var snap walpb.Snapshot - pbutil.MustUnmarshal(&snap, rec.Data) - if snap.Index == w.start.Index { - if snap.Term != w.start.Term { - state.Reset() - return nil, state, nil, ErrSnapshotMismatch - } - match = true - } - default: - state.Reset() - return nil, state, nil, fmt.Errorf("unexpected block type %d", rec.Type) - } - } - - switch w.tail() { - case nil: - // We do not have to read out all entries in read mode. - // The last record maybe a partial written one, so - // ErrunexpectedEOF might be returned. - if err != io.EOF && err != io.ErrUnexpectedEOF { - state.Reset() - return nil, state, nil, err - } - default: - // We must read all of the entries if WAL is opened in write mode. - if err != io.EOF { - state.Reset() - return nil, state, nil, err - } - // decodeRecord() will return io.EOF if it detects a zero record, - // but this zero record may be followed by non-zero records from - // a torn write. Overwriting some of these non-zero records, but - // not all, will cause CRC errors on WAL open. Since the records - // were never fully synced to disk in the first place, it's safe - // to zero them out to avoid any CRC errors from new writes. - if _, err = w.tail().Seek(w.decoder.lastOffset(), io.SeekStart); err != nil { - return nil, state, nil, err - } - if err = fileutil.ZeroToEnd(w.tail().File); err != nil { - return nil, state, nil, err - } - } - - err = nil - if !match { - err = ErrSnapshotNotFound - } - - // close decoder, disable reading - if w.readClose != nil { - w.readClose() - w.readClose = nil - } - w.start = walpb.Snapshot{} - - w.metadata = metadata - - if w.tail() != nil { - // create encoder (chain crc with the decoder), enable appending - w.encoder, err = newFileEncoder(w.tail().File, w.decoder.lastCRC()) - if err != nil { - return - } - } - w.decoder = nil - - return metadata, state, ents, err -} - -// Verify reads through the given WAL and verifies that it is not corrupted. -// It creates a new decoder to read through the records of the given WAL. -// It does not conflict with any open WAL, but it is recommended not to -// call this function after opening the WAL for writing. -// If it cannot read out the expected snap, it will return ErrSnapshotNotFound. -// If the loaded snap doesn't match with the expected one, it will -// return error ErrSnapshotMismatch. -func Verify(walDir string, snap walpb.Snapshot) error { - var metadata []byte - var err error - var match bool - - rec := &walpb.Record{} - - names, nameIndex, err := selectWALFiles(walDir, snap) - if err != nil { - return err - } - - // open wal files in read mode, so that there is no conflict - // when the same WAL is opened elsewhere in write mode - rs, _, closer, err := openWALFiles(walDir, names, nameIndex, false) - if err != nil { - return err - } - - // create a new decoder from the readers on the WAL files - decoder := newDecoder(rs...) - - for err = decoder.decode(rec); err == nil; err = decoder.decode(rec) { - switch rec.Type { - case metadataType: - if metadata != nil && !bytes.Equal(metadata, rec.Data) { - return ErrMetadataConflict - } - metadata = rec.Data - case crcType: - crc := decoder.crc.Sum32() - // Current crc of decoder must match the crc of the record. - // We need not match 0 crc, since the decoder is a new one at this point. - if crc != 0 && rec.Validate(crc) != nil { - return ErrCRCMismatch - } - decoder.updateCRC(rec.Crc) - case snapshotType: - var loadedSnap walpb.Snapshot - pbutil.MustUnmarshal(&loadedSnap, rec.Data) - if loadedSnap.Index == snap.Index { - if loadedSnap.Term != snap.Term { - return ErrSnapshotMismatch - } - match = true - } - // We ignore all entry and state type records as these - // are not necessary for validating the WAL contents - case entryType: - case stateType: - default: - return fmt.Errorf("unexpected block type %d", rec.Type) - } - } - - if closer != nil { - closer() - } - - // We do not have to read out all the WAL entries - // as the decoder is opened in read mode. - if err != io.EOF && err != io.ErrUnexpectedEOF { - return err - } - - if !match { - return ErrSnapshotNotFound - } - - return nil -} - -// cut closes current file written and creates a new one ready to append. -// cut first creates a temp wal file and writes necessary headers into it. -// Then cut atomically rename temp wal file to a wal file. -func (w *WAL) cut() error { - // close old wal file; truncate to avoid wasting space if an early cut - off, serr := w.tail().Seek(0, io.SeekCurrent) - if serr != nil { - return serr - } - if err := w.tail().Truncate(off); err != nil { - return err - } - if err := w.sync(); err != nil { - return err - } - - fpath := filepath.Join(w.dir, walName(w.seq()+1, w.enti+1)) - - // create a temp wal file with name sequence + 1, or truncate the existing one - newTail, err := w.fp.Open() - if err != nil { - return err - } - - // update writer and save the previous crc - w.locks = append(w.locks, newTail) - prevCrc := w.encoder.crc.Sum32() - w.encoder, err = newFileEncoder(w.tail().File, prevCrc) - if err != nil { - return err - } - if err = w.saveCrc(prevCrc); err != nil { - return err - } - if err = w.encoder.encode(&walpb.Record{Type: metadataType, Data: w.metadata}); err != nil { - return err - } - if err = w.saveState(&w.state); err != nil { - return err - } - // atomically move temp wal file to wal file - if err = w.sync(); err != nil { - return err - } - - off, err = w.tail().Seek(0, io.SeekCurrent) - if err != nil { - return err - } - - if err = os.Rename(newTail.Name(), fpath); err != nil { - return err - } - if err = fileutil.Fsync(w.dirFile); err != nil { - return err - } - - // reopen newTail with its new path so calls to Name() match the wal filename format - newTail.Close() - - if newTail, err = fileutil.LockFile(fpath, os.O_WRONLY, fileutil.PrivateFileMode); err != nil { - return err - } - if _, err = newTail.Seek(off, io.SeekStart); err != nil { - return err - } - - w.locks[len(w.locks)-1] = newTail - - prevCrc = w.encoder.crc.Sum32() - w.encoder, err = newFileEncoder(w.tail().File, prevCrc) - if err != nil { - return err - } - - plog.Infof("segmented wal file %v is created", fpath) - return nil -} - -func (w *WAL) sync() error { - if w.encoder != nil { - if err := w.encoder.flush(); err != nil { - return err - } - } - start := time.Now() - err := fileutil.Fdatasync(w.tail().File) - - duration := time.Since(start) - if duration > warnSyncDuration { - plog.Warningf("sync duration of %v, expected less than %v", duration, warnSyncDuration) - } - syncDurations.Observe(duration.Seconds()) - - return err -} - -// ReleaseLockTo releases the locks, which has smaller index than the given index -// except the largest one among them. -// For example, if WAL is holding lock 1,2,3,4,5,6, ReleaseLockTo(4) will release -// lock 1,2 but keep 3. ReleaseLockTo(5) will release 1,2,3 but keep 4. -func (w *WAL) ReleaseLockTo(index uint64) error { - w.mu.Lock() - defer w.mu.Unlock() - - if len(w.locks) == 0 { - return nil - } - - var smaller int - found := false - - for i, l := range w.locks { - _, lockIndex, err := parseWalName(filepath.Base(l.Name())) - if err != nil { - return err - } - if lockIndex >= index { - smaller = i - 1 - found = true - break - } - } - - // if no lock index is greater than the release index, we can - // release lock up to the last one(excluding). - if !found { - smaller = len(w.locks) - 1 - } - - if smaller <= 0 { - return nil - } - - for i := 0; i < smaller; i++ { - if w.locks[i] == nil { - continue - } - w.locks[i].Close() - } - w.locks = w.locks[smaller:] - - return nil -} - -func (w *WAL) Close() error { - w.mu.Lock() - defer w.mu.Unlock() - - if w.fp != nil { - w.fp.Close() - w.fp = nil - } - - if w.tail() != nil { - if err := w.sync(); err != nil { - return err - } - } - for _, l := range w.locks { - if l == nil { - continue - } - if err := l.Close(); err != nil { - plog.Errorf("failed to unlock during closing wal: %s", err) - } - } - - return w.dirFile.Close() -} - -func (w *WAL) saveEntry(e *raftpb.Entry) error { - // TODO: add MustMarshalTo to reduce one allocation. - b := pbutil.MustMarshal(e) - rec := &walpb.Record{Type: entryType, Data: b} - if err := w.encoder.encode(rec); err != nil { - return err - } - w.enti = e.Index - return nil -} - -func (w *WAL) saveState(s *raftpb.HardState) error { - if raft.IsEmptyHardState(*s) { - return nil - } - w.state = *s - b := pbutil.MustMarshal(s) - rec := &walpb.Record{Type: stateType, Data: b} - return w.encoder.encode(rec) -} - -func (w *WAL) Save(st raftpb.HardState, ents []raftpb.Entry) error { - w.mu.Lock() - defer w.mu.Unlock() - - // short cut, do not call sync - if raft.IsEmptyHardState(st) && len(ents) == 0 { - return nil - } - - mustSync := raft.MustSync(st, w.state, len(ents)) - - // TODO(xiangli): no more reference operator - for i := range ents { - if err := w.saveEntry(&ents[i]); err != nil { - return err - } - } - if err := w.saveState(&st); err != nil { - return err - } - - curOff, err := w.tail().Seek(0, io.SeekCurrent) - if err != nil { - return err - } - if curOff < SegmentSizeBytes { - if mustSync { - return w.sync() - } - return nil - } - - return w.cut() -} - -func (w *WAL) SaveSnapshot(e walpb.Snapshot) error { - b := pbutil.MustMarshal(&e) - - w.mu.Lock() - defer w.mu.Unlock() - - rec := &walpb.Record{Type: snapshotType, Data: b} - if err := w.encoder.encode(rec); err != nil { - return err - } - // update enti only when snapshot is ahead of last index - if w.enti < e.Index { - w.enti = e.Index - } - return w.sync() -} - -func (w *WAL) saveCrc(prevCrc uint32) error { - return w.encoder.encode(&walpb.Record{Type: crcType, Crc: prevCrc}) -} - -func (w *WAL) tail() *fileutil.LockedFile { - if len(w.locks) > 0 { - return w.locks[len(w.locks)-1] - } - return nil -} - -func (w *WAL) seq() uint64 { - t := w.tail() - if t == nil { - return 0 - } - seq, _, err := parseWalName(filepath.Base(t.Name())) - if err != nil { - plog.Fatalf("bad wal name %s (%v)", t.Name(), err) - } - return seq -} - -func closeAll(rcs ...io.ReadCloser) error { - for _, f := range rcs { - if err := f.Close(); err != nil { - return err - } - } - return nil -} diff --git a/vendor/go.etcd.io/etcd/wal/walpb/record.go b/vendor/go.etcd.io/etcd/wal/walpb/record.go deleted file mode 100644 index 30a05e0c139c..000000000000 --- a/vendor/go.etcd.io/etcd/wal/walpb/record.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package walpb - -import "errors" - -var ( - ErrCRCMismatch = errors.New("walpb: crc mismatch") -) - -func (rec *Record) Validate(crc uint32) error { - if rec.Crc == crc { - return nil - } - rec.Reset() - return ErrCRCMismatch -} diff --git a/vendor/go.etcd.io/etcd/wal/walpb/record.pb.go b/vendor/go.etcd.io/etcd/wal/walpb/record.pb.go deleted file mode 100644 index 3ce63ddc2eb6..000000000000 --- a/vendor/go.etcd.io/etcd/wal/walpb/record.pb.go +++ /dev/null @@ -1,504 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: record.proto - -/* - Package walpb is a generated protocol buffer package. - - It is generated from these files: - record.proto - - It has these top-level messages: - Record - Snapshot -*/ -package walpb - -import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - - io "io" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type Record struct { - Type int64 `protobuf:"varint,1,opt,name=type" json:"type"` - Crc uint32 `protobuf:"varint,2,opt,name=crc" json:"crc"` - Data []byte `protobuf:"bytes,3,opt,name=data" json:"data,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Record) Reset() { *m = Record{} } -func (m *Record) String() string { return proto.CompactTextString(m) } -func (*Record) ProtoMessage() {} -func (*Record) Descriptor() ([]byte, []int) { return fileDescriptorRecord, []int{0} } - -type Snapshot struct { - Index uint64 `protobuf:"varint,1,opt,name=index" json:"index"` - Term uint64 `protobuf:"varint,2,opt,name=term" json:"term"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Snapshot) Reset() { *m = Snapshot{} } -func (m *Snapshot) String() string { return proto.CompactTextString(m) } -func (*Snapshot) ProtoMessage() {} -func (*Snapshot) Descriptor() ([]byte, []int) { return fileDescriptorRecord, []int{1} } - -func init() { - proto.RegisterType((*Record)(nil), "walpb.Record") - proto.RegisterType((*Snapshot)(nil), "walpb.Snapshot") -} -func (m *Record) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Record) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRecord(dAtA, i, uint64(m.Type)) - dAtA[i] = 0x10 - i++ - i = encodeVarintRecord(dAtA, i, uint64(m.Crc)) - if m.Data != nil { - dAtA[i] = 0x1a - i++ - i = encodeVarintRecord(dAtA, i, uint64(len(m.Data))) - i += copy(dAtA[i:], m.Data) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *Snapshot) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Snapshot) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRecord(dAtA, i, uint64(m.Index)) - dAtA[i] = 0x10 - i++ - i = encodeVarintRecord(dAtA, i, uint64(m.Term)) - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func encodeVarintRecord(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *Record) Size() (n int) { - var l int - _ = l - n += 1 + sovRecord(uint64(m.Type)) - n += 1 + sovRecord(uint64(m.Crc)) - if m.Data != nil { - l = len(m.Data) - n += 1 + l + sovRecord(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *Snapshot) Size() (n int) { - var l int - _ = l - n += 1 + sovRecord(uint64(m.Index)) - n += 1 + sovRecord(uint64(m.Term)) - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func sovRecord(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozRecord(x uint64) (n int) { - return sovRecord(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Record) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Record: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Record: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= (int64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Crc", wireType) - } - m.Crc = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Crc |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRecord - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRecord(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRecord - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Snapshot) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Snapshot: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Snapshot: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) - } - m.Index = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Index |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType) - } - m.Term = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Term |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRecord(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRecord - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipRecord(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRecord - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRecord - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRecord - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthRecord - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRecord - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipRecord(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthRecord = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowRecord = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("record.proto", fileDescriptorRecord) } - -var fileDescriptorRecord = []byte{ - // 186 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x29, 0x4a, 0x4d, 0xce, - 0x2f, 0x4a, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x2d, 0x4f, 0xcc, 0x29, 0x48, 0x92, - 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x8b, 0xe8, 0x83, 0x58, 0x10, 0x49, 0x25, 0x3f, 0x2e, 0xb6, - 0x20, 0xb0, 0x62, 0x21, 0x09, 0x2e, 0x96, 0x92, 0xca, 0x82, 0x54, 0x09, 0x46, 0x05, 0x46, 0x0d, - 0x66, 0x27, 0x96, 0x13, 0xf7, 0xe4, 0x19, 0x82, 0xc0, 0x22, 0x42, 0x62, 0x5c, 0xcc, 0xc9, 0x45, - 0xc9, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0xbc, 0x50, 0x09, 0x90, 0x80, 0x90, 0x10, 0x17, 0x4b, 0x4a, - 0x62, 0x49, 0xa2, 0x04, 0xb3, 0x02, 0xa3, 0x06, 0x4f, 0x10, 0x98, 0xad, 0xe4, 0xc0, 0xc5, 0x11, - 0x9c, 0x97, 0x58, 0x50, 0x9c, 0x91, 0x5f, 0x22, 0x24, 0xc5, 0xc5, 0x9a, 0x99, 0x97, 0x92, 0x5a, - 0x01, 0x36, 0x92, 0x05, 0xaa, 0x13, 0x22, 0x04, 0xb6, 0x2d, 0xb5, 0x28, 0x17, 0x6c, 0x28, 0x0b, - 0xdc, 0xb6, 0xd4, 0xa2, 0x5c, 0x27, 0x91, 0x13, 0x0f, 0xe5, 0x18, 0x4e, 0x3c, 0x92, 0x63, 0xbc, - 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x19, 0x8f, 0xe5, 0x18, 0x00, 0x01, 0x00, 0x00, - 0xff, 0xff, 0x7f, 0x5e, 0x5c, 0x46, 0xd3, 0x00, 0x00, 0x00, -}