-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
pickfirst: New pick first policy for dualstack #7498
Merged
arjan-bal
merged 64 commits into
grpc:master
from
arjan-bal:pickfirst_one_address_per_subconn
Oct 10, 2024
Merged
Changes from 56 commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
a1f262c
Use one subconn per address in pickfirst
arjan-bal 9043079
address review comments
arjan-bal 2541d51
ensure subConnList is never nil
arjan-bal f961973
Defer subConnList creation till conection start
arjan-bal cb5acc6
Move empty subConnList handling into refreshList function
arjan-bal 22e0bd4
Fix race conditions
arjan-bal 258145a
Replace mutex with atomic for subConnList state
arjan-bal eeacec3
Use a go routine to manage phase 1 connection attempts
arjan-bal 632f4df
support both pickfirst together
arjan-bal 69c6c7b
Use Java style implementation
arjan-bal 67b3e93
Revert comment change
arjan-bal cceb75d
Fix revive warnings
arjan-bal 0d43e4b
Synchronize using callback serializer
arjan-bal b2a092a
Prepare for running all tests with new pf
arjan-bal 56bfb59
Fix test failures
arjan-bal 17c63d2
Enable test using new pf
arjan-bal f1daad1
Fix tests
arjan-bal 747bd8a
Add unit tests
arjan-bal 84194db
Fix vet
arjan-bal 586b091
Calculate coverage using new pickfirst also
arjan-bal 31e8a10
Fix lint error
arjan-bal fcb0120
simplify serializer usage
arjan-bal 91b63ce
Remove re-resolution requsts since they are made by addrConn
arjan-bal 036fea3
Verify server addr in subconn in tests
arjan-bal 9a2d6a9
test balancer state transitions
arjan-bal 2a36f7f
Fix address to endpoint conversion logic
arjan-bal a8a243a
Address review comments
arjan-bal abb263b
Remove stale comment
arjan-bal 67b9b6b
Fix tests
arjan-bal 0792002
Fix vet
arjan-bal 3561462
start connecting in exitIdle only when balancer is in idle
arjan-bal d82da59
Address review comments
arjan-bal 2ed4aff
Add comments to address review
arjan-bal fe8637f
Handle subconn transitions from CONNECTING to IDLE
arjan-bal 02267d3
address review comments
arjan-bal a3049fe
Address review comments
arjan-bal 11924a9
fix vet
arjan-bal fd4817a
User existing test utils
arjan-bal e266639
make tests more readable
arjan-bal c44c80a
address review comments
arjan-bal 4a221d1
no more table driven tests
arjan-bal 08e8cb9
Keep b.state and state rerported to clientconn in sync
arjan-bal 2b2c2a3
Address review comments
arjan-bal 34da793
Address review comments
arjan-bal 6a7720e
Update picker less frequently
arjan-bal 1914445
Fix typos
arjan-bal ef1af59
address review comments
arjan-bal 45f3368
Merge remote-tracking branch 'source/master' into pickfirst_one_addre…
arjan-bal efa343b
Fix test breakage due to #7613
arjan-bal 60e14d0
Replace the callback serializer with a mutex
arjan-bal 88fbabe
Convert requestConnectionLocked to iteration from recursion
arjan-bal 30256a5
Fix lint
arjan-bal 6daf9cc
Report TF on resolver error
arjan-bal 1f03ef9
Comment wrapping, s/subcon/SubCon/g and flatten the endpoint list ear…
arjan-bal 61c4816
Don't close SubConns in resolverErrorLocked and fix comments
arjan-bal 2e9f873
Move common tests to pickfirst_test.go
arjan-bal c4b4aa4
Set first pass when exiting idle
arjan-bal f0e479e
Ensure exitIdle doesn't increment the address list multiple times
arjan-bal 58e2ff7
Move handling of CONNECITN to IDLE subchannels to outer block
arjan-bal 3103efe
Fix test log statement
arjan-bal a40d619
Merge branch 'master' of github.com:grpc/grpc-go into pickfirst_one_a…
arjan-bal e98bb80
Organize packages based on review comments
arjan-bal a5b55e4
use onceFunc in idlePicker and reduce duplication when entering IDLE
arjan-bal eb5a09a
Fix comments
arjan-bal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* | ||
* Copyright 2024 gRPC 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 pickfirst | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"google.golang.org/grpc/balancer" | ||
"google.golang.org/grpc/connectivity" | ||
"google.golang.org/grpc/internal/grpctest" | ||
"google.golang.org/grpc/internal/testutils" | ||
"google.golang.org/grpc/resolver" | ||
) | ||
|
||
const ( | ||
// Default timeout for tests in this package. | ||
defaultTestTimeout = 10 * time.Second | ||
// Default short timeout, to be used when waiting for events which are not | ||
// expected to happen. | ||
defaultTestShortTimeout = 100 * time.Millisecond | ||
) | ||
|
||
type s struct { | ||
grpctest.Tester | ||
} | ||
|
||
func Test(t *testing.T) { | ||
grpctest.RunSubTests(t, s{}) | ||
} | ||
|
||
// TestPickFirstLeaf_InitialResolverError sends a resolver error to the balancer | ||
// before a valid resolver update. It verifies that the clientconn state is | ||
// updated to TRANSIENT_FAILURE. | ||
func (s) TestPickFirstLeaf_InitialResolverError(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) | ||
defer cancel() | ||
cc := testutils.NewBalancerClientConn(t) | ||
bal := pickfirstBuilder{}.Build(cc, balancer.BuildOptions{}) | ||
defer bal.Close() | ||
bal.ResolverError(errors.New("resolution failed: test error")) | ||
|
||
if err := cc.WaitForConnectivityState(ctx, connectivity.TransientFailure); err != nil { | ||
t.Fatalf("cc.WaitForConnectivityState(%v) returned error: %v", connectivity.TransientFailure, err) | ||
} | ||
|
||
// After sending a valid update, the LB policy should report CONNECTING. | ||
ccState := balancer.ClientConnState{ | ||
ResolverState: resolver.State{ | ||
Endpoints: []resolver.Endpoint{ | ||
{Addresses: []resolver.Address{{Addr: "1.1.1.1:1"}}}, | ||
{Addresses: []resolver.Address{{Addr: "2.2.2.2:2"}}}, | ||
}, | ||
}, | ||
} | ||
if err := bal.UpdateClientConnState(ccState); err != nil { | ||
t.Fatalf("UpdateClientConnState(%v) returned error: %v", ccState, err) | ||
} | ||
|
||
if err := cc.WaitForConnectivityState(ctx, connectivity.Connecting); err != nil { | ||
t.Fatalf("cc.WaitForConnectivityState(%v) returned error: %v", connectivity.Connecting, err) | ||
} | ||
} | ||
|
||
// TestPickFirstLeaf_ResolverErrorinTF sends a resolver error to the balancer | ||
// before when it's attempting to connect to a SubConn TRANSIENT_FAILURE. It | ||
// verifies that the picker is updated and the SubConn is not closed. | ||
func (s) TestPickFirstLeaf_ResolverErrorinTF(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) | ||
defer cancel() | ||
cc := testutils.NewBalancerClientConn(t) | ||
bal := pickfirstBuilder{}.Build(cc, balancer.BuildOptions{}) | ||
defer bal.Close() | ||
|
||
// After sending a valid update, the LB policy should report CONNECTING. | ||
ccState := balancer.ClientConnState{ | ||
ResolverState: resolver.State{ | ||
Endpoints: []resolver.Endpoint{ | ||
{Addresses: []resolver.Address{{Addr: "1.1.1.1:1"}}}, | ||
}, | ||
}, | ||
} | ||
|
||
if err := bal.UpdateClientConnState(ccState); err != nil { | ||
t.Fatalf("UpdateClientConnState(%v) returned error: %v", ccState, err) | ||
} | ||
|
||
sc1 := <-cc.NewSubConnCh | ||
if err := cc.WaitForConnectivityState(ctx, connectivity.Connecting); err != nil { | ||
t.Fatalf("cc.WaitForConnectivityState(%v) returned error: %v", connectivity.Connecting, err) | ||
} | ||
|
||
scErr := fmt.Errorf("test error: connection refused") | ||
sc1.UpdateState(balancer.SubConnState{ | ||
ConnectivityState: connectivity.TransientFailure, | ||
ConnectionError: scErr, | ||
}) | ||
|
||
if err := cc.WaitForPickerWithErr(ctx, scErr); err != nil { | ||
t.Fatalf("cc.WaitForPickerWithErr(%v) returned error: %v", scErr, err) | ||
} | ||
|
||
bal.ResolverError(errors.New("resolution failed: test error")) | ||
if err := cc.WaitForErrPicker(ctx); err != nil { | ||
t.Fatalf("cc.WaitForPickerWithErr() returned error: %v", err) | ||
} | ||
|
||
select { | ||
case <-time.After(defaultTestShortTimeout): | ||
case sc := <-cc.ShutdownSubConnCh: | ||
t.Fatalf("Unexpected SubConn shutdown: %v", sc) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does anything use this
coverage_new_pickfirst.out
file? How? By wildcard?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I verified that it gets used by checking that the coverage went up after adding this step.
Codecov docs just say that multiple reports are merged "automatically", but don't specify the logic:
It is possible to explicitly specify the coverage files, we don't do that for the existing
coverage.out
filename.