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 #6545] Remove getTopicConfigs method in interface MessageStore #6531

Merged
merged 19 commits into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -2060,7 +2060,7 @@ public Optional<TopicConfig> getTopicConfig(String topic) {
}

public void setTopicConfigTable(ConcurrentMap<String, TopicConfig> topicConfigTable) {
this.consumeQueueStore.setTopicConfigTable(topicConfigTable);
this.consumeQueueStore.setTopicConfigFunction(topic -> topicConfigTable != null ? topicConfigTable.get(topic) : null);
joeCarf marked this conversation as resolved.
Show resolved Hide resolved
}

public BrokerIdentity getBrokerIdentity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import org.apache.rocketmq.common.ThreadFactoryImpl;
import org.apache.rocketmq.common.TopicConfig;
import org.apache.rocketmq.common.attribute.CQType;
Expand Down Expand Up @@ -64,18 +65,17 @@ public class ConsumeQueueStore {
protected final QueueOffsetAssigner queueOffsetAssigner = new QueueOffsetAssigner();
protected final ConcurrentMap<String/* topic */, ConcurrentMap<Integer/* queueId */, ConsumeQueueInterface>> consumeQueueTable;

// Should be careful, do not change the topic config
// TopicConfigManager is more suitable here.
private ConcurrentMap<String, TopicConfig> topicConfigTable;
// get config from topicConfigTable and prevent modification
private Function<String, TopicConfig> getConfigFunc;

public ConsumeQueueStore(DefaultMessageStore messageStore, MessageStoreConfig messageStoreConfig) {
this.messageStore = messageStore;
this.messageStoreConfig = messageStoreConfig;
this.consumeQueueTable = new ConcurrentHashMap<>(32);
}

public void setTopicConfigTable(ConcurrentMap<String, TopicConfig> topicConfigTable) {
this.topicConfigTable = topicConfigTable;
public void setTopicConfigFunction(Function<String, TopicConfig> getConfigFunc) {
this.getConfigFunc = getConfigFunc;;
}

private FileQueueLifeCycle getLifeCycle(String topic, int queueId) {
Expand Down Expand Up @@ -173,7 +173,7 @@ private ConsumeQueueInterface createConsumeQueueByType(CQType cqType, String top
}

private void queueTypeShouldBe(String topic, CQType cqTypeExpected) {
TopicConfig topicConfig = this.topicConfigTable == null ? null : this.topicConfigTable.get(topic);
TopicConfig topicConfig = this.getConfigFunc.apply(topic);

CQType cqTypeActual = QueueTypeUtils.getCQType(Optional.ofNullable(topicConfig));

Expand Down Expand Up @@ -542,11 +542,12 @@ public ConcurrentMap<String, TopicConfig> getTopicConfigs() {
}

public Optional<TopicConfig> getTopicConfig(String topic) {
if (this.topicConfigTable == null) {
TopicConfig config = this.getConfigFunc.apply(topic);
if (config == null) {
joeCarf marked this conversation as resolved.
Show resolved Hide resolved
return Optional.empty();
}

return Optional.ofNullable(this.topicConfigTable.get(topic));
return Optional.of(config);
}

public long getTotalSize() {
Expand Down