未验证 提交 366e6e72 编写于 作者: V von gosling 提交者: GitHub

Merge pull request #1705 from duhenglucky/pull_consumer_offset

[ISSUE #1706]feat(pull_consumer) refactor the consumer offset update logic
......@@ -269,7 +269,7 @@ public class DefaultLitePullConsumer extends ClientConfig implements LitePullCon
@Override
public void commitSync() {
this.defaultLitePullConsumerImpl.commitSync();
this.defaultLitePullConsumerImpl.commitAll();
}
@Override
......
......@@ -177,6 +177,10 @@ public class AssignedMessageQueue {
}
}
public Set<MessageQueue> getAssignedMessageQueues() {
return this.assignedMessageQueueState.keySet();
}
private class MessageQueueState {
private MessageQueue messageQueue;
private ProcessQueue processQueue;
......
......@@ -590,37 +590,14 @@ public class DefaultLitePullConsumerImpl implements MQConsumerInner {
}
}
public synchronized void commitSync() {
public synchronized void commitAll() {
try {
for (MessageQueue messageQueue : assignedMessageQueue.messageQueues()) {
long consumerOffset = assignedMessageQueue.getConsumerOffset(messageQueue);
if (consumerOffset != -1) {
ProcessQueue processQueue = assignedMessageQueue.getProcessQueue(messageQueue);
long preConsumerOffset = this.getOffsetStore().readOffset(messageQueue, ReadOffsetType.READ_FROM_MEMORY);
if (processQueue != null && !processQueue.isDropped() && consumerOffset != preConsumerOffset) {
if (processQueue != null && !processQueue.isDropped()) {
updateConsumeOffset(messageQueue, consumerOffset);
updateConsumeOffsetToBroker(messageQueue, consumerOffset, false);
}
}
}
if (defaultLitePullConsumer.getMessageModel() == MessageModel.BROADCASTING) {
offsetStore.persistAll(assignedMessageQueue.messageQueues());
}
} catch (Exception e) {
log.error("An error occurred when update consume offset synchronously.", e);
}
}
private synchronized void commitAll() {
try {
for (MessageQueue messageQueue : assignedMessageQueue.messageQueues()) {
long consumerOffset = assignedMessageQueue.getConsumerOffset(messageQueue);
if (consumerOffset != -1) {
ProcessQueue processQueue = assignedMessageQueue.getProcessQueue(messageQueue);
long preConsumerOffset = this.getOffsetStore().readOffset(messageQueue, ReadOffsetType.READ_FROM_MEMORY);
if (processQueue != null && !processQueue.isDropped() && consumerOffset != preConsumerOffset) {
updateConsumeOffset(messageQueue, consumerOffset);
updateConsumeOffsetToBroker(messageQueue, consumerOffset, true);
}
}
}
......@@ -927,11 +904,16 @@ public class DefaultLitePullConsumerImpl implements MQConsumerInner {
try {
checkServiceState();
Set<MessageQueue> mqs = new HashSet<MessageQueue>();
if (this.subscriptionType == SubscriptionType.SUBSCRIBE) {
Set<MessageQueue> allocateMq = this.rebalanceImpl.getProcessQueueTable().keySet();
mqs.addAll(allocateMq);
} else if (this.subscriptionType == SubscriptionType.ASSIGN) {
Set<MessageQueue> assignedMessageQueue = this.assignedMessageQueue.getAssignedMessageQueues();
mqs.addAll(assignedMessageQueue);
}
this.offsetStore.persistAll(mqs);
} catch (Exception e) {
log.error("group: " + this.defaultLitePullConsumer.getConsumerGroup() + " persistConsumerOffset exception", e);
log.error("Persist consumer offset error for group: {} ", this.defaultLitePullConsumer.getConsumerGroup(), e);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册