Interface CachedSchemaLookup

All Known Implementing Classes:
LruSchemaRegistryClient

public interface CachedSchemaLookup
Non-blocking, cache-only lookups used by the async validation path.

A SchemaRegistryClient that also implements this interface can answer from its local cache without a network call, letting the validator return RETRY on a miss instead of blocking the append path on Schema Registry. A client that does not implement it simply falls back to the synchronous path.

Implementations must not block: every method either answers from cache or reports a miss (null for the *IfCached methods). Kicking off an asynchronous refresh on a miss is expected.

Three-way result, not two. getIdIfCached(String, ParsedSchema) and getGuidIfCached(String, ParsedSchema) must distinguish "not cached yet" from "known not to exist":

  • a cached value — the caller compares it against the record's id/guid;
  • null — a genuine cache miss; the caller returns RETRY and a background fetch is kicked off;
  • ID_ABSENT / GUID_ABSENT — definitively absent (e.g. found in a negative cache); the caller rejects the record.

Returning null for the third case is a correctness bug, not a stylistic one: the record would be retried indefinitely instead of rejected. On the broker RETRY surfaces as UNKNOWN_TOPIC_OR_PARTITION, which producers retry.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Returned by getGuidIfCached(String, ParsedSchema) when the schema is known not to be registered.
    static final Integer
    Returned by getIdIfCached(String, ParsedSchema) when the schema is known not to be registered.
  • Method Summary

    Modifier and Type
    Method
    Description
    getGuidIfCached(String subject, io.confluent.kafka.schemaregistry.ParsedSchema schema)
    The cached guid registered for schema under subject; null on a genuine cache miss (caller returns RETRY); GUID_ABSENT when the schema is known not to be registered (caller rejects).
    getIdIfCached(String subject, io.confluent.kafka.schemaregistry.ParsedSchema schema)
    The cached id registered for schema under subject; null on a genuine cache miss (caller returns RETRY); ID_ABSENT when the schema is known not to be registered (caller rejects).
    io.confluent.kafka.schemaregistry.ParsedSchema
    getSchemaByGuidIfCached(String guid, String subject, io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy strategy, String topic, boolean isKey, String contextName)
    The cached schema for guid, or null on a cache miss.
    io.confluent.kafka.schemaregistry.ParsedSchema
    getSchemaBySubjectAndIdIfCached(String subject, int id, io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy strategy, String topic, boolean isKey, String contextName)
    The cached schema for subject and id, or null on a cache miss.
    boolean
    True when guid is known not to exist, so the record can be rejected without consulting Schema Registry.
    boolean
    isIdBanned(String subject, int id)
    True when id is known not to exist for subject, so the record can be rejected without consulting Schema Registry.
  • Field Details

  • Method Details

    • isIdBanned

      boolean isIdBanned(String subject, int id)
      True when id is known not to exist for subject, so the record can be rejected without consulting Schema Registry.
    • isGuidBanned

      boolean isGuidBanned(String guid)
      True when guid is known not to exist, so the record can be rejected without consulting Schema Registry.
    • getSchemaBySubjectAndIdIfCached

      io.confluent.kafka.schemaregistry.ParsedSchema getSchemaBySubjectAndIdIfCached(String subject, int id, io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy strategy, String topic, boolean isKey, String contextName)
      The cached schema for subject and id, or null on a cache miss. strategy, topic, isKey and contextName are used to resolve the subject for the follow-up schema-to-id lookup warmed on a miss.
    • getSchemaByGuidIfCached

      io.confluent.kafka.schemaregistry.ParsedSchema getSchemaByGuidIfCached(String guid, String subject, io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy strategy, String topic, boolean isKey, String contextName)
      The cached schema for guid, or null on a cache miss. The remaining arguments serve the same purpose as in getSchemaBySubjectAndIdIfCached(String, int, SubjectNameStrategy, String, boolean, String).
    • getIdIfCached

      Integer getIdIfCached(String subject, io.confluent.kafka.schemaregistry.ParsedSchema schema)
      The cached id registered for schema under subject; null on a genuine cache miss (caller returns RETRY); ID_ABSENT when the schema is known not to be registered (caller rejects). See the three-way contract on the class javadoc.
    • getGuidIfCached

      String getGuidIfCached(String subject, io.confluent.kafka.schemaregistry.ParsedSchema schema)
      The cached guid registered for schema under subject; null on a genuine cache miss (caller returns RETRY); GUID_ABSENT when the schema is known not to be registered (caller rejects). See the three-way contract on the class javadoc.