代码拉取完成,页面将自动刷新
/*
Copyright IBM Corp All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package etcdraft
import (
"sync/atomic"
"github.com/hyperledger/fabric-protos-go/orderer/etcdraft"
"gitee.com/bupt-zkjc/fabric/common/flogging"
"gitee.com/bupt-zkjc/fabric/common/metrics"
"gitee.com/bupt-zkjc/fabric/protoutil"
"go.etcd.io/etcd/raft"
)
// Tracker periodically poll Raft Status, and update disseminator
// so that status is populated to followers.
type Tracker struct {
id uint64
sender *Disseminator
gauge metrics.Gauge
active *atomic.Value
counter int
logger *flogging.FabricLogger
}
func (t *Tracker) Check(status *raft.Status) {
// leaderless
if status.Lead == raft.None {
t.gauge.Set(0)
t.active.Store([]uint64{})
return
}
// follower
if status.RaftState == raft.StateFollower {
return
}
// leader
current := []uint64{t.id}
for id, progress := range status.Progress {
if id == t.id {
// `RecentActive` for leader's Progress is expected to be false in current implementation of etcd/raft,
// but because not marking the leader recently active might be considered a bug and fixed in the future,
// we explicitly defend against adding the leader, to avoid potential duplicate
continue
}
if progress.RecentActive {
current = append(current, id)
}
}
last := t.active.Load().([]uint64)
t.active.Store(current)
if len(current) != len(last) {
t.counter = 0
return
}
// consider active nodes to be stable if it holds for 3 iterations, to avoid glitch
// in this value when the recent status is reset on leader election intervals
if t.counter < 3 {
t.counter++
return
}
t.counter = 0
t.logger.Debugf("Current active nodes in cluster are: %+v", current)
t.gauge.Set(float64(len(current)))
metadata := protoutil.MarshalOrPanic(&etcdraft.ClusterMetadata{ActiveNodes: current})
t.sender.UpdateMetadata(metadata)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。