-
Notifications
You must be signed in to change notification settings - Fork 199
/
snapshotStatistics.go
57 lines (46 loc) · 1.13 KB
/
snapshotStatistics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package state
import (
"sync"
"time"
)
type snapshotStatistics struct {
numNodes uint64
numDataTries uint64
trieSize uint64
startTime time.Time
wg *sync.WaitGroup
mutex sync.RWMutex
}
func newSnapshotStatistics(delta int) *snapshotStatistics {
wg := &sync.WaitGroup{}
wg.Add(delta)
return &snapshotStatistics{
wg: wg,
startTime: time.Now(),
}
}
// AddSize will add the given size to the trie size counter
func (ss *snapshotStatistics) AddSize(size uint64) {
ss.mutex.Lock()
defer ss.mutex.Unlock()
ss.numNodes++
ss.trieSize += size
}
// SnapshotFinished marks the ending of a snapshot goroutine
func (ss *snapshotStatistics) SnapshotFinished() {
ss.wg.Done()
}
// NewSnapshotStarted marks the starting of a new snapshot goroutine
func (ss *snapshotStatistics) NewSnapshotStarted() {
ss.wg.Add(1)
}
// NewDataTrie increases the data Tries counter
func (ss *snapshotStatistics) NewDataTrie() {
ss.mutex.Lock()
defer ss.mutex.Unlock()
ss.numDataTries++
}
// WaitForSnapshotsToFinish will wait until the waitGroup counter is zero
func (ss *snapshotStatistics) WaitForSnapshotsToFinish() {
ss.wg.Wait()
}