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

[fix][txn] fix NPE of TransactionMetaStoreHandler #15840

Conversation

congbobo184
Copy link
Contributor

@congbobo184 congbobo184 commented May 30, 2022

05:30:15.799 [pulsar-client-io-14-1] ERROR org.apache.pulsar.client.impl.ProducerImpl - [persistent://public/default/sink-topic-partition-7] [normal-pulsar-1-58] Failed to create producer: Disconnected from server at 127.0.0.1/127.0.0.1:6650
05:30:15.799 [pulsar-client-internal-19-1] ERROR org.apache.pulsar.client.impl.TransactionMetaStoreHandler - The cnx was null when the TC handler was ready
java.lang.NullPointerException: null
  at org.apache.pulsar.client.impl.TransactionMetaStoreHandler.checkStateAndSendRequest(TransactionMetaStoreHandler.java:664) ~[test-transaction-1.0-SNAPSHOT-jar-with-dependencies.jar:?]
  at org.apache.pulsar.client.impl.TransactionMetaStoreHandler.lambda$newTransactionAsync$7(TransactionMetaStoreHandler.java:206) ~[test-transaction-1.0-SNAPSHOT-jar-with-dependencies.jar:?]
  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[?:?]
  at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[?:?]
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[?:?]
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[?:?]
  at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[test-transaction-1.0-SNAPSHOT-jar-with-dependencies.jar:?]
  at java.lang.Thread.run(Thread.java:829) ~[?:?]

Motivation

fix transactionMetadataStoreHandle cnx is null.

connectionHandler.setClientCnx(cnx);
cnx.registerTransactionMetaStoreHandler(transactionCoordinatorId, this);
// if broker protocol version < 19, don't send TcClientConnectRequest to broker.
if (cnx.getRemoteEndpointProtocolVersion() > ProtocolVersion.v18.getValue()) {
long requestId = client.newRequestId();
ByteBuf request = Commands.newTcClientConnectRequest(transactionCoordinatorId, requestId);
cnx.sendRequestWithId(request, requestId).thenRun(() -> {
internalPinnedExecutor.execute(() -> {
LOG.info("Transaction coordinator client connect success! tcId : {}", transactionCoordinatorId);
if (!changeToReadyState()) {
setState(State.Closed);
cnx.channel().close();
}
if (!this.connectFuture.isDone()) {
this.connectFuture.complete(null);
}
this.connectionHandler.resetBackoff();
pendingRequests.forEach((requestID, opBase) -> checkStateAndSendRequest(opBase));

because

cnx.sendRequestWithId(request, requestId).thenRun(() -> {

is the async method, set cnx, and change to ready state is not an atomic operation.

  1. set cnx into this handle
  2. reconnect will set the cnx to null
  3. then send connect request and get a response that will change state to ready state.
  4. the client will not reconnect because the state is ready
  5. the cnx also is null. transactionMetadataStoreHandle will not do txn op.

Modifications

fix race condition

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

  • Does this pull requestintroducese a new feature? (yes)
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
  • If a feature is not applicable for documentation, explain why?
  • If a feature is not documented yet in this PR, please create afollow-upp issue for adding the documentation

@congbobo184 congbobo184 added type/bug The PR fixed a bug or issue reported a bug area/transaction doc-not-needed Your PR changes do not impact docs release/2.9.3 release/2.10.1 labels May 30, 2022
@congbobo184 congbobo184 added this to the 2.11.0 milestone May 30, 2022
@congbobo184 congbobo184 self-assigned this May 30, 2022
@HQebupt
Copy link
Contributor

HQebupt commented May 30, 2022

/pulsarbot run-failure-checks

Copy link
Member

@mattisonchao mattisonchao left a comment

Choose a reason for hiding this comment

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

LGTM,

@codelipenghui codelipenghui merged commit f9b0912 into apache:master Jun 9, 2022
@codelipenghui codelipenghui changed the title [fix][txn] Transaction metadata client cnx is null [fix][txn] fix NPE of TransactionMetaStoreHandler Jun 9, 2022
codelipenghui pushed a commit that referenced this pull request Jun 10, 2022
@codelipenghui codelipenghui added the cherry-picked/branch-2.9 Archived: 2.9 is end of life label Jun 10, 2022
codelipenghui pushed a commit that referenced this pull request Jun 12, 2022
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request Jun 13, 2022
(cherry picked from commit f9b0912)
(cherry picked from commit fc40d10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/transaction cherry-picked/branch-2.9 Archived: 2.9 is end of life cherry-picked/branch-2.10 doc-not-needed Your PR changes do not impact docs release/2.9.3 release/2.10.1 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.

4 participants