45
45
import com .evolvedbinary .j8fu .function .SupplierE ;
46
46
import org .exist .util .sanity .SanityCheck ;
47
47
48
+ import javax .annotation .Nullable ;
49
+
48
50
/**
49
51
* Database recovery. This class is used once during startup to check
50
52
* if the database is in a consistent state. If not, the class attempts to recover
@@ -59,11 +61,13 @@ public class RecoveryManager {
59
61
private final DBBroker broker ;
60
62
private final JournalRecoveryAccessor journalRecovery ;
61
63
private final boolean restartOnError ;
64
+ private final boolean hideProgressBar ;
62
65
63
66
public RecoveryManager (final DBBroker broker , final JournalManager journalManager , final boolean restartOnError ) {
64
67
this .broker = broker ;
65
68
this .journalRecovery = journalManager .getRecoveryAccessor (this );
66
69
this .restartOnError = restartOnError ;
70
+ this .hideProgressBar = Boolean .getBoolean ("exist.recovery.progressbar.hide" );
67
71
}
68
72
69
73
/**
@@ -121,7 +125,7 @@ public boolean recover() throws LogException {
121
125
Loggable next ;
122
126
try {
123
127
final long lastSize = FileUtils .sizeQuietly (last );
124
- final ProgressBar scanProgressBar = new ProgressBar ("Scanning journal " , lastSize );
128
+ @ Nullable final ProgressBar scanProgressBar = hideProgressBar ? null : new ProgressBar ("Scanning journal " , lastSize );
125
129
while ((next = reader .nextEntry ()) != null ) {
126
130
// LOG.debug(next.dump());
127
131
if (next .getLogType () == LogEntryTypes .TXN_START ) {
@@ -136,9 +140,14 @@ public boolean recover() throws LogException {
136
140
}
137
141
lastLsn = next .getLsn ();
138
142
139
- scanProgressBar .set (next .getLsn ().getOffset ());
143
+ if (scanProgressBar != null ) {
144
+ scanProgressBar .set (next .getLsn ().getOffset ());
145
+ }
146
+ }
147
+
148
+ if (scanProgressBar != null ) {
149
+ scanProgressBar .set (lastSize ); // 100%
140
150
}
141
- scanProgressBar .set (lastSize ); // 100%
142
151
} catch (final LogException e ) {
143
152
if (LOG .isDebugEnabled ()) {
144
153
LOG .debug ("Caught exception while reading log" , e );
@@ -257,7 +266,7 @@ private void doRecovery(final int txnCount, final Path last, final JournalReader
257
266
int redoCnt = 0 ;
258
267
try {
259
268
final long lastSize = FileUtils .sizeQuietly (last );
260
- final ProgressBar redoProgressBar = new ProgressBar ("Redo " , lastSize );
269
+ @ Nullable final ProgressBar redoProgressBar = hideProgressBar ? null : new ProgressBar ("Redo " , lastSize );
261
270
while ((next = reader .nextEntry ()) != null ) {
262
271
SanityCheck .ASSERT (next .getLogType () != LogEntryTypes .CHECKPOINT ,
263
272
"Found a checkpoint during recovery run! This should not ever happen." );
@@ -275,13 +284,20 @@ private void doRecovery(final int txnCount, final Path last, final JournalReader
275
284
// LOG.debug("Redo: " + next.dump());
276
285
// redo the log entry
277
286
next .redo ();
278
- redoProgressBar .set (next .getLsn ().getOffset ());
287
+
288
+ if (redoProgressBar != null ) {
289
+ redoProgressBar .set (next .getLsn ().getOffset ());
290
+ }
291
+
279
292
if (next .getLsn ().equals (lastLsn )) {
280
293
// last readable entry reached. Stop here.
281
294
break ;
282
295
}
283
296
}
284
- redoProgressBar .set (lastSize ); // 100% done
297
+
298
+ if (redoProgressBar != null ) {
299
+ redoProgressBar .set (lastSize ); // 100% done
300
+ }
285
301
} catch (final Exception e ) {
286
302
LOG .error ("Exception caught while redoing transactions. Aborting recovery to avoid possible damage. " +
287
303
"Before starting again, make sure to run a check via the emergency export tool." , e );
@@ -302,8 +318,8 @@ private void doRecovery(final int txnCount, final Path last, final JournalReader
302
318
// do a reverse scan of the log, undoing all uncommitted transactions
303
319
try {
304
320
final long lastSize = FileUtils .sizeQuietly (last );
305
- final ProgressBar undoProgressBar = new ProgressBar ("Undo " , lastSize );
306
- while ((next = reader .previousEntry ()) != null ) {
321
+ final ProgressBar undoProgressBar = hideProgressBar ? null : new ProgressBar ("Undo " , lastSize );
322
+ while ((next = reader .previousEntry ()) != null ) {
307
323
if (next .getLogType () == LogEntryTypes .TXN_START ) {
308
324
if (runningTxns .get (next .getTransactionId ()) != null ) {
309
325
runningTxns .remove (next .getTransactionId ());
@@ -325,9 +341,14 @@ private void doRecovery(final int txnCount, final Path last, final JournalReader
325
341
next .undo ();
326
342
}
327
343
328
- undoProgressBar .set (lastSize - next .getLsn ().getOffset ());
344
+ if (undoProgressBar != null ) {
345
+ undoProgressBar .set (lastSize - next .getLsn ().getOffset ());
346
+ }
347
+ }
348
+
349
+ if (undoProgressBar != null ) {
350
+ undoProgressBar .set (lastSize ); // 100% done
329
351
}
330
- undoProgressBar .set (lastSize ); // 100% done
331
352
} catch (final Exception e ) {
332
353
LOG .warn ("Exception caught while undoing dirty transactions. Remaining transactions to be undone: {}. Aborting recovery to avoid possible damage. Before starting again, make sure to run a check via the emergency export tool." , runningTxns .size (), e );
333
354
if (next != null )
0 commit comments