Interface CachedSchemaLookup
- All Known Implementing Classes:
LruSchemaRegistryClient
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 returnsRETRYand 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
FieldsModifier and TypeFieldDescriptionstatic final StringReturned bygetGuidIfCached(String, ParsedSchema)when the schema is known not to be registered.static final IntegerReturned bygetIdIfCached(String, ParsedSchema)when the schema is known not to be registered. -
Method Summary
Modifier and TypeMethodDescriptiongetGuidIfCached(String subject, io.confluent.kafka.schemaregistry.ParsedSchema schema) The cached guid registered forschemaundersubject;nullon a genuine cache miss (caller returnsRETRY);GUID_ABSENTwhen the schema is known not to be registered (caller rejects).getIdIfCached(String subject, io.confluent.kafka.schemaregistry.ParsedSchema schema) The cached id registered forschemaundersubject;nullon a genuine cache miss (caller returnsRETRY);ID_ABSENTwhen the schema is known not to be registered (caller rejects).io.confluent.kafka.schemaregistry.ParsedSchemagetSchemaByGuidIfCached(String guid, String subject, io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy strategy, String topic, boolean isKey, String contextName) The cached schema forguid, or null on a cache miss.io.confluent.kafka.schemaregistry.ParsedSchemagetSchemaBySubjectAndIdIfCached(String subject, int id, io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy strategy, String topic, boolean isKey, String contextName) The cached schema forsubjectandid, or null on a cache miss.booleanisGuidBanned(String guid) True whenguidis known not to exist, so the record can be rejected without consulting Schema Registry.booleanisIdBanned(String subject, int id) True whenidis known not to exist forsubject, so the record can be rejected without consulting Schema Registry.
-
Field Details
-
ID_ABSENT
Returned bygetIdIfCached(String, ParsedSchema)when the schema is known not to be registered. Valid schema ids are positive, so this never equals a record's id and the caller's comparison rejects. -
GUID_ABSENT
Returned bygetGuidIfCached(String, ParsedSchema)when the schema is known not to be registered. Never equals a real guid, so the caller's comparison rejects.- See Also:
-
-
Method Details
-
isIdBanned
True whenidis known not to exist forsubject, so the record can be rejected without consulting Schema Registry. -
isGuidBanned
True whenguidis 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 forsubjectandid, or null on a cache miss.strategy,topic,isKeyandcontextNameare 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 forguid, or null on a cache miss. The remaining arguments serve the same purpose as ingetSchemaBySubjectAndIdIfCached(String, int, SubjectNameStrategy, String, boolean, String). -
getIdIfCached
The cached id registered forschemaundersubject;nullon a genuine cache miss (caller returnsRETRY);ID_ABSENTwhen the schema is known not to be registered (caller rejects). See the three-way contract on the class javadoc. -
getGuidIfCached
The cached guid registered forschemaundersubject;nullon a genuine cache miss (caller returnsRETRY);GUID_ABSENTwhen the schema is known not to be registered (caller rejects). See the three-way contract on the class javadoc.
-