Skip to content

Commit

Permalink
sync.go linter fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ucwong committed Jul 18, 2020
1 parent d89bd08 commit 3a4eeb6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (tfs *TorrentFS) Stop() error {
return nil
}
// Wait until every goroutine terminates.
tfs.monitor.Stop()
tfs.monitor.stop()
return nil
}

Expand Down
56 changes: 28 additions & 28 deletions sync.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package torrentfs

// Copyright 2020 The CortexTheseus Authors
// This file is part of the CortexTheseus library.
//
Expand All @@ -13,7 +15,6 @@
//
// You should have received a copy of the GNU Lesser General Public License
// along with the CortexTheseus library. If not, see <http://www.gnu.org/licenses/>.
package torrentfs

import (
"errors"
Expand Down Expand Up @@ -123,12 +124,12 @@ func NewMonitor(flag *Config, cache, compress, listen bool) (*Monitor, error) {
tMana.Search(k, int64(v), true)
}

m.IndexInit()
m.indexInit()

return m, nil
}

func (m *Monitor) IndexCheck() error {
func (m *Monitor) indexCheck() error {
log.Info("Loading storage data ... ...", "latest", m.fs.LastListenBlockNumber, "checkpoint", m.fs.CheckPoint, "root", m.fs.Root(), "version", m.fs.Version(), "current", m.currentNumber)
genesis, err := m.rpcBlockByNumber(0)
if err != nil {
Expand Down Expand Up @@ -159,7 +160,7 @@ func (m *Monitor) IndexCheck() error {
return nil
}

func (m *Monitor) IndexInit() error {
func (m *Monitor) indexInit() error {
fileMap := make(map[metainfo.Hash]*types.FileInfo)
for _, file := range m.fs.Files() {
if f, ok := fileMap[file.Meta.InfoHash]; ok {
Expand Down Expand Up @@ -188,11 +189,11 @@ func (m *Monitor) IndexInit() error {
IsCreate: true,
})
if file.LeftSize == 0 {
seed += 1
seed++
} else if file.Meta.RawSize == file.LeftSize && file.LeftSize > 0 {
pending += 1
pending++
} else if file.Meta.RawSize > file.LeftSize && file.LeftSize > 0 {
pause += 1
pause++
}
}
log.Info("Storage current state", "total", len(m.fs.Files()), "dis", len(fileMap), "seed", seed, "pause", pause, "pending", pending, "capcity", common.StorageSize(capcity), "blocks", len(m.fs.Blocks()), "txs", m.fs.Txs())
Expand Down Expand Up @@ -346,15 +347,14 @@ func (m *Monitor) parseFileMeta(tx *types.Transaction, meta *types.FileMeta, b *
if err != nil {
log.Warn("Create file failed", "err", err)
return err
} else {
if update && op == 1 {
log.Debug("Create new file", "ih", meta.InfoHash, "op", op)
m.dl.UpdateTorrent(types.FlowControlMeta{
InfoHash: meta.InfoHash,
BytesRequested: 0,
IsCreate: true,
})
}
}
if update && op == 1 {
log.Debug("Create new file", "ih", meta.InfoHash, "op", op)
m.dl.UpdateTorrent(types.FlowControlMeta{
InfoHash: meta.InfoHash,
BytesRequested: 0,
IsCreate: true,
})
}
return nil
}
Expand Down Expand Up @@ -453,7 +453,7 @@ func (m *Monitor) exit() {
}
}

func (m *Monitor) Stop() {
func (m *Monitor) stop() {
m.closeOnce.Do(func() {
if atomic.LoadInt32(&(m.terminated)) == 1 {
return
Expand Down Expand Up @@ -517,7 +517,7 @@ func (m *Monitor) startWork() error {
m.currentBlock()
m.startNumber = uint64(math.Min(float64(m.fs.LastListenBlockNumber), float64(m.currentNumber))) // ? m.currentNumber:m.fs.LastListenBlockNumber

if err := m.IndexCheck(); err != nil {
if err := m.indexCheck(); err != nil {
return err
}
//m.wg.Add(1)
Expand Down Expand Up @@ -599,7 +599,7 @@ func (m *Monitor) currentBlock() (uint64, error) {
return uint64(currentNumber), nil
}

func (m *Monitor) Skip(i uint64) bool {
func (m *Monitor) skip(i uint64) bool {
if len(m.ckp.Skips) == 0 || i > m.ckp.Skips[len(m.ckp.Skips)-1].To || i < m.ckp.Skips[0].From {
return false
}
Expand Down Expand Up @@ -652,7 +652,7 @@ func (m *Monitor) syncLastBlock() uint64 {
break
}

if m.ckp != nil && m.Skip(i) {
if m.ckp != nil && m.skip(i) {
//m.lastNumber = i - 1
i++
continue
Expand All @@ -678,8 +678,8 @@ func (m *Monitor) syncLastBlock() uint64 {
m.lastNumber = i - 1
if maxNumber-minNumber > delay/2 {
elapsed := time.Duration(mclock.Now()) - time.Duration(start)
elapsed_a := time.Duration(mclock.Now()) - time.Duration(m.start)
log.Warn("Chain segment frozen", "from", minNumber, "to", i, "range", uint64(i-minNumber), "current", uint64(m.currentNumber), "progress", float64(i)/float64(m.currentNumber), "last", m.lastNumber, "elapsed", common.PrettyDuration(elapsed), "bps", float64(i-minNumber)*1000*1000*1000/float64(elapsed), "bps_a", float64(maxNumber)*1000*1000*1000/float64(elapsed_a), "cap", len(m.taskCh))
elapsedA := time.Duration(mclock.Now()) - time.Duration(m.start)
log.Warn("Chain segment frozen", "from", minNumber, "to", i, "range", uint64(i-minNumber), "current", uint64(m.currentNumber), "progress", float64(i)/float64(m.currentNumber), "last", m.lastNumber, "elapsed", common.PrettyDuration(elapsed), "bps", float64(i-minNumber)*1000*1000*1000/float64(elapsed), "bps_a", float64(maxNumber)*1000*1000*1000/float64(elapsedA), "cap", len(m.taskCh))
}
return 0
}*/
Expand All @@ -704,8 +704,8 @@ func (m *Monitor) syncLastBlock() uint64 {
m.lastNumber = i - 1
if maxNumber-minNumber > delay/2 {
elapsed := time.Duration(mclock.Now()) - time.Duration(start)
elapsed_a := time.Duration(mclock.Now()) - time.Duration(m.start)
log.Warn("Chain segment frozen", "from", minNumber, "to", i, "range", uint64(i-minNumber), "current", uint64(m.currentNumber), "progress", float64(i)/float64(m.currentNumber), "last", m.lastNumber, "elapsed", common.PrettyDuration(elapsed), "bps", float64(i-minNumber)*1000*1000*1000/float64(elapsed), "bps_a", float64(maxNumber)*1000*1000*1000/float64(elapsed_a), "cap", len(m.taskCh))
elapsedA := time.Duration(mclock.Now()) - time.Duration(m.start)
log.Warn("Chain segment frozen", "from", minNumber, "to", i, "range", uint64(i-minNumber), "current", uint64(m.currentNumber), "progress", float64(i)/float64(m.currentNumber), "last", m.lastNumber, "elapsed", common.PrettyDuration(elapsed), "bps", float64(i-minNumber)*1000*1000*1000/float64(elapsed), "bps_a", float64(maxNumber)*1000*1000*1000/float64(elapsedA), "cap", len(m.taskCh))
}
return 0
}*/
Expand All @@ -715,8 +715,8 @@ func (m *Monitor) syncLastBlock() uint64 {
//if maxNumber-minNumber > batch-1 {
if maxNumber-minNumber > delay {
elapsed := time.Duration(mclock.Now()) - time.Duration(start)
elapsed_a := time.Duration(mclock.Now()) - time.Duration(m.start)
log.Info("Chain segment frozen", "from", minNumber, "to", maxNumber, "range", uint64(maxNumber-minNumber), "current", uint64(m.currentNumber), "progress", float64(maxNumber)/float64(m.currentNumber), "last", m.lastNumber, "elapsed", common.PrettyDuration(elapsed), "bps", float64(maxNumber-minNumber)*1000*1000*1000/float64(elapsed), "bps_a", float64(maxNumber)*1000*1000*1000/float64(elapsed_a), "duration", common.PrettyDuration(elapsed_a))
elapsedA := time.Duration(mclock.Now()) - time.Duration(m.start)
log.Info("Chain segment frozen", "from", minNumber, "to", maxNumber, "range", uint64(maxNumber-minNumber), "current", uint64(m.currentNumber), "progress", float64(maxNumber)/float64(m.currentNumber), "last", m.lastNumber, "elapsed", common.PrettyDuration(elapsed), "bps", float64(maxNumber-minNumber)*1000*1000*1000/float64(elapsed), "bps_a", float64(maxNumber)*1000*1000*1000/float64(elapsedA), "duration", common.PrettyDuration(elapsedA))
}
return uint64(maxNumber - minNumber)
}
Expand All @@ -725,8 +725,8 @@ func (m *Monitor) solve(block *types.Block) error {
i := block.Number
if i%65536 == 0 {
defer func() {
elapsed_a := time.Duration(mclock.Now()) - time.Duration(m.start)
log.Info(ProgressBar(int64(i), int64(m.currentNumber), ""), "start", m.startNumber, "max", uint64(m.currentNumber), "last", m.lastNumber, "cur", i, "bps", math.Abs(float64(i)-float64(m.startNumber))*1000*1000*1000/float64(elapsed_a), "elapsed", common.PrettyDuration(elapsed_a), "scope", m.scope, "db", common.PrettyDuration(m.fs.Metrics()), "blocks", len(m.fs.Blocks()), "txs", m.fs.Txs(), "files", len(m.fs.Files()), "root", m.fs.Root())
elapsedA := time.Duration(mclock.Now()) - time.Duration(m.start)
log.Info(ProgressBar(int64(i), int64(m.currentNumber), ""), "start", m.startNumber, "max", uint64(m.currentNumber), "last", m.lastNumber, "cur", i, "bps", math.Abs(float64(i)-float64(m.startNumber))*1000*1000*1000/float64(elapsedA), "elapsed", common.PrettyDuration(elapsedA), "scope", m.scope, "db", common.PrettyDuration(m.fs.Metrics()), "blocks", len(m.fs.Blocks()), "txs", m.fs.Txs(), "files", len(m.fs.Files()), "root", m.fs.Root())
m.fs.SkipPrint()
}()
}
Expand Down

0 comments on commit 3a4eeb6

Please sign in to comment.