Adjust and rename blockProgressLogger -> nameProgressLogger. Use it in makeNameHashNext() to track progress.
This commit is contained in:
parent
b859832907
commit
2b7f065855
3 changed files with 49 additions and 42 deletions
|
@ -49,6 +49,9 @@ type ClaimTrie struct {
|
||||||
|
|
||||||
// Registrered cleanup functions which are invoked in the Close() in reverse order.
|
// Registrered cleanup functions which are invoked in the Close() in reverse order.
|
||||||
cleanups []func() error
|
cleanups []func() error
|
||||||
|
|
||||||
|
// nameLogger communicates progress of claimtrie rebuild.
|
||||||
|
nameLogger *nameProgressLogger
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg config.Config) (*ClaimTrie, error) {
|
func New(cfg config.Config) (*ClaimTrie, error) {
|
||||||
|
@ -345,15 +348,19 @@ func (ct *ClaimTrie) ResetHeight(height int32) error {
|
||||||
func (ct *ClaimTrie) runFullTrieRebuild(names [][]byte, interrupt <-chan struct{}) {
|
func (ct *ClaimTrie) runFullTrieRebuild(names [][]byte, interrupt <-chan struct{}) {
|
||||||
var nhns chan NameHashNext
|
var nhns chan NameHashNext
|
||||||
if names == nil {
|
if names == nil {
|
||||||
node.LogOnce("Building the entire claim trie in RAM...")
|
node.Log("Building the entire claim trie in RAM...")
|
||||||
|
ct.nameLogger = newNameProgressLogger("Processed", node.GetLogger())
|
||||||
nhns = ct.makeNameHashNext(nil, true, interrupt)
|
nhns = ct.makeNameHashNext(nil, true, interrupt)
|
||||||
} else {
|
} else {
|
||||||
|
ct.nameLogger = nil
|
||||||
nhns = ct.makeNameHashNext(names, false, interrupt)
|
nhns = ct.makeNameHashNext(names, false, interrupt)
|
||||||
}
|
}
|
||||||
|
|
||||||
for nhn := range nhns {
|
for nhn := range nhns {
|
||||||
ct.merkleTrie.Update(nhn.Name, nhn.Hash, false)
|
ct.merkleTrie.Update(nhn.Name, nhn.Hash, false)
|
||||||
|
if ct.nameLogger != nil {
|
||||||
|
ct.nameLogger.LogName(nhn.Name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,53 +2,51 @@
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package netsync
|
package claimtrie
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btclog"
|
"github.com/btcsuite/btclog"
|
||||||
btcutil "github.com/lbryio/lbcutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// blockProgressLogger provides periodic logging for other services in order
|
// nameProgressLogger provides periodic logging for other services in order
|
||||||
// to show users progress of certain "actions" involving some or all current
|
// to show users progress of certain "actions" involving some or all current
|
||||||
// blocks. Ex: syncing to best chain, indexing all blocks, etc.
|
// claim names. Ex: rebuilding claimtrie.
|
||||||
type blockProgressLogger struct {
|
type nameProgressLogger struct {
|
||||||
receivedLogBlocks int64
|
totalLogName int64
|
||||||
receivedLogTx int64
|
recentLogName int64
|
||||||
lastBlockLogTime time.Time
|
lastLogNameTime time.Time
|
||||||
|
|
||||||
subsystemLogger btclog.Logger
|
subsystemLogger btclog.Logger
|
||||||
progressAction string
|
progressAction string
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// newBlockProgressLogger returns a new block progress logger.
|
// newNameProgressLogger returns a new name progress logger.
|
||||||
// The progress message is templated as follows:
|
// The progress message is templated as follows:
|
||||||
// {progressAction} {numProcessed} {blocks|block} in the last {timePeriod}
|
// {progressAction} {numProcessed} {names|name} in the last {timePeriod} (total {totalProcessed})
|
||||||
// ({numTxs}, height {lastBlockHeight}, {lastBlockTimeStamp})
|
func newNameProgressLogger(progressMessage string, logger btclog.Logger) *nameProgressLogger {
|
||||||
func newBlockProgressLogger(progressMessage string, logger btclog.Logger) *blockProgressLogger {
|
return &nameProgressLogger{
|
||||||
return &blockProgressLogger{
|
lastLogNameTime: time.Now(),
|
||||||
lastBlockLogTime: time.Now(),
|
progressAction: progressMessage,
|
||||||
progressAction: progressMessage,
|
subsystemLogger: logger,
|
||||||
subsystemLogger: logger,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// LogBlockHeight logs a new block height as an information message to show
|
// LogName logs a new name as an information message to show progress
|
||||||
// progress to the user. In order to prevent spam, it limits logging to one
|
// to the user. In order to prevent spam, it limits logging to one
|
||||||
// message every 10 seconds with duration and totals included.
|
// message every 10 seconds with duration and totals included.
|
||||||
func (b *blockProgressLogger) LogBlockHeight(block *btcutil.Block) {
|
func (n *nameProgressLogger) LogName(name []byte) {
|
||||||
b.Lock()
|
n.Lock()
|
||||||
defer b.Unlock()
|
defer n.Unlock()
|
||||||
|
|
||||||
b.receivedLogBlocks++
|
n.totalLogName++
|
||||||
b.receivedLogTx += int64(len(block.MsgBlock().Transactions))
|
n.recentLogName++
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
duration := now.Sub(b.lastBlockLogTime)
|
duration := now.Sub(n.lastLogNameTime)
|
||||||
if duration < time.Second*10 {
|
if duration < time.Second*10 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -57,24 +55,18 @@ func (b *blockProgressLogger) LogBlockHeight(block *btcutil.Block) {
|
||||||
durationMillis := int64(duration / time.Millisecond)
|
durationMillis := int64(duration / time.Millisecond)
|
||||||
tDuration := 10 * time.Millisecond * time.Duration(durationMillis/10)
|
tDuration := 10 * time.Millisecond * time.Duration(durationMillis/10)
|
||||||
|
|
||||||
// Log information about new block height.
|
// Log information about progress.
|
||||||
blockStr := "blocks"
|
nameStr := "names"
|
||||||
if b.receivedLogBlocks == 1 {
|
if n.recentLogName == 1 {
|
||||||
blockStr = "block"
|
nameStr = "name"
|
||||||
}
|
}
|
||||||
txStr := "transactions"
|
n.subsystemLogger.Infof("%s %d %s in the last %s (total %d)",
|
||||||
if b.receivedLogTx == 1 {
|
n.progressAction, n.recentLogName, nameStr, tDuration, n.totalLogName)
|
||||||
txStr = "transaction"
|
|
||||||
}
|
|
||||||
b.subsystemLogger.Infof("%s %d %s in the last %s (%d %s, height %d, %s)",
|
|
||||||
b.progressAction, b.receivedLogBlocks, blockStr, tDuration, b.receivedLogTx,
|
|
||||||
txStr, block.Height(), block.MsgBlock().Header.Timestamp)
|
|
||||||
|
|
||||||
b.receivedLogBlocks = 0
|
n.recentLogName = 0
|
||||||
b.receivedLogTx = 0
|
n.lastLogNameTime = now
|
||||||
b.lastBlockLogTime = now
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *blockProgressLogger) SetLastLogTime(time time.Time) {
|
func (n *nameProgressLogger) SetLastLogTime(time time.Time) {
|
||||||
b.lastBlockLogTime = time
|
n.lastLogNameTime = time
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,10 @@ func UseLogger(logger btclog.Logger) {
|
||||||
log = logger
|
log = logger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetLogger() btclog.Logger {
|
||||||
|
return log
|
||||||
|
}
|
||||||
|
|
||||||
var loggedStrings = map[string]bool{} // is this gonna get too large?
|
var loggedStrings = map[string]bool{} // is this gonna get too large?
|
||||||
var loggedStringsMutex sync.Mutex
|
var loggedStringsMutex sync.Mutex
|
||||||
|
|
||||||
|
@ -42,6 +46,10 @@ func LogOnce(s string) {
|
||||||
log.Info(s)
|
log.Info(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Log(s string) {
|
||||||
|
log.Info(s)
|
||||||
|
}
|
||||||
|
|
||||||
func Warn(s string) {
|
func Warn(s string) {
|
||||||
log.Warn(s)
|
log.Warn(s)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue