• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: コミット

Golang implemented sidechain for Bytom


コミットメタ情報

リビジョン568892ca3bfaa3a8ed32b7fc39c16ed2548595cc (tree)
日時2019-08-19 16:07:25
作者HAOYUatHZ <haoyu@prot...>
コミッターHAOYUatHZ

ログメッセージ

remove locks

変更サマリ

差分

--- a/toolbar/precog/monitor/connection.go
+++ b/toolbar/precog/monitor/connection.go
@@ -20,10 +20,8 @@ func (m *monitor) connectNodesRoutine() {
2020 }
2121
2222 func (m *monitor) dialNodes() error {
23- for m.isConnected() {
24- time.Sleep(5 * time.Second)
25- }
26- log.Info("Start to reconnect to peers...")
23+ // m.Lock()
24+ log.Info("Start to reconnect to nodes...")
2725 var nodes []*orm.Node
2826 if err := m.db.Model(&orm.Node{}).Find(&nodes).Error; err != nil {
2927 return err
@@ -47,7 +45,7 @@ func (m *monitor) dialNodes() error {
4745
4846 // connected peers will be skipped in switch.DialPeers()
4947 m.sw.DialPeers(addresses)
50- m.setConnected()
5148 log.Info("DialPeers done.")
49+ // m.Unlock()
5250 return nil
5351 }
--- a/toolbar/precog/monitor/discover.go
+++ b/toolbar/precog/monitor/discover.go
@@ -33,10 +33,7 @@ func (m *monitor) collectDiscoveredNodes() {
3333 continue
3434 }
3535 log.Info("discover new node: ", node)
36-
37- for m.isConnected() {
38- time.Sleep(1 * time.Second)
39- }
36+ // m.Lock()
4037 if err := m.upSertNode(&config.Node{
4138 PublicKey: node.ID.String(),
4239 Host: node.IP.String(),
@@ -46,5 +43,6 @@ func (m *monitor) collectDiscoveredNodes() {
4643 }
4744
4845 nodeMap[node.ID.String()] = node
46+ // m.Unlock()
4947 }
5048 }
--- a/toolbar/precog/monitor/monitor.go
+++ b/toolbar/precog/monitor/monitor.go
@@ -6,7 +6,7 @@ import (
66 "os"
77 "os/user"
88 "strings"
9- "sync/atomic"
9+ // "sync"
1010 "time"
1111
1212 "github.com/jinzhu/gorm"
@@ -29,6 +29,7 @@ import (
2929 )
3030
3131 type monitor struct {
32+ // *sync.RWMutex
3233 cfg *config.Config
3334 db *gorm.DB
3435 nodeCfg *vaporCfg.Config
@@ -69,6 +70,7 @@ func NewMonitor(cfg *config.Config, db *gorm.DB) *monitor {
6970 }
7071
7172 return &monitor{
73+ // RWMutex: &sync.RWMutex{},
7274 cfg: cfg,
7375 db: db,
7476 nodeCfg: nodeCfg,
@@ -161,10 +163,6 @@ func (m *monitor) prepareReactors(peers *peers.PeerSet) error {
161163 return m.sw.GetSecurity().Start()
162164 }
163165
164-// TODO:
165-// 现象是,时间区间过小时, 会一直有 dial ,但是不能 send业务层 msg
166-// 还不确定是不是死锁,时间调大一点比如15s 就可以正确运行
167-// 想法,自己再另外加锁,或者找到锁住的真正原因
168166 func (m *monitor) checkStatusRoutine() {
169167 peers := peers.NewPeerSet(m.sw)
170168 if err := m.prepareReactors(peers); err != nil {
@@ -179,9 +177,7 @@ func (m *monitor) checkStatusRoutine() {
179177 bestHeight := uint64(0)
180178 ticker := time.NewTicker(time.Duration(m.cfg.CheckFreqSeconds) * time.Second)
181179 for range ticker.C {
182- for !m.isConnected() {
183- time.Sleep(1 * time.Second)
184- }
180+ // m.Lock()
185181 log.Info("connected peers: ", m.sw.GetPeers().List())
186182
187183 for _, peer := range m.sw.GetPeers().List() {
@@ -223,21 +219,7 @@ func (m *monitor) checkStatusRoutine() {
223219
224220 peers.RemovePeer(p.ID())
225221 }
226-
227- m.setDisonnected()
228222 log.Info("Disonnect all peers.")
223+ // m.Unlock()
229224 }
230225 }
231-
232-func (m *monitor) isConnected() bool {
233- atomic.LoadUint32(&m.connected)
234- return m.connected == uint32(1)
235-}
236-
237-func (m *monitor) setConnected() {
238- atomic.StoreUint32(&m.connected, 1)
239-}
240-
241-func (m *monitor) setDisonnected() {
242- atomic.StoreUint32(&m.connected, 0)
243-}
旧リポジトリブラウザで表示