Package com.linkedin.davinci.client
Class AvroGenericDaVinciClient<K,V>
- java.lang.Object
-
- com.linkedin.davinci.client.AvroGenericDaVinciClient<K,V>
-
- All Implemented Interfaces:
DaVinciClient<K,V>
,AvroGenericReadComputeStoreClient<K,V>
,AvroGenericStoreClient<K,V>
,java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
AvroSpecificDaVinciClient
public class AvroGenericDaVinciClient<K,V> extends java.lang.Object implements DaVinciClient<K,V>, AvroGenericReadComputeStoreClient<K,V>
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_CHUNK_SPLIT_THRESHOLD
protected org.apache.logging.log4j.Logger
logger
static java.util.concurrent.ExecutorService
READ_CHUNK_EXECUTOR
The following two fields are used to speed up the requests with a big number of keys: 1.
-
Constructor Summary
Constructors Modifier Constructor Description AvroGenericDaVinciClient(DaVinciConfig daVinciConfig, ClientConfig clientConfig, VeniceProperties backendConfig, java.util.Optional<java.util.Set<java.lang.String>> managedClients)
protected
AvroGenericDaVinciClient(DaVinciConfig daVinciConfig, ClientConfig clientConfig, VeniceProperties backendConfig, java.util.Optional<java.util.Set<java.lang.String>> managedClients, ICProvider icProvider, AbstractAvroChunkingAdapter<V> chunkingAdapter, java.lang.Runnable preValidation, java.util.concurrent.Executor readChunkExecutorForLargeRequest)
AvroGenericDaVinciClient(DaVinciConfig daVinciConfig, ClientConfig clientConfig, VeniceProperties backendConfig, java.util.Optional<java.util.Set<java.lang.String>> managedClients, ICProvider icProvider, java.util.concurrent.Executor readChunkExecutorForLargeRequest)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<java.util.Map<K,V>>
batchGet(java.util.Set<K> keys)
Get the values associated with the given keys and return them in a map of keys to values.void
close()
Release the internal resources.void
compute(ComputeRequestWrapper computeRequestWrapper, java.util.Set<K> keys, org.apache.avro.Schema resultSchema, StreamingCallback<K,ComputeGenericRecord> callback, long preRequestTimeInNS)
ComputeRequestBuilder<K>
compute(java.util.Optional<ClientStats> stats, AvroGenericReadComputeStoreClient computeStoreClient)
void
computeWithKeyPrefixFilter(byte[] keyPrefix, ComputeRequestWrapper computeRequestWrapper, StreamingCallback<org.apache.avro.generic.GenericRecord,org.apache.avro.generic.GenericRecord> callback)
protected D2ServiceDiscoveryResponse
discoverService()
java.util.concurrent.CompletableFuture<V>
get(K key)
Lookup the value by given key, and get(key).get() will return null if it doesn't exist.java.util.concurrent.CompletableFuture<V>
get(K key, V reusableValue)
Similar toAvroGenericStoreClient.get(Object)
except that it allows passing in a {@param reusedValue} instance, to minimize GC.protected AbstractAvroChunkingAdapter<V>
getAvroChunkingAdapter()
static DaVinciBackend
getBackend()
protected GenericRecordChunkingAdapter
getGenericRecordChunkingAdapter()
org.apache.avro.Schema
getKeySchema()
Get key schema.org.apache.avro.Schema
getLatestValueSchema()
Deprecated.int
getPartitionCount()
Get partition count of a store.SchemaReader
getSchemaReader()
java.lang.String
getStoreName()
protected void
initBackend(ClientConfig clientConfig, VeniceConfigLoader configLoader, java.util.Optional<java.util.Set<java.lang.String>> managedClients, ICProvider icProvider, java.util.Optional<ObjectCacheConfig> cacheConfig, DaVinciRecordTransformerFunctionalInterface recordTransformerFunction)
protected boolean
isPartitionReadyToServe(VersionBackend versionBackend, int partition)
Check if user partition is ready to serve traffic.protected boolean
isPartitionSubscribed(VersionBackend versionBackend, int partition)
boolean
isProjectionFieldValidationEnabled()
boolean
isReady()
static <K> java.util.List<java.util.List<K>>
split(java.util.Set<K> keySet, int threshold)
void
start()
void
streamingBatchGet(java.util.Set<K> keys, StreamingCallback<K,V> callback)
Streaming interface forAvroGenericStoreClient.batchGet(Set)
.protected java.util.concurrent.CompletableFuture<java.lang.Void>
subscribe(ComplementSet<java.lang.Integer> partitions)
java.util.concurrent.CompletableFuture<java.lang.Void>
subscribe(java.util.Set<java.lang.Integer> partitions)
Ingest specific partition/partitions locally.java.util.concurrent.CompletableFuture<java.lang.Void>
subscribeAll()
Ingest the entire data (i.e.protected void
throwIfNotReady()
java.lang.String
toString()
protected void
unsubscribe(ComplementSet<java.lang.Integer> partitions)
void
unsubscribe(java.util.Set<java.lang.Integer> partitions)
Stop ingesting a partition locally, and drop its associated local states/data.void
unsubscribeAll()
Stop ingesting all subscribed partition locally, and drop their associated local states/data.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.linkedin.venice.client.store.AvroGenericReadComputeStoreClient
compute, compute, compute
-
Methods inherited from interface com.linkedin.venice.client.store.AvroGenericStoreClient
streamingBatchGet
-
-
-
-
Field Detail
-
logger
protected final org.apache.logging.log4j.Logger logger
-
READ_CHUNK_EXECUTOR
public static final java.util.concurrent.ExecutorService READ_CHUNK_EXECUTOR
The following two fields are used to speed up the requests with a big number of keys: 1. Split the big request into smaller chunks. 2. Execute these chunks concurrently.
-
DEFAULT_CHUNK_SPLIT_THRESHOLD
public static final int DEFAULT_CHUNK_SPLIT_THRESHOLD
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AvroGenericDaVinciClient
public AvroGenericDaVinciClient(DaVinciConfig daVinciConfig, ClientConfig clientConfig, VeniceProperties backendConfig, java.util.Optional<java.util.Set<java.lang.String>> managedClients)
-
AvroGenericDaVinciClient
public AvroGenericDaVinciClient(DaVinciConfig daVinciConfig, ClientConfig clientConfig, VeniceProperties backendConfig, java.util.Optional<java.util.Set<java.lang.String>> managedClients, ICProvider icProvider, java.util.concurrent.Executor readChunkExecutorForLargeRequest)
-
AvroGenericDaVinciClient
protected AvroGenericDaVinciClient(DaVinciConfig daVinciConfig, ClientConfig clientConfig, VeniceProperties backendConfig, java.util.Optional<java.util.Set<java.lang.String>> managedClients, ICProvider icProvider, AbstractAvroChunkingAdapter<V> chunkingAdapter, java.lang.Runnable preValidation, java.util.concurrent.Executor readChunkExecutorForLargeRequest)
-
-
Method Detail
-
getSchemaReader
public SchemaReader getSchemaReader()
- Specified by:
getSchemaReader
in interfaceAvroGenericReadComputeStoreClient<K,V>
-
getStoreName
public java.lang.String getStoreName()
- Specified by:
getStoreName
in interfaceAvroGenericStoreClient<K,V>
-
getKeySchema
public org.apache.avro.Schema getKeySchema()
Description copied from interface:AvroGenericStoreClient
Get key schema.- Specified by:
getKeySchema
in interfaceAvroGenericStoreClient<K,V>
-
getLatestValueSchema
@Deprecated public org.apache.avro.Schema getLatestValueSchema()
Deprecated.Description copied from interface:AvroGenericStoreClient
Get the latest value schema known in current store client. This function doesn't guarantee it will return the latest schema if you add a new value schema when current store client is running.- Specified by:
getLatestValueSchema
in interfaceAvroGenericStoreClient<K,V>
-
getPartitionCount
public int getPartitionCount()
Description copied from interface:DaVinciClient
Get partition count of a store.- Specified by:
getPartitionCount
in interfaceDaVinciClient<K,V>
- Returns:
- partition count
-
subscribeAll
public java.util.concurrent.CompletableFuture<java.lang.Void> subscribeAll()
Description copied from interface:DaVinciClient
Ingest the entire data (i.e. all partitions) locally.- Specified by:
subscribeAll
in interfaceDaVinciClient<K,V>
- Returns:
- a future which completes when the data is ready to serve
-
subscribe
public java.util.concurrent.CompletableFuture<java.lang.Void> subscribe(java.util.Set<java.lang.Integer> partitions)
Description copied from interface:DaVinciClient
Ingest specific partition/partitions locally.- Specified by:
subscribe
in interfaceDaVinciClient<K,V>
- Parameters:
partitions
- the set of partition IDs to subscribe to- Returns:
- a future which completes when the partitions are ready to serve
-
subscribe
protected java.util.concurrent.CompletableFuture<java.lang.Void> subscribe(ComplementSet<java.lang.Integer> partitions)
-
unsubscribeAll
public void unsubscribeAll()
Description copied from interface:DaVinciClient
Stop ingesting all subscribed partition locally, and drop their associated local states/data. If applications intend to keep the states/data for future use, no need to invoke this function before callingAvroGenericStoreClient.close()
.- Specified by:
unsubscribeAll
in interfaceDaVinciClient<K,V>
-
unsubscribe
public void unsubscribe(java.util.Set<java.lang.Integer> partitions)
Description copied from interface:DaVinciClient
Stop ingesting a partition locally, and drop its associated local states/data. If applications intend to keep the states/data for future use, no need to invoke this function before callingAvroGenericStoreClient.close()
.- Specified by:
unsubscribe
in interfaceDaVinciClient<K,V>
- Parameters:
partitions
- the set of partition IDs to unsubscribe from
-
unsubscribe
protected void unsubscribe(ComplementSet<java.lang.Integer> partitions)
-
get
public java.util.concurrent.CompletableFuture<V> get(K key)
Description copied from interface:AvroGenericStoreClient
Lookup the value by given key, and get(key).get() will return null if it doesn't exist. For now, if any backend error/exception happens, get(Object key).get() will throwExecutionException
, which is a wrapper of the real exception.- Specified by:
get
in interfaceAvroGenericStoreClient<K,V>
- Returns:
-
get
public java.util.concurrent.CompletableFuture<V> get(K key, V reusableValue)
Description copied from interface:AvroGenericStoreClient
Similar toAvroGenericStoreClient.get(Object)
except that it allows passing in a {@param reusedValue} instance, to minimize GC.- Specified by:
get
in interfaceAvroGenericStoreClient<K,V>
-
split
public static <K> java.util.List<java.util.List<K>> split(java.util.Set<K> keySet, int threshold)
-
batchGet
public java.util.concurrent.CompletableFuture<java.util.Map<K,V>> batchGet(java.util.Set<K> keys) throws VeniceClientException
Description copied from interface:AvroGenericStoreClient
Get the values associated with the given keys and return them in a map of keys to values. Note that the returned map will only contain entries for the keys which have a value associated with them.- Specified by:
batchGet
in interfaceAvroGenericStoreClient<K,V>
- Returns:
- Throws:
VeniceClientException
-
streamingBatchGet
public void streamingBatchGet(java.util.Set<K> keys, StreamingCallback<K,V> callback) throws VeniceClientException
Description copied from interface:AvroGenericStoreClient
Streaming interface forAvroGenericStoreClient.batchGet(Set)
. You can find more info inStreamingCallback
.- Specified by:
streamingBatchGet
in interfaceAvroGenericStoreClient<K,V>
- Throws:
VeniceClientException
-
isProjectionFieldValidationEnabled
public boolean isProjectionFieldValidationEnabled()
- Specified by:
isProjectionFieldValidationEnabled
in interfaceAvroGenericReadComputeStoreClient<K,V>
-
compute
public ComputeRequestBuilder<K> compute(java.util.Optional<ClientStats> stats, AvroGenericReadComputeStoreClient computeStoreClient) throws VeniceClientException
- Specified by:
compute
in interfaceAvroGenericReadComputeStoreClient<K,V>
- Throws:
VeniceClientException
-
compute
public void compute(ComputeRequestWrapper computeRequestWrapper, java.util.Set<K> keys, org.apache.avro.Schema resultSchema, StreamingCallback<K,ComputeGenericRecord> callback, long preRequestTimeInNS) throws VeniceClientException
- Specified by:
compute
in interfaceAvroGenericReadComputeStoreClient<K,V>
- Throws:
VeniceClientException
-
computeWithKeyPrefixFilter
public void computeWithKeyPrefixFilter(byte[] keyPrefix, ComputeRequestWrapper computeRequestWrapper, StreamingCallback<org.apache.avro.generic.GenericRecord,org.apache.avro.generic.GenericRecord> callback)
- Specified by:
computeWithKeyPrefixFilter
in interfaceAvroGenericReadComputeStoreClient<K,V>
-
isReady
public boolean isReady()
-
isPartitionReadyToServe
protected boolean isPartitionReadyToServe(VersionBackend versionBackend, int partition)
Check if user partition is ready to serve traffic.
-
isPartitionSubscribed
protected boolean isPartitionSubscribed(VersionBackend versionBackend, int partition)
-
throwIfNotReady
protected void throwIfNotReady()
-
getAvroChunkingAdapter
protected AbstractAvroChunkingAdapter<V> getAvroChunkingAdapter()
-
getGenericRecordChunkingAdapter
protected GenericRecordChunkingAdapter getGenericRecordChunkingAdapter()
-
discoverService
protected D2ServiceDiscoveryResponse discoverService()
-
initBackend
protected void initBackend(ClientConfig clientConfig, VeniceConfigLoader configLoader, java.util.Optional<java.util.Set<java.lang.String>> managedClients, ICProvider icProvider, java.util.Optional<ObjectCacheConfig> cacheConfig, DaVinciRecordTransformerFunctionalInterface recordTransformerFunction)
-
getBackend
public static DaVinciBackend getBackend()
-
start
public void start()
- Specified by:
start
in interfaceAvroGenericStoreClient<K,V>
-
close
public void close()
Description copied from interface:AvroGenericStoreClient
Release the internal resources.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceAvroGenericStoreClient<K,V>
- Specified by:
close
in interfacejava.io.Closeable
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-