Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/grpc/grpc-java into otel-…
Browse files Browse the repository at this point in the history
…tracing-module
  • Loading branch information
YifeiZhuang committed Aug 29, 2024
2 parents 71db5e4 + c63e354 commit 0fcbb51
Show file tree
Hide file tree
Showing 42 changed files with 879 additions and 716 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ jobs:
name: "Gradle wrapper validation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: gradle/wrapper-validation-action@v1
- uses: actions/checkout@v4
- uses: gradle/actions/wrapper-validation@v4
2 changes: 1 addition & 1 deletion .github/workflows/lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
lock:
runs-on: ubuntu-latest
steps:
- uses: dessant/lock-threads@v4
- uses: dessant/lock-threads@v5
with:
github-token: ${{ github.token }}
issue-inactive-days: 90
Expand Down
20 changes: 11 additions & 9 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ jobs:
fail-fast: false # Should swap to true if we grow a large matrix

steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: ${{ matrix.jre }}
distribution: 'temurin'

- name: Gradle cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
Expand All @@ -37,7 +37,7 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: Maven cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.m2/repository
Expand All @@ -46,7 +46,7 @@ jobs:
restore-keys: |
${{ runner.os }}-maven-
- name: Protobuf cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: /tmp/protobuf-cache
key: ${{ runner.os }}-maven-${{ hashFiles('buildscripts/make_dependencies.sh') }}
Expand All @@ -55,7 +55,7 @@ jobs:
run: buildscripts/kokoro/unix.sh
- name: Post Failure Upload Test Reports to Artifacts
if: ${{ failure() }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Test Reports (JRE ${{ matrix.jre }})
path: |
Expand All @@ -71,23 +71,25 @@ jobs:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
run: ./gradlew :grpc-all:coveralls -PskipAndroid=true -x compileJava
- name: Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

bazel:
runs-on: ubuntu-latest
env:
USE_BAZEL_VERSION: 6.0.0

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Check versions match in MODULE.bazel and repositories.bzl
run: |
diff -u <(sed -n '/GRPC_DEPS_START/,/GRPC_DEPS_END/ {/GRPC_DEPS_/! p}' MODULE.bazel) \
<(sed -n '/GRPC_DEPS_START/,/GRPC_DEPS_END/ {/GRPC_DEPS_/! p}' repositories.bzl)
- name: Bazel cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cache/bazel/*/cache
Expand Down
5 changes: 0 additions & 5 deletions android-interop-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ dependencies {

implementation project(':grpc-android'),
project(':grpc-core'),
project(':grpc-auth'),
project(':grpc-census'),
project(':grpc-okhttp'),
project(':grpc-protobuf-lite'),
Expand All @@ -81,10 +80,6 @@ dependencies {
libraries.androidx.test.rules,
libraries.opencensus.contrib.grpc.metrics

implementation (libraries.google.auth.oauth2Http) {
exclude group: 'org.apache.httpcomponents'
}

implementation (project(':grpc-services')) {
exclude group: 'com.google.protobuf'
exclude group: 'com.google.guava'
Expand Down
83 changes: 30 additions & 53 deletions core/src/main/java/io/grpc/internal/PickFirstLeafLoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import io.grpc.EquivalentAddressGroup;
import io.grpc.LoadBalancer;
import io.grpc.Status;
import io.grpc.SynchronizationContext;
import io.grpc.SynchronizationContext.ScheduledHandle;
import java.net.SocketAddress;
import java.util.ArrayList;
Expand Down Expand Up @@ -61,7 +60,7 @@ final class PickFirstLeafLoadBalancer extends LoadBalancer {
static final int CONNECTION_DELAY_INTERVAL_MS = 250;
private final Helper helper;
private final Map<SocketAddress, SubchannelData> subchannels = new HashMap<>();
private Index addressIndex;
private final Index addressIndex = new Index(ImmutableList.of());
private int numTf = 0;
private boolean firstPass = true;
@Nullable
Expand Down Expand Up @@ -122,9 +121,7 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
final ImmutableList<EquivalentAddressGroup> newImmutableAddressGroups =
ImmutableList.<EquivalentAddressGroup>builder().addAll(cleanServers).build();

if (addressIndex == null) {
addressIndex = new Index(newImmutableAddressGroups);
} else if (rawConnectivityState == READY) {
if (rawConnectivityState == READY) {
// If the previous ready subchannel exists in new address list,
// keep this connection and don't create new subchannels
SocketAddress previousAddress = addressIndex.getCurrentAddress();
Expand All @@ -133,9 +130,8 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
SubchannelData subchannelData = subchannels.get(previousAddress);
subchannelData.getSubchannel().updateAddresses(addressIndex.getCurrentEagAsList());
return Status.OK;
} else {
addressIndex.reset(); // Previous ready subchannel not in the new list of addresses
}
// Previous ready subchannel not in the new list of addresses
} else {
addressIndex.updateGroups(newImmutableAddressGroups);
}
Expand All @@ -156,20 +152,18 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
}
}

if (oldAddrs.size() == 0 || rawConnectivityState == CONNECTING
|| rawConnectivityState == READY) {
// start connection attempt at first address
if (oldAddrs.size() == 0) {
// Make tests happy; they don't properly assume starting in CONNECTING
rawConnectivityState = CONNECTING;
updateBalancingState(CONNECTING, new Picker(PickResult.withNoResult()));
cancelScheduleTask();
requestConnection();
}

} else if (rawConnectivityState == IDLE) {
// start connection attempt at first address when requested
SubchannelPicker picker = new RequestConnectionPicker(this);
updateBalancingState(IDLE, picker);
if (rawConnectivityState == READY) {
// connect from beginning when prompted
rawConnectivityState = IDLE;
updateBalancingState(IDLE, new RequestConnectionPicker(this));

} else if (rawConnectivityState == TRANSIENT_FAILURE) {
} else if (rawConnectivityState == CONNECTING || rawConnectivityState == TRANSIENT_FAILURE) {
// start connection attempt at first address
cancelScheduleTask();
requestConnection();
Expand Down Expand Up @@ -207,9 +201,7 @@ public void handleNameResolutionError(Status error) {
subchannelData.getSubchannel().shutdown();
}
subchannels.clear();
if (addressIndex != null) {
addressIndex.updateGroups(null);
}
addressIndex.updateGroups(ImmutableList.of());
rawConnectivityState = TRANSIENT_FAILURE;
updateBalancingState(TRANSIENT_FAILURE, new Picker(PickResult.withError(error)));
}
Expand Down Expand Up @@ -372,7 +364,7 @@ private void shutdownRemaining(SubchannelData activeSubchannelData) {
*/
@Override
public void requestConnection() {
if (addressIndex == null || !addressIndex.isValid() || rawConnectivityState == SHUTDOWN ) {
if (!addressIndex.isValid() || rawConnectivityState == SHUTDOWN) {
return;
}

Expand All @@ -390,22 +382,14 @@ public void requestConnection() {
scheduleNextConnection();
break;
case CONNECTING:
if (enableHappyEyeballs) {
scheduleNextConnection();
} else {
subchannelData.subchannel.requestConnection();
}
scheduleNextConnection();
break;
case TRANSIENT_FAILURE:
addressIndex.increment();
requestConnection();
break;
case READY: // Shouldn't ever happen
log.warning("Requesting a connection even though we have a READY subchannel");
break;
case SHUTDOWN:
default:
// Makes checkstyle happy
// Wait for current subchannel to change state
}
}

Expand All @@ -430,16 +414,7 @@ public void run() {
}
}

SynchronizationContext synchronizationContext = null;
try {
synchronizationContext = helper.getSynchronizationContext();
} catch (NullPointerException e) {
// All helpers should have a sync context, but if one doesn't (ex. user had a custom test)
// we don't want to break previously working functionality.
return;
}

scheduleConnectionTask = synchronizationContext.schedule(
scheduleConnectionTask = helper.getSynchronizationContext().schedule(
new StartNextConnection(),
CONNECTION_DELAY_INTERVAL_MS,
TimeUnit.MILLISECONDS,
Expand Down Expand Up @@ -477,8 +452,7 @@ private SubchannelData createNewSubchannel(SocketAddress addr, Attributes attrs)
}

private boolean isPassComplete() {
if (addressIndex == null || addressIndex.isValid()
|| subchannels.size() < addressIndex.size()) {
if (addressIndex.isValid() || subchannels.size() < addressIndex.size()) {
return false;
}
for (SubchannelData sc : subchannels.values()) {
Expand All @@ -497,12 +471,9 @@ public void onSubchannelState(ConnectivityStateInfo newState) {
log.log(Level.FINE, "Received health status {0} for subchannel {1}",
new Object[]{newState, subchannelData.subchannel});
subchannelData.healthStateInfo = newState;
try {
if (subchannelData == subchannels.get(addressIndex.getCurrentAddress())) {
updateHealthCheckedState(subchannelData);
}
} catch (IllegalStateException e) {
log.fine("Health listener received state change after subchannel was removed");
if (addressIndex.isValid()
&& subchannelData == subchannels.get(addressIndex.getCurrentAddress())) {
updateHealthCheckedState(subchannelData);
}
}
}
Expand Down Expand Up @@ -566,11 +537,12 @@ public PickResult pickSubchannel(PickSubchannelArgs args) {
@VisibleForTesting
static final class Index {
private List<EquivalentAddressGroup> addressGroups;
private int size;
private int groupIndex;
private int addressIndex;

public Index(List<EquivalentAddressGroup> groups) {
this.addressGroups = groups != null ? groups : Collections.emptyList();
updateGroups(groups);
}

public boolean isValid() {
Expand Down Expand Up @@ -629,9 +601,14 @@ public List<EquivalentAddressGroup> getCurrentEagAsList() {
/**
* Update to new groups, resetting the current index.
*/
public void updateGroups(ImmutableList<EquivalentAddressGroup> newGroups) {
addressGroups = newGroups != null ? newGroups : Collections.emptyList();
public void updateGroups(List<EquivalentAddressGroup> newGroups) {
addressGroups = checkNotNull(newGroups, "newGroups");
reset();
int size = 0;
for (EquivalentAddressGroup eag : newGroups) {
size += eag.getAddresses().size();
}
this.size = size;
}

/**
Expand All @@ -652,7 +629,7 @@ public boolean seekTo(SocketAddress needle) {
}

public int size() {
return (addressGroups != null) ? addressGroups.size() : 0;
return size;
}
}

Expand Down
Loading

0 comments on commit 0fcbb51

Please sign in to comment.