Package com.linkedin.venice.helix
Class HelixReadOnlySchemaRepository
java.lang.Object
com.linkedin.venice.helix.HelixReadOnlySchemaRepository
- All Implemented Interfaces:
ReadOnlySchemaRepository
,StoreDataChangedListener
,VeniceResource
- Direct Known Subclasses:
HelixReadOnlyZKSharedSchemaRepository
public class HelixReadOnlySchemaRepository
extends Object
implements ReadOnlySchemaRepository, StoreDataChangedListener
This class is used to cache store schema and provide various query operations.
This expected user is router to support venice client schema query operations,
and storage node for schema validation;
TODO:
1. This class needs to periodically clear/warm up local cache since we might miss some notifications:
1.` Re-connect;
One way to achieve to record the previous clear timestamp, and clear it again when the duration
exceeds some amount of time in query functions.
We need to reach out Helix team for this issue since it will impact Helix cache as well.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionHelixReadOnlySchemaRepository
(ReadOnlyStoreRepository storeRepository, org.apache.helix.zookeeper.impl.client.ZkClient zkClient, HelixAdapterSerializer adapter, String clusterName, int refreshAttemptsForZkReconnect, long refreshIntervalForZkReconnectInMs) -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear local cache and watchesgetDerivedSchema
(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) 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) getSupersetOrLatestValueSchema
(String storeName) Caller shouldn't modify the returned SchemeEntrygetSupersetSchema
(String storeName) Get the superset value schema for a given store.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.getValueSchemas
(String storeName) This function is used to retrieve all the value schemas for the given store.void
handleStoreChanged
(Store store) void
handleStoreCreated
(Store store) Do nothing here, since we want to warm up local cache gradually.void
handleStoreDeleted
(String storeName) For store deletion, we need to delete the local cache entry right way, otherwise the local cache may contain the stale entries for store-delete-and-add scenario.boolean
hasValueSchema
(String storeName, int id) This function is used to check whether the value schema id is valid in the given store.void
refresh()
Refer toclear()
This function will clear the local cache/watches, and populates the schemaMap from schemaRepository.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.StoreDataChangedListener
handleStoreDeleted
-
Field Details
-
VALUE_SCHEMA_STARTING_ID
public static final int VALUE_SCHEMA_STARTING_ID- See Also:
-
-
Constructor Details
-
HelixReadOnlySchemaRepository
public HelixReadOnlySchemaRepository(ReadOnlyStoreRepository storeRepository, org.apache.helix.zookeeper.impl.client.ZkClient zkClient, HelixAdapterSerializer adapter, String clusterName, int refreshAttemptsForZkReconnect, long refreshIntervalForZkReconnectInMs)
-
-
Method Details
-
getKeySchema
This function is used to retrieve key schema for the given store. If store doesn't exist, this function will return null; If key schema for the given store doesn't exist, will return null; Otherwise, it will return the key schema; Caller shouldn't modify the returned SchemeEntry- 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
-
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
-
getValueSchemas
This function is used to retrieve all the value schemas for the given store. Caller shouldn't modify the returned SchemeEntry list.- Specified by:
getValueSchemas
in interfaceReadOnlySchemaRepository
- Returns:
- value schema list
-
getDerivedSchemas
- Specified by:
getDerivedSchemas
in interfaceReadOnlySchemaRepository
-
getSupersetOrLatestValueSchema
Caller shouldn't modify the returned SchemeEntry- 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.
-
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()Refer toclear()
This function will clear the local cache/watches, and populates the schemaMap from schemaRepository.- Specified by:
refresh
in interfaceVeniceResource
-
clear
public void clear()Clear local cache and watches- Specified by:
clear
in interfaceVeniceResource
-
handleStoreCreated
Do nothing here, since we want to warm up local cache gradually.- Specified by:
handleStoreCreated
in interfaceStoreDataChangedListener
-
handleStoreDeleted
For store deletion, we need to delete the local cache entry right way, otherwise the local cache may contain the stale entries for store-delete-and-add scenario.- Specified by:
handleStoreDeleted
in interfaceStoreDataChangedListener
-
handleStoreChanged
- Specified by:
handleStoreChanged
in interfaceStoreDataChangedListener
-