Rename nameProgressLogger -> claimProgressLogger and tweak log message.

This commit is contained in:
Jonathan Moody 2022-06-14 13:38:43 -04:00 committed by Roy Lee
parent 2b7f065855
commit ca9b4e5529
2 changed files with 17 additions and 17 deletions

View file

@ -50,8 +50,8 @@ type ClaimTrie struct {
// Registrered cleanup functions which are invoked in the Close() in reverse order.
cleanups []func() error
// nameLogger communicates progress of claimtrie rebuild.
nameLogger *nameProgressLogger
// claimLogger communicates progress of claimtrie rebuild.
claimLogger *claimProgressLogger
}
func New(cfg config.Config) (*ClaimTrie, error) {
@ -349,17 +349,17 @@ func (ct *ClaimTrie) runFullTrieRebuild(names [][]byte, interrupt <-chan struct{
var nhns chan NameHashNext
if names == nil {
node.Log("Building the entire claim trie in RAM...")
ct.nameLogger = newNameProgressLogger("Processed", node.GetLogger())
ct.claimLogger = newClaimProgressLogger("Processed", node.GetLogger())
nhns = ct.makeNameHashNext(nil, true, interrupt)
} else {
ct.nameLogger = nil
ct.claimLogger = nil
nhns = ct.makeNameHashNext(names, false, interrupt)
}
for nhn := range nhns {
ct.merkleTrie.Update(nhn.Name, nhn.Hash, false)
if ct.nameLogger != nil {
ct.nameLogger.LogName(nhn.Name)
if ct.claimLogger != nil {
ct.claimLogger.LogName(nhn.Name)
}
}
}

View file

@ -11,10 +11,10 @@ import (
"github.com/btcsuite/btclog"
)
// nameProgressLogger provides periodic logging for other services in order
// claimProgressLogger provides periodic logging for other services in order
// to show users progress of certain "actions" involving some or all current
// claim names. Ex: rebuilding claimtrie.
type nameProgressLogger struct {
type claimProgressLogger struct {
totalLogName int64
recentLogName int64
lastLogNameTime time.Time
@ -24,21 +24,21 @@ type nameProgressLogger struct {
sync.Mutex
}
// newNameProgressLogger returns a new name progress logger.
// newClaimProgressLogger returns a new name progress logger.
// The progress message is templated as follows:
// {progressAction} {numProcessed} {names|name} in the last {timePeriod} (total {totalProcessed})
func newNameProgressLogger(progressMessage string, logger btclog.Logger) *nameProgressLogger {
return &nameProgressLogger{
func newClaimProgressLogger(progressMessage string, logger btclog.Logger) *claimProgressLogger {
return &claimProgressLogger{
lastLogNameTime: time.Now(),
progressAction: progressMessage,
subsystemLogger: logger,
}
}
// LogName logs a new name as an information message to show progress
// to the user. In order to prevent spam, it limits logging to one
// message every 10 seconds with duration and totals included.
func (n *nameProgressLogger) LogName(name []byte) {
// LogName logs a new claim name as an information message to show progress
// to the user. In order to prevent spam, it limits logging to one message
// every 10 seconds with duration and totals included.
func (n *claimProgressLogger) LogName(name []byte) {
n.Lock()
defer n.Unlock()
@ -60,13 +60,13 @@ func (n *nameProgressLogger) LogName(name []byte) {
if n.recentLogName == 1 {
nameStr = "name"
}
n.subsystemLogger.Infof("%s %d %s in the last %s (total %d)",
n.subsystemLogger.Infof("%s %d claim %s in the last %s (total %d)",
n.progressAction, n.recentLogName, nameStr, tDuration, n.totalLogName)
n.recentLogName = 0
n.lastLogNameTime = now
}
func (n *nameProgressLogger) SetLastLogTime(time time.Time) {
func (n *claimProgressLogger) SetLastLogTime(time time.Time) {
n.lastLogNameTime = time
}