Skip to content

[functions] Enable custom function producer behavior - Part 1 of Proposed PIP 84 - #10154

Closed
devinbost wants to merge 1 commit into
apache:masterfrom
devinbost:update-producerconfigs
Closed

devinbost wants to merge 1 commit into
apache:masterfrom
devinbost:update-producerconfigs

Conversation

@devinbost

Copy link
Copy Markdown
Contributor

Part 1 of [Proposal] PIP 84: Cluster-Wide and Function-Specific Producer Defaults
For details, see the mailing list discussion

Fixes #9986

This PR adds these properties to ProducerConfig:

    public Boolean batchingDisabled;
    public Boolean chunkingEnabled;
    public Boolean blockIfQueueFullDisabled;
    public CompressionType compressionType;
    public HashingScheme hashingScheme;
    public MessageRoutingMode messageRoutingMode;
    public Long batchingMaxPublishDelay;

It updates the methods that convert between the ProducerConfig and the protobuf ProducerSpec.
It adds logic to use the new function producer settings when they are provided; otherwise, it reverts to the prior behavior.
It also refactors the FunctionResultRouter to prevent a race condition on isBatchingEnabled.

It adds these properties to ProducerSpec in Function.proto:

    bool batchingDisabled = 6;
    bool chunkingEnabled = 7;
    bool blockIfQueueFullDisabled = 8;
    CompressionType compressionType = 9;
    HashingScheme hashingScheme = 10;
    MessageRoutingMode messageRoutingMode = 11;
    int64 batchingMaxPublishDelay = 12;

and adds these new enums to Function.proto:

enum CompressionType {
    LZ4 = 0;
    NONE = 1;
    ZLIB = 2;
    ZSTD = 3;
    SNAPPY = 4;
}

enum HashingScheme {
    MURMUR3_32HASH = 0;
    JAVA_STRING_HASH = 1;
}

enum MessageRoutingMode {
    CUSTOM_PARTITION = 0;
    SINGLE_PARTITION = 1;
    ROUND_ROBIN_PARTITION = 2;
}

The new protobuf files have not yet been generated for Python and Go functions, but those changes are planned in a subsequent PR.

Existing tests have been updated to include the new properties, and additional tests have been provided to ensure that new configs merge properly into existing configs during function registration/update.

Changes did not need to be made to the Admin CLI parameters because the Admin CLI already provides a way for the ProducerConfig to be provided as a JSON string.

Docs will be provided in a subsequent PR.

@devinbost

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

2 similar comments
@devinbost

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

@devinbost

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

@devinbost

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

@devinbost

Copy link
Copy Markdown
Contributor Author

@jerrypeng @sijie @codelipenghui @freeznet I got all the tests to pass (after 5 runs...), and this PR needs a review.

@devinbost

Copy link
Copy Markdown
Contributor Author

This PR is the derivative of #9987

@devinbost

Copy link
Copy Markdown
Contributor Author

Also @eolivelli

Producer<O> newProducer = null;

if (this.config.getFunctionDetails() != null && this.config.getFunctionDetails().getSink() != null &&
this.config.getFunctionDetails().getSink().getProducerSpec() != null){

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.

this.config.getFunctionDetails().getSink().getProducerSpec() will never return null. This is technically changing the existing behavior of publish when called from Context. I don't think this is the right change. If a user want to use a custom producer to produce in the function (instead of just returning), the user should be able to:

  1. Instantiate a PulsarClient, create a producer, and sent messages (already can do this today)
  2. We can add a new method called "newProducerBuilder()" to the Context in which the returned builder automatically inherits some of the settings such as authentication from the function.

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.

@jerrypeng Thanks for reviewing the PR. I want to better understand your suggestion. I'm hearing several things, so please correct any of my misunderstandings:

  1. Instead of performing the null check on this.config.getFunctionDetails().getSink().getProducerSpec(), I could skip the null check and just pass through the protobuf properties directly. The defaults they use match the existing configurations, but it sounds like there's a concern that it could still change existing behavior?
  2. You're saying that I could define a new method, newProducerBuilder() to inherit the protobuf settings (instead of passing them through directly, like I mentioned above), but it sounds like there are other settings I'd want to inherit as well (such as relating to authentication)?

Would the newProducerBuilder() method be used instead of getProducer() by functions that want to use the new settings? It sounds like that would require a code change for any existing function that we want to update to use the new settings. Is that right?

@codelipenghui

Copy link
Copy Markdown
Contributor

The pr had no activity for 30 days, mark with Stale label.

@github-actions

github-actions Bot commented Mar 4, 2022

Copy link
Copy Markdown

@devinbost:Thanks for your contribution. For this PR, do we need to update docs?
(The PR template contains info about doc, which helps others know more about the changes. Can you provide doc-related info in this and future PR descriptions? Thanks)

@tisonkun

Copy link
Copy Markdown
Member

Closed as stale and conflict. Please rebase and resubmit the patch if it's still relevant.

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.

[Functions] Need a way to disable message batching between functions

4 participants