diff --git a/src/main/java/org/tron/core/db/api/IndexHelper.java b/src/main/java/org/tron/core/db/api/IndexHelper.java index 8e22432fea6..193af8e630f 100644 --- a/src/main/java/org/tron/core/db/api/IndexHelper.java +++ b/src/main/java/org/tron/core/db/api/IndexHelper.java @@ -1,5 +1,6 @@ package org.tron.core.db.api; +import javax.annotation.PostConstruct; import javax.annotation.Resource; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -34,6 +35,14 @@ public class IndexHelper { @Resource private Index.Iface assetIssueIndex; + @PostConstruct + public void init() { + transactionIndex.fill(); + blockIndex.fill(); + witnessIndex.fill(); + accountIndex.fill(); + assetIssueIndex.fill(); + } private void add(Index.Iface index, byte[] bytes) { index.add(bytes); } diff --git a/src/main/java/org/tron/core/db/api/index/AbstractIndex.java b/src/main/java/org/tron/core/db/api/index/AbstractIndex.java index 3d443ef864e..bafd3f480ef 100644 --- a/src/main/java/org/tron/core/db/api/index/AbstractIndex.java +++ b/src/main/java/org/tron/core/db/api/index/AbstractIndex.java @@ -56,9 +56,10 @@ protected T getObject(final WrappedByteArray byteArray) { return getObject(byteArray.getBytes()); } - protected void fill() { + @Override + public void fill() { int size = Iterables.size(database); - if (size != 0 && (!indexPath.exists() || index.size() < size)) { + if (size != 0 && !indexPath.exists()) { database.forEach(e -> add(e.getKey())); } } diff --git a/src/main/java/org/tron/core/db/api/index/AccountIndex.java b/src/main/java/org/tron/core/db/api/index/AccountIndex.java index b81543540b4..ccbfc330a48 100644 --- a/src/main/java/org/tron/core/db/api/index/AccountIndex.java +++ b/src/main/java/org/tron/core/db/api/index/AccountIndex.java @@ -40,7 +40,6 @@ public AccountIndex(@Qualifier("accountStore") final TronDatabase extends Iterable { long size(); String getName(); + + void fill(); } } diff --git a/src/main/java/org/tron/core/db/api/index/TransactionIndex.java b/src/main/java/org/tron/core/db/api/index/TransactionIndex.java index 61603839ed6..9871d6bc256 100644 --- a/src/main/java/org/tron/core/db/api/index/TransactionIndex.java +++ b/src/main/java/org/tron/core/db/api/index/TransactionIndex.java @@ -49,7 +49,6 @@ public void init() { index.addIndex(DiskIndex.onAttribute(OWNERS)); index.addIndex(DiskIndex.onAttribute(TOS)); index.addIndex(DiskIndex.onAttribute(TIMESTAMP)); - fill(); } @Override diff --git a/src/main/java/org/tron/core/db/api/index/WitnessIndex.java b/src/main/java/org/tron/core/db/api/index/WitnessIndex.java index 2900426182f..b7bbf5d09a5 100644 --- a/src/main/java/org/tron/core/db/api/index/WitnessIndex.java +++ b/src/main/java/org/tron/core/db/api/index/WitnessIndex.java @@ -43,7 +43,6 @@ public void init() { // index.addIndex(DiskIndex.onAttribute(Witness_ADDRESS)); index.addIndex(DiskIndex.onAttribute(PUBLIC_KEY)); index.addIndex(DiskIndex.onAttribute(Witness_URL)); - fill(); } @Override