-
Notifications
You must be signed in to change notification settings - Fork 32
router, backend: retry connecting to different backends #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Copyright 2023 PingCAP, Inc. | ||
| // | ||
| // 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 router | ||
|
|
||
| type BackendSelector struct { | ||
| excluded []string | ||
| cur string | ||
| routeOnce func(excluded []string) string | ||
| addConn func(addr string, conn RedirectableConn) error | ||
| } | ||
|
|
||
| func (bs *BackendSelector) Reset() { | ||
| bs.excluded = bs.excluded[:0] | ||
| } | ||
|
|
||
| func (bs *BackendSelector) Next() string { | ||
| if len(bs.cur) > 0 { | ||
| bs.excluded = append(bs.excluded, bs.cur) | ||
| } | ||
| bs.cur = bs.routeOnce(bs.excluded) | ||
| return bs.cur | ||
| } | ||
|
|
||
| func (bs *BackendSelector) Succeed(conn RedirectableConn) error { | ||
| return bs.addConn(bs.cur, conn) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import ( | |
| "fmt" | ||
| "net" | ||
| "sync" | ||
| "time" | ||
|
|
||
| "github.com/pingcap/TiProxy/lib/util/errors" | ||
| pnet "github.com/pingcap/TiProxy/pkg/proxy/net" | ||
|
|
@@ -101,7 +102,7 @@ func (auth *Authenticator) verifyBackendCaps(logger *zap.Logger, backendCapabili | |
| return nil | ||
| } | ||
|
|
||
| type backendIOGetter func(ctx ConnContext, auth *Authenticator, resp *pnet.HandshakeResp) (*pnet.PacketIO, error) | ||
| type backendIOGetter func(ctx ConnContext, auth *Authenticator, resp *pnet.HandshakeResp, timeout time.Duration) (*pnet.PacketIO, error) | ||
|
|
||
| func (auth *Authenticator) handshakeFirstTime(logger *zap.Logger, clientIO *pnet.PacketIO, handshakeHandler HandshakeHandler, | ||
| getBackendIO backendIOGetter, frontendTLSConfig, backendTLSConfig *tls.Config) error { | ||
|
|
@@ -160,7 +161,7 @@ func (auth *Authenticator) handshakeFirstTime(logger *zap.Logger, clientIO *pnet | |
| auth.attrs = resp.Attrs | ||
|
|
||
| // In case of testing, backendIO is passed manually that we don't want to bother with the routing logic. | ||
| backendIO, err := getBackendIO(auth, auth, resp) | ||
| backendIO, err := getBackendIO(auth, auth, resp, 5*time.Second) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a constant,
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's different. The one passed to
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think both.I think that |
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.