Skip to content

Commit 841f70a

Browse files
authored
Merge branch 'apache:master' into RATIS-2251
2 parents d0aec29 + 7f85d46 commit 841f70a

File tree

48 files changed

+856
-120
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+856
-120
lines changed

.github/workflows/check.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ on:
7979
env:
8080
MAVEN_ARGS: --batch-mode --show-version
8181
MAVEN_OPTS: -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.http.retryHandler.class=standard -Dmaven.wagon.http.retryHandler.count=3
82-
WITH_COVERAGE: true
82+
WITH_COVERAGE: ${{ github.event_name == 'push' }}
8383

8484
jobs:
8585
check:
@@ -157,7 +157,6 @@ jobs:
157157
dev-support/checks/${{ inputs.script }}.sh ${{ inputs.script-args }}
158158
env:
159159
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
160-
WITH_COVERAGE: ${{ inputs.with-coverage }}
161160

162161
- name: Summary of failures
163162
if: ${{ failure() }}

.github/workflows/ci.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ jobs:
5050
timeout-minutes: 30
5151
secrets: inherit
5252

53+
release:
54+
uses: ./.github/workflows/check.yaml
55+
with:
56+
script: release
57+
timeout-minutes: 30
58+
secrets: inherit
59+
5360
repro:
5461
needs:
5562
- build
@@ -99,7 +106,7 @@ jobs:
99106
- unit
100107
runs-on: ubuntu-24.04
101108
timeout-minutes: 30
102-
if: (github.repository == 'apache/ratis' || github.repository == 'apache/incubator-ratis') && github.event_name != 'pull_request'
109+
if: github.event_name != 'pull_request'
103110
steps:
104111
- name: Checkout project
105112
uses: actions/checkout@v4
@@ -130,6 +137,7 @@ jobs:
130137
- name: Calculate combined coverage
131138
run: ./dev-support/checks/coverage.sh
132139
- name: Upload coverage to Sonar
140+
if: github.repository == 'apache/ratis'
133141
run: ./dev-support/checks/sonar.sh
134142
env:
135143
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}

dev-support/checks/release.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -e -u -o pipefail
18+
19+
# This script tests the local part of the release process. It does not publish anything.
20+
21+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
22+
cd "$DIR/../.." || exit 1
23+
24+
: "${RATISVERSION:="0.0.1"}"
25+
: "${RC:="-ci-test"}"
26+
: "${STAGING_REPO_DIR:="/tmp/ratis.staging-repo"}"
27+
: "${SVNDISTDIR:="/tmp/ratis.svn"}"
28+
: "${USERID:="ratis-ci-not-for-release"}"
29+
30+
MVN_REPO_DIR="${HOME}/.m2/repository"
31+
32+
mkdir -p "${SVNDISTDIR}"
33+
34+
if [[ -z "${CODESIGNINGKEY:-}" ]]; then
35+
gpg --batch --passphrase '' --pinentry-mode loopback --quick-generate-key "${USERID}" rsa4096 default 1d
36+
CODESIGNINGKEY=$(gpg --list-keys --with-colons "${USERID}" | grep '^pub:' | cut -f5 -d:)
37+
fi
38+
39+
git config user.email || git config user.email 'test@example.com'
40+
git config user.name || git config user.name 'Test User'
41+
42+
export CODESIGNINGKEY MVN_REPO_DIR RATISVERSION RC SVNDISTDIR
43+
44+
export MAVEN_ARGS="--batch-mode"
45+
46+
dev-support/make_rc.sh 1-prepare-src
47+
dev-support/make_rc.sh 2-verify-bin
48+
dev-support/make_rc.sh 3-publish-mvn -DaltDeploymentRepository="local::default::file://${STAGING_REPO_DIR}"
49+
dev-support/make_rc.sh 4-assembly

dev-support/checks/sonar.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ if [ ! "$SONAR_TOKEN" ]; then
2424
fi
2525

2626
${MVN} -B verify -DskipShade -DskipTests \
27-
org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar \
27+
sonar:sonar \
2828
-Dsonar.coverage.jacoco.xmlReportPaths="$(pwd)/target/coverage/all.xml" \
2929
-Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=apache -Dsonar.projectKey=apache-ratis

dev-support/make_rc.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ mvnFun() {
118118
mv "apache-ratis-${RATISVERSION}-src" "apache-ratis-${RATISVERSION}"
119119
cd "apache-ratis-${RATISVERSION}"
120120

121-
mvnFun clean verify -DskipTests=true -Prelease -Papache-release -Dgpg.keyname="${CODESIGNINGKEY}"
121+
mvnFun clean verify -DskipTests=true -Prelease -Papache-release -Dgpg.keyname="${CODESIGNINGKEY}" "$@"
122122
}
123123

124124
3-publish-mvn() {
@@ -137,7 +137,10 @@ mvnFun() {
137137
for i in *.tar.gz; do gpg --print-md SHA512 "${i}" > "${i}.sha512"; done
138138
for i in *.tar.gz; do gpg --print-mds "${i}" > "${i}.mds"; done
139139
cd "$SVNDISTDIR"
140-
svn add "${RATISVERSION}" || svn add "${RATISVERSION}/${RC#-}"
140+
# skip svn add in CI
141+
if [[ -z "${CI:-}" ]]; then
142+
svn add "${RATISVERSION}" || svn add "${RATISVERSION}/${RC#-}"
143+
fi
141144
}
142145

143146
5-publish-git(){

pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
<maven-surefire-plugin.version>3.0.0-M9</maven-surefire-plugin.version>
178178
<wagon-ssh.version>3.5.3</wagon-ssh.version>
179179
<hadoop-maven-plugins.version>3.4.0</hadoop-maven-plugins.version>
180+
<sonar-maven-plugin.version>5.0.0.4389</sonar-maven-plugin.version>
180181

181182

182183
<!-- org.codehaus.mojo -->
@@ -207,11 +208,11 @@
207208
<maven.min.version>3.3.9</maven.min.version>
208209

209210
<!-- Contains all shaded thirdparty dependencies -->
210-
<ratis.thirdparty.version>1.0.8</ratis.thirdparty.version>
211+
<ratis.thirdparty.version>1.0.9</ratis.thirdparty.version>
211212

212213
<!-- Need these for the protobuf compiler. *MUST* match what is in ratis-thirdparty -->
213214
<shaded.protobuf.version>3.25.5</shaded.protobuf.version>
214-
<shaded.grpc.version>1.69.0</shaded.grpc.version>
215+
<shaded.grpc.version>1.71.0</shaded.grpc.version>
215216

216217
<!-- Test properties -->
217218
<maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
@@ -732,6 +733,11 @@
732733
<artifactId>cyclonedx-maven-plugin</artifactId>
733734
<version>${cyclonedx.version}</version>
734735
</plugin>
736+
<plugin>
737+
<groupId>org.sonarsource.scanner.maven</groupId>
738+
<artifactId>sonar-maven-plugin</artifactId>
739+
<version>${sonar-maven-plugin.version}</version>
740+
</plugin>
735741
</plugins>
736742
</pluginManagement>
737743

ratis-common/src/main/java/org/apache/ratis/protocol/ClientId.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.ratis.protocol;
1919

2020
import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
21+
import org.apache.ratis.util.WeakValueCache;
2122

2223
import java.util.UUID;
2324

@@ -26,13 +27,17 @@
2627
* to correctly identify retry requests from the same client.
2728
*/
2829
public final class ClientId extends RaftId {
29-
private static final Factory<ClientId> FACTORY = new Factory<ClientId>() {
30+
private static final Factory<ClientId> FACTORY = new Factory<ClientId>(ClientId.class) {
3031
@Override
3132
ClientId newInstance(UUID uuid) {
3233
return new ClientId(uuid);
3334
}
3435
};
3536

37+
static WeakValueCache<UUID, ClientId> getCache() {
38+
return FACTORY.getCache();
39+
}
40+
3641
public static ClientId emptyClientId() {
3742
return FACTORY.emptyId();
3843
}

ratis-common/src/main/java/org/apache/ratis/protocol/RaftGroup.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@
1919

2020
import org.apache.ratis.util.Preconditions;
2121

22-
import java.util.*;
22+
import java.util.Arrays;
23+
import java.util.Collection;
24+
import java.util.Collections;
25+
import java.util.HashMap;
26+
import java.util.Map;
27+
import java.util.Objects;
28+
2329

2430
/**
2531
* Description of a raft group, which has a unique {@link RaftGroupId} and a collection of {@link RaftPeer}.

ratis-common/src/main/java/org/apache/ratis/protocol/RaftGroupId.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.ratis.protocol;
1919

2020
import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
21+
import org.apache.ratis.util.WeakValueCache;
2122

2223
import java.util.UUID;
2324

@@ -27,13 +28,17 @@
2728
* This is a value-based class.
2829
*/
2930
public final class RaftGroupId extends RaftId {
30-
private static final Factory<RaftGroupId> FACTORY = new Factory<RaftGroupId>() {
31+
private static final Factory<RaftGroupId> FACTORY = new Factory<RaftGroupId>(RaftGroupId.class) {
3132
@Override
3233
RaftGroupId newInstance(UUID uuid) {
3334
return new RaftGroupId(uuid);
3435
}
3536
};
3637

38+
static WeakValueCache<UUID, RaftGroupId> getCache() {
39+
return FACTORY.getCache();
40+
}
41+
3742
public static RaftGroupId emptyGroupId() {
3843
return FACTORY.emptyId();
3944
}

ratis-common/src/main/java/org/apache/ratis/protocol/RaftId.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@
1717
*/
1818
package org.apache.ratis.protocol;
1919

20-
import org.apache.ratis.thirdparty.com.google.common.cache.Cache;
21-
import org.apache.ratis.thirdparty.com.google.common.cache.CacheBuilder;
2220
import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
2321
import org.apache.ratis.thirdparty.com.google.protobuf.UnsafeByteOperations;
2422
import org.apache.ratis.util.JavaUtils;
2523
import org.apache.ratis.util.Preconditions;
24+
import org.apache.ratis.util.WeakValueCache;
2625

2726
import java.nio.ByteBuffer;
2827
import java.util.Objects;
2928
import java.util.UUID;
30-
import java.util.concurrent.ExecutionException;
3129
import java.util.function.Supplier;
3230

3331
/** Unique identifier implemented using {@link UUID}. */
@@ -53,18 +51,20 @@ static ByteString toByteString(UUID uuid) {
5351
}
5452

5553
abstract static class Factory<ID extends RaftId> {
56-
private final Cache<UUID, ID> cache = CacheBuilder.newBuilder()
57-
.weakValues()
58-
.build();
54+
private final WeakValueCache<UUID, ID> cache;
55+
56+
Factory(Class<ID> clazz) {
57+
this.cache = new WeakValueCache<>(clazz.getSimpleName() + "_UUID", this::newInstance);
58+
}
5959

6060
abstract ID newInstance(UUID uuid);
6161

62+
WeakValueCache<UUID, ID> getCache() {
63+
return cache;
64+
}
65+
6266
final ID valueOf(UUID uuid) {
63-
try {
64-
return cache.get(uuid, () -> newInstance(uuid));
65-
} catch (ExecutionException e) {
66-
throw new IllegalStateException("Failed to valueOf(" + uuid + ")", e);
67-
}
67+
return cache.getOrCreate(uuid);
6868
}
6969

7070
final ID valueOf(ByteString bytes) {

0 commit comments

Comments
 (0)