vitess.io/vitess@v0.16.2/go/cmd/vtgateclienttest/services/fallback.go (about)

     1  /*
     2  Copyright 2019 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 services
    18  
    19  import (
    20  	"context"
    21  
    22  	"vitess.io/vitess/go/sqltypes"
    23  	"vitess.io/vitess/go/vt/vtgate/vtgateservice"
    24  
    25  	binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
    26  	querypb "vitess.io/vitess/go/vt/proto/query"
    27  	topodatapb "vitess.io/vitess/go/vt/proto/topodata"
    28  	vtgatepb "vitess.io/vitess/go/vt/proto/vtgate"
    29  )
    30  
    31  // fallbackClient implements vtgateservice.VTGateService, and always passes
    32  // through to its fallback service. This is useful to embed into other clients
    33  // so the fallback behavior doesn't have to be explicitly implemented in each
    34  // one.
    35  type fallbackClient struct {
    36  	fallback vtgateservice.VTGateService
    37  }
    38  
    39  func newFallbackClient(fallback vtgateservice.VTGateService) fallbackClient {
    40  	return fallbackClient{fallback: fallback}
    41  }
    42  
    43  func (c fallbackClient) Execute(ctx context.Context, session *vtgatepb.Session, sql string, bindVariables map[string]*querypb.BindVariable) (*vtgatepb.Session, *sqltypes.Result, error) {
    44  	return c.fallback.Execute(ctx, session, sql, bindVariables)
    45  }
    46  
    47  func (c fallbackClient) ExecuteBatch(ctx context.Context, session *vtgatepb.Session, sqlList []string, bindVariablesList []map[string]*querypb.BindVariable) (*vtgatepb.Session, []sqltypes.QueryResponse, error) {
    48  	return c.fallback.ExecuteBatch(ctx, session, sqlList, bindVariablesList)
    49  }
    50  
    51  func (c fallbackClient) StreamExecute(ctx context.Context, session *vtgatepb.Session, sql string, bindVariables map[string]*querypb.BindVariable, callback func(*sqltypes.Result) error) error {
    52  	return c.fallback.StreamExecute(ctx, session, sql, bindVariables, callback)
    53  }
    54  
    55  func (c fallbackClient) Prepare(ctx context.Context, session *vtgatepb.Session, sql string, bindVariables map[string]*querypb.BindVariable) (*vtgatepb.Session, []*querypb.Field, error) {
    56  	return c.fallback.Prepare(ctx, session, sql, bindVariables)
    57  }
    58  
    59  func (c fallbackClient) CloseSession(ctx context.Context, session *vtgatepb.Session) error {
    60  	return c.fallback.CloseSession(ctx, session)
    61  }
    62  
    63  func (c fallbackClient) ResolveTransaction(ctx context.Context, dtid string) error {
    64  	return c.fallback.ResolveTransaction(ctx, dtid)
    65  }
    66  
    67  func (c fallbackClient) VStream(ctx context.Context, tabletType topodatapb.TabletType, vgtid *binlogdatapb.VGtid, filter *binlogdatapb.Filter, flags *vtgatepb.VStreamFlags, send func([]*binlogdatapb.VEvent) error) error {
    68  	return c.fallback.VStream(ctx, tabletType, vgtid, filter, flags, send)
    69  }
    70  
    71  func (c fallbackClient) HandlePanic(err *error) {
    72  	c.fallback.HandlePanic(err)
    73  }