Skip to content

Commit

Permalink
support storing Retained messages of single tenant cross multiple ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
popduke committed Sep 20, 2024
1 parent 0a92a32 commit dcb8f6e
Show file tree
Hide file tree
Showing 57 changed files with 1,215 additions and 708 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

package com.baidu.bifromq.dist.entity;

import static com.baidu.bifromq.dist.util.TopicUtil.escape;
import static com.baidu.bifromq.dist.util.TopicUtil.isNormalTopicFilter;
import static com.baidu.bifromq.dist.util.TopicUtil.unescape;
import static com.baidu.bifromq.util.TopicUtil.escape;
import static com.baidu.bifromq.util.TopicUtil.unescape;
import static com.baidu.bifromq.util.TopicConst.DELIMITER_CHAR;
import static com.baidu.bifromq.util.TopicConst.NUL;
import static com.baidu.bifromq.util.TopicConst.NUL_CHAR;
import static com.baidu.bifromq.util.TopicConst.ORDERED_SHARE;
import static com.baidu.bifromq.util.TopicConst.UNORDERED_SHARE;
import static com.baidu.bifromq.util.TopicUtil.isNormalTopicFilter;
import static com.google.protobuf.ByteString.copyFromUtf8;

import com.baidu.bifromq.dist.rpc.proto.GroupMatchRecord;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static com.baidu.bifromq.util.TopicConst.DELIMITER_CHAR;
import static com.baidu.bifromq.util.TopicConst.ORDERED_SHARE;
import static com.baidu.bifromq.util.TopicConst.UNORDERED_SHARE;
import static com.baidu.bifromq.dist.util.TopicUtil.unescape;
import static com.baidu.bifromq.util.TopicUtil.unescape;

import com.google.common.collect.Sets;
import com.google.protobuf.ByteString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package com.baidu.bifromq.dist.entity;


import static com.baidu.bifromq.dist.util.TopicUtil.unescape;
import static com.baidu.bifromq.util.TopicUtil.unescape;
import static com.baidu.bifromq.util.TopicConst.NUL;

import com.baidu.bifromq.type.MatchInfo;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

package com.baidu.bifromq.dist;

import static com.baidu.bifromq.dist.util.TopicUtil.fastJoin;
import static com.baidu.bifromq.dist.util.TopicUtil.parse;
import static com.baidu.bifromq.util.TopicUtil.fastJoin;
import static com.baidu.bifromq.util.TopicUtil.parse;
import static com.baidu.bifromq.util.TopicConst.DELIMITER;
import static com.baidu.bifromq.util.TopicConst.MULTI_WILDCARD;
import static com.baidu.bifromq.util.TopicConst.NUL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static com.baidu.bifromq.util.TopicConst.SINGLE_WILDCARD;
import static com.baidu.bifromq.util.TopicConst.SYS_PREFIX;

import com.baidu.bifromq.dist.util.TopicUtil;
import com.baidu.bifromq.util.TopicUtil;
import java.util.List;
import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package com.baidu.bifromq.dist;

import static com.baidu.bifromq.dist.util.TopicUtil.escape;
import static com.baidu.bifromq.util.TopicUtil.escape;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import static com.baidu.bifromq.dist.entity.EntityUtil.parseTopicFilter;
import static com.baidu.bifromq.dist.entity.EntityUtil.toMatchRecordKey;
import static com.baidu.bifromq.dist.entity.EntityUtil.toQInboxId;
import static com.baidu.bifromq.dist.util.TopicUtil.escape;
import static com.baidu.bifromq.util.TopicUtil.escape;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@

import static com.baidu.bifromq.dist.TestUtil.randomTopic;
import static com.baidu.bifromq.dist.TestUtil.randomTopicFilter;
import static com.baidu.bifromq.dist.util.TopicUtil.escape;
import static com.baidu.bifromq.dist.util.TopicUtil.fastJoin;
import static com.baidu.bifromq.dist.util.TopicUtil.parse;
import static com.baidu.bifromq.util.TopicUtil.escape;
import static com.baidu.bifromq.util.TopicUtil.fastJoin;
import static com.baidu.bifromq.util.TopicUtil.parse;
import static com.baidu.bifromq.util.TopicConst.NUL;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

import com.baidu.bifromq.dist.TestUtil;
import com.baidu.bifromq.dist.util.TopicUtil;
import com.baidu.bifromq.util.TopicUtil;
import com.baidu.bifromq.util.TopicConst;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import com.baidu.bifromq.dist.trie.TopicTrieNode;
import com.baidu.bifromq.dist.TestUtil;
import com.baidu.bifromq.dist.util.TopicUtil;
import com.baidu.bifromq.util.TopicUtil;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.openjdk.jmh.annotations.Level;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import com.baidu.bifromq.dist.rpc.proto.DistServiceROCoProcInput;
import com.baidu.bifromq.dist.trie.TopicFilterIterator;
import com.baidu.bifromq.dist.trie.TopicTrieNode;
import com.baidu.bifromq.dist.util.TopicUtil;
import com.baidu.bifromq.util.TopicUtil;
import com.baidu.bifromq.plugin.settingprovider.ISettingProvider;
import com.baidu.bifromq.plugin.settingprovider.Setting;
import com.baidu.bifromq.sysprops.props.DataPlaneBurstLatencyMillis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package com.baidu.bifromq.dist.worker;

import static com.baidu.bifromq.dist.util.TopicUtil.escape;
import static com.baidu.bifromq.util.TopicUtil.escape;
import static com.baidu.bifromq.metrics.TenantMetric.MqttPersistentFanOutBytes;
import static com.baidu.bifromq.plugin.eventcollector.ThreadLocalEventPool.getLocal;
import static com.bifromq.plugin.resourcethrottler.TenantResourceType.TotalPersistentFanOutBytesPerSeconds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import static com.baidu.bifromq.dist.entity.EntityUtil.toGroupMatchRecordKey;
import static com.baidu.bifromq.dist.entity.EntityUtil.toNormalMatchRecordKey;
import static com.baidu.bifromq.dist.entity.EntityUtil.toScopedTopicFilter;
import static com.baidu.bifromq.dist.util.TopicUtil.isNormalTopicFilter;
import static com.baidu.bifromq.util.TopicUtil.isNormalTopicFilter;
import static java.util.Collections.singletonMap;

import com.baidu.bifromq.basekv.proto.Boundary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
* See the License for the specific language governing permissions and limitations under the License.
*/

package com.baidu.bifromq.dist.worker.index;
package com.baidu.bifromq.dist.worker;

import static com.baidu.bifromq.util.TopicConst.MULTI_WILDCARD;
import static com.baidu.bifromq.util.TopicConst.SINGLE_WILDCARD;
import static com.baidu.bifromq.util.TopicConst.SYS_PREFIX;

import com.baidu.bifromq.dist.util.TopicUtil;
import com.baidu.bifromq.util.TopicUtil;
import com.baidu.bifromq.util.index.Branch;
import com.baidu.bifromq.util.index.TopicLevelTrie;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand All @@ -35,6 +37,8 @@ public <T> Map<Branch<T>, Action> selectBranch(Map<String, Branch<T>> branches,
if (currentLevel < topicLevels.size() - 1) {
// not last level
String topicLevelToMatch = topicLevels.get(currentLevel);
boolean matchParent = currentLevel + 1 == topicLevels.size() - 1
&& topicLevels.get(currentLevel + 1).equals(MULTI_WILDCARD);
switch (topicLevelToMatch) {
case SINGLE_WILDCARD -> {
Map<Branch<T>, Action> result = new HashMap<>();
Expand All @@ -44,30 +48,15 @@ public <T> Map<Branch<T>, Action> selectBranch(Map<String, Branch<T>> branches,
// + skip SYS topic
continue;
}
result.put(branch, Action.CONTINUE);
}
return result;
}
case MULTI_WILDCARD -> {
Map<Branch<T>, Action> result = new HashMap<>();
for (Map.Entry<String, Branch<T>> entry : branches.entrySet()) {
Branch<T> branch = entry.getValue();
if (currentLevel == 0 && entry.getKey().startsWith(SYS_PREFIX)) {
// # skip SYS topic
continue;
}
result.put(branch, Action.MATCH_AND_CONTINUE);
result.put(branch, matchParent ? Action.MATCH_AND_CONTINUE : Action.CONTINUE);
}
return result;
}
default -> {
assert !topicLevelToMatch.equals(MULTI_WILDCARD) : "MULTI_WILDCARD should be the last level";
if (branches.containsKey(topicLevelToMatch)) {
if (currentLevel + 1 < topicLevels.size()
&& topicLevels.get(currentLevel + 1).equals(MULTI_WILDCARD)) {
// # match parent level
return Map.of(branches.get(topicLevelToMatch), Action.MATCH_AND_CONTINUE);
}
return Map.of(branches.get(topicLevelToMatch), Action.CONTINUE);
return Map.of(branches.get(topicLevelToMatch),
matchParent ? Action.MATCH_AND_CONTINUE : Action.CONTINUE);
}
return Collections.emptyMap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
import com.baidu.bifromq.basekv.proto.Boundary;
import com.baidu.bifromq.dist.entity.GroupMatching;
import com.baidu.bifromq.dist.entity.Matching;
import com.baidu.bifromq.dist.worker.index.TopicIndex;
import com.baidu.bifromq.metrics.ITenantMeter;
import com.baidu.bifromq.metrics.TenantMetric;
import com.baidu.bifromq.sysprops.props.DistMaxCachedRoutesPerTenant;
import com.baidu.bifromq.dist.worker.TopicIndex;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.Expiry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.baidu.bifromq.dist.entity.Matching;
import com.baidu.bifromq.dist.trie.TopicFilterIterator;
import com.baidu.bifromq.dist.trie.TopicTrieNode;
import com.baidu.bifromq.dist.util.TopicUtil;
import com.baidu.bifromq.util.TopicUtil;
import com.google.common.collect.Sets;
import com.google.protobuf.ByteString;
import io.micrometer.core.instrument.Timer;
Expand Down
Loading

0 comments on commit dcb8f6e

Please sign in to comment.