New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Issue 9602] Add schema type validation #9797
[Issue 9602] Add schema type validation #9797
Conversation
/pulsarbot run-failure-checks |
@congbobo184 @gaoran10 Please help review this PR. |
|
||
import com.google.common.collect.Sets; | ||
import org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest; | ||
import org.apache.pulsar.client.api.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to avoid star import.
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.testng.Assert.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the above comment.
private final String namespace = "test-namespace"; | ||
private final String namespaceName = PUBLIC_TENANT + "/" + namespace; | ||
|
||
@BeforeMethod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to change to BeforeClass? This can avoid start and shutdown the mock service for each test.
@@ -140,6 +140,15 @@ | |||
SchemaCompatibilityStrategy strategy) { | |||
return trimDeletedSchemaAndGetList(schemaId).thenCompose(schemaAndMetadataList -> | |||
getSchemaVersionBySchemaData(schemaAndMetadataList, schema).thenCompose(schemaVersion -> { | |||
if (schemaAndMetadataList.size() > 0) { | |||
for (SchemaAndMetadata metadata : schemaAndMetadataList) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you need to check if strategy
is not ALWAYS_COMPATIBLE
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is really a need to check the strategy type, so I will add that and unit tests.
compatibilityChecks.getOrDefault(newSchema.getType(), SchemaCompatibilityCheck.DEFAULT) | ||
.checkCompatible(existingSchemaData, newSchema, strategy); | ||
} | ||
if (newSchema.getType() != existingSchemaData.getType()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you need to check if strategy
is not ALWAYS_COMPATIBLE
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to check compatibility here. Because in checkConsumerCompatibility will judge. If it is ALWAYS_COMPATIBLE, it will not be called here.
@sijie Please review this PR again, thanks. |
Fixes apache#9602 ### Motivation The schema should not be able to modify the type after it is first created. Unless he is Always compatible. ### Modifications When uploading a schema, it is verified that the type of the newly uploaded schema is consistent with the schema in the metadata. When checkCompatible, change the Primitive type from checking only to checking all. ### Verifying this change * When a producer is created, the schema is defined, and when a producer is created again, the schema type is not always the same, otherwise an exception will be thrown. * When a producer is created, the schema is defined, and when a consumer is created again, the schema type is not always the same, otherwise an exception will be thrown. * When a consumer is created, the schema is defined, and when a producer is created again, the schema type is not always the same, otherwise an exception will be thrown. * When a consumer is created, the schema is defined, and when a consumer is created again, the schema type is not always the same, otherwise an exception will be thrown. * When compatibility is set to always compatible. No exceptions are thrown. ### Does this pull request potentially affect one of the following parts: *If `yes` was chosen, please highlight the changes* - The schema: (yes)
Fixes #9602 The schema should not be able to modify the type after it is first created. Unless he is Always compatible. When uploading a schema, it is verified that the type of the newly uploaded schema is consistent with the schema in the metadata. When checkCompatible, change the Primitive type from checking only to checking all. * When a producer is created, the schema is defined, and when a producer is created again, the schema type is not always the same, otherwise an exception will be thrown. * When a producer is created, the schema is defined, and when a consumer is created again, the schema type is not always the same, otherwise an exception will be thrown. * When a consumer is created, the schema is defined, and when a producer is created again, the schema type is not always the same, otherwise an exception will be thrown. * When a consumer is created, the schema is defined, and when a consumer is created again, the schema type is not always the same, otherwise an exception will be thrown. * When compatibility is set to always compatible. No exceptions are thrown. *If `yes` was chosen, please highlight the changes* - The schema: (yes) (cherry picked from commit b45adde)
Related to #9797 ### Motivation Fix schema type check issue when use always compatible strategy. 1. For non-transitive strategy, only check schema type for the last schema 2. For transitive strategy, check all schema's type 3. Get schema by schema data should consider different schema types
Related to #9797 Fix schema type check issue when use always compatible strategy. 1. For non-transitive strategy, only check schema type for the last schema 2. For transitive strategy, check all schema's type 3. Get schema by schema data should consider different schema types (cherry picked from commit 04f8c96)
Fixes #9602
Motivation
The schema should not be able to modify the type after it is first created. Unless he is Always compatible.
Modifications
When uploading a schema, it is verified that the type of the newly uploaded schema is consistent with the schema in the metadata.
When checkCompatible, change the Primitive type from checking only to checking all.
Verifying this change
When a producer is created, the schema is defined, and when a producer is created again, the schema type is not always the same, otherwise an exception will be thrown.
When a producer is created, the schema is defined, and when a consumer is created again, the schema type is not always the same, otherwise an exception will be thrown.
When a consumer is created, the schema is defined, and when a producer is created again, the schema type is not always the same, otherwise an exception will be thrown.
When a consumer is created, the schema is defined, and when a consumer is created again, the schema type is not always the same, otherwise an exception will be thrown.
When compatibility is set to always compatible. No exceptions are thrown.
Does this pull request potentially affect one of the following parts:
If
yes
was chosen, please highlight the changes