Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Flush column family #1682

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -408,22 +408,27 @@ public List<byte[]> loadAllKeysFromTable(Class<? extends Persistable> column) {
}

private void flushHandle(ColumnFamilyHandle handle) throws RocksDBException {
List<byte[]> itemsToDelete = new ArrayList<>();
try (RocksIterator iterator = db.newIterator(handle)) {

for (iterator.seekToLast(); iterator.isValid(); iterator.prev()) {
itemsToDelete.add(iterator.key());
}
}
if (!itemsToDelete.isEmpty()) {
log.info("Amount to delete: " + itemsToDelete.size());
}
int counter = 0;
for (byte[] itemToDelete : itemsToDelete) {
if (++counter % 10000 == 0) {
log.info("Deleted: {}", counter);
try (WriteBatch delBatch = new WriteBatch();
WriteOptions writeOptions = new WriteOptions()
//We are explicit about what happens if the node reboots before a flush to the db
.setDisableWAL(false)
//We want to make sure deleted data was indeed deleted
.setSync(true)) {
int counter = 0;
try (RocksIterator iterator = db.newIterator(handle)) {
for (iterator.seekToLast(); iterator.isValid(); iterator.prev()) {
delBatch.delete(handle, iterator.key());
if (++counter % 10000 == 0) {
db.write(writeOptions, delBatch);
log.info("Deleted: {}", counter);
delBatch.clear();
}
}
}
db.delete(handle, itemToDelete);

//delete remaining
db.write(writeOptions, delBatch);
log.info("Deleted {} entries in total", counter);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package com.iota.iri.storage.rocksDB;

import com.iota.iri.TransactionTestUtils;
import com.iota.iri.model.Hash;
import com.iota.iri.model.IntegerIndex;
import com.iota.iri.model.persistables.Transaction;
import com.iota.iri.storage.Indexable;
import com.iota.iri.storage.Persistable;
import com.iota.iri.storage.Tangle;
import com.iota.iri.utils.Pair;
import org.apache.commons.io.FileUtils;
import org.junit.*;
import org.junit.runners.MethodSorters;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import org.apache.commons.io.FileUtils;
import org.junit.*;
import org.junit.runners.MethodSorters;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class RocksDBPersistenceProviderTest {

Expand Down Expand Up @@ -76,4 +79,17 @@ public void testDeleteBatch() throws Exception {
rocksDBPersistenceProvider.get(Transaction.class, index).bytes());
}
}

@Test
public void testClear() throws Exception {
Transaction tx = TransactionTestUtils.buildTransaction(TransactionTestUtils.getTransactionTrits());
Hash hash = TransactionTestUtils.getTransactionHash();
rocksDBPersistenceProvider.save(tx, hash);
Assert.assertTrue("Tx isn't found in DB after it was saved",
rocksDBPersistenceProvider.exists(Transaction.class, hash));
rocksDBPersistenceProvider.clear(Transaction.class);
rocksDBPersistenceProvider.clearMetadata(Transaction.class);
Assert.assertFalse("Tx is found in DB after it was cleared",
rocksDBPersistenceProvider.exists(Transaction.class, hash));
}
}