Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -240,26 +240,36 @@ private void fetch(FetchState fetchState) {
.setInboxId(inboxId)
.setIncarnation(incarnation)
.setFetched(fetched).build());
if (fetched.getQos0MsgCount() > 0 || fetched.getSendBufferMsgCount() > 0) {
if (fetched.getQos0MsgCount() > 0) {
fetchState.lastFetchQoS0Seq.set(
fetched.getQos0Msg(fetched.getQos0MsgCount() - 1).getSeq());
Fetched.Result result = fetched.getResult();
switch (result) {
case OK -> {
if (fetched.getQos0MsgCount() > 0 || fetched.getSendBufferMsgCount() > 0) {
if (fetched.getQos0MsgCount() > 0) {
fetchState.lastFetchQoS0Seq.set(
fetched.getQos0Msg(fetched.getQos0MsgCount() - 1).getSeq());
}
int fetchedCount = 0;
if (fetched.getSendBufferMsgCount() > 0) {
fetchedCount += fetched.getSendBufferMsgCount();
fetchState.downStreamCapacity.accumulateAndGet(
fetched.getSendBufferMsgCount(),
(a, b) -> a == NOT_KNOWN_CAPACITY ? a : Math.max(a - b, 0));
fetchState.lastFetchSendBufferSeq.set(
fetched.getSendBufferMsg(fetched.getSendBufferMsgCount() - 1).getSeq());
}
fetchState.hasMore.set(fetchedCount >= request.params().getMaxFetch()
|| fetchState.signalFetchTS.get() > fetchTS);
} else {
fetchState.hasMore.set(fetchState.signalFetchTS.get() > fetchTS);
}
}
int fetchedCount = 0;
if (fetched.getSendBufferMsgCount() > 0) {
fetchedCount += fetched.getSendBufferMsgCount();
fetchState.downStreamCapacity.accumulateAndGet(fetched.getSendBufferMsgCount(),
(a, b) -> a == NOT_KNOWN_CAPACITY ? a : Math.max(a - b, 0));
fetchState.lastFetchSendBufferSeq.set(
fetched.getSendBufferMsg(fetched.getSendBufferMsgCount() - 1).getSeq());
}
fetchState.hasMore.set(fetchedCount >= request.params().getMaxFetch()
|| fetchState.signalFetchTS.get() > fetchTS);
} else {
fetchState.hasMore.set(fetchState.signalFetchTS.get() > fetchTS);
case BACK_PRESSURE_REJECTED, TRY_LATER -> fetchState.hasMore.set(true);
default -> fetchState.hasMore.set(false);
}
fetchState.fetching.set(false);
if (fetchState.downStreamCapacity.get() > 0 && fetchState.hasMore.get()) {
if (result == Fetched.Result.OK
&& fetchState.downStreamCapacity.get() > 0
&& fetchState.hasMore.get()) {
fetch(sessionId);
}
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,40 @@ public void shouldNotRewindStartAfterWhenHintIsStale() {
pipeline.close();
}

@Test
public void shouldRetryAfterTryLaterOnHint() {
InboxFetcherRegistry registry = new InboxFetcherRegistry();
TestFetcher fetcher = new TestFetcher();
InboxFetchPipeline pipeline = new InboxFetchPipeline(responseObserver, fetcher, registry);

long sessionId = 3503L;
pipeline.onNext(hint(sessionId, 2));

FetchRequest firstRequest = fetcher.awaitRequest();
assertNotNull(firstRequest);

fetcher.completeNext(Fetched.newBuilder()
.setResult(Fetched.Result.TRY_LATER)
.build());

await().until(() -> {
synchronized (received) {
return !received.isEmpty();
}
});

pipeline.onNext(hint(sessionId, 2));

FetchRequest retryRequest = fetcher.awaitRequest();
assertNotNull(retryRequest);

fetcher.completeNext(Fetched.newBuilder()
.setResult(Fetched.Result.OK)
.build());

pipeline.close();
}

@Test
public void shouldCleanStaleSessionIdWhenFetchStateMissing() throws Exception {
InboxFetcherRegistry registry = new InboxFetcherRegistry();
Expand Down
Loading