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

[ISSUE #9149]Assign offset in offsetTable even if the subscription key not exist. #9150

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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.offset;

import com.google.common.collect.Maps;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -417,27 +418,14 @@ public void assignResetOffset(String topic, String group, int queueId, long offs
}

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

map.put(queueId, offset);
LOG.debug("Reset offset OK. Topic={}, group={}, queueId={}, resetOffset={}",
topic, group, queueId, offset);
resetOffsetTable.computeIfAbsent(key, k -> Maps.newConcurrentMap()).put(queueId, offset);
LOG.debug("Reset offset OK. Topic={}, group={}, queueId={}, resetOffset={}", topic, group, queueId, offset);

// Two things are important here:
// 1, currentOffsetMap might be null if there is no previous records;
// 2, Our overriding here may get overridden by the client instantly in concurrent cases; But it still makes
// sense in cases like clients are offline.
ConcurrentMap<Integer, Long> currentOffsetMap = offsetTable.get(key);
if (null != currentOffsetMap) {
currentOffsetMap.put(queueId, offset);
}
offsetTable.computeIfAbsent(key, k -> Maps.newConcurrentMap()).put(queueId, offset);
}

public boolean hasOffsetReset(String topic, String group, int queueId) {
Expand Down
Loading