20
20
import java .util .concurrent .ScheduledExecutorService ;
21
21
import java .util .concurrent .TimeUnit ;
22
22
import java .util .concurrent .atomic .AtomicInteger ;
23
- import java .util .concurrent .locks .LockSupport ;
24
23
import java .util .stream .Collectors ;
25
24
import javax .annotation .PostConstruct ;
26
25
import lombok .Getter ;
42
41
import org .tron .core .db2 .common .Value ;
43
42
import org .tron .core .db2 .common .WrappedByteArray ;
44
43
import org .tron .core .exception .RevokingStoreIllegalStateException ;
44
+ import org .tron .core .exception .TronError ;
45
45
import org .tron .core .store .CheckPointV2Store ;
46
46
import org .tron .core .store .CheckTmpStore ;
47
47
@@ -68,7 +68,6 @@ public class SnapshotManager implements RevokingDatabase {
68
68
69
69
private volatile int flushCount = 0 ;
70
70
71
- private Thread exitThread ;
72
71
private volatile boolean hitDown ;
73
72
74
73
private Map <String , ListeningExecutorService > flushServices = new HashMap <>();
@@ -105,15 +104,6 @@ public void init() {
105
104
}
106
105
}, 10000 , 3600 , TimeUnit .MILLISECONDS );
107
106
}
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 ();
117
107
}
118
108
119
109
public static String simpleDecode (byte [] bytes ) {
@@ -281,13 +271,6 @@ public void shutdown() {
281
271
ExecutorServiceManager .shutdownAndAwaitTermination (pruneCheckpointThread , pruneName );
282
272
flushServices .forEach ((key , value ) -> ExecutorServiceManager .shutdownAndAwaitTermination (value ,
283
273
"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
- }
291
274
}
292
275
293
276
public void updateSolidity (int hops ) {
@@ -298,7 +281,7 @@ public void updateSolidity(int hops) {
298
281
}
299
282
}
300
283
301
- private boolean shouldBeRefreshed () {
284
+ public boolean shouldBeRefreshed () {
302
285
return flushCount >= maxFlushCount ;
303
286
}
304
287
@@ -367,12 +350,12 @@ public void flush() {
367
350
} catch (TronDBException e ) {
368
351
logger .error (" Find fatal error, program will be exited soon." , e );
369
352
hitDown = true ;
370
- LockSupport . unpark ( exitThread );
353
+ throw new TronError ( e , TronError . ErrCode . DB_FLUSH );
371
354
}
372
355
}
373
356
}
374
357
375
- private void createCheckpoint () {
358
+ public void createCheckpoint () {
376
359
TronDatabase <byte []> checkPointStore = null ;
377
360
boolean syncFlag ;
378
361
try {
@@ -430,7 +413,7 @@ private TronDatabase<byte[]> getCheckpointDB(String dbName) {
430
413
return new CheckPointV2Store (CHECKPOINT_V2_DIR +"/" +dbName );
431
414
}
432
415
433
- private List <String > getCheckpointList () {
416
+ public List <String > getCheckpointList () {
434
417
String dbPath = Paths .get (StorageUtils .getOutputDirectoryByDbName (CHECKPOINT_V2_DIR ),
435
418
CommonParameter .getInstance ().getStorage ().getDbDirectory ()).toString ();
436
419
File file = new File (Paths .get (dbPath , CHECKPOINT_V2_DIR ).toString ());
@@ -490,10 +473,10 @@ public void check() {
490
473
if (!isV2Open ()) {
491
474
List <String > cpList = getCheckpointList ();
492
475
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 );
497
480
}
498
481
checkV1 ();
499
482
} else {
0 commit comments