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

PIP 68: Exclusive Producer #8685

Merged
merged 6 commits into from
Dec 3, 2020
Merged

Conversation

merlimat
Copy link
Contributor

Motivation

Implementation of https://github.com/apache/pulsar/wiki/PIP-68%3A-Exclusive-Producer

This is the first part of the implementation of exclusive producer. It adds support for ProducerAccessMode.Exclusive.

The 2nd mode, ProducerAccessMode.WaitForExclusive, will be added in separate PR.

@merlimat merlimat added the type/feature The PR added a new feature or issue requested a new feature label Nov 24, 2020
@merlimat merlimat added this to the 2.8.0 milestone Nov 24, 2020
@merlimat merlimat self-assigned this Nov 24, 2020
Copy link
Contributor

@rdhabalia rdhabalia left a comment

Choose a reason for hiding this comment

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

LGTM.. few minor comments.

}

protected CompletableFuture<Optional<Long>> incrementTopicEpochIfNeeded(Producer producer) {
lock.writeLock().lock();
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 avoid locking for normal producer usecase?

if (producers.isEmpty() && producer.getAccessMode() == Shared) {
return CompletableFuture.completedFuture(topicEpoch);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to @rdhabalia suggestion

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'm not sure that we can avoid the locking, and I'm not sure that it's something to worry about in the context of adding a producer.
Actually, in the specific case there's still a race condition between updating the producers map, since the update to hasExclusiveProducer and the insertion into producers map should be atomic as well.

return future;
}

// case WaitForExclusive:
Copy link
Contributor

Choose a reason for hiding this comment

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

I have one suggestion. I am sure you must have thought about it but can't we rename WaitForExclusive with FailOver as it will be consistent to subscription type name and it will need no explanation and easy to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem I see is that it's not exactly the same thing and that can confuse people:

  1. The semantic of creating a WaitForExclusive is different because the newProducer()....create() call is hanging until that particular producer is selected, unlike in consumers where it's created immediately but it will not receive messages.
  2. The use case is mostly different from "failover" for reliability purpose, since you can use WaitForExclusive to do leader election

checkArgument(producer.getTopic() == this);

if (producers.remove(producer.getProducerName(), producer)) {
handleProducerRemoved(producer);
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we need lock here else it may create a race condition and producer with WaitForExclusive may wait forever.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No lock needed there so far. Other changes are needed for WaitForExclusive, it's not implemented in this PR

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

Great work!
I left a few little suggestions

}

protected CompletableFuture<Optional<Long>> incrementTopicEpochIfNeeded(Producer producer) {
lock.writeLock().lock();
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to @rdhabalia suggestion

@merlimat
Copy link
Contributor Author

merlimat commented Dec 1, 2020

Rebased and addressed comments

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

LGTM
Great work

One question, with an Exclusive Producer, what happens if I delete and recreate a topic?

  • create a topic
  • start ex producer and write
  • delete/create the same topic
  • is the producer still valid?
    I expect the ex producer to be fenced out.
    Is this the case?

@@ -86,5 +88,11 @@ void runMessageExpiryCheck() {
}
}

private static final Random random = new Random();
Copy link
Contributor

Choose a reason for hiding this comment

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

What about setting a fixed seed? In order to have reproducible tests execution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just to get random topic names. We don't really need it to be reproducible.

@merlimat
Copy link
Contributor Author

merlimat commented Dec 2, 2020

One question, with an Exclusive Producer, what happens if I delete and recreate a topic?

  • create a topic
  • start ex producer and write
  • delete/create the same topic
  • is the producer still valid?
    I expect the ex producer to be fenced out.
    Is this the case?

Deleting the topic will delete all the state associated with the topic. If the topic is re-created, it's effectively a different topic. All the state associated with the topic is gone: subscriptions, dedup state, fencing.

The topic epoch will be reset after the deletion, so it should allow the producer. I will add specific test for this.

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

Great. Thank you

@merlimat merlimat merged commit d12486b into apache:master Dec 3, 2020
@merlimat merlimat deleted the exclusive-producer branch December 3, 2020 01:38
RobertIndie pushed a commit to RobertIndie/pulsar that referenced this pull request Dec 8, 2020
* PIP 68: Exclusive Producer

* Added missing enums cases in C++

* Addressed comments

* Moved constant to top of file

* Fix mistake in previous update

* Added handling for topic deletion
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.

None yet

4 participants