vitess.io/vitess@v0.16.2/go/vt/vtorc/inst/replication_thread_state.go (about) 1 /* 2 Copyright 2019 GitHub Inc. 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 inst 18 19 import "vitess.io/vitess/go/mysql" 20 21 type ReplicationThreadState int 22 23 const ( 24 ReplicationThreadStateNoThread ReplicationThreadState = -1 25 ReplicationThreadStateStopped ReplicationThreadState = 0 26 ReplicationThreadStateRunning ReplicationThreadState = 1 27 ReplicationThreadStateOther ReplicationThreadState = 2 28 ) 29 30 func ReplicationThreadStateFromStatus(status string) ReplicationThreadState { 31 switch status { 32 case "No": 33 return ReplicationThreadStateStopped 34 case "Yes": 35 return ReplicationThreadStateRunning 36 } 37 return ReplicationThreadStateOther 38 } 39 40 // ReplicationThreadStateFromReplicationState gets the replication thread state from replication state 41 // TODO: Merge these two into one 42 func ReplicationThreadStateFromReplicationState(state mysql.ReplicationState) ReplicationThreadState { 43 switch state { 44 case mysql.ReplicationStateStopped: 45 return ReplicationThreadStateStopped 46 case mysql.ReplicationStateRunning: 47 return ReplicationThreadStateRunning 48 case mysql.ReplicationStateConnecting: 49 return ReplicationThreadStateOther 50 default: 51 return ReplicationThreadStateNoThread 52 } 53 } 54 55 func (replicationThreadState *ReplicationThreadState) IsRunning() bool { 56 return *replicationThreadState == ReplicationThreadStateRunning 57 } 58 func (replicationThreadState *ReplicationThreadState) IsStopped() bool { 59 return *replicationThreadState == ReplicationThreadStateStopped 60 } 61 func (replicationThreadState *ReplicationThreadState) Exists() bool { 62 return *replicationThreadState != ReplicationThreadStateNoThread 63 }