Skip to content

Commit 2ad367e

Browse files
authored
[controller] Auto-initialize ZK admin protocol version and enable detection service by default (linkedin#2769)
1 parent 6b527ed commit 2ad367e

6 files changed

Lines changed: 38 additions & 12 deletions

File tree

internal/venice-common/src/main/java/com/linkedin/venice/ConfigKeys.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3274,7 +3274,7 @@ private ConfigKeys() {
32743274
/**
32753275
* Enables / disables protocol version auto-detection service in parent controller.
32763276
* This service is responsible for detecting the admin operation protocol version to serialize message
3277-
* Default value is disabled (false).
3277+
* Default value is enabled (true).
32783278
*/
32793279
public static final String CONTROLLER_PROTOCOL_VERSION_AUTO_DETECTION_SERVICE_ENABLED =
32803280
"controller.protocol.version.auto.detection.service.enabled";

internal/venice-test-common/src/integrationTest/java/com/linkedin/venice/endToEnd/TestProtocolVersionAutoDetection.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public class TestProtocolVersionAutoDetection {
3838
@BeforeClass(alwaysRun = true)
3939
public void setUp() {
4040
Properties parentControllerProps = new Properties();
41-
parentControllerProps.put(CONTROLLER_PROTOCOL_VERSION_AUTO_DETECTION_SERVICE_ENABLED, true);
4241
parentControllerProps.put(CONTROLLER_PROTOCOL_VERSION_AUTO_DETECTION_SLEEP_MS, SERVICE_INTERVAL_MS);
4342
parentControllerProps.put(CONTROLLER_SSL_ENABLED, "false");
4443

services/venice-controller/src/main/java/com/linkedin/venice/controller/ProtocolVersionAutoDetectionService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
* 1. Get the current admin operation protocol versions from all controllers (parent + child) in the current cluster
2626
* and find the smallest version - good version to use.
2727
* 2. Get the admin operation protocol version from ZK.
28-
* 3. If the version in ZK is different from the current version, update the version in ZK.
29-
* To disable step 3, set the admin version for the cluster in ZK as -1.
28+
* 3. If the version in ZK is different from the current version, update the version in ZK. This includes the case
29+
* where ZK has no recorded version (sentinel -1), which is treated as needing initialization to the current good
30+
* version.
3031
*/
3132
public class ProtocolVersionAutoDetectionService extends AbstractVeniceService {
3233
private static final Logger LOGGER = LogManager.getLogger(ProtocolVersionAutoDetectionService.class);
@@ -134,8 +135,7 @@ private Runnable getRunnableTask() {
134135
clusterName,
135136
currentGoodVersion,
136137
upstreamVersion);
137-
if (upstreamVersion != -1 && currentGoodVersion != Long.MAX_VALUE
138-
&& !Objects.equals(currentGoodVersion, upstreamVersion)) {
138+
if (currentGoodVersion != Long.MAX_VALUE && !Objects.equals(currentGoodVersion, upstreamVersion)) {
139139
admin.updateAdminOperationProtocolVersion(clusterName, currentGoodVersion);
140140
LOGGER.info(
141141
"Updated admin operation protocol version in ZK for cluster {} from {} to {}",

services/venice-controller/src/main/java/com/linkedin/venice/controller/VeniceControllerClusterConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ public VeniceControllerClusterConfig(VeniceProperties props) {
12691269
props.getBoolean(ConfigKeys.CONTROLLER_ENABLE_HYBRID_STORE_PARTITION_COUNT_UPDATE, false);
12701270

12711271
this.isProtocolVersionAutoDetectionServiceEnabled =
1272-
props.getBoolean(CONTROLLER_PROTOCOL_VERSION_AUTO_DETECTION_SERVICE_ENABLED, false);
1272+
props.getBoolean(CONTROLLER_PROTOCOL_VERSION_AUTO_DETECTION_SERVICE_ENABLED, true);
12731273
this.protocolVersionAutoDetectionSleepMS =
12741274
props.getLong(CONTROLLER_PROTOCOL_VERSION_AUTO_DETECTION_SLEEP_MS, TimeUnit.MINUTES.toMillis(10));
12751275

services/venice-controller/src/main/java/com/linkedin/venice/controller/VeniceParentHelixAdmin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ public Set<Integer> getInUseValueSchemaIds(String clusterName, String storeName)
789789

790790
/**
791791
* Fetches the writer schema ID from ZK.
792-
* If the upstream protocol version (the one in /adminTopicMetadata) is -1 or larger than latest schema, returns the latest;
792+
* If the upstream protocol version (the one in /adminTopicMetadataV2) is -1 or larger than latest schema, returns the latest;
793793
* otherwise, returns the version in ZK.
794794
* @param clusterName The name of the cluster for which the writer schema id is to be fetched.
795795
* @return The writer schema id to be used to serialize the admin operation.

services/venice-controller/src/test/java/com/linkedin/venice/controller/TestProtocolVersionAutoDetectionService.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@
5353
* 1. The protocol version auto-detection service correctly detects the smallest local admin operation protocol version
5454
* for all consumers in the cluster.
5555
* 2. The service correctly updates the admin operation protocol version for the cluster.
56-
* 3. The service handles the case where the admin operation protocol version is -1, indicating that no update is needed.
57-
* 4. The service handles the case where the request to get the admin operation protocol version fails.
56+
* 3. The service skips the update when the upstream version already matches the smallest good version.
57+
* 4. The service updates ZK from the sentinel -1 (undefined) to the smallest good version on first detection.
58+
* 5. The service handles the case where the request to get the admin operation protocol version fails.
5859
*/
5960
public class TestProtocolVersionAutoDetectionService {
6061
private VeniceHelixAdmin admin;
@@ -194,11 +195,12 @@ public void testProtocolVersionDetection() throws Exception {
194195
}
195196

196197
@Test
197-
public void testProtocolVersionDetectionWithNoUpdate() throws Exception {
198-
// When version is -1, no need to update
198+
public void testProtocolVersionDetectionWithMatchingUpstreamVersion() throws Exception {
199+
// When upstream version equals the smallest good version, no update is needed.
199200
AdminMetadata adminMetadata = new AdminMetadata();
200201
adminMetadata.setPubSubPosition(InMemoryPubSubPosition.of(1L));
201202
adminMetadata.setExecutionId(1L);
203+
adminMetadata.setAdminOperationProtocolVersion(1L);
202204

203205
doReturn(adminMetadata).when(admin).getAdminTopicMetadata(clusterName, Optional.empty());
204206

@@ -249,6 +251,31 @@ public void testProtocolVersionDetectionWithNoUpdate() throws Exception {
249251
localProtocolVersionAutoDetectionService.stopInner();
250252
}
251253

254+
@Test
255+
public void testProtocolVersionDetectionUpdatesWhenUpstreamIsUndefined() throws Exception {
256+
// When upstream version is undefined (sentinel -1) in ZK, the service should still update ZK to the smallest
257+
// good version observed across controllers (1L in this setup).
258+
AdminMetadata adminMetadata = new AdminMetadata();
259+
adminMetadata.setPubSubPosition(InMemoryPubSubPosition.of(1L));
260+
adminMetadata.setExecutionId(1L);
261+
// Intentionally do not call setAdminOperationProtocolVersion -> getAdminOperationProtocolVersion() returns -1.
262+
263+
doReturn(adminMetadata).when(admin).getAdminTopicMetadata(clusterName, Optional.empty());
264+
265+
ProtocolVersionAutoDetectionStats realStats = createRealStats(clusterName);
266+
ProtocolVersionAutoDetectionService localProtocolVersionAutoDetectionService =
267+
new ProtocolVersionAutoDetectionService(clusterName, admin, realStats, DEFAULT_SLEEP_INTERVAL_MS);
268+
269+
localProtocolVersionAutoDetectionService.startInner();
270+
271+
TestUtils.waitForNonDeterministicAssertion(5, TimeUnit.SECONDS, () -> {
272+
verify(admin, atLeastOnce()).getAdminOperationVersionFromControllers(clusterName);
273+
verify(adminConsumerService, atLeastOnce()).updateAdminOperationProtocolVersion(clusterName, 1L);
274+
});
275+
276+
localProtocolVersionAutoDetectionService.stopInner();
277+
}
278+
252279
@Test
253280
public void testGetLocalAdminOperationProtocolVersionForAllConsumers() {
254281
ProtocolVersionAutoDetectionService localProtocolVersionAutoDetectionService =

0 commit comments

Comments
 (0)