Skip to content

Commit 3c0452c

Browse files
committed
use DiskIndex instead of other index
1 parent 0639a13 commit 3c0452c

7 files changed

Lines changed: 184 additions & 229 deletions

File tree

src/main/java/org/tron/core/db/api/StoreAPI.java

Lines changed: 136 additions & 152 deletions
Large diffs are not rendered by default.

src/main/java/org/tron/core/db/api/index/AbstractIndex.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ public abstract class AbstractIndex<E extends ProtoCapsule, T> implements Iface<
2020
protected ConcurrentIndexedCollection<WrappedByteArray> index;
2121

2222
public AbstractIndex() {
23-
index = new ConcurrentIndexedCollection<>();
2423
setAttribute();
2524
}
2625

27-
public AbstractIndex(Persistence<WrappedByteArray, ? extends Comparable> persistence) {
26+
public void initIndex(Persistence<WrappedByteArray, ? extends Comparable> persistence) {
2827
index = new ConcurrentIndexedCollection<>(persistence);
29-
setAttribute();
3028
}
3129

3230
@Override
Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package org.tron.core.db.api.index;
22

33
import com.googlecode.cqengine.attribute.Attribute;
4+
import com.googlecode.cqengine.attribute.SimpleAttribute;
5+
import com.googlecode.cqengine.index.disk.DiskIndex;
6+
import com.googlecode.cqengine.index.hash.HashIndex;
47
import com.googlecode.cqengine.index.navigable.NavigableIndex;
58
import com.googlecode.cqengine.index.suffix.SuffixTreeIndex;
69
import com.googlecode.cqengine.persistence.Persistence;
10+
import com.googlecode.cqengine.persistence.disk.DiskPersistence;
711
import lombok.extern.slf4j.Slf4j;
812
import org.springframework.beans.factory.annotation.Autowired;
913
import org.springframework.beans.factory.annotation.Qualifier;
@@ -22,41 +26,23 @@
2226
@Slf4j
2327
public class AccountIndex extends AbstractIndex<AccountCapsule, Account> {
2428

25-
public static Attribute<WrappedByteArray, String> Account_ADDRESS;
26-
public static Attribute<WrappedByteArray, Long> Account_BALANCE;
29+
public static SimpleAttribute<WrappedByteArray, String> Account_ADDRESS;
2730

2831
@Autowired
2932
public AccountIndex(@Qualifier("accountStore") final TronDatabase<AccountCapsule> database) {
30-
super();
31-
this.database = database;
32-
}
33-
34-
public AccountIndex(final TronDatabase<AccountCapsule> database,
35-
Persistence<WrappedByteArray, ? extends Comparable> persistence) {
36-
super(persistence);
3733
this.database = database;
3834
}
3935

4036
@PostConstruct
4137
public void init() {
42-
index.addIndex(SuffixTreeIndex.onAttribute(Account_ADDRESS));
43-
index.addIndex(NavigableIndex.onAttribute(Account_BALANCE));
38+
initIndex(DiskPersistence.onPrimaryKey(Account_ADDRESS));
39+
// index.addIndex(DiskIndex.onAttribute(Account_ADDRESS));
4440
fill();
4541
}
4642

4743
@Override
4844
protected void setAttribute() {
4945
Account_ADDRESS = attribute("account address",
5046
bytes -> ByteArray.toHexString(bytes.getBytes()));
51-
Account_BALANCE = attribute("account balance",
52-
bytes -> {
53-
try {
54-
Account account = getObject(bytes);
55-
return account.getBalance();
56-
} catch (Exception e) {
57-
throw new RuntimeException(e);
58-
}
59-
});
60-
6147
}
6248
}

src/main/java/org/tron/core/db/api/index/AssetIssueIndex.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package org.tron.core.db.api.index;
22

33
import com.googlecode.cqengine.attribute.Attribute;
4+
import com.googlecode.cqengine.attribute.SimpleAttribute;
5+
import com.googlecode.cqengine.index.disk.DiskIndex;
6+
import com.googlecode.cqengine.index.hash.HashIndex;
47
import com.googlecode.cqengine.index.navigable.NavigableIndex;
58
import com.googlecode.cqengine.index.suffix.SuffixTreeIndex;
69
import com.googlecode.cqengine.persistence.Persistence;
10+
import com.googlecode.cqengine.persistence.disk.DiskPersistence;
711
import lombok.extern.slf4j.Slf4j;
812
import org.springframework.beans.factory.annotation.Autowired;
913
import org.springframework.beans.factory.annotation.Qualifier;
@@ -23,30 +27,23 @@
2327
public class AssetIssueIndex extends AbstractIndex<AssetIssueCapsule, AssetIssueContract> {
2428

2529
public static Attribute<WrappedByteArray, String> AssetIssue_OWNER_RADDRESS;
26-
public static Attribute<WrappedByteArray, String> AssetIssue_NAME;
30+
public static SimpleAttribute<WrappedByteArray, String> AssetIssue_NAME;
2731
public static Attribute<WrappedByteArray, Long> AssetIssue_START;
2832
public static Attribute<WrappedByteArray, Long> AssetIssue_END;
2933

3034
@Autowired
3135
public AssetIssueIndex(
3236
@Qualifier("assetIssueStore") final TronDatabase<AssetIssueCapsule> database) {
33-
super();
34-
this.database = database;
35-
}
36-
37-
public AssetIssueIndex(
38-
final TronDatabase<AssetIssueCapsule> database,
39-
Persistence<WrappedByteArray, ? extends Comparable> persistence) {
40-
super(persistence);
4137
this.database = database;
4238
}
4339

4440
@PostConstruct
4541
public void init() {
46-
index.addIndex(SuffixTreeIndex.onAttribute(AssetIssue_OWNER_RADDRESS));
47-
index.addIndex(SuffixTreeIndex.onAttribute(AssetIssue_NAME));
48-
index.addIndex(NavigableIndex.onAttribute(AssetIssue_START));
49-
index.addIndex(NavigableIndex.onAttribute(AssetIssue_END));
42+
initIndex(DiskPersistence.onPrimaryKey(AssetIssue_NAME));
43+
index.addIndex(DiskIndex.onAttribute(AssetIssue_OWNER_RADDRESS));
44+
// index.addIndex(DiskIndex.onAttribute(AssetIssue_NAME));
45+
index.addIndex(DiskIndex.onAttribute(AssetIssue_START));
46+
index.addIndex(DiskIndex.onAttribute(AssetIssue_END));
5047
fill();
5148
}
5249

src/main/java/org/tron/core/db/api/index/BlockIndex.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package org.tron.core.db.api.index;
22

33
import com.googlecode.cqengine.attribute.Attribute;
4+
import com.googlecode.cqengine.attribute.SimpleAttribute;
5+
import com.googlecode.cqengine.index.disk.DiskIndex;
46
import com.googlecode.cqengine.index.hash.HashIndex;
57
import com.googlecode.cqengine.index.navigable.NavigableIndex;
68
import com.googlecode.cqengine.index.suffix.SuffixTreeIndex;
79
import com.googlecode.cqengine.persistence.Persistence;
10+
import com.googlecode.cqengine.persistence.disk.DiskPersistence;
811
import lombok.extern.slf4j.Slf4j;
912
import org.springframework.beans.factory.annotation.Autowired;
1013
import org.springframework.beans.factory.annotation.Qualifier;
@@ -28,7 +31,7 @@
2831
@Slf4j
2932
public class BlockIndex extends AbstractIndex<BlockCapsule, Block> {
3033

31-
public static Attribute<WrappedByteArray, String> Block_ID;
34+
public static SimpleAttribute<WrappedByteArray, String> Block_ID;
3235
public static Attribute<WrappedByteArray, Long> Block_NUMBER;
3336
public static Attribute<WrappedByteArray, String> TRANSACTIONS;
3437
public static Attribute<WrappedByteArray, Long> WITNESS_ID;
@@ -39,26 +42,19 @@ public class BlockIndex extends AbstractIndex<BlockCapsule, Block> {
3942
@Autowired
4043
public BlockIndex(
4144
@Qualifier("blockStore") final TronDatabase<BlockCapsule> database) {
42-
super();
43-
this.database = database;
44-
}
45-
46-
public BlockIndex(
47-
final TronDatabase<BlockCapsule> database,
48-
Persistence<WrappedByteArray, ? extends Comparable> persistence) {
49-
super(persistence);
5045
this.database = database;
5146
}
5247

5348
@PostConstruct
5449
public void init() {
55-
index.addIndex(SuffixTreeIndex.onAttribute(Block_ID));
56-
index.addIndex(NavigableIndex.onAttribute(Block_NUMBER));
57-
index.addIndex(HashIndex.onAttribute(TRANSACTIONS));
58-
index.addIndex(NavigableIndex.onAttribute(WITNESS_ID));
59-
index.addIndex(SuffixTreeIndex.onAttribute(WITNESS_ADDRESS));
60-
index.addIndex(SuffixTreeIndex.onAttribute(OWNERS));
61-
index.addIndex(SuffixTreeIndex.onAttribute(TOS));
50+
initIndex(DiskPersistence.onPrimaryKey(Block_ID));
51+
// index.addIndex(DiskIndex.onAttribute(Block_ID));
52+
index.addIndex(DiskIndex.onAttribute(Block_NUMBER));
53+
index.addIndex(DiskIndex.onAttribute(TRANSACTIONS));
54+
index.addIndex(DiskIndex.onAttribute(WITNESS_ID));
55+
index.addIndex(DiskIndex.onAttribute(WITNESS_ADDRESS));
56+
index.addIndex(DiskIndex.onAttribute(OWNERS));
57+
index.addIndex(DiskIndex.onAttribute(TOS));
6258
fill();
6359
}
6460

src/main/java/org/tron/core/db/api/index/TransactionIndex.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
import com.googlecode.cqengine.attribute.Attribute;
44
import com.googlecode.cqengine.attribute.SimpleAttribute;
5+
import com.googlecode.cqengine.index.disk.DiskIndex;
56
import com.googlecode.cqengine.index.hash.HashIndex;
67
import com.googlecode.cqengine.index.navigable.NavigableIndex;
78
import com.googlecode.cqengine.index.suffix.SuffixTreeIndex;
89
import com.googlecode.cqengine.persistence.Persistence;
10+
import com.googlecode.cqengine.persistence.disk.DiskPersistence;
11+
import com.googlecode.cqengine.persistence.offheap.OffHeapPersistence;
12+
import com.googlecode.cqengine.persistence.onheap.OnHeapPersistence;
913
import lombok.extern.slf4j.Slf4j;
1014
import org.springframework.beans.factory.annotation.Autowired;
1115
import org.springframework.beans.factory.annotation.Qualifier;
@@ -34,23 +38,16 @@ public class TransactionIndex extends AbstractIndex<TransactionCapsule, Transact
3438
@Autowired
3539
public TransactionIndex(
3640
@Qualifier("transactionStore") final TronDatabase<TransactionCapsule> database) {
37-
super();
38-
this.database = database;
39-
}
40-
41-
public TransactionIndex(
42-
final TronDatabase<TransactionCapsule> database,
43-
Persistence<WrappedByteArray, ? extends Comparable> persistence) {
44-
super(persistence);
4541
this.database = database;
4642
}
4743

4844
@PostConstruct
4945
public void init() {
50-
index.addIndex(SuffixTreeIndex.onAttribute(Transaction_ID));
51-
index.addIndex(HashIndex.onAttribute(OWNERS));
52-
index.addIndex(HashIndex.onAttribute(TOS));
53-
index.addIndex(NavigableIndex.onAttribute(TIMESTAMP));
46+
initIndex(DiskPersistence.onPrimaryKey(Transaction_ID));
47+
// index.addIndex(DiskIndex.onAttribute(Transaction_ID));
48+
index.addIndex(DiskIndex.onAttribute(OWNERS));
49+
index.addIndex(DiskIndex.onAttribute(TOS));
50+
index.addIndex(DiskIndex.onAttribute(TIMESTAMP));
5451
fill();
5552
}
5653

src/main/java/org/tron/core/db/api/index/WitnessIndex.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package org.tron.core.db.api.index;
22

33
import com.googlecode.cqengine.attribute.Attribute;
4+
import com.googlecode.cqengine.attribute.SimpleAttribute;
5+
import com.googlecode.cqengine.index.disk.DiskIndex;
6+
import com.googlecode.cqengine.index.hash.HashIndex;
47
import com.googlecode.cqengine.index.suffix.SuffixTreeIndex;
58
import com.googlecode.cqengine.persistence.Persistence;
9+
import com.googlecode.cqengine.persistence.disk.DiskPersistence;
610
import lombok.extern.slf4j.Slf4j;
711
import org.springframework.beans.factory.annotation.Autowired;
812
import org.springframework.beans.factory.annotation.Qualifier;
@@ -21,29 +25,22 @@
2125
@Slf4j
2226
public class WitnessIndex extends AbstractIndex<WitnessCapsule, Witness> {
2327

24-
public static Attribute<WrappedByteArray, String> Witness_ADDRESS;
28+
public static SimpleAttribute<WrappedByteArray, String> Witness_ADDRESS;
2529
public static Attribute<WrappedByteArray, String> PUBLIC_KEY;
2630
public static Attribute<WrappedByteArray, String> Witness_URL;
2731

2832
@Autowired
2933
public WitnessIndex(
3034
@Qualifier("witnessStore") final TronDatabase<WitnessCapsule> database) {
31-
super();
32-
this.database = database;
33-
}
34-
35-
public WitnessIndex(
36-
final TronDatabase<WitnessCapsule> database,
37-
Persistence<WrappedByteArray, ? extends Comparable> persistence) {
38-
super(persistence);
3935
this.database = database;
4036
}
4137

4238
@PostConstruct
4339
public void init() {
44-
index.addIndex(SuffixTreeIndex.onAttribute(Witness_ADDRESS));
45-
index.addIndex(SuffixTreeIndex.onAttribute(PUBLIC_KEY));
46-
index.addIndex(SuffixTreeIndex.onAttribute(Witness_URL));
40+
initIndex(DiskPersistence.onPrimaryKey(Witness_ADDRESS));
41+
// index.addIndex(DiskIndex.onAttribute(Witness_ADDRESS));
42+
index.addIndex(DiskIndex.onAttribute(PUBLIC_KEY));
43+
index.addIndex(DiskIndex.onAttribute(Witness_URL));
4744
fill();
4845
}
4946

0 commit comments

Comments
 (0)