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);
}
}
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;
}
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();
}
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);
}
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()));
// }
}
}
}
Aggregations