Skip to content

[PIP-43] Support producer to send msg with different schema - #5165

Merged
sijie merged 2 commits into
apache:masterfrom
yittg:message-explicit-schema
Oct 25, 2019
Merged

[PIP-43] Support producer to send msg with different schema#5165
sijie merged 2 commits into
apache:masterfrom
yittg:message-explicit-schema

Conversation

@yittg

@yittg yittg commented Sep 10, 2019

Copy link
Copy Markdown
Contributor

Master Issue: #5141

Motivation

Implement part-1 of PIP-43.

Modifications

  • New message api to specify message schema explicitly;
  • Mechanism of registering schema on producing;
  • Batch message container support to check message schema;
  • Configuration for seamless introduction of this feature;

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows in SimpleSchemaTest:

  • newProducerForMessageSchemaOnTopicWithMultiVersionSchema
  • newProducerForMessageSchemaOnTopicInitialWithNoSchema
  • newProducerForMessageSchemaWithBatch

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

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API: (yes)
  • The schema: (yes)
  • The default values of configurations: (no)
  • The wire protocol: (yes)
  • The rest endpoints: (no)
  • The admin cli options: (no)
  • Anything that affects deployment: (no)

Documentation

  • Does this pull request introduce a new feature? (yes)
  • If yes, how is the feature documented? (JavaDocs)
  • If a feature is not documented yet in this PR, please create a followup issue for adding the documentation

    Docs in followup issue.

@yittg
yittg force-pushed the message-explicit-schema branch 5 times, most recently from 081945f to 1e5d71d Compare September 10, 2019 10:06
@sijie sijie added type/feature The PR added a new feature or issue requested a new feature component/schemaregistry labels Sep 10, 2019
@sijie sijie added this to the 2.5.0 milestone Sep 10, 2019
@sijie

sijie commented Sep 10, 2019

Copy link
Copy Markdown
Member

/cc @congbobo184 for review as well.

@yittg
yittg force-pushed the message-explicit-schema branch 3 times, most recently from 87b1eec to e7165ef Compare September 11, 2019 03:16
Comment thread pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java Outdated
@yittg
yittg force-pushed the message-explicit-schema branch from e7165ef to 24aedfa Compare September 11, 2019 16:01

@sijie sijie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

overall looks good. left two comments, PTAL

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it seems to me that this method is a bit confusing. T is the original type, no? shouldn't it be a different type?

<V> TypedMessageBuilder<V> newMessage(Schema<V> schema);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@sijie yeah, you are right. I would change the signature in the following PR to make this one easier to review. It would break some more inner method of implementation class.

@yittg yittg Sep 14, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll leave a TODO, or just hide this interface for still not complete

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have hidden this interface and left a TODO.

Comment thread pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ProducerBuilder.java Outdated
@yittg
yittg force-pushed the message-explicit-schema branch 2 times, most recently from b61d097 to 814ded0 Compare September 14, 2019 14:31
@yittg
yittg requested a review from sijie September 16, 2019 05:54
@yittg
yittg force-pushed the message-explicit-schema branch from 814ded0 to d595c0c Compare September 17, 2019 01:59
@yittg

yittg commented Sep 17, 2019

Copy link
Copy Markdown
Contributor Author

ping @sijie @congbobo184 @jiazhai @codelipenghui, Any more comments?
Thanks

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me, just left a few comments

Comment thread pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/SchemaHash.java Outdated
Comment thread pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleSchemaTest.java Outdated
@yittg
yittg force-pushed the message-explicit-schema branch 3 times, most recently from d3913f4 to 2bf3eef Compare September 17, 2019 07:29

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall looks good to me, nice work! @yittg

@codelipenghui

Copy link
Copy Markdown
Contributor

run cpp tests
run java8 tests

@yittg

yittg commented Sep 18, 2019

Copy link
Copy Markdown
Contributor Author

run cpp tests

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@yittg I think this should be improved. We should avoid calling sync methods.

A better implementation here is:

  • if a new schema is needed, flush out all the existing pending requests to the broker. because all the existing pending requests use old schemas that are already registered in broker.
  • introduce a state for the client (e.g. REGISTERING_SCHEMA). Turn the client into REGISTERING_SCHEMA state. All the requests should be added in the pending queue and wait until the schema is registered in the broker.
  • after a schema is successfully registered in the broker, flush all the pending requests to the broker.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, agree with you on executing command asynchronously. It's a better implementation, I will get it out.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

First try pushed, PTAL.

@yittg
yittg force-pushed the message-explicit-schema branch from 2bf3eef to a7d89d8 Compare September 21, 2019 09:43
@yittg
yittg force-pushed the message-explicit-schema branch from a7d89d8 to 8d5e8c8 Compare September 21, 2019 10:20
@yittg

yittg commented Sep 24, 2019

Copy link
Copy Markdown
Contributor Author

@sijie Does the new implementation make sense?

@congbobo184

Copy link
Copy Markdown
Contributor

run Integration Tests

@yittg

yittg commented Sep 30, 2019

Copy link
Copy Markdown
Contributor Author

@sijie @codelipenghui @congbobo184 May I take up some more of your time to PUSH this PR on.

@jiazhai

jiazhai commented Oct 3, 2019

Copy link
Copy Markdown
Member

run Integration Tests

2 similar comments
@congbobo184

Copy link
Copy Markdown
Contributor

run Integration Tests

@jiazhai

jiazhai commented Oct 7, 2019

Copy link
Copy Markdown
Member

run Integration Tests

@codelipenghui
codelipenghui requested a review from sijie October 8, 2019 10:37
@sijie

sijie commented Oct 14, 2019

Copy link
Copy Markdown
Member

@yittg sorry for late review. I am looking into it today.

if (opSendMsg != null) {
processOpSendMsg(opSendMsg);
}
opSendMsgs = Collections.singletonList(batchMessageContainer.createOpSendMsg());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The original code was there to avoid creating collections for non-batching case. I would prefer not rewriting this logic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's ok to leave it as it is.

private void processOpSendMsg(OpSendMsg op) {
try {
batchMessageContainer.clear();
if (op.msg != null && isBatchMessagingEnabled()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

any reason why you are adding this logic here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

op.msg means a single non-batch message. we should flush the current batch if needed.
batchMessageContainer.clear(); was moved into batchMessageAndSend.
Then processOpSendMsg not only for batch message.

Don't we need to do the flush, to keep the order or something else?

return topic.addSchema(schema);
} else {
return topic.hasSchema().thenCompose((hasSchema) -> {
log.info("[{}] {} configured with schema {}",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we keep the origin log statement when refactoring the code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

producer_id not carried in CommandGetOrCreateSchema, actually need it?
Or a -1 as placeholder?

return new TypedMessageBuilderImpl<>(this, schema);
}

// TODO: same parameterized type `T` with producer for the moment,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Create a github issue for this change and add the github issue in this TODO comment? It is a good practice to always track TODO items in github issues.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should I just edit the master issue, with a checklist, or new a issue for each TODO?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

a master issue with a checklist will be good enough.

@sijie

sijie commented Oct 25, 2019

Copy link
Copy Markdown
Member

@yittg sorry for late response.

@sijie
sijie merged commit 13e35f7 into apache:master Oct 25, 2019
@yittg
yittg deleted the message-explicit-schema branch October 25, 2019 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/feature The PR added a new feature or issue requested a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants