Skip to content

Commit

Permalink
feat(arm): limit arm only support RocksDB
Browse files Browse the repository at this point in the history
  • Loading branch information
halibobo1205 committed Oct 31, 2024
1 parent 1ed1162 commit cfb07a0
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
101 changes: 101 additions & 0 deletions common/src/main/java/org/tron/common/arch/Arch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package org.tron.common.arch;

public class Arch {

private final StringBuilder info = new StringBuilder();

public static Arch builder() {
return new Arch();
}

public String build() {
return info.toString();
}

public Arch withOsName() {
info.append("os.name").append(": ").append(getOsName()).append("\n");
return this;
}

public Arch withOsArch() {
info.append("os.arch").append(": ").append(getOsArch()).append("\n");
return this;
}

public Arch withBitModel() {
info.append("bit.model").append(": ").append(getBitModel()).append("\n");
return this;
}

public Arch withJavaVersion() {
info.append("java.version").append(": ").append(javaVersion()).append("\n");
return this;
}

public Arch withJavaSpecificationVersion() {
info.append("java.specification.version").append(": ").append(javaSpecificationVersion())
.append("\n");
return this;
}

public Arch withJavaVendor() {
info.append("java.vendor").append(": ").append(javaVendor()).append("\n");
return this;
}

public static Arch withAll() {
return Arch.builder()
.withOsName()
.withOsArch()
.withBitModel()
.withJavaVersion()
.withJavaSpecificationVersion()
.withJavaVendor();
}

public static String getOsName() {
return System.getProperty("os.name").toLowerCase().trim();

}
public static String getOsArch() {
return System.getProperty("os.arch").toLowerCase().trim();
}

public static int getBitModel() {
String prop = System.getProperty("sun.arch.data.model");
if (prop == null) {
prop = System.getProperty("com.ibm.vm.bitmode");
}
if (prop != null) {
return Integer.parseInt(prop);
}
// GraalVM support, see https://github.com/fusesource/jansi/issues/162
String arch = System.getProperty("os.arch");
if (arch.endsWith("64") && "Substrate VM".equals(System.getProperty("java.vm.name"))) {
return 64;
}
return -1; // we don't know...
}

public static String javaVersion() {
return System.getProperty("java.version").toLowerCase().trim();
}

public static String javaSpecificationVersion() {
return System.getProperty("java.specification.version").toLowerCase().trim();
}

public static String javaVendor() {
return System.getProperty("java.vendor").toLowerCase().trim();
}

public static boolean isArm64() {
String osArch = getOsArch();
return osArch.contains("arm64") || osArch.contains("aarch64");
}

@Override
public String toString() {
return info.toString();
}
}
8 changes: 8 additions & 0 deletions common/src/main/java/org/tron/core/config/args/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.iq80.leveldb.CompressionType;
import org.iq80.leveldb.Options;
import org.tron.common.arch.Arch;
import org.tron.common.cache.CacheStrategies;
import org.tron.common.cache.CacheType;
import org.tron.common.utils.DbOptionalsUtils;
Expand All @@ -42,6 +44,7 @@
* @version 1.0
* @since 2018/5/25
*/
@Slf4j(topic = "db")
public class Storage {

/**
Expand Down Expand Up @@ -87,6 +90,7 @@ public class Storage {
* Default values of directory
*/
private static final String DEFAULT_DB_ENGINE = "LEVELDB";
private static final String ROCKS_DB_ENGINE = "ROCKSDB";
private static final boolean DEFAULT_DB_SYNC = false;
private static final boolean DEFAULT_EVENT_SUBSCRIBE_CONTRACT_PARSE = true;
private static final String DEFAULT_DB_DIRECTORY = "database";
Expand Down Expand Up @@ -171,6 +175,10 @@ public class Storage {
private final Map<String, Sha256Hash> dbRoots = Maps.newConcurrentMap();

public static String getDbEngineFromConfig(final Config config) {
if (Arch.isArm64()) {
logger.info("Arm64 architecture detected, using RocksDB as db engine, ignore config.");
return ROCKS_DB_ENGINE;
}
return config.hasPath(DB_ENGINE_CONFIG_KEY)
? config.getString(DB_ENGINE_CONFIG_KEY) : DEFAULT_DB_ENGINE;
}
Expand Down
3 changes: 3 additions & 0 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.quartz.CronExpression;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.tron.common.arch.Arch;
import org.tron.common.args.Account;
import org.tron.common.args.GenesisBlock;
import org.tron.common.args.Witness;
Expand Down Expand Up @@ -1636,6 +1637,8 @@ private static void initBackupProperty(Config config) {
public static void logConfig() {
CommonParameter parameter = CommonParameter.getInstance();
logger.info("\n");
logger.info("************************ System info ************************");
logger.info("{}", Arch.withAll());
logger.info("************************ Net config ************************");
logger.info("P2P version: {}", parameter.getNodeP2pVersion());
logger.info("LAN IP: {}", parameter.getNodeLanIp());
Expand Down

0 comments on commit cfb07a0

Please sign in to comment.