vitess.io/vitess@v0.16.2/go/vt/vttablet/tabletmanager/rpc_agent.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 tabletmanager 18 19 import ( 20 "context" 21 "time" 22 23 "vitess.io/vitess/go/vt/hook" 24 "vitess.io/vitess/go/vt/logutil" 25 "vitess.io/vitess/go/vt/mysqlctl/tmutils" 26 27 querypb "vitess.io/vitess/go/vt/proto/query" 28 replicationdatapb "vitess.io/vitess/go/vt/proto/replicationdata" 29 tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata" 30 topodatapb "vitess.io/vitess/go/vt/proto/topodata" 31 ) 32 33 // RPCTM defines the interface implemented by the TM for RPCs. 34 // It is useful for RPC implementations to test their full stack. 35 type RPCTM interface { 36 // RPC calls 37 38 // Various read-only methods 39 40 Ping(ctx context.Context, args string) string 41 42 GetSchema(ctx context.Context, request *tabletmanagerdatapb.GetSchemaRequest) (*tabletmanagerdatapb.SchemaDefinition, error) 43 44 GetPermissions(ctx context.Context) (*tabletmanagerdatapb.Permissions, error) 45 46 // Various read-write methods 47 48 SetReadOnly(ctx context.Context, rdonly bool) error 49 50 ChangeType(ctx context.Context, tabletType topodatapb.TabletType, semiSync bool) error 51 52 Sleep(ctx context.Context, duration time.Duration) 53 54 ExecuteHook(ctx context.Context, hk *hook.Hook) *hook.HookResult 55 56 RefreshState(ctx context.Context) error 57 58 RunHealthCheck(ctx context.Context) 59 60 ReloadSchema(ctx context.Context, waitPosition string) error 61 62 PreflightSchema(ctx context.Context, changes []string) ([]*tabletmanagerdatapb.SchemaChangeResult, error) 63 64 ApplySchema(ctx context.Context, change *tmutils.SchemaChange) (*tabletmanagerdatapb.SchemaChangeResult, error) 65 66 LockTables(ctx context.Context) error 67 68 UnlockTables(ctx context.Context) error 69 70 ExecuteQuery(ctx context.Context, req *tabletmanagerdatapb.ExecuteQueryRequest) (*querypb.QueryResult, error) 71 72 ExecuteFetchAsDba(ctx context.Context, req *tabletmanagerdatapb.ExecuteFetchAsDbaRequest) (*querypb.QueryResult, error) 73 74 ExecuteFetchAsAllPrivs(ctx context.Context, req *tabletmanagerdatapb.ExecuteFetchAsAllPrivsRequest) (*querypb.QueryResult, error) 75 76 ExecuteFetchAsApp(ctx context.Context, req *tabletmanagerdatapb.ExecuteFetchAsAppRequest) (*querypb.QueryResult, error) 77 78 // Replication related methods 79 PrimaryStatus(ctx context.Context) (*replicationdatapb.PrimaryStatus, error) 80 81 ReplicationStatus(ctx context.Context) (*replicationdatapb.Status, error) 82 83 FullStatus(ctx context.Context) (*replicationdatapb.FullStatus, error) 84 85 StopReplication(ctx context.Context) error 86 87 StopReplicationMinimum(ctx context.Context, position string, waitTime time.Duration) (string, error) 88 89 StartReplication(ctx context.Context, semiSync bool) error 90 91 StartReplicationUntilAfter(ctx context.Context, position string, waitTime time.Duration) error 92 93 GetReplicas(ctx context.Context) ([]string, error) 94 95 PrimaryPosition(ctx context.Context) (string, error) 96 97 WaitForPosition(ctx context.Context, pos string) error 98 99 // VExec generic API 100 VExec(ctx context.Context, query, workflow, keyspace string) (*querypb.QueryResult, error) 101 102 // VReplication API 103 VReplicationExec(ctx context.Context, query string) (*querypb.QueryResult, error) 104 VReplicationWaitForPos(ctx context.Context, id int, pos string) error 105 106 // VDiff API 107 VDiff(ctx context.Context, req *tabletmanagerdatapb.VDiffRequest) (*tabletmanagerdatapb.VDiffResponse, error) 108 109 // Reparenting related functions 110 111 ResetReplication(ctx context.Context) error 112 113 InitPrimary(ctx context.Context, semiSync bool) (string, error) 114 115 PopulateReparentJournal(ctx context.Context, timeCreatedNS int64, actionName string, tabletAlias *topodatapb.TabletAlias, pos string) error 116 117 InitReplica(ctx context.Context, parent *topodatapb.TabletAlias, replicationPosition string, timeCreatedNS int64, semiSync bool) error 118 119 DemotePrimary(ctx context.Context) (*replicationdatapb.PrimaryStatus, error) 120 121 UndoDemotePrimary(ctx context.Context, semiSync bool) error 122 123 ReplicaWasPromoted(ctx context.Context) error 124 125 ResetReplicationParameters(ctx context.Context) error 126 127 SetReplicationSource(ctx context.Context, parent *topodatapb.TabletAlias, timeCreatedNS int64, waitPosition string, forceStartReplication bool, semiSync bool) error 128 129 StopReplicationAndGetStatus(ctx context.Context, stopReplicationMode replicationdatapb.StopReplicationMode) (StopReplicationAndGetStatusResponse, error) 130 131 ReplicaWasRestarted(ctx context.Context, parent *topodatapb.TabletAlias) error 132 133 PromoteReplica(ctx context.Context, semiSync bool) (string, error) 134 135 // Backup / restore related methods 136 137 Backup(ctx context.Context, logger logutil.Logger, request *tabletmanagerdatapb.BackupRequest) error 138 139 RestoreFromBackup(ctx context.Context, logger logutil.Logger, request *tabletmanagerdatapb.RestoreFromBackupRequest) error 140 141 // HandleRPCPanic is to be called in a defer statement in each 142 // RPC input point. 143 HandleRPCPanic(ctx context.Context, name string, args, reply any, verbose bool, err *error) 144 }