Skip to content

Commit 737da66

Browse files
committed
Introduce ServiceVersion framework to support backward compatible and reduce BlcokIdLayout message
1 parent 28fd03a commit 737da66

18 files changed

Lines changed: 273 additions & 53 deletions

File tree

client/src/main/java/org/apache/uniffle/client/impl/ShuffleWriteClientImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,8 @@ public void registerShuffle(
590590
valueClassName,
591591
comparatorClassName,
592592
mergedBlockSize,
593-
mergeClassLoader);
593+
mergeClassLoader,
594+
blockIdLayout);
594595
RssRegisterShuffleResponse response =
595596
getShuffleServerClient(shuffleServerInfo).registerShuffle(request);
596597

common/src/main/java/org/apache/uniffle/common/ShuffleServerInfo.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class ShuffleServerInfo implements Serializable {
3535

3636
private int nettyPort = -1;
3737

38+
private int serviceVersion = 0;
39+
3840
@VisibleForTesting
3941
public ShuffleServerInfo(String host, int port) {
4042
this.id = host + "-" + port;
@@ -57,10 +59,16 @@ public ShuffleServerInfo(String id, String host, int port) {
5759
}
5860

5961
public ShuffleServerInfo(String id, String host, int grpcPort, int nettyPort) {
62+
this(id, host, grpcPort, nettyPort, 0);
63+
}
64+
65+
public ShuffleServerInfo(
66+
String id, String host, int grpcPort, int nettyPort, int serviceVersion) {
6067
this.id = id;
6168
this.host = host;
6269
this.grpcPort = grpcPort;
6370
this.nettyPort = nettyPort;
71+
this.serviceVersion = serviceVersion;
6472
}
6573

6674
public String getId() {
@@ -79,6 +87,10 @@ public int getNettyPort() {
7987
return nettyPort;
8088
}
8189

90+
public int getServiceVersion() {
91+
return serviceVersion;
92+
}
93+
8294
@Override
8395
public int hashCode() {
8496
// By default id = host + "-" + grpc port, if netty port is greater than 0,
@@ -121,7 +133,8 @@ private static ShuffleServerInfo convertFromShuffleServerId(
121133
shuffleServerId.getId(),
122134
shuffleServerId.getIp(),
123135
shuffleServerId.getPort(),
124-
shuffleServerId.getNettyPort());
136+
shuffleServerId.getNettyPort(),
137+
shuffleServerId.getServiceVersion());
125138
return shuffleServerInfo;
126139
}
127140

common/src/main/java/org/apache/uniffle/common/netty/protocol/Decoders.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public static ShuffleServerInfo decodeShuffleServerInfo(ByteBuf byteBuf) {
3636
String host = ByteBufUtils.readLengthAndString(byteBuf);
3737
int grpcPort = byteBuf.readInt();
3838
int nettyPort = byteBuf.readInt();
39-
return new ShuffleServerInfo(id, host, grpcPort, nettyPort);
39+
// this decodeShuffleServerInfo method is deprecated,
40+
// clients do not need to encode service version
41+
return new ShuffleServerInfo(id, host, grpcPort, nettyPort, 0);
4042
}
4143

4244
public static ShuffleBlockInfo decodeShuffleBlockInfo(ByteBuf byteBuf) {
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
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+
18+
package org.apache.uniffle.common.rpc;
19+
20+
import java.util.Arrays;
21+
import java.util.Map;
22+
import java.util.stream.Collectors;
23+
24+
public class ServiceVersion {
25+
public static final ServiceVersion NEWEST_VERSION =
26+
new ServiceVersion(Feature.getNewest().getVersion());
27+
static final Map<Integer, Feature> VALUE_MAP =
28+
Arrays.stream(Feature.values()).collect(Collectors.toMap(Feature::getVersion, s -> s));
29+
private final int version;
30+
31+
public ServiceVersion(int version) {
32+
this.version = version;
33+
}
34+
35+
public Feature getCurrentFeature() {
36+
return VALUE_MAP.get(version);
37+
}
38+
39+
public boolean supportFeature(Feature registerBlockIdLayout) {
40+
return version >= registerBlockIdLayout.getVersion();
41+
}
42+
43+
public int getVersion() {
44+
return version;
45+
}
46+
47+
public enum Feature {
48+
// Treat the old version as init version
49+
INIT_VERSION(0),
50+
// Register block id layout to server to avoid sending block id layout for each getShuffleResult
51+
// request
52+
REGISTER_BLOCK_ID_LAYOUT(1),
53+
;
54+
55+
private final int version;
56+
57+
Feature(int version) {
58+
this.version = version;
59+
}
60+
61+
public int getVersion() {
62+
return version;
63+
}
64+
65+
public static Feature getNewest() {
66+
Feature[] enumConstants = Feature.class.getEnumConstants();
67+
return enumConstants[enumConstants.length - 1];
68+
}
69+
}
70+
}

common/src/main/java/org/apache/uniffle/common/util/BlockIdLayout.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.apache.uniffle.common.config.RssClientConf;
2323
import org.apache.uniffle.common.config.RssConf;
24+
import org.apache.uniffle.proto.RssProtos;
2425

2526
/**
2627
* This represents the actual bit layout of {@link BlockId}s.
@@ -194,6 +195,14 @@ public BlockId asBlockId(int sequenceNo, int partitionId, long taskAttemptId) {
194195
(int) taskAttemptId);
195196
}
196197

198+
public RssProtos.BlockIdLayout toProto() {
199+
return RssProtos.BlockIdLayout.newBuilder()
200+
.setSequenceNoBits(sequenceNoBits)
201+
.setPartitionIdBits(partitionIdBits)
202+
.setTaskAttemptIdBits(taskAttemptIdBits)
203+
.build();
204+
}
205+
197206
public static BlockIdLayout from(RssConf rssConf) {
198207
int sequenceBits = rssConf.get(RssClientConf.BLOCKID_SEQUENCE_NO_BITS);
199208
int partitionBits = rssConf.get(RssClientConf.BLOCKID_PARTITION_ID_BITS);

coordinator/src/main/java/org/apache/uniffle/coordinator/CoordinatorGrpcService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,8 @@ private ServerNode toServerNode(ShuffleServerHeartBeatRequest request) {
537537
request.getServerId().getJettyPort(),
538538
request.getStartTimeMs(),
539539
request.getVersion(),
540-
request.getGitCommitId());
540+
request.getGitCommitId(),
541+
request.getServiceVersion());
541542
}
542543

543544
/**

coordinator/src/main/java/org/apache/uniffle/coordinator/ServerNode.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Map;
2121
import java.util.Set;
2222

23+
import com.google.common.annotations.VisibleForTesting;
2324
import com.google.common.collect.Maps;
2425
import com.google.common.collect.Sets;
2526

@@ -29,6 +30,7 @@
2930

3031
public class ServerNode implements Comparable<ServerNode> {
3132

33+
private final int serviceVersion;
3234
private String id;
3335
private String ip;
3436
private int grpcPort;
@@ -51,7 +53,7 @@ public ServerNode(String id) {
5153
this(id, "", 0, 0, 0, 0, 0, Sets.newHashSet(), ServerStatus.EXCLUDED);
5254
}
5355

54-
// Only for test
56+
@VisibleForTesting
5557
public ServerNode(
5658
String id,
5759
String ip,
@@ -124,6 +126,7 @@ public ServerNode(
124126
-1);
125127
}
126128

129+
@VisibleForTesting
127130
public ServerNode(
128131
String id,
129132
String ip,
@@ -181,7 +184,8 @@ public ServerNode(
181184
jettyPort,
182185
startTime,
183186
"",
184-
"");
187+
"",
188+
0);
185189
}
186190

187191
public ServerNode(
@@ -199,7 +203,8 @@ public ServerNode(
199203
int jettyPort,
200204
long startTime,
201205
String version,
202-
String gitCommitId) {
206+
String gitCommitId,
207+
int serviceVersion) {
203208
this.id = id;
204209
this.ip = ip;
205210
this.grpcPort = grpcPort;
@@ -221,6 +226,7 @@ public ServerNode(
221226
this.startTime = startTime;
222227
this.version = version;
223228
this.gitCommitId = gitCommitId;
229+
this.serviceVersion = serviceVersion;
224230
}
225231

226232
public ShuffleServerId convertToGrpcProto() {
@@ -230,6 +236,7 @@ public ShuffleServerId convertToGrpcProto() {
230236
.setPort(grpcPort)
231237
.setNettyPort(nettyPort)
232238
.setJettyPort(jettyPort)
239+
.setServiceVersion(serviceVersion)
233240
.build();
234241
}
235242

internal-client/src/main/java/org/apache/uniffle/client/factory/ShuffleServerClientFactory.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@ private ShuffleServerClient createShuffleServerClient(
4747
String clientType, ShuffleServerInfo shuffleServerInfo, RssConf rssConf) {
4848
if (clientType.equalsIgnoreCase(ClientType.GRPC.name())) {
4949
return new ShuffleServerGrpcClient(
50-
rssConf, shuffleServerInfo.getHost(), shuffleServerInfo.getGrpcPort());
50+
rssConf,
51+
shuffleServerInfo.getHost(),
52+
shuffleServerInfo.getGrpcPort(),
53+
shuffleServerInfo.getServiceVersion());
5154
} else if (clientType.equalsIgnoreCase(ClientType.GRPC_NETTY.name())) {
5255
return new ShuffleServerGrpcNettyClient(
5356
rssConf,
5457
shuffleServerInfo.getHost(),
5558
shuffleServerInfo.getGrpcPort(),
56-
shuffleServerInfo.getNettyPort());
59+
shuffleServerInfo.getNettyPort(),
60+
shuffleServerInfo.getServiceVersion());
5761
} else {
5862
throw new UnsupportedOperationException("Unsupported client type " + clientType);
5963
}

internal-client/src/main/java/org/apache/uniffle/client/impl/grpc/CoordinatorGrpcClient.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.apache.uniffle.common.ServerStatus;
5353
import org.apache.uniffle.common.ShuffleServerInfo;
5454
import org.apache.uniffle.common.exception.RssException;
55+
import org.apache.uniffle.common.rpc.ServiceVersion;
5556
import org.apache.uniffle.common.rpc.StatusCode;
5657
import org.apache.uniffle.common.storage.StorageInfo;
5758
import org.apache.uniffle.common.storage.StorageInfoUtils;
@@ -149,6 +150,7 @@ public ShuffleServerHeartBeatResponse doSendHeartBeat(
149150
.setStartTimeMs(startTimeMs)
150151
.setVersion(Constants.VERSION)
151152
.setGitCommitId(Constants.REVISION_SHORT)
153+
.setServiceVersion(ServiceVersion.NEWEST_VERSION.getVersion())
152154
.build();
153155

154156
RssProtos.StatusCode status;
@@ -421,7 +423,11 @@ public Map<Integer, List<ShuffleServerInfo>> getPartitionToServers(
421423
.map(
422424
ss ->
423425
new ShuffleServerInfo(
424-
ss.getId(), ss.getIp(), ss.getPort(), ss.getNettyPort()))
426+
ss.getId(),
427+
ss.getIp(),
428+
ss.getPort(),
429+
ss.getNettyPort(),
430+
ss.getServiceVersion()))
425431
.collect(Collectors.toList());
426432
for (int i = startPartition; i <= endPartition; i++) {
427433
partitionToServers.put(i, shuffleServerInfos);
@@ -446,7 +452,12 @@ public Map<ShuffleServerInfo, List<PartitionRange>> getServerToPartitionRanges(
446452
new PartitionRange(assign.getStartPartition(), assign.getEndPartition());
447453
for (ShuffleServerId ssi : shuffleServerIds) {
448454
ShuffleServerInfo shuffleServerInfo =
449-
new ShuffleServerInfo(ssi.getId(), ssi.getIp(), ssi.getPort(), ssi.getNettyPort());
455+
new ShuffleServerInfo(
456+
ssi.getId(),
457+
ssi.getIp(),
458+
ssi.getPort(),
459+
ssi.getNettyPort(),
460+
ssi.getServiceVersion());
450461
if (!serverToPartitionRanges.containsKey(shuffleServerInfo)) {
451462
serverToPartitionRanges.put(shuffleServerInfo, Lists.newArrayList());
452463
}

internal-client/src/main/java/org/apache/uniffle/client/impl/grpc/GrpcClient.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,35 @@
2525
import org.slf4j.Logger;
2626
import org.slf4j.LoggerFactory;
2727

28+
import org.apache.uniffle.common.rpc.ServiceVersion;
2829
import org.apache.uniffle.common.util.GrpcNettyUtils;
2930

3031
public abstract class GrpcClient {
3132

3233
private static final Logger logger = LoggerFactory.getLogger(GrpcClient.class);
3334
protected String host;
3435
protected int port;
36+
protected ServiceVersion serviceVersion;
3537
protected boolean usePlaintext;
3638
protected int maxRetryAttempts;
3739
protected ManagedChannel channel;
3840

3941
protected GrpcClient(String host, int port, int maxRetryAttempts, boolean usePlaintext) {
40-
this(host, port, maxRetryAttempts, usePlaintext, 0, 0, 0);
42+
this(host, port, 0, maxRetryAttempts, usePlaintext, 0, 0, 0);
4143
}
4244

4345
protected GrpcClient(
4446
String host,
4547
int port,
48+
int serviceVersion,
4649
int maxRetryAttempts,
4750
boolean usePlaintext,
4851
int pageSize,
4952
int maxOrder,
5053
int smallCacheSize) {
5154
this.host = host;
5255
this.port = port;
56+
this.serviceVersion = new ServiceVersion(serviceVersion);
5357
this.maxRetryAttempts = maxRetryAttempts;
5458
this.usePlaintext = usePlaintext;
5559

@@ -75,6 +79,10 @@ protected GrpcClient(ManagedChannel channel) {
7579
this.channel = channel;
7680
}
7781

82+
public ServiceVersion getServiceVersion() {
83+
return serviceVersion;
84+
}
85+
7886
public void close() {
7987
try {
8088
channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);

0 commit comments

Comments
 (0)