Skip to content

Commit 9356ee2

Browse files
committed
[feature] Add the System Property 'exist.recovery.progressbar.hide' to hide the Journal Recovery progress bars
1 parent e8f7135 commit 9356ee2

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

exist-core/src/main/java/org/exist/storage/recovery/RecoveryManager.java

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
import com.evolvedbinary.j8fu.function.SupplierE;
4646
import org.exist.util.sanity.SanityCheck;
4747

48+
import javax.annotation.Nullable;
49+
4850
/**
4951
* Database recovery. This class is used once during startup to check
5052
* if the database is in a consistent state. If not, the class attempts to recover
@@ -59,11 +61,13 @@ public class RecoveryManager {
5961
private final DBBroker broker;
6062
private final JournalRecoveryAccessor journalRecovery;
6163
private final boolean restartOnError;
64+
private final boolean hideProgressBar;
6265

6366
public RecoveryManager(final DBBroker broker, final JournalManager journalManager, final boolean restartOnError) {
6467
this.broker = broker;
6568
this.journalRecovery = journalManager.getRecoveryAccessor(this);
6669
this.restartOnError = restartOnError;
70+
this.hideProgressBar = Boolean.getBoolean("exist.recovery.progressbar.hide");
6771
}
6872

6973
/**
@@ -121,7 +125,7 @@ public boolean recover() throws LogException {
121125
Loggable next;
122126
try {
123127
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);
125129
while ((next = reader.nextEntry()) != null) {
126130
// LOG.debug(next.dump());
127131
if (next.getLogType() == LogEntryTypes.TXN_START) {
@@ -136,9 +140,14 @@ public boolean recover() throws LogException {
136140
}
137141
lastLsn = next.getLsn();
138142

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%
140150
}
141-
scanProgressBar.set(lastSize); // 100%
142151
} catch (final LogException e) {
143152
if (LOG.isDebugEnabled()) {
144153
LOG.debug("Caught exception while reading log", e);
@@ -257,7 +266,7 @@ private void doRecovery(final int txnCount, final Path last, final JournalReader
257266
int redoCnt = 0;
258267
try {
259268
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);
261270
while ((next = reader.nextEntry()) != null) {
262271
SanityCheck.ASSERT(next.getLogType() != LogEntryTypes.CHECKPOINT,
263272
"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
275284
// LOG.debug("Redo: " + next.dump());
276285
// redo the log entry
277286
next.redo();
278-
redoProgressBar.set(next.getLsn().getOffset());
287+
288+
if (redoProgressBar != null) {
289+
redoProgressBar.set(next.getLsn().getOffset());
290+
}
291+
279292
if (next.getLsn().equals(lastLsn)) {
280293
// last readable entry reached. Stop here.
281294
break;
282295
}
283296
}
284-
redoProgressBar.set(lastSize); // 100% done
297+
298+
if (redoProgressBar != null) {
299+
redoProgressBar.set(lastSize); // 100% done
300+
}
285301
} catch (final Exception e) {
286302
LOG.error("Exception caught while redoing transactions. Aborting recovery to avoid possible damage. " +
287303
"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
302318
// do a reverse scan of the log, undoing all uncommitted transactions
303319
try {
304320
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) {
307323
if (next.getLogType() == LogEntryTypes.TXN_START) {
308324
if (runningTxns.get(next.getTransactionId()) != null) {
309325
runningTxns.remove(next.getTransactionId());
@@ -325,9 +341,14 @@ private void doRecovery(final int txnCount, final Path last, final JournalReader
325341
next.undo();
326342
}
327343

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
329351
}
330-
undoProgressBar.set(lastSize); // 100% done
331352
} catch (final Exception e) {
332353
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);
333354
if (next != null)

0 commit comments

Comments
 (0)