• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

docker / libnetwork / #3476

pending completion
#3476

push

web-flow
Merge pull request #1919 from fcrisciani/logfix

4 of 4 new or added lines in 1 file covered. (100.0%)

11876 of 27870 relevant lines covered (42.61%)

38611.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.23
/endpoint_cnt.go
1
package libnetwork
2

3
import (
4
        "encoding/json"
5
        "fmt"
6
        "sync"
7

8
        "github.com/docker/libnetwork/datastore"
9
)
10

11
type endpointCnt struct {
12
        n        *network
13
        Count    uint64
14
        dbIndex  uint64
15
        dbExists bool
16
        sync.Mutex
17
}
18

19
const epCntKeyPrefix = "endpoint_count"
20

21
func (ec *endpointCnt) Key() []string {
1,277✔
22
        ec.Lock()
1,277✔
23
        defer ec.Unlock()
1,277✔
24

1,277✔
25
        return []string{epCntKeyPrefix, ec.n.id}
1,277✔
26
}
1,277✔
27

28
func (ec *endpointCnt) KeyPrefix() []string {
529✔
29
        ec.Lock()
529✔
30
        defer ec.Unlock()
529✔
31

529✔
32
        return []string{epCntKeyPrefix, ec.n.id}
529✔
33
}
529✔
34

35
func (ec *endpointCnt) Value() []byte {
127✔
36
        ec.Lock()
127✔
37
        defer ec.Unlock()
127✔
38

127✔
39
        b, err := json.Marshal(ec)
127✔
40
        if err != nil {
127✔
41
                return nil
×
42
        }
×
43
        return b
127✔
44
}
45

46
func (ec *endpointCnt) SetValue(value []byte) error {
101✔
47
        ec.Lock()
101✔
48
        defer ec.Unlock()
101✔
49

101✔
50
        return json.Unmarshal(value, &ec)
101✔
51
}
101✔
52

53
func (ec *endpointCnt) Index() uint64 {
120✔
54
        ec.Lock()
120✔
55
        defer ec.Unlock()
120✔
56
        return ec.dbIndex
120✔
57
}
120✔
58

59
func (ec *endpointCnt) SetIndex(index uint64) {
226✔
60
        ec.Lock()
226✔
61
        ec.dbIndex = index
226✔
62
        ec.dbExists = true
226✔
63
        ec.Unlock()
226✔
64
}
226✔
65

66
func (ec *endpointCnt) Exists() bool {
125✔
67
        ec.Lock()
125✔
68
        defer ec.Unlock()
125✔
69
        return ec.dbExists
125✔
70
}
125✔
71

72
func (ec *endpointCnt) Skip() bool {
322✔
73
        ec.Lock()
322✔
74
        defer ec.Unlock()
322✔
75
        return !ec.n.persist
322✔
76
}
322✔
77

78
func (ec *endpointCnt) New() datastore.KVObject {
101✔
79
        ec.Lock()
101✔
80
        defer ec.Unlock()
101✔
81

101✔
82
        return &endpointCnt{
101✔
83
                n: ec.n,
101✔
84
        }
101✔
85
}
101✔
86

87
func (ec *endpointCnt) CopyTo(o datastore.KVObject) error {
369✔
88
        ec.Lock()
369✔
89
        defer ec.Unlock()
369✔
90

369✔
91
        dstEc := o.(*endpointCnt)
369✔
92
        dstEc.n = ec.n
369✔
93
        dstEc.Count = ec.Count
369✔
94
        dstEc.dbExists = ec.dbExists
369✔
95
        dstEc.dbIndex = ec.dbIndex
369✔
96

369✔
97
        return nil
369✔
98
}
369✔
99

100
func (ec *endpointCnt) DataScope() string {
242✔
101
        return ec.n.DataScope()
242✔
102
}
242✔
103

104
func (ec *endpointCnt) EndpointCnt() uint64 {
42✔
105
        ec.Lock()
42✔
106
        defer ec.Unlock()
42✔
107

42✔
108
        return ec.Count
42✔
109
}
42✔
110

111
func (ec *endpointCnt) updateStore() error {
2✔
112
        store := ec.n.getController().getStore(ec.DataScope())
2✔
113
        if store == nil {
2✔
114
                return fmt.Errorf("store not found for scope %s on endpoint count update", ec.DataScope())
×
115
        }
×
116
        // make a copy of count and n to avoid being overwritten by store.GetObject
117
        count := ec.EndpointCnt()
2✔
118
        n := ec.n
2✔
119
        for {
6✔
120
                if err := ec.n.getController().updateToStore(ec); err == nil || err != datastore.ErrKeyModified {
6✔
121
                        return err
2✔
122
                }
2✔
123
                if err := store.GetObject(datastore.Key(ec.Key()...), ec); err != nil {
2✔
124
                        return fmt.Errorf("could not update the kvobject to latest on endpoint count update: %v", err)
×
125
                }
×
126
                ec.Lock()
2✔
127
                ec.Count = count
2✔
128
                ec.n = n
2✔
129
                ec.Unlock()
2✔
130
        }
131
}
132

133
func (ec *endpointCnt) setCnt(cnt uint64) error {
2✔
134
        ec.Lock()
2✔
135
        ec.Count = cnt
2✔
136
        ec.Unlock()
2✔
137
        return ec.updateStore()
2✔
138
}
2✔
139

140
func (ec *endpointCnt) atomicIncDecEpCnt(inc bool) error {
78✔
141
retry:
78✔
142
        ec.Lock()
78✔
143
        if inc {
120✔
144
                ec.Count++
42✔
145
        } else {
78✔
146
                if ec.Count > 0 {
72✔
147
                        ec.Count--
36✔
148
                }
36✔
149
        }
150
        ec.Unlock()
78✔
151

78✔
152
        store := ec.n.getController().getStore(ec.DataScope())
78✔
153
        if store == nil {
78✔
154
                return fmt.Errorf("store not found for scope %s", ec.DataScope())
×
155
        }
×
156

157
        if err := ec.n.getController().updateToStore(ec); err != nil {
78✔
158
                if err == datastore.ErrKeyModified {
×
159
                        if err := store.GetObject(datastore.Key(ec.Key()...), ec); err != nil {
×
160
                                return fmt.Errorf("could not update the kvobject to latest when trying to atomic add endpoint count: %v", err)
×
161
                        }
×
162

163
                        goto retry
×
164
                }
165

166
                return err
×
167
        }
168

169
        return nil
78✔
170
}
171

172
func (ec *endpointCnt) IncEndpointCnt() error {
42✔
173
        return ec.atomicIncDecEpCnt(true)
42✔
174
}
42✔
175

176
func (ec *endpointCnt) DecEndpointCnt() error {
36✔
177
        return ec.atomicIncDecEpCnt(false)
36✔
178
}
36✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2024 Coveralls, Inc