From db56a8eb6a1711dfe78c5ec2c1f47a17f0878a93 Mon Sep 17 00:00:00 2001 From: halibobo1205 Date: Mon, 3 Jun 2024 17:45:36 +0800 Subject: [PATCH] feat(db/rocksdb): update rocksdbjni --- .../rocksdb/RocksDbDataSourceImpl.java | 6 +++--- .../MarketOrderPriceComparatorForRockDB.java | 19 ++++++++----------- .../java/org/tron/core/db/TronDatabase.java | 4 ++-- .../tron/core/db/TronStoreWithRevoking.java | 4 ++-- .../store/MarketPairPriceToOrderStore.java | 4 ++-- common/build.gradle | 4 ++-- plugins/README.md | 4 +--- plugins/build.gradle | 6 +++--- .../main/java/org/tron/plugins/DbConvert.java | 8 +------- .../MarketOrderPriceComparatorForRockDB.java | 19 +++++++------------ .../java/org/tron/plugins/DbConvertTest.java | 2 +- 11 files changed, 32 insertions(+), 48 deletions(-) diff --git a/chainbase/src/main/java/org/tron/common/storage/rocksdb/RocksDbDataSourceImpl.java b/chainbase/src/main/java/org/tron/common/storage/rocksdb/RocksDbDataSourceImpl.java index 6c5d8018487..3b8afd7f35d 100644 --- a/chainbase/src/main/java/org/tron/common/storage/rocksdb/RocksDbDataSourceImpl.java +++ b/chainbase/src/main/java/org/tron/common/storage/rocksdb/RocksDbDataSourceImpl.java @@ -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; @@ -60,11 +60,11 @@ public class RocksDbDataSourceImpl extends DbStat implements DbSourceInter`: Input path for leveldb, default: output-directory/database. - ``: 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] + java -jar Toolkit.jar db convert [-h] # examples java -jar Toolkit.jar db convert output-directory/database /tmp/database ``` diff --git a/plugins/build.gradle b/plugins/build.gradle index 54ae7cba1c6..b1108d8324d 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -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.3' - compile 'io.github.tronprotocol:leveldb:1.18.3' + compile group: 'org.rocksdb', name: 'rocksdbjni', version: '7.7.3' + compile 'com.halibobor:leveldbjni-all:1.18.3' + compile 'com.halibobor:leveldb:1.18.3' compile project(":protocol") } diff --git a/plugins/src/main/java/org/tron/plugins/DbConvert.java b/plugins/src/main/java/org/tron/plugins/DbConvert.java index a75b235bbcf..c5e69b74418 100644 --- a/plugins/src/main/java/org/tron/plugins/DbConvert.java +++ b/plugins/src/main/java/org/tron/plugins/DbConvert.java @@ -49,13 +49,7 @@ public class DbConvert implements Callable { 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; diff --git a/plugins/src/main/java/org/tron/plugins/comparator/MarketOrderPriceComparatorForRockDB.java b/plugins/src/main/java/org/tron/plugins/comparator/MarketOrderPriceComparatorForRockDB.java index cd718bdd2d7..388711f99c6 100644 --- a/plugins/src/main/java/org/tron/plugins/comparator/MarketOrderPriceComparatorForRockDB.java +++ b/plugins/src/main/java/org/tron/plugins/comparator/MarketOrderPriceComparatorForRockDB.java @@ -1,11 +1,11 @@ package org.tron.plugins.comparator; +import java.nio.ByteBuffer; +import org.rocksdb.AbstractComparator; import org.rocksdb.ComparatorOptions; -import org.rocksdb.DirectSlice; -import org.rocksdb.util.DirectBytewiseComparator; import org.tron.plugins.utils.MarketUtils; -public class MarketOrderPriceComparatorForRockDB extends DirectBytewiseComparator { +public class MarketOrderPriceComparatorForRockDB extends AbstractComparator { public MarketOrderPriceComparatorForRockDB(final ComparatorOptions copt) { super(copt); @@ -17,21 +17,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; } diff --git a/plugins/src/test/java/org/tron/plugins/DbConvertTest.java b/plugins/src/test/java/org/tron/plugins/DbConvertTest.java index 150e47c9f65..0117a445418 100644 --- a/plugins/src/test/java/org/tron/plugins/DbConvertTest.java +++ b/plugins/src/test/java/org/tron/plugins/DbConvertTest.java @@ -18,7 +18,7 @@ public void testRun() throws IOException { @Test public void testRunWithSafe() throws IOException { String[] args = new String[] { "db", "convert", INPUT_DIRECTORY, - temporaryFolder.newFolder().toString(),"--safe" }; + temporaryFolder.newFolder().toString()}; Assert.assertEquals(0, cli.execute(args)); }