Skip to content

[improve][schema]Improve the getSchema() method in SchemaRegistryServiceImpl.java #23354

Open
nikam14 wants to merge 5 commits intoapache:masterfrom
nikam14:improve_method
Open

[improve][schema]Improve the getSchema() method in SchemaRegistryServiceImpl.java #23354
nikam14 wants to merge 5 commits intoapache:masterfrom
nikam14:improve_method

Conversation

@nikam14
Copy link
Contributor

@nikam14 nikam14 commented Sep 26, 2024

Motivation

In SchemaRegistryServiceImpl.java there are two getSchema() methods.
1 - getSchema(String schemaId)
2 - getSchema(String schemaId, SchemaVersion version)
In the first method after getting Schema it is checked that whether the Schema is deleted or not. In Second method it is not checked when Schema.version=Latest . Which means it may return a deleted Schema.
So, checking it in getSchema(String schemaId, SchemaVersion version) can improve code, prevent from any future issue.

Modifications

checking Schema is deleted or not before return in getSchema(String schemaId, SchemaVersion version) method.
If it is deleted then return Null else return Schema.
Removing the check from getSchema(String schemaId) and adding it in getSchema(String schemaId, SchemaVersion version).

Verifying this change

  • Make sure that the change passes the CI checks.

This change is already covered by existing tests.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Sep 26, 2024
.thenApply(schema -> new SchemaAndMetadata(schemaId, schema, stored.version));
.thenApply(schema -> new SchemaAndMetadata(schemaId, schema, stored.version))
.thenApply((schema) -> {
if (version == SchemaVersion.Latest) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a test to show the changes make sense

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changes are covered in SchemaServiceTest.java

Copy link
Member

Choose a reason for hiding this comment

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

changes are covered in SchemaServiceTest.java

@nikam14 Please add a test that shows that this change was needed. I don't see any test changes in this PR, so that is missing.

@nikam14 nikam14 requested a review from BewareMyPower October 3, 2024 06:17
@lhotari
Copy link
Member

lhotari commented Oct 9, 2024

In SchemaRegistryServiceImpl.java there are two getSchema() methods.
1 - getSchema(String schemaId)
2 - getSchema(String schemaId, SchemaVersion version)
In the first method after getting Schema it is checked that whether the Schema is deleted or not. In Second method it is not checked when Schema.version=Latest .
Adding the check can improve code.

Instead of explaining how the code is implemented, please explain why it was a problem instead. You can show this is a test too.

@nikam14
Copy link
Contributor Author

nikam14 commented Oct 14, 2024

These changes not cover any issue.
Changes are covered by existing tests.
This PR just improves code.

@lhotari
Copy link
Member

lhotari commented Oct 14, 2024

These changes not cover any issue. Changes are covered by existing tests. This PR just improves code.

@nikam14 That doesn't make much sense.
In the motivation there is "So, checking it in getSchema(String schemaId, SchemaVersion version) can improve code, prevent from any future issue.".
Please add a test case for the potential future issue.

@nikam14
Copy link
Contributor Author

nikam14 commented Oct 14, 2024

changes are covered in Test addLotsOfEntriesThenDelete()-SchemaServiceTest.java. No need to add test case.

@lhotari
Copy link
Member

lhotari commented Oct 14, 2024

changes are covered in Test addLotsOfEntriesThenDelete()-SchemaServiceTest.java. No need to add test case.

please check my comment #23354 (comment) . What is the potential future issue you would like to prepare for? Could you please add a test case for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-not-needed Your PR changes do not impact docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants