forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix][transaction] avoid too many ServiceUnitNotReadyException for tr…
…ansaction buffer handler (apache#14894) ### Motivation 1. Added max concurrent request limitation for transaction buffer client 2. Add the request to the pending request queue after reaching the concurrent request limitation 3. Avoid duplicated lookup cache invalidation
- Loading branch information
1 parent
2dcd7ff
commit 384c528
Showing
9 changed files
with
298 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
257 changes: 182 additions & 75 deletions
257
...n/java/org/apache/pulsar/broker/transaction/buffer/impl/TransactionBufferHandlerImpl.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...st/java/org/apache/pulsar/broker/transaction/buffer/TransactionBufferHandlerImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.broker.transaction.buffer; | ||
|
||
import org.apache.pulsar.broker.transaction.buffer.impl.TransactionBufferHandlerImpl; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.doNothing; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.when; | ||
import static org.testng.Assert.assertEquals; | ||
|
||
import org.apache.pulsar.client.impl.ClientCnx; | ||
import org.apache.pulsar.client.impl.PulsarClientImpl; | ||
import org.apache.pulsar.common.api.proto.TxnAction; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
@Test(groups = "broker") | ||
public class TransactionBufferHandlerImplTest { | ||
|
||
@Test | ||
public void testRequestCredits() { | ||
PulsarClientImpl pulsarClient = mock(PulsarClientImpl.class); | ||
when(pulsarClient.getConnection(anyString())).thenReturn(CompletableFuture.completedFuture(mock(ClientCnx.class))); | ||
TransactionBufferHandlerImpl handler = spy(new TransactionBufferHandlerImpl(pulsarClient, null, 1000)); | ||
doNothing().when(handler).endTxn(any()); | ||
for (int i = 0; i < 500; i++) { | ||
handler.endTxnOnTopic("t", 1L, 1L, TxnAction.COMMIT, 1L); | ||
} | ||
assertEquals(handler.getAvailableRequestCredits(), 500); | ||
for (int i = 0; i < 500; i++) { | ||
handler.endTxnOnTopic("t", 1L, 1L, TxnAction.COMMIT, 1L); | ||
} | ||
assertEquals(handler.getAvailableRequestCredits(), 0); | ||
handler.endTxnOnTopic("t", 1L, 1L, TxnAction.COMMIT, 1L); | ||
assertEquals(handler.getPendingRequestsCount(), 1); | ||
handler.onResponse(null); | ||
assertEquals(handler.getAvailableRequestCredits(), 0); | ||
assertEquals(handler.getPendingRequestsCount(), 0); | ||
} | ||
|
||
@Test | ||
public void testMinRequestCredits() { | ||
TransactionBufferHandlerImpl handler = spy(new TransactionBufferHandlerImpl(null, null, 50)); | ||
assertEquals(handler.getAvailableRequestCredits(), 100); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters