github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/dbnode/client/write_batch_pool.go (about) 1 // Copyright (c) 2016 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package client 22 23 import ( 24 "github.com/m3db/m3/src/dbnode/generated/thrift/rpc" 25 "github.com/m3db/m3/src/x/pool" 26 ) 27 28 var ( 29 writeBatchRawRequestZeroed rpc.WriteBatchRawRequest 30 writeBatchRawV2RequestZeroed rpc.WriteBatchRawV2Request 31 ) 32 33 type writeBatchRawRequestPool interface { 34 // Init pool 35 Init() 36 37 // Get a write batch request 38 Get() *rpc.WriteBatchRawRequest 39 40 // Put a write batch request 41 Put(w *rpc.WriteBatchRawRequest) 42 } 43 44 type poolOfWriteBatchRawRequest struct { 45 pool pool.ObjectPool 46 } 47 48 func newWriteBatchRawRequestPool(opts pool.ObjectPoolOptions) writeBatchRawRequestPool { 49 p := pool.NewObjectPool(opts) 50 return &poolOfWriteBatchRawRequest{p} 51 } 52 53 func (p *poolOfWriteBatchRawRequest) Init() { 54 p.pool.Init(func() interface{} { 55 return &rpc.WriteBatchRawRequest{} 56 }) 57 } 58 59 func (p *poolOfWriteBatchRawRequest) Get() *rpc.WriteBatchRawRequest { 60 return p.pool.Get().(*rpc.WriteBatchRawRequest) 61 } 62 63 func (p *poolOfWriteBatchRawRequest) Put(w *rpc.WriteBatchRawRequest) { 64 *w = writeBatchRawRequestZeroed 65 p.pool.Put(w) 66 } 67 68 type writeBatchRawV2RequestPool interface { 69 // Init pool. 70 Init() 71 72 // Get a write batch request. 73 Get() *rpc.WriteBatchRawV2Request 74 75 // Put a write batch request. 76 Put(w *rpc.WriteBatchRawV2Request) 77 } 78 79 type poolOfWriteBatchRawV2Request struct { 80 pool pool.ObjectPool 81 } 82 83 func newWriteBatchRawV2RequestPool(opts pool.ObjectPoolOptions) writeBatchRawV2RequestPool { 84 p := pool.NewObjectPool(opts) 85 return &poolOfWriteBatchRawV2Request{p} 86 } 87 88 func (p *poolOfWriteBatchRawV2Request) Init() { 89 p.pool.Init(func() interface{} { 90 return &rpc.WriteBatchRawV2Request{} 91 }) 92 } 93 94 func (p *poolOfWriteBatchRawV2Request) Get() *rpc.WriteBatchRawV2Request { 95 return p.pool.Get().(*rpc.WriteBatchRawV2Request) 96 } 97 98 func (p *poolOfWriteBatchRawV2Request) Put(w *rpc.WriteBatchRawV2Request) { 99 *w = writeBatchRawV2RequestZeroed 100 p.pool.Put(w) 101 }