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

Runtime dev 0730 #141

Merged
merged 2 commits into from
Jul 30, 2023
Merged
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 @@ -24,6 +24,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.annotation.PostConstruct;
import org.apache.commons.collections.MapUtils;
import org.apache.rocketmq.eventbridge.adapter.runtime.boot.common.CirculatorContext;
Expand Down Expand Up @@ -67,7 +68,7 @@ public void init() {

@Override
public void run() {
List<ConnectRecord> afterTransformConnect= Lists.newArrayList();
List<ConnectRecord> afterTransformConnect = new CopyOnWriteArrayList<>();;
while (!stopped) {
try {
Map<String, List<ConnectRecord>> eventRecordMap = circulatorContext.takeEventRecords(batchSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class LitePullConsumerImpl implements LitePullConsumer {
private static final Long PULL_TIME_DELAY_MILLS_WHEN_BROKER_FLOW_CONTROL = 30L;
private static final Long PULL_TIME_DELAY_MILLS_WHEN_EXCEPTION = TimeUnit.SECONDS.toMillis(3);
private static final String DEFAULT_INSTANCE_NAME = "EventBridge_Consumer_INSTANCE";
private static final Integer PULL_BATCH_NUM = 32;

public LitePullConsumerImpl(final ClientConfig clientConfig, final RPCHook rpcHook) {
this.clientConfig = clientConfig;
Expand Down Expand Up @@ -224,16 +225,8 @@ public void run() {
return;
}
long offset = localMessageCache.nextPullOffset(messageQueue);
int batchNums = localMessageCache.nextPullBatchNums();
// If batchNums is zero, an exception will be thrown and then trigger a delay
if (batchNums <= 0) {
log.warn("Local cache is full, delay the pull task {} ms for message queue {}",
PULL_TIME_DELAY_MILLS_WHEN_EXCEPTION, messageQueue);
pullLater(PullTask.this, PULL_TIME_DELAY_MILLS_WHEN_EXCEPTION, TimeUnit.MILLISECONDS);
return;
}

rocketmqPullConsumer.pullBlockIfNotFound(this.messageQueue, this.tag, offset, batchNums, new PullCallback() {
rocketmqPullConsumer.pullBlockIfNotFound(this.messageQueue, this.tag, offset, PULL_BATCH_NUM, new PullCallback() {
@Override
public void onSuccess(PullResult pullResult) {
try {
Expand All @@ -249,7 +242,7 @@ public void onSuccess(PullResult pullResult) {
if (pq != null && !pq.isDropped()) {
pq.putMessage(pullResult.getMsgFoundList());
for (final MessageExt messageExt : pullResult.getMsgFoundList()) {
localMessageCache.submitConsumeRequest(new ConsumeRequest(messageExt, messageQueue, pq));
localMessageCache.submitConsumeRequest(new ConsumeRequest(messageExt, messageQueue, pq), Long.MAX_VALUE);
}
localMessageCache.updatePullOffset(messageQueue, pullResult.getNextBeginOffset());
pullImmediately(PullTask.this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,13 @@ void shrinkPullOffsetTable(Set<MessageQueue> mqDivided) {
pullOffsetTable.entrySet().removeIf(next -> !mqDivided.contains(next.getKey()));
}

void submitConsumeRequest(ConsumeRequest consumeRequest) {
boolean submitConsumeRequest(ConsumeRequest consumeRequest, Long timeout) {
try {
consumeRequestCache.put(consumeRequest);
} catch (InterruptedException ignore) {
return consumeRequestCache.offer(consumeRequest, timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
log.warn("put consumeRequestCache failed", e);
}
return false;
}

public List<MessageExt> poll(final int pullBatchSize, final Duration timeout) {
Expand Down