Repository navigation
feat: support multiple schema version for producer and consumer - #611
Conversation
| } | ||
| } | ||
|
|
||
| func (s *schemaInfoCache) get(key string) (schema *Schema) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Why is casting needed here?
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
Can this be simplified or a comment added. I'm having a difficult time understanding.
b9cea6a to
0b1bb11
Compare
|
Hello @cckellogg and @oryx2. |
|
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 |
|
@chiragbparikh there are merge conflicts in this PR. please resolve them so that the PR can be reviewed |
|
@lhotari I just resolve them, please check. |
|
|
||
| log log.Logger | ||
|
|
||
| providersMutex sync.RWMutex |
There was a problem hiding this comment.
Run go fmt to fix all formatting issues
| // Disable multiple Schame Version | ||
| // Default false |
|
@cckellogg PTAL |
|
|
||
| log log.Logger | ||
|
|
||
| providersMutex sync.RWMutex |
There was a problem hiding this comment.
Run go fmt to fix all formatting issues
| schema = s.cache[key] | ||
| s.lock.RUnlock() | ||
| if schema != nil { | ||
| return |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Do we allow schema version overwrite?
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
since Key and Value are both declared as *string, do you need check the reference is not nil before assigning them to properties?
There was a problem hiding this comment.
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.
| } | ||
|
|
||
| func (h *httpLookupService) GetSchema(topic string, schemaVersion []byte) (schema *pb.Schema, err error) { | ||
| return nil, errors.New("not support") |
There was a problem hiding this comment.
Can we make this more descriptive? Maybe an error like this helps to debug.
errors.New("GetSchema is supported by httpLookupService")
There was a problem hiding this comment.
Thanks, I will add error message.
| } | ||
|
|
||
| if p.options.DisableMultiSchema { | ||
| if msg.Schema != p.options.Schema { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()
|
@cckellogg @zzzming can we please review the changes on the PR. Thanks in advance. |
|
@cckellogg @wolfstudy can we please get this MR merged. We are eagerly waiting to use this feature. |
|
@cckellogg can we please get a review on this MR? Appreciate it! |
…nto apache-master # Conflicts: # pulsar/consumer_partition.go # pulsar/producer_partition.go
|
This feature is something that we are eagerly awaiting. |
|
@oryx2 could you please check the CI errors? thanks. |
|
@freeznet OK |
Sorry,I mad some syntax error when resolve conflicts.Already fixed.Thanks for review. |
|
@oryx2 thanks, please check the CI failures again |
|
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? |
Master Issue: https://github.com/apache/pulsar/wiki/PIP-43%3A-producer-send-message-with-different-schema#changespart-1 Related pr #611 ### Motivation Currently pulsar go sdk has supported multi-version schema in above pr, but the pr does not support `getSchema()` method with http lookup service. So that we will encounter error when we call `msg.GetSchemaValue(v interface{}) error` function with http serviceUrl. Demo below: ``` func createClient() Client { // create client //lookupURL := "pulsar://localhost:6650" lookupURL := "http://localhost:8080" // change to http protocol serviceUrl client, err := NewClient(ClientOptions{ URL: lookupURL, }) if err != nil { log.Fatal(err) } return client } func TestBytesSchema(t *testing.T) { client := createClient() defer client.Close() topic := newTopicName() properties := make(map[string]string) properties["pulsar"] = "hello" producerSchemaBytes := NewBytesSchema(properties) producer, err := client.CreateProducer(ProducerOptions{ Topic: topic, Schema: producerSchemaBytes, }) assert.NoError(t, err) _, err = producer.Send(context.Background(), &ProducerMessage{ Value: []byte(`{"key": "value"}`), }) require.NoError(t, err) producer.Close() // Create consumer consumerSchemaBytes := NewBytesSchema(nil) assert.NotNil(t, consumerSchemaBytes) consumer, err := client.Subscribe(ConsumerOptions{ Topic: topic, SubscriptionName: "sub-1", Schema: consumerSchemaBytes, SubscriptionInitialPosition: SubscriptionPositionEarliest, }) assert.Nil(t, err) ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() // Receive first message var out1 []byte msg1, err := consumer.Receive(ctx) assert.NoError(t, err) err = msg1.GetSchemaValue(&out1) assert.NoError(t, err) assert.Equal(t, []byte(`{"key": "value"}`), out1) consumer.Ack(msg1) require.NoError(t, err) } ``` Test output: ``` /root/go/pkg/mod/golang.org/[email protected]/bin/go tool test2json -t /root/.cache/JetBrains/GoLand2024.1/tmp/GoLand/___TestBytesSchema_in_github_com_apache_pulsar_client_go_pulsar.test -test.v -test.paniconexit0 -test.run ^\QTestBytesSchema\E$ === RUN TestBytesSchema time="2025-05-14T16:32:45+08:00" level=info msg="Connecting to broker" remote_addr="pulsar://localhost:6650" time="2025-05-14T16:32:45+08:00" level=info msg="TCP connection established" local_addr="127.0.0.1:36638" remote_addr="pulsar://localhost:6650" time="2025-05-14T16:32:45+08:00" level=info msg="Connection is ready" local_addr="127.0.0.1:36638" remote_addr="pulsar://localhost:6650" time="2025-05-14T16:32:45+08:00" level=info msg="Connected producer" cnx="127.0.0.1:36638 -> 127.0.0.1:6650" epoch=0 topic="persistent://public/default/my-topic-147368803" time="2025-05-14T16:32:45+08:00" level=info msg="Created producer" cnx="127.0.0.1:36638 -> 127.0.0.1:6650" producerID=1 producer_name=standalone-42-1 topic="persistent://public/default/my-topic-147368803" time="2025-05-14T16:32:45+08:00" level=info msg="Closing producer" producerID=1 producer_name=standalone-42-1 topic="persistent://public/default/my-topic-147368803" time="2025-05-14T16:32:45+08:00" level=info msg="Closed producer" producerID=1 producer_name=standalone-42-1 topic="persistent://public/default/my-topic-147368803" time="2025-05-14T16:32:45+08:00" level=info msg="Connected consumer" consumerID=1 name=yzway subscription=sub-1 topic="persistent://public/default/my-topic-147368803" time="2025-05-14T16:32:45+08:00" level=info msg="Created consumer" consumerID=1 name=yzway subscription=sub-1 topic="persistent://public/default/my-topic-147368803" schema_test.go:101: Error Trace: /data/code/dev/pulsar-client-go/pulsar/schema_test.go:101 Error: Received unexpected error: GetSchema is not supported by httpLookupService Test: TestBytesSchema schema_test.go:102: Error Trace: /data/code/dev/pulsar-client-go/pulsar/schema_test.go:102 Error: Not equal: expected: []byte{0x7b, 0x22, 0x6b, 0x65, 0x79, 0x22, 0x3a, 0x20, 0x22, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x7d} actual : []byte(nil) Diff: --- Expected +++ Actual @@ -1,4 +1,2 @@ -([]uint8) (len=16) { - 00000000 7b 22 6b 65 79 22 3a 20 22 76 61 6c 75 65 22 7d |{"key": "value"}| -} +([]uint8) <nil> Test: TestBytesSchema schema_test.go:104: Error Trace: /data/code/dev/pulsar-client-go/pulsar/schema_test.go:104 Error: Received unexpected error: GetSchema is not supported by httpLookupService Test: TestBytesSchema time="2025-05-14T16:32:45+08:00" level=info msg="Closing consumer=1" consumerID=1 name=yzway subscription=sub-1 topic="persistent://public/default/my-topic-147368803" time="2025-05-14T16:32:45+08:00" level=info msg="Closed consumer" consumerID=1 name=yzway subscription=sub-1 topic="persistent://public/default/my-topic-147368803" --- FAIL: TestBytesSchema (0.12s) Expected :[]byte{0x7b, 0x22, 0x6b, 0x65, 0x79, 0x22, 0x3a, 0x20, 0x22, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x7d} Actual :[]byte(nil) ``` ### Modifications - Update LookupService interface return type from `GetSchema(topic string, schemaVersion []byte) (schema *pb.Schema, err error)` to `GetSchema(topic string, schemaVersion []byte) (*LookupSchema, error)` to support http lookup protocol in `lookup_service.go` - Support HTTPLookupService `GetSchema(topic string, schemaVersion []byte) (*LookupSchema, error)` function in `lookup_service.go` - Add http lookup `GetSchema()` related test cases in schema_test.go
Motivation
Implement PIP-43.
Support multiple schema version for producer and consumer.
Modifications
DisableMultiSchemaoption for producerVerifying this change
(Please pick either of the following options)
Does this pull request potentially affect one of the following parts:
If
yeswas chosen, please highlight the changesDocumentation