Commit Graph
298 Commits
Author SHA1 Message Date
Gil 7bdcd93dfb Fix benchmark builds on non-Apple platforms (#1677) 2018-08-13 12:57:23 -07:00
Mina Farid d6075418fa Fuzz test internal method in FIRFieldPath (#1675) 2018-08-13 14:02:38 -04:00
Gil 15ef78f090 Replace uses of absl::string_view in constructor parameters with std::string (#1676)
* Add a MakeStringView benchmark

Turns out this is worse than just creating a std::string:

BM_MakeString             29 ns         29 ns  189065849
BM_MakeStringView         59 ns         59 ns   93013367

* Convert database_id to take std::string

* Convert DatabaseInfo to take std::string

* Convert User to take std::string

* Convert Token to take std::string

* Convert MakeStringView([NSString stringWithFormat:]) to StringFormat
2018-08-13 11:02:28 -07:00
Gil 902fccf4b9 Initial filesystem implementation (#1633)
* Move Path into a separate filesystem library

* Add a filesystem interface and an NSFileManager-based implementation

* Use Path/Filesystem in FSTPersistenceTestHelpers
2018-08-13 09:04:13 -07:00
Gil 762b0b5500 Reimplement util::MakeString(NSString*) (#1673)
* Add a benchmark for string_apple.h

* Reimplement MakeString in terms of CoreFoundation
2018-08-13 08:11:21 -07:00
Gil db764c5d34 Move fuzzers out of core/test (#1668)
* Move fuzzers out of core/test
* Clean run of sync_project.rb
2018-08-09 15:41:52 -04:00
rsgowman 786f7666f9 Refactor serializers (#1625)
* Use nanopb::Reader, Writer, in the serializer's public methods. This eliminates overloads that take raw bytes.
* Refactor the serializer's return values from Status, StatusOr<T> to void, optional<T> (or unique_ptr<T>) for encoding/decode methods, respectively.
* Errors during serializer encoding methods now fatal. Previously, we'd propagate the errors back to the caller, but there aren't any errors that could realistically be recovered from. So now we just abort(). (This is in contrast to *de*coding methods, which could generate errors that we might want to recover from.)
* Reduce early returns in the serializers
* Unify public/private method return values of the serializers. Now the private methods return void/optional, just like the public methods.
* Reader::ReadTag now tracks the last read tag. This allows:
  * RequireWireType to not need it as a parameter
  * SkipField to not need it as a parameter
  * ReadTag to be inlined into most switch statements
* Move RequireWireType into ReadX methods
* Reader::SkipField -> Reader::SkipUnknown
* Add ReadNestedMessage overload in order to accept non-static functions.
* Add a few using statements to simplify code. (Also keeps local serializer more in sync with the remote serializer.)
* Use nullopt/nullptr instead of {}
* Reader::update_status() -> Fail()
* Add DecodeSnapshotVersion
* Don't directly update status within nanopb::Reader. Instead, call Reader::Fail() (which calls Status::Update()). This ensures we don't accidentally overwrite the first error status with
a subsequent one.
2018-08-08 17:32:25 -04:00
Gil 00f4f6d037 Migrate LevelDB Key classes to C++ (#1651)
* Migrate to LevelDbVersionKey

* Migrate to LevelDbMutationKey

* Migrate to LevelDbDocumentMutationKey

* Migrate to LevelDbMutationQueueKey

* Migrate to LevelDbTargetGlobalKey

* Migrate to LevelDbTargetKey

* Migrate to LevelDbQueryTargetKey

* Migrate to LevelDbTargetDocumentKey

* Migrate to LevelDbDocumentTargetKey

* Migrate to LevelDbRemoteDocumentKey

Also:
  - Remove FSTLevelDBKey and tests
  - Remove StringView and tests
2018-08-08 12:34:03 -07:00
Michael Lehenbauer da1c5346dd Fix for #1632.
get with source='cache' was not properly handling cached deleted documents.
2018-08-06 14:25:09 -07:00
Gil 4b90618818 Migrate [LevelDBKey descriptionForKey:] to DescribeKey() (#1638)
* Convert FSTLevelDBKeyTests to DescribeKey()

Note that the description coverage is already in leveldb_key_test.cc

* Rename Describe to DescribeKey

* Fix pointer alignment in leveldb_key.cc

* Add DescribeKey overloads for other string types

Unforunately, both leveldb::Slice and absl::string_view implicitly
convert from std::string which makes providing overloads for both
ambiguous for anything that converts to either.

* Migrate [FSTLevelDBKey descriptionForKey:] to DescribeKey()
2018-08-06 11:40:27 -07:00
Gil 154f96efd2 Convert FSTLevelDBMutationQueue.userID to std::string (#1637) 2018-08-06 08:11:06 -07:00
Sebastian Schmidt d9b50374ab Add multi-client support to the iOS spec runner (#1631) 2018-08-03 17:06:04 -07:00
Mina Farid 50dbc19456 Rename fuzz targets and use dictionary and corpus (#1628)
* Rename fuzz targets and use dictionary and corpus
* Added a comment about naming
2018-08-03 16:12:05 -04:00
Marek Gilbert 695f814fbb Merge branch 'release-5.5.0' into wilhuff/merge-5.5.0 2018-08-02 15:43:55 -07:00
Gil 2f0cd067e0 Bump CoreOnly requirements to 5.5.0 (#1629) 2018-08-02 15:38:16 -07:00
Gil 3799292eb3 Cherry pick fix for #1591 for M30 (#1626)
* Fixes decoding WriteResults for deletes (with no updateTime). (#1622)

This should resolve #1591.  We were inadvertantly decoding the WriteResult as
having an updateTime of 0 which caused it to be older than the version of the
document in the RemoteDocumentsCache. Therefore we kept the old version in
the cache instead of persisting the deleted document. This caused the document
to reappear in the query results until we resolved it via a limbo resolution.

* Add changelog entry for delete WriteResult fix (d9f116). (#1623)

* Actually this fix is going out with 0.13.0
2018-08-02 16:42:10 -04:00
Michael Lehenbauer d9f11627a3 Fixes decoding WriteResults for deletes (with no updateTime). (#1622)
This should resolve #1591.  We were inadvertantly decoding the WriteResult as
having an updateTime of 0 which caused it to be older than the version of the
document in the RemoteDocumentsCache. Therefore we kept the old version in
the cache instead of persisting the deleted document. This caused the document
to reappear in the query results until we resolved it via a limbo resolution.
2018-08-01 19:16:48 -07:00
Sebastian Schmidt f5ede65deb Don't look up TargetId in notifyLocalViewChanges (#1607) 2018-07-31 10:19:57 -07:00
Greg Soltis c0fcc092f4 Fix some comments (#1606)
* Fix a comment

* Remove another comment
2018-07-31 08:44:39 -07:00
zxu 098f93c5ed fix import pattern (#1604)
* fix import pattern

* fix style

* move check into cpplint.py

* replace than with rather than
2018-07-31 10:30:49 -04:00
Gil 6aaf6e6fd0 Add initial support for non-UTF-8 compilation and filenames (#1599)
* Add UTF-8 to wide character conversions for Windows pathnames.

* Explicitly mark UTF-8 string literals

Without this, string literals are encoded in the host's encoding, which
can be anything including CP-1252 on Windows, which will generate
invalid UTF-8 data when fed through our serializer.
2018-07-28 10:13:48 -07:00
Greg Soltis 16a5210b3c Merging the LRU branch (#1600)
* Switch to reference delegates for garbage collection (#1410)

* Bump sequence number on resume token refresh

* Style

* Fix comment formatting

* Add FSTReferenceDelegate definition and documentation

* Add methods to return nil for delegates, wire up inMemoryPins

* Add hook for removing a reference

* Start work on reference delegates

* Fix up tests to support adding documents at a sequence number

* Implement removing references

* Remove from target when dropped from local view

* Fix warning

* Add hooks for removal from mutation queue

* Add hooks for limbo document updates

* Style

* Drop commented-out code

* Fixup after merging master

* Start importing delegate implementations

* Memory LRU tests pass

* Make memory lru work, start fixing up lru tests. All with hidden sequence numbers

* Most LRU tests passing w/ memory

* Big LRU test passes w/ memory

* Leveldb LRU tests pass

* All passing except local store tests

* All tests pass

* Fix localstore tests

* Revert removeQueryData change

* Remove collectGarbage calls

* Remove NoOp GC

* More cleanup

* Refactor FSTHelpers

* Cleanup and commenting

* Comments and cleanup

* Comments

* Drop nullable for reference delegates, and old persistence method on spec tests

* Fix missing sequence bump, remove unneeded targetID

* Style

* Drop commented-out code

* Satisfy the linters and copyrighters, etc.

* Drop more commented-out code

* Fix import -> include, NSUInteger -> int

* Start work on test comments

* FSTDocumentKey -> DocumentKey

* Sample of LRU test refactor (#1424)

* Sample of test refactor

* Drop errant 'struct' keyword

* More test refactoring

* Make gc a member variable too

* Tests refactored to use member variables

* Assign delegates procedurally, rather than passing in a block

* Fix up FSTLevelDB a little

* listens -> listenTargets

* Rename GCEnabled

* remove isSentinel

* reword comment

* Add case for non-eager GC to test

* Style

* Cleaning the lint trap

* Clean up LRU tests (#1433)

* Add copious helpers and some docs to lru tests

* Style

* Method name refactor, add comment

* Drop FSTGarbageCollector and FSTEagerGarbageCollector (#1440)

* Drop FSTGarbageCollector and FSTEagerGarbageCollector

* Drop unused containsKey from FSTLevelDBMutationQueue

* Style

* Include sequence number in FSTQueryData hash and isEqual (#1568)

* Include sequence number in FSTQueryData hash and isEqual methods

* Style

* Switch to util::Hash

* Fix preserving query cache metadata (#1569)

* Add failing test

* Move the restart tests to the leveldb test suite

* Style

* Add new persistence test helper

* Fix test failure

* Review feedback

* Style
2018-07-27 13:58:11 -07:00
Mina Farid 31f6f804c5 Added fuzz testing target: FIRFieldPath (#1575)
* Added `FIELDPATH` to the list of available fuzzing targets.
* Added fuzzing method for creating `FIRFieldPath` objects.
* Added corpus and dictionary for `FIRFieldPath`.
2018-07-27 15:25:13 -04:00
Mina Farid 143c36c232 Fuzz testing refactoring (#1563)
* Added fuzzing targets read from env variable.
* Refactored Serializer fuzz tests in a separate file
* Separate header file for each fuzzing target.
* Write crashing outputs using `artifact_prefix` flag to `NSTemporaryDirectory`.
2018-07-23 09:55:32 -04:00
Marek Gilbert ed5da58a17 Merge remote-tracking branch 'origin/release-5.4.1' into merge-5.4.1 2018-07-20 09:57:46 -07:00
Greg Soltis 3b939a2362 Add Google Benchmark library and benchmark leveldb (#1137)
* Step one of benchmarking

* Benchmark writing to leveldb

* Comment out and style

* More comments

* Fix warnings

* Someday I will lint as good as computer

* Some light commenting and static-ing

* It seems to be working?

* Remove unused test file

* Drop commented-out deps

* Revert string quoting in pbxproj file

* Drop reference to deleted file

* Move podspec, fix import

* Lots of C++ style changes

* Style

* Drop whitespace
2018-07-19 19:43:58 -07:00
Mina Farid ab8ec2d725 Multiple fuzz testing targets (#1550)
* Read fuzzing target `FUZZING_TARGET` environment variable.
2018-07-19 17:02:02 -04:00
Sebastian Schmidt 9a241b2d7e Add spec test support for target-scoped resume tokens (#1498) 2018-07-19 11:55:43 -07:00
Gil c22a190871 Add a schema migration that drops the query cache (#1558)
This is a force fix for potential existence filter mismatches caused by
firebase/firebase-ios-sdk#1548

The essential problem is that when resuming a query, the server is
allowed to forget deletes. If the number of incorrectly synthesized
deletes matches the number of server-forgotten deletes then the
existence filter can give a false positive, preventing the cache from
self healing.

Dropping the query cache clears any client-side resume token which
prevents a false positive existence filter mismatch.

Note that the remote document cache and mutation queues are unaffected
so any cached documents that do exist will still work while offline

https://github.com/firebase/firebase-js-sdk/pull/1019
2018-07-19 11:22:55 -07:00
Gil 756da9c10c Add a schema migration that drops the query cache (#1558)
This is a force fix for potential existence filter mismatches caused by
firebase/firebase-ios-sdk#1548

The essential problem is that when resuming a query, the server is
allowed to forget deletes. If the number of incorrectly synthesized
deletes matches the number of server-forgotten deletes then the
existence filter can give a false positive, preventing the cache from
self healing.

Dropping the query cache clears any client-side resume token which
prevents a false positive existence filter mismatch.

Note that the remote document cache and mutation queues are unaffected
so any cached documents that do exist will still work while offline

https://github.com/firebase/firebase-js-sdk/pull/1019
2018-07-19 11:21:22 -07:00
Gil 9cc378a420 Allow remote updates from watch to heal a cache with synthesized deletes in it (#1557)
* Update spec tests from the js-sdk

* Allow remote updates from watch to heal a cache with synthesized deletes in it

Port of https://github.com/firebase/firebase-js-sdk/pull/1015

Addresses #1548
2018-07-19 10:44:18 -07:00
Michael Lehenbauer 7d438b5e0c b/72533250: Fix issue with limbo resolutions triggering incorrect manufactured deletes. (#1556)
[Port of https://github.com/firebase/firebase-js-sdk/pull/1014]

This fixes an issue occurring when a limbo target receives a documentUpdate,
then a global snapshot, and then a CURRENT. Because there was a global
snapshot before the CURRENT, WatchChangeAggregator has no pending document
updates and calls SyncEngine.remoteKeysForTarget to see if we previously got any
document from the backend for the target. See:
https://github.com/firebase/firebase-js-sdk/blob/6905339235ad801291edc696dd75a08e80647f5b/packages/firestore/src/remote/watch_change.ts#L422

Prior to this change, remoteKeysForTarget returned empty because
it relies on our Views to track the contents of the target, and we don't
have Views for limbo targets. Thus WatchChangeAggregator incorrectly
manufactures a NoDocument document update which deletes data from our
cache.

The fix is to have SyncEngine track the fact that we did indeed get
a document for the limbo resolution and return it from
remoteKeysForTarget.
2018-07-19 10:44:11 -07:00
Gil fe0952c832 Allow remote updates from watch to heal a cache with synthesized deletes in it (#1557)
* Update spec tests from the js-sdk

* Allow remote updates from watch to heal a cache with synthesized deletes in it

Port of https://github.com/firebase/firebase-js-sdk/pull/1015

Addresses #1548
2018-07-19 07:15:47 -07:00
Paul Beusterien acba81fcb0 Update versions for Release 5.4.1 2018-07-19 07:02:11 -07:00
Michael Lehenbauer c204a1cbfc b/72533250: Fix issue with limbo resolutions triggering incorrect manufactured deletes. (#1556)
[Port of https://github.com/firebase/firebase-js-sdk/pull/1014]

This fixes an issue occurring when a limbo target receives a documentUpdate,
then a global snapshot, and then a CURRENT. Because there was a global
snapshot before the CURRENT, WatchChangeAggregator has no pending document
updates and calls SyncEngine.remoteKeysForTarget to see if we previously got any
document from the backend for the target. See:
https://github.com/firebase/firebase-js-sdk/blob/6905339235ad801291edc696dd75a08e80647f5b/packages/firestore/src/remote/watch_change.ts#L422

Prior to this change, remoteKeysForTarget returned empty because
it relies on our Views to track the contents of the target, and we don't
have Views for limbo targets. Thus WatchChangeAggregator incorrectly
manufactures a NoDocument document update which deletes data from our
cache.

The fix is to have SyncEngine track the fact that we did indeed get
a document for the limbo resolution and return it from
remoteKeysForTarget.
2018-07-18 20:33:32 -07:00
Gil 853b4deab7 Remove the exclusive tag from the Firestore spec tests (#1555)
* Remove exclusive tag in spec tests.

* Mutations can return nil

For example, a patch mutation applied to a nil baseDoc will return nil.
2018-07-18 14:55:10 -07:00
Gil c7fb0a4875 Generate CMake frameworks from podspecs (#1531)
* Rename utils.cmake to cc_rules.cmake

This makes it less of a dumping ground

* Fix sign mismatch in FIRApp

* Implement a podspec_framework CMake function

... that generates a CMake framework library target from a podspec.

* Remove manual CMake scripts for xcodebuild
2018-07-16 11:46:55 -07:00
Mina Farid 22562f49eb Fuzz testing uses protoc from a pod dependency (#1538) 2018-07-16 13:55:10 -04:00
Gil e963b606f3 Migrate contents of SwiftBuildTest to Firestore_SwiftTests_iOS (#1524)
* Move main.swift to BasicCompileTests.swift

* Remove SwiftBuildTest from the Podfile, Xcode project, build.sh

Add Firestore_SwiftTests_iOS, but only if building with Xcode 9 or
better.
2018-07-15 10:44:01 -07:00
Mina Farid 730780faf4 Fuzz testing Serializer with a dictionary and corpus (#1513)
Added functionality to read dictionary file and seed input corpus from bundle
2018-07-13 15:02:48 -04:00
Gil 09c75c4fb8 Fix Firestore when compiled with Xcode 8.3 (#1519)
* Add a travis stage that tests building Firestore with Xcode 8.3.

* Simulate on a device available in Xcode 8

* Fix compile errors under Xcode 8.3.3

* Remove Firestore_SwiftTests_iOS from the Firestore_Tests_iOS Scheme

I'll create a new target for this but in another PR.

* Add an entry to CHANGELOG.md
2018-07-11 19:21:48 -07:00
rsgowman 82ef0886bf Move creation of FSTFilter objects to static create method on FSTFilter. (#1512)
Rather than previously inlining it in the calling code. This is to unify
filter creation across platforms.

(This change involves altering FSTFilter from a protocol to an abstract
class.)
2018-07-11 21:59:49 -04:00
Gil e1ace703fb Fix Firestore source errors under VS2017 (#1515)
* Project file updates from sync_project.rb

* Fix misc compile errors under VS2017

* Fix util/hashing under VS2017

std::hash<int> is not just a pass through in Microsoft's STL.

* Disable unsafe code warnings in VS2017

... where comparing against a reference implementation that has no easy
safe equivalent.

* Handle drive letters in paths on Windows
2018-07-11 15:27:50 -07:00
Ryan Wilson 79f663d5ea Add Auth interoperability library. (#1501)
* Add Auth interoperability library.

This allows other SDKs to retrieve the user ID and fetch a new
Auth token in a type-safe way through the Core container.

* Remove unnecessary import.

* Add missing copyright.

* Resolve comments.

- Remove unnecessary umbrella header.
- Move to version 1.0.
- Add tvOS support for app lifecycle changes.

* Move public interop headers to private.

* Add public_header_files too.

* Moved headers back into public.

* Shorten Interoperability and Interoperable to Interop.

* Add AuthInterop to travis linting.

* Fixed tag format in AuthInterop.podspec.

* Add AuthInterop path to Firestore Podfile.
2018-07-11 17:40:25 -04:00
Michael Lehenbauer 25f8691970 Expose array transforms and array contains queries. (#1514)
Also remove test code that was combining multiple array contains
queries since those were disallowed in
https://github.com/firebase/firebase-ios-sdk/commit/0ec836f9ca71b27fa54a11ae9e07e60b8c5cc002
2018-07-10 16:58:56 -07:00
Konstantin Varlamov 6466c35737 C++ migration: add a C++ implementation of FSTExponentialBackoff (#1465)
This is a pretty close port of `FSTExponentialBackoff`. The changes are pretty minor:

* delay is calculated using <chrono> duration types, not plain numbers, which should be a little more type-safe;
* split a piece of code into a ClampDelay function, because it's reasonably close to std::clamp;
* rephrased the class-level comment to make it clearer that the first attempt always has delay = 0;
* added simple tests (other platforms don't have tests for this).

Also make sure that canceling a DelayedOperation is always valid.
2018-07-10 17:45:16 -04:00
Konstantin Varlamov 0f0a1dab2d Eliminate unnecessary DocumentKey->FSTDocumentKey conversions (#1507) 2018-07-10 16:08:18 -04:00
Konstantin Varlamov ff95ffc61b In FSTLocalDocumentsView, search for all batches affecting a set of keys in one go (#1505)
This uses the newly-added allMutationBatchesAffectingDocumentKeys to find/deserialize all such batches in one go and then reuse the batches while processing a set of keys.
2018-07-10 13:59:25 -04:00
Gil bd69fae810 pod update for the addition of GoogleUtilities (#1506) 2018-07-09 13:34:56 -07:00
Gil a5eb8952f8 Add allMutationsAffectingDocumentKeys to FSTMutationQueue (#1479)
* Pod updates for Cocapods 1.5.3

* Add allMutationsAffectingDocumentKeys
2018-07-09 10:03:27 -07:00