Skip to content

Commit 175b9a9

Browse files
amabluea-maurice
authored andcommitted
Added NoopPersistenceManager, removed NoopPersistenceStorageEngine.
At some point I added a NoopPersistenceStorageEngine which is a version of the PersistenceStorageEngine interface which takes no actions, intended for use with the special .info sync tree which does not persist it's data. However, that was the wrong level of abstraction, and it was the PersistenceManager that should have had the Noop version of it. This fixes a potential issue where .info values are returned null instead of the value they are supposed to be. PiperOrigin-RevId: 293012252
1 parent 38f9f74 commit 175b9a9

9 files changed

+262
-201
lines changed

database/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ set(desktop_SRCS
9797
src/desktop/disconnection_desktop.cc
9898
src/desktop/mutable_data_desktop.cc
9999
src/desktop/persistence/in_memory_persistence_storage_engine.cc
100-
src/desktop/persistence/noop_persistence_storage_engine.cc
100+
src/desktop/persistence/noop_persistence_manager.cc
101101
src/desktop/persistence/persistence_manager.cc
102102
src/desktop/persistence/prune_forest.cc
103103
src/desktop/push_child_name_generator.cc

database/src/desktop/core/sync_tree.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ enum Persist {
4646
class SyncTree {
4747
public:
4848
SyncTree(UniquePtr<WriteTree> pending_write_tree,
49-
UniquePtr<PersistenceManager> persistence_manager,
49+
UniquePtr<PersistenceManagerInterface> persistence_manager,
5050
UniquePtr<ListenProvider> listen_provider)
5151
: pending_write_tree_(std::move(pending_write_tree)),
5252
persistence_manager_(std::move(persistence_manager)),
@@ -187,7 +187,7 @@ class SyncTree {
187187

188188
// The persistence manager, which is used to interact with the persisted data
189189
// on disk (both reads and writes).
190-
UniquePtr<PersistenceManager> persistence_manager_;
190+
UniquePtr<PersistenceManagerInterface> persistence_manager_;
191191

192192
// A tree that contains the SyncPoints for each location being watched in the
193193
// database.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "database/src/desktop/persistence/noop_persistence_manager.h"
16+
17+
#define VERIFY_INSIDE_TRANSACTION() \
18+
FIREBASE_DEV_ASSERT_MESSAGE( \
19+
this->inside_transaction_, \
20+
"Transaction expected to already be in progress.")
21+
22+
namespace firebase {
23+
namespace database {
24+
namespace internal {
25+
26+
NoopPersistenceManager::NoopPersistenceManager() : inside_transaction_(false) {}
27+
28+
void NoopPersistenceManager::SaveUserOverwrite(const Path& path,
29+
const Variant& variant,
30+
WriteId write_id) {
31+
VERIFY_INSIDE_TRANSACTION();
32+
}
33+
34+
void NoopPersistenceManager::SaveUserMerge(const Path& path,
35+
const CompoundWrite& children,
36+
WriteId write_id) {
37+
VERIFY_INSIDE_TRANSACTION();
38+
}
39+
40+
void NoopPersistenceManager::RemoveUserWrite(WriteId write_id) {
41+
VERIFY_INSIDE_TRANSACTION();
42+
}
43+
44+
void NoopPersistenceManager::RemoveAllUserWrites() {
45+
VERIFY_INSIDE_TRANSACTION();
46+
}
47+
48+
void NoopPersistenceManager::ApplyUserWriteToServerCache(
49+
const Path& path, const Variant& variant) {
50+
VERIFY_INSIDE_TRANSACTION();
51+
}
52+
53+
void NoopPersistenceManager::ApplyUserWriteToServerCache(
54+
const Path& path, const CompoundWrite& merge) {
55+
VERIFY_INSIDE_TRANSACTION();
56+
}
57+
58+
std::vector<UserWriteRecord> NoopPersistenceManager::LoadUserWrites() {
59+
return std::vector<UserWriteRecord>();
60+
}
61+
62+
CacheNode NoopPersistenceManager::ServerCache(const QuerySpec& query_spec) {
63+
return CacheNode();
64+
}
65+
66+
void NoopPersistenceManager::UpdateServerCache(const QuerySpec& query_spec,
67+
const Variant& variant) {
68+
VERIFY_INSIDE_TRANSACTION();
69+
}
70+
71+
void NoopPersistenceManager::UpdateServerCache(const Path& path,
72+
const CompoundWrite& children) {
73+
VERIFY_INSIDE_TRANSACTION();
74+
}
75+
76+
void NoopPersistenceManager::SetQueryActive(const QuerySpec& query_spec) {
77+
VERIFY_INSIDE_TRANSACTION();
78+
}
79+
80+
void NoopPersistenceManager::SetQueryInactive(const QuerySpec& query_spec) {
81+
VERIFY_INSIDE_TRANSACTION();
82+
}
83+
84+
void NoopPersistenceManager::SetQueryComplete(const QuerySpec& query_spec) {
85+
VERIFY_INSIDE_TRANSACTION();
86+
}
87+
88+
void NoopPersistenceManager::SetTrackedQueryKeys(
89+
const QuerySpec& query_spec, const std::set<std::string>& keys) {
90+
VERIFY_INSIDE_TRANSACTION();
91+
}
92+
93+
void NoopPersistenceManager::UpdateTrackedQueryKeys(
94+
const QuerySpec& query_spec, const std::set<std::string>& added,
95+
const std::set<std::string>& removed) {
96+
VERIFY_INSIDE_TRANSACTION();
97+
}
98+
99+
bool NoopPersistenceManager::RunInTransaction(std::function<bool()> func) {
100+
FIREBASE_DEV_ASSERT_MESSAGE(!inside_transaction_,
101+
"RunInTransaction called when an existing "
102+
"transaction is already in progress.");
103+
inside_transaction_ = true;
104+
bool success = func();
105+
inside_transaction_ = false;
106+
return success;
107+
}
108+
109+
} // namespace internal
110+
} // namespace database
111+
} // namespace firebase
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef FIREBASE_DATABASE_CLIENT_CPP_SRC_DESKTOP_PERSISTENCE_NOOP_PERSISTENCE_MANAGER_H_
16+
#define FIREBASE_DATABASE_CLIENT_CPP_SRC_DESKTOP_PERSISTENCE_NOOP_PERSISTENCE_MANAGER_H_
17+
18+
#include <functional>
19+
#include <set>
20+
#include <string>
21+
#include <vector>
22+
23+
#include "app/memory/unique_ptr.h"
24+
#include "app/src/mutex.h"
25+
#include "app/src/path.h"
26+
#include "database/src/common/query_spec.h"
27+
#include "database/src/desktop/core/cache_policy.h"
28+
#include "database/src/desktop/core/tracked_query_manager.h"
29+
#include "database/src/desktop/persistence/persistence_manager.h"
30+
#include "database/src/desktop/persistence/persistence_manager_interface.h"
31+
#include "database/src/desktop/persistence/persistence_storage_engine.h"
32+
#include "database/src/desktop/view/view_cache.h"
33+
34+
namespace firebase {
35+
namespace database {
36+
namespace internal {
37+
38+
class NoopPersistenceManager : public PersistenceManagerInterface {
39+
public:
40+
NoopPersistenceManager();
41+
42+
// Persist a user write to the storage engine.
43+
//
44+
// @param path The path for this write.
45+
// @param variant The variant for this write.
46+
// @param write_id The write id that was used for this write.
47+
void SaveUserOverwrite(const Path& path, const Variant& variant,
48+
WriteId write_id) override;
49+
50+
// Persist a user merge to the storage engine.
51+
//
52+
// @param path The path for this merge.
53+
// @param children The children for this merge.
54+
// @param write_id The write id that was used for this merge.
55+
void SaveUserMerge(const Path& path, const CompoundWrite& children,
56+
WriteId write_id) override;
57+
58+
// Remove the user write with the given write id.
59+
//
60+
// @param write_id The write id to remove.
61+
void RemoveUserWrite(WriteId write_id) override;
62+
63+
// Remove all user writes.
64+
void RemoveAllUserWrites() override;
65+
66+
// Applies the write to the storage engine so that it can be persisted.
67+
void ApplyUserWriteToServerCache(const Path& path,
68+
const Variant& variant) override;
69+
70+
// Applies the merge to the storage engine so that it can be persisted.
71+
void ApplyUserWriteToServerCache(const Path& path,
72+
const CompoundWrite& merge) override;
73+
74+
// Return a list of all writes that were persisted
75+
//
76+
// @return The list of writes
77+
std::vector<UserWriteRecord> LoadUserWrites() override;
78+
79+
// Returns any cached variant or children as a CacheNode. The query is *not*
80+
// used to filter the variant but rather to determine if it can be considered
81+
// complete.
82+
//
83+
// @param query The query at the path
84+
// @return The cached variant or an empty CacheNode if no cache is available
85+
CacheNode ServerCache(const QuerySpec& query) override;
86+
87+
// Overwrite the server cache at the location given by the given QuerySpec.
88+
void UpdateServerCache(const QuerySpec& query,
89+
const Variant& variant) override;
90+
91+
// Merge the given write into theserver cache at the location given by the
92+
// given QuerySpec.
93+
void UpdateServerCache(const Path& path,
94+
const CompoundWrite& children) override;
95+
96+
// Begin tracking the given QuerySpec.
97+
void SetQueryActive(const QuerySpec& query) override;
98+
99+
// Stop tracking the given QuerySpec.
100+
void SetQueryInactive(const QuerySpec& query) override;
101+
102+
// Inform the TrackedQueryManager to mark the tracked query as complete.
103+
void SetQueryComplete(const QuerySpec& query) override;
104+
105+
// Inform the storage engine which keys should be tracked for a given Query.
106+
void SetTrackedQueryKeys(const QuerySpec& query,
107+
const std::set<std::string>& keys) override;
108+
109+
// Updates the set of keys that should be tracked for a given Query.
110+
void UpdateTrackedQueryKeys(const QuerySpec& query,
111+
const std::set<std::string>& added,
112+
const std::set<std::string>& removed) override;
113+
114+
// Run a transaction. Transactions are functions that are going to change
115+
// values in the database, and they must do so effectively atomically. Two
116+
// transacations cannot be run at the same time in different threads, they
117+
// must be scheduled to run by Scheduler. A transaction should return true to
118+
// signal that it completed successfully, or false if there was an error.
119+
// Certain actions can only be performed from inside a transaction, and those
120+
// functions will assert if they are not called between calls to
121+
// BeingTransaction and EndTransaction.
122+
bool RunInTransaction(std::function<bool()> func) override;
123+
124+
private:
125+
bool inside_transaction_;
126+
};
127+
128+
} // namespace internal
129+
} // namespace database
130+
} // namespace firebase
131+
132+
#endif // FIREBASE_DATABASE_CLIENT_CPP_SRC_DESKTOP_PERSISTENCE_NOOP_PERSISTENCE_MANAGER_H_

database/src/desktop/persistence/noop_persistence_storage_engine.cc

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)