Juan Hernandez created KAFKA-2884:
-------------------------------------
Summary: Schema cache corruption in JsonConverter
Key: KAFKA-2884
URL: https://issues.apache.org/jira/browse/KAFKA-2884
Project: Kafka
Issue Type: Bug
Components: copycat
Affects Versions: 0.9.0.0
Environment: MacBook Pro 15'' mid-2014
Mac OS X 10.11.1
Reporter: Juan Hernandez
Assignee: Ewen Cheslack-Postava
There is an issue with the schema cache in the {{JsonConverter}} class when
using Struct types that corrupts its entries.
The schema cache returns an schema object for a given field type which then
gets modified setting the field name.
{code}
ObjectNode fieldJsonSchema = asJsonSchema(field.schema());
fieldJsonSchema.put(JsonSchema.STRUCT_FIELD_NAME_FIELD_NAME, field.name());
{code}
The same `fieldJsonSchema` object instance is returned for following fields (of
the same type) and the field name attribute
({{JsonSchema.STRUCT_FIELD_NAME_FIELD_NAME}}) is set overwritting the previous
value. This causes to serialize a corrupted schema in the message.
{code:title=JsonConverter.java|borderStyle=solid}
private ObjectNode asJsonSchema(Schema schema) {
if (schema == null)
return null;
ObjectNode cached = fromConnectSchemaCache.get(schema);
if (cached != null)
return cached;
// ....
case STRUCT:
jsonSchema =
JsonNodeFactory.instance.objectNode().put(JsonSchema.SCHEMA_TYPE_FIELD_NAME,
JsonSchema.STRUCT_TYPE_NAME);
ArrayNode fields = JsonNodeFactory.instance.arrayNode();
for (Field field : schema.fields()) {
ObjectNode fieldJsonSchema = asJsonSchema(field.schema());
fieldJsonSchema.put(JsonSchema.STRUCT_FIELD_NAME_FIELD_NAME,
field.name());
fields.add(fieldJsonSchema);
}
jsonSchema.set(JsonSchema.STRUCT_FIELDS_FIELD_NAME, fields);
break;
// ...
}
{code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)