forked from dolthub/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtgate.go
92 lines (77 loc) · 3.1 KB
/
vtgate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2012, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"flag"
"time"
log "github.com/golang/glog"
"github.com/youtube/vitess/go/exit"
"github.com/youtube/vitess/go/vt/discovery"
"github.com/youtube/vitess/go/vt/servenv"
"github.com/youtube/vitess/go/vt/topo"
"github.com/youtube/vitess/go/vt/vtgate"
"github.com/youtube/vitess/go/vt/vtgate/planbuilder"
"golang.org/x/net/context"
)
var (
cell = flag.String("cell", "test_nj", "cell to use")
schemaFile = flag.String("vschema_file", "", "JSON schema file")
retryDelay = flag.Duration("retry-delay", 2*time.Millisecond, "retry delay")
retryCount = flag.Int("retry-count", 2, "retry count")
connTimeoutTotal = flag.Duration("conn-timeout-total", 3*time.Second, "vttablet connection timeout (total)")
connTimeoutPerConn = flag.Duration("conn-timeout-per-conn", 1500*time.Millisecond, "vttablet connection timeout (per connection)")
connLife = flag.Duration("conn-life", 365*24*time.Hour, "average life of vttablet connections")
maxInFlight = flag.Int("max-in-flight", 0, "maximum number of calls to allow simultaneously")
healthCheckRetryDelay = flag.Duration("healthcheck_retry_delay", 5*time.Second, "health check retry delay")
testGateway = flag.String("test_gateway", "", "additional gateway to test health check module")
)
var resilientSrvTopoServer *vtgate.ResilientSrvTopoServer
var topoReader *TopoReader
var healthCheck discovery.HealthCheck
var initFakeZK func()
func init() {
servenv.RegisterDefaultFlags()
}
func main() {
defer exit.Recover()
flag.Parse()
servenv.Init()
if initFakeZK != nil {
initFakeZK()
}
ts := topo.GetServer()
defer topo.CloseServers()
var schema *planbuilder.Schema
if *schemaFile != "" {
var err error
if schema, err = planbuilder.LoadFile(*schemaFile); err != nil {
log.Error(err)
exit.Return(1)
}
log.Infof("v3 is enabled: loaded schema from file: %v", *schemaFile)
} else {
ctx := context.Background()
schemaJSON, err := ts.GetVSchema(ctx)
if err != nil {
log.Warningf("Skipping v3 initialization: GetVSchema failed: %v", err)
goto startServer
}
schema, err = planbuilder.NewSchema([]byte(schemaJSON))
if err != nil {
log.Warningf("Skipping v3 initialization: GetVSchema failed: %v", err)
goto startServer
}
log.Infof("v3 is enabled: loaded schema from topo")
}
startServer:
resilientSrvTopoServer = vtgate.NewResilientSrvTopoServer(ts, "ResilientSrvTopoServer")
// For the initial phase vtgate is exposing
// topoReader api. This will be subsumed by
// vtgate once vtgate's client functions become active.
topoReader = NewTopoReader(resilientSrvTopoServer)
servenv.Register("toporeader", topoReader)
healthCheck = discovery.NewHealthCheck(*connTimeoutTotal, *healthCheckRetryDelay)
vtgate.Init(healthCheck, ts, resilientSrvTopoServer, schema, *cell, *retryDelay, *retryCount, *connTimeoutTotal, *connTimeoutPerConn, *connLife, *maxInFlight, *testGateway)
servenv.RunDefault()
}