Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,8 @@ ext.createDiffFile = { ->

// venice-client
':!clients/venice-client/src/main/java/com/linkedin/venice/fastclient/factory/ClientFactory.java',
// CLI tool requiring real D2/ZK infrastructure to test
':!clients/venice-client/src/main/java/com/linkedin/venice/fastclient/FastClientQueryTool.java',
// unit test for gRPC Transport Client is not straightforward, adding to exclusion list for now
':!clients/venice-client/src/main/java/com/linkedin/venice/fastclient/transport/GrpcTransportClient.java',
// unit test for deprecated DispatchingVsonStoreClient is not meaningful since most logic is in its parent class
Expand All @@ -771,6 +773,8 @@ ext.createDiffFile = { ->

// venice-common
':!internal/venice-common/src/main/java/com/linkedin/venice/controllerapi/ControllerClient.java',
// D2 utility requiring real ZooKeeper to test
':!internal/venice-common/src/main/java/com/linkedin/venice/d2/D2ConfigUtils.java',
':!internal/venice-common/src/main/java/com/linkedin/venice/acl/handler/StoreAclHandler.java',

// venice-client-common
Expand Down
24 changes: 23 additions & 1 deletion clients/venice-client/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
plugins {
id 'com.github.johnrengelman.shadow'
}

dependencies {
// For helix-based metadata impl, and this will be removed before onboarding any customers.
implementation project(':internal:venice-common')
Expand Down Expand Up @@ -35,6 +39,24 @@ dependencies {
testImplementation libraries.openTelemetryTestSdk
}

shadowJar {
mergeServiceFiles()
}

artifacts {
archives shadowJar
}

jar {
manifest {
attributes = [
'Implementation-Title': 'Venice Fast Client',
'Implementation-Version': project.version,
'Main-Class': 'com.linkedin.venice.fastclient.FastClientQueryTool'
]
}
}

ext {
jacocoCoverageThreshold = 0.53
}
Expand All @@ -44,4 +66,4 @@ checkerFramework {
checkers = ['org.checkerframework.checker.nullness.NullnessChecker']
skipCheckerFramework = true
excludeTests = true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
package com.linkedin.venice.fastclient;

import com.linkedin.avroutil1.compatibility.AvroCompatibilityHelper;
import com.linkedin.d2.balancer.D2Client;
import com.linkedin.d2.balancer.D2ClientBuilder;
import com.linkedin.r2.transport.common.Client;
import com.linkedin.r2.transport.common.TransportClientFactory;
import com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter;
import com.linkedin.r2.transport.http.client.HttpClientFactory;
import com.linkedin.venice.D2.D2ClientUtils;
import com.linkedin.venice.client.store.AvroGenericStoreClient;
import com.linkedin.venice.exceptions.VeniceException;
import com.linkedin.venice.fastclient.factory.ClientFactory;
import com.linkedin.venice.fastclient.meta.StoreMetadataFetchMode;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericDatumReader;


/**
* A CLI tool to query values from a Venice store using the fast client with D2 service discovery.
*
* Usage: java -jar venice-client-all.jar {@literal <store_name>} {@literal <key>} {@literal <zk_address>} [--insecure]
*
* The optional --insecure flag enables a trust-all SSL context for environments where HTTPS
* is used with self-signed or untrusted certificates (e.g., Docker quickstart).
* Without this flag, the tool uses plain HTTP transport only.
*/
public class FastClientQueryTool {
public static void main(String[] args) throws Exception {
if (args.length < 3) {
System.out.println("Usage: java -jar venice-client-all.jar <store_name> <key> <zk_address> [--insecure]");
System.exit(1);
}

String storeName = args[0];
String keyString = args[1];
String zkAddress = args[2];
boolean insecure = args.length > 3 && "--insecure".equals(args[3]);

TransportClientFactory httpTransport = new HttpClientFactory.Builder().setUsePipelineV2(true).build();
D2ClientBuilder d2ClientBuilder = new D2ClientBuilder().setZkHosts(zkAddress)
.setZkSessionTimeout(5000, TimeUnit.MILLISECONDS)
.setZkStartupTimeout(5000, TimeUnit.MILLISECONDS)
.setLbWaitTimeout(5000, TimeUnit.MILLISECONDS)
.setBasePath("/d2");

Map<String, Object> r2Properties;

if (insecure) {
// Trust-all SSLContext for environments with self-signed/untrusted certs (non-production use)
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}

public void checkClientTrusted(X509Certificate[] certs, String authType) {
}

public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} };
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new SecureRandom());
SSLParameters sslParameters = sslContext.getDefaultSSLParameters();

Map<String, TransportClientFactory> transportClients = new HashMap<>();
transportClients.put("http", httpTransport);
transportClients.put("https", httpTransport);

d2ClientBuilder.setSSLContext(sslContext)
.setSSLParameters(sslParameters)
.setIsSSLEnabled(true)
.setClientFactories(transportClients);

r2Properties = new HashMap<>();
r2Properties.put(HttpClientFactory.HTTP_SSL_CONTEXT, sslContext);
r2Properties.put(HttpClientFactory.HTTP_SSL_PARAMS, sslParameters);
} else {
r2Properties = Collections.emptyMap();
}

D2Client d2Client = d2ClientBuilder.build();
D2ClientUtils.startClient(d2Client);

Client r2Client = new TransportClientAdapter(httpTransport.getClient(r2Properties));

// Build fast client config
ClientConfig clientConfig = new ClientConfig.ClientConfigBuilder<>().setStoreName(storeName)
.setR2Client(r2Client)
.setD2Client(d2Client)
.setClusterDiscoveryD2Service("venice-discovery")
.setStoreMetadataFetchMode(StoreMetadataFetchMode.SERVER_BASED_METADATA)
.setMetadataRefreshIntervalInSeconds(1)
.build();

try (AvroGenericStoreClient<Object, Object> client = ClientFactory.getAndStartGenericStoreClient(clientConfig)) {
// Poll until metadata (key schema) is available
Schema keySchema = null;
Exception lastException = null;
long deadline = System.currentTimeMillis() + 30_000;
while (keySchema == null) {
if (System.currentTimeMillis() > deadline) {
String message = "Timed out waiting for metadata to be fetched for store: " + storeName;
if (lastException != null) {
throw new VeniceException(message + ". Last error: " + lastException.getMessage(), lastException);
}
throw new VeniceException(message);
}
try {
keySchema = client.getKeySchema();
} catch (Exception e) {
// Metadata not yet available, record and retry until timeout
lastException = e;
keySchema = null;
}
if (keySchema == null) {
Thread.sleep(200);
}
}

Object key = convertKey(keyString, keySchema);

Object value = client.get(key).get(15, TimeUnit.SECONDS);

System.out.println("key-class=" + key.getClass().getCanonicalName());
System.out.println("value-class=" + (value == null ? "null" : value.getClass().getCanonicalName()));
System.out.println("key=" + keyString);
System.out.println("value=" + (value == null ? "null" : value.toString()));
} finally {
D2ClientUtils.shutdownClient(d2Client);
}
}

static Object convertKey(String keyString, Schema keySchema) {
Object key;
switch (keySchema.getType()) {
case INT:
key = Integer.parseInt(keyString);
break;
case LONG:
key = Long.parseLong(keyString);
break;
case FLOAT:
key = Float.parseFloat(keyString);
break;
case DOUBLE:
key = Double.parseDouble(keyString);
break;
case BOOLEAN:
key = Boolean.parseBoolean(keyString);
break;
case STRING:
key = keyString;
break;
default:
try {
key = new GenericDatumReader<>(keySchema, keySchema).read(
null,
AvroCompatibilityHelper
.newJsonDecoder(keySchema, new ByteArrayInputStream(keyString.getBytes(StandardCharsets.UTF_8))));
} catch (IOException e) {
throw new VeniceException("Invalid input key: " + keyString, e);
}
break;
}
return key;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.linkedin.venice.fastclient;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

import com.linkedin.avroutil1.compatibility.AvroCompatibilityHelper;
import com.linkedin.venice.exceptions.VeniceException;
import org.apache.avro.Schema;
import org.testng.annotations.Test;


public class FastClientQueryToolTest {
@Test
public void testConvertKeyString() {
Schema schema = Schema.create(Schema.Type.STRING);
Object key = FastClientQueryTool.convertKey("hello", schema);
assertEquals(key, "hello");
}

@Test
public void testConvertKeyInt() {
Schema schema = Schema.create(Schema.Type.INT);
Object key = FastClientQueryTool.convertKey("42", schema);
assertEquals(key, 42);
}

@Test
public void testConvertKeyLong() {
Schema schema = Schema.create(Schema.Type.LONG);
Object key = FastClientQueryTool.convertKey("123456789", schema);
assertEquals(key, 123456789L);
}

@Test
public void testConvertKeyFloat() {
Schema schema = Schema.create(Schema.Type.FLOAT);
Object key = FastClientQueryTool.convertKey("1.5", schema);
assertEquals(key, 1.5f);
}

@Test
public void testConvertKeyDouble() {
Schema schema = Schema.create(Schema.Type.DOUBLE);
Object key = FastClientQueryTool.convertKey("1.5", schema);
assertEquals(key, 1.5);
}

@Test
public void testConvertKeyBoolean() {
Schema schema = Schema.create(Schema.Type.BOOLEAN);
Object key = FastClientQueryTool.convertKey("true", schema);
assertEquals(key, true);

key = FastClientQueryTool.convertKey("false", schema);
assertEquals(key, false);
}

@Test(expectedExceptions = NumberFormatException.class)
public void testConvertKeyIntWithInvalidInput() {
Schema schema = Schema.create(Schema.Type.INT);
FastClientQueryTool.convertKey("not_a_number", schema);
}

@Test(expectedExceptions = VeniceException.class)
public void testConvertKeyComplexSchemaWithInvalidJson() {
Schema schema = Schema.createRecord("TestRecord", null, "test", false);
schema.setFields(
java.util.Collections.singletonList(
AvroCompatibilityHelper.createSchemaField("field1", Schema.create(Schema.Type.STRING), null, null)));
FastClientQueryTool.convertKey("not_valid_json", schema);
}

@Test
public void testConvertKeyComplexSchemaWithValidJson() {
Schema schema = Schema.createRecord("TestRecord", null, "test", false);
schema.setFields(
java.util.Collections.singletonList(
AvroCompatibilityHelper.createSchemaField("field1", Schema.create(Schema.Type.STRING), null, null)));
Object key = FastClientQueryTool.convertKey("{\"field1\": \"value1\"}", schema);
assertTrue(key.toString().contains("value1"));
}
}
2 changes: 2 additions & 0 deletions docker/build-venice-docker-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ version=$oss_release
cp *py venice-client/
cp ../clients/venice-push-job/build/libs/venice-push-job-all.jar venice-client/
cp ../clients/venice-thin-client/build/libs/venice-thin-client-all.jar venice-client/
cp ../clients/venice-client/build/libs/venice-client-all.jar venice-client/
cp ../clients/venice-admin-tool/build/libs/venice-admin-tool-all.jar venice-client/
cp *py venice-client-jupyter/
cp ../clients/venice-push-job/build/libs/venice-push-job-all.jar venice-client-jupyter/
Expand Down Expand Up @@ -51,6 +52,7 @@ done

rm -f venice-client/venice-push-job-all.jar
rm -f venice-client/venice-thin-client-all.jar
rm -f venice-client/venice-client-all.jar
rm -f venice-client/venice-admin-tool-all.jar
rm -f venice-client-jupyter/venice-push-job-all.jar
rm -f venice-client-jupyter/venice-thin-client-all.jar
Expand Down
2 changes: 2 additions & 0 deletions docker/venice-client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ WORKDIR ${VENICE_DIR}

COPY venice-push-job-all.jar bin/venice-push-job-all.jar
COPY venice-thin-client-all.jar bin/venice-thin-client-all.jar
COPY venice-client-all.jar bin/venice-client-all.jar
COPY venice-admin-tool-all.jar bin/venice-admin-tool-all.jar
COPY sample-data sample-data
COPY run-vpj.sh .
COPY fetch.sh .
COPY fast-client-fetch.sh .
COPY create-store.sh .
COPY avro-to-json.sh .
RUN chmod +x *.sh
Expand Down
10 changes: 10 additions & 0 deletions docker/venice-client/fast-client-fetch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

if [ "$#" -lt 2 ]; then
echo "Usage: $0 <storeName> <key>" >&2
exit 1
fi

storeName=$1
key=$2
java -jar /opt/venice/bin/venice-client-all.jar "$storeName" "$key" zookeeper:2181 2>/dev/null
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ssl.to.kakfa=false
controller.parent.mode=false
controller.system.schema.cluster.name=venice-cluster0
cluster.to.d2=venice-cluster0:venice-discovery
cluster.to.server.d2=venice-cluster0:venice-server-d2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we include the cluster name in the corresponding server d2 too? e.g. venice-cluster0:venice-server-cluster0-d2. Otherwise it's going to be confusing when we try to run with multiple clusters.

delay.to.rebalance.ms=0
offline.job.start.timeout.ms=60000
topic.cleanup.sleep.interval.between.topic.list.fetch.ms=30000
Expand Down
6 changes: 5 additions & 1 deletion docker/venice-router/single-dc-configs/router.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ router.connection.limit=20
system.schema.cluster.name=venice-cluster0
zookeeper.address=zookeeper:2181
sslToStorageNodes=false
router.enable.ssl=false
max.read.capacity=20000000
router.max.outgoing.connection=10
router.httpasyncclient.connection.warming.low.water.mark=1
kafka.zk.address=zookeeper:2181
router.max.outgoing.connection.per.route=2
router.http.client.pool.size=2
cluster.to.d2=venice-cluster0:venice-discovery
cluster.to.server.d2=venice-cluster0:venice-server-d2
kafka.bootstrap.servers=kafka:9092
router.storage.node.client.type=APACHE_HTTP_ASYNC_CLIENT
router.io.worker.count=4
router.io.worker.count=4
router.d2.announce.enabled=true
router.d2.announce.host=venice-router
Loading
Loading