Skip to content
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

Merged
merged 7 commits into from
Jul 19, 2019
Merged

Add deleted schema judgment when adding schema #4731

merged 7 commits into from
Jul 19, 2019

Conversation

congbobo184
Copy link
Contributor

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

@congbobo184 congbobo184 changed the title Add delete schema judgment when adding schema Add deleted schema judgment when adding schema Jul 15, 2019
) {

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Member

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 ->
Copy link
Member

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) -> {
})

@sijie sijie added component/schemaregistry type/bug The PR fixed a bug or issue reported a bug labels Jul 16, 2019
@sijie sijie modified the milestones: 2.5.0, 2.4.1 Jul 16, 2019
@codelipenghui
Copy link
Contributor

retest this please

Unverified

This user has not yet uploaded their public signing key.
…e_the_schema
@@ -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())
Copy link
Contributor

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.

@codelipenghui
Copy link
Contributor

retest this please

@jiazhai
Copy link
Member

jiazhai commented Jul 19, 2019

run integration tests

@congbobo184
Copy link
Contributor Author

This PR fixed #4763

@congbobo184
Copy link
Contributor Author

run Integration Tests

@sijie
Copy link
Member

sijie commented Jul 19, 2019

retest this please

@congbobo184
Copy link
Contributor Author

run java8 tests

2 similar comments
@congbobo184
Copy link
Contributor Author

run java8 tests

@codelipenghui
Copy link
Contributor

run java8 tests

@sijie sijie merged commit 6ec2e16 into apache:master Jul 19, 2019
easyfan pushed a commit to easyfan/pulsar that referenced this pull request Jul 26, 2019
### Motivation
to fix apache#4724

### Verifying this change
Add the tests for it
jiazhai pushed a commit that referenced this pull request Aug 28, 2019
### Motivation
to fix #4724

### Verifying this change
Add the tests for it

(cherry picked from commit 6ec2e16)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New schemas should overwrite deleted schemas
5 participants