Skip to content

Commit

Permalink
Merge pull request #6613 from planetscale/ss-oc2-vt-mode
Browse files Browse the repository at this point in the history
orc: vitess mode
  • Loading branch information
sougou authored Sep 3, 2020
2 parents b364fa5 + e2ccf88 commit 187be0a
Show file tree
Hide file tree
Showing 22 changed files with 903 additions and 308 deletions.
12 changes: 12 additions & 0 deletions config/orchestrator/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Debug": true,
"MySQLTopologyUser": "orc_client_user",
"MySQLTopologyPassword": "orc_client_user_password",
"MySQLReplicaUser": "vt_repl",
"MySQLReplicaPassword": "",
"BackendDB": "sqlite",
"SQLite3DataFile": "/home/sougou/dev/src/vitess.io/vitess/vtdataroot/orchestrator.sqlite3",
"RecoverMasterClusterFilters": ["*"],
"RecoveryPeriodBlockSeconds": 1,
"DelayMasterPromotionIfSQLThreadNotUpToDate": true
}
7 changes: 1 addition & 6 deletions go/cmd/orchestrator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var AppVersion, GitCommit string

// main is the application's entry point. It will either spawn a CLI or HTTP itnerfaces.
func main() {
// TODO(sougou): change this to use vitess servenv framework
configFile := flag.String("config", "", "config file name")
command := flag.String("c", "", "command, required. See full list of commands via 'orchestrator -c help'")
strict := flag.Bool("strict", false, "strict mode (more checks, slower)")
Expand All @@ -57,7 +58,6 @@ func main() {
config.RuntimeCLIFlags.Statement = flag.String("statement", "", "Statement/hint")
config.RuntimeCLIFlags.GrabElection = flag.Bool("grab-election", false, "Grab leadership (only applies to continuous mode)")
config.RuntimeCLIFlags.PromotionRule = flag.String("promotion-rule", "prefer", "Promotion rule for register-andidate (prefer|neutral|prefer_not|must_not)")
config.RuntimeCLIFlags.Version = flag.Bool("version", false, "Print version and exit")
config.RuntimeCLIFlags.SkipContinuousRegistration = flag.Bool("skip-continuous-registration", false, "Skip cli commands performaing continuous registration (to reduce orchestratrator backend db load")
config.RuntimeCLIFlags.EnableDatabaseUpdate = flag.Bool("enable-database-update", false, "Enable database update, overrides SkipOrchestratorDatabaseUpdate")
config.RuntimeCLIFlags.IgnoreRaftSetup = flag.Bool("ignore-raft-setup", false, "Override RaftEnabled for CLI invocation (CLI by default not allowed for raft setups). NOTE: operations by CLI invocation may not reflect in all raft nodes.")
Expand Down Expand Up @@ -91,11 +91,6 @@ func main() {
if *stack {
log.SetPrintStackTrace(*stack)
}
if *config.RuntimeCLIFlags.Version {
fmt.Println(AppVersion)
fmt.Println(GitCommit)
return
}

startText := "starting orchestrator"
if AppVersion != "" {
Expand Down
23 changes: 23 additions & 0 deletions go/cmd/orchestrator/plugin_consultopo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright 2019 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreedto in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

// This plugin imports consultopo to register the consul implementation of TopoServer.

import (
_ "vitess.io/vitess/go/vt/topo/consultopo"
)
23 changes: 23 additions & 0 deletions go/cmd/orchestrator/plugin_etcd2topo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright 2019 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

// This plugin imports etcd2topo to register the etcd2 implementation of TopoServer.

import (
_ "vitess.io/vitess/go/vt/topo/etcd2topo"
)
23 changes: 23 additions & 0 deletions go/cmd/orchestrator/plugin_grpctmclient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright 2019 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

// Imports and register the gRPC tabletmanager client

import (
_ "vitess.io/vitess/go/vt/vttablet/grpctmclient"
)
23 changes: 23 additions & 0 deletions go/cmd/orchestrator/plugin_kubernetestopo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright 2020 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

// This plugin imports k8stopo to register the kubernetes implementation of TopoServer.

import (
_ "vitess.io/vitess/go/vt/topo/k8stopo"
)
23 changes: 23 additions & 0 deletions go/cmd/orchestrator/plugin_zk2topo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright 2019 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreedto in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

// Imports and register the zk2 TopologyServer

import (
_ "vitess.io/vitess/go/vt/topo/zk2topo"
)
4 changes: 2 additions & 2 deletions go/vt/orchestrator/app/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ func standardHttp(continuousDiscovery bool) {
m.Use(gzip.All())
// Render html templates from templates directory
m.Use(render.Renderer(render.Options{
Directory: "resources",
Directory: "web/orchestrator",
Layout: "templates/layout",
HTMLContentType: "text/html",
}))
m.Use(martini.Static("resources/public", martini.StaticOptions{Prefix: config.Config.URLPrefix}))
m.Use(martini.Static("web/orchestrator/public", martini.StaticOptions{Prefix: config.Config.URLPrefix}))
if config.Config.UseMutualTLS {
m.Use(ssl.VerifyOUs(config.Config.SSLValidOUs))
}
Expand Down
3 changes: 3 additions & 0 deletions go/vt/orchestrator/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const (
// Configuration makes for orchestrator configuration input, which can be provided by user via JSON formatted file.
// Some of the parameteres have reasonable default values, and some (like database credentials) are
// strictly expected from user.
// TODO(sougou): change this to yaml parsing, and possible merge with tabletenv.
type Configuration struct {
Debug bool // set debug mode (similar to --debug option)
EnableSyslog bool // Should logs be directed (in addition) to syslog daemon?
Expand All @@ -74,6 +75,8 @@ type Configuration struct {
AgentsServerPort string // port orchestrator agents talk back to
MySQLTopologyUser string
MySQLTopologyPassword string
MySQLReplicaUser string // If set, use this credential instead of discovering from mysql. TODO(sougou): deprecate this in favor of fetching from vttablet
MySQLReplicaPassword string
MySQLTopologyCredentialsConfigFile string // my.cnf style configuration file from where to pick credentials. Expecting `user`, `password` under `[client]` section
MySQLTopologySSLPrivateKeyFile string // Private key file used to authenticate with a Topology mysql instance with TLS
MySQLTopologySSLCertFile string // Certificate PEM file used to authenticate with a Topology mysql instance with TLS
Expand Down
14 changes: 14 additions & 0 deletions go/vt/orchestrator/db/generate_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,4 +851,18 @@ var generateSQLBase = []string{
`
CREATE INDEX first_seen_idx_database_instance_stale_binlog_coordinates ON database_instance_stale_binlog_coordinates (first_seen)
`,
`
CREATE TABLE IF NOT EXISTS vitess_tablet (
hostname varchar(128) CHARACTER SET ascii NOT NULL,
port smallint(5) unsigned NOT NULL,
cell varchar(128) CHARACTER SET ascii NOT NULL,
tablet_type smallint(5) NOT NULL,
master_timestamp timestamp NOT NULL,
info varchar(512) CHARACTER SET ascii NOT NULL,
PRIMARY KEY (hostname, port)
) ENGINE=InnoDB DEFAULT CHARSET=ascii
`,
`
CREATE INDEX cell_idx_vitess_tablet ON vitess_tablet (cell)
`,
}
34 changes: 30 additions & 4 deletions go/vt/orchestrator/external/golib/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ import (
"fmt"
"log/syslog"
"os"
"runtime"
"runtime/debug"
"strings"
"time"

"vitess.io/vitess/go/vt/log"
)

// LogLevel indicates the severity of a log entry
Expand Down Expand Up @@ -123,6 +127,11 @@ func SetSyslogLevel(logLevel LogLevel) {

// logFormattedEntry nicely formats and emits a log entry
func logFormattedEntry(logLevel LogLevel, message string, args ...interface{}) string {
return logDepth(logLevel, 0, message, args...)
}

// logFormattedEntry nicely formats and emits a log entry
func logDepth(logLevel LogLevel, depth int, message string, args ...interface{}) string {
if logLevel > globalLogLevel {
return ""
}
Expand All @@ -137,7 +146,8 @@ func logFormattedEntry(logLevel LogLevel, message string, args ...interface{}) s
}

msgArgs := fmt.Sprintf(message, args...)
entryString := fmt.Sprintf("%s %s %s", localizedTime.Format(TimeFormat), logLevel, msgArgs)
sourceFile, pos := callerPos(depth)
entryString := fmt.Sprintf("%s %8s %s:%d] %s", localizedTime.Format(TimeFormat), logLevel, sourceFile, pos, msgArgs)
fmt.Fprintln(os.Stderr, entryString)

if syslogWriter != nil {
Expand Down Expand Up @@ -167,13 +177,27 @@ func logFormattedEntry(logLevel LogLevel, message string, args ...interface{}) s
return entryString
}

func callerPos(depth int) (string, int) {
_, file, line, ok := runtime.Caller(4 + depth)
if !ok {
file = "???"
line = 1
} else {
slash := strings.LastIndex(file, "/")
if slash >= 0 {
file = file[slash+1:]
}
}
return file, line
}

// logEntry emits a formatted log entry
func logEntry(logLevel LogLevel, message string, args ...interface{}) string {
entryString := message
for _, s := range args {
entryString += fmt.Sprintf(" %s", s)
}
return logFormattedEntry(logLevel, entryString)
return logDepth(logLevel, 1, entryString)
}

// logErrorEntry emits a log entry based on given error object
Expand All @@ -199,7 +223,8 @@ func Debugf(message string, args ...interface{}) string {
}

func Info(message string, args ...interface{}) string {
return logEntry(INFO, message, args...)
log.Infof(message, args...)
return fmt.Sprintf(message, args...)
}

func Infof(message string, args ...interface{}) string {
Expand Down Expand Up @@ -227,7 +252,8 @@ func Error(message string, args ...interface{}) error {
}

func Errorf(message string, args ...interface{}) error {
return errors.New(logFormattedEntry(ERROR, message, args...))
log.Infof(message, args...)
return fmt.Errorf(message, args...)
}

func Errore(err error) error {
Expand Down
14 changes: 14 additions & 0 deletions go/vt/orchestrator/inst/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,28 @@ import (
"encoding/json"
"fmt"
"strings"
"time"

"vitess.io/vitess/go/vt/orchestrator/config"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
)

type AnalysisCode string
type StructureAnalysisCode string

const (
NoProblem AnalysisCode = "NoProblem"
ClusterHasNoMaster AnalysisCode = "ClusterHasNoMaster"
DeadMasterWithoutReplicas AnalysisCode = "DeadMasterWithoutReplicas"
DeadMaster AnalysisCode = "DeadMaster"
DeadMasterAndReplicas AnalysisCode = "DeadMasterAndReplicas"
DeadMasterAndSomeReplicas AnalysisCode = "DeadMasterAndSomeReplicas"
MasterHasMaster AnalysisCode = "MasterHasMaster"
MasterIsReadOnly AnalysisCode = "MasterIsReadOnly"
ReplicaIsWritable AnalysisCode = "ReplicaIsWritable"
NotConnectedToMaster AnalysisCode = "NotConnectedToMaster"
ConnectedToWrongMaster AnalysisCode = "ConnectedToWrongMaster"
ReplicationStopped AnalysisCode = "ReplicationStopped"
UnreachableMasterWithLaggingReplicas AnalysisCode = "UnreachableMasterWithLaggingReplicas"
UnreachableMaster AnalysisCode = "UnreachableMaster"
MasterSingleReplicaNotReplicating AnalysisCode = "MasterSingleReplicaNotReplicating"
Expand Down Expand Up @@ -116,12 +125,16 @@ const (
type ReplicationAnalysis struct {
AnalyzedInstanceKey InstanceKey
AnalyzedInstanceMasterKey InstanceKey
TabletType topodatapb.TabletType
MasterTimeStamp time.Time
SuggestedClusterAlias string
ClusterDetails ClusterInfo
AnalyzedInstanceDataCenter string
AnalyzedInstanceRegion string
AnalyzedInstancePhysicalEnvironment string
AnalyzedInstanceBinlogCoordinates BinlogCoordinates
IsMaster bool
IsClusterMaster bool
IsCoMaster bool
LastCheckValid bool
LastCheckPartialSuccess bool
Expand All @@ -134,6 +147,7 @@ type ReplicationAnalysis struct {
Replicas InstanceKeyMap
SlaveHosts InstanceKeyMap // for backwards compatibility. Equals `Replicas`
IsFailingToConnectToMaster bool
ReplicationStopped bool
Analysis AnalysisCode
Description string
StructureAnalysis []StructureAnalysisCode
Expand Down
Loading

0 comments on commit 187be0a

Please sign in to comment.