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

[Broker] Always let system topic TRANSACTION_BUFFER_SNAPSHOT be auto created #10876

Merged
merged 3 commits into from
Jun 10, 2021

Conversation

michaeljmarshall
Copy link
Member

Fixes #10871

Motivation

From the linked issue:

While testing the 2.8.0rc2 I found that if you start a Pulsar broker with transactionCoordinatorEnabled=true and allowAutoTopicCreation=false the broker does not work.

The TRANSACTION_BUFFER_SNAPSHOT topic is a system topic, and it should be auto created as needed.

Modifications

  1. Updated the logic in the isAllowAutoTopicCreation method to ensure that TRANSACTION_BUFFER_SNAPSHOT is considered a system topic.
  2. Updated the logic in checkTopicIsEventsNames to take a TopicName and then check for equality in stead of check endsWith. That could have technically led to unexpected behavior if the topic name was something like my__change_events or my__transaction_buffer_snapshot.
  3. Check for isSystemTopicEnabled first to prevent potentially unnecessary string equality checks.

Verifying this change

This is a simple fix that has limit impact. We'll want to verify that the logic is correct regarding allowing TRANSACTION_BUFFER_SNAPSHOT to be auto created. Otherwise, there should be tests covering the uses of this checkTopicIsEventsNames method.

Note that this change will impact the PersistentTopic and the PersistentSubscription classes. Based on reading through the usage of the checkTopicIsEventsNames method, I think this is the right change for those classes. Here are the affected usages:

TopicName topicName = TopicName.get(topic);
if (brokerService.getPulsar().getConfiguration().isTransactionCoordinatorEnabled()
&& !checkTopicIsEventsNames(topic)
&& !topicName.getEncodedLocalName().startsWith(TopicName.TRANSACTION_COORDINATOR_ASSIGN.getLocalName())
&& !topicName.getEncodedLocalName().startsWith(MLTransactionLogImpl.TRANSACTION_LOG_PREFIX)
&& !topicName.getEncodedLocalName().endsWith(MLPendingAckStore.PENDING_ACK_STORE_SUFFIX)) {
this.transactionBuffer = brokerService.getPulsar()
.getTransactionBufferProvider().newTransactionBuffer(this, transactionCompletableFuture);
} else {
this.transactionCompletableFuture.complete(null);
this.transactionBuffer = new TransactionBufferDisable();
}
transactionBuffer.syncMaxReadPositionForNormalPublish((PositionImpl) ledger.getLastConfirmedEntry());
}

if (topic.getBrokerService().getPulsar().getConfig().isTransactionCoordinatorEnabled()
&& !checkTopicIsEventsNames(topicName)
&& !topicName.startsWith(TopicName.TRANSACTION_COORDINATOR_ASSIGN.getLocalName())
&& !topicName.startsWith(MLTransactionLogImpl.TRANSACTION_LOG_PREFIX)
&& !topicName.endsWith(MLPendingAckStore.PENDING_ACK_STORE_SUFFIX)) {
this.pendingAckHandle = new PendingAckHandleImpl(this);
} else {
this.pendingAckHandle = new PendingAckHandleDisabled();
}

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

If yes was chosen, please highlight the changes

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

Documentation

I don't think we need new documentation for this, but if someone more familiar with transactions wants docs, please let me know where I can add docs.

@michaeljmarshall
Copy link
Member Author

@congbobo184 @codelipenghui @sijie @merlimat - PTAL. I am not familiar with the intricacies of the transaction code base within the brokers, but I think this change should fix the issue that @eolivelli discovered in #10871.

@michaeljmarshall
Copy link
Member Author

/pulsarbot run-failure-checks

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.

looks good

please add an unit test

@michaeljmarshall
Copy link
Member Author

@eolivelli - done. I didn't see a good way to test the other usages of the checkTopicIsEventsNames method. If someone more familiar with transactions can provide a good way to test this method's usage in those cases, please let me know.

@merlimat merlimat added the type/bug The PR fixed a bug or issue reported a bug label Jun 9, 2021
Copy link
Contributor

@congbobo184 congbobo184 left a comment

Choose a reason for hiding this comment

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

LGTM

@merlimat merlimat dismissed eolivelli’s stale review June 10, 2021 04:57

The unit test was added. Merging now to include in 2.8 rc3

@merlimat merlimat merged commit b1b3b3c into apache:master Jun 10, 2021
@merlimat merlimat added this to the 2.8.0 milestone Jun 10, 2021
@michaeljmarshall michaeljmarshall deleted the system-auto-topic-creation branch June 10, 2021 05:53
@eolivelli
Copy link
Contributor

LGTM

it would be great to have a new 2.8.0rc3

codelipenghui pushed a commit that referenced this pull request Jun 11, 2021
…created (#10876)

* Always let system topic TRANSACTION_BUFFER_SNAPSHOT be auto created

* Remove unused import

* Add EVENTS_TOPIC_NAMES set; add unit tests

(cherry picked from commit b1b3b3c)
eolivelli pushed a commit to datastax/pulsar that referenced this pull request Jun 14, 2021
…created (apache#10876)

* Always let system topic TRANSACTION_BUFFER_SNAPSHOT be auto created

* Remove unused import

* Add EVENTS_TOPIC_NAMES set; add unit tests

(cherry picked from commit b1b3b3c)
(cherry picked from commit e44be07)
yangl pushed a commit to yangl/pulsar that referenced this pull request Jun 23, 2021
…created (apache#10876)

* Always let system topic TRANSACTION_BUFFER_SNAPSHOT be auto created

* Remove unused import

* Add EVENTS_TOPIC_NAMES set; add unit tests
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
…created (apache#10876)

* Always let system topic TRANSACTION_BUFFER_SNAPSHOT be auto created

* Remove unused import

* Add EVENTS_TOPIC_NAMES set; add unit tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Transactions] Problems in case of transactionCoordinatorEnabled=true and allowAutoTopicCreation=false
4 participants