Repository navigation
Conversation
…ge engine tests
When reconstructing cached server data from LevelDB in VariantAddCachedValue(),
checking IsPriorityKey(directory) without checking !variant->is_null() wrapped
an uninitialized Variant::Null() placeholder into {".value": Null} whenever
".priority" sorted lexicographically before sibling child keys (e.g., "subkey",
"value"). Guard the scalar-wrapping branch with !variant->is_null() so map
nodes initialize as empty maps while scalar values with ".priority" still wrap
into {".value", ".priority"}.
Also enable firebase_rtdb_desktop_level_db_persistence_storage_engine_test in
CMake, fix portability issues (gmock header, uint64_t, testing::TempDir() with
leveldb::DestroyDB cleanup), and add regression tests covering maps and scalars
with .priority.
On Android and iOS, deleting the C++ Database wrapper and calling Database::GetInstance() reuses the underlying native FirebaseDatabase/FIRDatabase singleton, preserving persistence_enabled across instances for the lifetime of the App. On Desktop, however, DatabaseInternal::persistence_enabled_ was stored only on the instance and reset to false after delete database + Database::GetInstance(). Remember persistence_enabled_ per (App*, normalized database URL) in a thread-safe map, clean up entries automatically via the App's CleanupNotifier when the App is destroyed, and add unit tests in database_desktop_test.cc.
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to track and persist the persistence-enabled state across DatabaseInternal instances on desktop, ensuring proper cleanup when an App is destroyed. It also fixes an issue in the LevelDB storage engine where a priority key sorting before child keys on a null variant incorrectly wrapped Null in a .value field, and adds comprehensive unit tests. The reviewer suggests updating NormalizeDatabaseUrl to include the database namespace in the normalized URL, which prevents distinct database instances sharing the same host (e.g., in emulator or multi-tenant environments) from incorrectly sharing persistence settings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes two Desktop Realtime Database offline persistence bugs: preserving
persistence_enabled_across recreatedDatabaseInternalinstances for the lifetime of anApp, and preventing LevelDB cache reconstruction from corrupting maps whose.prioritykey sorts before sibling child keys. It also enables the LevelDB persistence storage engine unit tests in CMake and adds dedicated unit tests for both fixes.Highlights
DatabaseInternal::persistence_enabled_in a thread-safe map keyed by liveApp*and normalized database URL (ParseUrlwith lowercased hostname), matching Android and iOS lifecycle behavior acrossdelete database+Database::GetInstance(...)and automatically cleaning up entries viaCleanupNotifierwhen theAppis destroyed..priorityReconstruction Fix: Guarded scalar-wrapping inVariantAddCachedValue()with!variant->is_null()so map nodes whose.prioritykey sorts lexicographically before sibling child keys (such as"subkey"or"value") initialize as empty maps instead of{".value": Null}, while scalars with.prioritycontinue to reconstruct as{".value", ".priority"}.firebase_rtdb_desktop_level_db_persistence_storage_engine_testin CMake with cross-platformtesting::TempDir()andleveldb::DestroyDB()cleanup, added.prioritymap/scalar regression tests, and addedfirebase_rtdb_desktop_database_desktop_testcovering cross-instance persistence, URL normalization, isolation, post-init immutability, andAppdestruction cleanup.Changelog
persistence_enabled()getter onDatabaseInternalfor unit testing.App*-scoped map (GetPersistenceEnabledMap()guarded by leaf lockg_persistence_enabled_mutex) storingpersistence_enabled_by normalized database URL.NormalizeDatabaseUrl()usingParseUrlwith lowercased hostnames (falling back to the raw URL on parse failure).DatabaseInternal::DatabaseInternal()to restorepersistence_enabled_from the map andDatabaseInternal::SetPersistenceEnabled()to persist the setting and register cleanup onApp'sCleanupNotifier.VariantAddCachedValue()to check!variant->is_null()before wrapping a non-map variant into{".value": *variant}when encountering.priority.firebase_rtdb_desktop_level_db_persistence_storage_engine_testandfirebase_rtdb_desktop_database_desktop_testtargets.DatabaseInternal::SetPersistenceEnabled()defaults, persistence across instances,falseoverridingtrue, URL normalization, invalid URL fallback, App/URL isolation, post-repo_immutability, and cleanup onAppdestruction.TEST_TMPDIR/<windows.h>temp directory logic withtesting::TempDir(), unique suite+test directory names, andleveldb::DestroyDB()cleanup inInitializeLevelDb(),TearDown(), andConstructorBasic.RunTwice()to close and reopenengine_directly without wiping the database mid-test.gmock/gmock.hinclude anduint64_tportability..priority(including keys sorting before and after.priority, nested maps, falsy scalars, and scalar/map overwrites).