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
4 changes: 3 additions & 1 deletion Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
#include "Firestore/core/src/util/async_queue.h"
#include "Firestore/core/src/util/empty.h"

#include "Firestore/core/src/local/target_data_fwd.h"

namespace firebase {
namespace firestore {

namespace local {

class Persistence;
class TargetData;

} // namespace local
} // namespace firestore
Expand Down
9 changes: 8 additions & 1 deletion Firestore/core/src/core/core_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <memory>
#include <string>

#include "Firestore/core/src/model/types.h"

namespace firebase {
namespace firestore {

Expand Down Expand Up @@ -56,7 +58,12 @@ class SyncEngine;
class SyncEngineCallback;
class Target;
class TargetOrPipeline;
class TargetIdGenerator;

template <typename TargetIdType>
class TargetIdGeneratorTemplate;

using TargetIdGenerator = TargetIdGeneratorTemplate<model::TargetId>;
using RemoteTargetIdGenerator = TargetIdGeneratorTemplate<model::RemoteTargetId>;
class Transaction;
class ViewDocumentChanges;
class ViewChange;
Expand Down
3 changes: 2 additions & 1 deletion Firestore/core/src/core/sync_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@
#include "Firestore/core/src/util/status.h"
#include "absl/strings/string_view.h"

#include "Firestore/core/src/local/target_data_fwd.h"

namespace firebase {
namespace firestore {

namespace local {
class LocalStore;
class TargetData;
} // namespace local

namespace model {
Expand Down
16 changes: 11 additions & 5 deletions Firestore/core/src/core/target_id_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,36 @@
#include "Firestore/core/src/util/hard_assert.h"

using firebase::firestore::model::TargetId;
using firebase::firestore::model::RemoteTargetId;

namespace firebase {
namespace firestore {
namespace core {

TargetIdGenerator::TargetIdGenerator(TargetIdGeneratorId generator_id,
TargetId seed)
template <typename TargetIdType>
TargetIdGeneratorTemplate<TargetIdType>::TargetIdGeneratorTemplate(
TargetIdGeneratorId generator_id, TargetIdType seed)
: generator_id_(generator_id) {
seek(seed);
}

void TargetIdGenerator::seek(TargetId target_id) {
const TargetId generator = static_cast<TargetId>(generator_id_);
template <typename TargetIdType>
void TargetIdGeneratorTemplate<TargetIdType>::seek(TargetIdType target_id) {
const TargetIdType generator = static_cast<TargetIdType>(generator_id_);
HARD_ASSERT((target_id & generator) == generator,
"Cannot supply target ID from different generator ID");
next_id_ = target_id;
}

TargetId TargetIdGenerator::NextId() {
template <typename TargetIdType>
TargetIdType TargetIdGeneratorTemplate<TargetIdType>::NextId() {
int next_id = next_id_;
next_id_ += 1 << kReservedBits;
return next_id;
}

template class TargetIdGeneratorTemplate<TargetId>;

} // namespace core
} // namespace firestore
} // namespace firebase
28 changes: 18 additions & 10 deletions Firestore/core/src/core/target_id_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef FIRESTORE_CORE_SRC_CORE_TARGET_ID_GENERATOR_H_
#define FIRESTORE_CORE_SRC_CORE_TARGET_ID_GENERATOR_H_

#include "Firestore/core/src/core/core_fwd.h"
#include "Firestore/core/src/model/types.h"

namespace firebase {
Expand Down Expand Up @@ -44,18 +45,19 @@ enum class TargetIdGeneratorId { TargetCache = 0, SyncEngine = 1 };
*/
// TODO(mrschmidt): Explore removing this class in favor of generating these IDs
// directly in SyncEngine and LocalStore.
class TargetIdGenerator {
template <typename TargetIdType>
class TargetIdGeneratorTemplate {
public:
TargetIdGenerator() = default;
TargetIdGeneratorTemplate() = default;

/**
* Creates and returns the TargetIdGenerator for the local store.
*
* @param after An ID to start at. Every call to NextId returns a larger id.
* @return An instance of TargetIdGenerator.
*/
static TargetIdGenerator TargetCacheTargetIdGenerator(model::TargetId after) {
TargetIdGenerator generator(TargetIdGeneratorId::TargetCache, after);
static TargetIdGeneratorTemplate TargetCacheTargetIdGenerator(TargetIdType after) {
TargetIdGeneratorTemplate generator(TargetIdGeneratorId::TargetCache, after);
// Make sure that the next call to `NextId()` returns the first value after
// 'after'.
generator.NextId();
Expand All @@ -67,23 +69,29 @@ class TargetIdGenerator {
*
* @return An instance of TargetIdGenerator.
*/
static TargetIdGenerator SyncEngineTargetIdGenerator() {
static TargetIdGeneratorTemplate SyncEngineTargetIdGenerator() {
// Sync engine assigns target IDs for limbo document detection.
return TargetIdGenerator(TargetIdGeneratorId::SyncEngine, 1);
return TargetIdGeneratorTemplate(TargetIdGeneratorId::SyncEngine, 1);
}

static TargetIdGeneratorTemplate SyncEngineTargetIdGenerator(TargetIdType after) {
TargetIdGeneratorTemplate generator(TargetIdGeneratorId::SyncEngine, after);
generator.NextId();
return generator;
}

TargetIdGeneratorId generator_id() {
return generator_id_;
}

model::TargetId NextId();
TargetIdType NextId();

private:
TargetIdGenerator(TargetIdGeneratorId generator_id, model::TargetId seed);
void seek(model::TargetId target_id);
TargetIdGeneratorTemplate(TargetIdGeneratorId generator_id, TargetIdType seed);
void seek(TargetIdType target_id);

TargetIdGeneratorId generator_id_ = TargetIdGeneratorId::TargetCache;
model::TargetId next_id_ = 0;
TargetIdType next_id_ = 0;

static const int kReservedBits = 1;
};
Expand Down
1 change: 0 additions & 1 deletion Firestore/core/src/local/leveldb_target_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ namespace local {

class LevelDbPersistence;
class LocalSerializer;
class TargetData;

/** Cached Queries backed by LevelDB. */
class LevelDbTargetCache : public TargetCache {
Expand Down
4 changes: 2 additions & 2 deletions Firestore/core/src/local/local_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "Firestore/core/src/remote/serializer.h"
#include "Firestore/core/src/util/status_fwd.h"

#include "Firestore/core/src/local/target_data_fwd.h"

namespace firebase {
namespace firestore {

Expand Down Expand Up @@ -60,8 +62,6 @@ class NamedQuery;

namespace local {

class TargetData;

/**
* @brief Serializer for values stored in the LocalStore.
*
Expand Down
3 changes: 2 additions & 1 deletion Firestore/core/src/local/local_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "Firestore/core/src/model/model_fwd.h"
#include "absl/types/optional.h"

#include "Firestore/core/src/remote/remote_event_fwd.h"

namespace firebase {
namespace firestore {

Expand All @@ -51,7 +53,6 @@ class FieldIndex;
} // namespace model

namespace remote {
class RemoteEvent;
class TargetChange;
} // namespace remote

Expand Down
1 change: 0 additions & 1 deletion Firestore/core/src/local/lru_garbage_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ namespace firestore {
namespace local {

class LruGarbageCollector;
class TargetData;

ABSL_CONST_INIT extern const model::ListenSequenceNumber
kListenSequenceNumberInvalid;
Expand Down
2 changes: 1 addition & 1 deletion Firestore/core/src/local/reference_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "Firestore/core/src/model/types.h"
#include "absl/strings/string_view.h"
#include "Firestore/core/src/local/target_data_fwd.h"

namespace firebase {
namespace firestore {
Expand All @@ -31,7 +32,6 @@ class DocumentKey;
namespace local {

class ReferenceSet;
class TargetData;

/**
* A ReferenceDelegate instance handles all of the hooks into the
Expand Down
4 changes: 2 additions & 2 deletions Firestore/core/src/local/sizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include <cstdint>

#include "Firestore/core/src/local/target_data_fwd.h"

namespace firebase {
namespace firestore {
namespace model {
Expand All @@ -30,8 +32,6 @@ class MutationBatch;

namespace local {

class TargetData;

/**
* Estimates the stored size of documents and queries.
*/
Expand Down
2 changes: 1 addition & 1 deletion Firestore/core/src/local/target_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "Firestore/core/src/core/pipeline_util.h" // Added for TargetOrPipeline
#include "Firestore/core/src/model/model_fwd.h"
#include "Firestore/core/src/model/types.h"
#include "Firestore/core/src/local/target_data_fwd.h"

namespace firebase {
namespace firestore {
Expand All @@ -33,7 +34,6 @@ class Target;
} // namespace core

namespace local {
class TargetData;

using OrphanedDocumentCallback =
std::function<void(const model::DocumentKey&, model::ListenSequenceNumber)>;
Expand Down
Loading
Loading