Skip to content

Commit 0a3f2aa

Browse files
authored
Merge pull request #5150 from tronprotocol/revert-5105-feature/auto_prune_blockv2
Revert "feat(db): prune lite node data automatically"
2 parents 80516d7 + 0c3dc83 commit 0a3f2aa

11 files changed

Lines changed: 4 additions & 492 deletions

File tree

chainbase/src/main/java/org/tron/common/storage/prune/ChainDataPruner.java

Lines changed: 0 additions & 149 deletions
This file was deleted.

chainbase/src/main/java/org/tron/core/ChainBaseManager.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.apache.commons.collections4.CollectionUtils;
1212
import org.springframework.beans.factory.annotation.Autowired;
1313
import org.springframework.stereotype.Component;
14-
import org.tron.common.parameter.CommonParameter;
1514
import org.tron.common.storage.metric.DbStatService;
1615
import org.tron.common.utils.ForkController;
1716
import org.tron.common.utils.Sha256Hash;
@@ -242,6 +241,8 @@ public class ChainBaseManager {
242241
@Setter
243242
private NodeType nodeType;
244243

244+
@Getter
245+
@Setter
245246
private long lowestBlockNum = -1; // except num = 0.
246247

247248
public void closeOneStore(ITronChainBase database) {
@@ -430,15 +431,6 @@ private void init() {
430431
this.nodeType = getLowestBlockNum() > 1 ? NodeType.LITE : NodeType.FULL;
431432
}
432433

433-
public long getLowestBlockNum(){
434-
if(isLiteNode() && CommonParameter.getInstance().getStorage().isDbAutoPrune()) {
435-
return this.blockIndexStore.getLimitNumber(1, 1).stream()
436-
.map(BlockId::getNum).findFirst().orElseThrow(
437-
() -> new IllegalArgumentException("LowestBlockNum not found!"));
438-
}
439-
return lowestBlockNum;
440-
}
441-
442434
public boolean isLiteNode() {
443435
return getNodeType() == NodeType.LITE;
444436
}

chainbase/src/main/java/org/tron/core/db2/core/SnapshotRoot.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@
22

33
import com.google.common.collect.Maps;
44
import com.google.common.collect.Streams;
5-
import java.util.Arrays;
65
import java.util.HashMap;
76
import java.util.Iterator;
87
import java.util.List;
98
import java.util.Map;
109
import java.util.Objects;
11-
import java.util.Set;
1210
import java.util.stream.Collectors;
1311
import lombok.Getter;
1412
import org.tron.common.cache.CacheManager;
1513
import org.tron.common.cache.CacheType;
1614
import org.tron.common.cache.TronCache;
1715
import org.tron.common.parameter.CommonParameter;
18-
import org.tron.common.storage.prune.ChainDataPruner;
1916
import org.tron.common.utils.ByteArray;
2017
import org.tron.core.ChainBaseManager;
2118
import org.tron.core.capsule.AccountCapsule;
@@ -41,7 +38,6 @@ public SnapshotRoot(DB<byte[], byte[]> db) {
4138
if (CACHE_DBS.contains(this.db.getDbName())) {
4239
this.cache = CacheManager.allocate(CacheType.findByType(this.db.getDbName()));
4340
}
44-
ChainDataPruner.register(this.db.getDbName(), this);
4541
}
4642

4743
private boolean needOptAsset() {

common/src/main/java/org/tron/core/Constant.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.tron.core;
22

3-
import org.tron.core.config.Parameter.ChainConstant;
4-
53
public class Constant {
64

75
//config for testnet, mainnet, beta
@@ -41,8 +39,6 @@ public class Constant {
4139
public static final int ONE_HUNDRED = 100;
4240
public static final int ONE_THOUSAND = 1000;
4341

44-
public static final long ONE_DAY_BLOCKS_PREDICT = 24 * 60 * 60 * 1000 / ChainConstant.BLOCK_PRODUCED_INTERVAL;
45-
4642
public static final byte[] ZTRON_EXPANDSEED_PERSONALIZATION = {'Z', 't', 'r', 'o', 'n', '_', 'E',
4743
'x',
4844
'p', 'a', 'n', 'd', 'S', 'e', 'e', 'd'};

common/src/main/java/org/tron/core/config/args/Storage.java

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.tron.common.utils.DbOptionalsUtils;
3333
import org.tron.common.utils.FileUtil;
3434
import org.tron.common.utils.Property;
35-
import org.tron.core.Constant;
3635

3736
/**
3837
* Custom storage configurations
@@ -55,10 +54,6 @@ public class Storage {
5554
private static final String ESTIMATED_TRANSACTIONS_CONFIG_KEY =
5655
"storage.txCache.estimatedTransactions";
5756
private static final String SNAPSHOT_MAX_FLUSH_COUNT_CONFIG_KEY = "storage.snapshot.maxFlushCount";
58-
private static final String DB_AUTO_PRUNE_SWITCH_CONFIG_KEY = "storage.prune.enable";
59-
private static final String DB_AUTO_PRUNE_RETAIN_CONFIG_KEY = "storage.prune.retain";
60-
private static final String DB_AUTO_PRUNE_FREQUENCY_CONFIG_KEY = "storage.prune.frequency";
61-
private static final String DB_AUTO_PRUNE_BATCH_CONFIG_KEY = "storage.prune.batch";
6257
private static final String PROPERTIES_CONFIG_KEY = "storage.properties";
6358
private static final String PROPERTIES_CONFIG_DB_KEY = "storage";
6459
private static final String PROPERTIES_CONFIG_DEFAULT_KEY = "default";
@@ -96,11 +91,6 @@ public class Storage {
9691
private static final boolean DEFAULT_CHECKPOINT_SYNC = true;
9792
private static final int DEFAULT_ESTIMATED_TRANSACTIONS = 1000;
9893
private static final int DEFAULT_SNAPSHOT_MAX_FLUSH_COUNT = 1;
99-
private static final boolean DEFAULT_DB_AUTO_PRUNE_SWITCH = false;
100-
private static final int DEFAULT_DB_AUTO_PRUNE_RETAIN = 864000;
101-
private static final int DEFAULT_DB_AUTO_PRUNE_FREQUENCY = 3;
102-
private static final int DEFAULT_DB_AUTO_PRUNE_BATCH = 50;
103-
10494
private Config storage;
10595

10696
/**
@@ -122,22 +112,6 @@ public class Storage {
122112
@Setter
123113
private int maxFlushCount;
124114

125-
@Getter
126-
@Setter
127-
private boolean dbAutoPrune;
128-
129-
@Getter
130-
@Setter
131-
private int dbAutoPruneRetain;
132-
133-
@Getter
134-
@Setter
135-
private int dbAutoPruneFrequency;
136-
137-
@Getter
138-
@Setter
139-
private int dbAutoPruneBatch;
140-
141115
/**
142116
* Index storage directory: /path/to/{indexDirectory}
143117
*/
@@ -208,57 +182,6 @@ public static int getSnapshotMaxFlushCountFromConfig(final Config config) {
208182
return maxFlushCountConfig;
209183
}
210184

211-
public void setDbAutoPruneInfo(final Config config) {
212-
setDbAutoPrune(Storage.getDbAutoPruneSwitchFromConfig(config));
213-
setDbAutoPruneRetain(Storage.getDbAutoPruneRetainFromConfig(config));
214-
setDbAutoPruneFrequency(
215-
Storage.getDbAutoPruneFrequencyFromConfig(config));
216-
setDbAutoPruneBatch(Storage.getDbAutoPruneBatchFromConfig(config));
217-
}
218-
219-
public static boolean getDbAutoPruneSwitchFromConfig(final Config config) {
220-
return config.hasPath(DB_AUTO_PRUNE_SWITCH_CONFIG_KEY)
221-
? config.getBoolean(DB_AUTO_PRUNE_SWITCH_CONFIG_KEY) : DEFAULT_DB_AUTO_PRUNE_SWITCH;
222-
}
223-
224-
public static int getDbAutoPruneRetainFromConfig(final Config config) {
225-
if (!config.hasPath(DB_AUTO_PRUNE_RETAIN_CONFIG_KEY)) {
226-
return DEFAULT_DB_AUTO_PRUNE_RETAIN;
227-
}
228-
int dbAutoPruneRetain = config.getInt(DB_AUTO_PRUNE_RETAIN_CONFIG_KEY);
229-
if (dbAutoPruneRetain < 30 * Constant.ONE_DAY_BLOCKS_PREDICT) {
230-
throw new IllegalArgumentException(
231-
"[storage.prune.retain] value must not be less than 864000!");
232-
}
233-
return dbAutoPruneRetain;
234-
}
235-
236-
public static int getDbAutoPruneFrequencyFromConfig(final Config config) {
237-
if (!config.hasPath(DB_AUTO_PRUNE_FREQUENCY_CONFIG_KEY)) {
238-
return DEFAULT_DB_AUTO_PRUNE_FREQUENCY;
239-
}
240-
int dbAutoPruneFrequency = config.getInt(DB_AUTO_PRUNE_FREQUENCY_CONFIG_KEY);
241-
if (dbAutoPruneFrequency < 1) {
242-
throw new IllegalArgumentException("[storage.prune.frequency] value must not be less than " +
243-
"1!");
244-
}
245-
return dbAutoPruneFrequency;
246-
}
247-
248-
public static int getDbAutoPruneBatchFromConfig(final Config config) {
249-
if (!config.hasPath(DB_AUTO_PRUNE_BATCH_CONFIG_KEY)) {
250-
return DEFAULT_DB_AUTO_PRUNE_BATCH;
251-
}
252-
int dbAutoPruneBatch = config.getInt(DB_AUTO_PRUNE_BATCH_CONFIG_KEY);
253-
if (dbAutoPruneBatch < 1) {
254-
throw new IllegalArgumentException("[storage.prune.batch] value must not be less than 1!");
255-
}
256-
if (dbAutoPruneBatch > 50) {
257-
throw new IllegalArgumentException("[storage.prune.batch] value must not be more than 50!");
258-
}
259-
return dbAutoPruneBatch;
260-
}
261-
262185
public static Boolean getContractParseSwitchFromConfig(final Config config) {
263186
return config.hasPath(EVENT_SUBSCRIBE_CONTRACT_PARSE)
264187
? config.getBoolean(EVENT_SUBSCRIBE_CONTRACT_PARSE)

framework/src/main/java/org/tron/core/config/args/Args.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,6 @@ public static void setParam(final String[] args, final String confFileName) {
523523
PARAMETER.storage.setEstimatedBlockTransactions(
524524
Storage.getEstimatedTransactionsFromConfig(config));
525525
PARAMETER.storage.setMaxFlushCount(Storage.getSnapshotMaxFlushCountFromConfig(config));
526-
PARAMETER.storage.setDbAutoPruneInfo(config);
527526

528527
PARAMETER.storage.setDefaultDbOptions(config);
529528
PARAMETER.storage.setPropertyMapFromConfig(config);

framework/src/main/java/org/tron/core/db/Manager.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
import org.tron.common.prometheus.MetricLabels;
7070
import org.tron.common.prometheus.Metrics;
7171
import org.tron.common.runtime.RuntimeImpl;
72-
import org.tron.common.storage.prune.ChainDataPruner;
7372
import org.tron.common.utils.ByteArray;
7473
import org.tron.common.utils.JsonUtil;
7574
import org.tron.common.utils.Pair;
@@ -226,8 +225,6 @@ public class Manager {
226225
@Autowired
227226
@Getter
228227
private ChainBaseManager chainBaseManager;
229-
@Autowired
230-
private ChainDataPruner chainDataPruner;
231228
// transactions cache
232229
private BlockingQueue<TransactionCapsule> pendingTransactions;
233230
@Getter
@@ -1915,7 +1912,6 @@ public NullifierStore getNullifierStore() {
19151912

19161913
public void closeAllStore() {
19171914
logger.info("******** Begin to close db. ********");
1918-
chainDataPruner.shutdown();
19191915
chainBaseManager.closeAllStore();
19201916
logger.info("******** End to close db. ********");
19211917
}

0 commit comments

Comments
 (0)