@Test public void testInconsistentDumpsLoading() { List<Path> reversed = new ArrayList<>(dumps); Collections.reverse(reversed); Path[] paths = reversed.toArray(new Path[]{}); boolean loaded = blockLoader.loadBlocks(paths); assertFalse(loaded); }
public boolean loadBlocks(Function<Path, DumpWalker> walkerFactory, Path... paths) { if (ArrayUtils.isEmpty(paths)) { logger.warn("There is nothing to import."); return false; } initPipelines(); AtomicLong maxBlockNumber = new AtomicLong(); boolean allBlocksImported; try { for (Path dump : paths) { try (DumpWalker walker = walkerFactory.apply(dump)) { walker.forEach(rlp -> { Block block = new Block(rlp); if (maxBlockNumber.get() < block.getNumber()) { maxBlockNumber.set(block.getNumber()); } exec1.push(block); }); } } exec1.join(); dbFlushManager.flushSync(); allBlocksImported = maxBlockNumber.get() == blockchain.getBestBlock().getNumber(); } catch (Exception e) { e.printStackTrace(); allBlocksImported = false; } if (allBlocksImported) { System.out.printf("All of %s blocks was successfully loaded.\n", maxBlockNumber); } else { System.out.printf("Some blocks have been lost during the loading."); } return allBlocksImported; }
BlockLoader { public boolean loadBlocks(Function<Path, DumpWalker> walkerFactory, Path... paths) { if (ArrayUtils.isEmpty(paths)) { logger.warn("There is nothing to import."); return false; } initPipelines(); AtomicLong maxBlockNumber = new AtomicLong(); boolean allBlocksImported; try { for (Path dump : paths) { try (DumpWalker walker = walkerFactory.apply(dump)) { walker.forEach(rlp -> { Block block = new Block(rlp); if (maxBlockNumber.get() < block.getNumber()) { maxBlockNumber.set(block.getNumber()); } exec1.push(block); }); } } exec1.join(); dbFlushManager.flushSync(); allBlocksImported = maxBlockNumber.get() == blockchain.getBestBlock().getNumber(); } catch (Exception e) { e.printStackTrace(); allBlocksImported = false; } if (allBlocksImported) { System.out.printf("All of %s blocks was successfully loaded.\n", maxBlockNumber); } else { System.out.printf("Some blocks have been lost during the loading."); } return allBlocksImported; } }
BlockLoader { public boolean loadBlocks(Function<Path, DumpWalker> walkerFactory, Path... paths) { if (ArrayUtils.isEmpty(paths)) { logger.warn("There is nothing to import."); return false; } initPipelines(); AtomicLong maxBlockNumber = new AtomicLong(); boolean allBlocksImported; try { for (Path dump : paths) { try (DumpWalker walker = walkerFactory.apply(dump)) { walker.forEach(rlp -> { Block block = new Block(rlp); if (maxBlockNumber.get() < block.getNumber()) { maxBlockNumber.set(block.getNumber()); } exec1.push(block); }); } } exec1.join(); dbFlushManager.flushSync(); allBlocksImported = maxBlockNumber.get() == blockchain.getBestBlock().getNumber(); } catch (Exception e) { e.printStackTrace(); allBlocksImported = false; } if (allBlocksImported) { System.out.printf("All of %s blocks was successfully loaded.\n", maxBlockNumber); } else { System.out.printf("Some blocks have been lost during the loading."); } return allBlocksImported; } @Autowired  BlockLoader(BlockHeaderValidator headerValidator, Blockchain blockchain, DbFlushManager dbFlushManager); }
BlockLoader { public boolean loadBlocks(Function<Path, DumpWalker> walkerFactory, Path... paths) { if (ArrayUtils.isEmpty(paths)) { logger.warn("There is nothing to import."); return false; } initPipelines(); AtomicLong maxBlockNumber = new AtomicLong(); boolean allBlocksImported; try { for (Path dump : paths) { try (DumpWalker walker = walkerFactory.apply(dump)) { walker.forEach(rlp -> { Block block = new Block(rlp); if (maxBlockNumber.get() < block.getNumber()) { maxBlockNumber.set(block.getNumber()); } exec1.push(block); }); } } exec1.join(); dbFlushManager.flushSync(); allBlocksImported = maxBlockNumber.get() == blockchain.getBestBlock().getNumber(); } catch (Exception e) { e.printStackTrace(); allBlocksImported = false; } if (allBlocksImported) { System.out.printf("All of %s blocks was successfully loaded.\n", maxBlockNumber); } else { System.out.printf("Some blocks have been lost during the loading."); } return allBlocksImported; } @Autowired  BlockLoader(BlockHeaderValidator headerValidator, Blockchain blockchain, DbFlushManager dbFlushManager); boolean loadBlocks(Function<Path, DumpWalker> walkerFactory, Path... paths); boolean loadBlocks(Path... paths); }
BlockLoader { public boolean loadBlocks(Function<Path, DumpWalker> walkerFactory, Path... paths) { if (ArrayUtils.isEmpty(paths)) { logger.warn("There is nothing to import."); return false; } initPipelines(); AtomicLong maxBlockNumber = new AtomicLong(); boolean allBlocksImported; try { for (Path dump : paths) { try (DumpWalker walker = walkerFactory.apply(dump)) { walker.forEach(rlp -> { Block block = new Block(rlp); if (maxBlockNumber.get() < block.getNumber()) { maxBlockNumber.set(block.getNumber()); } exec1.push(block); }); } } exec1.join(); dbFlushManager.flushSync(); allBlocksImported = maxBlockNumber.get() == blockchain.getBestBlock().getNumber(); } catch (Exception e) { e.printStackTrace(); allBlocksImported = false; } if (allBlocksImported) { System.out.printf("All of %s blocks was successfully loaded.\n", maxBlockNumber); } else { System.out.printf("Some blocks have been lost during the loading."); } return allBlocksImported; } @Autowired  BlockLoader(BlockHeaderValidator headerValidator, Blockchain blockchain, DbFlushManager dbFlushManager); boolean loadBlocks(Function<Path, DumpWalker> walkerFactory, Path... paths); boolean loadBlocks(Path... paths);  }