Skip to content

Commit a75c2dc

Browse files
committed
feat(db): optimize RocksDB configuration for CI environments to reduce filesystem operations and stabilize disk usage
1 parent 98a54d1 commit a75c2dc

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ subprojects {
9898
reproducibleFileOrder = true
9999
duplicatesStrategy = DuplicatesStrategy.INCLUDE // allow duplicates
100100
}
101+
tasks.withType(Test).configureEach {
102+
// https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:environment
103+
environment 'CI', 'true'
104+
}
101105
}
102106

103107
task copyToParent(type: Copy) {

common/src/main/java/org/tron/common/setting/RocksDbSettings.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.tron.common.setting;
22

3+
import java.util.Arrays;
34
import lombok.Getter;
45
import lombok.extern.slf4j.Slf4j;
56
import org.rocksdb.BlockBasedTableConfig;
@@ -44,6 +45,15 @@ public class RocksDbSettings {
4445

4546
private static final LRUCache cache = new LRUCache(1 * 1024 * 1024 * 1024L);
4647

48+
private static final String[] CI_ENVIRONMENT_VARIABLES = {
49+
"CI",
50+
"JENKINS_URL",
51+
"TRAVIS",
52+
"CIRCLECI",
53+
"GITHUB_ACTIONS",
54+
"GITLAB_CI"
55+
};
56+
4757
private RocksDbSettings() {
4858

4959
}
@@ -185,6 +195,23 @@ public static Options getOptionsByDbName(String dbName) {
185195
options.setComparator(new MarketOrderPriceComparatorForRocksDB(comparatorOptions));
186196
}
187197

198+
if (isRunningInCI()) {
199+
// Disable fallocate calls to avoid issues with disk space
200+
options.setAllowFAllocate(false);
201+
// Set WAL size limits to avoid excessive disk
202+
options.setMaxTotalWalSize(2 * 1024 * 1024);
203+
// Set recycle log file
204+
options.setRecycleLogFileNum(1);
205+
// Enable creation of missing column families
206+
options.setCreateMissingColumnFamilies(true);
207+
// Set max background flushes to 1 to reduce resource usage
208+
options.setMaxBackgroundFlushes(1);
209+
}
210+
188211
return options;
189212
}
213+
214+
private static boolean isRunningInCI() {
215+
return Arrays.stream(CI_ENVIRONMENT_VARIABLES).anyMatch(System.getenv()::containsKey);
216+
}
190217
}

0 commit comments

Comments
 (0)