vitess.io/vitess@v0.16.2/go/vt/vtgate/planbuilder/migration.go (about) 1 /* 2 Copyright 2021 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/schema" 23 "vitess.io/vitess/go/vt/sqlparser" 24 "vitess.io/vitess/go/vt/vterrors" 25 "vitess.io/vitess/go/vt/vtgate/engine" 26 "vitess.io/vitess/go/vt/vtgate/planbuilder/plancontext" 27 ) 28 29 func buildAlterMigrationPlan(query string, vschema plancontext.VSchema, enableOnlineDDL bool) (*planResult, error) { 30 if !enableOnlineDDL { 31 return nil, schema.ErrOnlineDDLDisabled 32 } 33 dest, ks, tabletType, err := vschema.TargetDestination("") 34 if err != nil { 35 return nil, err 36 } 37 if ks == nil { 38 return nil, vterrors.VT09005() 39 } 40 41 if tabletType != topodatapb.TabletType_PRIMARY { 42 return nil, vterrors.VT09006("ALTER") 43 } 44 45 if dest == nil { 46 dest = key.DestinationAllShards{} 47 } 48 49 send := &engine.Send{ 50 Keyspace: ks, 51 TargetDestination: dest, 52 Query: query, 53 } 54 return newPlanResult(send), nil 55 } 56 57 func buildRevertMigrationPlan(query string, stmt *sqlparser.RevertMigration, vschema plancontext.VSchema, enableOnlineDDL bool) (*planResult, error) { 58 if !enableOnlineDDL { 59 return nil, schema.ErrOnlineDDLDisabled 60 } 61 dest, ks, tabletType, err := vschema.TargetDestination("") 62 if err != nil { 63 return nil, err 64 } 65 if ks == nil { 66 return nil, vterrors.VT09005() 67 } 68 69 if tabletType != topodatapb.TabletType_PRIMARY { 70 return nil, vterrors.VT09006("REVERT") 71 } 72 73 if dest == nil { 74 dest = key.DestinationAllShards{} 75 } 76 77 emig := &engine.RevertMigration{ 78 Keyspace: ks, 79 TargetDestination: dest, 80 Stmt: stmt, 81 Query: query, 82 } 83 return newPlanResult(emig), nil 84 } 85 86 func buildShowMigrationLogsPlan(query string, vschema plancontext.VSchema, enableOnlineDDL bool) (*planResult, error) { 87 if !enableOnlineDDL { 88 return nil, schema.ErrOnlineDDLDisabled 89 } 90 dest, ks, tabletType, err := vschema.TargetDestination("") 91 if err != nil { 92 return nil, err 93 } 94 if ks == nil { 95 return nil, vterrors.VT09005() 96 } 97 98 if tabletType != topodatapb.TabletType_PRIMARY { 99 return nil, vterrors.VT09006("SHOW") 100 } 101 102 if dest == nil { 103 dest = key.DestinationAllShards{} 104 } 105 106 send := &engine.Send{ 107 Keyspace: ks, 108 TargetDestination: dest, 109 Query: query, 110 } 111 return newPlanResult(send), nil 112 }