Rename nameProgressLogger -> claimProgressLogger and tweak log message.
This commit is contained in:
parent
67ce441247
commit
2312b0fbd3
2 changed files with 17 additions and 17 deletions
|
@ -50,8 +50,8 @@ 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.
|
// claimLogger communicates progress of claimtrie rebuild.
|
||||||
nameLogger *nameProgressLogger
|
claimLogger *claimProgressLogger
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg config.Config) (*ClaimTrie, error) {
|
func New(cfg config.Config) (*ClaimTrie, error) {
|
||||||
|
@ -349,17 +349,17 @@ func (ct *ClaimTrie) runFullTrieRebuild(names [][]byte, interrupt <-chan struct{
|
||||||
var nhns chan NameHashNext
|
var nhns chan NameHashNext
|
||||||
if names == nil {
|
if names == nil {
|
||||||
node.Log("Building the entire claim trie in RAM...")
|
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)
|
nhns = ct.makeNameHashNext(nil, true, interrupt)
|
||||||
} else {
|
} else {
|
||||||
ct.nameLogger = nil
|
ct.claimLogger = 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 {
|
if ct.claimLogger != nil {
|
||||||
ct.nameLogger.LogName(nhn.Name)
|
ct.claimLogger.LogName(nhn.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,10 @@ import (
|
||||||
"github.com/btcsuite/btclog"
|
"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
|
// to show users progress of certain "actions" involving some or all current
|
||||||
// claim names. Ex: rebuilding claimtrie.
|
// claim names. Ex: rebuilding claimtrie.
|
||||||
type nameProgressLogger struct {
|
type claimProgressLogger struct {
|
||||||
totalLogName int64
|
totalLogName int64
|
||||||
recentLogName int64
|
recentLogName int64
|
||||||
lastLogNameTime time.Time
|
lastLogNameTime time.Time
|
||||||
|
@ -24,21 +24,21 @@ type nameProgressLogger struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// newNameProgressLogger returns a new name progress logger.
|
// newClaimProgressLogger returns a new name progress logger.
|
||||||
// The progress message is templated as follows:
|
// The progress message is templated as follows:
|
||||||
// {progressAction} {numProcessed} {names|name} in the last {timePeriod} (total {totalProcessed})
|
// {progressAction} {numProcessed} {names|name} in the last {timePeriod} (total {totalProcessed})
|
||||||
func newNameProgressLogger(progressMessage string, logger btclog.Logger) *nameProgressLogger {
|
func newClaimProgressLogger(progressMessage string, logger btclog.Logger) *claimProgressLogger {
|
||||||
return &nameProgressLogger{
|
return &claimProgressLogger{
|
||||||
lastLogNameTime: time.Now(),
|
lastLogNameTime: time.Now(),
|
||||||
progressAction: progressMessage,
|
progressAction: progressMessage,
|
||||||
subsystemLogger: logger,
|
subsystemLogger: logger,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// LogName logs a new name as an information message to show progress
|
// 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
|
// to the user. In order to prevent spam, it limits logging to one message
|
||||||
// message every 10 seconds with duration and totals included.
|
// every 10 seconds with duration and totals included.
|
||||||
func (n *nameProgressLogger) LogName(name []byte) {
|
func (n *claimProgressLogger) LogName(name []byte) {
|
||||||
n.Lock()
|
n.Lock()
|
||||||
defer n.Unlock()
|
defer n.Unlock()
|
||||||
|
|
||||||
|
@ -60,13 +60,13 @@ func (n *nameProgressLogger) LogName(name []byte) {
|
||||||
if n.recentLogName == 1 {
|
if n.recentLogName == 1 {
|
||||||
nameStr = "name"
|
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.progressAction, n.recentLogName, nameStr, tDuration, n.totalLogName)
|
||||||
|
|
||||||
n.recentLogName = 0
|
n.recentLogName = 0
|
||||||
n.lastLogNameTime = now
|
n.lastLogNameTime = now
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *nameProgressLogger) SetLastLogTime(time time.Time) {
|
func (n *claimProgressLogger) SetLastLogTime(time time.Time) {
|
||||||
n.lastLogNameTime = time
|
n.lastLogNameTime = time
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue