Skip to content

C++ migration: port write stream-related part of FSTRemoteStore #2335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 127 commits into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
76b206b
Remove extra imports and includes
var-const Jan 15, 2019
7dcb9ae
Port
var-const Jan 15, 2019
88ba1a7
Forgotten method
var-const Jan 15, 2019
895bf45
style.sh
var-const Jan 15, 2019
b66c5d2
Forgotten the main part!
var-const Jan 15, 2019
3f5fdae
Fixup unit tests
var-const Jan 15, 2019
5ce04b8
Wip
var-const Jan 16, 2019
3dc3170
Step back
var-const Jan 18, 2019
9d1f931
Core compiles
var-const Jan 18, 2019
7ea798e
Merge branch 'master' into varconst/fst-watch-change
var-const Jan 18, 2019
84842be
quick fix
var-const Jan 18, 2019
e5132be
Test helpers
var-const Jan 18, 2019
6c85090
MockDatastore
var-const Jan 18, 2019
f7a90b5
FSTLocalStoreTests
var-const Jan 18, 2019
267963f
wip
var-const Jan 18, 2019
60a5726
wip
var-const Jan 18, 2019
dd9d98d
FSTRemoveEventTests
var-const Jan 18, 2019
aec3f54
FSTSerializerBetaTests
var-const Jan 19, 2019
b012929
wip
var-const Jan 19, 2019
1da0672
wip
var-const Jan 21, 2019
e0f77f2
wip
var-const Jan 21, 2019
df5cd00
wip
var-const Jan 21, 2019
5d3313a
wip
var-const Jan 21, 2019
31e5f3d
wip
var-const Jan 21, 2019
0637243
Ship it!
var-const Jan 21, 2019
26b39c7
use changes
var-const Jan 21, 2019
2cab650
quick fix
var-const Jan 21, 2019
ca88d8c
Unit tests pass
var-const Jan 21, 2019
2c0a7ef
style.sh
var-const Jan 21, 2019
52b131d
Small fixes
var-const Jan 21, 2019
35ce8cc
Get rid of ids alias
var-const Jan 21, 2019
8230fbb
Fixes
var-const Jan 21, 2019
ceb3bee
Move the test
var-const Jan 21, 2019
dd617de
Restore nooutstandingresponses variable
var-const Jan 21, 2019
9d80eea
Small fixes
var-const Jan 21, 2019
836d4de
style.sh
var-const Jan 21, 2019
134acaf
Review feedback
var-const Jan 22, 2019
f8dd5a5
Review feedback
var-const Jan 22, 2019
c02df53
comment
var-const Jan 22, 2019
ce17913
Appease linter
var-const Jan 22, 2019
a87cf7e
Initial
var-const Jan 22, 2019
d6a137a
wip
var-const Jan 23, 2019
1c99679
wip
var-const Jan 23, 2019
b2e0dd1
Initial
var-const Jan 23, 2019
e076f25
style.sh
var-const Jan 23, 2019
359d938
Merge branch 'master' into varconst/fst-document-view-change-type
var-const Jan 23, 2019
4b7c6a7
forgotten file
var-const Jan 23, 2019
7164e2b
Merge branch 'varconst/fst-document-view-change-type' into varconst/f…
var-const Jan 23, 2019
48fbab6
pt. 1 compiles
var-const Jan 23, 2019
0325248
Wip
var-const Jan 23, 2019
acbc626
wip
var-const Jan 24, 2019
b178b00
Merge branch 'master' into varconst/fst-watch-change-aggregator
var-const Jan 24, 2019
78395d8
In theory, all methods implemented
var-const Jan 24, 2019
4fee491
wip
var-const Jan 24, 2019
626efec
Almost compiles
var-const Jan 24, 2019
66db96a
Merge branch 'master' into varconst/fst-watch-change-aggregator
var-const Jan 24, 2019
d5defb1
appease linter
var-const Jan 24, 2019
52b2171
Bring method order into compliance
var-const Jan 24, 2019
e5fcf94
Compliacne, pt.2
var-const Jan 24, 2019
7a48512
core compiles
var-const Jan 25, 2019
66d8af2
unit tests compile
var-const Jan 26, 2019
594a841
Fix unit test -- all pass
var-const Jan 26, 2019
77d9cd7
style.sh
var-const Jan 26, 2019
fdf05a7
Review feedback
var-const Jan 26, 2019
a910ccd
Merge branch 'varconst/fst-watch-change-aggregator' into varconst/fst…
var-const Jan 26, 2019
c71a541
undo formatting
var-const Jan 26, 2019
24a745e
fix
var-const Jan 26, 2019
142f08c
Merge branch 'varconst/fst-watch-change-aggregator' into varconst/fst…
var-const Jan 27, 2019
e402e8b
Merge branch 'master' into varconst/fst-target-change
var-const Jan 27, 2019
e3dd85e
Temp code
var-const Jan 27, 2019
1eb4096
Implementation
var-const Jan 28, 2019
4147c3d
Updating references wip (FSTRemoteEventsTests still to do)
var-const Jan 28, 2019
3b3b012
Unit tests compile
var-const Jan 28, 2019
f1140d9
Unit tests compile and pass
var-const Jan 28, 2019
7ee766f
style.sh
var-const Jan 28, 2019
f00494a
Minor improvements
var-const Jan 28, 2019
766e940
Review feedback
var-const Jan 29, 2019
68ced12
Merge branch 'varconst/fst-target-change' into varconst/fst-remote-ev…
var-const Jan 29, 2019
90450fd
Initial implementation
var-const Jan 29, 2019
ed7ee52
Updating references
var-const Jan 29, 2019
ab6d050
Merge branch 'master' into varconst/fst-remote-event2
var-const Jan 29, 2019
920a921
All compiles
var-const Jan 29, 2019
3d509ec
style.sh
var-const Jan 29, 2019
b2d8ce4
Minor consistency changes
var-const Jan 29, 2019
355ced0
Skeleton
var-const Jan 29, 2019
df4c82e
Pseudochange
var-const Jan 29, 2019
9b494ee
Undo pseudochange
var-const Jan 29, 2019
c5a82f9
unstyle
var-const Jan 29, 2019
65b6ae2
Review feedback
var-const Jan 30, 2019
055372e
Merge branch 'varconst/fst-remote-event2' into varconst/fst-online-st…
var-const Jan 30, 2019
9435faf
Merge branch 'master' into varconst/fst-online-state-tracker
var-const Jan 30, 2019
151f99d
Change extension
var-const Jan 30, 2019
06947a5
style
var-const Jan 30, 2019
26bb8a9
wip
var-const Jan 30, 2019
61f821e
Redundant
var-const Jan 30, 2019
448b1fc
wip
var-const Jan 30, 2019
a7d99ae
wip
var-const Jan 30, 2019
286850f
Merge branch 'varconst/fst-online-state-tracker' into varconst/fst-re…
var-const Jan 30, 2019
6119d54
core actually compiles
var-const Jan 30, 2019
8fa4e74
style.sh
var-const Jan 30, 2019
6702112
wip
var-const Jan 31, 2019
4ec169e
unit tests compile
var-const Jan 31, 2019
6db2ee9
style.sh
var-const Jan 31, 2019
463b652
accidental
var-const Jan 31, 2019
dba5e70
small fixes
var-const Jan 31, 2019
97229a8
initial
var-const Feb 1, 2019
5266f7c
initial cont.
var-const Feb 1, 2019
43c575a
Merge branch 'master' into varconst/fst-online-state-tracker
var-const Feb 1, 2019
53f00fc
Compiles!
var-const Feb 1, 2019
1858aae
all tests pass
var-const Feb 1, 2019
4589e1f
style.sh
var-const Feb 1, 2019
3025ca3
Merge branch 'varconst/fst-online-state-tracker' into varconst/fst-re…
var-const Feb 1, 2019
882a137
Merge branch 'master' into varconst/fst-remote-store1
var-const Feb 1, 2019
5f1ac4b
Merge branch 'varconst/fst-remote-store1' into varconst/fst-remote-st…
var-const Feb 1, 2019
28e0689
android method order
var-const Feb 1, 2019
c803f61
web method order
var-const Feb 1, 2019
aa18e6c
rename
var-const Feb 1, 2019
ce0d114
undo
var-const Feb 1, 2019
318debc
Review feedback
var-const Feb 1, 2019
0e477c2
Merge branch 'varconst/fst-remote-store1' into varconst/fst-remote-st…
var-const Feb 1, 2019
924b455
Review feedback
var-const Feb 1, 2019
af88702
style.sh
var-const Feb 1, 2019
33da753
fix weird bug
var-const Feb 2, 2019
808e169
Merge branch 'varconst/fst-remote-store1' into varconst/fst-remote-st…
var-const Feb 2, 2019
a196232
Merge branch 'master' into varconst/fst-remote-store2
var-const Feb 6, 2019
217a47f
Review feedback
var-const Feb 7, 2019
fa1082e
Fix
var-const Feb 7, 2019
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
2 changes: 1 addition & 1 deletion Firestore/Example/Tests/Local/FSTLocalStoreTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ - (void)acknowledgeMutationWithVersion:(FSTTestSnapshotVersion)documentVersion {
transformResults:nil];
FSTMutationBatchResult *result = [FSTMutationBatchResult resultWithBatch:batch
commitVersion:version
mutationResults:@[ mutationResult ]
mutationResults:{mutationResult}
streamToken:nil];
_lastChanges = [self.localStore acknowledgeBatchWithResult:result];
}
Expand Down
5 changes: 3 additions & 2 deletions Firestore/Example/Tests/SpecTests/FSTMockDatastore.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <memory>
#include <unordered_map>
#include <vector>

#include "Firestore/core/src/firebase/firestore/model/snapshot_version.h"
#include "Firestore/core/src/firebase/firestore/model/types.h"
Expand All @@ -40,7 +41,7 @@ class MockDatastore : public Datastore {
auth::CredentialsProvider* credentials);

std::shared_ptr<WatchStream> CreateWatchStream(WatchStreamCallback* callback) override;
std::shared_ptr<WriteStream> CreateWriteStream(id<FSTWriteStreamDelegate> delegate) override;
std::shared_ptr<WriteStream> CreateWriteStream(WriteStreamCallback* callback) override;

/**
* A count of the total number of requests sent to the watch stream since the beginning of the
Expand Down Expand Up @@ -82,7 +83,7 @@ class MockDatastore : public Datastore {
int WritesSent() const;

/** Injects a write ack as though it had come from the backend in response to a write. */
void AckWrite(const model::SnapshotVersion& version, NSArray<FSTMutationResult*>* results);
void AckWrite(const model::SnapshotVersion& version, std::vector<FSTMutationResult*> results);

/** Injects a stream failure as though it had come from the backend. */
void FailWrite(const util::Status& error);
Expand Down
28 changes: 14 additions & 14 deletions Firestore/Example/Tests/SpecTests/FSTMockDatastore.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#import "Firestore/Source/Local/FSTQueryData.h"
#import "Firestore/Source/Model/FSTMutation.h"
#import "Firestore/Source/Remote/FSTSerializerBeta.h"
#import "Firestore/Source/Remote/FSTStream.h"

#include "Firestore/core/src/firebase/firestore/auth/credentials_provider.h"
#include "Firestore/core/src/firebase/firestore/auth/empty_credentials_provider.h"
Expand Down Expand Up @@ -161,18 +160,18 @@ void WriteWatchChange(const WatchChange& change, SnapshotVersion snap) {
CredentialsProvider* credentials_provider,
FSTSerializerBeta* serializer,
GrpcConnection* grpc_connection,
id<FSTWriteStreamDelegate> delegate,
WriteStreamCallback* callback,
MockDatastore* datastore)
: WriteStream{worker_queue, credentials_provider, serializer, grpc_connection, delegate},
: WriteStream{worker_queue, credentials_provider, serializer, grpc_connection, callback},
datastore_{datastore},
delegate_{delegate} {
callback_{callback} {
}

void Start() override {
HARD_ASSERT(!open_, "Trying to start already started write stream");
open_ = true;
sent_mutations_ = {};
[delegate_ writeStreamDidOpen];
callback_->OnWriteStreamOpen();
}

void Stop() override {
Expand All @@ -194,7 +193,7 @@ bool IsOpen() const override {
void WriteHandshake() override {
datastore_->IncrementWriteStreamRequests();
SetHandshakeComplete();
[delegate_ writeStreamDidCompleteHandshake];
callback_->OnWriteStreamHandshakeComplete();
}

void WriteMutations(NSArray<FSTMutation*>* mutations) override {
Expand All @@ -203,14 +202,14 @@ void WriteMutations(NSArray<FSTMutation*>* mutations) override {
}

/** Injects a write ack as though it had come from the backend in response to a write. */
void AckWrite(const SnapshotVersion& commitVersion, NSArray<FSTMutationResult*>* results) {
[delegate_ writeStreamDidReceiveResponseWithVersion:commitVersion mutationResults:results];
void AckWrite(const SnapshotVersion& commitVersion, std::vector<FSTMutationResult*> results) {
callback_->OnWriteStreamMutationResult(commitVersion, std::move(results));
}

/** Injects a failed write response as though it had come from the backend. */
void FailStream(const Status& error) {
open_ = false;
[delegate_ writeStreamWasInterruptedWithError:error];
callback_->OnWriteStreamClose(error);
}

/**
Expand All @@ -236,7 +235,7 @@ int sent_mutations_count() const {
bool open_ = false;
std::queue<NSArray<FSTMutation*>*> sent_mutations_;
MockDatastore* datastore_ = nullptr;
id<FSTWriteStreamDelegate> delegate_ = nullptr;
WriteStreamCallback* callback_ = nullptr;
};

MockDatastore::MockDatastore(const core::DatabaseInfo& database_info,
Expand All @@ -257,11 +256,11 @@ int sent_mutations_count() const {
return watch_stream_;
}

std::shared_ptr<WriteStream> MockDatastore::CreateWriteStream(id<FSTWriteStreamDelegate> delegate) {
std::shared_ptr<WriteStream> MockDatastore::CreateWriteStream(WriteStreamCallback* callback) {
write_stream_ = std::make_shared<MockWriteStream>(
worker_queue_, credentials_,
[[FSTSerializerBeta alloc] initWithDatabaseID:&database_info_->database_id()],
grpc_connection(), delegate, this);
grpc_connection(), callback, this);

return write_stream_;
}
Expand Down Expand Up @@ -290,8 +289,9 @@ int sent_mutations_count() const {
return write_stream_->sent_mutations_count();
}

void MockDatastore::AckWrite(const SnapshotVersion& version, NSArray<FSTMutationResult*>* results) {
write_stream_->AckWrite(version, results);
void MockDatastore::AckWrite(const SnapshotVersion& version,
std::vector<FSTMutationResult*> results) {
write_stream_->AckWrite(version, std::move(results));
}

void MockDatastore::FailWrite(const Status& error) {
Expand Down
2 changes: 1 addition & 1 deletion Firestore/Example/Tests/SpecTests/FSTSpecTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ - (void)doWriteAck:(NSDictionary *)spec {

FSTMutationResult *mutationResult = [[FSTMutationResult alloc] initWithVersion:version
transformResults:nil];
[self.driver receiveWriteAckWithVersion:version mutationResults:@[ mutationResult ]];
[self.driver receiveWriteAckWithVersion:version mutationResults:{mutationResult}];
}

- (void)doFailWrite:(NSDictionary *)spec {
Expand Down
7 changes: 4 additions & 3 deletions Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <map>
#include <unordered_map>
#include <vector>

#import "Firestore/Source/Remote/FSTRemoteStore.h"

Expand Down Expand Up @@ -195,9 +196,9 @@ typedef std::unordered_map<firebase::firestore::auth::User,
* the mutation. Snapshot versions must be monotonically increasing.
* @param mutationResults The mutation results for the write that is being acked.
*/
- (FSTOutstandingWrite *)receiveWriteAckWithVersion:
(const firebase::firestore::model::SnapshotVersion &)commitVersion
mutationResults:(NSArray<FSTMutationResult *> *)mutationResults;
- (FSTOutstandingWrite *)
receiveWriteAckWithVersion:(const firebase::firestore::model::SnapshotVersion &)commitVersion
mutationResults:(std::vector<FSTMutationResult *>)mutationResults;

/**
* A count of the mutations written to the write stream by the FSTSyncEngine, but not yet
Expand Down
5 changes: 3 additions & 2 deletions Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,13 @@ - (void)changeUser:(const User &)user {

- (FSTOutstandingWrite *)receiveWriteAckWithVersion:(const SnapshotVersion &)commitVersion
mutationResults:
(NSArray<FSTMutationResult *> *)mutationResults {
(std::vector<FSTMutationResult *>)mutationResults {
FSTOutstandingWrite *write = [self currentOutstandingWrites].firstObject;
[[self currentOutstandingWrites] removeObjectAtIndex:0];
[self validateNextWriteSent:write.write];

_workerQueue->EnqueueBlocking([&] { _datastore->AckWrite(commitVersion, mutationResults); });
_workerQueue->EnqueueBlocking(
[&] { _datastore->AckWrite(commitVersion, std::move(mutationResults)); });

return write;
}
Expand Down
5 changes: 3 additions & 2 deletions Firestore/Source/Model/FSTMutationBatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import <Foundation/Foundation.h>

#include <unordered_map>
#include <vector>

#include "Firestore/core/src/firebase/firestore/model/document_key.h"
#include "Firestore/core/src/firebase/firestore/model/document_key_set.h"
Expand Down Expand Up @@ -102,13 +103,13 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (instancetype)resultWithBatch:(FSTMutationBatch *)batch
commitVersion:(firebase::firestore::model::SnapshotVersion)commitVersion
mutationResults:(NSArray<FSTMutationResult *> *)mutationResults
mutationResults:(std::vector<FSTMutationResult *>)mutationResults
streamToken:(nullable NSData *)streamToken;

- (const firebase::firestore::model::SnapshotVersion &)commitVersion;
- (const std::vector<FSTMutationResult *> &)mutationResults;

@property(nonatomic, strong, readonly) FSTMutationBatch *batch;
@property(nonatomic, strong, readonly) NSArray<FSTMutationResult *> *mutationResults;
@property(nonatomic, strong, readonly, nullable) NSData *streamToken;

- (const firebase::firestore::model::DocumentVersionMap &)docVersions;
Expand Down
23 changes: 14 additions & 9 deletions Firestore/Source/Model/FSTMutationBatch.mm
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ - (FSTMaybeDocument *_Nullable)applyToRemoteDocument:(FSTMaybeDocument *_Nullabl
"applyTo: key %s doesn't match maybeDoc key %s", documentKey.ToString(),
maybeDoc.key.ToString());

HARD_ASSERT(mutationBatchResult.mutationResults.count == self.mutations.count,
HARD_ASSERT(mutationBatchResult.mutationResults.size() == self.mutations.count,
"Mismatch between mutations length (%s) and results length (%s)",
self.mutations.count, mutationBatchResult.mutationResults.count);
self.mutations.count, mutationBatchResult.mutationResults.size());

for (NSUInteger i = 0; i < self.mutations.count; i++) {
FSTMutation *mutation = self.mutations[i];
Expand Down Expand Up @@ -130,25 +130,26 @@ - (DocumentKeySet)keys {
@interface FSTMutationBatchResult ()
- (instancetype)initWithBatch:(FSTMutationBatch *)batch
commitVersion:(SnapshotVersion)commitVersion
mutationResults:(NSArray<FSTMutationResult *> *)mutationResults
mutationResults:(std::vector<FSTMutationResult *>)mutationResults
streamToken:(nullable NSData *)streamToken
docVersions:(DocumentVersionMap)docVersions NS_DESIGNATED_INITIALIZER;
@end

@implementation FSTMutationBatchResult {
SnapshotVersion _commitVersion;
std::vector<FSTMutationResult *> _mutationResults;
DocumentVersionMap _docVersions;
}

- (instancetype)initWithBatch:(FSTMutationBatch *)batch
commitVersion:(SnapshotVersion)commitVersion
mutationResults:(NSArray<FSTMutationResult *> *)mutationResults
mutationResults:(std::vector<FSTMutationResult *>)mutationResults
streamToken:(nullable NSData *)streamToken
docVersions:(DocumentVersionMap)docVersions {
if (self = [super init]) {
_batch = batch;
_commitVersion = std::move(commitVersion);
_mutationResults = mutationResults;
_mutationResults = std::move(mutationResults);
_streamToken = streamToken;
_docVersions = std::move(docVersions);
}
Expand All @@ -159,17 +160,21 @@ - (instancetype)initWithBatch:(FSTMutationBatch *)batch
return _commitVersion;
}

- (const std::vector<FSTMutationResult *> &)mutationResults {
return _mutationResults;
}

- (const DocumentVersionMap &)docVersions {
return _docVersions;
}

+ (instancetype)resultWithBatch:(FSTMutationBatch *)batch
commitVersion:(SnapshotVersion)commitVersion
mutationResults:(NSArray<FSTMutationResult *> *)mutationResults
mutationResults:(std::vector<FSTMutationResult *>)mutationResults
streamToken:(nullable NSData *)streamToken {
HARD_ASSERT(batch.mutations.count == mutationResults.count,
HARD_ASSERT(batch.mutations.count == mutationResults.size(),
"Mutations sent %s must equal results received %s", batch.mutations.count,
mutationResults.count);
mutationResults.size());

DocumentVersionMap docVersions;
NSArray<FSTMutation *> *mutations = batch.mutations;
Expand All @@ -186,7 +191,7 @@ + (instancetype)resultWithBatch:(FSTMutationBatch *)batch

return [[FSTMutationBatchResult alloc] initWithBatch:batch
commitVersion:std::move(commitVersion)
mutationResults:mutationResults
mutationResults:std::move(mutationResults)
streamToken:streamToken
docVersions:std::move(docVersions)];
}
Expand Down
Loading