Skip to content

Commit e87f9cb

Browse files
RongtongJinRongtongJin
andauthored
[ISSUE #9875] Optimize the RocksDB config shutdown logic when useSingleRocksDBForAllConfigs is set to true to prevent JVM crashes. (#9874)
* Optimize the RocksDB config shutdown logic when useSingleRocksDBForAllConfigs is set to true to prevent JVM crashes. Change-Id: I309e8d13b6adc46d68146c05ffd7e026e2852ad8 * Fix bug Change-Id: Ie577e32f65a3902dd60d654f80a8e7eda5790fbf --------- Co-authored-by: RongtongJin <[email protected]>
1 parent e984023 commit e87f9cb

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

broker/src/main/java/org/apache/rocketmq/broker/config/v1/RocksDBConfigManager.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public class RocksDBConfigManager {
3838

3939
public static final Charset CHARSET = StandardCharsets.UTF_8;
4040

41-
public volatile boolean isStop = false;
4241
public ConfigRocksDBStorage configRocksDBStorage = null;
4342
private FlushOptions flushOptions = null;
4443
private volatile long lastFlushMemTableMicroSecond = 0;
@@ -72,11 +71,14 @@ public RocksDBConfigManager(String filePath, long memTableFlushInterval, Compres
7271
}
7372

7473
public boolean init(boolean readOnly) {
75-
this.isStop = false;
7674
this.configRocksDBStorage = ConfigRocksDBStorage.getStore(filePath, readOnly, compressionType);
7775
return this.configRocksDBStorage.start();
7876
}
7977

78+
public boolean isLoaded() {
79+
return this.configRocksDBStorage != null && this.configRocksDBStorage.isLoaded();
80+
}
81+
8082
public boolean init() {
8183
return this.init(false);
8284
}
@@ -113,7 +115,6 @@ public void start() {
113115
}
114116

115117
public boolean stop() {
116-
this.isStop = true;
117118
ConfigRocksDBStorage.shutdown(filePath);
118119
if (this.flushOptions != null) {
119120
this.flushOptions.close();
@@ -123,7 +124,7 @@ public boolean stop() {
123124

124125
public void flushWAL() {
125126
try {
126-
if (this.isStop) {
127+
if (!isLoaded()) {
127128
return;
128129
}
129130
if (this.configRocksDBStorage != null) {
@@ -183,4 +184,5 @@ public Statistics getStatistics() {
183184

184185
return configRocksDBStorage.getStatistics();
185186
}
187+
186188
}

broker/src/main/java/org/apache/rocketmq/broker/config/v1/RocksDBConsumerOffsetManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public String configFilePath() {
157157

158158
@Override
159159
public synchronized void persist() {
160-
if (!rocksDBConfigManager.isStop) {
160+
if (rocksDBConfigManager.isLoaded()) {
161161
try (WriteBatch writeBatch = new WriteBatch()) {
162162
for (Entry<String, ConcurrentMap<Integer, Long>> entry : this.offsetTable.entrySet()) {
163163
putWriteBatch(writeBatch, entry.getKey(), entry.getValue());

common/src/main/java/org/apache/rocketmq/common/config/AbstractRocksDBStorage.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,10 @@ public synchronized boolean start() {
481481
*/
482482
protected abstract void preShutdown();
483483

484+
public boolean isLoaded() {
485+
return loaded;
486+
}
487+
484488
public synchronized boolean shutdown() {
485489
try {
486490
if (!this.loaded) {

0 commit comments

Comments
 (0)