@@ -355,15 +355,7 @@ private void generateInfoProperties(String propertyfile, long num)
355355 private long getLatestBlockHeaderNum (String databaseDir ) throws IOException , RocksDBException {
356356 // query latest_block_header_number from checkpoint first
357357 final String latestBlockHeaderNumber = "latest_block_header_number" ;
358- List <String > cpList = getCheckpointV2List (databaseDir );
359- DBInterface checkpointDb ;
360- if (cpList .size () > 0 ) {
361- String lastestCp = cpList .get (cpList .size () - 1 );
362- checkpointDb = DbTool .getDB (
363- databaseDir + "/" + DBUtils .CHECKPOINT_DB_V2 , lastestCp );
364- } else {
365- checkpointDb = DbTool .getDB (databaseDir , CHECKPOINT_DB );
366- }
358+ DBInterface checkpointDb = getCheckpointDb (databaseDir );
367359 Long blockNumber = getLatestBlockHeaderNumFromCP (checkpointDb ,
368360 latestBlockHeaderNumber .getBytes ());
369361 if (blockNumber != null ) {
@@ -594,7 +586,7 @@ private void mergeBak2Database(String liteDir, BlockNumInfo blockNumInfo) throws
594586 private byte [] getDataFromSourceDB (String sourceDir , String dbName , byte [] key )
595587 throws IOException , RocksDBException {
596588 DBInterface sourceDb = DbTool .getDB (sourceDir , dbName );
597- DBInterface checkpointDb = DbTool . getDB (sourceDir , CHECKPOINT_DB );
589+ DBInterface checkpointDb = getCheckpointDb (sourceDir );
598590 // get data from tmp first.
599591 byte [] valueFromTmp = checkpointDb .get (Bytes .concat (simpleEncode (dbName ), key ));
600592 byte [] value ;
@@ -672,6 +664,19 @@ private long getSecondBlock(String databaseDir) throws RocksDBException, IOExcep
672664 return num ;
673665 }
674666
667+ private DBInterface getCheckpointDb (String sourceDir ) throws IOException , RocksDBException {
668+ List <String > cpList = getCheckpointV2List (sourceDir );
669+ DBInterface checkpointDb ;
670+ if (cpList .size () > 0 ) {
671+ String latestCp = cpList .get (cpList .size () - 1 );
672+ checkpointDb = DbTool .getDB (
673+ sourceDir + "/" + DBUtils .CHECKPOINT_DB_V2 , latestCp );
674+ } else {
675+ checkpointDb = DbTool .getDB (sourceDir , CHECKPOINT_DB );
676+ }
677+ return checkpointDb ;
678+ }
679+
675680 @ VisibleForTesting
676681 public static void setRecentBlks (long recentBlks ) {
677682 RECENT_BLKS = recentBlks ;
0 commit comments