-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the issue gRPC notify thread blocked (#965)
Add backpressure buffer with ERROR strategy to notifying and shared polling topic listeners. When overflow happens, the controller will send a gRPC error after all buffered messages and disconnect the client. Signed-off-by: Xin Li <[email protected]>
- Loading branch information
1 parent
c252dbb
commit e301647
Showing
10 changed files
with
84 additions
and
9 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
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
58 changes: 58 additions & 0 deletions
58
...r-grpc/src/test/java/com/hedera/mirror/grpc/listener/AbstractSharedTopicListenerTest.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,58 @@ | ||
package com.hedera.mirror.grpc.listener; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.Vector; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.LongStream; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import reactor.core.Exceptions; | ||
import reactor.test.StepVerifier; | ||
|
||
import com.hedera.mirror.grpc.domain.TopicMessage; | ||
import com.hedera.mirror.grpc.domain.TopicMessageFilter; | ||
|
||
public abstract class AbstractSharedTopicListenerTest extends AbstractTopicListenerTest { | ||
|
||
@Test | ||
@DisplayName("slow subscriber receives overflow exception and normal subscriber is not affected") | ||
void slowSubscriberOverflowException() { | ||
int maxBufferSize = 16; | ||
listenerProperties.setMaxBufferSize(maxBufferSize); | ||
|
||
TopicMessageFilter filter = TopicMessageFilter.builder() | ||
.startTime(Instant.EPOCH) | ||
.build(); | ||
|
||
// create a normal subscriber to keep the shared flux open | ||
Vector<Long> sequenceNumbers = new Vector<>(); | ||
var subscription = getTopicListener().listen(filter) | ||
.map(TopicMessage::getSequenceNumber) | ||
.subscribe(sequenceNumbers::add); | ||
|
||
// the slow subscriber | ||
getTopicListener().listen(filter) | ||
.map(TopicMessage::getSequenceNumber) | ||
.as(p -> StepVerifier.create(p, 1)) // initial request amount - 1 | ||
.thenRequest(1) // trigger subscription | ||
.thenAwait(Duration.ofMillis(10L)) | ||
.then(() -> { | ||
// upon subscription, step verifier will request 2, so we need 2 + maxBufferSize + 1 to trigger | ||
// overflow error | ||
domainBuilder.topicMessages(maxBufferSize + 3, future).blockLast(); | ||
}) | ||
.expectNext(1L, 2L) | ||
.thenAwait(Duration.ofMillis(500L)) // stall to overrun backpressure buffer | ||
.thenRequest(Long.MAX_VALUE) | ||
.expectNextSequence(LongStream.range(3, maxBufferSize + 3).boxed().collect(Collectors.toList())) | ||
.expectErrorMatches(Exceptions::isOverflow) | ||
.verify(Duration.ofMillis(600L)); | ||
|
||
assertThat(subscription.isDisposed()).isFalse(); | ||
subscription.dispose(); | ||
assertThat(sequenceNumbers).isEqualTo(LongStream.range(1, maxBufferSize + 4).boxed().collect(Collectors.toList())); | ||
} | ||
} |
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