Skip to content

[improve][client] Move acknowledge APIs to another interface and improve docs - #18519

Merged
BewareMyPower merged 3 commits into
apache:masterfrom
BewareMyPower:bewaremypower/ack-api
Nov 29, 2022
Merged

BewareMyPower merged 3 commits into
apache:masterfrom
BewareMyPower:bewaremypower/ack-api

Conversation

@BewareMyPower

Copy link
Copy Markdown
Contributor

Motivation

Currently there are many acknowledge methods in Consumer interface, including:

  • 7 overloads of acknowledgeAsync
  • 4 overloads of acknowledge
  • 3 overloads of acknowledgeCumulativeAsync
  • 2 overloads of acknowledgeCumulative

The JavaDocs of these APIs are also massive and duplicated. For example, some terms are not for application users like "pending ack", which should not appear in API Docs.

Modifications

  • Add a new interface MessageAcknowledger and move the acknowledge APIs into this new interface.
  • Improve the API docs. For some overload methods, change them to default methods so that duplicated description can be avoided.

The new API docs should be much more clear than before. Though this PR adds a new API, the API compatibility is guaranteed.

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

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository: BewareMyPower#9

…ove docs

### Motivation

Currently there are many acknowledge methods in `Consumer` interface,
including:
- 7 overloads of `acknowledgeAsync`
- 4 overloads of `acknowledge`
- 3 overloads of `acknowledgeCumulativeAsync`
- 2 overloads of `acknowledgeCumulative`

The JavaDocs of these APIs are also massive and duplicated. For example,
some terms are not for application users like "pending ack", which
should not appear in API Docs.

### Modifications

- Add a new interface `MessageAcknowledger` and move the acknowledge
  APIs into this new interface.
  - Improve the API docs. For some overload methods, change them to
    default methods so that duplicated description can be avoided.

The new API docs should be much more clear than before. Though this
PR adds a new API, the API compatibility is guaranteed.
@BewareMyPower BewareMyPower self-assigned this Nov 17, 2022
@github-actions github-actions Bot added the doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. label Nov 17, 2022

@eolivelli eolivelli 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.

Is it API compatible with applications compiled against the previous version of the API ? is it a binary compatible change ?

There are many components (Functions, Sinks, Sources..) that inherit the Pulsar API from the container, we must ensure that changing the API jars doesn't break compatibility and requires rebuilding the applications

@BewareMyPower

Copy link
Copy Markdown
Contributor Author

we must ensure that changing the API jars doesn't break compatibility and requires rebuilding the applications

Is there any way to verify it?

@BewareMyPower

Copy link
Copy Markdown
Contributor Author

@eolivelli I wrote a function just now with the 2.10.2 dependency.

package org.example;

import org.apache.pulsar.functions.api.Context;
import org.apache.pulsar.functions.api.Function;

public class StringLengthExample implements Function<String, Integer> {

    @Override
    public Integer process(String input, Context context) throws Exception {
        return input.length();
    }
}
    <dependency>
      <groupId>org.apache.pulsar</groupId>
      <artifactId>pulsar-functions-api</artifactId>
      <version>2.10.2</version>
    </dependency>

Then I created the function in the branch of this PR and it works well.

./bin/pulsar-admin functions create \
 --jar ./PulsarFunctionDemo-1.0-SNAPSHOT.jar \
 --classname org.example.StringLengthExample \
 --tenant public \
 --namespace default \
 --name word-count \
 --inputs persistent://public/default/sentences \
 --output persistent://public/default/count
./bin/pulsar-client produce sentences -m "hello world java"
$ ./bin/pulsar-client consume -s sub count -n 0
...
----- got message -----
key:[null], properties:[__pfn_input_msg_id__=CAsQADAA, __pfn_input_topic__=persistent://public/default/sentences], content:16

Could it verify the API and binary compatibility?

@BewareMyPower

BewareMyPower commented Nov 17, 2022 •

Copy link
Copy Markdown
Contributor Author

I added the Consumer related API invocations, it also worked well.

        final PulsarClient client = PulsarClient.builder().serviceUrl("pulsar://localhost:6650").build();
        final Consumer<String> consumer = client.newConsumer(Schema.STRING)
                .topic("xxx")
                .subscriptionName("sub")
                .subscribe();
        consumer.acknowledge(MessageId.earliest);
        consumer.close();
        client.close();
        return input.length();

The change of this PR is similar to changing the API from

public interface A {
    void f();
    void f(int x);
    void g();
}

to

public interface F {
    void f(int x);
    // actually the default method is always overrided because the
    // previous implementation doesn't make it default
    default void f() {
        f(0);
    }
}
public interface A extends F {
    void g();
}

@BewareMyPower

Copy link
Copy Markdown
Contributor Author

@eolivelli Is there any more concern? If you concerned about the binary compatibility, from https://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html, we can see

here is a list of some important binary compatible changes that the Java programming language supports:
...
Moving a method upward in the class hierarchy.

We can also have a simple verification like:

.
├── AImpl.java
├── v0
│   └── A.java
└── v1
    ├── A.java
    └── F.java

where AImpl implements the interface A.

$ cat v0/A.java
public interface A {
    void f();
    void f(int x);
    void g();
}
$ cat v1/A.java
public interface A extends F {
    void g();
}
$ cat v1/F.java
public interface F {
    void f(int x);
    default void f() {
        f(100);
    }
}
$ javac AImpl.java v0/A.java
$ java -classpath $PWD/v0:$PWD AImpl
f()
f(1)
g()
$ javac v1/*.java
$ java -classpath $PWD/v1:$PWD AImpl
f()
f(1)
g()

@tisonkun tisonkun 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.

This can be a good refactor to go. To see the value of separating interfaces, we can actually mock (write test class) against the narrow interface in testing code.

@tisonkun
tisonkun requested a review from eolivelli November 23, 2022 02:54

@eolivelli eolivelli 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.

Lgtm

Thanks for double checking

@tisonkun

Copy link
Copy Markdown
Member

/pulsarbot run-failure-checks

@codecov-commenter

codecov-commenter commented Nov 24, 2022 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.62%. Comparing base (cee697b) to head (93c5d47).
⚠️ Report is 3224 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #18519      +/-   ##
============================================
+ Coverage     47.06%   49.62%   +2.55%     
+ Complexity     8956     8434     -522     
============================================
  Files           592      489     -103     
  Lines         56313    53642    -2671     
  Branches       5844     5703     -141     
============================================
+ Hits          26503    26619     +116     
+ Misses        26946    24011    -2935     
- Partials       2864     3012     +148     
Flag Coverage Δ
unittests 49.62% <ø> (+2.55%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 382 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Technoboy- Technoboy- added this to the 2.12.0 milestone Nov 29, 2022
@BewareMyPower
BewareMyPower merged commit 6a71948 into apache:master Nov 29, 2022
@BewareMyPower
BewareMyPower deleted the bewaremypower/ack-api branch December 7, 2022 14:07
lifepuzzlefun pushed a commit to lifepuzzlefun/pulsar that referenced this pull request Dec 9, 2022
lifepuzzlefun pushed a commit to lifepuzzlefun/pulsar that referenced this pull request Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/client doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. ready-to-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants