1// Copyright 2015 The etcd Authors 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package rafthttp 16 17import ( 18 "github.com/coreos/etcd/pkg/types" 19 "github.com/coreos/etcd/raft/raftpb" 20) 21 22type remote struct { 23 id types.ID 24 status *peerStatus 25 pipeline *pipeline 26} 27 28func startRemote(tr *Transport, urls types.URLs, id types.ID) *remote { 29 picker := newURLPicker(urls) 30 status := newPeerStatus(id) 31 pipeline := &pipeline{ 32 peerID: id, 33 tr: tr, 34 picker: picker, 35 status: status, 36 raft: tr.Raft, 37 errorc: tr.ErrorC, 38 } 39 pipeline.start() 40 41 return &remote{ 42 id: id, 43 status: status, 44 pipeline: pipeline, 45 } 46} 47 48func (g *remote) send(m raftpb.Message) { 49 select { 50 case g.pipeline.msgc <- m: 51 default: 52 if g.status.isActive() { 53 plog.MergeWarningf("dropped internal raft message to %s since sending buffer is full (bad/overloaded network)", g.id) 54 } 55 plog.Debugf("dropped %s to %s since sending buffer is full", m.Type, g.id) 56 sentFailures.WithLabelValues(types.ID(m.To).String()).Inc() 57 } 58} 59 60func (g *remote) stop() { 61 g.pipeline.stop() 62} 63 64func (g *remote) Pause() { 65 g.stop() 66} 67 68func (g *remote) Resume() { 69 g.pipeline.start() 70} 71