Search in sources :

Example 21 with DB

use of org.mapdb.DB in project eol-globi-data by jhpoelen.

the class ExporterAggregateUtil method exportDistinctInteractionsByStudy.

public static void exportDistinctInteractionsByStudy(Writer writer, GraphDatabaseService graphDatabase, RowWriter rowWriter) throws IOException {
    DB db = DBMaker.newMemoryDirectDB().compressionEnable().transactionDisable().make();
    final Map<Fun.Tuple3<Long, String, String>, List<String>> studyOccAggregate = db.createTreeMap("studyOccAggregate").make();
    NodeUtil.findStudies(graphDatabase, new StudyNodeListener() {

        @Override
        public void onStudy(StudyNode aStudy) {
            collectDistinctInteractions(aStudy, studyOccAggregate);
        }
    });
    for (Map.Entry<Fun.Tuple3<Long, String, String>, List<String>> distinctInteractions : studyOccAggregate.entrySet()) {
        rowWriter.writeRow(writer, new StudyNode(graphDatabase.getNodeById(distinctInteractions.getKey().a)), distinctInteractions.getKey().b, distinctInteractions.getKey().c, distinctInteractions.getValue());
    }
    db.close();
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) StudyNodeListener(org.eol.globi.util.StudyNodeListener) Map(java.util.Map) DB(org.mapdb.DB) StudyNode(org.eol.globi.domain.StudyNode)

Example 22 with DB

use of org.mapdb.DB in project eol-globi-data by jhpoelen.

the class TaxonInteractionIndexer method indexInteractions.

public void indexInteractions() {
    DB db = DBMaker.newMemoryDirectDB().compressionEnable().transactionDisable().make();
    final Map<Fun.Tuple3<Long, String, Long>, Long> taxonInteractions = db.createTreeMap("ottIdMap").make();
    collectTaxonInteractions(taxonInteractions);
    createTaxonInteractions(taxonInteractions);
    db.close();
}
Also used : DB(org.mapdb.DB)

Example 23 with DB

use of org.mapdb.DB in project rskj by rsksmart.

the class DefaultConfig method blockStore.

@Bean
public BlockStore blockStore(RskSystemProperties config) {
    String database = config.databaseDir();
    File blockIndexDirectory = new File(database + "/blocks/");
    File dbFile = new File(blockIndexDirectory, "index");
    if (!blockIndexDirectory.exists()) {
        boolean mkdirsSuccess = blockIndexDirectory.mkdirs();
        if (!mkdirsSuccess) {
            logger.error("Unable to create blocks directory: {}", blockIndexDirectory);
        }
    }
    DB indexDB = DBMaker.fileDB(dbFile).closeOnJvmShutdown().make();
    Map<Long, List<IndexedBlockStore.BlockInfo>> indexMap = indexDB.hashMapCreate("index").keySerializer(Serializer.LONG).valueSerializer(BLOCK_INFO_SERIALIZER).counterEnable().makeOrGet();
    KeyValueDataSource blocksDB = new LevelDbDataSource(config, "blocks");
    blocksDB.init();
    IndexedBlockStore indexedBlockStore = new IndexedBlockStore(indexMap, blocksDB, indexDB);
    return indexedBlockStore;
}
Also used : KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) List(java.util.List) LevelDbDataSource(org.ethereum.datasource.LevelDbDataSource) File(java.io.File) DB(org.mapdb.DB) Bean(org.springframework.context.annotation.Bean)

Example 24 with DB

use of org.mapdb.DB in project rskj by rsksmart.

the class IndexedBlockStoreTest method test7.

// leveldb + mapdb, multi branch, total re-branch test
@Test
public void test7() throws IOException {
    BigInteger bi = new BigInteger(32, new Random());
    String testDir = "test_db_" + bi;
    config.setDataBaseDir(testDir);
    DB indexDB = createMapDB(testDir);
    Map<Long, List<IndexedBlockStore.BlockInfo>> indexMap = createIndexMap(indexDB);
    KeyValueDataSource blocksDB = new LevelDbDataSource(config, "blocks");
    blocksDB.init();
    try {
        IndexedBlockStore indexedBlockStore = new IndexedBlockStore(indexMap, blocksDB, indexDB);
        Block genesis = Genesis.getInstance(config);
        List<Block> bestLine = getRandomChain(genesis.getHash().getBytes(), 1, 100);
        indexedBlockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
        BlockDifficulty td = genesis.getCumulativeDifficulty();
        for (int i = 0; i < bestLine.size(); ++i) {
            Block newBlock = bestLine.get(i);
            td = td.add(newBlock.getCumulativeDifficulty());
            indexedBlockStore.saveBlock(newBlock, td, true);
        }
        byte[] forkParentHash = bestLine.get(60).getHash().getBytes();
        long forkParentNumber = bestLine.get(60).getNumber();
        List<Block> forkLine = getRandomChain(forkParentHash, forkParentNumber + 1, 50);
        for (int i = 0; i < forkLine.size(); ++i) {
            Block newBlock = forkLine.get(i);
            Block parentBlock = indexedBlockStore.getBlockByHash(newBlock.getParentHash().getBytes());
            td = indexedBlockStore.getTotalDifficultyForHash(parentBlock.getHash().getBytes());
            td = td.add(newBlock.getCumulativeDifficulty());
            indexedBlockStore.saveBlock(newBlock, td, false);
        }
        Block bestBlock = bestLine.get(bestLine.size() - 1);
        Block forkBlock = forkLine.get(forkLine.size() - 1);
        indexedBlockStore.reBranch(forkBlock);
    } finally {
        blocksDB.close();
        indexDB.close();
        FileUtil.recursiveDelete(testDir);
    }
}
Also used : LevelDbDataSource(org.ethereum.datasource.LevelDbDataSource) BlockDifficulty(co.rsk.core.BlockDifficulty) BigInteger(java.math.BigInteger) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) Block(org.ethereum.core.Block) HashMapDB(org.ethereum.datasource.HashMapDB) DB(org.mapdb.DB) Test(org.junit.Test)

Aggregations

DB (org.mapdb.DB)24 Test (org.junit.Test)9 File (java.io.File)7 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)6 LevelDbDataSource (org.ethereum.datasource.LevelDbDataSource)6 BlockDifficulty (co.rsk.core.BlockDifficulty)5 IOException (java.io.IOException)5 BigInteger (java.math.BigInteger)5 Block (org.ethereum.core.Block)5 HashMapDB (org.ethereum.datasource.HashMapDB)5 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)3 BufferedReader (java.io.BufferedReader)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 ZipEntry (java.util.zip.ZipEntry)2 ZipInputStream (java.util.zip.ZipInputStream)2 NullOutputStream (org.apache.commons.io.output.NullOutputStream)2