forked from uber/ringpop-go
/
events.go
246 lines (206 loc) · 8.07 KB
/
events.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
// Copyright (c) 2015 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package swim
import (
"time"
"reflect"
"github.com/uber/ringpop-go/events"
)
// The ListenerFunc type is an adapter to allow the use of ordinary functions
// as EventListeners.
type ListenerFunc func(events.Event)
// HandleEvent calls f(e).
func (f ListenerFunc) HandleEvent(e events.Event) {
f(e)
}
// A MaxPAdjustedEvent occurs when the disseminator adjusts the max propagation
// count for changes
type MaxPAdjustedEvent struct {
OldPCount int `json:"oldPCount"`
NewPCount int `json:"newPCount"`
}
// A MemberlistChangesReceivedEvent contains changes received by the node's
// memberlist, pending application
type MemberlistChangesReceivedEvent struct {
Changes []Change `json:"changes"`
}
// A MemberlistChangesAppliedEvent contains changes that were applied to the
// node's memberlist as well as the previous and new checksums and the
// number of members in the memberlist
type MemberlistChangesAppliedEvent struct {
Changes []Change `json:"changes"`
OldChecksum uint32 `json:"oldChecksum"`
NewChecksum uint32 `json:"newChecksum"`
NumMembers int `json:"numMembers"`
}
// A FullSyncEvent is sent when the disseminator's node issues changes a
// full sync of the memberlist
type FullSyncEvent struct {
Remote string `json:"remote"`
RemoteChecksum uint32 `json:"remoteChecksum"`
}
// A JoinReceiveEvent is sent when a join request is received by a node
type JoinReceiveEvent struct {
Local string `json:"local"`
Source string `json:"source"`
}
// A JoinCompleteEvent is sent when a join request to remote node successfully
// completes
type JoinCompleteEvent struct {
Duration time.Duration `json:"duration"`
NumJoined int `json:"numJoined"`
Joined []string `json:"joined"`
}
// AddJoinListEvent is sent when a join list is added to the membership
type AddJoinListEvent struct {
Duration time.Duration `json:"duration"`
}
// JoinFailedReason indicates the reason a join failed
type JoinFailedReason string
const (
// Error as a JoinFailedReason indicates that the join failed because of an error
Error JoinFailedReason = "err"
// Destroyed as a JoinFailedReason indicates that the join failed because ringpop was destroyed during the join
Destroyed = "destroyed"
)
// A JoinFailedEvent is sent when a join request to remote node did not successfully
type JoinFailedEvent struct {
Reason JoinFailedReason
Error error
}
// A PingSendEvent is sent when the node sends a ping to a remote node
type PingSendEvent struct {
Local string `json:"local"`
Remote string `json:"remote"`
Changes []Change `json:"changes"`
}
// A PingSendCompleteEvent is sent when the node finished sending a ping to a remote node
type PingSendCompleteEvent struct {
Local string `json:"local"`
Remote string `json:"remote"`
Changes []Change `json:"changes"`
Duration time.Duration `json:"duration"`
}
// A PingReceiveEvent is sent when the node receives a ping from a remote node
type PingReceiveEvent struct {
Local string `json:"local"`
Source string `json:"source"`
Changes []Change `json:"changes"`
}
// A PingRequestsSendEvent is sent when the node sends ping requests to remote nodes
type PingRequestsSendEvent struct {
Local string `json:"local"`
Target string `json:"target"`
Peers []string `json:"peers"`
}
// A PingRequestSendErrorEvent is sent when the node can't get a response sending ping requests to remote nodes
type PingRequestSendErrorEvent struct {
Local string `json:"local"`
Target string `json:"target"`
Peers []string `json:"peers"`
Peer string `json:"peer"`
}
// A PingRequestsSendCompleteEvent is sent when the node finished sending ping requests to remote nodes
type PingRequestsSendCompleteEvent struct {
Local string `json:"local"`
Target string `json:"target"`
Peers []string `json:"peers"`
Peer string `json:"peer"`
Duration time.Duration `json:"duration"`
}
// A PingRequestReceiveEvent is sent when the node receives a pign request from a remote node
type PingRequestReceiveEvent struct {
Local string `json:"local"`
Source string `json:"source"`
Target string `json:"target"`
Changes []Change `json:"changes"`
}
// A PingRequestPingEvent is sent when the node sends a ping to the target node at the
// behest of the source node and receives a response
type PingRequestPingEvent struct {
Local string `json:"local"`
Source string `json:"source"`
Target string `json:"target"`
Duration time.Duration `json:"duration"`
}
// A ProtocolDelayComputeEvent is sent when protocol delay is computed during a gossip run
type ProtocolDelayComputeEvent struct {
Duration time.Duration `json:"duration"`
}
// A ProtocolFrequencyEvent is sent when a gossip run is finished
type ProtocolFrequencyEvent struct {
Duration time.Duration `json:"duration"`
}
// A ChecksumComputeEvent is sent when a the rings checksum is computed
type ChecksumComputeEvent struct {
Duration time.Duration `json:"duration"`
Checksum uint32 `json:"checksum"`
OldChecksum uint32 `json:"oldchecksum"`
}
// A ChangesCalculatedEvent is sent when the disseminator generated the list of changes to send in a ping or its response
type ChangesCalculatedEvent struct {
Changes []Change
}
// A ChangeFilteredEvent is sent when a change has been filtered from the list to be disseminated
type ChangeFilteredEvent struct {
Change Change
}
// A JoinTriesUpdateEvent is sent when the joiner tries to join a group
type JoinTriesUpdateEvent struct {
Retries int
}
// A MakeNodeStatusEvent is sent when Make[Status] is called on member list
type MakeNodeStatusEvent struct {
Status string
}
// A RequestBeforeReadyEvent is sent if a remote request came in for a ringpop endpoint while ringpop was not ready to process requests
type RequestBeforeReadyEvent struct {
Endpoint Endpoint
}
// A RefuteUpdateEvent is sent when a node detects gossip about its own state that needs to be corrected
type RefuteUpdateEvent struct{}
// A StartReverseFullSyncEvent is sent when a node starts the reverse full sync procedure
type StartReverseFullSyncEvent struct {
Target string `json:"target"`
}
// OmitReverseFullSyncEvent is sent when a node omits the reverse full sync
// prodedure because there are already the max number of reverse full sync
// processes running.
type OmitReverseFullSyncEvent struct {
Target string `json:"target"`
}
// RedundantReverseFullSyncEvent is sent when no new changes were added due
// to the reverse full sync.
type RedundantReverseFullSyncEvent struct {
Target string `json:"target"`
}
// DiscoHealEvent is sent when the discover provider healer attempts to heal a partition
type DiscoHealEvent struct{}
// AttemptHealEvent is sent when the healer is triggered
type AttemptHealEvent struct{}
// on is returns an EventListener that executes a function f upon receiving an
// event of type t.
func on(t interface{}, f func(e events.Event)) ListenerFunc {
return ListenerFunc(func(e events.Event) {
if reflect.TypeOf(t) == reflect.TypeOf(e) {
f(e)
}
})
}