Skip to content

fix: Update the Schema GetHashCode for Dictionary lookups #2390

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

Merged

Conversation

seanamorosoamtote
Copy link
Contributor

What

The GetHashCode for the Schema data contract was updated in June with additional properties to accomodate the DataContract work. However, the CachedSchemaRegistryClient is not able to retrieve items stored in its dictionary cache because of the References addition and how List<>'s are handled.

We saw severe slow down (around 15 seconds at times) registering a schema with 13 references (and their recursive references) because it was trying to query schemas that it already had in the Dictionary. When the changes proposed were made, the schemas that had been already retrieved were able to be pulled from the cache again (down to 1-2 seconds for large schemas, under a second for most).

Feel free to update as you wish but the code you need to ensure works is at src/Confluent.SchemaRegistry/CachedSchemaRegistryClient.cs

 if (!idBySchema.TryGetValue(schema, out int schemaId))
  {
      CleanCacheIfFull();

      schemaId = await restService.RegisterSchemaAsync(subject, schema, normalize)
          .ConfigureAwait(continueOnCapturedContext: false);
      idBySchema[schema] = schemaId;
  }

The if statement above would never get a schemaId from the idBySchema lookup.

Checklist

  • Contains customer facing changes? Including API/behavior changes
  • Did you add sufficient unit test and/or integration test coverage for this PR?
    • If not, please explain why it is not required

I don't see any unit tests surrounding this code anywhere or I would.

References

JIRA:

Test & Review

Serialize an object and debug the CachedSchemaRegistryClient to ensure that when a schema has been retrieved and/or registered it is able to be pulled from the dictionary.

Open questions / Follow-ups

@seanamorosoamtote seanamorosoamtote requested review from a team as code owners January 6, 2025 21:45
@rayokota
Copy link
Member

rayokota commented Jan 6, 2025

/sem-approve

Copy link
Member

@rayokota rayokota left a comment

Choose a reason for hiding this comment

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

Thanks @seanamorosoamtote , LGTM

@rayokota rayokota merged commit 30c42b3 into confluentinc:master Jan 7, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants