@ -60,11 +60,12 @@ public class TrieLogHelper {
private static final int ROCKSDB_MAX_INSERTS_PER_TRANSACTION = 1000 ;
private static final int ROCKSDB_MAX_INSERTS_PER_TRANSACTION = 1000 ;
private static final Logger LOG = LoggerFactory . getLogger ( TrieLogHelper . class ) ;
private static final Logger LOG = LoggerFactory . getLogger ( TrieLogHelper . class ) ;
void prune (
boolean prune (
final DataStorageConfiguration config ,
final DataStorageConfiguration config ,
final BonsaiWorldStateKeyValueStorage rootWorldStateStorage ,
final BonsaiWorldStateKeyValueStorage rootWorldStateStorage ,
final MutableBlockchain blockchain ,
final MutableBlockchain blockchain ,
final Path dataDirectoryPath ) {
final Path dataDirectoryPath ) {
final String batchFileNameBase =
final String batchFileNameBase =
dataDirectoryPath . resolve ( DATABASE_PATH ) . resolve ( TRIE_LOG_FILE ) . toString ( ) ;
dataDirectoryPath . resolve ( DATABASE_PATH ) . resolve ( TRIE_LOG_FILE ) . toString ( ) ;
@ -82,10 +83,14 @@ public class TrieLogHelper {
lastBlockNumberToRetainTrieLogsFor ,
lastBlockNumberToRetainTrieLogsFor ,
rootWorldStateStorage ,
rootWorldStateStorage ,
layersToRetain ) ) {
layersToRetain ) ) {
return ;
return false ;
}
}
final long numberOfBatches = calculateNumberOfBatches ( layersToRetain ) ;
final long numberOfBatches = calculateNumberOfBatches ( layersToRetain ) ;
LOG . info (
"Starting pruning: retain {} trie logs, processing in {} batches..." ,
layersToRetain ,
numberOfBatches ) ;
processTrieLogBatches (
processTrieLogBatches (
rootWorldStateStorage ,
rootWorldStateStorage ,
@ -102,7 +107,7 @@ public class TrieLogHelper {
. count ( ) ;
. count ( ) ;
if ( countAfterPrune = = layersToRetain ) {
if ( countAfterPrune = = layersToRetain ) {
if ( deleteFiles ( batchFileNameBase , numberOfBatches ) ) {
if ( deleteFiles ( batchFileNameBase , numberOfBatches ) ) {
LOG . info ( "Prune ran successfully. Enjoy some disk space back! \uD83D\uDE80" ) ;
return true ;
} else {
} else {
throw new IllegalStateException (
throw new IllegalStateException (
"There was an error deleting the trie log backup files. Please ensure besu is working before deleting them manually." ) ;
"There was an error deleting the trie log backup files. Please ensure besu is working before deleting them manually." ) ;
@ -110,8 +115,11 @@ public class TrieLogHelper {
} else {
} else {
throw new IllegalStateException (
throw new IllegalStateException (
String . format (
String . format (
"Remaining trie logs (%d) did not match %s (%d). Trie logs backup files have not been deleted, it is safe to rerun the subcommand." ,
"Remaining trie logs (%d) did not match %s (%d). Trie logs backup files (in %s) have not been deleted, it is safe to rerun the subcommand." ,
countAfterPrune , BONSAI_STORAGE_FORMAT_MAX_LAYERS_TO_LOAD , layersToRetain ) ) ;
countAfterPrune ,
BONSAI_STORAGE_FORMAT_MAX_LAYERS_TO_LOAD ,
layersToRetain ,
batchFileNameBase ) ) ;
}
}
}
}
@ -131,7 +139,7 @@ public class TrieLogHelper {
final List < Hash > trieLogKeys =
final List < Hash > trieLogKeys =
getTrieLogKeysForBlocks ( blockchain , firstBlockOfBatch , lastBlockOfBatch ) ;
getTrieLogKeysForBlocks ( blockchain , firstBlockOfBatch , lastBlockOfBatch ) ;
LOG . info ( "Saving trie logs to retain in file (batch {})..." , batchNumber ) ;
LOG . info ( "Saving trie logs to retain in file {} (batch {})..." , batchFileName , batchNumber ) ;
saveTrieLogBatches ( batchFileName , rootWorldStateStorage , trieLogKeys ) ;
saveTrieLogBatches ( batchFileName , rootWorldStateStorage , trieLogKeys ) ;
}
}
@ -319,7 +327,7 @@ public class TrieLogHelper {
File file = new File ( batchFileName ) ;
File file = new File ( batchFileName ) ;
if ( file . exists ( ) ) {
if ( file . exists ( ) ) {
LOG . error ( "File already exists, skipping file creation" ) ;
LOG . warn ( "File already exists {} , skipping file creation" , batchFileName ) ;
return ;
return ;
}
}
@ -354,7 +362,7 @@ public class TrieLogHelper {
final String batchFileName ) {
final String batchFileName ) {
File file = new File ( batchFileName ) ;
File file = new File ( batchFileName ) ;
if ( file . exists ( ) ) {
if ( file . exists ( ) ) {
LOG . error ( "File already exists, skipping file creation" ) ;
LOG . warn ( "File already exists {} , skipping file creation" , batchFileName ) ;
return ;
return ;
}
}