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

feat: support multiple schema version for producer and consumer #611

Merged
merged 8 commits into from
Jul 7, 2022

Conversation

oryx2
Copy link
Contributor

@oryx2 oryx2 commented Sep 3, 2021

Motivation

Implement PIP-43.
Support multiple schema version for producer and consumer.

Modifications

  • add schema cache for producer and consumer
  • add DisableMultiSchema option for producer

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

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: (yes)
  • The schema: (yes)
  • The default values of configurations: (yes)
  • The wire protocol: (no)

Documentation

  • Does this pull request introduce a new feature? (no)
  • If yes, how is the feature documented? (not applicable / docs / GoDocs / 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

}
}

func (s *schemaInfoCache) get(key string) (schema *Schema) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove the variable names here and below and return values from the functions. It makes the code more difficult to follow especially below since some returns have values and others do not.

if err != nil {
return err
}
return (*schema).Decode(msg.payLoad, v)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is casting needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks review. Because schemaCache store the pointer of schema interface, I have change to schema instance .

}

if p.options.DisableMultiSchema {
if msg.Schema == nil && p.options.Schema == nil && !msg.Schema.GetSchemaInfo().isSame((p.options.Schema).GetSchemaInfo()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be simplified or a comment added. I'm having a difficult time understanding.

@chiragbparikh
Copy link

Hello @cckellogg and @oryx2.
Can this PR be merged. It is a great feature and we are looking forward to using it. Thanks!

@chiragbparikh
Copy link

Hello @cckellogg and @oryx2. This is a gentle reminder to please review and merge this PR. As I mentioned above we are eagerly waiting for this feature

@lhotari
Copy link
Member

lhotari commented Jan 19, 2022

@chiragbparikh there are merge conflicts in this PR. please resolve them so that the PR can be reviewed

@oryx2
Copy link
Contributor Author

oryx2 commented Jan 19, 2022

@lhotari I just resolve them, please check.

Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

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

Good work @oryx2 !

2 whitespace issues caught my eye, other than that LGTM. I'm not a Golang expert, so could you @zzzming please take a look?

@@ -143,10 +144,61 @@ type partitionConsumer struct {
dlq *dlqRouter

log log.Logger

providersMutex sync.RWMutex
Copy link
Member

Choose a reason for hiding this comment

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

whitespace

Copy link
Contributor

Choose a reason for hiding this comment

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

Run go fmt to fix all formatting issues

Comment on lines 169 to 170
// Disable multiple Schame Version
// Default false
Copy link
Member

Choose a reason for hiding this comment

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

whitespace

@lhotari
Copy link
Member

lhotari commented Jan 19, 2022

@cckellogg PTAL

@@ -143,10 +144,61 @@ type partitionConsumer struct {
dlq *dlqRouter

log log.Logger

providersMutex sync.RWMutex
Copy link
Contributor

Choose a reason for hiding this comment

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

Run go fmt to fix all formatting issues

schema = s.cache[key]
s.lock.RUnlock()
if schema != nil {
return
Copy link
Contributor

Choose a reason for hiding this comment

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

return schema nil

Copy link
Contributor

Choose a reason for hiding this comment

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

Or
s.lock.RLock()
schema, ok = s.cache[key]
s.lock.RUnlock()
if ok {
return schema, nil
}

s.lock.Lock()
defer s.lock.Unlock()

s.cache[schemaVersionHash] = schema
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we allow schema version overwrite?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, overwrite is not allowed. It is just a private function for SchemaInfoCache.Get which do the overwrite check.

var properties = make(map[string]string)
if pbSchema.Properties != nil {
for _, entry := range pbSchema.Properties {
properties[*entry.Key] = properties[*entry.Value]
Copy link
Contributor

Choose a reason for hiding this comment

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

since Key and Value are both declared as *string, do you need check the reference is not nil before assigning them to properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found a function do the same job ConvertToStringMap, but no check nil. May be I should add nil check in ConvertToStringMap function, then invoker it.

@@ -358,6 +378,9 @@ func (h *httpLookupService) GetTopicsOfNamespace(namespace string, mode GetTopic
return topics, nil
}

func (h *httpLookupService) GetSchema(topic string, schemaVersion []byte) (schema *pb.Schema, err error) {
return nil, errors.New("not support")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make this more descriptive? Maybe an error like this helps to debug.
errors.New("GetSchema is supported by httpLookupService")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I will add error message.

}

if p.options.DisableMultiSchema {
if msg.Schema != p.options.Schema {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if we want to compare the pointer or the actual value. Shema is an interface. So the current evaluation just make sure they are pointing to the same reference. Do you want to compare the value of Schema?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Maybe I can compare the value of Schema with this.
msg.Schema != nil && p.options.Schema != nil && msg.Schema.GetSchemaInfo().hash() != p.options.Schema.GetSchemaInfo().hash()

@chiragbparikh
Copy link

@cckellogg @zzzming can we please review the changes on the PR. Thanks in advance.

@wolfstudy wolfstudy added this to the 0.9.0 milestone Feb 16, 2022
@chiragbparikh
Copy link

@cckellogg @wolfstudy can we please get this MR merged. We are eagerly waiting to use this feature.

@chiragbparikh
Copy link

@cckellogg can we please get a review on this MR? Appreciate it!

…nto apache-master

# Conflicts:
#	pulsar/consumer_partition.go
#	pulsar/producer_partition.go
@RajatBanerjee
Copy link

This feature is something that we are eagerly awaiting.

@freeznet
Copy link
Contributor

freeznet commented Jul 4, 2022

@oryx2 could you please check the CI errors? thanks.

@oryx2
Copy link
Contributor Author

oryx2 commented Jul 4, 2022

@freeznet OK

@oryx2
Copy link
Contributor Author

oryx2 commented Jul 4, 2022

@freeznet OK

Sorry,I mad some syntax error when resolve conflicts.Already fixed.Thanks for review.

@freeznet
Copy link
Contributor

freeznet commented Jul 5, 2022

@oryx2 thanks, please check the CI failures again

@pomazanov
Copy link

I am curious why this PR is getting so little attention. If there is no need for FORWARD_TRANSITIVE strategy in golang client, what would be a good alternative?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants