vitess.io/vitess@v0.16.2/go/vt/vttablet/tabletmanager/vdiff/shard_streamer.go (about)

     1  /*
     2  Copyright 2022 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package vdiff
    18  
    19  import (
    20  	"context"
    21  
    22  	"vitess.io/vitess/go/sqltypes"
    23  	querypb "vitess.io/vitess/go/vt/proto/query"
    24  	topodatapb "vitess.io/vitess/go/vt/proto/topodata"
    25  	"vitess.io/vitess/go/vt/vtgate/engine"
    26  )
    27  
    28  // shardStreamer streams rows from one shard.
    29  // shardStreamer satisfies engine.StreamExecutor, and can be added to Primitives of engine.MergeSort.
    30  // Each tableDiffer has one shardStreamer per source and one for the target.
    31  type shardStreamer struct {
    32  	tablet *topodatapb.Tablet // tablet currently picked to stream from
    33  	shard  string
    34  
    35  	snapshotPosition string                // gtid set of the current snapshot which is being streamed from
    36  	result           chan *sqltypes.Result // the next row is sent to this channel and received by the comparator
    37  	err              error
    38  }
    39  
    40  // StreamExecute implements the StreamExecutor interface of the Primitive executor and
    41  // it simply waits for a result to be available for this shard and sends it to the merge sorter.
    42  func (sm *shardStreamer) StreamExecute(ctx context.Context, vcursor engine.VCursor, bindVars map[string]*querypb.BindVariable, wantfields bool, callback func(*sqltypes.Result) error) error {
    43  	for result := range sm.result {
    44  		if err := callback(result); err != nil {
    45  			return err
    46  		}
    47  	}
    48  	return sm.err
    49  }