Skip to content

Commit 6de74f3

Browse files
mutianfigorbernstein2gcf-owl-bot[bot]steveniemitz
authored
fix: a rare race condition in the row merger (#1939) (#2002)
* fix: a rare race condition in the row merger (#1939) * fix: a rare race condition in the row merger This would manifest as a hang when iterating over a ServerStream from ReadRows Change-Id: I74533c6714b40a68ec0ef81dadac747e10bee39d * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: Fix flaky metrics tests (#1865) This fixes a few flaky unit tests that relied on `Thread.sleep` to ensure that all metrics processing was done. Rather than using `Thread.sleep`, we can instead use an inline event queue in the OpenCensus stats component to execute all work inline, removing the need to wait for anything to finish. --------- Co-authored-by: Igor Bernstein <[email protected]> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Steven Niemitz <[email protected]>
1 parent 8127d34 commit 6de74f3

File tree

8 files changed

+251
-101
lines changed

8 files changed

+251
-101
lines changed

.github/workflows/ci.yaml

Lines changed: 79 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,54 @@
1-
'on':
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# Github action job to test core java library features on
15+
# downstream client libraries before they are released.
16+
on:
217
push:
318
branches:
4-
- 2.25.x
5-
pull_request: null
19+
- main
20+
pull_request:
621
name: ci
722
jobs:
823
units:
924
runs-on: ubuntu-latest
1025
strategy:
1126
fail-fast: false
1227
matrix:
13-
java:
14-
- 11
15-
- 17
28+
java: [11, 17]
1629
steps:
17-
- uses: actions/checkout@v3
18-
- uses: actions/setup-java@v3
19-
with:
20-
distribution: temurin
21-
java-version: ${{matrix.java}}
22-
- run: java -version
23-
- run: .kokoro/build.sh
24-
env:
25-
JOB_TYPE: test
30+
- uses: actions/checkout@v3
31+
- uses: actions/setup-java@v3
32+
with:
33+
distribution: temurin
34+
java-version: ${{matrix.java}}
35+
- run: java -version
36+
- run: .kokoro/build.sh
37+
env:
38+
JOB_TYPE: test
2639
units-java8:
27-
name: units (8)
40+
# Building using Java 17 and run the tests with Java 8 runtime
41+
name: "units (8)"
2842
runs-on: ubuntu-latest
2943
steps:
3044
- uses: actions/checkout@v3
3145
- uses: actions/setup-java@v3
3246
with:
3347
java-version: 8
3448
distribution: temurin
35-
- name: >-
36-
Set jvm system property environment variable for surefire plugin (unit
37-
tests)
49+
- name: "Set jvm system property environment variable for surefire plugin (unit tests)"
50+
# Maven surefire plugin (unit tests) allows us to specify JVM to run the tests.
51+
# https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#jvm
3852
run: echo "SUREFIRE_JVM_OPT=-Djvm=${JAVA_HOME}/bin/java" >> $GITHUB_ENV
3953
shell: bash
4054
- uses: actions/setup-java@v3
@@ -47,64 +61,63 @@ jobs:
4761
windows:
4862
runs-on: windows-latest
4963
steps:
50-
- name: Support longpaths
51-
run: git config --system core.longpaths true
52-
- uses: actions/checkout@v3
53-
- uses: actions/setup-java@v3
54-
with:
55-
distribution: temurin
56-
java-version: 8
57-
- run: java -version
58-
- run: .kokoro/build.bat
59-
env:
60-
JOB_TYPE: test
64+
- name: Support longpaths
65+
run: git config --system core.longpaths true
66+
- uses: actions/checkout@v3
67+
- uses: actions/setup-java@v3
68+
with:
69+
distribution: temurin
70+
java-version: 8
71+
- run: java -version
72+
- run: .kokoro/build.bat
73+
env:
74+
JOB_TYPE: test
6175
dependencies:
6276
runs-on: ubuntu-latest
6377
strategy:
6478
matrix:
65-
java:
66-
- 17
79+
java: [17]
6780
steps:
68-
- uses: actions/checkout@v3
69-
- uses: actions/setup-java@v3
70-
with:
71-
distribution: temurin
72-
java-version: ${{matrix.java}}
73-
- run: java -version
74-
- run: .kokoro/dependencies.sh
81+
- uses: actions/checkout@v3
82+
- uses: actions/setup-java@v3
83+
with:
84+
distribution: temurin
85+
java-version: ${{matrix.java}}
86+
- run: java -version
87+
- run: .kokoro/dependencies.sh
7588
javadoc:
7689
runs-on: ubuntu-latest
7790
steps:
78-
- uses: actions/checkout@v3
79-
- uses: actions/setup-java@v3
80-
with:
81-
distribution: temurin
82-
java-version: 17
83-
- run: java -version
84-
- run: .kokoro/build.sh
85-
env:
86-
JOB_TYPE: javadoc
91+
- uses: actions/checkout@v3
92+
- uses: actions/setup-java@v3
93+
with:
94+
distribution: temurin
95+
java-version: 17
96+
- run: java -version
97+
- run: .kokoro/build.sh
98+
env:
99+
JOB_TYPE: javadoc
87100
lint:
88101
runs-on: ubuntu-latest
89102
steps:
90-
- uses: actions/checkout@v3
91-
- uses: actions/setup-java@v3
92-
with:
93-
distribution: temurin
94-
java-version: 11
95-
- run: java -version
96-
- run: .kokoro/build.sh
97-
env:
98-
JOB_TYPE: lint
103+
- uses: actions/checkout@v3
104+
- uses: actions/setup-java@v3
105+
with:
106+
distribution: temurin
107+
java-version: 11
108+
- run: java -version
109+
- run: .kokoro/build.sh
110+
env:
111+
JOB_TYPE: lint
99112
clirr:
100113
runs-on: ubuntu-latest
101114
steps:
102-
- uses: actions/checkout@v3
103-
- uses: actions/setup-java@v3
104-
with:
105-
distribution: temurin
106-
java-version: 8
107-
- run: java -version
108-
- run: .kokoro/build.sh
109-
env:
110-
JOB_TYPE: clirr
115+
- uses: actions/checkout@v3
116+
- uses: actions/setup-java@v3
117+
with:
118+
distribution: temurin
119+
java-version: 8
120+
- run: java -version
121+
- run: .kokoro/build.sh
122+
env:
123+
JOB_TYPE: clirr

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ If you are using Maven without the BOM, add this to your dependencies:
5050
If you are using Gradle 5.x or later, add this to your dependencies:
5151

5252
```Groovy
53-
implementation platform('com.google.cloud:libraries-bom:26.18.0')
53+
implementation platform('com.google.cloud:libraries-bom:26.26.0')
5454
5555
implementation 'com.google.cloud:google-cloud-bigtable'
5656
```
5757
If you are using Gradle without BOM, add this to your dependencies:
5858

5959
```Groovy
60-
implementation 'com.google.cloud:google-cloud-bigtable:2.24.1'
60+
implementation 'com.google.cloud:google-cloud-bigtable:2.29.1'
6161
```
6262

6363
If you are using SBT, add this to your dependencies:
6464

6565
```Scala
66-
libraryDependencies += "com.google.cloud" % "google-cloud-bigtable" % "2.24.1"
66+
libraryDependencies += "com.google.cloud" % "google-cloud-bigtable" % "2.29.1"
6767
```
6868
<!-- {x-version-update-end} -->
6969

@@ -609,7 +609,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
609609
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigtable/java11.html
610610
[stability-image]: https://img.shields.io/badge/stability-stable-green
611611
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-bigtable.svg
612-
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigtable/2.24.1
612+
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigtable/2.29.1
613613
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
614614
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
615615
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/reframing/ReframingResponseObserver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ private void deliverUnsafe() {
277277
// Optimization: the inner loop will eager process any accumulated state, so reset the lock
278278
// for just this iteration. (If another event occurs during processing, it can increment the
279279
// lock to enqueue another iteration).
280-
lock.lazySet(1);
280+
lock.set(1);
281281

282282
// Process the upstream message if one exists.
283283
pollUpstream();

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableTracerCallableTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.junit.Assert.fail;
2020

2121
import com.google.api.gax.rpc.ClientContext;
22+
import com.google.api.gax.rpc.ServerStream;
2223
import com.google.api.gax.rpc.UnavailableException;
2324
import com.google.bigtable.v2.BigtableGrpc.BigtableImplBase;
2425
import com.google.bigtable.v2.CheckAndMutateRowRequest;
@@ -54,7 +55,6 @@
5455
import io.grpc.Status;
5556
import io.grpc.StatusRuntimeException;
5657
import io.grpc.stub.StreamObserver;
57-
import io.opencensus.impl.stats.StatsComponentImpl;
5858
import io.opencensus.stats.StatsComponent;
5959
import io.opencensus.tags.TagKey;
6060
import io.opencensus.tags.TagValue;
@@ -74,7 +74,7 @@ public class BigtableTracerCallableTest {
7474

7575
private FakeService fakeService = new FakeService();
7676

77-
private final StatsComponent localStats = new StatsComponentImpl();
77+
private final StatsComponent localStats = new SimpleStatsComponent();
7878
private EnhancedBigtableStub stub;
7979
private EnhancedBigtableStub noHeaderStub;
8080
private int attempts;
@@ -157,10 +157,9 @@ public void tearDown() {
157157
}
158158

159159
@Test
160-
public void testGFELatencyMetricReadRows() throws InterruptedException {
161-
stub.readRowsCallable().call(Query.create(TABLE_ID));
162-
163-
Thread.sleep(WAIT_FOR_METRICS_TIME_MS);
160+
public void testGFELatencyMetricReadRows() {
161+
ServerStream<?> call = stub.readRowsCallable().call(Query.create(TABLE_ID));
162+
call.forEach(r -> {});
164163

165164
long latency =
166165
StatsTestUtils.getAggregationValueAsLong(

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracerTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public class BuiltinMetricsTracerTest {
109109
private static final long FAKE_SERVER_TIMING = 50;
110110
private static final long SERVER_LATENCY = 100;
111111
private static final long APPLICATION_LATENCY = 200;
112+
private static final long SLEEP_VARIABILITY = 15;
112113

113114
private static final long CHANNEL_BLOCKING_LATENCY = 75;
114115

@@ -353,7 +354,11 @@ public void onComplete() {
353354
.recordOperation(status.capture(), tableId.capture(), zone.capture(), cluster.capture());
354355

355356
assertThat(counter.get()).isEqualTo(fakeService.getResponseCounter().get());
356-
assertThat(applicationLatency.getValue()).isAtLeast(APPLICATION_LATENCY * counter.get());
357+
// Thread.sleep might not sleep for the requested amount depending on the interrupt period
358+
// defined by the OS.
359+
// On linux this is ~1ms but on windows may be as high as 15-20ms.
360+
assertThat(applicationLatency.getValue())
361+
.isAtLeast((APPLICATION_LATENCY - SLEEP_VARIABILITY) * counter.get());
357362
assertThat(applicationLatency.getValue())
358363
.isAtMost(operationLatency.getValue() - SERVER_LATENCY);
359364
}

0 commit comments

Comments
 (0)