-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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 #7064] [RIP-66-1] Support KV(RocksDB) Storage for Metadata #7092
Merged
RongtongJin
merged 33 commits into
apache:develop
from
fujian-zfj:develop_rocksdb_metadata
Aug 4, 2023
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
09c0c8c
typo int readme[ecosystem]
fujian-zfj 89713ba
Merge branch 'apache:develop' into develop
fujian-zfj 8d0c4fc
Merge branch 'apache:develop' into develop
fujian-zfj 2c9e961
Merge branch 'apache:develop' into develop
fujian-zfj 93d6669
Merge branch 'apache:develop' into develop
fujian-zfj 2dd16d6
Merge branch 'apache:develop' into develop
fujian-zfj e02c7aa
Merge branch 'apache:develop' into develop
fujian-zfj cb8c7b0
Merge branch 'apache:develop' into develop
fujian-zfj 03f707f
Merge branch 'apache:develop' into develop
fujian-zfj 6ef608f
Merge branch 'apache:develop' into develop
fujian-zfj 818919f
Merge branch 'apache:develop' into develop
fujian-zfj b315381
Merge branch 'apache:develop' into develop
fujian-zfj 5d1b050
Merge branch 'apache:develop' into develop
fujian-zfj de2238b
Merge branch 'apache:develop' into develop
fujian-zfj d22756f
Merge branch 'apache:develop' into develop
fujian-zfj 83d8178
Merge branch 'apache:develop' into develop
fujian-zfj a4c94a9
Merge branch 'apache:develop' into develop
fujian-zfj 7234a41
Merge branch 'apache:develop' into develop
fujian-zfj c7708a7
Merge branch 'apache:develop' into develop
fujian-zfj 166ebbd
Merge branch 'apache:develop' into develop
fujian-zfj 6b27cc7
Merge branch 'apache:develop' into develop
fujian-zfj 3b0a27b
Merge branch 'apache:develop' into develop
fujian-zfj 80e259e
rocksdb metadata
fujian-zfj 11a0c32
add unit test
fujian-zfj 18b909b
fix testOffsetPersistInMemory
fujian-zfj 2fa8485
fix unit test
fujian-zfj 2de0cca
fix unit test
fujian-zfj 0cc5cff
remove unused import
fujian-zfj 03d9988
move RocksDBOffsetSerialize to broker moudle
fujian-zfj 1a99cc8
Fix bazel build scripts
lizhanhui e0aae35
Flag QueryMsgByKeyIT as flaky as it fails at frequency: 5 out of 32
lizhanhui 7e4a409
change public to private of some inner method
fujian-zfj 26eec8f
Merge branch 'develop_rocksdb_metadata' of github.com:fujian-zfj/rock…
fujian-zfj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
102 changes: 102 additions & 0 deletions
102
broker/src/main/java/org/apache/rocketmq/broker/offset/RocksDBConsumerOffsetManager.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,102 @@ | ||
/* | ||
* 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.io.File; | ||
import java.util.Iterator; | ||
import java.util.Map.Entry; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
import org.apache.rocketmq.broker.BrokerController; | ||
import org.apache.rocketmq.common.config.RocksDBConfigManager; | ||
import org.apache.rocketmq.common.utils.DataConverter; | ||
import org.rocksdb.WriteBatch; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.serializer.SerializerFeature; | ||
|
||
public class RocksDBConsumerOffsetManager extends ConsumerOffsetManager { | ||
|
||
public RocksDBConsumerOffsetManager(BrokerController brokerController) { | ||
super(brokerController); | ||
this.rocksDBConfigManager = new RocksDBConfigManager(this.brokerController.getMessageStoreConfig().getMemTableFlushInterval()); | ||
} | ||
|
||
@Override | ||
public boolean load() { | ||
return this.rocksDBConfigManager.load(configFilePath(), this::decode0); | ||
} | ||
|
||
@Override | ||
public boolean stop() { | ||
return this.rocksDBConfigManager.stop(); | ||
} | ||
|
||
@Override | ||
protected void removeConsumerOffset(String topicAtGroup) { | ||
try { | ||
byte[] keyBytes = topicAtGroup.getBytes(DataConverter.charset); | ||
this.rocksDBConfigManager.delete(keyBytes); | ||
} catch (Exception e) { | ||
LOG.error("kv remove consumerOffset Failed, {}", topicAtGroup); | ||
} | ||
} | ||
|
||
@Override | ||
protected void decode0(final byte[] key, final byte[] body) { | ||
String topicAtGroup = new String(key, DataConverter.charset); | ||
RocksDBOffsetSerializeWrapper wrapper = JSON.parseObject(body, RocksDBOffsetSerializeWrapper.class); | ||
|
||
this.offsetTable.put(topicAtGroup, wrapper.getOffsetTable()); | ||
LOG.info("load exist local offset, {}, {}", topicAtGroup, wrapper.getOffsetTable()); | ||
} | ||
|
||
@Override | ||
public String configFilePath() { | ||
return this.brokerController.getMessageStoreConfig().getStorePathRootDir() + File.separator + "config" + File.separator + "consumerOffsets" + File.separator; | ||
} | ||
|
||
@Override | ||
public synchronized void persist() { | ||
WriteBatch writeBatch = new WriteBatch(); | ||
try { | ||
Iterator<Entry<String, ConcurrentMap<Integer, Long>>> iterator = this.offsetTable.entrySet().iterator(); | ||
while (iterator.hasNext()) { | ||
Entry<String, ConcurrentMap<Integer, Long>> entry = iterator.next(); | ||
putWriteBatch(writeBatch, entry.getKey(), entry.getValue()); | ||
|
||
if (writeBatch.getDataSize() >= 4 * 1024) { | ||
this.rocksDBConfigManager.batchPutWithWal(writeBatch); | ||
} | ||
} | ||
this.rocksDBConfigManager.batchPutWithWal(writeBatch); | ||
this.rocksDBConfigManager.flushWAL(); | ||
} catch (Exception e) { | ||
LOG.error("consumer offset persist Failed", e); | ||
} finally { | ||
writeBatch.close(); | ||
} | ||
} | ||
|
||
private void putWriteBatch(final WriteBatch writeBatch, final String topicGroupName, final ConcurrentMap<Integer, Long> offsetMap) throws Exception { | ||
byte[] keyBytes = topicGroupName.getBytes(DataConverter.charset); | ||
RocksDBOffsetSerializeWrapper wrapper = new RocksDBOffsetSerializeWrapper(); | ||
wrapper.setOffsetTable(offsetMap); | ||
byte[] valueBytes = JSON.toJSONBytes(wrapper, SerializerFeature.BrowserCompatible); | ||
writeBatch.put(keyBytes, valueBytes); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When was the method called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This interface is mainly to let RocksDBConsumeOffsetManager to override and delete the data in rocksdb, you can see the overridden method in RocksDBConsumeOffsetManager.