@@ -24,9 +24,6 @@ import (
24
24
)
25
25
26
26
type BaseSlot interface {
27
- // Name returns it's slot name which should be global unique.
28
- Name () string
29
-
30
27
// Order returns the sort value of the slot.
31
28
// SlotChain will sort all it's slots by ascending sort value in each bucket
32
29
// (StatPrepareSlot bucket、RuleCheckSlot bucket and StatSlot bucket)
@@ -77,8 +74,6 @@ type StatSlot interface {
77
74
// SlotChain hold all system slots and customized slot.
78
75
// SlotChain support plug-in slots developed by developer.
79
76
type SlotChain struct {
80
- // RWMutex guard the slots in SlotChain and make sure the concurrency safe
81
- sync.RWMutex
82
77
// statPres is in ascending order by StatPrepareSlot.Order() value.
83
78
statPres []StatPrepareSlot
84
79
// ruleChecks is in ascending order by RuleCheckSlot.Order() value.
@@ -108,7 +103,6 @@ var (
108
103
109
104
func NewSlotChain () * SlotChain {
110
105
return & SlotChain {
111
- RWMutex : sync.RWMutex {},
112
106
statPres : make ([]StatPrepareSlot , 0 , 8 ),
113
107
ruleChecks : make ([]RuleCheckSlot , 0 , 8 ),
114
108
stats : make ([]StatSlot , 0 , 8 ),
@@ -130,31 +124,6 @@ func (sc *SlotChain) RefurbishContext(c *EntryContext) {
130
124
}
131
125
}
132
126
133
- // ValidateStatPrepareSlotNaming checks whether the name of StatPrepareSlot exists in SlotChain.[]StatPrepareSlot
134
- // return true the name of StatPrepareSlot doesn't exist in SlotChain.[]StatPrepareSlot
135
- // ValidateStatPrepareSlotNaming is non-thread safe,
136
- // In concurrency scenario, ValidateStatPrepareSlotNaming must be guarded by SlotChain.RWMutex#RLock
137
- func ValidateStatPrepareSlotNaming (sc * SlotChain , s StatPrepareSlot ) bool {
138
- isValid := true
139
- f := func (slot StatPrepareSlot ) {
140
- if slot .Name () == s .Name () {
141
- isValid = false
142
- }
143
- }
144
- sc .RangeStatPrepareSlot (f )
145
-
146
- return isValid
147
- }
148
-
149
- // RangeStatPrepareSlot iterates the SlotChain.[]StatPrepareSlot and call f function for each StatPrepareSlot
150
- // RangeStatPrepareSlot is non-thread safe,
151
- // In concurrency scenario, RangeStatPrepareSlot must be guarded by SlotChain.RWMutex#RLock
152
- func (sc * SlotChain ) RangeStatPrepareSlot (f func (slot StatPrepareSlot )) {
153
- for _ , slot := range sc .statPres {
154
- f (slot )
155
- }
156
- }
157
-
158
127
// AddStatPrepareSlot adds the StatPrepareSlot slot to the StatPrepareSlot list of the SlotChain.
159
128
// All StatPrepareSlot in the list will be sorted according to StatPrepareSlot.Order() in ascending order.
160
129
// AddStatPrepareSlot is non-thread safe,
@@ -166,31 +135,6 @@ func (sc *SlotChain) AddStatPrepareSlot(s StatPrepareSlot) {
166
135
})
167
136
}
168
137
169
- // ValidateRuleCheckSlotNaming checks whether the name of RuleCheckSlot exists in SlotChain.[]RuleCheckSlot
170
- // return true the name of RuleCheckSlot doesn't exist in SlotChain.[]RuleCheckSlot
171
- // ValidateRuleCheckSlotNaming is non-thread safe,
172
- // In concurrency scenario, ValidateRuleCheckSlotNaming must be guarded by SlotChain.RWMutex#RLock
173
- func ValidateRuleCheckSlotNaming (sc * SlotChain , s RuleCheckSlot ) bool {
174
- isValid := true
175
- f := func (slot RuleCheckSlot ) {
176
- if slot .Name () == s .Name () {
177
- isValid = false
178
- }
179
- }
180
- sc .RangeRuleCheckSlot (f )
181
-
182
- return isValid
183
- }
184
-
185
- // RangeRuleCheckSlot iterates the SlotChain.[]RuleCheckSlot and call f function for each RuleCheckSlot
186
- // RangeRuleCheckSlot is non-thread safe,
187
- // In concurrency scenario, RangeRuleCheckSlot must be guarded by SlotChain.RWMutex#RLock
188
- func (sc * SlotChain ) RangeRuleCheckSlot (f func (slot RuleCheckSlot )) {
189
- for _ , slot := range sc .ruleChecks {
190
- f (slot )
191
- }
192
- }
193
-
194
138
// AddRuleCheckSlot adds the RuleCheckSlot to the RuleCheckSlot list of the SlotChain.
195
139
// All RuleCheckSlot in the list will be sorted according to RuleCheckSlot.Order() in ascending order.
196
140
// AddRuleCheckSlot is non-thread safe,
@@ -202,31 +146,6 @@ func (sc *SlotChain) AddRuleCheckSlot(s RuleCheckSlot) {
202
146
})
203
147
}
204
148
205
- // ValidateStatSlotNaming checks whether the name of StatSlot exists in SlotChain.[]StatSlot
206
- // return true the name of StatSlot doesn't exist in SlotChain.[]StatSlot
207
- // ValidateStatSlotNaming is non-thread safe,
208
- // In concurrency scenario, ValidateStatSlotNaming must be guarded by SlotChain.RWMutex#RLock
209
- func ValidateStatSlotNaming (sc * SlotChain , s StatSlot ) bool {
210
- isValid := true
211
- f := func (slot StatSlot ) {
212
- if slot .Name () == s .Name () {
213
- isValid = false
214
- }
215
- }
216
- sc .RangeStatSlot (f )
217
-
218
- return isValid
219
- }
220
-
221
- // RangeStatSlot iterates the SlotChain.[]StatSlot and call f function for each StatSlot
222
- // RangeStatSlot is non-thread safe,
223
- // In concurrency scenario, RangeStatSlot must be guarded by SlotChain.RWMutex#RLock
224
- func (sc * SlotChain ) RangeStatSlot (f func (slot StatSlot )) {
225
- for _ , slot := range sc .stats {
226
- f (slot )
227
- }
228
- }
229
-
230
149
// AddStatSlot adds the StatSlot to the StatSlot list of the SlotChain.
231
150
// All StatSlot in the list will be sorted according to StatSlot.Order() in ascending order.
232
151
// AddStatSlot is non-thread safe,
@@ -241,11 +160,9 @@ func (sc *SlotChain) AddStatSlot(s StatSlot) {
241
160
// The entrance of slot chain
242
161
// Return the TokenResult and nil if internal panic.
243
162
func (sc * SlotChain ) Entry (ctx * EntryContext ) * TokenResult {
244
- sc .RLock ()
245
163
// This should not happen, unless there are errors existing in Sentinel internal.
246
164
// If happened, need to add TokenResult in EntryContext
247
165
defer func () {
248
- sc .RUnlock ()
249
166
if err := recover (); err != nil {
250
167
logging .Error (errors .Errorf ("%+v" , err ), "Sentinel internal panic in SlotChain.Entry()" )
251
168
ctx .SetError (errors .Errorf ("%+v" , err ))
@@ -311,9 +228,6 @@ func (sc *SlotChain) exit(ctx *EntryContext) {
311
228
if ctx .IsBlocked () {
312
229
return
313
230
}
314
-
315
- sc .RLock ()
316
- defer sc .RUnlock ()
317
231
for _ , s := range sc .stats {
318
232
s .OnCompleted (ctx )
319
233
}
0 commit comments