vitess.io/vitess@v0.16.2/go/vt/vtgate/planbuilder/throttler.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 planbuilder
    18  
    19  import (
    20  	"vitess.io/vitess/go/vt/key"
    21  	topodatapb "vitess.io/vitess/go/vt/proto/topodata"
    22  	"vitess.io/vitess/go/vt/vterrors"
    23  	"vitess.io/vitess/go/vt/vtgate/engine"
    24  	"vitess.io/vitess/go/vt/vtgate/planbuilder/plancontext"
    25  )
    26  
    27  func buildShowThrottledAppsPlan(query string, vschema plancontext.VSchema) (*planResult, error) {
    28  	dest, ks, tabletType, err := vschema.TargetDestination("")
    29  	if err != nil {
    30  		return nil, err
    31  	}
    32  	if ks == nil {
    33  		return nil, vterrors.VT09005()
    34  	}
    35  
    36  	if tabletType != topodatapb.TabletType_PRIMARY {
    37  		return nil, vterrors.VT09007("SHOW")
    38  	}
    39  
    40  	if dest == nil {
    41  		dest = key.DestinationAllShards{}
    42  	}
    43  
    44  	return newPlanResult(&engine.Send{
    45  		Keyspace:          ks,
    46  		TargetDestination: dest,
    47  		Query:             query,
    48  	}), nil
    49  }
    50  
    51  func buildShowThrottlerStatusPlan(query string, vschema plancontext.VSchema) (*planResult, error) {
    52  	dest, ks, tabletType, err := vschema.TargetDestination("")
    53  	if err != nil {
    54  		return nil, err
    55  	}
    56  	if ks == nil {
    57  		return nil, vterrors.VT09005()
    58  	}
    59  
    60  	if tabletType != topodatapb.TabletType_PRIMARY {
    61  		return nil, vterrors.VT09010()
    62  	}
    63  
    64  	if dest == nil {
    65  		dest = key.DestinationAllShards{}
    66  	}
    67  
    68  	return newPlanResult(&engine.Send{
    69  		Keyspace:          ks,
    70  		TargetDestination: dest,
    71  		Query:             query,
    72  	}), nil
    73  }