Skip to content
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

arch:support arm64 #27

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import java.util.stream.Collectors;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.rocksdb.AbstractComparator;
import org.rocksdb.BlockBasedTableConfig;
import org.rocksdb.BloomFilter;
import org.rocksdb.Checkpoint;
import org.rocksdb.DirectComparator;
import org.rocksdb.InfoLogLevel;
import org.rocksdb.Logger;
import org.rocksdb.Options;
Expand Down Expand Up @@ -60,11 +60,11 @@ public class RocksDbDataSourceImpl extends DbStat implements DbSourceInter<byte[
private ReadWriteLock resetDbLock = new ReentrantReadWriteLock();
private static final String KEY_ENGINE = "ENGINE";
private static final String ROCKSDB = "ROCKSDB";
private DirectComparator comparator;
private AbstractComparator comparator;
private static final org.slf4j.Logger rocksDbLogger = LoggerFactory.getLogger(ROCKSDB);

public RocksDbDataSourceImpl(String parentPath, String name, RocksDbSettings settings,
DirectComparator comparator) {
AbstractComparator comparator) {
this.dataBaseName = name;
this.parentPath = parentPath;
this.comparator = comparator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.tron.common.utils;

import org.rocksdb.AbstractComparator;
import org.rocksdb.ComparatorOptions;
import org.rocksdb.DirectSlice;
import org.rocksdb.util.DirectBytewiseComparator;
import org.tron.core.capsule.utils.MarketUtils;

public class MarketOrderPriceComparatorForRockDB extends DirectBytewiseComparator {
import java.nio.ByteBuffer;

public class MarketOrderPriceComparatorForRockDB extends AbstractComparator {

public MarketOrderPriceComparatorForRockDB(final ComparatorOptions copt) {
super(copt);
Expand All @@ -17,21 +19,16 @@ public String name() {
}

@Override
public int compare(final DirectSlice a, final DirectSlice b) {
public int compare(final ByteBuffer a, final ByteBuffer b) {
return MarketUtils.comparePriceKey(convertDataToBytes(a), convertDataToBytes(b));
}

/**
* DirectSlice.data().array will throw UnsupportedOperationException.
* */
public byte[] convertDataToBytes(DirectSlice directSlice) {
int capacity = directSlice.data().capacity();
byte[] bytes = new byte[capacity];

for (int i = 0; i < capacity; i++) {
bytes[i] = directSlice.get(i);
}

public byte[] convertDataToBytes(ByteBuffer buf) {
byte[] bytes = new byte[buf.remaining()];
buf.get(bytes);
return bytes;
}

Expand Down
4 changes: 2 additions & 2 deletions chainbase/src/main/java/org/tron/core/db/TronDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.iq80.leveldb.WriteOptions;
import org.rocksdb.DirectComparator;
import org.rocksdb.AbstractComparator;
import org.springframework.beans.factory.annotation.Autowired;
import org.tron.common.parameter.CommonParameter;
import org.tron.common.storage.WriteOptionsWrapper;
Expand Down Expand Up @@ -70,7 +70,7 @@ protected org.iq80.leveldb.Options getOptionsByDbNameForLevelDB(String dbName) {
return StorageUtils.getOptionsByDbName(dbName);
}

protected DirectComparator getDirectComparator() {
protected AbstractComparator getDirectComparator() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.iq80.leveldb.WriteOptions;
import org.rocksdb.DirectComparator;
import org.rocksdb.AbstractComparator;
import org.springframework.beans.factory.annotation.Autowired;
import org.tron.common.parameter.CommonParameter;
import org.tron.common.storage.leveldb.LevelDbDataSourceImpl;
Expand Down Expand Up @@ -81,7 +81,7 @@ protected org.iq80.leveldb.Options getOptionsByDbNameForLevelDB(String dbName) {
return StorageUtils.getOptionsByDbName(dbName);
}

protected DirectComparator getDirectComparator() {
protected AbstractComparator getDirectComparator() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.util.Collections;
import java.util.List;
import org.iq80.leveldb.Options;
import org.rocksdb.AbstractComparator;
import org.rocksdb.ComparatorOptions;
import org.rocksdb.DirectComparator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -35,7 +35,7 @@ protected Options getOptionsByDbNameForLevelDB(String dbName) {

//todo: to test later
@Override
protected DirectComparator getDirectComparator() {
protected AbstractComparator getDirectComparator() {
ComparatorOptions comparatorOptions = new ComparatorOptions();
return new MarketOrderPriceComparatorForRockDB(comparatorOptions);
}
Expand Down
6 changes: 3 additions & 3 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ if (isWindows()) {
}
} else {
ext {
leveldbGroup = "org.fusesource.leveldbjni"
leveldbGroup = "io.github.tronprotocol"
leveldbName = "leveldbjni-all"
leveldbVersion = "1.8"
leveldbVersion = "1.18.3"
}
}

Expand All @@ -37,7 +37,7 @@ dependencies {
compile group: 'com.beust', name: 'jcommander', version: '1.72'
compile group: 'com.typesafe', name: 'config', version: '1.3.2'
compile group: leveldbGroup, name: leveldbName, version: leveldbVersion
compile group: 'org.rocksdb', name: 'rocksdbjni', version: '5.15.10'
compile group: 'org.rocksdb', name: 'rocksdbjni', version: '7.7.3'
// https://mvnrepository.com/artifact/org.quartz-scheduler/quartz
compile group: 'org.quartz-scheduler', name: 'quartz', version: '2.3.2'
compile group: 'io.prometheus', name: 'simpleclient', version: '0.15.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,87 +4,139 @@
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.tron.common.backup.BackupManager.BackupStatusEnum;
import org.tron.common.backup.message.KeepAliveMessage;
import org.tron.common.backup.socket.BackupServer;
import org.tron.common.backup.socket.UdpEvent;
import org.tron.common.parameter.CommonParameter;
import org.tron.common.utils.PublicMethod;
import org.tron.core.Constant;
import org.tron.core.config.args.Args;

public class BackupManagerTest {

@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
private BackupManager manager;
private BackupServer backupServer;

@Before
public void setUp() throws Exception {
Args.setParam(new String[] {"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF);
CommonParameter.getInstance().setBackupPort(PublicMethod.chooseRandomPort());
manager = new BackupManager();
backupServer = new BackupServer(manager);
}

@After
public void tearDown() {
Args.clearParam();
}

@Test
public void test() throws Exception {
String[] a = new String[0];
Args.setParam(a, Constant.TESTNET_CONF);
CommonParameter parameter = CommonParameter.getInstance();
parameter.setBackupPriority(8);
CommonParameter.getInstance().setBackupPriority(8);
List<String> members = new ArrayList<>();
members.add("127.0.0.2");
parameter.setBackupMembers(members);
CommonParameter.getInstance().setBackupMembers(members);

BackupManager manager = new BackupManager();

Field field = manager.getClass().getDeclaredField("localIp");
Field field = manager.getClass().getDeclaredField("localIp");
field.setAccessible(true);
field.set(manager, "127.0.0.1");

Assert.assertEquals(manager.getStatus(), BackupManager.BackupStatusEnum.MASTER);
Assert.assertEquals(BackupManager.BackupStatusEnum.MASTER, manager.getStatus());

field = manager.getClass().getDeclaredField("executorService");
field = manager.getClass().getDeclaredField("executorService");
field.setAccessible(true);
ScheduledExecutorService executorService = (ScheduledExecutorService) field.get(manager);
manager.init();
executorService.shutdown();
Assert.assertEquals(manager.getStatus(), BackupManager.BackupStatusEnum.INIT);
Assert.assertEquals(BackupManager.BackupStatusEnum.INIT, manager.getStatus());

/* ip not in the members */
manager.setStatus(BackupManager.BackupStatusEnum.INIT);
KeepAliveMessage message = new KeepAliveMessage(false, 6);
InetSocketAddress address = new InetSocketAddress("127.0.0.3", 1000);
UdpEvent event = new UdpEvent(message, address);
manager.handleEvent(event);
Assert.assertEquals(manager.getStatus(), BackupManager.BackupStatusEnum.INIT);
Assert.assertEquals(BackupManager.BackupStatusEnum.INIT, manager.getStatus());

/* ip not the member */
address = new InetSocketAddress("127.0.0.3", 1000);
message = new KeepAliveMessage(false, 6);
event = new UdpEvent(message, address);
manager.handleEvent(event);
Assert.assertEquals(manager.getStatus(), BackupManager.BackupStatusEnum.INIT);
Assert.assertEquals(BackupManager.BackupStatusEnum.INIT, manager.getStatus());

/* keepAliveMessage.getFlag() || peerPriority > priority */
address = new InetSocketAddress("127.0.0.2", 1000);
message = new KeepAliveMessage(false, 6);
event = new UdpEvent(message, address);
manager.handleEvent(event);
Assert.assertEquals(manager.getStatus(), BackupManager.BackupStatusEnum.INIT);
Assert.assertEquals(BackupStatusEnum.SLAVER, manager.getStatus());

/* keepAliveMessage.getFlag() || peerPriority > priority */
message = new KeepAliveMessage(false, 10);
event = new UdpEvent(message, address);
manager.handleEvent(event);
Assert.assertEquals(manager.getStatus(), BackupManager.BackupStatusEnum.SLAVER);
Assert.assertEquals(BackupManager.BackupStatusEnum.SLAVER, manager.getStatus());

/* keepAliveMessage.getFlag() || peerPriority > priority */
manager.setStatus(BackupManager.BackupStatusEnum.INIT);
message = new KeepAliveMessage(true, 6);
event = new UdpEvent(message, address);
manager.handleEvent(event);
Assert.assertEquals(manager.getStatus(), BackupManager.BackupStatusEnum.SLAVER);
Assert.assertEquals(BackupManager.BackupStatusEnum.SLAVER, manager.getStatus());

manager.setStatus(BackupManager.BackupStatusEnum.MASTER);
message = new KeepAliveMessage(false, 10);
event = new UdpEvent(message, address);
manager.handleEvent(event);
Assert.assertEquals(manager.getStatus(), BackupManager.BackupStatusEnum.MASTER);
Assert.assertEquals(BackupManager.BackupStatusEnum.MASTER, manager.getStatus());

message = new KeepAliveMessage(true, 10);
event = new UdpEvent(message, address);
manager.handleEvent(event);
Assert.assertEquals(manager.getStatus(), BackupManager.BackupStatusEnum.SLAVER);
Assert.assertEquals(BackupManager.BackupStatusEnum.SLAVER, manager.getStatus());

}

@Test
public void testSendKeepAliveMessage() throws Exception {
CommonParameter parameter = CommonParameter.getInstance();
parameter.setBackupPriority(8);
List<String> members = new ArrayList<>();
members.add("127.0.0.2");
parameter.setBackupMembers(members);

Field field = manager.getClass().getDeclaredField("localIp");
field.setAccessible(true);
field.set(manager, "127.0.0.1");

Assert.assertEquals(manager.getStatus(), BackupManager.BackupStatusEnum.MASTER);
backupServer.initServer();
manager.init();

Thread.sleep(parameter.getKeepAliveInterval() + 1000);//test send KeepAliveMessage

field = manager.getClass().getDeclaredField("executorService");
field.setAccessible(true);
ScheduledExecutorService executorService = (ScheduledExecutorService) field.get(manager);
executorService.shutdown();

Field field2 = backupServer.getClass().getDeclaredField("executor");
field2.setAccessible(true);
ExecutorService executorService2 = (ExecutorService) field2.get(backupServer);
executorService2.shutdown();

Assert.assertEquals(BackupManager.BackupStatusEnum.INIT, manager.getStatus());
}
}
8 changes: 8 additions & 0 deletions framework/src/test/java/org/tron/core/tire/TrieTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.bouncycastle.util.Arrays;
import org.junit.Assert;
import org.junit.Test;
import org.tron.core.capsule.utils.FastByteComparisons;
import org.tron.core.capsule.utils.RLP;
import org.tron.core.trie.TrieImpl;
import org.tron.core.trie.TrieImpl.Node;
Expand Down Expand Up @@ -151,4 +152,11 @@ private void assertFalse(byte[] key1, byte[] key2, TrieImpl trieCopy) {
Assert.assertFalse(trieCopy.verifyProof(trieCopy.getRootHash(), key2, trieCopy.prove(key1)));
}

@Test
public void testFastByteComparisons() {
byte[] test1 = new byte[] {0x00, 0x00, 0x01, 0x02, 0x03, 0x04};
byte[] test2 = new byte[] {0x00, 0x01, 0x02, 0x03, 0x04};
Assert.assertEquals(0, FastByteComparisons.compareTo(test1, 1, 5, test2, 0, 5));
}

}
4 changes: 1 addition & 3 deletions plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ DB convert provides a helper which can convert LevelDB data to RocksDB data, par

- `<src>`: Input path for leveldb, default: output-directory/database.
- `<dest>`: Output path for rocksdb, default: output-directory-dst/database.
- `--safe`: In safe mode, read data from leveldb then put into rocksdb, it's a very time-consuming procedure. If not, just change engine.properties from leveldb to rocksdb, rocksdb
is compatible with leveldb for the current version. This may not be the case in the future, default: false.
- `-h | --help`: Provide the help info.

### Examples:

```shell script
# full command
java -jar Toolkit.jar db convert [-h] [--safe] <src> <dest>
java -jar Toolkit.jar db convert [-h] <src> <dest>
# examples
java -jar Toolkit.jar db convert output-directory/database /tmp/database
```
Expand Down
6 changes: 3 additions & 3 deletions plugins/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ dependencies {
compile group: 'com.typesafe', name: 'config', version: '1.3.2'
compile group: 'me.tongfei', name: 'progressbar', version: '0.9.3'
compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.69'
compile group: 'org.rocksdb', name: 'rocksdbjni', version: '5.15.10'
compile 'io.github.tronprotocol:leveldbjni-all:1.18.2'
compile 'io.github.tronprotocol:leveldb:1.18.2'
compile group: 'org.rocksdb', name: 'rocksdbjni', version: '7.7.3'
compile 'io.github.tronprotocol:leveldbjni-all:1.18.3'
compile 'io.github.tronprotocol:leveldb:1.18.3'
compile project(":protocol")
}

Expand Down
8 changes: 1 addition & 7 deletions plugins/src/main/java/org/tron/plugins/DbConvert.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,7 @@ public class DbConvert implements Callable<Integer> {
description = "Output path for rocksdb. Default: ${DEFAULT-VALUE}")
private File dest;

@CommandLine.Option(names = {"--safe"},
description = "In safe mode, read data from leveldb then put rocksdb."
+ "If not, just change engine.properties from leveldb to rocksdb,"
+ "rocksdb is compatible with leveldb for current version."
+ "This may not be the case in the future."
+ "Default: ${DEFAULT-VALUE}")
private boolean safe;
private final boolean safe = true;

@CommandLine.Option(names = {"-h", "--help"})
private boolean help;
Expand Down
Loading
Loading