You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/05/23 11:22:55 UTC
[GitHub] [pulsar] Demogorgon314 opened a new pull request, #15718: [fix][schema] Fix update schema forward compatibility strategy behavior
Demogorgon314 opened a new pull request, #15718:
URL: https://github.com/apache/pulsar/pull/15718
### Motivation
Currently, when we use the schema forward compatibility strategy to create(update) an existing schema(it misses some fields), the current behavior is to return the existing schema, it will skip the schema compatibility check, we should check the schema compatibility first.
The detail can see in the unit test.
### Modifications
* Fix update schema forward compatibility strategy behavior
* Add a unit test to cover this case.
### Documentation
Check the box below or label this PR directly.
Need to update docs?
- [ ] `doc-required`
(Your PR needs to update docs and you will update later)
- [x] `no-need-doc`
(Please explain why)
- [ ] `doc`
(Your PR contains doc changes)
- [ ] `doc-added`
(Docs have been already added)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] BewareMyPower commented on a diff in pull request #15718: [fix][schema] Fix update schema forward compatibility strategy behavior
Posted by GitBox <gi...@apache.org>.
BewareMyPower commented on code in PR #15718:
URL: https://github.com/apache/pulsar/pull/15718#discussion_r885226788
##########
pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleSchemaTest.java:
##########
@@ -1299,4 +1300,41 @@ public void testConsumeAvroMessagesWithoutSchema() throws Exception {
producer.close();
consumer.close();
}
+
+ @Test
+ public void testUpdateSchemaForward() throws Exception {
+ String topic = "my-property/my-ns/test";
+ admin.namespaces().setSchemaCompatibilityStrategy(
+ "my-property/my-ns/",
+ SchemaCompatibilityStrategy.FORWARD);
+ Schema<V3Data> v3Schema = Schema.AVRO(V3Data.class);
+ Schema<V4Data> v4Schema = Schema.AVRO(V4Data.class);
+
+ admin.schemas().createSchema(topic, v3Schema.getSchemaInfo());
+ admin.schemas().createSchema(topic, v4Schema.getSchemaInfo());
+
+ try {
+ admin.schemas().createSchema(topic, v3Schema.getSchemaInfo());
+ fail("Should fail here, since the forward schema compatibility strategy doesn't allow removing the field.");
+ } catch (Exception e) {
+ assertTrue(e.getMessage().contains("org.apache.avro.SchemaValidationException: Unable to read schema"));
+ }
+ }
+
+ @Data
+ @Builder
+ @NoArgsConstructor
+ @AllArgsConstructor
+ static class V4Data {
+ int i;
+ int j;
+ }
+
+ @Data
+ @Builder
+ @NoArgsConstructor
+ @AllArgsConstructor
+ static class V3Data {
+ int i;
+ }
Review Comment:
We can remove these two classes and reuse `V1Data` and `IncompatibleData` instead.
##########
pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleSchemaTest.java:
##########
@@ -1299,4 +1300,41 @@ public void testConsumeAvroMessagesWithoutSchema() throws Exception {
producer.close();
consumer.close();
}
+
+ @Test
+ public void testUpdateSchemaForward() throws Exception {
+ String topic = "my-property/my-ns/test";
+ admin.namespaces().setSchemaCompatibilityStrategy(
+ "my-property/my-ns/",
+ SchemaCompatibilityStrategy.FORWARD);
+ Schema<V3Data> v3Schema = Schema.AVRO(V3Data.class);
+ Schema<V4Data> v4Schema = Schema.AVRO(V4Data.class);
+
+ admin.schemas().createSchema(topic, v3Schema.getSchemaInfo());
+ admin.schemas().createSchema(topic, v4Schema.getSchemaInfo());
+
+ try {
+ admin.schemas().createSchema(topic, v3Schema.getSchemaInfo());
+ fail("Should fail here, since the forward schema compatibility strategy doesn't allow removing the field.");
+ } catch (Exception e) {
Review Comment:
```suggestion
} catch (PulsarAdminException.ConflictException e) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] Demogorgon314 commented on a diff in pull request #15718: [fix][schema] Fix update schema forward compatibility strategy behavior
Posted by GitBox <gi...@apache.org>.
Demogorgon314 commented on code in PR #15718:
URL: https://github.com/apache/pulsar/pull/15718#discussion_r889775229
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/SchemaRegistryServiceImpl.java:
##########
@@ -178,15 +178,8 @@ public CompletableFuture<List<CompletableFuture<SchemaAndMetadata>>> getAllSchem
@NotNull
public CompletableFuture<SchemaVersion> putSchemaIfAbsent(String schemaId, SchemaData schema,
Review Comment:
@congbobo184
I see. In the current implementation this is correct behavior, right?
Maybe we should let `createSchema` method return the version of the schema, so users can see whether the schema is changed or not? If this change makes sense, I'll draft a proposal to introduce a new `createOrUpdateSchema` admin API, it can able to return the schema version.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] Demogorgon314 commented on pull request #15718: [fix][schema] Fix update schema forward compatibility strategy behavior
Posted by GitBox <gi...@apache.org>.
Demogorgon314 commented on PR #15718:
URL: https://github.com/apache/pulsar/pull/15718#issuecomment-1135302225
/pulsarbot run-failure-checks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] BewareMyPower commented on pull request #15718: [fix][schema] Fix update schema forward compatibility strategy behavior
Posted by GitBox <gi...@apache.org>.
BewareMyPower commented on PR #15718:
URL: https://github.com/apache/pulsar/pull/15718#issuecomment-1141702065
@congbobo184 @codelipenghui Please also take a look. This PR changes the current behavior but I think it should be correct. The problem is that even if `createSchema` accepted an incompatible schema, it would't fail with any exception. i.e. if we want to check if the `createSchema` succeeded, we could only call `getSchema` again and compare the schema definition, like what I did here: https://github.com/BewareMyPower/StreamNativeKafkaExamples/blob/b4a5fa992a9d0d8250101ec6d0dfc886819e4229/src/main/java/schema/serializers/CachedSchemaRegistryClient.java#L46-L55
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] Demogorgon314 closed pull request #15718: [fix][schema] Fix update schema forward compatibility strategy behavior
Posted by GitBox <gi...@apache.org>.
Demogorgon314 closed pull request #15718: [fix][schema] Fix update schema forward compatibility strategy behavior
URL: https://github.com/apache/pulsar/pull/15718
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] Demogorgon314 commented on pull request #15718: [fix][schema] Fix update schema forward compatibility strategy behavior
Posted by GitBox <gi...@apache.org>.
Demogorgon314 commented on PR #15718:
URL: https://github.com/apache/pulsar/pull/15718#issuecomment-1135331097
/pulsarbot run-failure-checks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] congbobo184 commented on a diff in pull request #15718: [fix][schema] Fix update schema forward compatibility strategy behavior
Posted by GitBox <gi...@apache.org>.
congbobo184 commented on code in PR #15718:
URL: https://github.com/apache/pulsar/pull/15718#discussion_r887795955
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/SchemaRegistryServiceImpl.java:
##########
@@ -178,15 +178,8 @@ public CompletableFuture<List<CompletableFuture<SchemaAndMetadata>>> getAllSchem
@NotNull
public CompletableFuture<SchemaVersion> putSchemaIfAbsent(String schemaId, SchemaData schema,
Review Comment:
First I agree with you, that when the admin API creates Schema should check the schema Compatibility first, but this method is putSchemaIfAbsent, if the schema exists, we should return the SchemaVersion, so I don't think we should change this method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] Demogorgon314 commented on pull request #15718: [fix][schema] Fix update schema forward compatibility strategy behavior
Posted by GitBox <gi...@apache.org>.
Demogorgon314 commented on PR #15718:
URL: https://github.com/apache/pulsar/pull/15718#issuecomment-1136612774
/pulsarbot run-failure-checks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] congbobo184 commented on a diff in pull request #15718: [fix][schema] Fix update schema forward compatibility strategy behavior
Posted by GitBox <gi...@apache.org>.
congbobo184 commented on code in PR #15718:
URL: https://github.com/apache/pulsar/pull/15718#discussion_r887795955
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/SchemaRegistryServiceImpl.java:
##########
@@ -178,15 +178,8 @@ public CompletableFuture<List<CompletableFuture<SchemaAndMetadata>>> getAllSchem
@NotNull
public CompletableFuture<SchemaVersion> putSchemaIfAbsent(String schemaId, SchemaData schema,
Review Comment:
First I agree with you, that when the admin API creates Schema should check the schema Compatibility, but this method is putSchemaIfAbsent, if the schema exists, we should return the SchemaVersion, so I don't think we should change this method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] congbobo184 commented on a diff in pull request #15718: [fix][schema] Fix update schema forward compatibility strategy behavior
Posted by GitBox <gi...@apache.org>.
congbobo184 commented on code in PR #15718:
URL: https://github.com/apache/pulsar/pull/15718#discussion_r889914385
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/SchemaRegistryServiceImpl.java:
##########
@@ -178,15 +178,8 @@ public CompletableFuture<List<CompletableFuture<SchemaAndMetadata>>> getAllSchem
@NotNull
public CompletableFuture<SchemaVersion> putSchemaIfAbsent(String schemaId, SchemaData schema,
Review Comment:
I think the existing schema should return the existing exception instead of checking compatibility. Create an existing schema, return a ConflictException, and the user will be confused. How do you feel about this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] github-actions[bot] commented on pull request #15718: [fix][schema] Fix update schema forward compatibility strategy behavior
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #15718:
URL: https://github.com/apache/pulsar/pull/15718#issuecomment-1176964890
The pr had no activity for 30 days, mark with Stale label.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org