OSDN Git Service
(root)
/
bytom
/
vapor.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
10fc1df
)
Revert "fk"
author
HAOYUatHZ
<haoyu@protonmail.com>
Mon, 19 Aug 2019 07:49:05 +0000
(15:49 +0800)
committer
HAOYUatHZ
<haoyu@protonmail.com>
Mon, 19 Aug 2019 07:49:05 +0000
(15:49 +0800)
This reverts commit
a24d9d6d08105f3db232c0a1c54e2a466ce779fd
.
toolbar/precog/monitor/connection.go
patch
|
blob
|
history
toolbar/precog/monitor/discover.go
patch
|
blob
|
history
toolbar/precog/monitor/monitor.go
patch
|
blob
|
history
toolbar/precog/monitor/stats.go
patch
|
blob
|
history
diff --git
a/toolbar/precog/monitor/connection.go
b/toolbar/precog/monitor/connection.go
index
366cbd8
..
9f716ad
100644
(file)
--- a/
toolbar/precog/monitor/connection.go
+++ b/
toolbar/precog/monitor/connection.go
@@
-20,11
+20,10
@@
func (m *monitor) connectNodesRoutine() {
}
func (m *monitor) dialNodes() error {
}
func (m *monitor) dialNodes() error {
+ // m.Lock()
log.Info("Start to reconnect to nodes...")
log.Info("Start to reconnect to nodes...")
- dbTx := m.db.Begin()
var nodes []*orm.Node
var nodes []*orm.Node
- if err := dbTx.Model(&orm.Node{}).Find(&nodes).Error; err != nil {
- dbTx.Rollback()
+ if err := m.db.Model(&orm.Node{}).Find(&nodes).Error; err != nil {
return err
}
return err
}
@@
-47,6
+46,6
@@
func (m *monitor) dialNodes() error {
// connected peers will be skipped in switch.DialPeers()
m.sw.DialPeers(addresses)
log.Info("DialPeers done.")
// connected peers will be skipped in switch.DialPeers()
m.sw.DialPeers(addresses)
log.Info("DialPeers done.")
-
dbTx.Commit
()
+
// m.Unlock
()
return nil
}
return nil
}
diff --git
a/toolbar/precog/monitor/discover.go
b/toolbar/precog/monitor/discover.go
index
5459688
..
0e9ef47
100644
(file)
--- a/
toolbar/precog/monitor/discover.go
+++ b/
toolbar/precog/monitor/discover.go
@@
-33,18
+33,16
@@
func (m *monitor) collectDiscoveredNodes() {
continue
}
log.Info("discover new node: ", node)
continue
}
log.Info("discover new node: ", node)
-
- dbTx := m.db.Begin()
- if err := m.upSertNode(dbTx, &config.Node{
+ // m.Lock()
+ if err := m.upSertNode(&config.Node{
PublicKey: node.ID.String(),
Host: node.IP.String(),
Port: node.TCP,
}); err != nil {
PublicKey: node.ID.String(),
Host: node.IP.String(),
Port: node.TCP,
}); err != nil {
- dbTx.Rollback()
log.Error(err)
log.Error(err)
- } else {
- nodeMap[node.ID.String()] = node
- dbTx.Commit()
}
}
+
+ nodeMap[node.ID.String()] = node
+ // m.Unlock()
}
}
}
}
diff --git
a/toolbar/precog/monitor/monitor.go
b/toolbar/precog/monitor/monitor.go
index
38010c9
..
4a302f7
100644
(file)
--- a/
toolbar/precog/monitor/monitor.go
+++ b/
toolbar/precog/monitor/monitor.go
@@
-103,16
+103,13
@@
func makePath() (string, error) {
func (m *monitor) Run() {
defer os.RemoveAll(m.nodeCfg.DBPath)
func (m *monitor) Run() {
defer os.RemoveAll(m.nodeCfg.DBPath)
- dbTx := m.db.Begin()
var seeds []string
for _, node := range m.cfg.Nodes {
seeds = append(seeds, fmt.Sprintf("%s:%d", node.Host, node.Port))
var seeds []string
for _, node := range m.cfg.Nodes {
seeds = append(seeds, fmt.Sprintf("%s:%d", node.Host, node.Port))
- if err := m.upSertNode(dbTx, &node); err != nil {
- dbTx.Rollback()
+ if err := m.upSertNode(&node); err != nil {
log.Error(err)
}
}
log.Error(err)
}
}
- dbTx.Commit()
m.nodeCfg.P2P.Seeds = strings.Join(seeds, ",")
if err := m.makeSwitch(); err != nil {
log.Fatal(err)
m.nodeCfg.P2P.Seeds = strings.Join(seeds, ",")
if err := m.makeSwitch(); err != nil {
log.Fatal(err)
@@
-180,7
+177,7
@@
func (m *monitor) checkStatusRoutine() {
bestHeight := uint64(0)
ticker := time.NewTicker(time.Duration(m.cfg.CheckFreqSeconds) * time.Second)
for range ticker.C {
bestHeight := uint64(0)
ticker := time.NewTicker(time.Duration(m.cfg.CheckFreqSeconds) * time.Second)
for range ticker.C {
-
dbTx := m.db.Begin
()
+
// m.Lock
()
log.Info("connected peers: ", m.sw.GetPeers().List())
for _, peer := range m.sw.GetPeers().List() {
log.Info("connected peers: ", m.sw.GetPeers().List())
for _, peer := range m.sw.GetPeers().List() {
@@
-203,6
+200,8
@@
func (m *monitor) checkStatusRoutine() {
if peerInfo.Height > bestHeight {
bestHeight = peerInfo.Height
}
if peerInfo.Height > bestHeight {
bestHeight = peerInfo.Height
}
+
+ m.savePeerInfo(peerInfo)
}
log.Info("bestHeight: ", bestHeight)
}
log.Info("bestHeight: ", bestHeight)
@@
-221,14
+220,6
@@
func (m *monitor) checkStatusRoutine() {
peers.RemovePeer(p.ID())
}
log.Info("Disonnect all peers.")
peers.RemovePeer(p.ID())
}
log.Info("Disonnect all peers.")
-
- for _, peerInfo := range peers.GetPeerInfos() {
- if err := m.savePeerInfo(dbTx, peerInfo); err != nil {
- dbTx.Rollback()
- log.Error(err)
- break
- }
- }
- dbTx.Commit()
+ // m.Unlock()
}
}
}
}
diff --git
a/toolbar/precog/monitor/stats.go
b/toolbar/precog/monitor/stats.go
index
6943532
..
88c819e
100644
(file)
--- a/
toolbar/precog/monitor/stats.go
+++ b/
toolbar/precog/monitor/stats.go
@@
-21,13
+21,13
@@
import (
// TODO: update lantency, active_time and status
// create or update: https://github.com/jinzhu/gorm/issues/1307
// TODO: update lantency, active_time and status
// create or update: https://github.com/jinzhu/gorm/issues/1307
-func (m *monitor) upSertNode(
dbTx *gorm.DB,
node *config.Node) error {
+func (m *monitor) upSertNode(node *config.Node) error {
if node.XPub != nil {
node.PublicKey = fmt.Sprintf("%v", node.XPub.PublicKey().String())
}
ormNode := &orm.Node{PublicKey: node.PublicKey}
if node.XPub != nil {
node.PublicKey = fmt.Sprintf("%v", node.XPub.PublicKey().String())
}
ormNode := &orm.Node{PublicKey: node.PublicKey}
- if err :=
dbTx
.Where(&orm.Node{PublicKey: node.PublicKey}).First(ormNode).Error; err != nil && err != gorm.ErrRecordNotFound {
+ if err :=
m.db
.Where(&orm.Node{PublicKey: node.PublicKey}).First(ormNode).Error; err != nil && err != gorm.ErrRecordNotFound {
return err
}
return err
}
@@
-39,7
+39,7
@@
func (m *monitor) upSertNode(dbTx *gorm.DB, node *config.Node) error {
}
ormNode.Host = node.Host
ormNode.Port = node.Port
}
ormNode.Host = node.Host
ormNode.Port = node.Port
- return
dbTx
.Where(&orm.Node{PublicKey: ormNode.PublicKey}).
+ return
m.db
.Where(&orm.Node{PublicKey: ormNode.PublicKey}).
Assign(&orm.Node{
Xpub: ormNode.Xpub,
Alias: ormNode.Alias,
Assign(&orm.Node{
Xpub: ormNode.Xpub,
Alias: ormNode.Alias,
@@
-48,14
+48,14
@@
func (m *monitor) upSertNode(dbTx *gorm.DB, node *config.Node) error {
}).FirstOrCreate(ormNode).Error
}
}).FirstOrCreate(ormNode).Error
}
-func (m *monitor) savePeerInfo(
dbTx *gorm.DB,
peerInfo *peers.PeerInfo) error {
+func (m *monitor) savePeerInfo(peerInfo *peers.PeerInfo) error {
xPub := &chainkd.XPub{}
if err := xPub.UnmarshalText([]byte(peerInfo.ID)); err != nil {
return err
}
ormNode := &orm.Node{}
xPub := &chainkd.XPub{}
if err := xPub.UnmarshalText([]byte(peerInfo.ID)); err != nil {
return err
}
ormNode := &orm.Node{}
- if err :=
dbTx
.Model(&orm.Node{}).Where(&orm.Node{PublicKey: xPub.PublicKey().String()}).
+ if err :=
m.db
.Model(&orm.Node{}).Where(&orm.Node{PublicKey: xPub.PublicKey().String()}).
UpdateColumn(&orm.Node{
Alias: peerInfo.Moniker,
Xpub: peerInfo.ID,
UpdateColumn(&orm.Node{
Alias: peerInfo.Moniker,
Xpub: peerInfo.ID,
@@
-74,7
+74,7
@@
func (m *monitor) savePeerInfo(dbTx *gorm.DB, peerInfo *peers.PeerInfo) error {
// PingTimes uint64
// PongTimes uint64
}
// PingTimes uint64
// PongTimes uint64
}
- if err :=
dbTx
.Model(&orm.NodeLiveness{}).Where("node_id = ? AND status != ?", ormNode.ID, common.NodeOfflineStatus).
+ if err :=
m.db
.Model(&orm.NodeLiveness{}).Where("node_id = ? AND status != ?", ormNode.ID, common.NodeOfflineStatus).
UpdateColumn(&orm.NodeLiveness{
BestHeight: ormNodeLiveness.BestHeight,
AvgLantencyMS: ormNodeLiveness.AvgLantencyMS,
UpdateColumn(&orm.NodeLiveness{
BestHeight: ormNodeLiveness.BestHeight,
AvgLantencyMS: ormNodeLiveness.AvgLantencyMS,