From e9925c7a6256bf1362fcf36484953cb790d453b6 Mon Sep 17 00:00:00 2001 From: Tanjin Xu Date: Thu, 18 Jan 2024 13:37:30 -0800 Subject: [PATCH 01/12] Disable CGO --- Makefile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f75e3a0721c..18cb702ed62 100644 --- a/Makefile +++ b/Makefile @@ -48,13 +48,16 @@ endif # Safe, since this code isn't performance critical. export CGO_CFLAGS := -O1 +# Disable CGO explicitly +export CGO_ENABLED=0 + # build the vitess binaries with dynamic dependency on libc build-dyn: ifndef NOBANNER echo $$(date): Building source tree endif bash ./build.env - CGO_ENABLED=0 go install -trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) -ldflags "$(shell tools/build_version_flags.sh)" ./go/... + go install -trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) -ldflags "$(shell tools/build_version_flags.sh)" ./go/... # build the vitess binaries statically build: @@ -63,7 +66,7 @@ ifndef NOBANNER endif bash ./build.env # build all the binaries by default with CGO disabled. - CGO_ENABLED=0 go install -trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) -ldflags "$(shell tools/build_version_flags.sh)" ./go/... + go install -trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) -ldflags "$(shell tools/build_version_flags.sh)" ./go/... # cross-build can be used to cross-compile Vitess client binaries # Outside of select client binaries (namely vtctlclient & vtexplain), cross-compiled Vitess Binaries are not recommended for production deployments @@ -76,7 +79,7 @@ endif # In order to cross-compile, go install requires GOBIN to be unset export GOBIN="" # For the specified GOOS + GOARCH, build all the binaries by default with CGO disabled - CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go install -trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) -ldflags "$(shell tools/build_version_flags.sh)" ./go/... + GOOS=${GOOS} GOARCH=${GOARCH} go install -trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) -ldflags "$(shell tools/build_version_flags.sh)" ./go/... if [ ! -x "${HOME}/go/bin/${GOOS}_${GOARCH}/vttablet" ]; then \ echo "Missing vttablet at: ${HOME}/go/bin/${GOOS}_${GOARCH}/vttablet" && exit; \ From 3f75e3066f3ff699f9658b02fd23cfa52f38f18b Mon Sep 17 00:00:00 2001 From: Tanjin Xu Date: Thu, 18 Jan 2024 16:35:13 -0800 Subject: [PATCH 02/12] revert bootstrap version change --- docker/base/Dockerfile.percona57 | 2 +- docker/base/Dockerfile.percona80 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/base/Dockerfile.percona57 b/docker/base/Dockerfile.percona57 index e3fb8bedc95..e30e0172d93 100644 --- a/docker/base/Dockerfile.percona57 +++ b/docker/base/Dockerfile.percona57 @@ -1,4 +1,4 @@ -ARG bootstrap_version=10.2 +ARG bootstrap_version=19 ARG image="vitess/bootstrap:${bootstrap_version}-percona57" FROM "${image}" diff --git a/docker/base/Dockerfile.percona80 b/docker/base/Dockerfile.percona80 index c7ae3ed7ac2..cfc93d3a579 100644 --- a/docker/base/Dockerfile.percona80 +++ b/docker/base/Dockerfile.percona80 @@ -1,4 +1,4 @@ -ARG bootstrap_version=10.2 +ARG bootstrap_version=19 ARG image="vitess/bootstrap:${bootstrap_version}-percona80" FROM "${image}" From 29fc96d3a7adc140de6677d4259447b1b5f6f90f Mon Sep 17 00:00:00 2001 From: Tanjin Xu Date: Fri, 19 Jan 2024 15:33:03 -0800 Subject: [PATCH 03/12] cache grpc dial options --- go/vt/grpcclient/client_auth_static.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/go/vt/grpcclient/client_auth_static.go b/go/vt/grpcclient/client_auth_static.go index 53be18cc4ff..63e47b23bda 100644 --- a/go/vt/grpcclient/client_auth_static.go +++ b/go/vt/grpcclient/client_auth_static.go @@ -31,6 +31,8 @@ var ( credsFile = flag.String("grpc_auth_static_client_creds", "", "when using grpc_static_auth in the server, this file provides the credentials to use to authenticate with server") // StaticAuthClientCreds implements client interface to be able to WithPerRPCCredentials _ credentials.PerRPCCredentials = (*StaticAuthClientCreds)(nil) + + grpcDialOptions = ([]grpc.DialOption) (nil) ) // StaticAuthClientCreds holder for client credentials @@ -56,6 +58,10 @@ func (c *StaticAuthClientCreds) RequireTransportSecurity() bool { // AppendStaticAuth optionally appends static auth credentials if provided. func AppendStaticAuth(opts []grpc.DialOption) ([]grpc.DialOption, error) { + if grpcDialOptions != nil { + return grpcDialOptions, nil + } + if *credsFile == "" { return opts, nil } From 683b028aa2ce8b877866814292e135efd62a155f Mon Sep 17 00:00:00 2001 From: Tanjin Xu Date: Fri, 19 Jan 2024 15:48:07 -0800 Subject: [PATCH 04/12] fix code --- go/vt/grpcclient/client_auth_static.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/go/vt/grpcclient/client_auth_static.go b/go/vt/grpcclient/client_auth_static.go index 63e47b23bda..c116fec0ecb 100644 --- a/go/vt/grpcclient/client_auth_static.go +++ b/go/vt/grpcclient/client_auth_static.go @@ -32,7 +32,7 @@ var ( // StaticAuthClientCreds implements client interface to be able to WithPerRPCCredentials _ credentials.PerRPCCredentials = (*StaticAuthClientCreds)(nil) - grpcDialOptions = ([]grpc.DialOption) (nil) + credsData = ([]byte)(nil) ) // StaticAuthClientCreds holder for client credentials @@ -58,19 +58,20 @@ func (c *StaticAuthClientCreds) RequireTransportSecurity() bool { // AppendStaticAuth optionally appends static auth credentials if provided. func AppendStaticAuth(opts []grpc.DialOption) ([]grpc.DialOption, error) { - if grpcDialOptions != nil { - return grpcDialOptions, nil - } - if *credsFile == "" { return opts, nil } - data, err := os.ReadFile(*credsFile) - if err != nil { - return nil, err + + var err error + if credsData == nil { + credsData, err = os.ReadFile(*credsFile) + if err != nil { + return nil, err + } } + clientCreds := &StaticAuthClientCreds{} - err = json.Unmarshal(data, clientCreds) + err = json.Unmarshal(credsData, clientCreds) if err != nil { return nil, err } From 96b3512344908d45ede3c814d8ba80a688c0195a Mon Sep 17 00:00:00 2001 From: Tanjin Xu Date: Fri, 19 Jan 2024 16:36:07 -0800 Subject: [PATCH 05/12] add sync.once --- go/vt/grpcclient/client_auth_static.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/go/vt/grpcclient/client_auth_static.go b/go/vt/grpcclient/client_auth_static.go index c116fec0ecb..4c0b8c7bdad 100644 --- a/go/vt/grpcclient/client_auth_static.go +++ b/go/vt/grpcclient/client_auth_static.go @@ -20,6 +20,7 @@ import ( "encoding/json" "flag" "os" + "sync" "context" @@ -64,7 +65,10 @@ func AppendStaticAuth(opts []grpc.DialOption) ([]grpc.DialOption, error) { var err error if credsData == nil { - credsData, err = os.ReadFile(*credsFile) + var once sync.Once + once.Do(func() { + credsData, err = os.ReadFile(*credsFile) + }) if err != nil { return nil, err } From 95c480c74f57e596a8a67bd6fd69ea97b5fc9b2e Mon Sep 17 00:00:00 2001 From: Tanjin Xu Date: Mon, 22 Jan 2024 10:39:00 -0800 Subject: [PATCH 06/12] move sync.once to global --- go/vt/grpcclient/client_auth_static.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/go/vt/grpcclient/client_auth_static.go b/go/vt/grpcclient/client_auth_static.go index 4c0b8c7bdad..f3783527fef 100644 --- a/go/vt/grpcclient/client_auth_static.go +++ b/go/vt/grpcclient/client_auth_static.go @@ -33,7 +33,9 @@ var ( // StaticAuthClientCreds implements client interface to be able to WithPerRPCCredentials _ credentials.PerRPCCredentials = (*StaticAuthClientCreds)(nil) - credsData = ([]byte)(nil) + clientCreds = (*StaticAuthClientCreds)(nil) + + once sync.Once ) // StaticAuthClientCreds holder for client credentials @@ -63,22 +65,27 @@ func AppendStaticAuth(opts []grpc.DialOption) ([]grpc.DialOption, error) { return opts, nil } - var err error - if credsData == nil { - var once sync.Once + if clientCreds == nil { + var err error once.Do(func() { + var credsData []byte credsData, err = os.ReadFile(*credsFile) + if err != nil { + return + } + + clientCreds = &StaticAuthClientCreds{} + err = json.Unmarshal(credsData, clientCreds) + if err != nil { + return + } }) + if err != nil { return nil, err } } - clientCreds := &StaticAuthClientCreds{} - err = json.Unmarshal(credsData, clientCreds) - if err != nil { - return nil, err - } creds := grpc.WithPerRPCCredentials(clientCreds) opts = append(opts, creds) return opts, nil From 5acdcc3a39872264317f5bbb527995ef4e85dceb Mon Sep 17 00:00:00 2001 From: Tanjin Xu Date: Mon, 22 Jan 2024 10:53:03 -0800 Subject: [PATCH 07/12] rework --- go/vt/grpcclient/client_auth_static.go | 30 ++++++++++++-------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/go/vt/grpcclient/client_auth_static.go b/go/vt/grpcclient/client_auth_static.go index f3783527fef..0b1d7ee6557 100644 --- a/go/vt/grpcclient/client_auth_static.go +++ b/go/vt/grpcclient/client_auth_static.go @@ -65,25 +65,23 @@ func AppendStaticAuth(opts []grpc.DialOption) ([]grpc.DialOption, error) { return opts, nil } - if clientCreds == nil { - var err error - once.Do(func() { - var credsData []byte - credsData, err = os.ReadFile(*credsFile) - if err != nil { - return - } - - clientCreds = &StaticAuthClientCreds{} - err = json.Unmarshal(credsData, clientCreds) - if err != nil { - return - } - }) + var err error + once.Do(func() { + var credsData []byte + credsData, err = os.ReadFile(*credsFile) + if err != nil { + return + } + clientCreds = &StaticAuthClientCreds{} + err = json.Unmarshal(credsData, clientCreds) if err != nil { - return nil, err + return } + }) + + if clientCreds == nil || err != nil { + return nil, err } creds := grpc.WithPerRPCCredentials(clientCreds) From f185aff7ed1435edc9ff8e9984f7cf435e1097b5 Mon Sep 17 00:00:00 2001 From: Tanjin Xu Date: Mon, 22 Jan 2024 10:55:39 -0800 Subject: [PATCH 08/12] ignore the err check --- go/vt/grpcclient/client_auth_static.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/vt/grpcclient/client_auth_static.go b/go/vt/grpcclient/client_auth_static.go index 0b1d7ee6557..ef89313e9f1 100644 --- a/go/vt/grpcclient/client_auth_static.go +++ b/go/vt/grpcclient/client_auth_static.go @@ -80,7 +80,7 @@ func AppendStaticAuth(opts []grpc.DialOption) ([]grpc.DialOption, error) { } }) - if clientCreds == nil || err != nil { + if clientCreds == nil { return nil, err } From f7b0aae5daa6ecb5220aa2de3b2c1d18362c99cd Mon Sep 17 00:00:00 2001 From: Tanjin Xu Date: Mon, 22 Jan 2024 10:57:11 -0800 Subject: [PATCH 09/12] fix the error check --- go/vt/grpcclient/client_auth_static.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/go/vt/grpcclient/client_auth_static.go b/go/vt/grpcclient/client_auth_static.go index ef89313e9f1..2770c96ae0b 100644 --- a/go/vt/grpcclient/client_auth_static.go +++ b/go/vt/grpcclient/client_auth_static.go @@ -65,23 +65,23 @@ func AppendStaticAuth(opts []grpc.DialOption) ([]grpc.DialOption, error) { return opts, nil } - var err error once.Do(func() { - var credsData []byte - credsData, err = os.ReadFile(*credsFile) + credsData, err := os.ReadFile(*credsFile) if err != nil { + // to-do: log the error message return } clientCreds = &StaticAuthClientCreds{} err = json.Unmarshal(credsData, clientCreds) if err != nil { + // to-do: log the error message return } }) if clientCreds == nil { - return nil, err + return nil, errors.New("no client creds found") } creds := grpc.WithPerRPCCredentials(clientCreds) From c01ba54d07b8b4b346a136de70086dae3912c886 Mon Sep 17 00:00:00 2001 From: Tanjin Xu Date: Mon, 22 Jan 2024 11:03:44 -0800 Subject: [PATCH 10/12] import errors --- go/vt/grpcclient/client_auth_static.go | 1 + 1 file changed, 1 insertion(+) diff --git a/go/vt/grpcclient/client_auth_static.go b/go/vt/grpcclient/client_auth_static.go index 2770c96ae0b..4b70680121e 100644 --- a/go/vt/grpcclient/client_auth_static.go +++ b/go/vt/grpcclient/client_auth_static.go @@ -21,6 +21,7 @@ import ( "flag" "os" "sync" + "errors" "context" From 234d18504fe57740367743a6114bbd9ba4bd2b2f Mon Sep 17 00:00:00 2001 From: Tanjin Xu Date: Wed, 24 Jan 2024 14:24:13 -0800 Subject: [PATCH 11/12] undo changes in v14 --- go/vt/discovery/tablet_health_check.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/go/vt/discovery/tablet_health_check.go b/go/vt/discovery/tablet_health_check.go index f0ad9b0a2ac..de345d515a5 100644 --- a/go/vt/discovery/tablet_health_check.go +++ b/go/vt/discovery/tablet_health_check.go @@ -19,7 +19,6 @@ package discovery import ( "context" "fmt" - "strings" "sync" "time" @@ -273,7 +272,7 @@ func (thc *tabletHealthCheck) checkConn(hc *HealthCheckImpl) { }() // Read stream health responses. - err := thc.stream(streamCtx, func(shr *query.StreamHealthResponse) error { + thc.stream(streamCtx, func(shr *query.StreamHealthResponse) error { // We received a message. Reset the back-off. retryDelay = hc.retryDelay // Don't block on send to avoid deadlocks. @@ -287,7 +286,7 @@ func (thc *tabletHealthCheck) checkConn(hc *HealthCheckImpl) { // streamCancel to make sure the watcher goroutine terminates. streamCancel() - if err != nil { + /*if err != nil { hcErrorCounters.Add([]string{thc.Target.Keyspace, thc.Target.Shard, topoproto.TabletTypeLString(thc.Target.TabletType)}, 1) // This means that another tablet has taken over the host:port that we were connected to. // So let's remove the tablet's data from the healthcheck, and if it is still a part of the @@ -302,7 +301,8 @@ func (thc *tabletHealthCheck) checkConn(hc *HealthCheckImpl) { // trivialUpdate = false because this is an error // up = false because we did not get a healthy response hc.updateHealth(thc.SimpleCopy(), thc.Target, false, false) - } + }*/ + // If there was a timeout send an error. We do this after stream has returned. // This will ensure that this update prevails over any previous message that // stream could have sent. From e714aee289bb5b6daa4c2fb88503d34c2c9f994e Mon Sep 17 00:00:00 2001 From: Tanjin Xu Date: Wed, 24 Jan 2024 15:35:47 -0800 Subject: [PATCH 12/12] undo the changes --- go/vt/discovery/tablet_health_check.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/go/vt/discovery/tablet_health_check.go b/go/vt/discovery/tablet_health_check.go index de345d515a5..338a229b48c 100644 --- a/go/vt/discovery/tablet_health_check.go +++ b/go/vt/discovery/tablet_health_check.go @@ -19,6 +19,7 @@ package discovery import ( "context" "fmt" + "strings" "sync" "time" @@ -272,7 +273,7 @@ func (thc *tabletHealthCheck) checkConn(hc *HealthCheckImpl) { }() // Read stream health responses. - thc.stream(streamCtx, func(shr *query.StreamHealthResponse) error { + err := thc.stream(streamCtx, func(shr *query.StreamHealthResponse) error { // We received a message. Reset the back-off. retryDelay = hc.retryDelay // Don't block on send to avoid deadlocks. @@ -286,7 +287,7 @@ func (thc *tabletHealthCheck) checkConn(hc *HealthCheckImpl) { // streamCancel to make sure the watcher goroutine terminates. streamCancel() - /*if err != nil { + if err != nil { hcErrorCounters.Add([]string{thc.Target.Keyspace, thc.Target.Shard, topoproto.TabletTypeLString(thc.Target.TabletType)}, 1) // This means that another tablet has taken over the host:port that we were connected to. // So let's remove the tablet's data from the healthcheck, and if it is still a part of the @@ -301,7 +302,7 @@ func (thc *tabletHealthCheck) checkConn(hc *HealthCheckImpl) { // trivialUpdate = false because this is an error // up = false because we did not get a healthy response hc.updateHealth(thc.SimpleCopy(), thc.Target, false, false) - }*/ + } // If there was a timeout send an error. We do this after stream has returned. // This will ensure that this update prevails over any previous message that