@Test public void testUnloadSuperblockFromDB() throws FailedVerificationException { OpBlockChain opBlockChain = dbConsensusManager.init(metadataDb); generateMore30Blocks(formatter, opBlockChain, dbConsensusManager, BOOTSTRAP_LIST); dbConsensusManager.saveMainBlockchain(opBlockChain); final long[] amount = new long[1]; OpBlockChain blockChain = new OpBlockChain(opBlockChain.getParent(), opBlockChain.getBlockHeaders(0), dbConsensusManager.createDbAccess( opBlockChain.getSuperBlockHash(), opBlockChain.getSuperblockHeaders()), opBlockChain.getRules()); jdbcTemplate.query("SELECT COUNT(*) FROM " + BLOCKS_TABLE + " WHERE superblock is NOT NULL", rs -> { amount[0] = rs.getLong(1); }); assertEquals(40, amount[0]); dbConsensusManager.unloadSuperblockFromDB(blockChain); jdbcTemplate.query("SELECT COUNT(*) FROM " + BLOCKS_TABLE + " WHERE superblock is NOT NULL", rs -> { amount[0] = rs.getLong(1); }); assertEquals(0, amount[0]); }
public OpBlockChain unloadSuperblockFromDB(OpBlockChain blc) { if (blc.isDbAccessed()) { SuperblockDbAccess dba = dbSuperBlocks.get(blc.getSuperBlockHash()); final OpBlockChain res = new OpBlockChain(blc.getParent(), blc.getRules()); List<OpBlock> lst = new ArrayList<OpBlock>(blc.getSuperblockFullBlocks()); byte[] blockHash = SecUtils.getHashBytes(blc.getSuperBlockHash()); Collections.reverse(lst); for (OpBlock block : lst) { res.replicateBlock(block); } return txTemplate.execute(new TransactionCallback<OpBlockChain>() { @Override public OpBlockChain doInTransaction(TransactionStatus status) { dba.markAsStale(true); jdbcTemplate.update("UPDATE " + OPERATIONS_TABLE + " set superblock = NULL where superblock = ?", blockHash); jdbcTemplate.update("UPDATE " + BLOCKS_TABLE + " set superblock = NULL where superblock = ? ", blockHash); for (String objTable : dbSchema.getObjectTables()) { jdbcTemplate.update("DELETE FROM " + objTable + " where superblock = ?", blockHash); } return res; } }) ; } return blc; }
DBConsensusManager { public OpBlockChain unloadSuperblockFromDB(OpBlockChain blc) { if (blc.isDbAccessed()) { SuperblockDbAccess dba = dbSuperBlocks.get(blc.getSuperBlockHash()); final OpBlockChain res = new OpBlockChain(blc.getParent(), blc.getRules()); List<OpBlock> lst = new ArrayList<OpBlock>(blc.getSuperblockFullBlocks()); byte[] blockHash = SecUtils.getHashBytes(blc.getSuperBlockHash()); Collections.reverse(lst); for (OpBlock block : lst) { res.replicateBlock(block); } return txTemplate.execute(new TransactionCallback<OpBlockChain>() { @Override public OpBlockChain doInTransaction(TransactionStatus status) { dba.markAsStale(true); jdbcTemplate.update("UPDATE " + OPERATIONS_TABLE + " set superblock = NULL where superblock = ?", blockHash); jdbcTemplate.update("UPDATE " + BLOCKS_TABLE + " set superblock = NULL where superblock = ? ", blockHash); for (String objTable : dbSchema.getObjectTables()) { jdbcTemplate.update("DELETE FROM " + objTable + " where superblock = ?", blockHash); } return res; } }) ; } return blc; } }
DBConsensusManager { public OpBlockChain unloadSuperblockFromDB(OpBlockChain blc) { if (blc.isDbAccessed()) { SuperblockDbAccess dba = dbSuperBlocks.get(blc.getSuperBlockHash()); final OpBlockChain res = new OpBlockChain(blc.getParent(), blc.getRules()); List<OpBlock> lst = new ArrayList<OpBlock>(blc.getSuperblockFullBlocks()); byte[] blockHash = SecUtils.getHashBytes(blc.getSuperBlockHash()); Collections.reverse(lst); for (OpBlock block : lst) { res.replicateBlock(block); } return txTemplate.execute(new TransactionCallback<OpBlockChain>() { @Override public OpBlockChain doInTransaction(TransactionStatus status) { dba.markAsStale(true); jdbcTemplate.update("UPDATE " + OPERATIONS_TABLE + " set superblock = NULL where superblock = ?", blockHash); jdbcTemplate.update("UPDATE " + BLOCKS_TABLE + " set superblock = NULL where superblock = ? ", blockHash); for (String objTable : dbSchema.getObjectTables()) { jdbcTemplate.update("DELETE FROM " + objTable + " where superblock = ?", blockHash); } return res; } }) ; } return blc; }  }
DBConsensusManager { public OpBlockChain unloadSuperblockFromDB(OpBlockChain blc) { if (blc.isDbAccessed()) { SuperblockDbAccess dba = dbSuperBlocks.get(blc.getSuperBlockHash()); final OpBlockChain res = new OpBlockChain(blc.getParent(), blc.getRules()); List<OpBlock> lst = new ArrayList<OpBlock>(blc.getSuperblockFullBlocks()); byte[] blockHash = SecUtils.getHashBytes(blc.getSuperBlockHash()); Collections.reverse(lst); for (OpBlock block : lst) { res.replicateBlock(block); } return txTemplate.execute(new TransactionCallback<OpBlockChain>() { @Override public OpBlockChain doInTransaction(TransactionStatus status) { dba.markAsStale(true); jdbcTemplate.update("UPDATE " + OPERATIONS_TABLE + " set superblock = NULL where superblock = ?", blockHash); jdbcTemplate.update("UPDATE " + BLOCKS_TABLE + " set superblock = NULL where superblock = ? ", blockHash); for (String objTable : dbSchema.getObjectTables()) { jdbcTemplate.update("DELETE FROM " + objTable + " where superblock = ?", blockHash); } return res; } }) ; } return blc; }  Map<String, OpBlock> getOrphanedBlocks(); String getSuperblockHash(); OpBlockChain init(MetadataDb metadataDB); OpIndexColumn getIndex(String type, String columnId); Collection<OpIndexColumn> getIndicesForType(String type); void insertBlock(OpBlock opBlock); OpBlockChain saveMainBlockchain(OpBlockChain blc); OpBlockChain compact(int prevSize, OpBlockChain blc, boolean db); int removeOperations(Set<String> ops); boolean removeFullBlock(OpBlock block); OpBlockChain unloadSuperblockFromDB(OpBlockChain blc); ResourceDTO storeResourceObject(ResourceDTO imageDTO); ResourceDTO getResourceObjectIfExists(ResourceDTO imageDTO); List<ResourceDTO> getResources(boolean status, int addedMoreThanSecondsAgo); void removeResource(ResourceDTO resDTO); void updateResourceActiveStatus(ResourceDTO imageDTO, boolean status); Long getAmountResourcesInDB(); boolean validateExistingOperation(OpOperation op); void insertOperation(OpOperation op); OpOperation getOperationByHash(String hash); String getSetting(String key); Map<String, Map<String, OpIndexColumn>> getIndices(); }
DBConsensusManager { public OpBlockChain unloadSuperblockFromDB(OpBlockChain blc) { if (blc.isDbAccessed()) { SuperblockDbAccess dba = dbSuperBlocks.get(blc.getSuperBlockHash()); final OpBlockChain res = new OpBlockChain(blc.getParent(), blc.getRules()); List<OpBlock> lst = new ArrayList<OpBlock>(blc.getSuperblockFullBlocks()); byte[] blockHash = SecUtils.getHashBytes(blc.getSuperBlockHash()); Collections.reverse(lst); for (OpBlock block : lst) { res.replicateBlock(block); } return txTemplate.execute(new TransactionCallback<OpBlockChain>() { @Override public OpBlockChain doInTransaction(TransactionStatus status) { dba.markAsStale(true); jdbcTemplate.update("UPDATE " + OPERATIONS_TABLE + " set superblock = NULL where superblock = ?", blockHash); jdbcTemplate.update("UPDATE " + BLOCKS_TABLE + " set superblock = NULL where superblock = ? ", blockHash); for (String objTable : dbSchema.getObjectTables()) { jdbcTemplate.update("DELETE FROM " + objTable + " where superblock = ?", blockHash); } return res; } }) ; } return blc; }  Map<String, OpBlock> getOrphanedBlocks(); String getSuperblockHash(); OpBlockChain init(MetadataDb metadataDB); OpIndexColumn getIndex(String type, String columnId); Collection<OpIndexColumn> getIndicesForType(String type); void insertBlock(OpBlock opBlock); OpBlockChain saveMainBlockchain(OpBlockChain blc); OpBlockChain compact(int prevSize, OpBlockChain blc, boolean db); int removeOperations(Set<String> ops); boolean removeFullBlock(OpBlock block); OpBlockChain unloadSuperblockFromDB(OpBlockChain blc); ResourceDTO storeResourceObject(ResourceDTO imageDTO); ResourceDTO getResourceObjectIfExists(ResourceDTO imageDTO); List<ResourceDTO> getResources(boolean status, int addedMoreThanSecondsAgo); void removeResource(ResourceDTO resDTO); void updateResourceActiveStatus(ResourceDTO imageDTO, boolean status); Long getAmountResourcesInDB(); boolean validateExistingOperation(OpOperation op); void insertOperation(OpOperation op); OpOperation getOperationByHash(String hash); String getSetting(String key); Map<String, Map<String, OpIndexColumn>> getIndices();  }