mirror of
https://github.com/datarhei/core.git
synced 2025-10-06 00:17:07 +08:00
Fix missing mutex for log history
This commit is contained in:
@@ -122,6 +122,7 @@ type parser struct {
|
|||||||
progress sync.RWMutex
|
progress sync.RWMutex
|
||||||
prelude sync.RWMutex
|
prelude sync.RWMutex
|
||||||
log sync.RWMutex
|
log sync.RWMutex
|
||||||
|
logHistory sync.RWMutex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,12 +169,15 @@ func New(config Config) Parser {
|
|||||||
|
|
||||||
p.lock.log.Lock()
|
p.lock.log.Lock()
|
||||||
p.log = ring.New(p.logLines)
|
p.log = ring.New(p.logLines)
|
||||||
|
p.lock.log.Unlock()
|
||||||
|
|
||||||
|
p.lock.logHistory.Lock()
|
||||||
historyLength := p.logHistoryLength + p.logMinimalHistoryLength
|
historyLength := p.logHistoryLength + p.logMinimalHistoryLength
|
||||||
|
|
||||||
if historyLength > 0 {
|
if historyLength > 0 {
|
||||||
p.logHistory = ring.New(historyLength)
|
p.logHistory = ring.New(historyLength)
|
||||||
}
|
}
|
||||||
|
p.lock.logHistory.Unlock()
|
||||||
|
|
||||||
if p.collector == nil {
|
if p.collector == nil {
|
||||||
p.collector = session.NewNullCollector()
|
p.collector = session.NewNullCollector()
|
||||||
@@ -191,8 +195,6 @@ func New(config Config) Parser {
|
|||||||
p.logpatterns.patterns = append(p.logpatterns.patterns, r)
|
p.logpatterns.patterns = append(p.logpatterns.patterns, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.lock.log.Unlock()
|
|
||||||
|
|
||||||
p.ResetStats()
|
p.ResetStats()
|
||||||
|
|
||||||
return p
|
return p
|
||||||
@@ -827,6 +829,9 @@ type ReportHistorySearchResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) SearchReportHistory(state string, from, to *time.Time) []ReportHistorySearchResult {
|
func (p *parser) SearchReportHistory(state string, from, to *time.Time) []ReportHistorySearchResult {
|
||||||
|
p.lock.logHistory.RLock()
|
||||||
|
defer p.lock.logHistory.RUnlock()
|
||||||
|
|
||||||
result := []ReportHistorySearchResult{}
|
result := []ReportHistorySearchResult{}
|
||||||
|
|
||||||
p.logHistory.Do(func(l interface{}) {
|
p.logHistory.Do(func(l interface{}) {
|
||||||
@@ -868,6 +873,7 @@ func (p *parser) storeReportHistory(state string, usage Usage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
report := p.Report()
|
report := p.Report()
|
||||||
|
progress := p.Progress()
|
||||||
|
|
||||||
p.ResetLog()
|
p.ResetLog()
|
||||||
|
|
||||||
@@ -875,11 +881,14 @@ func (p *parser) storeReportHistory(state string, usage Usage) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.lock.logHistory.Lock()
|
||||||
|
defer p.lock.logHistory.Unlock()
|
||||||
|
|
||||||
h := ReportHistoryEntry{
|
h := ReportHistoryEntry{
|
||||||
Report: report,
|
Report: report,
|
||||||
ExitedAt: time.Now(),
|
ExitedAt: time.Now(),
|
||||||
ExitState: state,
|
ExitState: state,
|
||||||
Progress: p.Progress(),
|
Progress: progress,
|
||||||
Usage: usage,
|
Usage: usage,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -922,6 +931,9 @@ func (p *parser) Report() Report {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) ReportHistory() []ReportHistoryEntry {
|
func (p *parser) ReportHistory() []ReportHistoryEntry {
|
||||||
|
p.lock.logHistory.RLock()
|
||||||
|
defer p.lock.logHistory.RUnlock()
|
||||||
|
|
||||||
var history = []ReportHistoryEntry{}
|
var history = []ReportHistoryEntry{}
|
||||||
|
|
||||||
p.logHistory.Do(func(l interface{}) {
|
p.logHistory.Do(func(l interface{}) {
|
||||||
@@ -936,11 +948,17 @@ func (p *parser) ReportHistory() []ReportHistoryEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) TransferReportHistory(dst Parser) error {
|
func (p *parser) TransferReportHistory(dst Parser) error {
|
||||||
|
p.lock.logHistory.RLock()
|
||||||
|
defer p.lock.logHistory.RUnlock()
|
||||||
|
|
||||||
pp, ok := dst.(*parser)
|
pp, ok := dst.(*parser)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("the target parser is not of the required type")
|
return fmt.Errorf("the target parser is not of the required type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pp.lock.logHistory.Lock()
|
||||||
|
defer pp.lock.logHistory.Unlock()
|
||||||
|
|
||||||
p.logHistory.Do(func(l interface{}) {
|
p.logHistory.Do(func(l interface{}) {
|
||||||
if l == nil {
|
if l == nil {
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user