Commit Graph
1174 Commits
Author SHA1 Message Date
Gil 38d9643a00 Disallow empty document fields (#4229)
Port of firebase/firebase-android-sdk#643.

Also make error messages align with Android's.
2019-11-04 17:03:10 -06:00
Gil 0d64c5bf69 Prevent race conditions in DatastoreTest (#4227)
* Prevent race conditions in DatastoreTest

Previously it was possible for tasks on the async queue to outlive the
instance of the DatastoreTest which could crash or cause TSAN
violations.

This fixes a flake that appeared in the AuthOutlivesDatastore test case.

* Improve readability of the error classification tests
2019-11-04 15:51:51 -06:00
wu-hui 2f53582530 Various minor fixes to make SDK compile on Linux (#4185) 2019-11-04 14:39:44 -05:00
Gil 3ea7197090 Port FSTQueryCacheTests to C++ (#4160)
* Move FSTQueryCacheTests files to Firestore/core

* Rewrite QueryCache tests in C++

* Fix test flake in local store tests

This doesn't affect production because we always set the additional
references pointer there, but it's technically optional and some tests
don't do this.
2019-11-02 09:09:25 -05:00
Konstantin Varlamov 04177614d0 Fix fuzz build (#4192) 2019-10-30 14:30:52 -04:00
Gil c93b71d57a Update CHANGELOG for Firestore v1.7.0 (#4195) 2019-10-30 08:44:08 -07:00
Konstantin Varlamov 8ea6b0dbb4 Add a changelog entry on the C++ serializer migration (#4188) 2019-10-29 20:14:35 -04:00
Brian Chen 251a70f26a Make IN queries publicly available (#4174) 2019-10-29 14:13:02 -07:00
Brian Chen 441d7eda8b Change id to NSArray<id> for IN queries (#4182) 2019-10-28 22:22:37 -07:00
Gil fb441a0376 Build all sources with CMake (#4159)
* Fix field initialization order

* Reduce dependencies in objc_compatibility_apple_test

This makes it possible to build and test util without having to build
everything

* Add a lint check for CMake files

* Find XCTest, if available

* Fix CMakeLists.txt to include all sources

* Fix test flake in local store tests

This doesn't affect production because we always set the additional
references pointer there, but it's technically optional and some tests
don't do this.
2019-10-28 13:03:21 -07:00
Konstantin Varlamov 8b23a3266d Remove Objective-C serializers and make local/ and remote/ (almost) fully C++ (#4151)
There are more sources that can be `.cc` now (e.g., in API); these are left for a follow-up PR.

The dependency on Objective-C proto library cannot be removed just yet due to current lack of pretty-printing support for Nanopb.
2019-10-23 20:56:44 -04:00
Gil 6fd815a5ed Port FSTRemoteDocumentCacheTests to C++ (#4136) 2019-10-23 12:28:16 -07:00
Konstantin Varlamov 2c53bb9139 C++ migration: use C++ serializer for communicating with the local store (#4116)
After this PR is merged, the Objective-C serializers can be completely removed from the project. Also, this PR changes the `Message` class quite a bit; it's probably in its final form now.

I did some performance testing locally and came to the conclusion that replacing Objective-C serializers with their C++ versions brings no performance downgrade; actually, there seems to be a very slight improvement. I tested writing large batches and reading large collections:
* both are network-dominated; wall time is about twice longer than CPU time;
* serialization represents a pretty small percentage of the total CPU time;
* for writing, C++ serialization is a little more efficient, taking ~6% of total CPU time, compared to ~8% in the Objective-C version. I've seen similar results for reading.

All integration tests pass, under Address Sanitizer as well.
2019-10-22 21:52:55 -04:00
Paul Beusterien a621e59217 Merge 6.11.0 (#4134) 2019-10-22 11:35:29 -07:00
Gil 3f1fbe7e9a Migrate FSTPersistenceTestHelpers to C++ (#4122)
* Move FSTPersistenceHelpers to core/test/.../local

* Rewrite persistence_testing in C++

* Migrate from FSTPersistenceTestHelpers to C++ persistence_testing

* Rename .mm to .cc where possible in IndexManager tests

* Remove Objective-C gunk from index_manager_test.h
2019-10-21 20:12:46 -07:00
wu-hui 2bcfcc2cfb remove NSException from firestore client (#4131) 2019-10-21 22:30:25 -04:00
Konstantin Varlamov e241a9a9b8 Optimize DocumentKey comparisons (#4123)
This came up while I was investigating the effect of new C++ serializers on performance. When writing large batches, one of the hottest functions turned out to be `firebase::firestore::util::operator==(const DocumentKey& lhs, const DocumentKey& rhs)`, accounting for 15-20% of total CPU time. There are two reasons why comparing keys is currently not very efficient:
* `BasePath::CompareTo`, to which this comparison eventually resolves, mistakenly uses the general-purpose `util::Compare` function rather than the more efficient `util::CompareContainer`;
* the default implementation of `Comparable::operator==` results in two comparisons per element ("less-than" followed by "greater-than"), even though one would be sufficient.

Fixing these issues results in 8-10% CPU time improvement when writing large batches.

To work around the latter, this PR defines a new mixin `InequalityComparable` that is exactly the same as `Comparable`, except it doesn't define `operator==`, forcing the inheriting class to implement it manually.

Some measurements (all done on the emulator in release mode with no logging) follow; the test case was to write 10 batches of 500 very small documents. Note that I found wall clock to fluctuate too much to be reliable and instead use the measurements from XCode's Time Profiler, which (presumably) shows CPU time. Each measurement shows total CPU time spent on `firebase::firestore::util::operator==` (all instantiations, not just for `DocumentKey`), followed by the percentage of time spent in this function compared to total runtime:
* no optimization:
    * 275ms/18.8%;
    * 245ms/16.9%;
    * 252ms/18.5%.
* `CompareContainer` optimization:
    * 124ms/9.7%;
    * 110ms/8.5%;
    * 128ms/10.0%.
* `CompareContainer` + `ComparableWithEqual` optimizations:
    * 95ms/7.3%;
    * 100ms/8.0%;
    * 112ms/9.2%.
2019-10-21 16:43:45 -04:00
Konstantin Varlamov 0f2a0bfeef Use C++ serializer for communicating with the backend (#4013)
Replace all uses of `FSTSerializerBeta` in `remote_objc_bridge.{h,mm}` with the C++ `Serializer`. Also, make most of `remote/` sources pure C++ and remove no-longer-used methods in `FSTSerializerBeta`. All integration tests pass, under Address Sanitizer as well.

Unfortunately, pretty-printing is still delegated to Objective-C, so that `remote_objc_bridge.mm` still has to be an Objective-C++ source (and which prevents inlining `remote_objc_bridge` into the streams).

#no-changelog Will add a changelog entry when local serializer is ported, too.
2019-10-18 17:58:14 -04:00
Gil cd460eca2d Rationalize input validation exceptions and assertion failures (#4107)
* Rationalize input validation exceptions and assertions

... under a single ThrowHandler concept. This makes it possible to set
an alternative ThrowHandler in our C# bindings that properly translates
input validation exceptions to the correct .NET exception types.

* Rename api/input_validation.h to util/exception.h

* Reimplement util/hard_assert.h in terms of util/exception.h
2019-10-18 12:58:45 -07:00
wu-hui 2ebb82d1c5 LocalSerializer feature complete (#4046)
* LocalSerializer feature complete

* Addressing comments 1

* Walk around nanopb boolean issue

* Rename to SafeReadBoolean
2019-10-17 17:04:47 -04:00
Sebastian Schmidt 2a434e0706 Move all ReferenceDelegate memory handling to .cc file (#4101)
This removes the requirement to include reference_delegate.h in consuming tests
2019-10-17 10:06:07 -07:00
Gil b1be1a9c70 Ensure that projectIDs are validated (#4073)
* Avoid priming the backend for emulator tests

* Validate that nil project ids are rejected
2019-10-17 10:03:01 -07:00
Paul Beusterien d8e3a11bb1 Restore Firebase pod to closed source location (#4112) 2019-10-17 09:45:04 -07:00
Sebastian Schmidt 0f315d65dc Fix potential race during client initialization (#4091) 2019-10-16 15:13:05 -07:00
Gil 539ff07fd1 Avoid references to DocumentIDProtocol in Swift < 5.1 (#4092) 2019-10-16 11:41:50 -07:00
Gil e6f073afd8 Update CHANGELOG for Firestore v1.6.1 (#4078) 2019-10-15 21:06:13 -07:00
Gil 53e91860e0 Rewrite SelfDocumentID as a property wrapper (#4031)
* Rewrite SelfDocumentID as a property wrapper

Make wrapped types conform to DocumentReferenceConvertible and use that
protocol to implement the conversion.

* Change DocumentReferenceConvertible to DocumentIDWrappable

* Make ServerTimestampWrappable use static functions

Use the same form as DocumentIDWrappable.

* Update extension String: ServerTimestampWrappable

* Use #if compiler, not #if swift

The FirebaseFirestoreSwift module is declared as conforming to Swift
4.0 so #if swift is still false, even when compiling with Swift 5.1.
Using #if compiler will see the actual compiler version. Property
wrappers don't depend on runtime features, so this works.

Also, allow Wrappable protocols to throw during conversions.
2019-10-15 12:59:36 -07:00
Konstantin Varlamov 046e2997ef Fix small issues in C++ serializer and port remaining tests (#4012)
These were discovered by running integration tests using the new `Serializer`.

Also, port all the missing tests from `FSTSerializerBetaTests.mm` (that I could find).
2019-10-11 15:34:18 -04:00
Sebastian Schmidt bf031c21ed Add SimpleQueryEngine (#3999) 2019-10-09 10:18:53 -07:00
wu-hui 3f1e2189cb Port remaining serializer methods (#3992) 2019-10-09 13:18:12 -04:00
Ryan Wilson bbcac27b72 Release 6.10.0 (#4022)
* Update versions for Release 6.10.0

* Cherrypick #3983 and include Database in release. (#3986)

* Remove log argument that causes SocketRocket crash (#3983)

* Add FirebaseDatabase to release.

* Update CHANGELOG with version.

* Cherrypick for #3984 along with CHANGELOG update. (#3988)

* Fix race condition in FIRComponentContainer instance creation (#3984)

* Fix race condition in FIRComponentContainer instance creation

Reported in #3967. Users sometimes seeing a crash when multiple threads
concurrently try to create Firestore instances. By inspection I found
that there's a race here where two threads can check for presence in the
cache, see nothing, proceed to creation, both store a value in the cache,
and both return their copies. This would lead to two Firestores being
created for a single App.

This replaces `dispatch_sync` on a serial queue with good old
`@synchronized` blocks. `dispatch_sync` will self-deadlock if called
from a thread already on the queue while `@synchronized` allows
recursion.

No new tests are added because several tests like
`testDependencyDoesntBlock` already cover this case.

* format

* Update Core CHANGELOG

* Update Core CHANGELOG again

* Fix merge from CHANGELOG
2019-10-09 12:10:33 -04:00
Gil 0733736c5e Rewrite ServerTimestamp as a property wrapper (#4003)
* Move ServerTimestamp into its own file

* Rewrite ServerTimestamp as a property wrapper

Add Swift4ServerTimestamp that behaves as before.

* Make ServerTimestampWrappable dictate timestamp conversion.

This makes the @ServerTimestamp property wrapper completely open to
extension by end users too.
2019-10-08 10:11:28 -07:00
Gil 847d72759d Fix formatting that was somehow ignored (#4002)
* Fix formatting that somehow was ignored.

* Minor tweaks to style.sh

... reflecting updated source layout.
2019-10-07 09:10:47 -07:00
Gil f32cc12ce0 Build Firestore with Xcode 11 (#4005)
* Drop dependency on OCMock

* Move Firestore onto Xcode 11 in Travis

* Special case simulators based on Xcode version, not product

This allows Firestore's build with Xcode 8.3.3 to continue to work.

* Make the Firestore Podfile install only one platform at a time

Use the PLATFORM environment variable to limit which targets are
modified. This makes the selected platform work but leaves the other
platforms in a broken state in the Xcode UI.

* Fix code signing errors on macOS builds
2019-10-07 08:46:06 -07:00
Gil 11de159e8e Migrate FSTRemoteEventTests to C++ (#3965)
* move (unchanged) into Firestore/core

* split out TestTargetMetadataProvider

... also rename to not start with "test".

* rewrite in C++
2019-10-04 11:55:20 -07:00
Konstantin Varlamov 893002541b Serializer: implement encoding and decoding of Target (#3932) 2019-10-03 19:05:05 -04:00
Gil 1a004119fa Project updates for recently added/moved files (#3994)
Occasionally Xcode will save these out--I can't predict when.
2019-10-03 16:02:14 -07:00
Sebastian Schmidt 41c411e8f4 Add QueryData.with() helpers (#3991) 2019-10-03 14:52:12 -07:00
Sebastian Schmidt c433f48fd8 Add Query.MatchesAllDocuments() (#3990) 2019-10-03 13:43:36 -07:00
Gil 7235f8f6f6 Rewrite ExplicitNull as a propertyWrapper (#3954)
Add Swift4ExplicitNull that behaves as before.
2019-10-02 16:47:49 -07:00
Gil 3d91a0fb0d Update CHANGELOG for Firestore v1.6.0 (#3976) 2019-10-02 11:54:43 -07:00
Gil 057d0dff1f Make FIRDocumentChange a closed enum (#3960) 2019-10-02 08:43:35 -07:00
Konstantin Varlamov dbca369b0e Fix CMake build with Clang 10 (#3972)
The as-of-yet-unreleased Clang 10 adds some new warnings which make the CMake build fail (due to `-Werror`):
* BoringSSL build now fails because some of its C code contains fallthroughs in switch statements that aren't properly annotated. This wasn't an issue before because previous versions of Clang ignored `-Wimplicit-fallthrough` in C mode;
* serializer test contains an expression that produces the following warning:
```
/src/firebase-ios-sdk/Firestore/core/test/firebase/firestore/remote/serializer_test.cc:446:29:
error: implicit conversion from 'std::__1::numeric_limits<long>::type' (aka 'long') to 'double'
changes value from 9223372036854775807 to 9223372036854775808 [-Werror,
-Wimplicit-int-float-conversion]
```

Fixes:
* upgrade the version of BoringSSL used to the latest master. There's no particular reason to choose this commit, other than it happens to be the latest. The actual fixes we need are [this](https://github.com/google/boringssl/commit/05cd93068b0a553afc48f69acbceae10c6a17593) and [this](https://github.com/google/boringssl/commit/fbebe833b180a1a0685803c59bba38916826dd2b);
* apply `static_cast` to the serializer test. Also, because the cast produces a different value, add a couple of additional values to test.

The breakage was discovered thanks to the fuzz build (which already uses Clang 10 from trunk).
2019-10-01 20:48:56 -04:00
Brian Chen bca8785e62 Move addSnapshotsInSyncListener to public (#3968) 2019-10-01 14:32:30 -07:00
Gil 228537cb66 Provide better error messages when encoding is not available (#3953)
* Rewrite FirestoreEncoderTests using assertThat

* Throw invalidValue for use of invalid top-level values

* Provide an message for not supported errors
2019-10-01 10:04:52 -07:00
Gil b37ab3b433 Migrate FSTViewSnapshotTests to C++ (#3919)
* view_snapshot_test: move (unchanged) from FSTViewSnapshotTest.mm

* view_snapshot_test: automated changes

* view_snapshot_test: sync_project.rb generated changes

* view_snapshot_test: manual fixes

* view_snapshot_test: shorten DocumentViewChange::Type
2019-09-30 19:55:03 -07:00
Gil 7d06d34e05 Migrate tests written as C++ into the C++ tree (#3917)
* field_transform_test: move into Firestore/core

* field_transform_test: project changes

* transform_operation_test: move into Firestore/core

* transform_operation_test: project changes
2019-09-30 18:07:59 -07:00
Brian Chen 6495dca55c Move snapshotsInSync to public (#3942) 2019-09-30 16:36:51 -07:00
Gil 62c4fa30d2 Migrate FSTQueryListenerTests to C++ (#3901) 2019-09-30 13:17:53 -07:00
Gil 9ec602efcb Migrate FSTViewTests to C++ (#3900)
* Add view testing utilities

* Copy FSTViewTests.mm to view_test.cc unchanged

* Migrate FSTViewTests to C++
2019-09-30 11:26:42 -07:00