Skip to content

Commit

Permalink
Merge pull request #293 from aionnetwork/dev-alexandra
Browse files Browse the repository at this point in the history
removing the use of JournalPruneDataSource
  • Loading branch information
iamyulong authored Mar 27, 2018
2 parents 5557530 + add64b0 commit 0f25aae
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
21 changes: 12 additions & 9 deletions modAionImpl/src/org/aion/zero/impl/db/AionRepositoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* Contributors:
* Aion foundation.
*
*
******************************************************************************/

package org.aion.zero.impl.db;
Expand Down Expand Up @@ -125,7 +125,7 @@ public TransactionStore<AionTransaction, AionTxReceipt, AionTxInfo> getTransacti
}

private Trie createStateTrie() {
return new SecureTrie(stateDSPrune).withPruningEnabled(pruneBlockCount >= 0);
return new SecureTrie(stateDatabase).withPruningEnabled(pruneBlockCount >= 0);
}

@Override
Expand Down Expand Up @@ -444,28 +444,31 @@ public synchronized void commitBlock(A0BlockHeader blockHeader) {
worldState.sync();
detailsDS.syncLargeStorage();

if (pruneBlockCount >= 0) {
// temporarily removed since never used
/* if (pruneBlockCount >= 0) {
stateDSPrune.storeBlockChanges(blockHeader);
detailsDS.getStorageDSPrune().storeBlockChanges(blockHeader);
pruneBlocks(blockHeader);
}
} */
}

private void pruneBlocks(A0BlockHeader curBlock) {
// TODO-AR: reenable state pruning
// temporarily removed since never used
/* private void pruneBlocks(A0BlockHeader curBlock) {
if (curBlock.getNumber() > bestBlockNumber) { // pruning only on
// increasing blocks
long pruneBlockNumber = curBlock.getNumber() - pruneBlockCount;
if (pruneBlockNumber >= 0) {
byte[] pruneBlockHash = blockStore.getBlockHashByNumber(pruneBlockNumber);
if (pruneBlockHash != null) {
A0BlockHeader header = blockStore.getBlockByHash(pruneBlockHash).getHeader();
stateDSPrune.prune(header);
detailsDS.getStorageDSPrune().prune(header);
// stateDSPrune.prune(header);
// detailsDS.getStorageDSPrune().prune(header);
}
}
}
bestBlockNumber = curBlock.getNumber();
}
} */

public Trie getWorldState() {
return worldState;
Expand All @@ -478,7 +481,7 @@ public synchronized IRepository getSnapshotTo(byte[] root) {
repo.blockStore = blockStore;
repo.cfg = cfg;
repo.stateDatabase = this.stateDatabase;
repo.stateDSPrune = this.stateDSPrune;
// repo.stateDSPrune = this.stateDSPrune;
repo.pruneBlockCount = this.pruneBlockCount;
repo.detailsDS = this.detailsDS;
repo.isSnapshot = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

import org.aion.base.db.IByteArrayKeyValueDatabase;
import org.aion.mcf.core.ImportResult;
import org.aion.mcf.trie.JournalPruneDataSource;
// import org.aion.mcf.trie.JournalPruneDataSource;
import org.aion.mcf.trie.TrieImpl;
import org.aion.zero.impl.db.AionRepositoryImpl;
import org.aion.zero.impl.types.AionBlock;
Expand Down Expand Up @@ -89,7 +89,7 @@ public void testRecoverWorldStateWithPartialWorldState() {

// delete some world state root entries from the database
TrieImpl trie = (TrieImpl) ((AionRepositoryImpl) chain.getRepository()).getWorldState();
IByteArrayKeyValueDatabase database = ((JournalPruneDataSource) trie.getCache().getDb()).getSrc();
IByteArrayKeyValueDatabase database = (IByteArrayKeyValueDatabase) trie.getCache().getDb();

for (byte[] key : statesToDelete) {
database.delete(key);
Expand Down Expand Up @@ -140,7 +140,7 @@ public void testRecoverWorldStateWithStartFromGenesis() {

// delete some world state root entries from the database
TrieImpl trie = (TrieImpl) ((AionRepositoryImpl) chain.getRepository()).getWorldState();
IByteArrayKeyValueDatabase database = ((JournalPruneDataSource) trie.getCache().getDb()).getSrc();
IByteArrayKeyValueDatabase database = (IByteArrayKeyValueDatabase) trie.getCache().getDb();

for (byte[] key : statesToDelete) {
database.delete(key);
Expand Down Expand Up @@ -189,7 +189,7 @@ public void testRecoverWorldStateWithoutGenesis() {

// delete some world state root entries from the database
TrieImpl trie = (TrieImpl) ((AionRepositoryImpl) chain.getRepository()).getWorldState();
IByteArrayKeyValueDatabase database = ((JournalPruneDataSource) trie.getCache().getDb()).getSrc();
IByteArrayKeyValueDatabase database = (IByteArrayKeyValueDatabase) trie.getCache().getDb();

List<byte[]> statesToDelete = new ArrayList<>();
statesToDelete.addAll(database.keys());
Expand Down
8 changes: 5 additions & 3 deletions modMcf/src/org/aion/mcf/db/AbstractRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
//import org.aion.dbmgr.exception.DriverManagerNoSuitableDriverRegisteredException;
import org.aion.log.AionLoggerFactory;
import org.aion.log.LogEnum;
import org.aion.mcf.trie.JournalPruneDataSource;
// import org.aion.mcf.trie.JournalPruneDataSource;
import org.aion.mcf.trie.Trie;
import org.aion.mcf.types.AbstractBlock;
import org.aion.mcf.vm.types.DataWord;
Expand Down Expand Up @@ -84,7 +84,7 @@ public abstract class AbstractRepository<BLK extends AbstractBlock<BH, ? extends

protected Collection<IByteArrayKeyValueDatabase> databaseGroup;

protected JournalPruneDataSource<BLK, BH> stateDSPrune;
// protected JournalPruneDataSource<BLK, BH> stateDSPrune;
protected DetailsDataStore<BLK, BH> detailsDS;

// Read Write Lock
Expand Down Expand Up @@ -200,7 +200,9 @@ protected void initializeDatabasesAndCaches() throws Exception {

// Setup the cache for transaction data source.
this.detailsDS = new DetailsDataStore<>(detailsDatabase, storageDatabase, this.cfg);
stateDSPrune = new JournalPruneDataSource<>(stateDatabase);
// disabling use of JournalPruneDataSource until functionality properly tested
// TODO-AR: enable pruning with the JournalPruneDataSource
// stateDSPrune = new JournalPruneDataSource<>(stateDatabase);
pruneBlockCount = pruneEnabled ? this.cfg.getPrune() : -1;
} catch (Exception e) { // Setting up databases and caches went wrong.
throw e;
Expand Down
14 changes: 7 additions & 7 deletions modMcf/src/org/aion/mcf/db/DetailsDataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
import org.aion.base.type.ITransaction;
import org.aion.base.util.ByteArrayWrapper;
import org.aion.mcf.vm.types.DataWord;
import org.aion.mcf.trie.JournalPruneDataSource;
// import org.aion.mcf.trie.JournalPruneDataSource;
import org.aion.mcf.types.AbstractBlock;

/**
* Detail data storage ,
*/
public class DetailsDataStore<BLK extends AbstractBlock<BH, ? extends ITransaction>, BH extends IBlockHeader> {

private JournalPruneDataSource<BLK, BH> storageDSPrune;
// private JournalPruneDataSource<BLK, BH> storageDSPrune;
private IRepositoryConfig repoConfig;

private IByteArrayKeyValueDatabase detailsSrc;
Expand All @@ -66,7 +66,7 @@ public DetailsDataStore<BLK, BH> withDb(IByteArrayKeyValueDatabase detailsSrc,
IByteArrayKeyValueDatabase storageSrc) {
this.detailsSrc = detailsSrc;
this.storageSrc = storageSrc;
this.storageDSPrune = new JournalPruneDataSource<>(storageSrc);
// this.storageDSPrune = new JournalPruneDataSource<>(storageSrc);
return this;
}

Expand Down Expand Up @@ -95,7 +95,7 @@ public synchronized IContractDetails<DataWord> get(byte[] key) {

// Found something from cache or database, return it by decoding it.
IContractDetails<DataWord> detailsImpl = repoConfig.contractDetailsImpl();
detailsImpl.setDataSource(storageDSPrune);
detailsImpl.setDataSource(storageSrc);
detailsImpl.decode(rawDetails.get()); // We can safely get as we checked
// if it is present.

Expand Down Expand Up @@ -164,7 +164,7 @@ public void syncLargeStorage() {

// Decode the details.
IContractDetails<DataWord> detailsImpl = repoConfig.contractDetailsImpl();
detailsImpl.setDataSource(storageDSPrune);
detailsImpl.setDataSource(storageSrc);
detailsImpl.decode(rawDetails.get()); // We can safely get as we
// checked if it is present.

Expand All @@ -173,9 +173,9 @@ public void syncLargeStorage() {
}
}

public JournalPruneDataSource<BLK, BH> getStorageDSPrune() {
/* public JournalPruneDataSource<BLK, BH> getStorageDSPrune() {
return storageDSPrune;
}
} */

public synchronized Set<ByteArrayWrapper> keys() {
// TODO - @yao do we wanted a sorted set?
Expand Down

0 comments on commit 0f25aae

Please sign in to comment.