@@ -355,15 +355,7 @@ private void generateInfoProperties(String propertyfile, long num)
355
355
private long getLatestBlockHeaderNum (String databaseDir ) throws IOException , RocksDBException {
356
356
// query latest_block_header_number from checkpoint first
357
357
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 );
367
359
Long blockNumber = getLatestBlockHeaderNumFromCP (checkpointDb ,
368
360
latestBlockHeaderNumber .getBytes ());
369
361
if (blockNumber != null ) {
@@ -594,7 +586,7 @@ private void mergeBak2Database(String liteDir, BlockNumInfo blockNumInfo) throws
594
586
private byte [] getDataFromSourceDB (String sourceDir , String dbName , byte [] key )
595
587
throws IOException , RocksDBException {
596
588
DBInterface sourceDb = DbTool .getDB (sourceDir , dbName );
597
- DBInterface checkpointDb = DbTool . getDB (sourceDir , CHECKPOINT_DB );
589
+ DBInterface checkpointDb = getCheckpointDb (sourceDir );
598
590
// get data from tmp first.
599
591
byte [] valueFromTmp = checkpointDb .get (Bytes .concat (simpleEncode (dbName ), key ));
600
592
byte [] value ;
@@ -672,6 +664,19 @@ private long getSecondBlock(String databaseDir) throws RocksDBException, IOExcep
672
664
return num ;
673
665
}
674
666
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
+
675
680
@ VisibleForTesting
676
681
public static void setRecentBlks (long recentBlks ) {
677
682
RECENT_BLKS = recentBlks ;
0 commit comments