forked from apache/rocketmq
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RIP-28] light message queue(LMQ) (apache#3694)
- Loading branch information
1 parent
fd39f7a
commit 6f1805c
Showing
34 changed files
with
2,466 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
broker/src/main/java/org/apache/rocketmq/broker/longpolling/LmqPullRequestHoldService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.rocketmq.broker.longpolling; | ||
|
||
import org.apache.rocketmq.broker.BrokerController; | ||
import org.apache.rocketmq.common.MixAll; | ||
import org.apache.rocketmq.common.constant.LoggerName; | ||
import org.apache.rocketmq.logging.InternalLogger; | ||
import org.apache.rocketmq.logging.InternalLoggerFactory; | ||
|
||
|
||
public class LmqPullRequestHoldService extends PullRequestHoldService { | ||
private static final InternalLogger LOGGER = InternalLoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); | ||
|
||
public LmqPullRequestHoldService(BrokerController brokerController) { | ||
super(brokerController); | ||
} | ||
|
||
@Override | ||
public String getServiceName() { | ||
return LmqPullRequestHoldService.class.getSimpleName(); | ||
} | ||
|
||
@Override | ||
public void checkHoldRequest() { | ||
for (String key : pullRequestTable.keySet()) { | ||
int idx = key.lastIndexOf(TOPIC_QUEUEID_SEPARATOR); | ||
if (idx <= 0 || idx >= key.length() - 1) { | ||
pullRequestTable.remove(key); | ||
continue; | ||
} | ||
String topic = key.substring(0, idx); | ||
int queueId = Integer.parseInt(key.substring(idx + 1)); | ||
final long offset = brokerController.getMessageStore().getMaxOffsetInQueue(topic, queueId); | ||
try { | ||
this.notifyMessageArriving(topic, queueId, offset); | ||
} catch (Throwable e) { | ||
LOGGER.error("check hold request failed. topic={}, queueId={}", topic, queueId, e); | ||
} | ||
if (MixAll.isLmq(topic)) { | ||
ManyPullRequest mpr = pullRequestTable.get(key); | ||
if (mpr == null || mpr.getPullRequestList() == null || mpr.getPullRequestList().isEmpty()) { | ||
pullRequestTable.remove(key); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
broker/src/main/java/org/apache/rocketmq/broker/offset/LmqConsumerOffsetManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.rocketmq.broker.offset; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import org.apache.rocketmq.broker.BrokerController; | ||
import org.apache.rocketmq.broker.BrokerPathConfigHelper; | ||
import org.apache.rocketmq.common.MixAll; | ||
import org.apache.rocketmq.remoting.protocol.RemotingSerializable; | ||
|
||
public class LmqConsumerOffsetManager extends ConsumerOffsetManager { | ||
private ConcurrentHashMap<String, Long> lmqOffsetTable = new ConcurrentHashMap<>(512); | ||
|
||
public LmqConsumerOffsetManager(BrokerController brokerController) { | ||
super(brokerController); | ||
} | ||
|
||
@Override | ||
public long queryOffset(final String group, final String topic, final int queueId) { | ||
if (!MixAll.isLmq(group)) { | ||
return super.queryOffset(group, topic, queueId); | ||
} | ||
// topic@group | ||
String key = topic + TOPIC_GROUP_SEPARATOR + group; | ||
Long offset = lmqOffsetTable.get(key); | ||
if (offset != null) { | ||
return offset; | ||
} | ||
return -1; | ||
} | ||
|
||
@Override | ||
public Map<Integer, Long> queryOffset(final String group, final String topic) { | ||
if (!MixAll.isLmq(group)) { | ||
return super.queryOffset(group, topic); | ||
} | ||
Map<Integer, Long> map = new HashMap<>(); | ||
// topic@group | ||
String key = topic + TOPIC_GROUP_SEPARATOR + group; | ||
Long offset = lmqOffsetTable.get(key); | ||
if (offset != null) { | ||
map.put(0, offset); | ||
} | ||
return map; | ||
} | ||
|
||
@Override | ||
public void commitOffset(final String clientHost, final String group, final String topic, final int queueId, | ||
final long offset) { | ||
if (!MixAll.isLmq(group)) { | ||
super.commitOffset(clientHost, group, topic, queueId, offset); | ||
return; | ||
} | ||
// topic@group | ||
String key = topic + TOPIC_GROUP_SEPARATOR + group; | ||
lmqOffsetTable.put(key, offset); | ||
} | ||
|
||
@Override | ||
public String encode() { | ||
return this.encode(false); | ||
} | ||
|
||
@Override | ||
public String configFilePath() { | ||
return BrokerPathConfigHelper.getLmqConsumerOffsetPath(brokerController.getMessageStoreConfig().getStorePathRootDir()); | ||
} | ||
|
||
@Override | ||
public void decode(String jsonString) { | ||
if (jsonString != null) { | ||
LmqConsumerOffsetManager obj = RemotingSerializable.fromJson(jsonString, LmqConsumerOffsetManager.class); | ||
if (obj != null) { | ||
super.offsetTable = obj.offsetTable; | ||
this.lmqOffsetTable = obj.lmqOffsetTable; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String encode(final boolean prettyFormat) { | ||
return RemotingSerializable.toJson(this, prettyFormat); | ||
} | ||
|
||
public ConcurrentHashMap<String, Long> getLmqOffsetTable() { | ||
return lmqOffsetTable; | ||
} | ||
|
||
public void setLmqOffsetTable(ConcurrentHashMap<String, Long> lmqOffsetTable) { | ||
this.lmqOffsetTable = lmqOffsetTable; | ||
} | ||
} |
Oops, something went wrong.