-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add deleted schema judgment when adding schema #4731
Add deleted schema judgment when adding schema #4731
Conversation
) { | ||
|
||
if (index.isEmpty()) { | ||
return completedFuture(null); | ||
} | ||
|
||
for (SchemaStorageFormat.IndexEntry entry : index) { | ||
if (Arrays.equals(entry.getHash().toByteArray(), hash)) { | ||
if (Arrays.equals(entry.getHash().toByteArray(), hash) && entry.getVersion() > maxDeletedVersion) { |
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.
if (Arrays.equals(entry.getHash().toByteArray(), hash) && entry.getVersion() > maxDeletedVersion) { | |
if (Arrays.equals(entry.getHash().toByteArray(), hash)) { | |
if (entry.getVersion() > maxDeletedVersion) { | |
return completedFuture(entry.getVersion()); | |
} else { | |
return completedFuture(null); | |
} | |
} |
@@ -129,7 +145,12 @@ | |||
.setTimestamp(clock.millis()) | |||
.addAllProps(toPairs(schema.getProps())) | |||
.build(); | |||
return schemaStorage.put(schemaId, info.toByteArray(), context); | |||
try { |
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.
try { | |
return getMaxDeletedVersion(schemaId).thenCompose(deleteVersion -> { | |
return schemaStorage.put(schemaId, info.toByteArray(), context, deleteVersion); | |
}) |
@@ -312,7 +312,7 @@ public void close() throws Exception { | |||
// There was a race condition on the schema creation. Since it has now been created, | |||
// retry the whole operation so that we have a chance to recover without bubbling error | |||
// back to producer/consumer | |||
putSchemaIfAbsent(schemaId, data, hash) | |||
putSchemaIfAbsent(schemaId, data, hash, -1) |
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.
define a constant for -1 and use the constant here.
@@ -129,7 +145,10 @@ | |||
.setTimestamp(clock.millis()) | |||
.addAllProps(toPairs(schema.getProps())) | |||
.build(); | |||
return schemaStorage.put(schemaId, info.toByteArray(), context); | |||
|
|||
return getMaxDeletedVersion(schemaId).thenCompose(deleteVersion -> |
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.
I think we should return the maxDeletedVersion when we are doing compatibility check above. This would reduce the number of times we are reading schema info. So the logic would be something like this:
getSchema(schemaId).thenCompose(existingSchema -> {
if (existingSchema == null) {
return completedFuture(-1L, true)
} else if (existingSchema.schema.isDeleted()) {
return completedFuture(existingSchema.schema.version, true);
} else {
if (isTransitiveStrategy) {
return ...;
} else {
// find the maxDeletedVersion in backward sequence.
return ...;
}
}
}).thenCompose((maxDeletedVersion, isCompatible) -> {
})
retest this please |
@@ -139,7 +140,7 @@ public void start() throws IOException { | |||
.thenApply(entry -> new StoredSchema | |||
( | |||
entry.getSchemaData().toByteArray(), | |||
new LongSchemaVersion(schemaLocator.getInfo().getVersion()) | |||
new LongSchemaVersion(indexEntry.getVersion()) |
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.
Please help create an issue that this change fixed.
retest this please |
run integration tests |
This PR fixed #4763 |
run Integration Tests |
retest this please |
…congbobo184/pulsar into add_schema_if_delete_the_schema
run java8 tests |
2 similar comments
run java8 tests |
run java8 tests |
### Motivation to fix apache#4724 ### Verifying this change Add the tests for it
Motivation
to fix #4724
Verifying this change
Add the tests for it
Does this pull request potentially affect one of the following parts:
If yes was chosen, please highlight the changes
Dependencies (does it add or upgrade a dependency): (no)
The public API: (no)
The schema: (yes)
The default values of configurations: (no)
The wire protocol: (no)
The rest endpoints: (no)
The admin cli options: (no)
Anything that affects deployment: (no)
Documentation
Does this pull request introduce a new feature? (yes / no)
If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
If a feature is not applicable for documentation, explain why?
If a feature is not documented yet in this PR, please create a followup issue for adding the documentation