2020import java .util .concurrent .ScheduledExecutorService ;
2121import java .util .concurrent .TimeUnit ;
2222import java .util .concurrent .atomic .AtomicInteger ;
23- import java .util .concurrent .locks .LockSupport ;
2423import java .util .stream .Collectors ;
2524import javax .annotation .PostConstruct ;
2625import lombok .Getter ;
4241import org .tron .core .db2 .common .Value ;
4342import org .tron .core .db2 .common .WrappedByteArray ;
4443import org .tron .core .exception .RevokingStoreIllegalStateException ;
44+ import org .tron .core .exception .TronError ;
4545import org .tron .core .store .CheckPointV2Store ;
4646import org .tron .core .store .CheckTmpStore ;
4747
@@ -68,7 +68,6 @@ public class SnapshotManager implements RevokingDatabase {
6868
6969 private volatile int flushCount = 0 ;
7070
71- private Thread exitThread ;
7271 private volatile boolean hitDown ;
7372
7473 private Map <String , ListeningExecutorService > flushServices = new HashMap <>();
@@ -105,15 +104,6 @@ public void init() {
105104 }
106105 }, 10000 , 3600 , TimeUnit .MILLISECONDS );
107106 }
108- exitThread = new Thread (() -> {
109- LockSupport .park ();
110- // to Guarantee Some other thread invokes unpark with the current thread as the target
111- if (hitDown ) {
112- System .exit (1 );
113- }
114- });
115- exitThread .setName ("exit-thread" );
116- exitThread .start ();
117107 }
118108
119109 public static String simpleDecode (byte [] bytes ) {
@@ -281,13 +271,6 @@ public void shutdown() {
281271 ExecutorServiceManager .shutdownAndAwaitTermination (pruneCheckpointThread , pruneName );
282272 flushServices .forEach ((key , value ) -> ExecutorServiceManager .shutdownAndAwaitTermination (value ,
283273 "flush-service-" + key ));
284- try {
285- exitThread .interrupt ();
286- // help GC
287- exitThread = null ;
288- } catch (Exception e ) {
289- logger .warn ("exitThread interrupt error" , e );
290- }
291274 }
292275
293276 public void updateSolidity (int hops ) {
@@ -298,7 +281,7 @@ public void updateSolidity(int hops) {
298281 }
299282 }
300283
301- private boolean shouldBeRefreshed () {
284+ public boolean shouldBeRefreshed () {
302285 return flushCount >= maxFlushCount ;
303286 }
304287
@@ -367,12 +350,12 @@ public void flush() {
367350 } catch (TronDBException e ) {
368351 logger .error (" Find fatal error, program will be exited soon." , e );
369352 hitDown = true ;
370- LockSupport . unpark ( exitThread );
353+ throw new TronError ( e , TronError . ErrCode . DB_FLUSH );
371354 }
372355 }
373356 }
374357
375- private void createCheckpoint () {
358+ public void createCheckpoint () {
376359 TronDatabase <byte []> checkPointStore = null ;
377360 boolean syncFlag ;
378361 try {
@@ -430,7 +413,7 @@ private TronDatabase<byte[]> getCheckpointDB(String dbName) {
430413 return new CheckPointV2Store (CHECKPOINT_V2_DIR +"/" +dbName );
431414 }
432415
433- private List <String > getCheckpointList () {
416+ public List <String > getCheckpointList () {
434417 String dbPath = Paths .get (StorageUtils .getOutputDirectoryByDbName (CHECKPOINT_V2_DIR ),
435418 CommonParameter .getInstance ().getStorage ().getDbDirectory ()).toString ();
436419 File file = new File (Paths .get (dbPath , CHECKPOINT_V2_DIR ).toString ());
@@ -490,10 +473,10 @@ public void check() {
490473 if (!isV2Open ()) {
491474 List <String > cpList = getCheckpointList ();
492475 if (cpList != null && cpList .size () != 0 ) {
493- logger . error ( "checkpoint check failed, the checkpoint version of database not match your " +
494- "config file, please set storage.checkpoint.version = 2 in your config file " +
495- "and restart the node." ) ;
496- System . exit (- 1 );
476+ String msg = "checkpoint check failed, the checkpoint version of database not match your "
477+ + "config file, please set storage.checkpoint.version = 2 in your config file "
478+ + "and restart the node." ;
479+ throw new TronError ( msg , TronError . ErrCode . CHECKPOINT_VERSION );
497480 }
498481 checkV1 ();
499482 } else {
0 commit comments