/
pooling.go
650 lines (560 loc) · 20 KB
/
pooling.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
// Copyright (c) 2017 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 config
import "fmt"
// PoolingType is a type of pooling, using runtime or mmap'd bytes pooling.
type PoolingType string
const (
// SimplePooling uses the basic Go runtime to allocate bytes for bytes pools.
SimplePooling PoolingType = "simple"
defaultPoolingType = SimplePooling
)
const (
defaultMaxFinalizerCapacity = 4
defaultBlockAllocSize = 16
defaultThriftBytesPoolAllocSize = 2048
)
type poolPolicyDefault struct {
size int
refillLowWaterMark float64
refillHighWaterMark float64
// Only used for capacity and max capacity pools.
capacity int
// Only used for max capacity pools.
maxCapacity int
}
type bucketPoolPolicyDefault struct {
buckets []CapacityPoolPolicy
}
var (
defaultRefillLowWaterMark = 0.7
defaultRefillHighWaterMark = 1.0
defaultPoolPolicy = poolPolicyDefault{
size: 4096,
refillLowWaterMark: 0,
refillHighWaterMark: 0,
}
defaultPoolPolicies = map[string]poolPolicyDefault{
"tagsIterator": defaultPoolPolicy,
"indexResults": defaultPoolPolicy,
"tagEncoder": defaultPoolPolicy,
"tagDecoder": defaultPoolPolicy,
"context": poolPolicyDefault{
size: 262144,
refillLowWaterMark: defaultRefillLowWaterMark,
refillHighWaterMark: defaultRefillHighWaterMark,
},
"series": poolPolicyDefault{
size: 262144,
refillLowWaterMark: defaultRefillLowWaterMark,
refillHighWaterMark: defaultRefillHighWaterMark,
},
"block": poolPolicyDefault{
size: 262144,
refillLowWaterMark: defaultRefillLowWaterMark,
refillHighWaterMark: defaultRefillHighWaterMark,
},
"encoder": poolPolicyDefault{
size: 262144,
refillLowWaterMark: defaultRefillLowWaterMark,
refillHighWaterMark: defaultRefillHighWaterMark,
},
"closers": poolPolicyDefault{
size: 104857,
refillLowWaterMark: defaultRefillLowWaterMark,
refillHighWaterMark: defaultRefillHighWaterMark,
},
"segmentReader": poolPolicyDefault{
size: 16384,
refillLowWaterMark: defaultRefillLowWaterMark,
refillHighWaterMark: defaultRefillHighWaterMark,
},
"iterator": poolPolicyDefault{
size: 2048,
refillLowWaterMark: defaultRefillLowWaterMark,
refillHighWaterMark: defaultRefillHighWaterMark,
},
"blockMetadata": poolPolicyDefault{
size: 65536,
refillLowWaterMark: defaultRefillLowWaterMark,
refillHighWaterMark: defaultRefillHighWaterMark,
},
"blocksMetadata": poolPolicyDefault{
size: 65536,
refillLowWaterMark: defaultRefillLowWaterMark,
refillHighWaterMark: defaultRefillHighWaterMark,
},
"identifier": poolPolicyDefault{
size: 262144,
refillLowWaterMark: defaultRefillLowWaterMark,
refillHighWaterMark: defaultRefillHighWaterMark,
},
"postingsList": poolPolicyDefault{
// defaultPostingsListPoolSize has a small default pool size since postings
// lists can frequently reach the size of 4mb each in practice even when
// reset.
size: 16,
refillLowWaterMark: defaultRefillLowWaterMark,
refillHighWaterMark: defaultRefillHighWaterMark,
},
"bufferBucket": poolPolicyDefault{
size: 65536,
refillLowWaterMark: defaultRefillLowWaterMark,
refillHighWaterMark: defaultRefillHighWaterMark,
},
"bufferBucketVersions": poolPolicyDefault{
size: 65536,
refillLowWaterMark: defaultRefillLowWaterMark,
refillHighWaterMark: defaultRefillHighWaterMark,
},
// Capacity pools.
"fetchBlockMetadataResults": poolPolicyDefault{
size: 65536,
refillLowWaterMark: defaultRefillLowWaterMark,
refillHighWaterMark: defaultRefillHighWaterMark,
capacity: 32,
},
"fetchBlocksMetadataResults": poolPolicyDefault{
size: 32,
refillLowWaterMark: defaultRefillLowWaterMark,
refillHighWaterMark: defaultRefillHighWaterMark,
capacity: 4096,
},
"replicaMetadataSlice": poolPolicyDefault{
size: 131072,
refillLowWaterMark: defaultRefillLowWaterMark,
refillHighWaterMark: defaultRefillHighWaterMark,
capacity: 3,
},
"blockMetadataSlice": poolPolicyDefault{
size: 65536,
refillLowWaterMark: defaultRefillLowWaterMark,
refillHighWaterMark: defaultRefillHighWaterMark,
capacity: 32,
},
"blocksMetadataSlice": poolPolicyDefault{
size: 32,
refillLowWaterMark: defaultRefillLowWaterMark,
refillHighWaterMark: defaultRefillHighWaterMark,
capacity: 4096,
},
// Max capacity pools.
"tags": poolPolicyDefault{
size: 4096,
refillLowWaterMark: defaultRefillLowWaterMark,
refillHighWaterMark: defaultRefillHighWaterMark,
capacity: 0,
maxCapacity: 16,
},
}
defaultBucketPoolPolicies = map[string]bucketPoolPolicyDefault{
"bytes": bucketPoolPolicyDefault{
buckets: []CapacityPoolPolicy{
{
Capacity: intPtr(16),
PoolPolicy: PoolPolicy{
Size: intPtr(524288),
RefillLowWaterMark: &defaultRefillLowWaterMark,
RefillHighWaterMark: &defaultRefillHighWaterMark,
},
},
{
Capacity: intPtr(32),
PoolPolicy: PoolPolicy{
Size: intPtr(262144),
RefillLowWaterMark: &defaultRefillLowWaterMark,
RefillHighWaterMark: &defaultRefillHighWaterMark,
},
},
{
Capacity: intPtr(64),
PoolPolicy: PoolPolicy{
Size: intPtr(131072),
RefillLowWaterMark: &defaultRefillLowWaterMark,
RefillHighWaterMark: &defaultRefillHighWaterMark,
},
},
{
Capacity: intPtr(128),
PoolPolicy: PoolPolicy{
Size: intPtr(65536),
RefillLowWaterMark: &defaultRefillLowWaterMark,
RefillHighWaterMark: &defaultRefillHighWaterMark,
},
},
{
Capacity: intPtr(256),
PoolPolicy: PoolPolicy{
Size: intPtr(65536),
RefillLowWaterMark: &defaultRefillLowWaterMark,
RefillHighWaterMark: &defaultRefillHighWaterMark,
},
},
{
Capacity: intPtr(1440),
PoolPolicy: PoolPolicy{
Size: intPtr(16384),
RefillLowWaterMark: &defaultRefillLowWaterMark,
RefillHighWaterMark: &defaultRefillHighWaterMark,
},
},
{
Capacity: intPtr(4096),
PoolPolicy: PoolPolicy{
Size: intPtr(8192),
RefillLowWaterMark: &defaultRefillLowWaterMark,
RefillHighWaterMark: &defaultRefillHighWaterMark,
},
},
},
},
}
)
// PoolingPolicy specifies the pooling policy. To add a new pool, follow these steps:
//
// 1. Add the pool to the struct below.
// 2. Add the default values to the defaultPoolPolicies or defaultBucketPoolPolicies map.
// 3. Add a call to initDefaultsAndValidate() for the new pool in the
// PoolingPolicy.InitDefaultsAndValidate() method.
type PoolingPolicy struct {
// The initial alloc size for a block.
BlockAllocSize *int `yaml:"blockAllocSize"`
// The thrift bytes pool max bytes slice allocation for a single binary field.
ThriftBytesPoolAllocSize *int `yaml:"thriftBytesPoolAllocSize"`
// The general pool type (currently only supported: simple).
Type *PoolingType `yaml:"type"`
// The Bytes pool buckets to use.
BytesPool BucketPoolPolicy `yaml:"bytesPool"`
// The policy for the Closers pool.
ClosersPool PoolPolicy `yaml:"closersPool"`
// The policy for the Context pool.
ContextPool ContextPoolPolicy `yaml:"contextPool"`
// The policy for the DatabaseSeries pool.
SeriesPool PoolPolicy `yaml:"seriesPool"`
// The policy for the DatabaseBlock pool.
BlockPool PoolPolicy `yaml:"blockPool"`
// The policy for the Encoder pool.
EncoderPool PoolPolicy `yaml:"encoderPool"`
// The policy for the Iterator pool.
IteratorPool PoolPolicy `yaml:"iteratorPool"`
// The policy for the Segment Reader pool.
SegmentReaderPool PoolPolicy `yaml:"segmentReaderPool"`
// The policy for the Identifier pool.
IdentifierPool PoolPolicy `yaml:"identifierPool"`
// The policy for the FetchBlockMetadataResult pool.
FetchBlockMetadataResultsPool CapacityPoolPolicy `yaml:"fetchBlockMetadataResultsPool"`
// The policy for the FetchBlocksMetadataResults pool.
FetchBlocksMetadataResultsPool CapacityPoolPolicy `yaml:"fetchBlocksMetadataResultsPool"`
// The policy for the ReplicaMetadataSlicePool pool.
ReplicaMetadataSlicePool CapacityPoolPolicy `yaml:"replicaMetadataSlicePool"`
// The policy for the BlockMetadat pool.
BlockMetadataPool PoolPolicy `yaml:"blockMetadataPool"`
// The policy for the BlockMetadataSlice pool.
BlockMetadataSlicePool CapacityPoolPolicy `yaml:"blockMetadataSlicePool"`
// The policy for the BlocksMetadata pool.
BlocksMetadataPool PoolPolicy `yaml:"blocksMetadataPool"`
// The policy for the BlocksMetadataSlice pool.
BlocksMetadataSlicePool CapacityPoolPolicy `yaml:"blocksMetadataSlicePool"`
// The policy for the tags pool.
TagsPool MaxCapacityPoolPolicy `yaml:"tagsPool"`
// The policy for the tags iterator pool.
TagsIteratorPool PoolPolicy `yaml:"tagIteratorPool"`
// The policy for the index.ResultsPool.
IndexResultsPool PoolPolicy `yaml:"indexResultsPool"`
// The policy for the TagEncoderPool.
TagEncoderPool PoolPolicy `yaml:"tagEncoderPool"`
// The policy for the TagDecoderPool.
TagDecoderPool PoolPolicy `yaml:"tagDecoderPool"`
// The policy for the WriteBatchPool.
WriteBatchPool WriteBatchPoolPolicy `yaml:"writeBatchPool"`
// The policy for the BufferBucket pool.
BufferBucketPool PoolPolicy `yaml:"bufferBucketPool"`
// The policy for the BufferBucketVersions pool.
BufferBucketVersionsPool PoolPolicy `yaml:"bufferBucketVersionsPool"`
// The policy for the PostingsListPool.
PostingsListPool PoolPolicy `yaml:"postingsListPool"`
}
// InitDefaultsAndValidate initializes all default values and validates the configuration
func (p *PoolingPolicy) InitDefaultsAndValidate() error {
if err := p.ClosersPool.initDefaultsAndValidate("closers"); err != nil {
return err
}
if err := p.ContextPool.initDefaultsAndValidate("context"); err != nil {
return err
}
if err := p.SeriesPool.initDefaultsAndValidate("series"); err != nil {
return err
}
if err := p.BlockPool.initDefaultsAndValidate("block"); err != nil {
return err
}
if err := p.EncoderPool.initDefaultsAndValidate("encoder"); err != nil {
return err
}
if err := p.IteratorPool.initDefaultsAndValidate("iterator"); err != nil {
return err
}
if err := p.SegmentReaderPool.initDefaultsAndValidate("segmentReader"); err != nil {
return err
}
if err := p.IdentifierPool.initDefaultsAndValidate("identifier"); err != nil {
return err
}
if err := p.FetchBlockMetadataResultsPool.initDefaultsAndValidate("fetchBlockMetadataResults"); err != nil {
return err
}
if err := p.FetchBlocksMetadataResultsPool.initDefaultsAndValidate("fetchBlocksMetadataResults"); err != nil {
return err
}
if err := p.ReplicaMetadataSlicePool.initDefaultsAndValidate("replicaMetadataSlice"); err != nil {
return err
}
if err := p.BlockMetadataPool.initDefaultsAndValidate("blockMetadata"); err != nil {
return err
}
if err := p.BlockMetadataSlicePool.initDefaultsAndValidate("blockMetadataSlice"); err != nil {
return err
}
if err := p.BlocksMetadataPool.initDefaultsAndValidate("blocksMetadata"); err != nil {
return err
}
if err := p.BlocksMetadataSlicePool.initDefaultsAndValidate("blocksMetadataSlice"); err != nil {
return err
}
if err := p.TagsPool.initDefaultsAndValidate("tags"); err != nil {
return err
}
if err := p.TagsIteratorPool.initDefaultsAndValidate("tagsIterator"); err != nil {
return err
}
if err := p.IndexResultsPool.initDefaultsAndValidate("indexResults"); err != nil {
return err
}
if err := p.TagEncoderPool.initDefaultsAndValidate("tagEncoder"); err != nil {
return err
}
if err := p.TagDecoderPool.initDefaultsAndValidate("tagDecoder"); err != nil {
return err
}
if err := p.PostingsListPool.initDefaultsAndValidate("postingsList"); err != nil {
return err
}
if err := p.BytesPool.initDefaultsAndValidate("bytes"); err != nil {
return err
}
if err := p.BufferBucketPool.initDefaultsAndValidate("bufferBucket"); err != nil {
return err
}
if err := p.BufferBucketVersionsPool.initDefaultsAndValidate("bufferBucketVersions"); err != nil {
return err
}
return nil
}
// BlockAllocSizeOrDefault returns the configured block alloc size if provided,
// or a default value otherwise.
func (p *PoolingPolicy) BlockAllocSizeOrDefault() int {
if p.BlockAllocSize != nil {
return *p.BlockAllocSize
}
return defaultBlockAllocSize
}
// ThriftBytesPoolAllocSizeOrDefault returns the configured thrift bytes pool
// max alloc size if provided, or a default value otherwise.
func (p *PoolingPolicy) ThriftBytesPoolAllocSizeOrDefault() int {
if p.ThriftBytesPoolAllocSize != nil {
return *p.ThriftBytesPoolAllocSize
}
return defaultThriftBytesPoolAllocSize
}
// TypeOrDefault returns the configured pooling type if provided, or a default
// value otherwise.
func (p *PoolingPolicy) TypeOrDefault() PoolingType {
if p.Type != nil {
return *p.Type
}
return defaultPoolingType
}
// PoolPolicy specifies a single pool policy.
type PoolPolicy struct {
// The size of the pool.
Size *int `yaml:"size"`
// The low watermark to start refilling the pool, if zero none.
RefillLowWaterMark *float64 `yaml:"lowWatermark"`
// The high watermark to stop refilling the pool, if zero none.
RefillHighWaterMark *float64 `yaml:"highWatermark"`
}
func (p *PoolPolicy) initDefaultsAndValidate(poolName string) error {
defaults, ok := defaultPoolPolicies[poolName]
if !ok {
return fmt.Errorf("no default values for pool: %s", poolName)
}
if p.Size == nil {
p.Size = &defaults.size
}
if p.RefillLowWaterMark == nil {
p.RefillLowWaterMark = &defaults.refillLowWaterMark
}
if p.RefillHighWaterMark == nil {
p.RefillHighWaterMark = &defaults.refillHighWaterMark
}
if *p.RefillLowWaterMark < 0 || *p.RefillLowWaterMark > 1 {
return fmt.Errorf(
"invalid lowWatermark value for %s pool, should be >= 0 and <= 1", poolName)
}
if *p.RefillHighWaterMark < 0 || *p.RefillHighWaterMark > 1 {
return fmt.Errorf(
"invalid lowWatermark value for %s pool, should be >= 0 and <= 1", poolName)
}
return nil
}
// SizeOrDefault returns the configured size if present, or a default value otherwise.
func (p *PoolPolicy) SizeOrDefault() int {
return *p.Size
}
// RefillLowWaterMarkOrDefault returns the configured refill low water mark if present,
// or a default value otherwise.
func (p *PoolPolicy) RefillLowWaterMarkOrDefault() float64 {
return *p.RefillLowWaterMark
}
// RefillHighWaterMarkOrDefault returns the configured refill high water mark if present,
// or a default value otherwise.
func (p *PoolPolicy) RefillHighWaterMarkOrDefault() float64 {
return *p.RefillHighWaterMark
}
// CapacityPoolPolicy specifies a single pool policy that has a
// per element capacity.
type CapacityPoolPolicy struct {
PoolPolicy `yaml:",inline"`
// The capacity of items in the pool.
Capacity *int `yaml:"capacity"`
}
// Validate validates the capacity pool policy config.
func (p *CapacityPoolPolicy) initDefaultsAndValidate(poolName string) error {
if err := p.PoolPolicy.initDefaultsAndValidate(poolName); err != nil {
return err
}
defaults, ok := defaultPoolPolicies[poolName]
if !ok {
return fmt.Errorf("no default values for pool: %s", poolName)
}
if p.Capacity == nil {
p.Capacity = &defaults.capacity
}
if *p.Capacity < 0 {
return fmt.Errorf("capacity of %s pool must be >= 0", poolName)
}
return nil
}
// CapacityOrDefault returns the configured capacity if present, or a default value otherwise.
func (p *CapacityPoolPolicy) CapacityOrDefault() int {
return *p.Capacity
}
// MaxCapacityPoolPolicy specifies a single pool policy that has a
// per element capacity, and a maximum allowed capacity as well.
type MaxCapacityPoolPolicy struct {
CapacityPoolPolicy `yaml:",inline"`
// The max capacity of items in the pool.
MaxCapacity *int `yaml:"maxCapacity"`
}
func (p *MaxCapacityPoolPolicy) initDefaultsAndValidate(poolName string) error {
if err := p.CapacityPoolPolicy.initDefaultsAndValidate(poolName); err != nil {
return err
}
defaults, ok := defaultPoolPolicies[poolName]
if !ok {
return fmt.Errorf("no default values for pool: %s", poolName)
}
if p.MaxCapacity == nil {
p.MaxCapacity = &defaults.maxCapacity
}
if *p.MaxCapacity < 0 {
return fmt.Errorf("maxCapacity of %s pool must be >= 0", poolName)
}
return nil
}
// MaxCapacityOrDefault returns the configured maximum capacity if present, or a
// default value otherwise.
func (p *MaxCapacityPoolPolicy) MaxCapacityOrDefault() int {
return *p.MaxCapacity
}
// BucketPoolPolicy specifies a bucket pool policy.
type BucketPoolPolicy struct {
// The pool buckets sizes to use
Buckets []CapacityPoolPolicy `yaml:"buckets"`
}
func (p *BucketPoolPolicy) initDefaultsAndValidate(poolName string) error {
defaults, ok := defaultBucketPoolPolicies[poolName]
if !ok {
return fmt.Errorf("no default values for pool: %s", poolName)
}
if p.Buckets == nil {
p.Buckets = defaults.buckets
}
for i, bucket := range p.Buckets {
// If the user provided buckets, but no values for refill low/high watermarks
// then set them to default values.
if bucket.RefillLowWaterMark == nil {
p.Buckets[i].RefillLowWaterMark = &defaultRefillLowWaterMark
}
if bucket.RefillHighWaterMark == nil {
p.Buckets[i].RefillHighWaterMark = &defaultRefillHighWaterMark
}
}
for _, bucket := range p.Buckets {
if bucket.Size == nil {
return fmt.Errorf("bucket size for pool %s cannot be nil", poolName)
}
if bucket.Capacity == nil {
return fmt.Errorf("bucket capacity for pool %s cannot be nil", poolName)
}
}
return nil
}
// WriteBatchPoolPolicy specifies the pooling policy for the WriteBatch pool.
type WriteBatchPoolPolicy struct {
// The size of the pool.
Size *int `yaml:"size"`
// InitialBatchSize controls the initial batch size for each WriteBatch when
// the pool is being constructed / refilled.
InitialBatchSize *int `yaml:"initialBatchSize"`
// MaxBatchSize controls the maximum size that a pooled WriteBatch can grow to
// and still remain in the pool.
MaxBatchSize *int `yaml:"maxBatchSize"`
}
// ContextPoolPolicy specifies the policy for the context pool.
type ContextPoolPolicy struct {
PoolPolicy `yaml:",inline"`
// The maximum allowable size for a slice of finalizers that the
// pool will allow to be returned (finalizer slices that grow too
// large during use will be discarded instead of returning to the
// pool where they would consume more memory.)
MaxFinalizerCapacity int `yaml:"maxFinalizerCapacity" validate:"min=0"`
}
// MaxFinalizerCapacityOrDefault returns the maximum finalizer capacity and
// fallsback to the default value if its not set.
func (p ContextPoolPolicy) MaxFinalizerCapacityOrDefault() int {
if p.MaxFinalizerCapacity == 0 {
return defaultMaxFinalizerCapacity
}
return p.MaxFinalizerCapacity
}
func intPtr(x int) *int {
return &x
}