github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/logtail/service/request.go (about)

     1  // Copyright 2021 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //	http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package service
    16  
    17  import (
    18  	"sync"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/common/morpc"
    21  	"github.com/matrixorigin/matrixone/pkg/pb/logtail"
    22  )
    23  
    24  // LogtailRequest wraps logtail.LogtailRequest.
    25  type LogtailRequest struct {
    26  	logtail.LogtailRequest
    27  }
    28  
    29  var _ morpc.Message = (*LogtailRequest)(nil)
    30  
    31  func (r *LogtailRequest) SetID(id uint64) {
    32  	r.RequestId = id
    33  }
    34  
    35  func (r *LogtailRequest) GetID() uint64 {
    36  	return r.RequestId
    37  }
    38  
    39  func (r *LogtailRequest) DebugString() string {
    40  	return r.LogtailRequest.String()
    41  }
    42  
    43  func (r *LogtailRequest) Size() int {
    44  	return r.ProtoSize()
    45  }
    46  
    47  // LogtailRequestPool acquires or releases LogtailRequest.
    48  type LogtailRequestPool interface {
    49  	// Acquire fetches item from pool.
    50  	Acquire() *LogtailRequest
    51  
    52  	// Release puts item back to pool.
    53  	Release(*LogtailRequest)
    54  }
    55  
    56  type requestPool struct {
    57  	pool *sync.Pool
    58  }
    59  
    60  func NewLogtailRequestPool() LogtailRequestPool {
    61  	return &requestPool{
    62  		pool: &sync.Pool{
    63  			New: func() any {
    64  				return &LogtailRequest{}
    65  			},
    66  		},
    67  	}
    68  }
    69  
    70  func (p *requestPool) Acquire() *LogtailRequest {
    71  	return p.pool.Get().(*LogtailRequest)
    72  }
    73  
    74  func (p *requestPool) Release(req *LogtailRequest) {
    75  	req.Reset()
    76  	p.pool.Put(req)
    77  }