Package com.linkedin.davinci.repository
Class NativeMetadataRepository
java.lang.Object
com.linkedin.davinci.repository.NativeMetadataRepository
- All Implemented Interfaces:
ClusterInfoProvider
,ReadOnlySchemaRepository
,ReadOnlyStoreRepository
,SubscriptionBasedReadOnlyStoreRepository
,VeniceResource
- Direct Known Subclasses:
ThinClientMetaStoreBasedRepository
public abstract class NativeMetadataRepository
extends Object
implements SubscriptionBasedReadOnlyStoreRepository, ReadOnlySchemaRepository, ClusterInfoProvider
Venice in-house implementation of a read only metadata repository where callers can retrieve various metadata such as
Store objects and their corresponding schemas. The implementers of this abstract class all relies on some flavors of
Venice system store to carry the metadata from Venice internal components (source) to external consumers such as a
DaVinci client (destination). This abstract class includes the implementation of an in-memory cache for all subscribed
stores' metadata. Callers are served by the cache and the cache is refreshed periodically by updating it with methods
provided by the implementers.
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
NativeMetadataRepository
(ClientConfig clientConfig, VeniceProperties backendConfig) protected
NativeMetadataRepository
(ClientConfig clientConfig, VeniceProperties backendConfig, Clock clock) -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
TODO: we may need to rename this function to be 'close' since this resource should not used any more after calling this function.Get all stores in the current repositoryprotected SchemaData
getAndCacheSchemaDataFromSystemStore
(String storeName) protected void
getAndSetStoreConfigFromSystemStore
(String storeName) Get the store cluster config from system store and update the local cache with it.int
getBatchGetLimit
(String storeName) Get batch-get limit for the specified storegetDerivedSchema
(String storeName, int valueSchemaId, int derivedSchemaId) getDerivedSchemaId
(String storeName, String derivedSchemaStr) Look up derived schema id and its corresponding value schema id by given store name and derived schema.getDerivedSchemas
(String storeName) static NativeMetadataRepository
getInstance
(ClientConfig clientConfig, VeniceProperties backendConfig) static NativeMetadataRepository
getInstance
(ClientConfig clientConfig, VeniceProperties backendConfig, ICProvider icProvider) getKeySchema
(String storeName) This function is used to retrieve key schema for the given store.getLatestDerivedSchema
(String storeName, int valueSchemaId) Get the most recent derived schema added to the given store and value schema idgetReplicationMetadataSchema
(String storeName, int valueSchemaId, int replicationMetadataVersionId) getReplicationMetadataSchemas
(String storeName) protected SchemaData
getSchemaDataFromMetaSystemStore
(String storeName) protected abstract SchemaData
getSchemaDataFromSystemStore
(String storeName) Get one store by given name from repository.protected StoreConfig
getStoreConfigFromMetaSystemStore
(String storeName) protected abstract StoreConfig
getStoreConfigFromSystemStore
(String storeName) protected abstract Store
getStoreFromSystemStore
(String storeName, String clusterName) protected abstract StoreMetaValue
getStoreMetaValue
(String storeName, StoreMetaKey key) getStoreOrThrow
(String storeName) getSupersetOrLatestValueSchema
(String storeName) Get the most recent value schema or superset value schema if one exists.getSupersetSchema
(String storeName) Get the superset value schema for a given store.long
Get total read quota of all stores.getValueSchema
(String storeName, int id) This function is used to retrieve the value schema for the given store and value schema id.int
getValueSchemaId
(String storeName, String valueSchemaStr) This function is used to retrieve value schema id for the given store and schema.protected SchemaEntry
getValueSchemaInternally
(String storeName, int id) getValueSchemas
(String storeName) This function is used to retrieve all the value schemas for the given store.getVeniceCluster
(String storeName) Get the associated Venice cluster name given a Venice store name.boolean
Whether the store exists or not.boolean
hasValueSchema
(String storeName, int id) This function is used to check whether the value schema id is valid in the given store.boolean
isReadComputationEnabled
(String storeName) Whether computation is enabled for the specified store.protected void
notifyStoreChanged
(Store store) protected void
notifyStoreCreated
(Store store) protected void
notifyStoreDeleted
(Store store) protected Store
void
refresh()
This method will be triggered periodically to keep the store/schema information up-to-date.refreshOneStore
(String storeName) Selective refresh operation which fetches one store from ZKvoid
Register store data change listener.protected Store
removeStore
(String storeName) protected void
removeStoreSchema
(String storeName) This function is used to remove schema entry for the given store from local cache, and related listeners as well.void
start()
void
void
Unregister store data change listener.void
unsubscribe
(String storeName) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.linkedin.venice.meta.ReadOnlySchemaRepository
getLatestDerivedSchema
Methods inherited from interface com.linkedin.venice.meta.ReadOnlyStoreRepository
waitVersion, waitVersion
-
Field Details
-
clientConfig
-
subscribedStoreMap
-
-
Constructor Details
-
NativeMetadataRepository
-
NativeMetadataRepository
protected NativeMetadataRepository(ClientConfig clientConfig, VeniceProperties backendConfig, Clock clock)
-
-
Method Details
-
start
public void start() -
getInstance
public static NativeMetadataRepository getInstance(ClientConfig clientConfig, VeniceProperties backendConfig) -
getInstance
public static NativeMetadataRepository getInstance(ClientConfig clientConfig, VeniceProperties backendConfig, ICProvider icProvider) -
subscribe
- Specified by:
subscribe
in interfaceSubscriptionBasedReadOnlyStoreRepository
- Throws:
InterruptedException
-
unsubscribe
- Specified by:
unsubscribe
in interfaceSubscriptionBasedReadOnlyStoreRepository
-
getStore
Description copied from interface:ReadOnlyStoreRepository
Get one store by given name from repository.- Specified by:
getStore
in interfaceReadOnlyStoreRepository
- Parameters:
storeName
- name of wanted store.- Returns:
- Store for given name.
-
getStoreOrThrow
- Specified by:
getStoreOrThrow
in interfaceReadOnlyStoreRepository
- Throws:
VeniceNoStoreException
-
hasStore
Description copied from interface:ReadOnlyStoreRepository
Whether the store exists or not.- Specified by:
hasStore
in interfaceReadOnlyStoreRepository
- Parameters:
storeName
- store name- Returns:
-
refreshOneStore
Description copied from interface:ReadOnlyStoreRepository
Selective refresh operation which fetches one store from ZK- Specified by:
refreshOneStore
in interfaceReadOnlyStoreRepository
- Parameters:
storeName
- store name- Returns:
- the newly refreshed store
-
getAllStores
Description copied from interface:ReadOnlyStoreRepository
Get all stores in the current repository- Specified by:
getAllStores
in interfaceReadOnlyStoreRepository
- Returns:
-
getTotalStoreReadQuota
public long getTotalStoreReadQuota()Description copied from interface:ReadOnlyStoreRepository
Get total read quota of all stores.- Specified by:
getTotalStoreReadQuota
in interfaceReadOnlyStoreRepository
-
registerStoreDataChangedListener
Description copied from interface:ReadOnlyStoreRepository
Register store data change listener.- Specified by:
registerStoreDataChangedListener
in interfaceReadOnlyStoreRepository
-
unregisterStoreDataChangedListener
Description copied from interface:ReadOnlyStoreRepository
Unregister store data change listener.- Specified by:
unregisterStoreDataChangedListener
in interfaceReadOnlyStoreRepository
-
getBatchGetLimit
Description copied from interface:ReadOnlyStoreRepository
Get batch-get limit for the specified store- Specified by:
getBatchGetLimit
in interfaceReadOnlyStoreRepository
- Returns:
-
isReadComputationEnabled
Description copied from interface:ReadOnlyStoreRepository
Whether computation is enabled for the specified store.- Specified by:
isReadComputationEnabled
in interfaceReadOnlyStoreRepository
- Parameters:
storeName
- store name- Returns:
-
getKeySchema
This function is used to retrieve key schema for the given store. If key schema for the given store doesn't exist, will return null; Otherwise, it will return the key schema;- Specified by:
getKeySchema
in interfaceReadOnlySchemaRepository
- Returns:
- null, if key schema for the given store doesn't exist; key schema entry, otherwise;
-
getValueSchema
This function is used to retrieve the value schema for the given store and value schema id. Caller shouldn't modify the returned SchemeEntry- Specified by:
getValueSchema
in interfaceReadOnlySchemaRepository
- Returns:
- null, if the schema doesn't exist; value schema entry, otherwise;
-
hasValueSchema
This function is used to check whether the value schema id is valid in the given store.- Specified by:
hasValueSchema
in interfaceReadOnlySchemaRepository
-
getValueSchemaId
This function is used to retrieve value schema id for the given store and schema.- Specified by:
getValueSchemaId
in interfaceReadOnlySchemaRepository
- Returns:
SchemaData.INVALID_VALUE_SCHEMA_ID
, if the schema doesn't exist in the given store; schema id (int), if the schema exists in the given store
-
getValueSchemas
This function is used to retrieve all the value schemas for the given store.- Specified by:
getValueSchemas
in interfaceReadOnlySchemaRepository
-
getSupersetOrLatestValueSchema
Description copied from interface:ReadOnlySchemaRepository
Get the most recent value schema or superset value schema if one exists.- Specified by:
getSupersetOrLatestValueSchema
in interfaceReadOnlySchemaRepository
-
getSupersetSchema
Description copied from interface:ReadOnlySchemaRepository
Get the superset value schema for a given store. Each store has at most one active superset schema. Specifically a store must have some features enabled (e.g. read compute, write compute) to have a superset value schema which evolves as new value schemas are added.- Specified by:
getSupersetSchema
in interfaceReadOnlySchemaRepository
- Returns:
- Superset value schema or
null
if store does not have any superset value schema.
-
getDerivedSchemaId
Description copied from interface:ReadOnlySchemaRepository
Look up derived schema id and its corresponding value schema id by given store name and derived schema. This is likely used by clients that write to Venice- Specified by:
getDerivedSchemaId
in interfaceReadOnlySchemaRepository
- Returns:
- a pair where the first value is value schema id and the second value is derived schema id
-
getDerivedSchema
public DerivedSchemaEntry getDerivedSchema(String storeName, int valueSchemaId, int derivedSchemaId) - Specified by:
getDerivedSchema
in interfaceReadOnlySchemaRepository
-
getDerivedSchemas
- Specified by:
getDerivedSchemas
in interfaceReadOnlySchemaRepository
-
getLatestDerivedSchema
Description copied from interface:ReadOnlySchemaRepository
Get the most recent derived schema added to the given store and value schema id- Specified by:
getLatestDerivedSchema
in interfaceReadOnlySchemaRepository
-
getReplicationMetadataSchema
public RmdSchemaEntry getReplicationMetadataSchema(String storeName, int valueSchemaId, int replicationMetadataVersionId) - Specified by:
getReplicationMetadataSchema
in interfaceReadOnlySchemaRepository
-
getReplicationMetadataSchemas
- Specified by:
getReplicationMetadataSchemas
in interfaceReadOnlySchemaRepository
-
refresh
public void refresh()This method will be triggered periodically to keep the store/schema information up-to-date.- Specified by:
refresh
in interfaceVeniceResource
-
clear
public void clear()TODO: we may need to rename this function to be 'close' since this resource should not used any more after calling this function.- Specified by:
clear
in interfaceVeniceResource
-
getAndSetStoreConfigFromSystemStore
Get the store cluster config from system store and update the local cache with it. Different implementation will get the data differently but should all populate the store cluster config map. -
getStoreConfigFromSystemStore
-
getStoreFromSystemStore
-
getStoreMetaValue
-
getStoreConfigFromMetaSystemStore
-
getSchemaDataFromMetaSystemStore
-
putStore
-
removeStore
-
notifyStoreCreated
-
notifyStoreDeleted
-
notifyStoreChanged
-
getAndCacheSchemaDataFromSystemStore
-
getValueSchemaInternally
-
getSchemaDataFromSystemStore
-
removeStoreSchema
This function is used to remove schema entry for the given store from local cache, and related listeners as well. -
getVeniceCluster
Description copied from interface:ClusterInfoProvider
Get the associated Venice cluster name given a Venice store name.- Specified by:
getVeniceCluster
in interfaceClusterInfoProvider
- Returns:
- the cluster name that the store belongs to or null if such information cannot be provided.
-