Skip to content

Commit

Permalink
reenabling the journal prune DS #298
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandraRoatis committed May 18, 2018
1 parent 623db38 commit 2f2d15d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 31 deletions.
29 changes: 13 additions & 16 deletions modAionImpl/src/org/aion/zero/impl/db/AionRepositoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public TransactionStore<AionTransaction, AionTxReceipt, AionTxInfo> getTransacti
}

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

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

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

// TODO-AR: reenable state pruning
// temporarily removed since never used
/* private void pruneBlocks(A0BlockHeader curBlock) {
if (curBlock.getNumber() > bestBlockNumber) { // pruning only on
// increasing blocks
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 @@ -543,7 +540,7 @@ public 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
8 changes: 3 additions & 5 deletions modMcf/src/org/aion/mcf/db/AbstractRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import static org.aion.db.impl.DatabaseFactory.Props;

//import org.aion.dbmgr.exception.DriverManagerNoSuitableDriverRegisteredException;
// import org.aion.mcf.trie.JournalPruneDataSource;
import org.aion.mcf.trie.JournalPruneDataSource;

/**
* Abstract Repository class.
Expand Down Expand Up @@ -94,7 +94,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 @@ -241,9 +241,7 @@ protected void initializeDatabasesAndCaches() throws Exception {

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

import java.util.*;

import static org.aion.base.util.ByteArrayWrapper.wrap;

// import org.aion.mcf.trie.JournalPruneDataSource;

/**
* 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 @@ -62,7 +61,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 @@ -91,7 +90,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(storageSrc);
detailsImpl.setDataSource(storageDSPrune);
detailsImpl.decode(rawDetails.get()); // We can safely get as we checked
// if it is present.

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

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

Expand All @@ -171,9 +170,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
4 changes: 2 additions & 2 deletions modMcf/src/org/aion/mcf/trie/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ public synchronized void commit(boolean flushCache) {
// batchMemorySize += length(key, value);
}
}
/* for (ByteArrayWrapper removedNode : removedNodes) {
for (ByteArrayWrapper removedNode : removedNodes) {
batch.put(removedNode.getData(), null);
} */
}

this.dataSource.putBatch(batch);
this.isDirty = false;
Expand Down

0 comments on commit 2f2d15d

Please sign in to comment.