Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions components/services/storage/dom_storage/local_storage_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ void LocalStorageImpl::OnDatabaseOpened(leveldb::Status status) {
if (!status.ok()) {
// If we failed to open the database, try to delete and recreate the
// database, or ultimately fallback to an in-memory database.
DeleteAndRecreateDatabase();
DeleteAndRecreateDatabase(DatabaseResetReason::kOpenFailed);
return;
}

Expand Down Expand Up @@ -708,14 +708,14 @@ void LocalStorageImpl::OnGotDatabaseVersion(leveldb::Status status,
&db_version) ||
db_version < kMinSchemaVersion ||
db_version > kCurrentLocalStorageSchemaVersion) {
DeleteAndRecreateDatabase();
DeleteAndRecreateDatabase(DatabaseResetReason::kVersionMismatch);
return;
}

database_initialized_ = true;
} else {
// Other read error. Possibly database corruption.
DeleteAndRecreateDatabase();
DeleteAndRecreateDatabase(DatabaseResetReason::kReadError);
return;
}

Expand Down Expand Up @@ -750,7 +750,9 @@ void LocalStorageImpl::OnConnectionFinished() {
on_database_opened_callbacks_.clear();
}

void LocalStorageImpl::DeleteAndRecreateDatabase() {
void LocalStorageImpl::DeleteAndRecreateDatabase(
DatabaseResetReason reason /*= DatabaseResetReason::kUnknown*/) {
UMA_HISTOGRAM_ENUMERATION("Cobalt.LocalStorage.DatabaseResetReason", reason);
if (connection_state_ == CONNECTION_SHUTDOWN)
return;

Expand Down Expand Up @@ -971,7 +973,7 @@ void LocalStorageImpl::OnCommitResult(leveldb::Status status) {
// Deleting StorageAreas in here could cause more commits (and commit
// errors), but those commits won't reach OnCommitResult because the area
// will have been deleted before the commit finishes.
DeleteAndRecreateDatabase();
DeleteAndRecreateDatabase(DatabaseResetReason::kCommitError);
}
}

Expand Down
13 changes: 12 additions & 1 deletion components/services/storage/dom_storage/local_storage_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,18 @@ class LocalStorageImpl : public base::trace_event::MemoryDumpProvider,
void OnGotDatabaseVersion(leveldb::Status status,
DomStorageDatabase::Value value);
void OnConnectionFinished();
void DeleteAndRecreateDatabase();

enum class DatabaseResetReason {
kOpenFailed,
kVersionMismatch,
kReadError,
kCommitError,
kUnknown,
kMaxValue = kUnknown,
};

void DeleteAndRecreateDatabase(DatabaseResetReason reason =
DatabaseResetReason::kUnknown);
void OnDBDestroyed(bool recreate_in_memory, leveldb::Status status);

StorageAreaHolder* GetOrCreateStorageArea(
Expand Down
8 changes: 8 additions & 0 deletions tools/metrics/histograms/metadata/cobalt/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ Always run the pretty print utility on this file after editing:
</summary>
</histogram>

<<<<<<< HEAD
<histogram name="Cobalt.StorageMigration.SentinelWriteResult"
enum="SentinelWriteResult" expires_after="never">
<owner>colinliang@google.com</owner>
Expand Down Expand Up @@ -346,6 +347,13 @@ Always run the pretty print utility on this file after editing:
all memory the process can access, including shared libraries, stack, heap,
and memory-mapped files. Recorded at regular intervals when memory metrics
are emitted.
=======
<histogram name="Cobalt.LocalStorage.DatabaseResetReason"
enum="LocalStorageDatabaseResetReason" expires_after="never">
<owner>charleykim@google.com</owner>
<summary>
Records the reason why the Local Storage database was reset.
>>>>>>> bca1d8a8ba (adding UMA for local storage DeleteAndRecreateDatabase() (#9354))
</summary>
</histogram>

Expand Down
Loading