Skip to content

Commit

Permalink
Bug 848136 - Part 1: Use WAL journal for Firefox Health Report; r=rne…
Browse files Browse the repository at this point in the history
…wman, mak
  • Loading branch information
indygreg committed Mar 26, 2013
1 parent 05d8bbf commit 8c8fb71
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions services/metrics/storage.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,15 @@ function MetricsStorageSqliteBackend(connection) {
}

MetricsStorageSqliteBackend.prototype = Object.freeze({
// Max size (in kibibytes) the WAL log is allowed to grow to before it is
// checkpointed.
//
// This was first deployed in bug 848136. We want a value large enough
// that we aren't checkpointing all the time. However, we want it
// small enough so we don't have to read so much when we open the
// database.
MAX_WAL_SIZE_KB: 512,

FIELD_DAILY_COUNTER: "daily-counter",
FIELD_DAILY_DISCRETE_NUMERIC: "daily-discrete-numeric",
FIELD_DAILY_DISCRETE_TEXT: "daily-discrete-text",
Expand Down Expand Up @@ -1105,6 +1114,43 @@ MetricsStorageSqliteBackend.prototype = Object.freeze({
_init: function() {
let self = this;
return Task.spawn(function initTask() {
// 0. Database file and connection configuration.

// This should never fail. But, we assume the default of 1024 in case it
// does.
let rows = yield self._connection.execute("PRAGMA page_size");
let pageSize = 1024;
if (rows.length) {
pageSize = rows[0].getResultByIndex(0);
}

self._log.debug("Page size is " + pageSize);

// Ensure temp tables are stored in memory, not on disk.
yield self._connection.execute("PRAGMA temp_store=MEMORY");

let journalMode;
rows = yield self._connection.execute("PRAGMA journal_mode=WAL");
if (rows.length) {
journalMode = rows[0].getResultByIndex(0);
}

self._log.info("Journal mode is " + journalMode);

if (journalMode == "wal") {
yield self._connection.execute("PRAGMA wal_autocheckpoint=" +
Math.ceil(self.MAX_WAL_SIZE_KB * 1024 / pageSize));
} else {
if (journalMode != "truncate") {
// Fall back to truncate (which is faster than delete).
yield self._connection.execute("PRAGMA journal_mode=TRUNCATE");
}

// And always use full synchronous mode to reduce possibility for data
// loss.
yield self._connection.execute("PRAGMA synchronous=FULL");
}

// 1. Create the schema.
yield self._connection.executeTransaction(function ensureSchema(conn) {
let schema = conn.schemaVersion;
Expand Down

0 comments on commit 8c8fb71

Please sign in to comment.