Class HelixReadOnlySchemaRepository

  • All Implemented Interfaces:
    ReadOnlySchemaRepository, StoreDataChangedListener, VeniceResource
    Direct Known Subclasses:
    HelixReadOnlyZKSharedSchemaRepository

    public class HelixReadOnlySchemaRepository
    extends java.lang.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 Detail

      • VALUE_SCHEMA_STARTING_ID

        public static final int VALUE_SCHEMA_STARTING_ID
        See Also:
        Constant Field Values
    • Constructor Detail

      • HelixReadOnlySchemaRepository

        public HelixReadOnlySchemaRepository​(ReadOnlyStoreRepository storeRepository,
                                             org.apache.helix.zookeeper.impl.client.ZkClient zkClient,
                                             HelixAdapterSerializer adapter,
                                             java.lang.String clusterName,
                                             int refreshAttemptsForZkReconnect,
                                             long refreshIntervalForZkReconnectInMs)
    • Method Detail

      • getKeySchema

        public SchemaEntry getKeySchema​(java.lang.String storeName)
        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 interface ReadOnlySchemaRepository
        Returns:
        null, if key schema for the given store doesn't exist; key schema entry, otherwise;
      • getValueSchema

        public SchemaEntry getValueSchema​(java.lang.String storeName,
                                          int id)
        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 interface ReadOnlySchemaRepository
        Returns:
        null, if the schema doesn't exist; value schema entry, otherwise;
      • hasValueSchema

        public boolean hasValueSchema​(java.lang.String storeName,
                                      int id)
        This function is used to check whether the value schema id is valid in the given store.
        Specified by:
        hasValueSchema in interface ReadOnlySchemaRepository
      • getValueSchemaId

        public int getValueSchemaId​(java.lang.String storeName,
                                    java.lang.String valueSchemaStr)
        This function is used to retrieve value schema id for the given store and schema.
        Specified by:
        getValueSchemaId in interface ReadOnlySchemaRepository
        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

        public GeneratedSchemaID getDerivedSchemaId​(java.lang.String storeName,
                                                    java.lang.String derivedSchemaStr)
        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 interface ReadOnlySchemaRepository
        Returns:
        a pair where the first value is value schema id and the second value is derived schema id
      • getValueSchemas

        public java.util.Collection<SchemaEntry> getValueSchemas​(java.lang.String storeName)
        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 interface ReadOnlySchemaRepository
        Returns:
        value schema list
      • getSupersetSchema

        public SchemaEntry getSupersetSchema​(java.lang.String storeName)
        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 interface ReadOnlySchemaRepository
        Returns:
        Superset value schema or null if store {@param storeName} does not have any superset value schema.
      • refresh

        public void refresh()
        Refer to clear() This function will clear the local cache/watches, and populates the schemaMap from schemaRepository.
        Specified by:
        refresh in interface VeniceResource
      • clear

        public void clear()
        Clear local cache and watches
        Specified by:
        clear in interface VeniceResource
      • handleStoreDeleted

        public void handleStoreDeleted​(java.lang.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.
        Specified by:
        handleStoreDeleted in interface StoreDataChangedListener