Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9db78024 authored by Tom Cherry's avatar Tom Cherry
Browse files

Log only a summary 'Found stale backup journal' message.

With the goal of reducing log spam, print only a summary 'Found stale
backup journal' messages instead of logging within the inner loop.
Previously, over 12k messages could be printed at a time from this
function.

Before this CL:
 - a backup was scheduled for each packageName from each stale
   journal
 - one (or two, if MORE_DEBUG) message was logged for each
   packageName in each journal file.

After this CL:

 - packageNames are de-duplicated before scheduling backups or logging
   (it's not clear to me whether duplicate packageNames previously
   occurred, in practice).
 - one message is logged for the number (if > 0) of stale journals.
 - one message is logged for the number (including their names, if
   MORE_DEBUG) of packages.

Bug: 161940947
Test: fewer 'Found state backup journal' messages printed
Merged-In: Ia1343e4cea31feb1eba9da561d20736eb5df0a14
Change-Id: Ia1343e4cea31feb1eba9da561d20736eb5df0a14
parent 1720916a
Loading
Loading
Loading
Loading
+22 −9
Original line number Diff line number Diff line
@@ -156,6 +156,7 @@ import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
@@ -1084,18 +1085,30 @@ public class UserBackupManagerService {

    private void parseLeftoverJournals() {
        ArrayList<DataChangedJournal> journals = DataChangedJournal.listJournals(mJournalDir);
        // TODO(b/162022005): Fix DataChangedJournal implementing equals() but not hashCode().
        journals.removeAll(Collections.singletonList(mJournal));
        if (!journals.isEmpty()) {
            Slog.i(TAG, "Found " + journals.size() + " stale backup journal(s), scheduling.");
        }
        Set<String> packageNames = new LinkedHashSet<>();
        for (DataChangedJournal journal : journals) {
            if (!journal.equals(mJournal)) {
            try {
                journal.forEach(packageName -> {
                        Slog.i(TAG, "Found stale backup journal, scheduling");
                        if (MORE_DEBUG) Slog.i(TAG, "  " + packageName);
                    if (packageNames.add(packageName)) {
                        dataChangedImpl(packageName);
                    }
                });
            } catch (IOException e) {
                Slog.e(TAG, "Can't read " + journal, e);
            }
        }
        if (!packageNames.isEmpty()) {
            String msg = "Stale backup journals: Scheduled " + packageNames.size()
                    + " package(s) total";
            if (MORE_DEBUG) {
                msg += ": " + packageNames;
            }
            Slog.i(TAG, msg);
        }
    }