Search in sources :

Example 26 with ByteArrayWrapper

use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.

the class Cache method delete.

public synchronized void delete(byte[] key) {
    ByteArrayWrapper wrappedKey = wrap(key);
    this.nodes.remove(wrappedKey);
    if (dataSource != null) {
        this.dataSource.delete(key);
    }
}
Also used : ByteArrayWrapper(org.aion.base.util.ByteArrayWrapper)

Example 27 with ByteArrayWrapper

use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.

the class Cache method setDB.

public synchronized void setDB(IByteArrayKeyValueStore kvds) {
    if (this.dataSource == kvds) {
        return;
    }
    Map<byte[], byte[]> rows = new HashMap<>();
    if (this.dataSource == null) {
        for (ByteArrayWrapper key : nodes.keySet()) {
            Node node = nodes.get(key);
            if (node == null) {
                rows.put(key.getData(), null);
            } else if (!node.isDirty()) {
                rows.put(key.getData(), node.getValue().encode());
            }
        }
    } else {
        for (byte[] key : this.dataSource.keys()) {
            rows.put(key, this.dataSource.get(key).get());
        }
        try {
            this.dataSource.close();
        } catch (Exception e) {
            LOG.error("Unable to close data source.", e);
        }
    }
    kvds.putBatch(rows);
    this.dataSource = kvds;
}
Also used : ByteArrayWrapper(org.aion.base.util.ByteArrayWrapper) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 28 with ByteArrayWrapper

use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.

the class JournalPruneDataSource method storeBlockChanges.

public synchronized void storeBlockChanges(BH header) {
    if (!enabled) {
        return;
    }
    currentUpdates.blockHeader = header;
    blockUpdates.put(new ByteArrayWrapper(header.getHash()), currentUpdates);
    currentUpdates = new Updates();
}
Also used : ByteArrayWrapper(org.aion.base.util.ByteArrayWrapper)

Example 29 with ByteArrayWrapper

use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.

the class JournalPruneDataSource method updateBatch.

public synchronized void updateBatch(Map<byte[], byte[]> rows) {
    Map<byte[], byte[]> insertsOnly = new HashMap<>();
    for (Map.Entry<byte[], byte[]> entry : rows.entrySet()) {
        ByteArrayWrapper keyW = new ByteArrayWrapper(entry.getKey());
        if (entry.getValue() != null) {
            if (enabled) {
                currentUpdates.insertedKeys.add(keyW);
                incRef(keyW);
            }
            insertsOnly.put(entry.getKey(), entry.getValue());
        } else {
            if (enabled) {
                currentUpdates.deletedKeys.add(keyW);
            }
        }
    }
    src.putBatch(insertsOnly);
}
Also used : ByteArrayWrapper(org.aion.base.util.ByteArrayWrapper)

Example 30 with ByteArrayWrapper

use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.

the class TrieImpl method cleanCache.

/**
 * Insert/delete operations on a Trie structure leaves the old nodes in
 * cache, this method scans the cache and removes them. The method is not
 * thread safe, the tree should not be modified during the cleaning process.
 */
public void cleanCache() {
    synchronized (cache) {
        CollectFullSetOfNodes collectAction = new CollectFullSetOfNodes();
        this.scanTree(this.getRootHash(), collectAction);
        Set<ByteArrayWrapper> hashSet = collectAction.getCollectedHashes();
        Map<ByteArrayWrapper, Node> nodes = this.getCache().getNodes();
        Set<ByteArrayWrapper> toRemoveSet = new HashSet<>();
        for (ByteArrayWrapper key : nodes.keySet()) {
            if (!hashSet.contains(key)) {
                toRemoveSet.add(key);
            }
        }
        for (ByteArrayWrapper key : toRemoveSet) {
            this.getCache().delete(key.getData());
        // if (LOG.isTraceEnabled()) {
        // LOG.trace("Garbage collected node: [{}]",
        // Hex.toHexString(key.getData()));
        // }
        }
    }
}
Also used : ByteArrayWrapper(org.aion.base.util.ByteArrayWrapper) HashSet(java.util.HashSet)

Aggregations

ByteArrayWrapper (org.aion.base.util.ByteArrayWrapper)45 BigInteger (java.math.BigInteger)10 Address (org.aion.base.type.Address)5 ITransaction (org.aion.base.type.ITransaction)4 Entry (java.util.Map.Entry)3 DataWord (org.aion.mcf.vm.types.DataWord)3 AionBlock (org.aion.zero.impl.types.AionBlock)3 Test (org.junit.Test)3 java.util (java.util)2 SimpleEntry (java.util.AbstractMap.SimpleEntry)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 ImportResult (org.aion.mcf.core.ImportResult)2 Value (org.aion.rlp.Value)2 AccountState (org.aion.txpool.common.AccountState)2 TxDependList (org.aion.txpool.common.TxDependList)2 AionTxReceipt (org.aion.zero.types.AionTxReceipt)2