Skip to content
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 @@ -16,6 +16,7 @@
*/
package org.apache.rocketmq.broker.config.v2;

import com.google.common.base.Strings;
import io.netty.buffer.ByteBuf;
import io.netty.util.internal.PlatformDependent;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -425,4 +426,29 @@ public long queryPullOffset(String group, String topic, int queueId) {
}
return -1;
}

@Override
public void assignResetOffset(String topic, String group, int queueId, long offset) {
if (Strings.isNullOrEmpty(topic) || Strings.isNullOrEmpty(group) || queueId < 0 || offset < 0) {
LOG.warn("Illegal arguments when assigning reset offset. Topic={}, group={}, queueId={}, offset={}",
topic, group, queueId, offset);
return;
}
if (!MixAll.isLmq(topic) || !MixAll.isLmq(group)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

super.assignResetOffset(topic, group, queueId, offset);
} else {
String key = topic + TOPIC_GROUP_SEPARATOR + group;
ConcurrentMap<Integer, Long> map = resetOffsetTable.get(key);
if (null == map) {
map = new ConcurrentHashMap<>();
ConcurrentMap<Integer, Long> previous = resetOffsetTable.putIfAbsent(key, map);
if (null != previous) {
map = previous;
}
}
map.put(queueId, offset);
}

this.commitOffset(null, topic, group, queueId, offset);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class ConsumerOffsetManager extends ConfigManager {
protected ConcurrentMap<String/* topic@group */, ConcurrentMap<Integer, Long>> offsetTable =
new ConcurrentHashMap<>(512);

private final ConcurrentMap<String, ConcurrentMap<Integer, Long>> resetOffsetTable =
protected final ConcurrentMap<String, ConcurrentMap<Integer, Long>> resetOffsetTable =
new ConcurrentHashMap<>(512);

private final ConcurrentMap<String/* topic@group */, ConcurrentMap<Integer, Long>> pullOffsetTable =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import com.google.common.base.Strings;
import org.apache.rocketmq.broker.BrokerController;
import org.apache.rocketmq.broker.BrokerPathConfigHelper;
import org.apache.rocketmq.common.MixAll;
Expand Down Expand Up @@ -132,4 +134,30 @@ public void removeOffset(String group) {
}
}
}

@Override
public void assignResetOffset(String topic, String group, int queueId, long offset) {
if (Strings.isNullOrEmpty(topic) || Strings.isNullOrEmpty(group) || queueId < 0 || offset < 0) {
LOG.warn("Illegal arguments when assigning reset offset. Topic={}, group={}, queueId={}, offset={}",
topic, group, queueId, offset);
return;
}
if (!MixAll.isLmq(topic) || !MixAll.isLmq(group)) {
super.assignResetOffset(topic, group, queueId, offset);
return;
}

String key = topic + TOPIC_GROUP_SEPARATOR + group;
ConcurrentMap<Integer, Long> map = resetOffsetTable.get(key);
if (null == map) {
map = new ConcurrentHashMap<>();
ConcurrentMap<Integer, Long> previous = resetOffsetTable.putIfAbsent(key, map);
if (null != previous) {
map = previous;
}
}
map.put(queueId, offset);

lmqOffsetTable.computeIfPresent(key, (k, oldValue) -> offset);
}
}
Loading