Schema compatibility issue for schema registry

2,828 views
Skip to first unread message

Hao Ren

unread,
Nov 6, 2015, 11:23:31 AM11/6/15
to Confluent Platform
Hi,

I have installed confluent platform v1.0.1 on my local PC.

When a schema is changed, even just add a field, it encountered an exception as the following:

Schema being registered is incompatible with the latest schema; error code: 409

You can easily produce this issue by run the following cmd:


curl -X POST -i -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data '{"schema": "{\"type\":\"record\",\"name\":\"test\",\"namespace\":\"lbc.test\",\"fields\":[{\"name\":\"first_name\",\"type\":\"string\"},{\"name\":\"age\",\"type\":\"int\"}]}"}' \

curl -X POST -i -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data '{"schema": "{\"type\":\"record\", \"name\":\"test\", \"namespace\":\"lbc.test\", \"fields\":[{\"name\":\"first_name\",\"type\":\"string\"}, {\"name\":\"age\",\"type\":\"int\"}, {\"name\":\"edu\",\"type\":[\"null\", \"string\"]} ]}"}' \


The second cmd just add a field called "edu" to the schema.
The "compatibility" of config is: backward. I have tried full and forward too. They don't work neither. "None" works fine, since it does not check schema compatibility.
It might be the workaround, but I still want to check schema.

Any help is highly appreciated.

Hao





Ewen Cheslack-Postava

unread,
Nov 6, 2015, 12:47:41 PM11/6/15
to Confluent Platform
Hi Hao,

Adding a field is only backwards compatible if the new field includes a default value. Using this command should work with compatibility set to the default "backwards":


curl -X POST -i -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data '{"schema": "{\"type\":\"record\", \"name\":\"test\", \"namespace\":\"lbc.test\", \"fields\":[{\"name\":\"first_name\",\"type\":\"string\"}, {\"name\":\"age\",\"type\":\"int\"}, {\"name\":\"edu\",\"type\":[\"null\", \"string\"],\"default\":null} ]}"}' \
http://localhost:8081/subjects/test-key/versions

(Note that I added "default": null to the "edu" field definition).

The reason the default is needed is that if you try to read a message in the old format with the new schema, the "edu" field will be missing. Since we need to fill it in with *something* to have a complete version 2 schema, it needs a default value. You can find a more detailed explanation in our docs here: http://docs.confluent.io/1.0.1/avro.html#backward-compatibility

-Ewen


--
You received this message because you are subscribed to the Google Groups "Confluent Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to confluent-platf...@googlegroups.com.
To post to this group, send email to confluent...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/confluent-platform/220cbdc1-64c4-42c5-bbac-abc1fc9956b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Thanks,
Ewen

Hao Ren

unread,
Nov 7, 2015, 5:03:29 PM11/7/15
to Confluent Platform
Thank you, Ewen.

It totally makes sense. =)
Thanks,
Ewen
Reply all
Reply to author
Forward
0 new messages