github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/logtail/service/event.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  	"context"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/pb/logtail"
    21  	"github.com/matrixorigin/matrixone/pkg/pb/timestamp"
    22  )
    23  
    24  const (
    25  	// FIXME: do we need to make event buffer size configurable?
    26  	eventBufferSize = 6 * 1024
    27  )
    28  
    29  // Notifier provides incremental logtail.
    30  type Notifier struct {
    31  	ctx context.Context
    32  	C   chan event
    33  }
    34  
    35  func NewNotifier(ctx context.Context, buffer int) *Notifier {
    36  	return &Notifier{
    37  		ctx: ctx,
    38  		C:   make(chan event, buffer),
    39  	}
    40  }
    41  
    42  // NotifyLogtail provides incremental logtail.
    43  func (n *Notifier) NotifyLogtail(
    44  	from, to timestamp.Timestamp, closeCB func(), tails ...logtail.TableLogtail,
    45  ) error {
    46  	select {
    47  	case <-n.ctx.Done():
    48  		return n.ctx.Err()
    49  	case n.C <- event{from: from, to: to, closeCB: closeCB, logtails: tails}:
    50  	}
    51  	return nil
    52  }
    53  
    54  type event struct {
    55  	from, to timestamp.Timestamp
    56  	closeCB  func()
    57  	logtails []logtail.TableLogtail
    58  }